added cmd_bots (lists all bots)
authorpk910 <philipp@zoelle1.de>
Thu, 10 Nov 2011 01:47:18 +0000 (02:47 +0100)
committerpk910 <philipp@zoelle1.de>
Thu, 10 Nov 2011 01:47:18 +0000 (02:47 +0100)
Makefile.am
src/bot_DummyServ.c
src/bot_NeonServ.c
src/bot_NeonSpam.c
src/bots.c
src/bots.h
src/cmd_global.h
src/cmd_global_bots.c [new file with mode: 0644]
src/commands.c

index 00abe9a605a45c79db2b211e073abc88bab19a73..ed81800dbb7cef663d11c5bbe54f52798b1f530b 100644 (file)
@@ -115,6 +115,7 @@ neonserv_SOURCES = src/version.c \
       src/cmd_neonserv_noregister.c \
       src/cmd_global_staff.c \
       src/cmd_global_motd.c \
+      src/cmd_global_bots.c \
       src/cmd_funcmds.c \
       src/ConfigParser.c
 
index 3ebe2676525234972df8918825f385a5c14bad8d..b618045e242f625a0d641569d8f0c5b3ab1e7431 100644 (file)
@@ -39,6 +39,7 @@
 #include "cmd_neonspam.h"
 
 #define BOTID 3
