diff options
-rw-r--r-- | doc/script_commands.txt | 21 | ||||
-rw-r--r-- | src/map/channel.c | 10 | ||||
-rw-r--r-- | src/map/channel.h | 3 | ||||
-rw-r--r-- | src/map/script.c | 51 |
4 files changed, 85 insertions, 0 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 5ba0aaa2e..0ba350ad1 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7450,6 +7450,27 @@ no RID is attached), false will be returned. In case of success, true is returned. --------------------------------------- + +*addchannelhandler("<#channel>", "<NPC::OnEvent>") + +This command will trigger the specified event every time a player +talks in the specified channel, with said player as attached rid. +It assigns the message to @channelmes$ + +OnChannelMessage: + channelmes("#chan", "Echo: " + @channelmes$); + end; + +OnInit: + addchannelhandler("#chan", "NPC::OnChannelMessage"); + +--------------------------------------- + +*removechannelhandler("<#channel>", "<NPC::OnEvent>") + +Removes a channel handler added by addchannelhandler() + +--------------------------------------- *rand(<number>{, <number>}) This function returns a number ... diff --git a/src/map/channel.c b/src/map/channel.c index ee8242b23..9ec415883 100644 --- a/src/map/channel.c +++ b/src/map/channel.c @@ -26,6 +26,7 @@ #include "map/instance.h" #include "map/irc-bot.h" #include "map/map.h" +#include "map/npc.h" #include "map/pc.h" #include "common/cbasetypes.h" #include "common/conf.h" @@ -278,12 +279,21 @@ void channel_send(struct channel_data *chan, struct map_session_data *sd, const clif->messagecolor_self(sd->fd, COLOR_RED, msg_sd(sd,1455)); return; } else if (sd) { + int i; + safesnprintf(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(); + + for (i = 0; i < MAX_EVENTQUEUE; i++) { + if (chan->handlers[i][0] != '\0') { + pc->setregstr(sd, script->add_str("@channelmes$"), msg); + npc->event(sd, chan->handlers[i], 0); + } + } } else { safesnprintf(message, 150, "[ #%s ] %s", chan->name, msg); clif->channel_msg2(chan, message); diff --git a/src/map/channel.h b/src/map/channel.h index e8696fd90..4ac3c6037 100644 --- a/src/map/channel.h +++ b/src/map/channel.h @@ -23,6 +23,8 @@ #include "common/hercules.h" #include "common/mmo.h" +#include "map/map.h" // EVENT_NAME_LENGTH, MAX_EVENTQUEUE + /** * Declarations **/ @@ -85,6 +87,7 @@ struct channel_data { unsigned char color; struct DBMap *users; struct DBMap *banned; + char handlers[MAX_EVENTQUEUE][EVENT_NAME_LENGTH]; unsigned int options; unsigned int owner; enum channel_types type; diff --git a/src/map/script.c b/src/map/script.c index b0922e3f8..599285e1e 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -22925,6 +22925,55 @@ BUILDIN(channelmes) return true; } +BUILDIN(addchannelhandler) +{ + int i; + const char *channelname = script_getstr(st, 2); + const char *eventname = script_getstr(st, 3); + struct channel_data *chan = channel->search(channelname, NULL); + + if (!chan) { + script_pushint(st, 0); + return true; + } + + ARR_FIND(0, MAX_EVENTQUEUE, i, chan->handlers[i][0] == '\0'); + + if (i < MAX_EVENTQUEUE) { + safestrncpy(chan->handlers[i], eventname, EVENT_NAME_LENGTH); //Event enqueued. + script_pushint(st, 1); + return true; + } + + ShowWarning("script:addchannelhandler: too many handlers for channel %s.\n", channelname); + script_pushint(st, 0); + return true; +} + +BUILDIN(removechannelhandler) +{ + int i; + const char *channelname = script_getstr(st, 2); + const char *eventname = script_getstr(st, 3); + struct channel_data *chan = channel->search(channelname, NULL); + + if (!chan) { + script_pushint(st, 0); + return true; + } + + for (i = 0; i < MAX_EVENTQUEUE; i++) { + if (strcmp(chan->handlers[i], eventname) == 0) { + chan->handlers[i][0] = '\0'; + script_pushint(st, 1); + return true; + } + } + + script_pushint(st, 0); + return true; +} + /** By Cydh Display script message showscript "<message>"{,<GID>}; @@ -23721,6 +23770,8 @@ void script_parse_builtin(void) { BUILDIN_DEF(navigateto, "s??????"), BUILDIN_DEF(channelmes, "ss"), + BUILDIN_DEF(addchannelhandler, "ss"), + BUILDIN_DEF(removechannelhandler, "ss"), BUILDIN_DEF(showscript, "s?"), BUILDIN_DEF(mergeitem,""), BUILDIN_DEF(_,"s"), |