added basic NeonSpam code (no functions)
authorpk910 <philipp@zoelle1.de>
Tue, 18 Oct 2011 20:27:29 +0000 (22:27 +0200)
committerpk910 <philipp@zoelle1.de>
Tue, 18 Oct 2011 20:51:38 +0000 (22:51 +0200)
Makefile.am
src/bot_NeonServ.c
src/bot_NeonServ.h
src/bot_NeonSpam.c [new file with mode: 0644]
src/bot_NeonSpam.h [new file with mode: 0644]
src/bots.c
src/bots.h
src/cmd_neonserv.h

index f437aeabc0643722b0bf426bc05df3e59db1d939..ad6a87d2e04aacef5d03aa8ae07788c3069019c0 100644 (file)
@@ -30,6 +30,7 @@ neonserv_SOURCES = src/version.c \
       src/DBHelper.c \
       src/bots.c \
       src/bot_NeonServ.c \
+      src/bot_NeonSpam.c \
       src/cmd_neonserv_access.c \
       src/cmd_neonserv_addban.c \
       src/cmd_neonserv_addtimeban.c \
index 5336737b181a1d88d8a404e386fb31c62db99c98..2f449e7f7330be9e9e8c5ee32ab70951cd9808dd 100644 (file)
@@ -340,24 +340,9 @@ cmd_neonserv_calc.c
 #include "event_neonserv_invite.c"
 #include "event_neonserv_topic.c"
 
+
 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;
+    return getChannelBot(chan, BOTID);
 }
 
 static void neonserv_bot_ready(struct ClientSocket *client) {
@@ -424,37 +409,6 @@ static void start_bots() {
             }
         }
     }
