{"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}
};
#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"
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();
--- /dev/null
+
+/*
+* 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);
+}
--- /dev/null
+
+/*
+* 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);
+}
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;
}
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);