From: pk910 Date: Sun, 30 Oct 2011 23:05:40 +0000 (+0100) Subject: made bind/unbind command bindings "required" (means: there has to be at least 1 comma... X-Git-Tag: v5.3~235 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=e45eec1545ffeac150e5389bf5dc08e1daeb25e7 made bind/unbind command bindings "required" (means: there has to be at least 1 command bound to this function) --- diff --git a/src/bot_DummyServ.c b/src/bot_DummyServ.c index 88e8461..9e77935 100644 --- a/src/bot_DummyServ.c +++ b/src/bot_DummyServ.c @@ -73,7 +73,6 @@ static void start_bots() { res = mysql_use(); while ((row = mysql_fetch_row(res)) != NULL) { - user = addUser(row[0]); strcpy(user->ident, row[1]); strcpy(user->realname, row[2]); @@ -84,22 +83,24 @@ static void start_bots() { 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]); - } + } + + printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", 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]); } } } + bind_unbound_required_functions(BOTID); } void init_DummyServ() { @@ -114,8 +115,8 @@ void init_DummyServ() { // 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("bind", neonserv_cmd_bind, 2, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED); + OPER_COMMAND("unbind", neonserv_cmd_unbind, 1, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED); 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); diff --git a/src/bot_NeonServ.c b/src/bot_NeonServ.c index 53ad351..97f4f24 100644 --- a/src/bot_NeonServ.c +++ b/src/bot_NeonServ.c @@ -313,6 +313,7 @@ static const struct default_language_entry msgtab[] = { {"NS_RENAME_DONE", "Renamed $b%s$b to $b%s$b."}, {"NS_RENAME_FAIL", "Failed renaming $b%s$b."}, {"NS_FUN_DISABLED", "Fun commands are disabled in %s."}, + {"NS_UNBIND_REQUIRED", "%1$s is a required function and there is no other command bound to %1$s. Bind anothjer command to %1$s first."}, /* {ARGS: bind} */ {NULL, NULL} }; @@ -387,7 +388,6 @@ static void start_bots() { res = mysql_use(); while ((row = mysql_fetch_row(res)) != NULL) { - user = addUser(row[0]); strcpy(user->ident, row[1]); strcpy(user->realname, row[2]); @@ -398,22 +398,24 @@ static void start_bots() { 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]); - } + } + + printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", 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]); } } } + bind_unbound_required_functions(BOTID); } void init_NeonServ() { @@ -488,8 +490,8 @@ void init_NeonServ() { OPER_COMMAND("csuspend", neonserv_cmd_csuspend, 1, 100, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG); OPER_COMMAND("cunsuspend", neonserv_cmd_cunsuspend,1, 100, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG); OPER_COMMAND("move", neonserv_cmd_move, 2, 300, 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("bind", neonserv_cmd_bind, 2, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED); + OPER_COMMAND("unbind", neonserv_cmd_unbind, 1, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED); OPER_COMMAND("oplog", neonserv_cmd_oplog, 0, 1, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG); OPER_COMMAND("search", neonserv_cmd_search, 1, 400, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH); OPER_COMMAND("setaccess", neonserv_cmd_setaccess, 2, 1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG); diff --git a/src/bot_NeonSpam.c b/src/bot_NeonSpam.c index 8463d43..57d9164 100644 --- a/src/bot_NeonSpam.c +++ b/src/bot_NeonSpam.c @@ -126,7 +126,6 @@ static void start_bots() { res = mysql_use(); while ((row = mysql_fetch_row(res)) != NULL) { - user = addUser(row[0]); strcpy(user->ident, row[1]); strcpy(user->realname, row[2]); @@ -137,22 +136,24 @@ static void start_bots() { 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]); - } + } + + printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", 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]); } } } + bind_unbound_required_functions(BOTID); } char* convertNeonSpamSettingsToString(unsigned int flags, char *buffer) { @@ -301,8 +302,8 @@ void init_NeonSpam() { // 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("bind", neonserv_cmd_bind, 2, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED); + OPER_COMMAND("unbind", neonserv_cmd_unbind, 1, 900, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED); OPER_COMMAND("csuspend", neonserv_cmd_csuspend, 1, 100, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG); OPER_COMMAND("cunsuspend", neonserv_cmd_cunsuspend,1, 100, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG); OPER_COMMAND("say", neonserv_cmd_say, 2, 600, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG); diff --git a/src/cmd_neonserv_unbind.c b/src/cmd_neonserv_unbind.c index a14ea46..67153d0 100644 --- a/src/cmd_neonserv_unbind.c +++ b/src/cmd_neonserv_unbind.c @@ -24,12 +24,21 @@ CMD_BIND(neonserv_cmd_unbind) { MYSQL_RES *res; MYSQL_ROW row; - printf_mysql_query("SELECT `id` FROM `bot_binds` WHERE `botclass` = '%d' AND `command` = '%s'", client->botid, escape_string(argv[0])); + printf_mysql_query("SELECT `function` FROM `bot_binds` WHERE `botclass` = '%d' AND `command` = '%s'", client->botid, escape_string(argv[0])); res = mysql_use(); if ((row = mysql_fetch_row(res)) == NULL) { reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]); return; } + struct cmd_function *function = find_cmd_function(client->botid, row[0]); + if(function && (function->flags & CMDFLAG_REQUIRED)) { + printf_mysql_query("SELECT `id` FROM `bot_binds` WHERE `botclass` = '%d' AND `function` = '%s'", client->botid, escape_string(function->name)); + res = mysql_use(); + if (mysql_num_rows(res) <= 1) { + reply(getTextBot(), user, "NS_UNBIND_REQUIRED", function->name); + return; + } + } unbind_cmd(client->botid, argv[0]); printf_mysql_query("DELETE FROM `bot_binds` WHERE `id` = '%s'", row[0]); reply(getTextBot(), user, "NS_UNBIND_DONE", argv[0]); diff --git a/src/modcmd.c b/src/modcmd.c index 301a502..90e46e0 100644 --- a/src/modcmd.c +++ b/src/modcmd.c @@ -701,3 +701,27 @@ struct cmd_binding *find_cmd_binding(int botid, char *cmd) { return NULL; } +void bind_unbound_required_functions(int botid) { + struct cmd_function *cmdfunc; + int i, found; + struct cmd_binding *cbind; + for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) { + if(cmdfunc->botid == botid && (cmdfunc->flags & CMDFLAG_REQUIRED)) { + found = 0; + for(i = 0; i < 27; i++) { + for(cbind = cmd_binds[i]; cbind; cbind = cbind->next) { + if(cbind->botid == botid && cbind->func == cmdfunc) { + found = 1; + break; + } + } + if(found) + break; + } + if(!found) { + bind_cmd_to_function(botid, cmdfunc->name, cmdfunc); + } + } + } +} + diff --git a/src/modcmd.h b/src/modcmd.h index 6d01cbf..4c8da64 100644 --- a/src/modcmd.h +++ b/src/modcmd.h @@ -31,6 +31,7 @@ #define CMDFLAG_LOG 0x0100 #define CMDFLAG_OPLOG 0x0200 #define CMDFLAG_EMPTY_ARGS 0x0400 +#define CMDFLAG_REQUIRED 0x0800 struct ClientSocket; struct UserNode; @@ -88,5 +89,6 @@ void bind_set_parameters(int botid, char *cmd, char *parameters); void bind_set_global_access(int botid, char *cmd, int gaccess); void bind_set_channel_access(int botid, char *cmd, char *chanaccess); struct cmd_binding *find_cmd_binding(int botid, char *cmd); +void bind_unbound_required_functions(int botid); #endif \ No newline at end of file