From 8f36123ac4f0dad6a9c2428b0b01a3ffd81017a4 Mon Sep 17 00:00:00 2001 From: ultramage Date: Mon, 29 Oct 2007 09:16:39 +0000 Subject: Command code cleaning (refer to topic:169759) * separated the execution part of command code into interface part and internal part to better see which checks are done and when (fixes problem where 'nocommand' mapflag blocked server npcs) * moved the internal commands list (array) to the end of the file, this let me discard that long block of ACMD_FUNC() declarations * removed enum AtCommandType from command headers and commands array; its purpose was perhaps to identify aliased commands, but apparently it was never finished because the rest of the code doesn't use it (also doing aliases like this is not a very good idea) * internally, commands are now referenced to using their function name * removed the @/# symbols from the command lists; all lookup functions will now properly deal with strings with- and without a command symbol (commands interface still requires the symbol tho', so TODO for later) * removed several unneeded commands (*id2 code, dmalloc debug commands) * reverted atcommand config from alphabetically-sorted to how it was before (with additional fixes; see /conf changelog) * added missing code for #dropall / #storeall * added a warning when trying to set gm level of an undefined command The structure of the commands table has changed, please adjust docs/guides to match the new format (sorry for the inconvenience). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11607 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/script.c | 94 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 46 deletions(-) (limited to 'src/map/script.c') diff --git a/src/map/script.c b/src/map/script.c index 8b2464be4..28cb7ed7e 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11006,80 +11006,82 @@ BUILDIN_FUNC(nude) *------------------------------------------*/ BUILDIN_FUNC(atcommand) { - TBL_PC *sd=NULL; - const char *cmd; + TBL_PC dummy_sd; + TBL_PC* sd; + int fd; + const char* cmd; cmd = script_getstr(st,2); - if (st->rid) - sd = script_rid2sd(st); - if (sd){ - if(cmd[0] != atcommand_symbol){ - cmd += strlen(sd->status.name); - while(*cmd != atcommand_symbol && *cmd != 0) - cmd++; - } - is_atcommand_sub(sd->fd, sd, cmd, 99); + if (st->rid) { + sd = script_rid2sd(st); + fd = sd->fd; } else { //Use a dummy character. - TBL_PC dummy_sd; - struct block_list *bl = NULL; + sd = &dummy_sd; + fd = 0; + memset(&dummy_sd, 0, sizeof(TBL_PC)); - if (st->oid) bl = map_id2bl(st->oid); - if (bl) { + if (st->oid) + { + struct block_list* bl = map_id2bl(st->oid); memcpy(&dummy_sd.bl, bl, sizeof(struct block_list)); if (bl->type == BL_NPC) - strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); + safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); } - if(cmd[0] != atcommand_symbol){ - cmd += strlen(dummy_sd.status.name); - while(*cmd != atcommand_symbol && *cmd != 0) - cmd++; - } - is_atcommand_sub(0, &dummy_sd, cmd, 99); } + // compatibility with previous implementation (deprecated!) + if(cmd[0] != atcommand_symbol) + { + cmd += strlen(sd->status.name); + while(*cmd != atcommand_symbol && *cmd != 0) + cmd++; + } + + is_atcommand_sub(fd, sd, cmd, 99); + return 0; } BUILDIN_FUNC(charcommand) { - TBL_PC *sd=NULL; - const char *cmd; - + TBL_PC dummy_sd; + TBL_PC* sd; + int fd; + const char* cmd; + cmd = script_getstr(st,2); - if (st->rid) + if (st->rid) { sd = script_rid2sd(st); - - if (sd){ - if(cmd[0] != charcommand_symbol){ - cmd += strlen(sd->status.name); - while(*cmd != charcommand_symbol && *cmd != 0) - cmd++; - } - is_charcommand_sub(sd->fd, sd, cmd,99); + fd = sd->fd; } else { //Use a dummy character. - TBL_PC dummy_sd; - struct block_list *bl = NULL; + sd = &dummy_sd; + fd = 0; + memset(&dummy_sd, 0, sizeof(TBL_PC)); - if (st->oid) bl = map_id2bl(st->oid); - if (bl) { + if (st->oid) + { + struct block_list* bl = map_id2bl(st->oid); memcpy(&dummy_sd.bl, bl, sizeof(struct block_list)); if (bl->type == BL_NPC) - strncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); + safestrncpy(dummy_sd.status.name, ((TBL_NPC*)bl)->name, NAME_LENGTH); } - if(cmd[0] != charcommand_symbol){ - cmd += strlen(dummy_sd.status.name); - while(*cmd != charcommand_symbol && *cmd != 0) - cmd++; - } - is_charcommand_sub(0, &dummy_sd, cmd, 99); } + // compatibility with previous implementation (deprecated!) + if(cmd[0] != charcommand_symbol) + { + cmd += strlen(sd->status.name); + while(*cmd != charcommand_symbol && *cmd != 0) + cmd++; + } + + is_charcommand_sub(fd, sd, cmd, 99); + return 0; } - /*========================================== * Displays a message for the player only (like system messages like "you got an apple" ) *------------------------------------------*/ -- cgit v1.2.3-60-g2f50