From: pk910 Date: Thu, 22 Sep 2011 20:12:18 +0000 (+0200) Subject: added cmd_bind & cmd_unbind X-Git-Tag: v5.3~377 X-Git-Url: http://git.pk910.de/?a=commitdiff_plain;h=291a2bac6013a6e5c54983016c0b060d68329126;p=NeonServV5.git added cmd_bind & cmd_unbind --- diff --git a/bot_NeonServ.c b/bot_NeonServ.c index 393f8f5..046fccc 100644 --- a/bot_NeonServ.c +++ b/bot_NeonServ.c @@ -210,6 +210,11 @@ static const struct default_language_entry msgtab[] = { {"NS_MOVE_SUSPENDED", "Moving cannot be performed if the source channel is suspended."}, {"NS_MOVE_SELF", "Moving cannot be performed if the source and target channels are the same."}, {"NS_MOVE_DONE", "Channel $b%s$b has been moved to $b%s$b."}, /* {ARGS: "#TestChan", "#NewTestChan"} */ + {"NS_BIND_ALREADY", "$b%s$b is already bound to %s."}, /* {ARGS: "TestCommand", "TestFunction"} */ + {"NS_BIND_UNKNOWN", "$b%s$b is an undefined function."}, /* {ARGS: "TestFunction"} */ + {"NS_BIND_DONE", "New command $b%s$b bound to %s."}, /* {ARGS: "TestCommand", "TestFunction"} */ + {"NS_UNBIND_NOT_FOUND", "There is no command called $b%s$b bound."}, /* {ARGS: "TestCommand"} */ + {"NS_UNBIND_DONE", "Unbound command $b%s$b."}, /* {ARGS: "TestCommand"} */ {NULL, NULL} }; @@ -273,8 +278,8 @@ INCLUDE ALL CMD's HERE #include "cmd_neonserv_chanservsync.c" //OPER CMD's -//#include "cmd_neonserv_bind.c" -//#include "cmd_neonserv_unbind.c" +#include "cmd_neonserv_bind.c" +#include "cmd_neonserv_unbind.c" //#include "cmd_neonserv_modcmd.c" #include "cmd_neonserv_register.c" #include "cmd_neonserv_unregister.c" @@ -485,6 +490,8 @@ void init_NeonServ() { register_command(BOTID, "csuspend", neonserv_cmd_csuspend, 1, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG, NULL, 100); register_command(BOTID, "cunsuspend", neonserv_cmd_cunsuspend,1, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG, NULL, 100); register_command(BOTID, "move", neonserv_cmd_move, 2, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG, NULL, 300); + register_command(BOTID, "bind", neonserv_cmd_bind, 2, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG, NULL, 900); + register_command(BOTID, "unbind", neonserv_cmd_unbind, 1, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG, NULL, 900); start_bots(); diff --git a/cmd_neonserv_bind.c b/cmd_neonserv_bind.c new file mode 100644 index 0000000..35b4d12 --- /dev/null +++ b/cmd_neonserv_bind.c @@ -0,0 +1,33 @@ + +/* +* argv[0] command name +* argv[1] command function +* argv[2-*] parameters (optional) +*/ + +static CMD_BIND(neonserv_cmd_bind) { + MYSQL_RES *res; + MYSQL_ROW row; + 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_BIND_ALREADY", argv[0], row[0]); + return; + } + char *params; + if(argc > 2) + params = merge_argv(argv, 2, argc); + else + params = ""; + struct cmd_function *function = find_cmd_function(client->botid, argv[1]); + if(!function) { + reply(getTextBot(), user, "NS_BIND_UNKNOWN", argv[1]); + return; + } + bind_cmd_to_function(client->botid, argv[0], function); + if(*params) + bind_set_parameters(client->botid, argv[0], params); + printf_mysql_query("INSERT INTO `bot_binds` (`botclass`, `command`, `function`, `parameters`) VALUES ('%d', '%s', '%s', '%s')", client->botid, escape_string(argv[0]), escape_string(function->name), params); + reply(getTextBot(), user, "NS_BIND_DONE", argv[0], function->name); + logEvent(event); +} diff --git a/cmd_neonserv_unbind.c b/cmd_neonserv_unbind.c new file mode 100644 index 0000000..db91274 --- /dev/null +++ b/cmd_neonserv_unbind.c @@ -0,0 +1,19 @@ + +/* +* argv[0] command name +*/ + +static 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])); + res = mysql_use(); + if ((row = mysql_fetch_row(res)) == NULL) { + reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]); + 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]); + logEvent(event); +} diff --git a/modcmd.c b/modcmd.c index 31ea320..7b5f65e 100644 --- a/modcmd.c +++ b/modcmd.c @@ -521,6 +521,15 @@ int unbind_cmd(int botid, char *cmd) { return 0; } +struct cmd_function *find_cmd_function(int botid, char *name) { + struct cmd_function *cmdfunc; + for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) { + if(cmdfunc->botid == botid && stricmp(cmdfunc->name, name) == 0) + break; + } + return cmdfunc; +} + struct ClientSocket *getTextBot() { return tmp_text_client; } diff --git a/modcmd.h b/modcmd.h index 4b5218c..3678131 100644 --- a/modcmd.h +++ b/modcmd.h @@ -62,6 +62,7 @@ int changeChannelTrigger(int botid, struct ChanNode *chan, char *new_trigger); int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func); int bind_cmd_to_command(int botid, char *cmd, char *func); int unbind_cmd(int botid, char *cmd); +struct cmd_function *find_cmd_function(int botid, char *name); struct ClientSocket *getTextBot(); void bind_set_parameters(int botid, char *cmd, char *parameters); void bind_set_global_access(int botid, char *cmd, int gaccess);