diff options
author | Haru <haru@dotalux.com> | 2013-08-05 16:02:25 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2013-08-12 17:14:51 +0200 |
commit | ca1f74fcd9974a8c06dee91b78a49fcb8d2b5095 (patch) | |
tree | 6812a68755e1ffe3314c7808dc59209f10fa1fee | |
parent | e7e2685a7dfb505e6ccabf83b44a2ea9620e1d86 (diff) | |
download | hercules-ca1f74fcd9974a8c06dee91b78a49fcb8d2b5095.tar.gz hercules-ca1f74fcd9974a8c06dee91b78a49fcb8d2b5095.tar.bz2 hercules-ca1f74fcd9974a8c06dee91b78a49fcb8d2b5095.tar.xz hercules-ca1f74fcd9974a8c06dee91b78a49fcb8d2b5095.zip |
Added support for long IRC messages
- IRC messages are no longer truncated to one line of client chat
message, if they are longer than that. They're instead posted as
multiple lines. (See comments in the source to disable this, if you
wish to.)
- Added a define for the max acceptable IRC message length, and
increased the size of send_string to fit it
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/map/irc-bot.c | 21 | ||||
-rw-r--r-- | src/map/irc-bot.h | 1 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c index 81c6981d0..fe7bf4bd4 100644 --- a/src/map/irc-bot.c +++ b/src/map/irc-bot.c @@ -23,7 +23,7 @@ struct irc_bot_interface irc_bot_s; -char send_string[200]; +char send_string[IRC_MESSAGE_LENGTH]; /** * Timer callback to (re-)connect to an IRC server @@ -172,7 +172,7 @@ void irc_parse_source(char *source, char *nick, char *ident, char *host) { * @param str Raw received message */ void irc_parse_sub(int fd, char *str) { - char source[180], command[60], buf1[500], buf2[500]; + char source[180], command[60], buf1[IRC_MESSAGE_LENGTH], buf2[IRC_MESSAGE_LENGTH]; char *target = buf1, *message = buf2; struct irc_func *func; @@ -206,8 +206,10 @@ void irc_parse_sub(int fd, char *str) { */ void irc_send(char *str) { int len = strlen(str) + 2; + if (len > IRC_MESSAGE_LENGTH-3) + len = IRC_MESSAGE_LENGTH-3; WFIFOHEAD(ircbot->fd, len); - snprintf((char*)WFIFOP(ircbot->fd,0),200, "%s\r\n", str); + snprintf((char*)WFIFOP(ircbot->fd,0),IRC_MESSAGE_LENGTH, "%s\r\n", str); WFIFOSET(ircbot->fd, len); } @@ -275,7 +277,7 @@ void irc_privmsg_ctcp(int fd, char *cmd, char *source, char *target, char *msg) void irc_privmsg(int fd, char *cmd, char *source, char *target, char *msg) { if( msg && *msg == '\001' && strlen(msg) > 2 && msg[strlen(msg)-1] == '\001' ) { // CTCP - char command[500], message[500]; + char command[IRC_MESSAGE_LENGTH], message[IRC_MESSAGE_LENGTH]; command[0] = message[0] = '\0'; sscanf(msg, "\001%499[^\001\r\n ] %499[^\r\n\001]\001", command, message); @@ -293,8 +295,15 @@ void irc_privmsg(int fd, char *cmd, char *source, char *target, char *msg) { ircbot->parse_source(source,source_nick,source_ident,source_host); if( ircbot->channel ) { - snprintf(send_string, 150, "[ #%s ] IRC.%s : %s",ircbot->channel->name,source_nick,msg); - clif->chsys_msg2(ircbot->channel,send_string); + int 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); + //break; // Uncomment this line to truncate long messages instead of posting them as multiple lines + if (strlen(msg) <= 149 - padding_len) + break; + msg += 149 - padding_len; + } } } } diff --git a/src/map/irc-bot.h b/src/map/irc-bot.h index c0a72dd07..aafbfccde 100644 --- a/src/map/irc-bot.h +++ b/src/map/irc-bot.h @@ -10,6 +10,7 @@ #define IRC_IDENT_LENGTH 40 #define IRC_HOST_LENGTH 63 #define IRC_FUNC_LENGTH 30 +#define IRC_MESSAGE_LENGTH 500 struct hChSysCh; |