--- deliantra/server/server/commands.c 2006/02/22 18:03:20 1.1.1.2 +++ deliantra/server/server/commands.c 2006/08/13 17:16:04 1.9 @@ -55,9 +55,6 @@ #ifdef DEBUG {"sstable", command_sstable, 0.0}, #endif -#ifdef DEBUG_MALLOC_LEVEL - {"verify", command_malloc_verify,0.0}, -#endif {"apply", command_apply, 1.0}, /* should be variable */ {"applymode", command_applymode, 1.0}, /* should be variable */ {"archs", command_archs, 0.0}, @@ -81,7 +78,6 @@ {"killpets", command_kill_pets,0.0}, {"listen", command_listen, 0.0}, {"logs", command_logs, 0.0}, - {"malloc", command_malloc, 0.0}, {"maps", command_maps, 0.0}, {"mapinfo", command_mapinfo, 0.0}, {"mark", command_mark, 0.0}, @@ -90,13 +86,12 @@ {"output-count", command_output_count,0.0}, {"peaceful", command_peaceful,0.0}, {"pickup", command_pickup, 1.0}, - {"players", command_players, 0.0}, {"prepare", command_prepare, 1.0}, {"quit", command_quit, 0.0}, + {"quit_character", command_real_quit, 0.0}, {"rename", command_rename_item, 0.0}, {"resistances", command_resistances, 0.0}, {"rotateshoottype", command_rotateshoottype, 0.0}, - {"shutdown", command_shutdown, 0.0}, {"skills", command_skills, 0.0}, /* shows player list of skills */ {"use_skill", command_uskill, 1.0}, {"quests", command_quests, 0.0}, @@ -241,6 +236,11 @@ {"kick", command_kick, 0.0}, {"learn_special_prayer", command_learn_special_prayer, 0.0}, {"learn_spell", command_learn_spell, 0.0}, +#ifdef DEBUG_MALLOC_LEVEL + {"verify", command_malloc_verify,0.0}, +#endif + {"malloc", command_malloc,0.0}, + {"players", command_players, 0.0}, {"plugin",command_loadplugin,0.0}, {"pluglist",command_listplugins,0.0}, {"plugout",command_unloadplugin,0.0}, @@ -251,6 +251,7 @@ {"reset", command_reset,0.0}, {"set_god", command_setgod, 0.0}, {"server_speed", command_speed,0.0}, + {"shutdown", command_shutdown, 0.0}, {"ssdumptable", command_ssdumptable,0.0}, {"stack_clear", command_stack_clear, 0.0 }, {"stack_list", command_stack_list, 0.0}, @@ -354,153 +355,3 @@ return asp->func; return NULL; } - -static CommFunc find_command(char *cmd) -{ - CommArray_s *asp, dummy; - char *cp; - - for (cp=cmd; *cp; cp++) - *cp =tolower(*cp); - - dummy.name =cmd; - asp =(CommArray_s *)bsearch((void *)&dummy, - (void *)Commands, CommandsSize, - sizeof(CommArray_s), compare_A); - LOG(llevDebug, "Getting asp for command string %s\n", cmd); - if (asp) - return asp->func; - else - { - LOG(llevDebug, "Now we are here\n"); - asp =(CommArray_s *)bsearch((void *)&dummy, - (void *)CommunicationCommands, CommunicationCommandSize, - sizeof(CommArray_s), compare_A); - if (asp) - return asp->func; - else - return NULL; - }; -} - -static CommFunc find_wizcommand(char *cmd) -{ - CommArray_s *asp, dummy; - char *cp; - - for (cp=cmd; *cp; cp++) - *cp =tolower(*cp); - - dummy.name =cmd; - asp =(CommArray_s *)bsearch((void *)&dummy, - (void *)WizCommands, WizCommandsSize, - sizeof(CommArray_s), compare_A); - if (asp) - return asp->func; - return NULL; -} - - -/* - * parse_string may be called from a player in the game or from a socket - * (op is NULL if it's a socket). - * It returnes 1 if it recognized the command, otherwise 0. - * Actually return value is used as can-repeat -flag - */ - -int parse_string(object *op, char *str) -{ - CommFunc f; - char *cp; - CommArray_s *asp; - -#ifdef INPUT_DEBUG - LOG(llevDebug, "Command: '%s'\n", str); -#endif - /* - * remove trailing spaces - */ - cp = str+strlen(str)-1; - while ( (cp>=str) && (*cp==' ')){ - *cp='\0'; - cp--; - } - /* - * No arguments? - */ - if (!(cp=strchr(str, ' '))) { - /* GROS - If we are here, then maybe this is a plugin-provided command ? */ - asp = find_plugin_command(str, op); - if (asp) - return asp->func(op, NULL); - - if ((f=find_command(str))) - return f(op, NULL); - if (QUERY_FLAG(op,FLAG_WIZ) && (f=find_wizcommand(str))) - return f(op, NULL); - - if(op) { - new_draw_info(NDI_UNIQUE, 0,op, "Unknown command. Try help."); - } - return 0; - } - - /* - * Command with some arguments - */ - - *(cp++) ='\0'; - /* Clear all spaces from the start of the optional argument */ - while (*cp==' ') cp++; - - asp = find_plugin_command(str,op); - if (asp) return asp->func(op,cp); - - if ((f=find_command(str))) - return f(op, cp); - if (QUERY_FLAG(op, FLAG_WIZ) && (f=find_wizcommand(str))) - return f(op, cp); - - if(op) { - new_draw_info(NDI_UNIQUE, 0,op, "Unknown command. Try help."); - } - return 0; -} - - -/* this function handles splitting up a ; separated - * compound command into sub-commands: it is recursive. - */ -int parse_command(object *op, char *str) { - char *tmp,*tmp2; - int i; - /* if it's a keybinding command, ignore semicolons */ - if(strstr(str,"bind")) return parse_string(op,str); - LOG(llevDebug, "parsin command '%s'\n", str); - /* If on a socket, you can not do complex commands. */ - if(op && (tmp=strchr(str,';'))!=NULL) /* we've found a ';' do the 1st and recurse */ - { - char buf[MAX_BUF]; - /* copy 1st command into buf */ - /* Even if tmp2 points the the input_buf, this should still - * be safe operation. - */ - for(i=0,tmp2=str;tmp2!=tmp;i++,tmp2++) - buf[i]= (*tmp2); - buf[i]='\0'; /* null terminate the copy*/ - strncpy(op->contr->input_buf,tmp2+1, MAX_BUF); - op->contr->input_buf[MAX_BUF-1]=0; - parse_string(op,buf); - } - else { - /* We need to set the input_buf to 0 so clear any complex keybinding - * there might be. However, str can be a pointer to input_buf in - * the case of a complex keybinding. So first we process the command, - * clear the buffer, and then return the value. - */ - i=parse_string(op,str); - if (op) op->contr->input_buf[0]=0; - return i; - } - return 0; -}