X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fevent_neonserv_mode.c;h=505d70d1abe45b356fd90dcce8a2839f68ba6e7a;hb=2d9db1adb1946aba00b203f40eff7d5db8163f01;hp=3eec5751de0e116a0dad3c78adb673f736a53a9d;hpb=07a2fd490b1a5164d9207a954259a51aa3e60e18;p=NeonServV5.git diff --git a/src/event_neonserv_mode.c b/src/event_neonserv_mode.c index 3eec575..505d70d 100644 --- a/src/event_neonserv_mode.c +++ b/src/event_neonserv_mode.c @@ -1,4 +1,4 @@ -/* event_neonserv_mode.c - NeonServ v5.0 +/* event_neonserv_mode.c - NeonServ v5.1 * Copyright (C) 2011 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -17,6 +17,9 @@ static USERLIST_CALLBACK(neonserv_event_mode_userlist_lookup); static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *modes, char **argv, int argc); +static int neonserv_cmd_mode_botwar_detect(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan); + +static int botwar_detect_executed; struct neonserv_event_mode_cache { struct ClientSocket *client; @@ -29,7 +32,7 @@ struct neonserv_event_mode_cache { static void neonserv_event_mode(struct UserNode *user, struct ChanNode *chan, char *modes, char **argv, int argc) { struct ClientSocket *client = getBotForChannel(chan); if(!client) return; //we can't "see" this event - if(user->flags & (USERFLAG_ISBOT | USERFLAG_ISIRCOP)) return; + if(isNetworkService(user)) return; loadChannelSettings(chan); if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return; struct neonserv_event_mode_cache *cache = malloc(sizeof(*cache)); @@ -69,6 +72,7 @@ static USERLIST_CALLBACK(neonserv_event_mode_userlist_lookup) { static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *modes, char **argv, int argc) { struct ClientSocket *textclient = ((client->flags & SOCKET_FLAG_PREFERRED) ? client : get_prefered_bot(client->botid)); + botwar_detect_executed = 0; MYSQL_ROW row, defaults = NULL; int i, arg, add = 1, skip = 0; unsigned int modetype; @@ -111,26 +115,28 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN break; } carg = argv[arg++]; - if(modes[i] == 'o') { + cuser = searchUserByNick(carg); + if(modes[i] == 'o' && !(add && isBot(cuser))) { if(uaccess < db_canop) { reply(textclient, user, "NS_MODE_ENFOPS", chan->name); db_canop = -1; } if(db_canop == -1) { - modeBufferSet(modeBuf, !add, modes[i], carg); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, !add, modes[i], carg); break; } - } else { + } else if(modes[i] == 'v') { if(uaccess < db_canvoice) { reply(textclient, user, "NS_MODE_ENFVOICE", chan->name); db_canvoice = -1; } if(db_canvoice == -1) { - modeBufferSet(modeBuf, !add, modes[i], carg); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, !add, modes[i], carg); break; } } - cuser = searchUserByNick(carg); if(!cuser) { break; //internal Bot error - this should never happen } @@ -138,12 +144,14 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN //check protection if(isBot(cuser)) { reply(textclient, user, "NS_SERVICE_IMMUNE", cuser->nick); - modeBufferSet(modeBuf, !add, modes[i], carg); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, !add, modes[i], carg); break; } if(isUserProtected(chan, cuser, user)) { reply(textclient, user, "NS_USER_PROTECTED", cuser->nick); - modeBufferSet(modeBuf, !add, modes[i], carg); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, !add, modes[i], carg); break; } } @@ -158,7 +166,8 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN db_canban = -1; } if(db_canban == -1) { - modeBufferSet(modeBuf, !add, modes[i], carg); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, !add, modes[i], carg); break; } char hostmask_buffer[NICKLEN+USERLEN+HOSTLEN+3]; @@ -182,7 +191,7 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN reply(textclient, user, "NS_LAME_MASK_WARNING", carg, match_count); } } - if(skip) { + if(skip && !neonserv_cmd_mode_botwar_detect(client, user, chan)) { modeBufferSet(modeBuf, !add, modes[i], carg); } break; @@ -205,7 +214,8 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN reply(textclient, user, "NS_MODE_LOCKED", tmp, chan->name); sent_modes_locked = 1; } - modeBufferSet(modeBuf, add, modes[i], modelock_val); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, add, modes[i], modelock_val); break; } } @@ -218,7 +228,8 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN sent_modes_locked = 1; } sprintf(tmp, "%d", *modelock_val); - modeBufferSet(modeBuf, add, modes[i], tmp); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, add, modes[i], tmp); break; } } @@ -235,7 +246,8 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN reply(textclient, user, "NS_MODE_LOCKED", tmp, chan->name); sent_modes_locked = 1; } - modeBufferSet(modeBuf, !add, modes[i], carg); + if(!neonserv_cmd_mode_botwar_detect(client, user, chan)) + modeBufferSet(modeBuf, !add, modes[i], carg); break; } break; @@ -244,3 +256,35 @@ static void neonserv_event_mode_async1(struct ClientSocket *client, struct UserN freeModeBuffer(modeBuf); freeModeNode(modelock); } + +static int neonserv_cmd_mode_botwar_detect(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan) { + struct ChanUser *chanuser = getChanUser(user, chan); + if(!chanuser) return 0; //flying super cow? + if(time(0) - chanuser->changeTime > BOTWAR_DETECTION_TIME) { + chanuser->changeTime = time(0); + chanuser->chageEvents = 1; + } else { + if(!botwar_detect_executed) + chanuser->chageEvents++; + botwar_detect_executed = 1; + if(chanuser->chageEvents >= BOTWAR_DETECTION_EVENTS || chanuser->chageEvents < 0) { + //BOTWAR! + chanuser->changeTime = time(0); + if(chanuser->chageEvents > 0) { + putsock(client, "NOTICE @%s :%s %s", chan->name, get_language_string(user, "NS_BOTWAR_DETECTED"), (BOTWAR_ALERT_CHAN ? get_language_string(user, "NS_BOTWAR_REPORTED") : "")); + if(BOTWAR_ALERT_CHAN) { + struct ChanNode *alertchan = getChanByName(BOTWAR_ALERT_CHAN); + struct ClientSocket *alertclient; + if(alertchan && (alertclient = getBotForChannel(chan)) != NULL) { + char msgBuf[MAXLEN]; + putsock(alertclient, "PRIVMSG %s :%s", alertchan->name, build_language_string(NULL, msgBuf, "NS_BOTWAR_ALERT", chan->name, user->nick)); + } + } + } + chanuser->chageEvents = -2; + return 1; + } + } + return 0; +} +