added OpenSSL handler
[NeonServV5.git] / src / bot_NeonSpam.c
index f1fe00ca8670bea6057781366998a174581f8b5b..0431f4a6665be84fc000f47b36b4b4abce1c5596 100644 (file)
 #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;
@@ -117,22 +143,18 @@ static void neonspam_trigger_callback(struct ChanNode *chan, char *trigger) {
 }
 
 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` 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[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