From 9f6ffd2f9aae9c39eb2fe2be2c60cfd45c18842a Mon Sep 17 00:00:00 2001 From: Emistry Haoyan Date: Sat, 13 Apr 2019 16:28:16 +0800 Subject: Added *consolemes script command - deprecated `*debugmes` script command. - added `*consolemes` script command which display the console message based on `type`. - allow map-server console to auto logging into text file depend on type of message. --- doc/script_commands.txt | 27 +++++++++++++++ npc/custom/etc/quest_warper.txt | 6 ++-- npc/custom/quests/quest_shop.txt | 4 +-- npc/custom/quests/thq/THQS_TTShop.txt | 4 +-- npc/dev/test.txt | 10 +++--- npc/woe-fe/agit_main.txt | 3 +- src/map/script.c | 62 ++++++++++++++++++++++++++++++++++- 7 files changed, 102 insertions(+), 14 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index b53dda2f6..f767f890d 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -7775,6 +7775,10 @@ solution rather than sending the map and the monster_id. *debugmes(""{, {, ...}}) + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @ /!\ This command is deprecated @ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + This command will print a message in the server console (map-server window), after applying the same format-string replacements as sprintf(). It will not be displayed anywhere else. Returns true on success. @@ -7788,6 +7792,29 @@ Example: --------------------------------------- +*consolemes("", ""{,{, ...}}) + +This command will print a message in the server console (map-server window), +after applying the same format-string replacements as sprintf(). It will not be +displayed anywhere else. Returns true on success. + +List of available are: + CONSOLEMES_DEBUG = 0 + CONSOLEMES_ERROR = 1 + CONSOLEMES_WARNING = 2 + CONSOLEMES_INFO = 3 + CONSOLEMES_STATUS = 4 + CONSOLEMES_NOTICE = 5 + +Example: + + // Displays "NAME has clicked me!" in the map-server window. + consolemes(CONSOLEMES_DEBUG, "%s has clicked me!", strcharinfo(PC_NAME)); + + consolemes(CONSOLEMES_DEBUG, "\033[0;32mHello World"); // supports ANSI escape sequences + +--------------------------------------- + *logmes(""{, }) This command will write the message given to the map server log files, as diff --git a/npc/custom/etc/quest_warper.txt b/npc/custom/etc/quest_warper.txt index 35b863e9d..2ae2e7f7f 100644 --- a/npc/custom/etc/quest_warper.txt +++ b/npc/custom/etc/quest_warper.txt @@ -82,7 +82,7 @@ function script Q_Warpra { case 2: warp $QW_SP_WarpMap$, $QW_SP_WarpX, $QW_SP_WarpY; close2; - debugmes "Please check your special warp menu settings on the Warpra."; + consolemes(CONSOLEMES_WARNING, "Please check your special warp menu settings on the Warpra."); end; case 3: goto L_town; case 4: goto L_dungeon; @@ -1533,7 +1533,7 @@ function script QWS_Dungeon_Warpra { mes "[Warpra]"; mes "Sorry, I can only unlock this location."; } else - debugmes "QWS_Dungeon_Warpra error, improper syntax?"; + consolemes(CONSOLEMES_ERROR, "QWS_Dungeon_Warpra error, improper syntax?"); return; function QWS_D_setbin { @@ -1577,7 +1577,7 @@ function script QWS_Town_Warpra { } else if (QWS_T_getbin(getarg(0)) == 1) { callfunc "Q_Warpra",0; } else - debugmes "QWS_Town_Warpra error, improper syntax ?"; + consolemes(CONSOLEMES_ERROR, "QWS_Town_Warpra error, improper syntax ?"); return; function QWS_T_setbin { diff --git a/npc/custom/quests/quest_shop.txt b/npc/custom/quests/quest_shop.txt index 739b53c02..c2481e991 100644 --- a/npc/custom/quests/quest_shop.txt +++ b/npc/custom/quests/quest_shop.txt @@ -170,13 +170,13 @@ OnEnd: function Add { if (getitemname(getarg(1)) == "null") { - debugmes "Quest reward #"+getarg(1)+" invalid (skipped)."; + consolemes(CONSOLEMES_WARNING, "Quest reward #"+getarg(1)+" invalid (skipped)."); return; } setarray .@j[0],getarg(2),getarg(3),getarg(4); for(set .@i,5; .@i PRICE function script thqs_menu_buy { if( getargcount() != 2 ) { - debugmes "thqs_menu_buy: Wrong number of arguments!!"; + consolemes(CONSOLEMES_ERROR, "thqs_menu_buy: Wrong number of arguments!!"); close; } @@ -101,7 +101,7 @@ function script thqs_menu_buy { .@mp$ = getarg(1); if( getarraysize( getd(.@mw$) ) != getarraysize( getd(.@mp$) ) ) { - debugmes "thqs_menu_buy: Missing entries in data!"; + consolemes(CONSOLEMES_ERROR, "thqs_menu_buy: Missing entries in data!"); close; } diff --git a/npc/dev/test.txt b/npc/dev/test.txt index 2822ee65c..a867a09b2 100644 --- a/npc/dev/test.txt +++ b/npc/dev/test.txt @@ -786,10 +786,10 @@ function script HerculesSelfTestHelper { callsub(OnCheck, "data_to_string (integer variable)", data_to_string(.@x), ".@x"); if (.errors) { - debugmes "Script engine self-test [ \033[0;31mFAILED\033[0m ]"; - debugmes "**** The test was completed with " + .errors + " errors. ****"; + consolemes(CONSOLEMES_DEBUG, "Script engine self-test [ \033[0;31mFAILED\033[0m ]"); + consolemes(CONSOLEMES_DEBUG, "**** The test was completed with " + .errors + " errors. ****"); } else { - debugmes "Script engine self-test [ \033[0;32mPASSED\033[0m ]"; + consolemes(CONSOLEMES_DEBUG, "Script engine self-test [ \033[0;32mPASSED\033[0m ]"); } return .errors; end; @@ -840,8 +840,8 @@ OnReportError: .@val$ = getarg(1,""); .@ref$ = getarg(2,""); if (.errors == 1) - debugmes "**** WARNING: Any self-test results past this point are unreliable because of previous errors. ****"; - debugmes "Error: "+.@msg$+": '"+.@val$+"' (found) != '"+.@ref$+"' (expected)"; + consolemes(CONSOLEMES_DEBUG, "**** WARNING: Any self-test results past this point are unreliable because of previous errors. ****"); + consolemes(CONSOLEMES_DEBUG, "Error: "+.@msg$+": '"+.@val$+"' (found) != '"+.@ref$+"' (expected)"); ++.errors; //end; return; diff --git a/npc/woe-fe/agit_main.txt b/npc/woe-fe/agit_main.txt index 5ac5b8e9a..a0db6402b 100644 --- a/npc/woe-fe/agit_main.txt +++ b/npc/woe-fe/agit_main.txt @@ -105,7 +105,8 @@ OnAgitBreak: // Show and log error if an unguilded player breaks the Emperium. (Should NEVER happen) if (.@GID <= 0) { .@notice$ = "Character "+strcharinfo(PC_NAME)+" ("+getcharid(CHAR_ID_CHAR)+") broke the Emperium in Castle: "+strnpcinfo(NPC_NAME_HIDDEN)+" while guildless. No data will be saved and Emperium respawned."; - logmes .@notice$; debugmes .@notice$; + logmes .@notice$; + consolemes(CONSOLEMES_NOTICE, .@notice$); donpcevent "Agit#"+strnpcinfo(NPC_NAME_HIDDEN)+"::OnStartArena"; end; } diff --git a/src/map/script.c b/src/map/script.c index fe8638ac3..a11bc0c75 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -24559,6 +24559,57 @@ static BUILDIN(getcalendartime) return true; } +enum consolemes_type { + CONSOLEMES_DEBUG = 0, + CONSOLEMES_ERROR = 1, + CONSOLEMES_WARNING = 2, + CONSOLEMES_INFO = 3, + CONSOLEMES_STATUS = 4, + CONSOLEMES_NOTICE = 5, +}; + +/*========================================== +* consolemes(, "text") +*------------------------------------------*/ +static BUILDIN(consolemes) +{ + struct StringBuf buf; + StrBuf->Init(&buf); + int type = script_hasdata(st, 2) ? script_getnum(st, 2) : 0; + + if (!script->sprintf_helper(st, 3, &buf)) { + StrBuf->Destroy(&buf); + script_pushint(st, 0); + return false; + } + + switch (type) { + default: + case CONSOLEMES_DEBUG: + ShowDebug("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_ERROR: + ShowError("consolemes: (st->rid: %d) (st->oid: %d) %s\n", st->rid, st->oid, StrBuf->Value(&buf)); + break; + case CONSOLEMES_WARNING: + ShowWarning("consolemes: (st->rid: %d) (st->oid: %d) %s\n", st->rid, st->oid, StrBuf->Value(&buf)); + break; + case CONSOLEMES_INFO: + ShowInfo("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_STATUS: + ShowStatus("consolemes: %s\n", StrBuf->Value(&buf)); + break; + case CONSOLEMES_NOTICE: + ShowNotice("consolemes: %s\n", StrBuf->Value(&buf)); + break; + } + + StrBuf->Destroy(&buf); + script_pushint(st, 1); + return true; +} + /** place holder for the translation macro **/ static BUILDIN(_) { @@ -25478,7 +25529,8 @@ static void script_parse_builtin(void) BUILDIN_DEF(sc_end,"i?"), BUILDIN_DEF(getstatus, "i?"), BUILDIN_DEF(getscrate,"ii?"), - BUILDIN_DEF(debugmes,"v*"), + BUILDIN_DEF_DEPRECATED(debugmes,"v*"), + BUILDIN_DEF(consolemes,"iv*"), BUILDIN_DEF2(catchpet,"pet","i"), BUILDIN_DEF2(birthpet,"bpet",""), BUILDIN_DEF(resetlvl,"i"), @@ -26205,6 +26257,14 @@ static void script_hardcoded_constants(void) script->set_constant("MAPINFO_SIZE_Y", MAPINFO_SIZE_Y, false, false); script->set_constant("MAPINFO_ZONE", MAPINFO_ZONE, false, false); + script->constdb_comment("consolemes options"); + script->set_constant("CONSOLEMES_DEBUG", CONSOLEMES_DEBUG, false, false); + script->set_constant("CONSOLEMES_ERROR", CONSOLEMES_ERROR, false, false); + script->set_constant("CONSOLEMES_WARNING", CONSOLEMES_WARNING, false, false); + script->set_constant("CONSOLEMES_INFO", CONSOLEMES_INFO, false, false); + script->set_constant("CONSOLEMES_STATUS", CONSOLEMES_STATUS, false, false); + script->set_constant("CONSOLEMES_NOTICE", CONSOLEMES_NOTICE, false, false); + script->constdb_comment("set/getiteminfo options"); script->set_constant("ITEMINFO_BUYPRICE", ITEMINFO_BUYPRICE, false, false); script->set_constant("ITEMINFO_SELLPRICE", ITEMINFO_SELLPRICE, false, false); -- cgit v1.2.3-60-g2f50