X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fbot_NeonSpam.c;h=981fda4851db8bec26757c6c6dd9d132d7adc773;hb=44436a96352a38631237978c9fd431cef3d85cfb;hp=f1fe00ca8670bea6057781366998a174581f8b5b;hpb=ffc462dec2b405f14d7b13d37e17b95ea6fdf2f5;p=NeonServV5.git diff --git a/src/bot_NeonSpam.c b/src/bot_NeonSpam.c index f1fe00c..981fda4 100644 --- a/src/bot_NeonSpam.c +++ b/src/bot_NeonSpam.c @@ -1,4 +1,4 @@ -/* bot_NeonSpam.c - NeonServ v5.2 +/* bot_NeonSpam.c - NeonServ v5.3 * Copyright (C) 2011 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -39,13 +39,14 @@ #include "cmd_neonspam.h" #define BOTID 2 +#define BOTALIAS "NeonSpam" static const struct default_language_entry msgtab[] = { - {"SS_SET_PERCENT", "%u is an invalid percent value (valid: 0-100)"}, - {"SS_SET_SENSIBILITY", "%s is an invalid sensibility format. (valid: amount:time e.g. 5:10)"}, - {"SS_SET_SENSIBILITY_AMOUNT", "%d is an invalid amount value. (valid: %d-%d)"}, - {"SS_SET_SENSIBILITY_TIME", "%d is an invalid time value. (valid: %d-%d)"}, - {"SS_SET_SPAMLIMIT", "%d is an invalid spamlimit value. (valid: %d-%d)"}, + {"SS_SET_PERCENT", "%u is an invalid percent value (valid: 0-100)"}, /* {ARGS: 120} */ + {"SS_SET_SENSIBILITY", "%s is an invalid sensibility format. (valid: amount:time e.g. 5:10)"}, /* {ARGS: "möp"} */ + {"SS_SET_SENSIBILITY_AMOUNT", "%d is an invalid amount value. (valid: %d-%d)"}, /* {ARGS: 120, 1, 5} */ + {"SS_SET_SENSIBILITY_TIME", "%d is an invalid time value. (valid: %d-%d)"}, /* {ARGS: 300, 15, 180} */ + {"SS_SET_SPAMLIMIT", "%d is an invalid spamlimit value. (valid: %d-%d)"}, /* {ARGS: 120, 2, 8} */ {"SS_SET_OPTION_SpamReaction_0", "Kick"}, {"SS_SET_OPTION_SpamReaction_1", "KickBan"}, {"SS_SET_OPTION_SpamReaction_2", "Timed Ban"}, @@ -88,6 +89,31 @@ static struct NeonSpamJoinNode *getNeonSpamJoinNode(struct ChanUser *chanuser); #include "event_neonspam_join.c" #include "event_neonspam_chanmsg.c" +static void neonspam_event_kick(struct UserNode *user, struct ChanUser *target, char *reason) { + struct ChanNode *chan = target->chan; + if(isBot(target->user)) { + struct ClientSocket *client = getChannelBot(chan, 0); + struct ClientSocket *bot = client; + for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) { + if(client->user == target->user) { + break; + } + } + if(!client) return; + if(bot && bot != client && (isModeSet(chan->modes, 'i') || isModeSet(chan->modes, 'a') || isModeSet(chan->modes, 'l'))) { + struct ChanUser *chanuser = getChanUser(bot->user, chan); + if(chanuser && chanuser->flags & CHANUSERFLAG_OPPED) + putsock(bot, "INVITE %s %s", target->user->nick, chan->name); + } + char *key = ""; + if(isModeSet(chan->modes, 'k')) { + key = getModeValue(chan->modes, 'k'); + } + putsock(client, "JOIN %s %s", chan->name, key); + return; + } +} + static void neonspam_bot_ready(struct ClientSocket *client) { MYSQL_RES *res; MYSQL_ROW row; @@ -106,33 +132,29 @@ static void neonspam_bot_ready(struct ClientSocket *client) { } } -static void neonspam_trigger_callback(struct ChanNode *chan, char *trigger) { +static void neonspam_trigger_callback(int clientid, struct ChanNode *chan, char *trigger) { MYSQL_RES *res; MYSQL_ROW row; loadChannelSettings(chan); printf_mysql_query("SELECT `trigger` FROM `bot_channels` LEFT JOIN `bots` ON `botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chan->channel_id, BOTID); res = mysql_use(); row = mysql_fetch_row(res); - strcpy(trigger, (strlen(row[0]) ? row[0] : "~")); + strcpy(trigger, ((row && strlen(row[0])) ? row[0] : "~")); } static void start_bots() { - struct UserNode *user; struct ClientSocket *client; MYSQL_RES *res, *res2; MYSQL_ROW row; - printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID); + printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue`, `ssl`, `bind` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID); res = mysql_use(); while ((row = mysql_fetch_row(res)) != NULL) { - user = addUser(row[0]); - strcpy(user->ident, row[1]); - strcpy(user->realname, row[2]); - user->flags |= USERFLAG_ISBOT; - client = create_socket(row[3], atoi(row[4]), row[5], user); + client = create_socket(row[3], atoi(row[4]), row[10], row[5], row[0], row[1], row[2]); client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0); client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0); + client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0); client->botid = BOTID; client->clientid = atoi(row[7]); connect_socket(client); @@ -291,6 +313,7 @@ static void createSpamNode(struct ChanUser *chanuser) { void init_NeonSpam() { + set_bot_alias(BOTID, BOTALIAS); start_bots(); //register events @@ -298,6 +321,7 @@ void init_NeonSpam() { bind_join(neonspam_event_join); bind_chanmsg(neonspam_event_chanmsg); bind_privctcp(general_event_privctcp); + bind_kick(neonspam_event_kick); set_trigger_callback(BOTID, neonspam_trigger_callback); @@ -313,3 +337,4 @@ void free_NeonSpam() { } #undef BOTID +#undef BOTALIAS