{NULL, NULL}
};
-//define some usefull functions :D
+//define some useful functions :D
static TIMEQ_CALLBACK(channel_ban_timeout);
+static struct ClientSocket *getBotForChannel(struct ChanNode *chan);
/*
INCLUDE ALL CMD's HERE
//#include "cmd_neonserv_iplocate.c"
//#include "cmd_neonserv_calc.c"
-//DEBUG
-#include "cmd_neonserv_modes.c"
+//EVENTS
+#include "event_neonserv_join.c"
+//#include "event_neonserv_part.c"
+//#include "event_neonserv_quit.c"
+//#include "event_neonserv_kick.c"
+//#include "event_neonserv_mode.c"
+//#include "event_neonserv_ctcp.c"
+//#include "event_neonserv_notice.c"
+//#include "event_neonserv_invite.c"
+
+static struct ClientSocket *getBotForChannel(struct ChanNode *chan) {
+ struct ClientSocket *bot, *use_bot = NULL, *second_bot = NULL, *third_bot = NULL;
+ struct ChanUser *chanuser;
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ if(bot->botid != BOTID) continue;
+ if((chanuser = getChanUser(bot->user, chan)) != NULL) {
+ if((chanuser->flags & CHANUSERFLAG_OPPED)) {
+ use_bot = bot;
+ if(bot->flags & SOCKET_FLAG_PREFERRED) break;
+ } else if(bot->flags & SOCKET_FLAG_PREFERRED)
+ second_bot = bot;
+ else
+ third_bot = bot;
+ }
+ }
+ if(!use_bot) use_bot = second_bot;
+ if(!use_bot) use_bot = third_bot;
+ return use_bot;
+}
static void neonserv_bot_ready(struct ClientSocket *client) {
MYSQL_RES *res;
res = mysql_use();
struct ChanNode *chan;
if((row = mysql_fetch_row(res)) != NULL && (chan = getChanByName(row[1])) != NULL) {
- struct ClientSocket *bot, *use_bot = NULL;
- struct ChanUser *chanuser;
- for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
- if((chanuser = getChanUser(bot->user, chan)) != NULL && (chanuser->flags & CHANUSERFLAG_OPPED)) {
- use_bot = bot;
- if(bot->flags & SOCKET_FLAG_PREFERRED) break;
- }
- }
+ struct ClientSocket *use_bot = getBotForChannel(chan);
if(use_bot) {
putsock(use_bot, "MODE %s -b %s", chan->name, row[0]);
}
register_command(BOTID, "move", neonserv_cmd_move, 2, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG, NULL, 300);
start_bots();
+
+ //register events
bind_bot_ready(neonserv_bot_ready);
+ bind_join(neonserv_event_join);
+
set_trigger_callback(BOTID, neonserv_trigger_callback);
register_default_language_table(msgtab);