diff options
author | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-01-13 09:34:49 +0000 |
---|---|---|
committer | ai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-01-13 09:34:49 +0000 |
commit | 0e628dcfe81a8067def049d0bfaafdcefbd1a847 (patch) | |
tree | aba2b649e943a585f93efa3e40414745512cacb8 | |
parent | 2552c703729fb2b01123da59fa22f40b82e9282a (diff) | |
download | hercules-0e628dcfe81a8067def049d0bfaafdcefbd1a847.tar.gz hercules-0e628dcfe81a8067def049d0bfaafdcefbd1a847.tar.bz2 hercules-0e628dcfe81a8067def049d0bfaafdcefbd1a847.tar.xz hercules-0e628dcfe81a8067def049d0bfaafdcefbd1a847.zip |
* Reformatting and minor cleanups to console-plugin related code.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14664 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r-- | Changelog-Trunk.txt | 2 | ||||
-rw-r--r-- | src/char/char.c | 28 | ||||
-rw-r--r-- | src/char_sql/char.c | 28 | ||||
-rw-r--r-- | src/common/core.h | 2 | ||||
-rw-r--r-- | src/login/login.c | 28 | ||||
-rw-r--r-- | src/map/map.c | 56 | ||||
-rw-r--r-- | src/plugins/console.c | 2 |
7 files changed, 65 insertions, 81 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index b9938d03b..b3627f0ec 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -1,5 +1,7 @@ Date Added +2011/01/13 + * Reformatting and minor cleanups to console-plugin related code. [Ai4rei] 2011/01/10 * Fixed script command 'cleararray' setting 1 element more, than it is told to (bugreport:2047, since r12253). [Ai4rei] - Fixed 'inaccessible element 127' issue in 'cleararray', 'setarray' (since r10813) and 'copyarray' (since r14608) script commands (bugreport:864, related r12253, follow up to r14608). diff --git a/src/char/char.c b/src/char/char.c index 314bfcdac..c0788f64e 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -3779,29 +3779,19 @@ int parse_char(int fd) } // Console Command Parser [Wizputer] -int parse_console(char* buf) +int parse_console(const char* command) { - char command[256]; + ShowNotice("Console command: %s\n", command); - memset(command, 0, sizeof(command)); - - sscanf(buf, "%[^\n]", command); - - //login_log("Console command :%s\n", command); - - if( strcmpi("shutdown", command) == 0 || - strcmpi("exit", command) == 0 || - strcmpi("quit", command) == 0 || - strcmpi("end", command) == 0 ) + if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 || strcmpi("end", command) == 0 ) runflag = 0; - else if( strcmpi("alive", command) == 0 || - strcmpi("status", command) == 0 ) + else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 ) ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n"); - else if( strcmpi("help", command) == 0 ){ - ShowInfo(CL_BOLD"Help of commands:"CL_RESET"\n"); - ShowInfo(" To shutdown the server:\n"); - ShowInfo(" 'shutdown|exit|qui|end'\n"); - ShowInfo(" To know if server is alive:\n"); + else if( strcmpi("help", command) == 0 ) + { + ShowInfo("To shutdown the server:\n"); + ShowInfo(" 'shutdown|exit|quit|end'\n"); + ShowInfo("To know if server is alive:\n"); ShowInfo(" 'alive|status'\n"); } diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 1c190c72e..fd012e419 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -3458,29 +3458,19 @@ int parse_char(int fd) } // Console Command Parser [Wizputer] -int parse_console(char* buf) +int parse_console(const char* command) { - char command[256]; + ShowNotice("Console command: %s\n", command); - memset(command, 0, sizeof(command)); - - sscanf(buf, "%[^\n]", command); - - //login_log("Console command :%s\n", command); - - if( strcmpi("shutdown", command) == 0 || - strcmpi("exit", command) == 0 || - strcmpi("quit", command) == 0 || - strcmpi("end", command) == 0 ) + if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 || strcmpi("end", command) == 0 ) runflag = 0; - else if( strcmpi("alive", command) == 0 || - strcmpi("status", command) == 0 ) + else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 ) ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n"); - else if( strcmpi("help", command) == 0 ){ - ShowInfo(CL_BOLD"Help of commands:"CL_RESET"\n"); - ShowInfo(" To shutdown the server:\n"); - ShowInfo(" 'shutdown|exit|qui|end'\n"); - ShowInfo(" To know if server is alive:\n"); + else if( strcmpi("help", command) == 0 ) + { + ShowInfo("To shutdown the server:\n"); + ShowInfo(" 'shutdown|exit|quit|end'\n"); + ShowInfo("To know if server is alive:\n"); ShowInfo(" 'alive|status'\n"); } diff --git a/src/common/core.h b/src/common/core.h index 68325505a..fc4af3e3e 100644 --- a/src/common/core.h +++ b/src/common/core.h @@ -11,7 +11,7 @@ extern int runflag; extern char *SERVER_NAME; extern char SERVER_TYPE; -extern int parse_console(char* buf); +extern int parse_console(const char* buf); extern const char *get_svn_revision(void); extern int do_init(int,char**); extern void set_server_type(void); diff --git a/src/login/login.c b/src/login/login.c index 0876f3fb2..1bce63900 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -323,31 +323,19 @@ int login_lan_config_read(const char *lancfgName) //----------------------- // Console Command Parser [Wizputer] //----------------------- -int parse_console(char* buf) +int parse_console(const char* command) { - char command[256]; + ShowNotice("Console command: %s\n", command); - memset(command, 0, sizeof(command)); - - sscanf(buf, "%[^\n]", command); - - ShowInfo("Console command :%s\n", command); - - if( strcmpi("shutdown", command) == 0 || - strcmpi("exit", command) == 0 || - strcmpi("quit", command) == 0 || - strcmpi("end", command) == 0 ) + if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 || strcmpi("end", command) == 0 ) runflag = 0; - else - if( strcmpi("alive", command) == 0 || - strcmpi("status", command) == 0 ) + else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 ) ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n"); - else - if( strcmpi("help", command) == 0 ) { - ShowInfo(CL_BOLD"Help of commands:"CL_RESET"\n"); - ShowInfo(" To shutdown the server:\n"); + else if( strcmpi("help", command) == 0 ) + { + ShowInfo("To shutdown the server:\n"); ShowInfo(" 'shutdown|exit|quit|end'\n"); - ShowInfo(" To know if server is alive:\n"); + ShowInfo("To know if server is alive:\n"); ShowInfo(" 'alive|status'\n"); } diff --git a/src/map/map.c b/src/map/map.c index f10c92f32..b1e92a62d 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3012,7 +3012,7 @@ static int char_ip_set = 0; /*========================================== * Console Command Parser [Wizputer] *------------------------------------------*/ -int parse_console(char* buf) +int parse_console(const char* buf) { char type[64]; char command[64]; @@ -3026,14 +3026,20 @@ int parse_console(char* buf) memset(&sd, 0, sizeof(struct map_session_data)); strcpy(sd.status.name, "console"); - if( (n=sscanf(buf, "%[^:]:%[^:]:%99s %d %d[^\n]",type,command,map,&x,&y)) < 5 ) - if( (n=sscanf(buf, "%[^:]:%[^\n]",type,command)) < 2 ) - n = sscanf(buf,"%[^\n]",type); + if( ( n = sscanf(buf, "%63[^:]:%63[^:]:%63s %d %d[^\n]", type, command, map, &x, &y) ) < 5 ) + { + if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 ) + { + n = sscanf(buf, "%63[^\n]", type); + } + } - if( n == 5 ) { + if( n == 5 ) + { m = map_mapname2mapid(map); - if( m < 0 ){ - ShowWarning("Console: Unknown map\n"); + if( m < 0 ) + { + ShowWarning("Console: Unknown map.\n"); return 0; } sd.bl.m = m; @@ -3042,32 +3048,40 @@ int parse_console(char* buf) sd.bl.x = x; if( y > 0 ) sd.bl.y = y; - } else { + } + else + { map[0] = '\0'; - if( n < 2 ) command[0] = '\0'; - if( n < 1 ) type[0] = '\0'; + if( n < 2 ) + command[0] = '\0'; + if( n < 1 ) + type[0] = '\0'; } - ShowInfo("Type of command: '%s' || Command: '%s' || Map: '%s' Coords: %d %d\n", type, command, map, x, y); + ShowNotice("Type of command: '%s' || Command: '%s' || Map: '%s' Coords: %d %d\n", type, command, map, x, y); - if( n == 5 && strcmpi("admin",type) == 0 ){ - if( !is_atcommand(sd.fd,&sd,command,0) ) + if( n == 5 && strcmpi("admin",type) == 0 ) + { + if( !is_atcommand(sd.fd, &sd, command, 0) ) ShowInfo("Console: not atcommand\n"); - } else if( n == 2 && strcmpi("server",type) == 0 ){ - if( strcmpi("shutdown",command) == 0 || - strcmpi("exit",command) == 0 || - strcmpi("quit",command) == 0 ){ + } + else if( n == 2 && strcmpi("server", type) == 0 ) + { + if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 ) + { runflag = 0; } - } else if( strcmpi("help",type) == 0 ){ - ShowNotice("To use GM commands:\n"); - ShowInfo("admin:<gm command>:<map of \"gm\"> <x> <y>\n"); + } + else if( strcmpi("help", type) == 0 ) + { + ShowInfo("To use GM commands:\n"); + ShowInfo(" admin:<gm command>:<map of \"gm\"> <x> <y>\n"); ShowInfo("You can use any GM command that doesn't require the GM.\n"); ShowInfo("No using @item or @warp however you can use @charwarp\n"); ShowInfo("The <map of \"gm\"> <x> <y> is for commands that need coords of the GM\n"); ShowInfo("IE: @spawn\n"); ShowInfo("To shutdown the server:\n"); - ShowInfo("server:shutdown\n"); + ShowInfo(" server:shutdown\n"); } return 0; diff --git a/src/plugins/console.c b/src/plugins/console.c index 7ea69c637..b1307f863 100644 --- a/src/plugins/console.c +++ b/src/plugins/console.c @@ -133,7 +133,7 @@ int (*add_timer_func_list)(TimerFunc func, char* name); int (*add_timer_interval)(unsigned int tick, TimerFunc func, int id, intptr data, int interval); int (*delete_timer)(int tid, TimerFunc func); unsigned int (*gettick)(void); -int (*parse_console)(char* buf); +int (*parse_console)(const char* buf); // Locals int tid = -1; // timer id |