diff options
author | Haruna <haru@dotalux.com> | 2015-01-24 14:38:39 +0100 |
---|---|---|
committer | Haruna <haru@dotalux.com> | 2015-01-24 14:38:39 +0100 |
commit | 6f3a82487fdffabf221a9a2dfc5ace027c333f95 (patch) | |
tree | 76f2ba97a955d0724949b5f233a81bcd4ea8cf52 /src/map/irc-bot.c | |
parent | a75714ca455c728d34918dd12200fcec87ebc0d4 (diff) | |
parent | 28eda3cd3dd7f8031668fdd8ba463e5661246348 (diff) | |
download | hercules-6f3a82487fdffabf221a9a2dfc5ace027c333f95.tar.gz hercules-6f3a82487fdffabf221a9a2dfc5ace027c333f95.tar.bz2 hercules-6f3a82487fdffabf221a9a2dfc5ace027c333f95.tar.xz hercules-6f3a82487fdffabf221a9a2dfc5ace027c333f95.zip |
Merge pull request #452 from HerculesWS/channel_refactor
Hercules Channel System refactor
Diffstat (limited to 'src/map/irc-bot.c')
-rw-r--r-- | src/map/irc-bot.c | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c index 36c19ccbd..d492ad9ca 100644 --- a/src/map/irc-bot.c +++ b/src/map/irc-bot.c @@ -10,7 +10,7 @@ #include <stdlib.h> #include <string.h> -#include "clif.h" +#include "channel.h" #include "map.h" #include "pc.h" #include "../common/cbasetypes.h" @@ -41,7 +41,7 @@ int irc_connect_timer(int tid, int64 tick, int id, intptr_t data) { ircbot->last_try = timer->gettick(); - if ((ircbot->fd = make_connection(ircbot->ip, clif->hChSys->irc_server_port, &opt)) > 0) { + if ((ircbot->fd = make_connection(ircbot->ip, channel->config->irc_server_port, &opt)) > 0) { session[ircbot->fd]->func_parse = ircbot->parse; session[ircbot->fd]->flag.server = 1; timer->add(timer->gettick() + 3000, ircbot->identify_timer, 0, 0); @@ -60,7 +60,7 @@ int irc_identify_timer(int tid, int64 tick, int id, intptr_t data) { sprintf(send_string, "USER HerculesWS%d 8 * : Hercules IRC Bridge",rnd()%777); ircbot->send(send_string); - sprintf(send_string, "NICK %s", clif->hChSys->irc_nick); + sprintf(send_string, "NICK %s", channel->config->irc_nick); ircbot->send(send_string); timer->add(timer->gettick() + 3000, ircbot->join_timer, 0, 0); @@ -76,15 +76,15 @@ int irc_join_timer(int tid, int64 tick, int id, intptr_t data) { if( !ircbot->isOn ) return 0; - if (clif->hChSys->irc_nick_pw[0] != '\0') { - sprintf(send_string, "PRIVMSG NICKSERV : IDENTIFY %s", clif->hChSys->irc_nick_pw); + if (channel->config->irc_nick_pw[0] != '\0') { + sprintf(send_string, "PRIVMSG NICKSERV : IDENTIFY %s", channel->config->irc_nick_pw); ircbot->send(send_string); - if (clif->hChSys->irc_use_ghost) { - sprintf(send_string, "PRIVMSG NICKSERV : GHOST %s %s", clif->hChSys->irc_nick, clif->hChSys->irc_nick_pw); + if (channel->config->irc_use_ghost) { + sprintf(send_string, "PRIVMSG NICKSERV : GHOST %s %s", channel->config->irc_nick, channel->config->irc_nick_pw); } } - sprintf(send_string, "JOIN %s", clif->hChSys->irc_channel); + sprintf(send_string, "JOIN %s", channel->config->irc_channel); ircbot->send(send_string); ircbot->isIn = true; @@ -120,7 +120,7 @@ int irc_parse(int fd) { ircbot->isOn = false; ircbot->isIn = false; ircbot->fails = 0; - ircbot->ip = host2ip(clif->hChSys->irc_server); + ircbot->ip = host2ip(channel->config->irc_server); timer->add(timer->gettick() + 120000, ircbot->connect_timer, 0, 0); return 0; } @@ -243,7 +243,7 @@ void irc_privmsg_ctcp(int fd, char *cmd, char *source, char *target, char *msg) if( strcmpi(cmd,"ACTION") == 0 ) { if( ircbot->channel ) { snprintf(send_string, 150, "[ #%s ] * IRC.%s %s *",ircbot->channel->name,source_nick,msg); - clif->chsys_msg2(ircbot->channel,send_string); + clif->channel_msg2(ircbot->channel,send_string); } } else if( strcmpi(cmd,"ERRMSG") == 0 ) { // Ignore it @@ -290,10 +290,10 @@ void irc_privmsg(int fd, char *cmd, char *source, char *target, char *msg) { irc_privmsg_ctcp(fd, command, source, target, message); #ifdef IRCBOT_DEBUG - } else if (strcmpi(target, clif->hChSys->irc_nick) == 0) { + } else if (strcmpi(target, channel->config->irc_nick) == 0) { ShowDebug("irc_privmsg: Received message from %s: '%s'\n", source ? source : "(null)", msg); #endif // IRCBOT_DEBUG - } else if (msg && strcmpi(target, clif->hChSys->irc_channel) == 0) { + } else if (msg && strcmpi(target, channel->config->irc_channel) == 0) { char source_nick[IRC_NICK_LENGTH], source_ident[IRC_IDENT_LENGTH], source_host[IRC_HOST_LENGTH]; source_nick[0] = source_ident[0] = source_host[0] = '\0'; @@ -305,7 +305,7 @@ void irc_privmsg(int fd, char *cmd, char *source, char *target, char *msg) { size_t padding_len = strlen(ircbot->channel->name) + strlen(source_nick) + 13; while (1) { snprintf(send_string, 150, "[ #%s ] IRC.%s : %s",ircbot->channel->name,source_nick,msg); - clif->chsys_msg2(ircbot->channel,send_string); + clif->channel_msg2(ircbot->channel,send_string); //break; // Uncomment this line to truncate long messages instead of posting them as multiple lines if (strlen(msg) <= 149 - padding_len) break; @@ -330,7 +330,7 @@ void irc_userjoin(int fd, char *cmd, char *source, char *target, char *msg) { if( ircbot->channel ) { snprintf(send_string, 150, "[ #%s ] User IRC.%s joined the channel.",ircbot->channel->name,source_nick); - clif->chsys_msg2(ircbot->channel,send_string); + clif->channel_msg2(ircbot->channel,send_string); } } @@ -352,7 +352,7 @@ void irc_userleave(int fd, char *cmd, char *source, char *target, char *msg) { snprintf(send_string, 150, "[ #%s ] User IRC.%s left the channel. [Quit: %s]",ircbot->channel->name,source_nick,msg); else snprintf(send_string, 150, "[ #%s ] User IRC.%s left the channel. [%s]",ircbot->channel->name,source_nick,msg); - clif->chsys_msg2(ircbot->channel,send_string); + clif->channel_msg2(ircbot->channel,send_string); } } @@ -371,7 +371,7 @@ void irc_usernick(int fd, char *cmd, char *source, char *target, char *msg) { if( ircbot->channel ) { snprintf(send_string, 150, "[ #%s ] User IRC.%s is now known as IRC.%s",ircbot->channel->name,source_nick,msg); - clif->chsys_msg2(ircbot->channel,send_string); + clif->channel_msg2(ircbot->channel,send_string); } } @@ -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", clif->hChSys->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); } @@ -406,12 +412,12 @@ void irc_bot_init(bool minimal) { if (minimal) return; - if (!clif->hChSys->irc) + if (!channel->config->irc) return; - if (!(ircbot->ip = host2ip(clif->hChSys->irc_server))) { - ShowError("Unable to resolve '%s' (irc server), disabling irc channel...\n", clif->hChSys->irc_server); - clif->hChSys->irc = false; + if (!(ircbot->ip = host2ip(channel->config->irc_server))) { + ShowError("Unable to resolve '%s' (irc server), disabling irc channel...\n", channel->config->irc_server); + channel->config->irc = false; return; } @@ -444,7 +450,7 @@ void irc_bot_init(bool minimal) { void irc_bot_final(void) { int i; - if (!clif->hChSys->irc) + if (!channel->config->irc) return; if( ircbot->isOn ) { ircbot->send("QUIT :Hercules is shutting down"); |