From 19b8cbb835e867febb597b34187f6bbca48cbe7b Mon Sep 17 00:00:00 2001 From: shennetsind Date: Mon, 22 Apr 2013 18:28:18 -0300 Subject: Hercules April 22 MEGA-ULTRA-LONG Patch~! http://hercules.ws/board/topic/470-hercules-april-22-patch/ Signed-off-by: shennetsind --- src/map/irc-bot.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/map/irc-bot.h (limited to 'src/map/irc-bot.h') diff --git a/src/map/irc-bot.h b/src/map/irc-bot.h new file mode 100644 index 000000000..d1bf0866d --- /dev/null +++ b/src/map/irc-bot.h @@ -0,0 +1,58 @@ +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Base Author: shennetsind @ http://hercules.ws + + +#ifndef _IRC_BOT_H_ +#define _IRC_BOT_H_ + +#define IRC_FUNC_LENGTH 30 + +struct hChSysCh; + +struct irc_func { + char name[IRC_FUNC_LENGTH]; + void (*func)(int, char*, char*, char*, char*); +}; + +struct irc_bot_interface { + int fd; + bool isIn; + unsigned int last_try; + unsigned char fails; + unsigned long ip; + unsigned short port; + /* */ + struct hChSysCh *channel; + /* */ + struct { + struct irc_func **list; + unsigned int size; + } funcs; + /* */ + void (*init) (void); + void (*final) (void); + /* */ + int (*parse) (int fd); + void (*parse_sub) (int fd, char *str); + void (*parse_source) (char *source, char *nick, char *ident, char *host); + /* */ + struct irc_func* (*func_search) (char* function_name); + /* */ + int (*connect_timer) (int tid, unsigned int tick, int id, intptr_t data); + int (*identify_timer) (int tid, unsigned int tick, int id, intptr_t data); + int (*join_timer) (int tid, unsigned int tick, int id, intptr_t data); + /* */ + void (*send)(char *str); + void (*relay) (char *name, char *msg); + /* */ + void (*pong) (int fd, char *cmd, char *source, char *target, char *msg); + void (*join) (int fd, char *cmd, char *source, char *target, char *msg); + void (*privmsg) (int fd, char *cmd, char *source, char *target, char *msg); +} irc_bot_s; + +struct irc_bot_interface *ircbot; + +void ircbot_defaults(void); + +#endif /* _IRC_BOT_H_ */ -- cgit v1.2.3-70-g09d2 From 5a74f3f57a671e7729d8f48cdcc1d6f9454f504b Mon Sep 17 00:00:00 2001 From: shennetsind Date: Wed, 24 Apr 2013 10:54:37 -0300 Subject: Fixed msvc warning on irc-bot Special Thanks to Zopokx! Signed-off-by: shennetsind --- src/map/irc-bot.c | 16 +++++++++------- src/map/irc-bot.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/map/irc-bot.h') diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c index 3e7d7eb06..28224244d 100644 --- a/src/map/irc-bot.c +++ b/src/map/irc-bot.c @@ -22,7 +22,7 @@ char send_string[200]; int irc_connect_timer(int tid, unsigned int tick, int id, intptr_t data) { - if( ircbot->fd != -1 || session[ircbot->fd] || ++ircbot->fails >= 3 ) + if( ircbot->isOn || ++ircbot->fails >= 3 ) return 0; ircbot->last_try = gettick(); @@ -35,7 +35,7 @@ int irc_connect_timer(int tid, unsigned int tick, int id, intptr_t data) { } int irc_identify_timer(int tid, unsigned int tick, int id, intptr_t data) { - if( ircbot->fd == -1 ) + if( !ircbot->isOn ) return 0; sprintf(send_string, "USER HerculesWS%d 8 * : Hercules IRC Bridge",rand()%777); @@ -49,7 +49,7 @@ int irc_identify_timer(int tid, unsigned int tick, int id, intptr_t data) { } int irc_join_timer(int tid, unsigned int tick, int id, intptr_t data) { - if( ircbot->fd == -1 ) + if( !ircbot->isOn ) return 0; if( hChSys.irc_nick_pw[0] != '\0' ) { @@ -79,7 +79,8 @@ int irc_parse(int fd) { if (session[fd]->flag.eof) { do_close(fd); - ircbot->fd = -1; + ircbot->fd = 0; + ircbot->isOn = false; ircbot->isIn = false; ircbot->fails = 0; ircbot->ip = host2ip(hChSys.irc_server); @@ -225,8 +226,9 @@ void irc_bot_init(void) { } ircbot->fails = 0; - ircbot->fd = -1; - ircbot->isIn = true; + ircbot->fd = 0; + ircbot->isIn = false; + ircbot->isOn = false; add_timer_func_list(ircbot->connect_timer, "irc_connect_timer"); add_timer(gettick() + 7000, ircbot->connect_timer, 0, 0); @@ -237,7 +239,7 @@ void irc_bot_final(void) { if( !hChSys.irc ) return; - if( ircbot->fd != -1 ) { + if( ircbot->isOn ) { ircbot->send("QUIT :Hercules is shutting down"); do_close(ircbot->fd); } diff --git a/src/map/irc-bot.h b/src/map/irc-bot.h index d1bf0866d..f4244e024 100644 --- a/src/map/irc-bot.h +++ b/src/map/irc-bot.h @@ -17,7 +17,7 @@ struct irc_func { struct irc_bot_interface { int fd; - bool isIn; + bool isIn, isOn; unsigned int last_try; unsigned char fails; unsigned long ip; -- cgit v1.2.3-70-g09d2