diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/map/channel.c | 15 | ||||
-rw-r--r-- | src/map/irc-bot.c | 12 | ||||
-rw-r--r-- | src/map/irc-bot.h | 2 | ||||
-rw-r--r-- | src/map/script.c | 26 |
4 files changed, 47 insertions, 8 deletions
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 |