+static struct cmd_binding *modcmd_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 = strstr(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;
+ } else {
+ //list all sub commands
+ int commandlen = sprintf(command, "%s ", parent_bind->cmd);
+ char subcommands[MAXLEN];
+ int subcompos = 0;
+ for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+ if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmplen(cbind->cmd, command, commandlen) == 0) {
+ if(strstr(cbind->cmd + commandlen, " ")) continue; //ignore if there is another space in the command (sub-sub-command :D)
+ subcompos += sprintf(subcommands + subcompos, (subcompos ? ", %s" : "%s"), cbind->cmd + commandlen);
+ }
+ }
+ reply(textclient, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, (subcompos ? subcommands : "\1dnone\1d"));
+ return NULL;
+ }
+}
+
+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);
+ if(args)
+ args[-1] = ' ';
+ 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;
+ }
+ if(cbind) {
+ *args_ptr = args;
+ if(cbind->func->func == modcmd_linker)
+ parent_bind = modcmd_linker_command(client, textclient, user, cbind, bind_index, args_ptr);
+ else
+ parent_bind = cbind;
+ }
+ }
+ return parent_bind;
+}
+