From: pk910 Date: Thu, 10 Nov 2011 01:47:18 +0000 (+0100) Subject: added cmd_bots (lists all bots) X-Git-Tag: v5.3~187 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=e99916c59372e6338a83d7bb866cbab63ccd2106 added cmd_bots (lists all bots) --- diff --git a/Makefile.am b/Makefile.am index 00abe9a..ed81800 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/bot_DummyServ.c b/src/bot_DummyServ.c index 3ebe267..b618045 100644 --- a/src/bot_DummyServ.c +++ b/src/bot_DummyServ.c @@ -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 diff --git a/src/bot_NeonServ.c b/src/bot_NeonServ.c index a920e8a..dbf3acb 100644 --- a/src/bot_NeonServ.c +++ b/src/bot_NeonServ.c @@ -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 diff --git a/src/bot_NeonSpam.c b/src/bot_NeonSpam.c index a0df1ea..050bc10 100644 --- a/src/bot_NeonSpam.c +++ b/src/bot_NeonSpam.c @@ -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 diff --git a/src/bots.c b/src/bots.c index b5cba8a..6a4ef84 100644 --- a/src/bots.c +++ b/src/bots.c @@ -28,6 +28,14 @@ #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; +} diff --git a/src/bots.h b/src/bots.h index 22683d8..0fead87 100644 --- a/src/bots.h +++ b/src/bots.h @@ -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 diff --git a/src/cmd_global.h b/src/cmd_global.h index c643820..b4aaa05 100644 --- a/src/cmd_global.h +++ b/src/cmd_global.h @@ -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 index 0000000..d2916c8 --- /dev/null +++ b/src/cmd_global_bots.c @@ -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 . + */ + +#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 diff --git a/src/commands.c b/src/commands.c index 08942fb..07adfac 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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