+#define BOTALIAS "DummyServ"
 
 static void dummyserv_bot_ready(struct ClientSocket *client) {
     MYSQL_RES *res;
@@ -105,6 +106,7 @@ static void start_bots() {
 
 void init_DummyServ() {
     
+    set_bot_alias(BOTID, BOTALIAS);
     start_bots();
     
     //register events
@@ -122,3 +124,4 @@ void free_DummyServ() {
 }
 
 #undef BOTID
+#undef BOTALIAS
index a920e8a085129943945582982c90db447f495610..dbf3acb5a04befcd38b08ec91132e19526808b1e 100644 (file)
@@ -36,6 +36,7 @@
 #include "cmd_neonserv.h"
 
 #define BOTID 1
+#define BOTALIAS "NeonServ"
 
 static const struct default_language_entry msgtab[] = {
     {"NS_USER_UNKNOWN", "User with nick $b%s$b does not exist."}, /* {ARGS: "TestUser"} */
@@ -333,6 +334,12 @@ static const struct default_language_entry msgtab[] = {
     {"NS_DNR_EXPIRES", "Expires"},
     {"NS_DNR_REASON", "Reason"},
     {"NS_STAFF_LOGGEDIN", "Logged in as"},
+    {"NS_BOTS_NICK", "Nick"},
+    {"NS_BOTS_SERVER", "Server:Port(:Pass)"},
+    {"NS_BOTS_CLASS", "Bot Class"},
+    {"NS_BOTS_FLAGS", "Flags"},
+    {"NS_BOTS_CHANNELS", "Channels"},
+    {"NS_BOTS_TRIGGER", "Trigger"},
     {NULL, NULL}
 };
 
@@ -439,6 +446,7 @@ static void start_bots() {
 
 void init_NeonServ() {
     
+    set_bot_alias(BOTID, BOTALIAS);
     start_bots();
     
     //register events
@@ -468,3 +476,4 @@ void free_NeonServ() {
 }
 
 #undef BOTID
+#undef BOTALIAS
index a0df1ea24a4e03b6e9593241edb15d67ec6bfffe..050bc107799b35b42bc795bb411ae15b3e1c0b07 100644 (file)
@@ -39,6 +39,7 @@
 #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)"}, /* {ARGS: 120} */
@@ -291,6 +292,7 @@ static void createSpamNode(struct ChanUser *chanuser) {
 
 void init_NeonSpam() {
     
+    set_bot_alias(BOTID, BOTALIAS);
     start_bots();
     
     //register events
@@ -313,3 +315,4 @@ void free_NeonSpam() {
 }
 
 #undef BOTID
+#undef BOTALIAS
index b5cba8a18fefa9b213c7f3914df8fa0a9f6d4818..6a4ef848f458d086f49bcedc7b6559f74747ff04 100644 (file)
 #include "bot_NeonSpam.h"
 #include "bot_DummyServ.h"
 
+struct cmd_bot_alias {
+    int botid;
+    char *alias;
+    struct cmd_bot_alias *next;
+};
+
+static struct cmd_bot_alias *bot_aliases = NULL;
+
 void init_bots() {
     init_NeonServ();
     init_NeonSpam();
@@ -138,3 +146,45 @@ static int general_ctcp(char *buffer, char *command, char *text) {
     }
     return 0;
 }
+
+void set_bot_alias(int botid, char *alias) {
+    struct cmd_bot_alias *botalias, *existing_alias = NULL;
+    for(botalias = bot_aliases; botalias; botalias = botalias->next) {
+        if(!stricmp(botalias->alias, alias))
+            return;
+        if(botalias->botid == botid)
+            existing_alias = botalias;
+    }
+    if(existing_alias) {
+        free(existing_alias->alias);
+        existing_alias->alias = strdup(alias);
+        return;
+    }
+    botalias = malloc(sizeof(*botalias));
+    if (!botalias) {
+        perror("malloc() failed");
+        return;
+    }
+    botalias->botid = botid;
+    botalias->alias = strdup(alias);
+    botalias->next = bot_aliases;
+    bot_aliases = botalias;
+}
+
+const char *resolve_botid(int botid) {
+    struct cmd_bot_alias *botalias;
+    for(botalias = bot_aliases; botalias; botalias = botalias->next) {
+        if(botalias->botid == botid)
+            return botalias->alias;
+    }
+    return NULL;
+}
+
+int resolve_botalias(const char *alias) {
+    struct cmd_bot_alias *botalias;
+    for(botalias = bot_aliases; botalias; botalias = botalias->next) {
+        if(!stricmp(botalias->alias, alias))
+            return botalias->botid;
+    }
+    return 0;
+}
index 22683d876356240bf909bde7b547e7313ebdbbe0..0fead874c7c78dfaaa0504983c9d57f79025a306 100644 (file)
@@ -31,5 +31,8 @@ void free_bots();
 struct ClientSocket *getChannelBot(struct ChanNode *chan, int botid);
 TIMEQ_CALLBACK(channel_ban_timeout);
 void general_event_privctcp(struct UserNode *user, struct UserNode *target, char *command, char *text);
+void set_bot_alias(int botid, char *alias);
+const char *resolve_botid(int botid);
+int resolve_botalias(const char *alias);
 
 #endif
\ No newline at end of file
index c643820207d8790c8b831a35ba4d2a346c254c62..b4aaa05f9d1dd594a334eb1cd79b6a4ae4e44641 100644 (file)
@@ -38,6 +38,7 @@
 #include "bots.h"
 
 CMD_BIND(global_cmd_bind);
+CMD_BIND(global_cmd_bots);
 CMD_BIND(global_cmd_command);
 CMD_BIND(global_cmd_commands);
 CMD_BIND(global_cmd_emote);
diff --git a/src/cmd_global_bots.c b/src/cmd_global_bots.c
new file mode 100644 (file)
index 0000000..d2916c8
--- /dev/null
@@ -0,0 +1,68 @@
+/* cmd_global_bots.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]    (optional) class name
+*/
+
+CMD_BIND(global_cmd_bots) {
+    struct Table *table;
+    MYSQL_RES *res, *res2;
+    MYSQL_ROW row, row2;
+    printf_mysql_query("SELECT `active`, `nick`, `server`, `port`, `pass`, `botclass`, `textbot`, `queue`, `defaulttrigger`, `max_channels`, `register_priority`, `id` FROM `bots`");
+    res = mysql_use();
+    table = table_init(6, mysql_num_rows(res) + 1, 0);
+    char *content[5];
+    content[0] = get_language_string(user, "NS_BOTS_NICK");
+    content[1] = get_language_string(user, "NS_BOTS_SERVER");
+    content[2] = get_language_string(user, "NS_BOTS_CLASS");
+    content[3] = get_language_string(user, "NS_BOTS_FLAGS");
+    content[4] = get_language_string(user, "NS_BOTS_CHANNELS");
+    content[5] = get_language_string(user, "NS_BOTS_TRIGGER");
+    table_add(table, content);
+    char botnick[NICKLEN + 3];
+    char botserver[MAXLEN];
+    char botflags[10];
+    int flagspos;
+    char botchans[20];
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        sprintf(botnick, (strcmp(row[0], "0") ? "%s" : "\00315%s\003"), row[1]);
+        contents[0] = botnick;
+        sprintf(botserver, (strcmp(row[4], "") ? "%s:%s:*" : "%s:%s"), row[2], row[3]);
+        contents[1] = botserver;
+        contents[2] = resolve_botid(atoi(row[5]));
+        flagspos = 0;
+        if(!strcmp(row[6], "1"))
+            botflags[flagspos++] = 't';
+        if(!strcmp(row[7], "1"))
+            botflags[flagspos++] = 'q';
+        botflags[flagspos] = '\0';
+        contents[3] = botflags;
+        printf_mysql_query("SELECT COUNT(*) FROM `bot_channels` WHERE `botid` = '%s'", row[11]);
+        res2 = mysql_use();
+        row2 = mysql_fetch_row(res2);
+        sprintf(botchans, "%s/%s", row2[0], row[9]);
+        contents[4] = botchans;
+        contents[5] = row[8];
+    }
+    char **table_lines = table_end(table);
+    for(i = 0; i < table->entrys; i++) {
+        reply(getTextBot(), user, table_lines[i]);
+    }
+}
\ No newline at end of file
index 08942fbad85d72f7173f67f5b834ecdb5a346a22..07adfac104709cdb19973c49ed2d607ce891ad0b 100644 (file)
@@ -47,6 +47,7 @@ void register_commands() {
     OPER_COMMAND("bind",         global_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
     OPER_COMMAND("unbind",       global_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
     OPER_COMMAND("setaccess",    global_cmd_setaccess, 2,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("bots",         global_cmd_bots,      0,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     #undef OPER_COMMAND
     
     //NeonServ Commands