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
#include "cmd_neonspam.h"
#define BOTID 3
+#define BOTALIAS "DummyServ"
static void dummyserv_bot_ready(struct ClientSocket *client) {
MYSQL_RES *res;
void init_DummyServ() {
+ set_bot_alias(BOTID, BOTALIAS);
start_bots();
//register events
}
#undef BOTID
+#undef BOTALIAS
#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"} */
{"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}
};
void init_NeonServ() {
+ set_bot_alias(BOTID, BOTALIAS);
start_bots();
//register events
}
#undef BOTID
+#undef BOTALIAS
#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} */
void init_NeonSpam() {
+ set_bot_alias(BOTID, BOTALIAS);
start_bots();
//register events
}
#undef BOTID
+#undef BOTALIAS
#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();
}
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;
+}
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
#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);
--- /dev/null
+/* 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
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