added cmd_addbot and cmd_delbot for dynamic bot management
authorpk910 <philipp@zoelle1.de>
Thu, 22 Dec 2011 00:01:01 +0000 (01:01 +0100)
committerpk910 <philipp@zoelle1.de>
Thu, 22 Dec 2011 00:04:04 +0000 (01:04 +0100)
Makefile.am
src/bot_NeonServ.c
src/cmd_global.h
src/cmd_global_addbot.c [new file with mode: 0644]
src/cmd_global_delbot.c [new file with mode: 0644]
src/commands.c

index 094eb2c004a2db963e29e1b5195a443dece50eb5..40af57ee77c353a592f926d159b40ed8cf379f6d 100644 (file)
@@ -121,6 +121,8 @@ neonserv_SOURCES = src/version.c \
       src/cmd_global_die.c \
       src/cmd_neonserv_nicklist.c \
       src/cmd_global_setbot.c \
+      src/cmd_global_addbot.c \
+      src/cmd_global_delbot.c \
       src/cmd_funcmds.c \
       src/ConfigParser.c
 
index a55e9addd6facb7e0dbcdb2d85e04fb474bfcd61..0421fdd6754010e683f04abfac4b80eab3d38b2c 100644 (file)
@@ -356,6 +356,10 @@ static const struct default_language_entry msgtab[] = {
     {"NS_SETBOT_PRIORITY_INVALID", "`%s` is an invalid priority value."}, /* {ARGS: "-1"} */
     {"NS_SETBOT_TRIGGER_INVALID", "`%s` is an invalid bot trigger."}, /* {ARGS: "tooLongTrigger"} */
     {"NS_SETBOT_TRIGGER_NOTE", "Please note: This Setting will only affect new channels."},
+    {"NS_ADDBOT_EXISTING", "A bot with nick %s does already exist."}, /* {ARGS: "NeonServ"} */
+    {"NS_ADDBOT_DONE", "Added %s with BotID $b%d$b."}, /* {ARGS: "NeonServ", 2} */
+    {"NS_DELBOT_NOT_FOUND", "Bot with BotID / nick $b%s$b not found."}, /* {ARGS: "NeonServ"} */
+    {"NS_DELBOT_DONE", "Bot deleted."},
     {NULL, NULL}
 };
 
index aa5a67d848928180dce40d11ee1b37493cb2432e..98dc94ef4c85b4c8f2cfb86b57aff16720f80c84 100644 (file)
 #include "EventLogger.h"
 #include "bots.h"
 
+CMD_BIND(global_cmd_addbot);
 CMD_BIND(global_cmd_bind);
 CMD_BIND(global_cmd_bots);
 CMD_BIND(global_cmd_command);
 CMD_BIND(global_cmd_commands);
+CMD_BIND(global_cmd_delbot);
 CMD_BIND(global_cmd_die);
 CMD_BIND(global_cmd_emote);
 CMD_BIND(global_cmd_god);
diff --git a/src/cmd_global_addbot.c b/src/cmd_global_addbot.c
new file mode 100644 (file)
index 0000000..3c12865
--- /dev/null
@@ -0,0 +1,43 @@
+/* cmd_global_addbot.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 "cmd_global.h"
+
+/*
+* argv[0]  nick
+* argv[1]  class
+*/
+
+CMD_BIND(global_cmd_addbot) {
+    MYSQL_RES *res;
+    int botid;
+    if((botid = resolve_botalias(argv[1])) != -1) {
+        reply(getTextBot(), user, "NS_SETBOT_INVALID_CLASS", argv[1]);
+        return;
+    }
+    printf_mysql_query("SELECT `id` FROM `bots` WHERE `nick` = '%s'", escape_string(argv[0]));
+    res = mysql_use();
+    if(mysql_fetch_row(res)) {
+        reply(getTextBot(), user, "NS_ADDBOT_EXISTING", argv[0]);
+        return;
+    }
+    printf_mysql_query("INSERT INTO `bots` (`nick`, `botclass`) VALUES ('%s', '%d')", escape_string(argv[0]), botid);
+    botid = (int) mysql_insert_id(mysql_conn);
+    reply(getTextBot(), user, "NS_ADDBOT_DONE", argv[0], botid);
+    logEvent(event);
+}
+
diff --git a/src/cmd_global_delbot.c b/src/cmd_global_delbot.c
new file mode 100644 (file)
index 0000000..1a37dd4
--- /dev/null
@@ -0,0 +1,43 @@
+/* cmd_global_delbot.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 "cmd_global.h"
+
+/*
+* argv[0]  nick/botid
+*/
+
+CMD_BIND(global_cmd_delbot) {
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    printf_mysql_query("SELECT `id` FROM `bots` WHERE `nick` = '%s' OR `id` = '%s'", escape_string(argv[0]), escape_string(argv[0]));
+    res = mysql_use();
+    if((row = mysql_fetch_row(res)) == NULL) {
+        reply(getTextBot(), user, "NS_DELBOT_NOT_FOUND", argv[0]);
+        return;
+    }
+    int botid = atoi(row[0]);
+    printf_mysql_query("DELETE FROM `bots` WHERE `id` = '%s'", row[0]);
+    for(client = getBots(0, NULL); client; client = getBots(0, client)) {
+        if(client->clientid == botid) {
+            close_socket(client);
+            break;
+        }
+    }
+    reply(getTextBot(), user, "NS_DELBOT_DONE");
+    logEvent(event);
+}
index 6d598180b2aa5e50f4989803f5f9f5899797d003..7963b070f3aa343e5cba203634afd11ed07c2bb5 100644 (file)
@@ -52,6 +52,8 @@ void register_commands() {
     OPER_COMMAND("restart",      global_cmd_restart,   0,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
     OPER_COMMAND("die",          global_cmd_die,       0,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
     OPER_COMMAND("setbot",       global_cmd_setbot,    1,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
+    OPER_COMMAND("addbot",       global_cmd_addbot,    2,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
+    OPER_COMMAND("delbot",       global_cmd_delbot,    1,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
     #undef OPER_COMMAND
     
     //NeonServ Commands