Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / bot_NeonSpam.c
index f1fe00ca8670bea6057781366998a174581f8b5b..7d7dc1f2c4d62732ddf032a7231b3381fa539dce 100644 (file)
@@ -1,5 +1,5 @@
-/* bot_NeonSpam.c - NeonServ v5.2
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* bot_NeonSpam.c - NeonServ v5.3
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #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,39 +132,42 @@ 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);
+    if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) {
+        strcpy(trigger, "~");
+        return;
+    }
+    printf_mysql_query("SELECT `trigger`, `defaulttrigger` 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] : "~"));
+    if(row[0] && *row[0])
+        strcpy(trigger, row[0]);
+    else
+        strcpy(trigger, ((row[1] && *row[1]) ? row[1] : "~"));
 }
 
 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);
     }
     
-    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
     res2 = mysql_use();
     while ((row = mysql_fetch_row(res2)) != NULL) {
         if(bind_cmd_to_command(BOTID, row[0], row[1])) {
@@ -151,6 +180,8 @@ static void start_bots() {
             if(row[4]) {
                 bind_set_channel_access(BOTID, row[0], row[4]);
             }
+            if(strcmp(row[5], "0"))
+                bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
         }
     }
     bind_unbound_required_functions(BOTID);
@@ -291,6 +322,7 @@ static void createSpamNode(struct ChanUser *chanuser) {
 
 void init_NeonSpam() {
     
+    set_bot_alias(BOTID, BOTALIAS);
     start_bots();
     
     //register events
@@ -298,6 +330,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 +346,4 @@ void free_NeonSpam() {
 }
 
 #undef BOTID
+#undef BOTALIAS