summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-01-23 13:50:03 +0100
committerHaru <haru@dotalux.com>2015-01-24 14:37:26 +0100
commitdfe8337d9ddb1a0b356ae86de9955845d280b759 (patch)
treef13976e43362237a697216a09457c1fa0ea41fae
parent3cfc6ddac576e236ccad0497d8e2ed2ae827c2bb (diff)
downloadhercules-dfe8337d9ddb1a0b356ae86de9955845d280b759.tar.gz
hercules-dfe8337d9ddb1a0b356ae86de9955845d280b759.tar.bz2
hercules-dfe8337d9ddb1a0b356ae86de9955845d280b759.tar.xz
hercules-dfe8337d9ddb1a0b356ae86de9955845d280b759.zip
Added script command 'channelmes'
Special thanks to Dastgir Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--doc/script_commands.txt14
-rw-r--r--src/map/channel.c15
-rw-r--r--src/map/irc-bot.c12
-rw-r--r--src/map/irc-bot.h2
-rw-r--r--src/map/script.c26
5 files changed, 61 insertions, 8 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 420f31943..3784667cb 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -7121,6 +7121,20 @@ be the NPC with the said name.
---------------------------------------
+*channelmes("<#channel>", "<message>");
+
+This command will send a message to the specified chat channel.
+
+The sent message will not include any character's names.
+
+For special channels, such as #map and #ally, the attached RID's map or guild
+will be used.
+
+If the channel doesn't exist (or, in the case of a character-specific channel,
+no RID is attached), false will be returned. In case of success, true is
+returned.
+
+---------------------------------------
*rand(<number>{,<number>});
This function returns a number ...
diff --git a/src/map/channel.c b/src/map/channel.c
index 7e0b9e15d..34ce60211 100644
--- a/src/map/channel.c
+++ b/src/map/channel.c
@@ -247,24 +247,31 @@ void channel_set_options(struct channel_data *chan, unsigned int options)
* @param chan The destination channel.
* @param sd The source character.
* @param msg The message to send.
+ *
+ * If no source character is specified, it'll send an anonymous message.
*/
void channel_send(struct channel_data *chan, struct map_session_data *sd, const char *msg)
{
+ char message[150];
nullpo_retv(chan);
- nullpo_retv(sd);
- if (chan->msg_delay != 0 && DIFF_TICK(sd->hchsysch_tick + chan->msg_delay*1000, timer->gettick()) > 0
+ if (sd && chan->msg_delay != 0
+ && DIFF_TICK(sd->hchsysch_tick + chan->msg_delay*1000, timer->gettick()) > 0
&& !pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN)) {
clif->colormes(sd->fd,COLOR_RED,msg_txt(1455));
return;
- } else {
- char message[150];
+ } else if (sd) {
snprintf(message, 150, "[ #%s ] %s : %s",chan->name,sd->status.name, msg);
clif->channel_msg(chan,sd,message);
if (chan->type == HCS_TYPE_IRC)
ircbot->relay(sd->status.name,msg);
if (chan->msg_delay != 0)
sd->hchsysch_tick = timer->gettick();
+ } else {
+ snprintf(message, 150, "[ #%s ] %s",chan->name, msg);
+ clif->channel_msg2(chan, message);
+ if (chan->type == HCS_TYPE_IRC)
+ ircbot->relay(NULL, msg);
}
}
diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c
index 173675911..d492ad9ca 100644
--- a/src/map/irc-bot.c
+++ b/src/map/irc-bot.c
@@ -380,10 +380,16 @@ void irc_usernick(int fd, char *cmd, char *source, char *target, char *msg) {
* @param name Sender's name
* @param msg Message text
*/
-void irc_relay(char *name, const char *msg) {
- if( !ircbot->isIn )
+void irc_relay(const char *name, const char *msg)
+{
+ if (!ircbot->isIn)
return;
- sprintf(send_string,"PRIVMSG %s :[ %s ] : %s", channel->config->irc_channel, name, msg);
+
+ if (name)
+ sprintf(send_string,"PRIVMSG %s :[ %s ] : %s", channel->config->irc_channel, name, msg);
+ else
+ sprintf(send_string,"PRIVMSG %s :%s", channel->config->irc_channel, msg);
+
ircbot->send(send_string);
}
diff --git a/src/map/irc-bot.h b/src/map/irc-bot.h
index 2eb0581df..8dcfea5bd 100644
--- a/src/map/irc-bot.h
+++ b/src/map/irc-bot.h
@@ -50,7 +50,7 @@ struct irc_bot_interface {
int (*join_timer) (int tid, int64 tick, int id, intptr_t data);
/* */
void (*send)(char *str);
- void (*relay) (char *name, const char *msg);
+ void (*relay) (const char *name, const char *msg);
/* */
void (*pong) (int fd, char *cmd, char *source, char *target, char *msg);
void (*privmsg) (int fd, char *cmd, char *source, char *target, char *msg);
diff --git a/src/map/script.c b/src/map/script.c
index a2ea86ac6..f50e56d2d 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -16,6 +16,7 @@
#include "atcommand.h"
#include "battle.h"
#include "battleground.h"
+#include "channel.h"
#include "chat.h"
#include "chrif.h"
#include "clif.h"
@@ -19012,6 +19013,29 @@ BUILDIN(shopcount) {
return true;
}
+/**
+ * @call channelmes("#channel", "message");
+ *
+ * Sends a message through the specified chat channel.
+ *
+ */
+BUILDIN(channelmes)
+{
+ struct map_session_data *sd = script->rid2sd(st);
+ const char *channelname = script_getstr(st, 2);
+ struct channel_data *chan = channel->search(channelname, sd);
+
+ if (!chan) {
+ script_pushint(st, 0);
+ return true;
+ }
+
+ channel->send(chan, NULL, script_getstr(st, 3));
+
+ script_pushint(st, 1);
+ return true;
+}
+
// declarations that were supposed to be exported from npc_chat.c
#ifdef PCRE_SUPPORT
BUILDIN(defpattern);
@@ -19637,6 +19661,8 @@ void script_parse_builtin(void) {
BUILDIN_DEF(tradertype,"i"),
BUILDIN_DEF(purchaseok,""),
BUILDIN_DEF(shopcount, "i"),
+
+ BUILDIN_DEF(channelmes, "ss"),
};
int i, len = ARRAYLENGTH(BUILDIN);
RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up