From a2c45a8db6d724b98ab41fe9e75e1f7ea7523d5d Mon Sep 17 00:00:00 2001 From: shennetsind Date: Thu, 2 May 2013 17:14:01 -0300 Subject: Introducing Hercules Plugin Mananger http://hercules.ws/board/topic/549-introducing-hercules-plugin-manager/ Signed-off-by: shennetsind --- src/common/console.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 222 insertions(+), 1 deletion(-) (limited to 'src/common/console.c') diff --git a/src/common/console.c b/src/common/console.c index 67897ee81..db914db98 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -8,6 +8,8 @@ #include "console.h" #ifndef MINICORE + #include "../common/ers.h" + #include "../common/malloc.h" #include "../common/atomic.h" #include "../common/spinlock.h" #include "../common/thread.h" @@ -77,7 +79,212 @@ int console_parse_key_pressed(void) { return FD_ISSET(STDIN_FILENO, &fds); } #endif /* _WIN32 */ +CPCMD(exit) { + runflag = 0; +} +CPCMD(ers_report) { + ers_report(); +} +CPCMD(help) { + unsigned int i = 0; + for ( i = 0; i < console->cmd_list_count; i++ ) { + if( console->cmd_list[i]->next_count ) { + ShowInfo("- '"CL_WHITE"%s"CL_RESET"' subs\n",console->cmd_list[i]->cmd); + console->parse_list_subs(console->cmd_list[i],2); + } else { + ShowInfo("- '"CL_WHITE"%s"CL_RESET"'\n",console->cmd_list[i]->cmd); + } + } +} +/* [Ind/Hercules] */ +CPCMD(malloc_usage) { + unsigned int val = (unsigned int)malloc_usage(); + ShowInfo("malloc_usage: %.2f MB\n",(double)(val)/1024); +} +#define CP_DEF_C(x) { #x , NULL , NULL, NULL } +#define CP_DEF_C2(x,y) { #x , NULL , #y, NULL } +#define CP_DEF_S(x,y) { #x , console_parse_ ## x , #y, NULL } +#define CP_DEF(x) { #x , console_parse_ ## x , NULL, NULL } +void console_load_defaults(void) { + struct { + char *name; + CParseFunc func; + char *connect; + struct CParseEntry *self; + } default_list[] = { + CP_DEF(help), + CP_DEF_C(server), + CP_DEF_S(ers_report,server), + CP_DEF_S(malloc_usage,server), + CP_DEF_S(exit,server), + }; + unsigned int i, len = ARRAYLENGTH(default_list); + struct CParseEntry *cmd; + + RECREATE(console->cmds,struct CParseEntry *, len); + + for(i = 0; i < len; i++) { + CREATE(cmd, struct CParseEntry, 1); + + safestrncpy(cmd->cmd, default_list[i].name, CP_CMD_LENGTH); + + if( default_list[i].func ) + cmd->u.func = default_list[i].func; + else + cmd->u.next = NULL; + + cmd->next_count = 0; + + console->cmd_count++; + console->cmds[i] = cmd; + default_list[i].self = cmd; + if( !default_list[i].connect ) { + RECREATE(console->cmd_list,struct CParseEntry *, ++console->cmd_list_count); + console->cmd_list[console->cmd_list_count - 1] = cmd; + } + } + + for(i = 0; i < len; i++) { + unsigned int k; + if( !default_list[i].connect ) + continue; + for(k = 0; k < console->cmd_count; k++) { + if( strcmpi(default_list[i].connect,console->cmds[k]->cmd) == 0 ) { + cmd = default_list[i].self; + RECREATE(console->cmds[k]->u.next, struct CParseEntry *, ++console->cmds[k]->next_count); + console->cmds[k]->u.next[console->cmds[k]->next_count - 1] = cmd; + break; + } + } + } +} +void console_parse_create(char *name, CParseFunc func) { + unsigned int i; + char *tok; + char sublist[CP_CMD_LENGTH * 5]; + struct CParseEntry *cmd; + + safestrncpy(sublist, name, CP_CMD_LENGTH * 5); + tok = strtok(sublist,":"); + + for ( i = 0; i < console->cmd_list_count; i++ ) { + if( strcmpi(tok,console->cmd_list[i]->cmd) == 0 ) + break; + } + if( i == console->cmd_list_count ) { + RECREATE(console->cmds,struct CParseEntry *, ++console->cmd_count); + CREATE(cmd, struct CParseEntry, 1); + safestrncpy(cmd->cmd, tok, CP_CMD_LENGTH); + cmd->next_count = 0; + console->cmds[console->cmd_count - 1] = cmd; + RECREATE(console->cmd_list,struct CParseEntry *, ++console->cmd_list_count); + console->cmd_list[console->cmd_list_count - 1] = cmd; + i = console->cmd_list_count - 1; + } + + cmd = console->cmd_list[i]; + while( ( tok = strtok(NULL, ":") ) != NULL ) { + + for(i = 0; i < cmd->next_count; i++) { + if( strcmpi(cmd->u.next[i]->cmd,tok) == 0 ) + break; + } + + if ( i == cmd->next_count ) { + RECREATE(console->cmds,struct CParseEntry *, ++console->cmd_count); + CREATE(console->cmds[console->cmd_count-1], struct CParseEntry, 1); + safestrncpy(console->cmds[console->cmd_count-1]->cmd, tok, CP_CMD_LENGTH); + console->cmds[console->cmd_count-1]->next_count = 0; + RECREATE(cmd->u.next, struct CParseEntry *, ++cmd->next_count); + cmd->u.next[cmd->next_count - 1] = console->cmds[console->cmd_count-1]; + cmd = console->cmds[console->cmd_count-1]; + continue; + } + + } + cmd->u.func = func; +} +void console_parse_list_subs(struct CParseEntry *cmd, unsigned char depth) { + unsigned int i; + char msg[CP_CMD_LENGTH * 2]; + for( i = 0; i < cmd->next_count; i++ ) { + if( cmd->u.next[i]->next_count ) { + memset(msg, '-', depth); + snprintf(msg + depth,CP_CMD_LENGTH * 2, " '"CL_WHITE"%s"CL_RESET"'",cmd->u.next[i]->cmd); + ShowInfo("%s subs\n",msg); + console->parse_list_subs(cmd->u.next[i],depth + 1); + } else { + memset(msg, '-', depth); + snprintf(msg + depth,CP_CMD_LENGTH * 2, " %s",cmd->u.next[i]->cmd); + ShowInfo("%s\n",msg); + } + } +} +void console_parse_sub(char *line) { + struct CParseEntry *cmd; + char bline[200]; + char *tok; + char sublist[CP_CMD_LENGTH * 5]; + unsigned int i, len = 0; + memcpy(bline, line, 200); + tok = strtok(line, " "); + for ( i = 0; i < console->cmd_list_count; i++ ) { + if( strcmpi(tok,console->cmd_list[i]->cmd) == 0 ) + break; + } + + if( i == console->cmd_list_count ) { + ShowError("'"CL_WHITE"%s"CL_RESET"' is not a known command, type '"CL_WHITE"help"CL_RESET"' to list all commands\n",line); + return; + } + + cmd = console->cmd_list[i]; + + len += snprintf(sublist,CP_CMD_LENGTH * 5,"%s", cmd->cmd) + 1; + + if( cmd->next_count == 0 && console->cmd_list[i]->u.func ) { + char *r = NULL; + if( (tok = strtok(NULL, " ")) ) { + r = bline; + r += len + 1; + } + cmd->u.func(r); + } else { + while( ( tok = strtok(NULL, " ") ) != NULL ) { + for( i = 0; i < cmd->next_count; i++ ) { + if( strcmpi(cmd->u.next[i]->cmd,tok) == 0 ) + break; + } + if( i == cmd->next_count ) { + if( strcmpi("help",tok) == 0 ) { + if( cmd->next_count ) { + ShowInfo("- '"CL_WHITE"%s"CL_RESET"' subs\n",sublist); + console->parse_list_subs(cmd,2); + } else { + ShowError("'"CL_WHITE"%s"CL_RESET"' doesn't possess any subcommands\n",sublist); + } + return; + } + ShowError("'"CL_WHITE"%s"CL_RESET"' is not a known subcommand of '"CL_WHITE"%s"CL_RESET"'\n",tok,cmd->cmd); + ShowError("type '"CL_WHITE"%s help"CL_RESET"' to list its subcommands\n",sublist); + return; + } + if( cmd->u.next[i]->next_count == 0 && cmd->u.next[i]->u.func ) { + char *r = NULL; + if( (tok = strtok(NULL, " ")) ) { + r = bline; + r += len + strlen(cmd->u.next[i]->cmd) + 1; + } + cmd->u.next[i]->u.func(r); + return; + } else + cmd = cmd->u.next[i]; + len += snprintf(sublist + len,CP_CMD_LENGTH * 5,":%s", cmd->cmd); + } + ShowError("it is only a category, type '"CL_WHITE"%s help"CL_RESET"' to list its subcommands\n",sublist); + } +} void console_parse(char* line) { int c, i = 0, len = MAX_CONSOLE_INPUT - 1;/* we leave room for the \0 :P */ @@ -122,7 +329,7 @@ int console_parse_timer(int tid, unsigned int tick, int id, intptr_t data) { int i; EnterSpinLock(&console->ptlock); for(i = 0; i < cinput.count; i++) { - parse_console(cinput.queue[i]); + console->parse_sub(cinput.queue[i]); } cinput.count = 0; LeaveSpinLock(&console->ptlock); @@ -163,12 +370,22 @@ void console_parse_init(void) { void console_init (void) { #ifdef CONSOLE_INPUT + console->cmd_count = console->cmd_list_count = 0; + console->load_defaults(); console->parse_init(); #endif } void console_final(void) { #ifdef CONSOLE_INPUT + int i; console->parse_final(); + for( i = 0; i < console->cmd_count; i++ ) { + if( console->cmds[i]->next_count ) + aFree(console->cmds[i]->u.next); + aFree(console->cmds[i]); + } + aFree(console->cmds); + aFree(console->cmd_list); #endif } void console_defaults(void) { @@ -182,6 +399,10 @@ void console_defaults(void) { console->parse_timer = console_parse_timer; console->pthread_main = cThread_main; console->parse = console_parse; + console->parse_sub = console_parse_sub; console->key_pressed = console_parse_key_pressed; + console->load_defaults = console_load_defaults; + console->parse_list_subs = console_parse_list_subs; + console->addCommand = console_parse_create; #endif } -- cgit v1.2.3-70-g09d2 From 6509af19cb4dbba9d8af7489301e58dc8c6ca9f7 Mon Sep 17 00:00:00 2001 From: Matheus Macabu Date: Thu, 2 May 2013 20:10:06 -0300 Subject: Follow-up to HPM. * Fixed small warning * Added support for Visual Studio 2010. Signed-off-by: Matheus Macabu --- .gitignore | 3 + Hercules-10.sln | 6 ++ src/common/console.c | 2 +- vcproj-10/char-server.vcxproj | 14 ++-- vcproj-10/char-server.vcxproj.filters | 14 ++-- vcproj-10/login-server.vcxproj | 6 +- vcproj-10/login-server.vcxproj.filters | 10 ++- vcproj-10/plugin-sample.vcxproj | 118 +++++++++++++++++++++++++++++++++ 8 files changed, 158 insertions(+), 15 deletions(-) create mode 100644 vcproj-10/plugin-sample.vcxproj (limited to 'src/common/console.c') diff --git a/.gitignore b/.gitignore index 7d981021d..480ac1fa3 100644 --- a/.gitignore +++ b/.gitignore @@ -87,6 +87,7 @@ /vcproj-12/mapcache /vcproj-12/map-server_sql /vcproj-12/*.user +/vcproj-12/plugin-sample/ # /vcproj-10/ /vcproj-10/map-server @@ -97,6 +98,7 @@ /vcproj-10/mapcache /vcproj-10/map-server_sql /vcproj-10/*.user +/vcproj-10/plugin-sample/ # /vcproj-9/ /vcproj-9/*.user @@ -107,3 +109,4 @@ /vcproj-9/login-server_sql /vcproj-9/map-server_sql /vcproj-9/mapcache +/vcproj-9/plugin-sample/ diff --git a/Hercules-10.sln b/Hercules-10.sln index a740ee0b1..997df68af 100644 --- a/Hercules-10.sln +++ b/Hercules-10.sln @@ -8,6 +8,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "map-server", "vcproj-10\map EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mapcache", "vcproj-10\mapcache.vcxproj", "{D356871D-58E1-450B-967A-E7E9646175AF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "plugin-sample", "vcproj-10\plugin-sample.vcxproj", "{E64C56D3-CDFB-483B-900B-A62D216B6D2F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -30,6 +32,10 @@ Global {D356871D-58E1-450B-967A-E7E9646175AF}.Debug|Win32.Build.0 = Debug|Win32 {D356871D-58E1-450B-967A-E7E9646175AF}.Release|Win32.ActiveCfg = Release|Win32 {D356871D-58E1-450B-967A-E7E9646175AF}.Release|Win32.Build.0 = Release|Win32 + {E64C56D3-CDFB-483B-900B-A62D216B6D2F}.Debug|Win32.ActiveCfg = Debug|Win32 + {E64C56D3-CDFB-483B-900B-A62D216B6D2F}.Debug|Win32.Build.0 = Debug|Win32 + {E64C56D3-CDFB-483B-900B-A62D216B6D2F}.Release|Win32.ActiveCfg = Release|Win32 + {E64C56D3-CDFB-483B-900B-A62D216B6D2F}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/common/console.c b/src/common/console.c index db914db98..c228ab790 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -377,7 +377,7 @@ void console_init (void) { } void console_final(void) { #ifdef CONSOLE_INPUT - int i; + unsigned int i; console->parse_final(); for( i = 0; i < console->cmd_count; i++ ) { if( console->cmds[i]->next_count ) diff --git a/vcproj-10/char-server.vcxproj b/vcproj-10/char-server.vcxproj index e07954292..46438b3aa 100644 --- a/vcproj-10/char-server.vcxproj +++ b/vcproj-10/char-server.vcxproj @@ -138,12 +138,13 @@ + - + - - + + @@ -171,7 +172,7 @@ - + @@ -181,8 +182,9 @@ + - + @@ -212,7 +214,7 @@ - + diff --git a/vcproj-10/char-server.vcxproj.filters b/vcproj-10/char-server.vcxproj.filters index 13788df95..3f3c2f6ac 100644 --- a/vcproj-10/char-server.vcxproj.filters +++ b/vcproj-10/char-server.vcxproj.filters @@ -4,7 +4,7 @@ common - + common @@ -82,7 +82,7 @@ char_sql - + char_sql @@ -115,6 +115,9 @@ common + + common + @@ -123,7 +126,7 @@ common - + common @@ -174,7 +177,7 @@ char_sql - + char_sql @@ -249,6 +252,9 @@ common + + common + diff --git a/vcproj-10/login-server.vcxproj b/vcproj-10/login-server.vcxproj index 20c780902..7cf90854d 100644 --- a/vcproj-10/login-server.vcxproj +++ b/vcproj-10/login-server.vcxproj @@ -138,6 +138,7 @@ + @@ -149,7 +150,7 @@ - + @@ -173,6 +174,7 @@ + @@ -182,7 +184,7 @@ - + diff --git a/vcproj-10/login-server.vcxproj.filters b/vcproj-10/login-server.vcxproj.filters index 0ce4b8b6e..46f4efbc4 100644 --- a/vcproj-10/login-server.vcxproj.filters +++ b/vcproj-10/login-server.vcxproj.filters @@ -16,7 +16,7 @@ common - + common @@ -88,6 +88,9 @@ common + + common + @@ -108,7 +111,7 @@ common - + common @@ -195,6 +198,9 @@ common + + common + diff --git a/vcproj-10/plugin-sample.vcxproj b/vcproj-10/plugin-sample.vcxproj new file mode 100644 index 000000000..4bb437cda --- /dev/null +++ b/vcproj-10/plugin-sample.vcxproj @@ -0,0 +1,118 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E64C56D3-CDFB-483B-900B-A62D216B6D2F} + plugin-sample + Win32Proj + plugin-sample + + + + DynamicLibrary + MultiByte + + + DynamicLibrary + MultiByte + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + ..\plugins\ + $(ProjectName)\$(Configuration)\ + false + ..\plugins\ + $(ProjectName)\$(Configuration)\ + false + AllRules.ruleset + + + AllRules.ruleset + + + plugin-sample + plugin-sample + + + + /MP %(AdditionalOptions) + Disabled + ..\src\common;..\3rdparty\msinttypes\include;%(AdditionalIncludeDirectories) + _DEBUG;WIN32;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + true + Level3 + ProgramDatabase + 4996;%(DisableSpecificWarnings) + true + + + _DEBUG;%(PreprocessorDefinitions) + 0x0417 + + + $(OutDir)$(TargetName).dll + + + true + $(IntDir)$(TargetName).pdb + false + $(IntDir)$(TargetName).lib + MachineX86 + + + + + /MP %(AdditionalOptions) + MaxSpeed + ..\src\common;..\3rdparty\msinttypes\include;%(AdditionalIncludeDirectories) + NDEBUG;WIN32;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + Level3 + ProgramDatabase + 4996;%(DisableSpecificWarnings) + + + NDEBUG;%(PreprocessorDefinitions) + 0x0417 + + + $(OutDir)$(TargetName).dll + + + true + $(IntDir)$(TargetName).pdb + true + true + false + $(IntDir)$(TargetName).lib + MachineX86 + + + + + + + + + \ No newline at end of file -- cgit v1.2.3-70-g09d2