-    
-    //load all timed bans
-    printf_mysql_query("SELECT `ban_id`, `ban_timeout` FROM `bans` WHERE `ban_timeout` > 0");
-    res = mysql_use();
-    char nameBuf[20];
-    while ((row = mysql_fetch_row(res)) != NULL) {
-        if(atol(row[1]) - time(0) > 0) {
-            sprintf(nameBuf, "ban_%s", row[0]);
-            timeq_add_name(nameBuf, atol(row[1]) - time(0), channel_ban_timeout, strdup(row[0]));
-        } else {
-            //timed out
-            printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", row[0]);
-        }
-    }
-}
-
-TIMEQ_CALLBACK(channel_ban_timeout) {
-    char *str_banid = data;
-    MYSQL_RES *res;
-    MYSQL_ROW row;
-    printf_mysql_query("SELECT `ban_mask`, `channel_name` FROM `bans` LEFT JOIN `channels` ON `ban_channel` = `channel_id` WHERE `ban_id` = '%s'", str_banid);
-    res = mysql_use();
-    struct ChanNode *chan;
-    if((row = mysql_fetch_row(res)) != NULL && (chan = getChanByName(row[1])) != NULL) {
-        struct ClientSocket *use_bot = getBotForChannel(chan);
-        if(use_bot) {
-            putsock(use_bot, "MODE %s -b %s", chan->name, row[0]);
-        }
-        printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", str_banid);
-    }
-    free(str_banid);
 }
 
 void init_NeonServ() {
index 1148f663f53e29fd0f2de8fbdd628bddebbcb364..3dee8c84f3d60796b623805cf2b049ec4eb683fc 100644 (file)
@@ -18,7 +18,6 @@
 #define _bot_NeonServ_h
 
 #include "main.h"
-#include "timeq.h"
 
 struct ChanNode;
 
@@ -26,7 +25,6 @@ void init_NeonServ();
 void loop_NeonServ();
 void free_NeonServ();
 
-TIMEQ_CALLBACK(channel_ban_timeout);
 struct ClientSocket *getBotForChannel(struct ChanNode *chan);
 
 #endif
\ No newline at end of file
diff --git a/src/bot_NeonSpam.c b/src/bot_NeonSpam.c
new file mode 100644 (file)
index 0000000..19d9876
--- /dev/null
@@ -0,0 +1,117 @@
+/* bot_NeonSpam.c - NeonServ v5.1
+ * Copyright (C) 2011  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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "bot_NeonSpam.h"
+#include "cmd_neonserv.h"
+
+#define BOTID 2
+
+static const struct default_language_entry msgtab[] = {
+    {NULL, NULL}
+};
+
+//EVENTS
+//#include "event_neonspam_join.c"
+
+static void neonspam_bot_ready(struct ClientSocket *client) {
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    
+    printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid);
+    res = mysql_use();
+    if ((row = mysql_fetch_row(res)) != NULL) {
+        putsock(client, "MODE %s +%s", client->user->nick, row[0]);
+    }
+    
+    printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d' AND `suspended` = '0'", client->clientid);
+    res = mysql_use();
+    
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        putsock(client, "JOIN %s %s", row[0], row[1]);
+    }
+}
+
+static void neonspam_trigger_callback(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] : "~"));
+}
+
+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` 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->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 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'", client->botid);
+        res2 = mysql_use();
+        while ((row = mysql_fetch_row(res2)) != NULL) {
+            if(bind_cmd_to_command(BOTID, row[0], row[1])) {
+                if(row[2] && strcmp(row[2], "")) {
+                    bind_set_parameters(BOTID, row[0], row[2]);
+                }
+                if(row[3]) {
+                    bind_set_global_access(BOTID, row[0], atoi(row[3]));
+                }
+                if(row[4]) {
+                    bind_set_channel_access(BOTID, row[0], row[4]);
+                }
+            }
+        }
+    }
+    
+}
+
+void init_NeonSpam() {
+    start_bots();
+    
+    //register events
+    bind_bot_ready(neonspam_bot_ready);
+    //bind_join(neonspam_event_join);
+    
+    set_trigger_callback(BOTID, neonspam_trigger_callback);
+    
+    register_default_language_table(msgtab);
+}
+
+void loop_NeonSpam() {
+    
+}
+
+void free_NeonSpam() {
+    
+}
+
+#undef BOTID
diff --git a/src/bot_NeonSpam.h b/src/bot_NeonSpam.h
new file mode 100644 (file)
index 0000000..e350439
--- /dev/null
@@ -0,0 +1,27 @@
+/* bot_NeonSpam.h - NeonServ v5.1
+ * Copyright (C) 2011  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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#ifndef _bot_NeonSpam_h
+#define _bot_NeonSpam_h
+
+#include "main.h"
+
+void init_NeonSpam();
+void loop_NeonSpam();
+void free_NeonSpam();
+
+#endif
\ No newline at end of file
index 43096d4079f548342b9878dc57f34f4e18d72d34..6f64c5e1cb0ebfb2c3f99f81288f9955898b2459 100644 (file)
  */
 
 #include "bots.h"
+#include "timeq.h"
+#include "mysqlConn.h"
+#include "ClientSocket.h"
+#include "UserNode.h"
+#include "ChanNode.h"
+#include "ChanUser.h"
 
 #include "bot_NeonServ.h"
+#include "bot_NeonSpam.h"
 
 void init_bots() {
     init_NeonServ();
+    init_NeonSpam();
+    
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    //load all timed bans
+    printf_mysql_query("SELECT `ban_id`, `ban_timeout` FROM `bans` WHERE `ban_timeout` > 0");
+    res = mysql_use();
+    char nameBuf[20];
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        if(atol(row[1]) - time(0) > 0) {
+            sprintf(nameBuf, "ban_%s", row[0]);
+            timeq_add_name(nameBuf, atol(row[1]) - time(0), channel_ban_timeout, strdup(row[0]));
+        } else {
+            //timed out
+            printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", row[0]);
+        }
+    }
 }
 
 void loop_bots() {
     loop_NeonServ();
+    loop_NeonSpam();
 }
 
 void free_bots() {
     free_NeonServ();
+    free_NeonSpam();
+}
+
+struct ClientSocket *getChannelBot(struct ChanNode *chan, int botid) {
+    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(botid && 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;
+}
+
+TIMEQ_CALLBACK(channel_ban_timeout) {
+    char *str_banid = data;
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    printf_mysql_query("SELECT `ban_mask`, `channel_name` FROM `bans` LEFT JOIN `channels` ON `ban_channel` = `channel_id` WHERE `ban_id` = '%s'", str_banid);
+    res = mysql_use();
+    struct ChanNode *chan;
+    if((row = mysql_fetch_row(res)) != NULL && (chan = getChanByName(row[1])) != NULL) {
+        struct ClientSocket *use_bot = getChannelBot(chan, 0);
+        if(use_bot) {
+            putsock(use_bot, "MODE %s -b %s", chan->name, row[0]);
+        }
+        printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", str_banid);
+    }
+    free(str_banid);
 }
index debf219d5dd37048dd2e5f2cb6881daaf89ebe4f..c0dcd299bcde5587b016d2ef597ac84df9ed4b54 100644 (file)
 #define _bots_h
 
 #include "main.h"
+#include "timeq.h"
+
+struct ChanNode;
+struct ClientSocket;
 
 void init_bots();
 void loop_bots();
 void free_bots();
 
+struct ClientSocket *getChannelBot(struct ChanNode *chan, int botid);
+TIMEQ_CALLBACK(channel_ban_timeout);
+
 #endif
\ No newline at end of file
index 5042cbb4406d356e30a1d8797728fe90306c5efc..f833ba4e3cd3d594bd649a7d2575b75e89f4d6d2 100644 (file)
@@ -35,6 +35,7 @@
 #include "timeq.h"
 #include "version.h"
 #include "EventLogger.h"
+#include "bots.h"
 #include "bot_NeonServ.h"
 
 CMD_BIND(neonserv_cmd_access);