added useless DummyServ (just for getting some events from channels, bots aren't...
authorpk910 <philipp@zoelle1.de>
Wed, 26 Oct 2011 00:28:06 +0000 (02:28 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 26 Oct 2011 01:01:35 +0000 (03:01 +0200)
Makefile.am
src/bot_DummyServ.c [new file with mode: 0644]
src/bot_DummyServ.h [new file with mode: 0644]
src/bots.c

index 534922fbc0a3b69160bfb9aff7f7736f18ba5507..8c32f660c6175ef37ec6cba5809d25f7b54ab523 100644 (file)
@@ -32,6 +32,7 @@ neonserv_SOURCES = src/version.c \
       src/bots.c \
       src/bot_NeonServ.c \
       src/bot_NeonSpam.c \
+      src/bot_DummyServ.c \
       src/cmd_neonserv_access.c \
       src/cmd_neonserv_addban.c \
       src/cmd_neonserv_addtimeban.c \
diff --git a/src/bot_DummyServ.c b/src/bot_DummyServ.c
new file mode 100644 (file)
index 0000000..88e8461
--- /dev/null
@@ -0,0 +1,142 @@
+/* bot_DummyServ.c - NeonServ v5.2
+ * 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_DummyServ.h"
+#include "modcmd.h"
+#include "IRCParser.h"
+#include "IRCEvents.h"
+#include "UserNode.h"
+#include "ChanNode.h"
+#include "ChanUser.h"
+#include "ModeNode.h"
+#include "BanNode.h"
+#include "ClientSocket.h"
+#include "mysqlConn.h"
+#include "lang.h"
+#include "HandleInfoHandler.h"
+#include "WHOHandler.h"
+#include "DBHelper.h"
+#include "tools.h"
+#include "timeq.h"
+#include "version.h"
+#include "EventLogger.h"
+#include "bots.h"
+#include "cmd_neonserv.h"
+#include "cmd_neonspam.h"
+
+#define BOTID 3
+
+static void dummyserv_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 dummyserv_trigger_callback(struct ChanNode *chan, char *trigger) {
+    //this bot doesn't have a trigger
+    strcpy(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);
+    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->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 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_DummyServ() {
+    
+    #define USER_COMMAND(NAME,FUNCTION,PARAMCOUNT,PRIVS,FLAGS) register_command(BOTID, NAME, FUNCTION, PARAMCOUNT, PRIVS, 0, FLAGS)
+    //               NAME              FUNCTION        PARAMS     PRIVS                FLAGS
+    USER_COMMAND("netinfo",      neonserv_cmd_netinfo,   0, NULL,                   0);
+    USER_COMMAND("version",      neonserv_cmd_version,   0, NULL,                   0);
+    #undef USER_COMMAND
+    
+    #define OPER_COMMAND(NAME,FUNCTION,PARAMCOUNT,GACCESS,FLAGS) register_command(BOTID, NAME, FUNCTION, PARAMCOUNT, NULL, GACCESS, FLAGS)
+    //            NAME            FUNCTION              PARAMS  ACCS  FLAGS
+    OPER_COMMAND("register",     neonserv_cmd_register,  1,     200,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
+    OPER_COMMAND("unregister",   neonserv_cmd_unregister,1,     200,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
+    OPER_COMMAND("bind",         neonserv_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("unbind",       neonserv_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("say",          neonserv_cmd_say,       2,     600,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
+    OPER_COMMAND("emote",        neonserv_cmd_emote,     2,     600,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
+    OPER_COMMAND("notice",       neonserv_cmd_notice,    2,     600,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
+    OPER_COMMAND("raw",          neonserv_cmd_raw,       1,     800,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("god",          neonserv_cmd_god,       0,     1,    CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    #undef OPER_COMMAND
+    
+    start_bots();
+    
+    //register events
+    bind_bot_ready(dummyserv_bot_ready);
+    
+    set_trigger_callback(BOTID, dummyserv_trigger_callback);
+}
+
+void loop_DummyServ() {
+    
+}
+
+void free_DummyServ() {
+    
+}
+
+#undef BOTID
diff --git a/src/bot_DummyServ.h b/src/bot_DummyServ.h
new file mode 100644 (file)
index 0000000..784016b
--- /dev/null
@@ -0,0 +1,26 @@
+/* bot_DummyServ.h - NeonServ v5.2
+ * 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_DummyServ_h
+#define _bot_DummyServ_h
+
+#include "main.h"
+
+void init_DummyServ();
+void loop_DummyServ();
+void free_DummyServ();
+
+#endif
\ No newline at end of file
index 21d43a06d5f208e22e7ff7eb96378037ad3ba671..b5cba8a18fefa9b213c7f3914df8fa0a9f6d4818 100644 (file)
 
 #include "bot_NeonServ.h"
 #include "bot_NeonSpam.h"
+#include "bot_DummyServ.h"
 
 void init_bots() {
     init_NeonServ();
     init_NeonSpam();
+    init_DummyServ();
     
     MYSQL_RES *res;
     MYSQL_ROW row;
@@ -51,11 +53,13 @@ void init_bots() {
 void loop_bots() {
     loop_NeonServ();
     loop_NeonSpam();
+    loop_DummyServ();
 }
 
 void free_bots() {
     free_NeonServ();
     free_NeonSpam();
+    free_DummyServ();
 }
 
 struct ClientSocket *getChannelBot(struct ChanNode *chan, int botid) {