-/* modcmd.c - NeonServ v5.5
+/* modcmd.c - NeonServ v5.6
* Copyright (C) 2011-2012 Philipp Kreil (pk910)
*
* This program is free software: you can redistribute it and/or modify
#include "mysqlConn.h"
#include "DBHelper.h"
#include "EventLogger.h"
+#include "tools.h"
+#include "log.h"
struct trigger_callback {
int botid;
triggerStr[0] = '\0';
trigger = malloc(sizeof(*trigger));
if (!trigger) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
trigger->botid = botid;
}
}
+static struct cmd_binding *modcmd_sub_linker_command(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct cmd_binding *cbind, int bind_index, char **args_ptr) {
+ //links subcommands
+ char command[MAXLEN];
+ struct cmd_binding *parent_bind = cbind;
+ char *args = *args_ptr;
+ if(args) {
+ char *subcmd = args;
+ args = strchr(args, ' ');
+ if(args) {
+ *args = '\0';
+ args++;
+ }
+ sprintf(command, "%s %s", parent_bind->cmd, subcmd);
+ for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+ if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmp(cbind->cmd, command) == 0)
+ break;
+ }
+ *args_ptr = args;
+ if(cbind && cbind->func->func == modcmd_linker) {
+ return modcmd_linker_command(client, textclient, user, cbind, bind_index, args_ptr);
+ }
+ return (cbind ? cbind : parent_bind);
+ } else
+ return parent_bind;
+}
+
static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
struct ChanNode *sent_chan = chan;
if(message[0] == '#') {
}
message = strdup(message);
int bind_index = get_binds_index(message[0]);
- char *args = strstr(message, " ");
+ char *args = strchr(message, ' ');
char *args_buffer = NULL; //we need this to save a possible pointer to a allocation we need to free
if(args) {
*args = '\0';
if(cbind->func->func == modcmd_linker) {
cbind = modcmd_linker_command(client, textclient, user, cbind, bind_index, &args);
if(cbind == NULL) break;
- }
- if(statistics_enabled)
- statistics_commands++;
+ } else if(cbind->flags & CMDFLAG_SUB_LINKER)
+ cbind = modcmd_sub_linker_command(client, textclient, user, cbind, bind_index, &args);
+ statistics_commands++;
total_triggered++;
cbind->triggered++;
if((BIND_FLAGS(cbind) & CMDFLAG_FUNCMD)) {
struct command_check_user_cache *data = malloc(sizeof(*data));
char **temp_argv = malloc(argc*sizeof(*temp_argv));
if (!data || !temp_argv) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
break;
}
memcpy(temp_argv, argv, argc*sizeof(*temp_argv));
}
cmdfunc = malloc(sizeof(*cmdfunc));
if (!cmdfunc) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cmdfunc->botid = botid;
if(!cb) {
cb = malloc(sizeof(*cb));
if (!cb) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cb->botid = botid;
}
cbind = malloc(sizeof(*cbind));
if (!cbind) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cbind->botid = botid;
}
cbind = malloc(sizeof(*cbind));
if (!cbind) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cbind->botid = botid;
}
botalias = malloc(sizeof(*botalias));
if (!botalias) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
botalias->botid = botid;