{"NS_EVENTS_HEADER", "The following channel events were found:"},
{"NS_OPLOG_HEADER", "The following oper events were found:"},
{"NS_SEARCH_HEADER", "The following channels were found:"},
+ {"NS_COMMAND_BINDING", "$b%s$b is a binding of %s %s"}, /* {ARGS: "TestCommand", "TestFunction", "TestParameters"} */
+ {"NS_COMMAND_ACCESS", "You need at least %d channel access and %d oper access to execute this command."}, /* {ARGS: 500, 100} */
{NULL, NULL}
};
#include "cmd_neonserv_version.c"
#include "cmd_neonserv_chanservsync.c"
#include "cmd_neonserv_events.c"
+#include "cmd_neonserv_command.c"
//OPER CMD's
#include "cmd_neonserv_bind.c"
USER_COMMAND("inviteme", neonserv_cmd_inviteme, 0, "#channel_getinvite", CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_LOG);
USER_COMMAND("help", neonserv_cmd_help, 0, NULL, 0);
USER_COMMAND("events", neonserv_cmd_events, 0, "1", CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+ USER_COMMAND("command", neonserv_cmd_command, 1, NULL, 0);
#undef USER_COMMAND
#define OPER_COMMAND(NAME,FUNCTION,PARAMCOUNT,GACCESS,FLAGS) register_command(BOTID, NAME, FUNCTION, PARAMCOUNT, NULL, GACCESS, FLAGS)
--- /dev/null
+
+/*
+* argv[0-1] command
+*/
+static int neonserv_cmd_command_chanaccess(struct cmd_binding *cbind, struct ChanNode *chan);
+static int neonserv_cmd_command_operaccess(struct cmd_binding *cbind);
+
+static CMD_BIND(neonserv_cmd_command) {
+ char *ident;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ struct cmd_binding *cbind = find_cmd_binding(client->botid, argv[0]);
+ if (!cbind) {
+ reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]);
+ return;
+ }
+ ident = argv[0];
+ reply(getTextBot(), user, "NS_COMMAND_BINDING", cbind->cmd, cbind->func->name, (cbind->parameters ? cbind->parameters : ""));
+ if(chan)
+ reply(getTextBot(), user, "NS_COMMAND_ACCESS", neonserv_cmd_command_chanaccess(cbind, chan), neonserv_cmd_command_operaccess(cbind));
+ printf_mysql_query("SELECT `user_lang` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
+ res = mysql_use();
+ char *lang;
+ if ((row = mysql_fetch_row(res)) != NULL)
+ lang = row[0];
+ else
+ lang = "en";
+ printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = '%s' AND `ident` = '%s'", escape_string(lang), escape_string(ident));
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) == NULL) {
+ if(stricmp(lang, "en")) {
+ printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = 'en' AND `ident` = '%s'", escape_string(ident));
+ res = mysql_use();
+ }
+ if ((row = mysql_fetch_row(res)) == NULL) {
+ printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = '%s' AND `ident` = '%s'", escape_string(lang), escape_string(cbind->func->name));
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) == NULL) {
+ if(stricmp(lang, "en")) {
+ printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = 'en' AND `ident` = '%s'", escape_string(cbind->func->name));
+ res = mysql_use();
+ }
+ if ((row = mysql_fetch_row(res)) == NULL) {
+ return;
+ }
+ }
+ }
+ }
+ char sendBuf[MAXLEN];
+ int sendBufPos = 0;
+ int i;
+ for(i = 0; i < strlen(row[0]); i++) {
+ switch(row[0][i]) {
+ case '\n':
+ if(sendBufPos) {
+ sendBuf[sendBufPos] = '\0';
+ reply(getTextBot(), user, "%s", sendBuf);
+ sendBufPos = 0;
+ }
+ break;
+ case '$':
+ switch(row[0][i+1]) {
+ case 'b':
+ sendBuf[sendBufPos++] = '\002';
+ i++;
+ break;
+ case 'k':
+ sendBuf[sendBufPos++] = '\003';
+ i++;
+ break;
+ case 'u':
+ sendBuf[sendBufPos++] = '\031';
+ i++;
+ break;
+ case 'C':
+ case 'S':
+ sendBufPos += sprintf(sendBuf + sendBufPos, "%s", client->user->nick);
+ i++;
+ break;
+ default:
+ sendBuf[sendBufPos++] = '$';
+ break;
+ }
+ break;
+ default:
+ sendBuf[sendBufPos++] = row[0][i];
+ break;
+ }
+ }
+ if(sendBufPos) {
+ sendBuf[sendBufPos] = '\0';
+ reply(getTextBot(), user, "%s", sendBuf);
+ sendBufPos = 0;
+ }
+}
+
+static int neonserv_cmd_command_chanaccess(struct cmd_binding *cbind, struct ChanNode *chan) {
+ char access_list[256];
+ int access_pos = 0;
+ int access_count = 0;
+ int minaccess = 0;
+ char *str_a, *str_b = cbind->func->channel_access, *str_c;
+ if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
+ str_b = cbind->channel_access;
+ access_list[0] = '\0';
+ if(str_b) {
+ str_c = strdup(str_b);
+ str_b = str_c;
+ while((str_a = str_b)) {
+ str_b = strstr(str_a, ",");
+ if(str_b) {
+ *str_b = '\0';
+ str_b++;
+ }
+ if(*str_a == '#') {
+ str_a++;
+ access_pos += sprintf(access_list+access_pos, (access_pos ? ", `%s`" : "`%s`"), str_a);
+ access_count++;
+ } else {
+ if(atoi(str_a) > minaccess)
+ minaccess = atoi(str_a);
+ }
+ }
+ free(str_c);
+ }
+ if(access_count) {
+ MYSQL_RES *res;
+ MYSQL_ROW row, defaults = NULL;
+ printf_mysql_query("SELECT %s FROM `channels` WHERE `channel_name` = '%s'", access_list, escape_string(chan->name));
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) != NULL) {
+ int i, caccess;
+ for(i = 0; i < access_count; i++) {
+ if(!row[i] && !defaults) {
+ printf_mysql_query("SELECT %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
+ defaults = mysql_fetch_row(mysql_use());
+ }
+ caccess = (row[i] ? atoi(row[i]) : atoi(defaults[i]));
+ if(caccess > minaccess)
+ minaccess = caccess;
+ }
+ }
+ }
+ return minaccess;
+}
+
+static int neonserv_cmd_command_operaccess(struct cmd_binding *cbind) {
+ return ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);
+}
//helpers :D
reply(getTextBot(), user, "special thanks to:");
reply(getTextBot(), user, " Zer0n, TeaTow (testing and ideas current version)");
+ reply(getTextBot(), user, " Buchman, Zer0n (translating current version)");
reply(getTextBot(), user, " Patschi95, DerGrinch, Darkfly, Zer0n, Buschman (testing and ideas older versions)");
reply(getTextBot(), user, " Buschman, Georg, richard (translating older versions)");
reply(getTextBot(), user, "and all the other users that reported all these nasty bugs :D");