diff options
90 files changed, 4080 insertions, 4037 deletions
diff --git a/.travis.yml b/.travis.yml index dd58b51..301fb20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,23 +74,16 @@ env: - ignore=this matrix: - allow_failures: - - compiler: clang - env: REAL_CC=clang-3.1 REAL_CXX=clang++-3.1 PPA=ppa:h-rayflood/llvm PACKAGE=clang-3.1 exclude: - env: ignore=this include: - compiler: clang - env: REAL_CC=clang-3.1 REAL_CXX=clang++-3.1 PPA=ppa:h-rayflood/llvm PACKAGE=clang-3.1 - - compiler: clang env: REAL_CC=clang-3.2 REAL_CXX=clang++-3.2 PPA=ppa:h-rayflood/llvm PACKAGE=clang-3.2 - compiler: clang env: REAL_CC=clang-3.3 REAL_CXX=clang++-3.3 PPA=ppa:h-rayflood/llvm PACKAGE=clang-3.3 - compiler: clang env: REAL_CC=clang-3.4 REAL_CXX=clang++-3.4 PPA=ppa:h-rayflood/llvm PACKAGE=clang-3.4 - compiler: gcc - env: REAL_CC=gcc-4.6 REAL_CXX=g++-4.6 PPA= PACKAGE=g++-4.6 - - compiler: gcc env: REAL_CC=gcc-4.7 REAL_CXX=g++-4.7 PPA=ppa:ubuntu-toolchain-r/test PACKAGE=g++-4.7 - compiler: gcc env: REAL_CC=gcc-4.8 REAL_CXX=g++-4.8 PPA=ppa:ubuntu-toolchain-r/test PACKAGE=g++-4.8 diff --git a/src/admin/ladmin.cpp b/src/admin/ladmin.cpp index 5d772e3..c635379 100644 --- a/src/admin/ladmin.cpp +++ b/src/admin/ladmin.cpp @@ -68,9 +68,9 @@ IP4Address login_ip = IP4_LOCALHOST; // IP of login-server static int login_port = 6900; // Port of login-server static -AccountPass admin_pass = stringish<AccountPass>("admin"); // Administration password +AccountPass admin_pass = stringish<AccountPass>("admin"_s); // Administration password static -AString ladmin_log_filename = "log/ladmin.log"; +AString ladmin_log_filename = "log/ladmin.log"_s; //------------------------------------------------------------------------- // LIST of COMMANDs that you can type at the prompt: // To use these commands you can only type only the first letters. @@ -267,7 +267,7 @@ int already_exit_function = 0; // sometimes, the exit function is called twice.. #pragma GCC diagnostic ignored "-Wmissing-noreturn" void SessionDeleter::operator()(SessionData *) { - assert(false && "ladmin does not have sessions"); + assert(false && "ladmin does not have sessions"_s); } #pragma GCC diagnostic pop @@ -340,315 +340,315 @@ void display_help(ZString param) XString command = param.xislice_h(std::find(param.begin(), param.end(), ' ')); if (command.startswith('?')) - command = "help"; + command = "help"_s; - LADMIN_LOG("Displaying of the commands or a command.\n"); + LADMIN_LOG("Displaying of the commands or a command.\n"_fmt); - if (command == "help") + if (command == "help"_s) { - PRINTF("help/?\n"); - PRINTF(" Display the description of the commands\n"); - PRINTF("help/? [command]\n"); - PRINTF(" Display the description of the specified command\n"); + PRINTF("help/?\n"_fmt); + PRINTF(" Display the description of the commands\n"_fmt); + PRINTF("help/? [command]\n"_fmt); + PRINTF(" Display the description of the specified command\n"_fmt); } - else if (command == "add") + else if (command == "add"_s) { - PRINTF("add <account_name> <sex> <password>\n"); - PRINTF(" Create an account with the default email (a@a.com).\n"); - PRINTF(" Concerning the sex, only the first letter is used (F or M).\n"); - PRINTF(" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n"); - PRINTF(" When the password is omitted,\n"); - PRINTF(" the input is done without displaying of the pressed keys.\n"); - PRINTF(" <example> add testname Male testpass\n"); + PRINTF("add <account_name> <sex> <password>\n"_fmt); + PRINTF(" Create an account with the default email (a@a.com).\n"_fmt); + PRINTF(" Concerning the sex, only the first letter is used (F or M).\n"_fmt); + PRINTF(" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n"_fmt); + PRINTF(" When the password is omitted,\n"_fmt); + PRINTF(" the input is done without displaying of the pressed keys.\n"_fmt); + PRINTF(" <example> add testname Male testpass\n"_fmt); } - else if (command == "ban") + else if (command == "ban"_s) { - PRINTF("ban yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" Changes the final date of a banishment of an account.\n"); - PRINTF(" Like banset, but <account name> is at end.\n"); + PRINTF("ban yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" Changes the final date of a banishment of an account.\n"_fmt); + PRINTF(" Like banset, but <account name> is at end.\n"_fmt); } - else if (command == "banadd") + else if (command == "banadd"_s) { - PRINTF("banadd <account_name> <modifier>\n"); - PRINTF(" Adds or substracts time from the final date of a banishment of an account.\n"); - PRINTF(" Modifier is done as follows:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - PRINTF("NOTE: If you modify the final date of a non-banished account,\n"); - PRINTF(" you fix the final date to (actual time +- adjustments)\n"); + PRINTF("banadd <account_name> <modifier>\n"_fmt); + PRINTF(" Adds or substracts time from the final date of a banishment of an account.\n"_fmt); + PRINTF(" Modifier is done as follows:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + PRINTF("NOTE: If you modify the final date of a non-banished account,\n"_fmt); + PRINTF(" you fix the final date to (actual time +- adjustments)\n"_fmt); } - else if (command == "banset") + else if (command == "banset"_s) { - PRINTF("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" Changes the final date of a banishment of an account.\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - PRINTF("banset <account_name> 0\n"); - PRINTF(" Set a non-banished account (0 = unbanished).\n"); + PRINTF("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" Changes the final date of a banishment of an account.\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + PRINTF("banset <account_name> 0\n"_fmt); + PRINTF(" Set a non-banished account (0 = unbanished).\n"_fmt); } - else if (command == "block") + else if (command == "block"_s) { - PRINTF("block <account name>\n"); - PRINTF(" Set state 5 (You have been blocked by the GM Team) to an account.\n"); - PRINTF(" This command works like state <account_name> 5.\n"); + PRINTF("block <account name>\n"_fmt); + PRINTF(" Set state 5 (You have been blocked by the GM Team) to an account.\n"_fmt); + PRINTF(" This command works like state <account_name> 5.\n"_fmt); } - else if (command == "check") + else if (command == "check"_s) { - PRINTF("check <account_name> <password>\n"); - PRINTF(" Check the validity of a password for an account.\n"); - PRINTF(" NOTE: Server will never sends back a password.\n"); - PRINTF(" It's the only method you have to know if a password is correct.\n"); - PRINTF(" The other method is to have a ('physical') access to the accounts file.\n"); + PRINTF("check <account_name> <password>\n"_fmt); + PRINTF(" Check the validity of a password for an account.\n"_fmt); + PRINTF(" NOTE: Server will never sends back a password.\n"_fmt); + PRINTF(" It's the only method you have to know if a password is correct.\n"_fmt); + PRINTF(" The other method is to have a ('physical') access to the accounts file.\n"_fmt); } - else if (command == "create") + else if (command == "create"_s) { - PRINTF("create <account_name> <sex> <email> <password>\n"); - PRINTF(" Like the 'add' command, but with e-mail moreover.\n"); - PRINTF(" <example> create testname Male my@mail.com testpass\n"); + PRINTF("create <account_name> <sex> <email> <password>\n"_fmt); + PRINTF(" Like the 'add' command, but with e-mail moreover.\n"_fmt); + PRINTF(" <example> create testname Male my@mail.com testpass\n"_fmt); } - else if (command == "delete") + else if (command == "delete"_s) { - PRINTF("delete <account name>\n"); - PRINTF(" Remove an account.\n"); - PRINTF(" This order requires confirmation. After confirmation, the account is deleted.\n"); + PRINTF("delete <account name>\n"_fmt); + PRINTF(" Remove an account.\n"_fmt); + PRINTF(" This order requires confirmation. After confirmation, the account is deleted.\n"_fmt); } - else if (command == "email") + else if (command == "email"_s) { - PRINTF("email <account_name> <email>\n"); - PRINTF(" Modify the e-mail of an account.\n"); + PRINTF("email <account_name> <email>\n"_fmt); + PRINTF(" Modify the e-mail of an account.\n"_fmt); } - else if (command == "getcount") + else if (command == "getcount"_s) { - PRINTF("getcount\n"); - PRINTF(" Give the number of players online on all char-servers.\n"); + PRINTF("getcount\n"_fmt); + PRINTF(" Give the number of players online on all char-servers.\n"_fmt); } - else if (command == "gm") + else if (command == "gm"_s) { - PRINTF("gm <account_name> [GM_level]\n"); - PRINTF(" Modify the GM level of an account.\n"); - PRINTF(" Default value remove GM level (GM level = 0).\n"); - PRINTF(" <example> gm testname 80\n"); + PRINTF("gm <account_name> [GM_level]\n"_fmt); + PRINTF(" Modify the GM level of an account.\n"_fmt); + PRINTF(" Default value remove GM level (GM level = 0).\n"_fmt); + PRINTF(" <example> gm testname 80\n"_fmt); } - else if (command == "id") + else if (command == "id"_s) { - PRINTF("id <account name>\n"); - PRINTF(" Give the id of an account.\n"); + PRINTF("id <account name>\n"_fmt); + PRINTF(" Give the id of an account.\n"_fmt); } - else if (command == "info") + else if (command == "info"_s) { - PRINTF("info <account_id>\n"); - PRINTF(" Display complete information of an account.\n"); + PRINTF("info <account_id>\n"_fmt); + PRINTF(" Display complete information of an account.\n"_fmt); } - else if (command == "kami") + else if (command == "kami"_s) { - PRINTF("kami <message>\n"); - PRINTF(" Sends a broadcast message on all map-server (in yellow).\n"); + PRINTF("kami <message>\n"_fmt); + PRINTF(" Sends a broadcast message on all map-server (in yellow).\n"_fmt); } - else if (command == "kamib") + else if (command == "kamib"_s) { - PRINTF("kamib <message>\n"); - PRINTF(" Sends a broadcast message on all map-server (in blue).\n"); + PRINTF("kamib <message>\n"_fmt); + PRINTF(" Sends a broadcast message on all map-server (in blue).\n"_fmt); } - else if (command == "list") + else if (command == "list"_s) { - PRINTF("list/ls [start_id [end_id]]\n"); - PRINTF(" Display a list of accounts.\n"); - PRINTF(" 'start_id', 'end_id': indicate end and start identifiers.\n"); - PRINTF(" Research by name is not possible with this command.\n"); - PRINTF(" <example> list 10 9999999\n"); + PRINTF("list/ls [start_id [end_id]]\n"_fmt); + PRINTF(" Display a list of accounts.\n"_fmt); + PRINTF(" 'start_id', 'end_id': indicate end and start identifiers.\n"_fmt); + PRINTF(" Research by name is not possible with this command.\n"_fmt); + PRINTF(" <example> list 10 9999999\n"_fmt); } - else if (command == "itemfrob") + else if (command == "itemfrob"_s) { - PRINTF("itemfrob <source-id> <dest-id>\n"); - PRINTF(" Translates item IDs for all accounts.\n"); - PRINTF(" Any items matching the source item ID will be mapped to the dest-id.\n"); - PRINTF(" <example> itemfrob 500 700\n"); + PRINTF("itemfrob <source-id> <dest-id>\n"_fmt); + PRINTF(" Translates item IDs for all accounts.\n"_fmt); + PRINTF(" Any items matching the source item ID will be mapped to the dest-id.\n"_fmt); + PRINTF(" <example> itemfrob 500 700\n"_fmt); } - else if (command == "listban") + else if (command == "listban"_s) { - PRINTF("listban [start_id [end_id]]\n"); - PRINTF(" Like list/ls, but only for accounts with state or banished.\n"); + PRINTF("listban [start_id [end_id]]\n"_fmt); + PRINTF(" Like list/ls, but only for accounts with state or banished.\n"_fmt); } - else if (command == "listgm") + else if (command == "listgm"_s) { - PRINTF("listgm [start_id [end_id]]\n"); - PRINTF(" Like list/ls, but only for GM accounts.\n"); + PRINTF("listgm [start_id [end_id]]\n"_fmt); + PRINTF(" Like list/ls, but only for GM accounts.\n"_fmt); } - else if (command == "listok") + else if (command == "listok"_s) { - PRINTF("listok [start_id [end_id]]\n"); - PRINTF(" Like list/ls, but only for accounts without state and not banished.\n"); + PRINTF("listok [start_id [end_id]]\n"_fmt); + PRINTF(" Like list/ls, but only for accounts without state and not banished.\n"_fmt); } - else if (command == "memo") + else if (command == "memo"_s) { - PRINTF("memo <account_name> <memo>\n"); - PRINTF(" Modify the memo of an account.\n"); - PRINTF(" 'memo': it can have until 253 characters (with spaces or not).\n"); + PRINTF("memo <account_name> <memo>\n"_fmt); + PRINTF(" Modify the memo of an account.\n"_fmt); + PRINTF(" 'memo': it can have until 253 characters (with spaces or not).\n"_fmt); } - else if (command == "name") + else if (command == "name"_s) { - PRINTF("name <account_id>\n"); - PRINTF(" Give the name of an account.\n"); + PRINTF("name <account_id>\n"_fmt); + PRINTF(" Give the name of an account.\n"_fmt); } - else if (command == "password") + else if (command == "password"_s) { - PRINTF("password <account_name> <new_password>\n"); - PRINTF(" Change the password of an account.\n"); - PRINTF(" When new password is omitted,\n"); - PRINTF(" the input is done without displaying of the pressed keys.\n"); + PRINTF("password <account_name> <new_password>\n"_fmt); + PRINTF(" Change the password of an account.\n"_fmt); + PRINTF(" When new password is omitted,\n"_fmt); + PRINTF(" the input is done without displaying of the pressed keys.\n"_fmt); } - else if (command == "reloadgm") + else if (command == "reloadgm"_s) { - PRINTF("reloadGM\n"); - PRINTF(" Reload GM configuration file\n"); + PRINTF("reloadGM\n"_fmt); + PRINTF(" Reload GM configuration file\n"_fmt); } - else if (command == "search") + else if (command == "search"_s) { - PRINTF("search <expression>\n"); - PRINTF(" Seek accounts.\n"); - PRINTF(" Displays the accounts whose names correspond.\n"); + PRINTF("search <expression>\n"_fmt); + PRINTF(" Seek accounts.\n"_fmt); + PRINTF(" Displays the accounts whose names correspond.\n"_fmt); } - else if (command == "sex") + else if (command == "sex"_s) { - PRINTF("sex <account_name> <sex>\n"); - PRINTF(" Modify the sex of an account.\n"); - PRINTF(" <example> sex testname Male\n"); + PRINTF("sex <account_name> <sex>\n"_fmt); + PRINTF(" Modify the sex of an account.\n"_fmt); + PRINTF(" <example> sex testname Male\n"_fmt); } - else if (command == "state") + else if (command == "state"_s) { - PRINTF("state <account_name> <new_state> <error_message_#7>\n"); - PRINTF(" Change the state of an account.\n"); - PRINTF(" 'new_state': state is the state of the packet 0x006a + 1.\n"); - PRINTF(" The possibilities are:\n"); - PRINTF(" 0 = Account ok\n"); - PRINTF(" 1 = Unregistered ID\n"); - PRINTF(" 2 = Incorrect Password\n"); - PRINTF(" 3 = This ID is expired\n"); - PRINTF(" 4 = Rejected from Server\n"); - PRINTF(" 5 = You have been blocked by the GM Team\n"); - PRINTF(" 6 = Your Game's EXE file is not the latest version\n"); - PRINTF(" 7 = You are Prohibited to log in until...\n"); - PRINTF(" 8 = Server is jammed due to over populated\n"); - PRINTF(" 9 = No MSG\n"); - PRINTF(" 100 = This ID has been totally erased\n"); - PRINTF(" all other values are 'No MSG', then use state 9 please.\n"); - PRINTF(" 'error_message_#7': message of the code error 6\n"); - PRINTF(" = Your are Prohibited to log in until... (packet 0x006a)\n"); + PRINTF("state <account_name> <new_state> <error_message_#7>\n"_fmt); + PRINTF(" Change the state of an account.\n"_fmt); + PRINTF(" 'new_state': state is the state of the packet 0x006a + 1.\n"_fmt); + PRINTF(" The possibilities are:\n"_fmt); + PRINTF(" 0 = Account ok\n"_fmt); + PRINTF(" 1 = Unregistered ID\n"_fmt); + PRINTF(" 2 = Incorrect Password\n"_fmt); + PRINTF(" 3 = This ID is expired\n"_fmt); + PRINTF(" 4 = Rejected from Server\n"_fmt); + PRINTF(" 5 = You have been blocked by the GM Team\n"_fmt); + PRINTF(" 6 = Your Game's EXE file is not the latest version\n"_fmt); + PRINTF(" 7 = You are Prohibited to log in until...\n"_fmt); + PRINTF(" 8 = Server is jammed due to over populated\n"_fmt); + PRINTF(" 9 = No MSG\n"_fmt); + PRINTF(" 100 = This ID has been totally erased\n"_fmt); + PRINTF(" all other values are 'No MSG', then use state 9 please.\n"_fmt); + PRINTF(" 'error_message_#7': message of the code error 6\n"_fmt); + PRINTF(" = Your are Prohibited to log in until... (packet 0x006a)\n"_fmt); } - else if (command == "timeadd") + else if (command == "timeadd"_s) { - PRINTF("timeadd <account_name> <modifier>\n"); - PRINTF(" Adds or substracts time from the validity limit of an account.\n"); - PRINTF(" Modifier is done as follows:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - PRINTF("NOTE: You can not modify a unlimited validity limit.\n"); - PRINTF(" If you want modify it, you want probably create a limited validity limit.\n"); - PRINTF(" So, at first, you must set the validity limit to a date/time.\n"); + PRINTF("timeadd <account_name> <modifier>\n"_fmt); + PRINTF(" Adds or substracts time from the validity limit of an account.\n"_fmt); + PRINTF(" Modifier is done as follows:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + PRINTF("NOTE: You can not modify a unlimited validity limit.\n"_fmt); + PRINTF(" If you want modify it, you want probably create a limited validity limit.\n"_fmt); + PRINTF(" So, at first, you must set the validity limit to a date/time.\n"_fmt); } - else if (command == "timeadd") + else if (command == "timeadd"_s) { - PRINTF("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" Changes the validity limit of an account.\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - PRINTF("timeset <account_name> 0\n"); - PRINTF(" Gives an unlimited validity limit (0 = unlimited).\n"); + PRINTF("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" Changes the validity limit of an account.\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + PRINTF("timeset <account_name> 0\n"_fmt); + PRINTF(" Gives an unlimited validity limit (0 = unlimited).\n"_fmt); } - else if (command == "unban") + else if (command == "unban"_s) { - PRINTF("unban/unbanish <account name>\n"); - PRINTF(" Remove the banishment of an account.\n"); - PRINTF(" This command works like banset <account_name> 0.\n"); + PRINTF("unban/unbanish <account name>\n"_fmt); + PRINTF(" Remove the banishment of an account.\n"_fmt); + PRINTF(" This command works like banset <account_name> 0.\n"_fmt); } - else if (command == "unblock") + else if (command == "unblock"_s) { - PRINTF("unblock <account name>\n"); - PRINTF(" Set state 0 (Account ok) to an account.\n"); - PRINTF(" This command works like state <account_name> 0.\n"); + PRINTF("unblock <account name>\n"_fmt); + PRINTF(" Set state 0 (Account ok) to an account.\n"_fmt); + PRINTF(" This command works like state <account_name> 0.\n"_fmt); } - else if (command == "version") + else if (command == "version"_s) { - PRINTF("version\n"); - PRINTF(" Display the version of the login-server.\n"); + PRINTF("version\n"_fmt); + PRINTF(" Display the version of the login-server.\n"_fmt); } - else if (command == "who") + else if (command == "who"_s) { - PRINTF("who <account name>\n"); - PRINTF(" Displays complete information of an account.\n"); + PRINTF("who <account name>\n"_fmt); + PRINTF(" Displays complete information of an account.\n"_fmt); } - else if (command == "quit" - || command == "exit" - || command == "end") - { - PRINTF("quit/end/exit\n"); - PRINTF(" End of the program of administration.\n"); + else if (command == "quit"_s + || command == "exit"_s + || command == "end"_s) + { + PRINTF("quit/end/exit\n"_fmt); + PRINTF(" End of the program of administration.\n"_fmt); } else { if (command) - PRINTF("Unknown command [%s] for help. Displaying of all commands.\n", + PRINTF("Unknown command [%s] for help. Displaying of all commands.\n"_fmt, AString(command)); - PRINTF(" help/? -- Display this help\n"); - PRINTF(" help/? [command] -- Display the help of the command\n"); - PRINTF(" add <account_name> <sex> <password> -- Create an account with default email\n"); - PRINTF(" ban yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n"); - PRINTF(" banadd <account_name> <modifier> -- Add or substract time from the final\n"); - PRINTF(" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n"); - PRINTF(" banset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n"); - PRINTF(" banset <account_name> 0 -- Un-banish an account\n"); - PRINTF(" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n"); - PRINTF(" check <account_name> <password> -- Check the validity of a password\n"); - PRINTF(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n"); - PRINTF(" delete <account name> -- Remove an account\n"); - PRINTF(" email <account_name> <email> -- Modify an email of an account\n"); - PRINTF(" getcount -- Give the number of players online\n"); - PRINTF(" gm <account_name> [GM_level] -- Modify the GM level of an account\n"); - PRINTF(" id <account name> -- Give the id of an account\n"); - PRINTF(" info <account_id> -- Display all information of an account\n"); - PRINTF(" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n"); - PRINTF(" kami <message> -- Sends a broadcast message (in yellow)\n"); - PRINTF(" kamib <message> -- Sends a broadcast message (in blue)\n"); - PRINTF(" list [First_id [Last_id]] -- Display a list of accounts\n"); - PRINTF(" listban [First_id [Last_id] ] -- Display a list of accounts\n"); - PRINTF(" with state or banished\n"); - PRINTF(" listgm [First_id [Last_id]] -- Display a list of GM accounts\n"); - PRINTF(" listok [First_id [Last_id] ] -- Display a list of accounts\n"); - PRINTF(" without state and not banished\n"); - PRINTF(" memo <account_name> <memo> -- Modify the memo of an account\n"); - PRINTF(" name <account_id> -- Give the name of an account\n"); - PRINTF(" password <account_name> <new_password> -- Change the password of an account\n"); - PRINTF(" quit/end/exit -- End of the program of administation\n"); - PRINTF(" reloadGM -- Reload GM configuration file\n"); - PRINTF(" search <expression> -- Seek accounts\n"); - PRINTF(" sex <nomcompte> <sexe> -- Modify the sex of an account\n"); - PRINTF(" state <account_name> <new_state> <error_message_#7> -- Change the state\n"); - PRINTF(" timeadd <account_name> <modifier> -- Add or substract time from the\n"); - PRINTF(" example: ta apple +1m-2mn1s-2y validity limit of an account\n"); - PRINTF(" timeset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n"); - PRINTF(" timeset <account_name> 0 -- Give a unlimited validity limit\n"); - PRINTF(" unban <account name> -- Remove the banishment of an account\n"); - PRINTF(" unblock <account name> -- Set state 0 (Account ok) to an account\n"); - PRINTF(" version -- Gives the version of the login-server\n"); - PRINTF(" who <account name> -- Display all information of an account\n"); - PRINTF(" who <account name> -- Display all information of an account\n"); - PRINTF(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n"); + PRINTF(" help/? -- Display this help\n"_fmt); + PRINTF(" help/? [command] -- Display the help of the command\n"_fmt); + PRINTF(" add <account_name> <sex> <password> -- Create an account with default email\n"_fmt); + PRINTF(" ban yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n"_fmt); + PRINTF(" banadd <account_name> <modifier> -- Add or substract time from the final\n"_fmt); + PRINTF(" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n"_fmt); + PRINTF(" banset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n"_fmt); + PRINTF(" banset <account_name> 0 -- Un-banish an account\n"_fmt); + PRINTF(" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n"_fmt); + PRINTF(" check <account_name> <password> -- Check the validity of a password\n"_fmt); + PRINTF(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n"_fmt); + PRINTF(" delete <account name> -- Remove an account\n"_fmt); + PRINTF(" email <account_name> <email> -- Modify an email of an account\n"_fmt); + PRINTF(" getcount -- Give the number of players online\n"_fmt); + PRINTF(" gm <account_name> [GM_level] -- Modify the GM level of an account\n"_fmt); + PRINTF(" id <account name> -- Give the id of an account\n"_fmt); + PRINTF(" info <account_id> -- Display all information of an account\n"_fmt); + PRINTF(" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n"_fmt); + PRINTF(" kami <message> -- Sends a broadcast message (in yellow)\n"_fmt); + PRINTF(" kamib <message> -- Sends a broadcast message (in blue)\n"_fmt); + PRINTF(" list [First_id [Last_id]] -- Display a list of accounts\n"_fmt); + PRINTF(" listban [First_id [Last_id] ] -- Display a list of accounts\n"_fmt); + PRINTF(" with state or banished\n"_fmt); + PRINTF(" listgm [First_id [Last_id]] -- Display a list of GM accounts\n"_fmt); + PRINTF(" listok [First_id [Last_id] ] -- Display a list of accounts\n"_fmt); + PRINTF(" without state and not banished\n"_fmt); + PRINTF(" memo <account_name> <memo> -- Modify the memo of an account\n"_fmt); + PRINTF(" name <account_id> -- Give the name of an account\n"_fmt); + PRINTF(" password <account_name> <new_password> -- Change the password of an account\n"_fmt); + PRINTF(" quit/end/exit -- End of the program of administation\n"_fmt); + PRINTF(" reloadGM -- Reload GM configuration file\n"_fmt); + PRINTF(" search <expression> -- Seek accounts\n"_fmt); + PRINTF(" sex <nomcompte> <sexe> -- Modify the sex of an account\n"_fmt); + PRINTF(" state <account_name> <new_state> <error_message_#7> -- Change the state\n"_fmt); + PRINTF(" timeadd <account_name> <modifier> -- Add or substract time from the\n"_fmt); + PRINTF(" example: ta apple +1m-2mn1s-2y validity limit of an account\n"_fmt); + PRINTF(" timeset <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n"_fmt); + PRINTF(" timeset <account_name> 0 -- Give a unlimited validity limit\n"_fmt); + PRINTF(" unban <account name> -- Remove the banishment of an account\n"_fmt); + PRINTF(" unblock <account name> -- Set state 0 (Account ok) to an account\n"_fmt); + PRINTF(" version -- Gives the version of the login-server\n"_fmt); + PRINTF(" who <account name> -- Display all information of an account\n"_fmt); + PRINTF(" who <account name> -- Display all information of an account\n"_fmt); + PRINTF(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n"_fmt); } } @@ -668,9 +668,9 @@ void addaccount(ZString param, int emailflag) // add command if (!qsplit(param, &name, &sex_, &password)) { - PRINTF("Please input an account name, a sex and a password.\n"); - PRINTF("<example> add testname Male testpass\n"); - LADMIN_LOG("Incomplete parameters to create an account ('add' command).\n"); + PRINTF("Please input an account name, a sex and a password.\n"_fmt); + PRINTF("<example> add testname Male testpass\n"_fmt); + LADMIN_LOG("Incomplete parameters to create an account ('add' command).\n"_fmt); return; } email_ = DEFAULT_EMAIL; @@ -680,9 +680,9 @@ void addaccount(ZString param, int emailflag) // 1: create command if (!qsplit(param, &name, &sex_, &email_, &password)) { - PRINTF("Please input an account name, a sex and a password.\n"); - PRINTF("<example> create testname Male my@mail.com testpass\n"); - LADMIN_LOG("Incomplete parameters to create an account ('create' command).\n"); + PRINTF("Please input an account name, a sex and a password.\n"_fmt); + PRINTF("<example> create testname Male my@mail.com testpass\n"_fmt); + LADMIN_LOG("Incomplete parameters to create an account ('create' command).\n"_fmt); return; } } @@ -690,18 +690,18 @@ void addaccount(ZString param, int emailflag) if (!name.is_print()) return; - if (!XString("MF").contains(sex)) + if (!"MF"_s.contains(sex)) { - PRINTF("Illegal gender [%c]. Please input M or F.\n", sex); - LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n", sex); + PRINTF("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); + LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); return; } if (!e_mail_check(email_)) { - PRINTF("Invalid email [%s]. Please input a valid e-mail.\n", + PRINTF("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); - LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n", + LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); return; } @@ -710,7 +710,7 @@ void addaccount(ZString param, int emailflag) if (!password.is_print()) return; - LADMIN_LOG("Request to login-server to create an account.\n"); + LADMIN_LOG("Request to login-server to create an account.\n"_fmt); WFIFOW(login_session, 0) = 0x7930; WFIFO_STRING(login_session, 2, name, 24); @@ -732,11 +732,11 @@ void banaddaccount(ZString param) if (!qsplit(param, &name, &modif)) { - PRINTF("Please input an account name and a modifier.\n"); - PRINTF(" <example>: banadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n"); + PRINTF("Please input an account name and a modifier.\n"_fmt); + PRINTF(" <example>: banadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n"_fmt); return; } if (!name.is_print()) @@ -744,23 +744,23 @@ void banaddaccount(ZString param) if (!modif) { - PRINTF("Please give an adjustment with this command:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("No adjustment isn't an adjustment ('banadd' command).\n"); + PRINTF("Please give an adjustment with this command:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> banadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("No adjustment isn't an adjustment ('banadd' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to modify a ban date/time.\n"); + LADMIN_LOG("Request to login-server to modify a ban date/time.\n"_fmt); WFIFOW(login_session, 0) = 0x794c; WFIFO_STRING(login_session, 2, name, 24); @@ -786,19 +786,19 @@ void bansetaccountsub(AccountName name, XString date, XString time_) if (!name.is_print()) return; - if (date != "0" + if (date != "0"_s && ((!extract(date, record<'/'>(&year, &month, &day)) && !extract(date, record<'-'>(&year, &month, &day)) && !extract(date, record<'.'>(&year, &month, &day))) || !extract(time_, record<':'>(&hour, &minute, &second)))) { - PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"); - PRINTF("You can imput 0 instead of if you use 'banset' command.\n"); - LADMIN_LOG("Invalid format for the date/time ('banset' or 'ban' command).\n"); + PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"_fmt); + PRINTF("You can imput 0 instead of if you use 'banset' command.\n"_fmt); + LADMIN_LOG("Invalid format for the date/time ('banset' or 'ban' command).\n"_fmt); return; } - if (date == "0") + if (date == "0"_s) { ban_until_time = TimeT(); } @@ -814,41 +814,41 @@ void bansetaccountsub(AccountName name, XString date, XString time_) } if (month < 1 || month > 12) { - PRINTF("Please give a correct value for the month (from 1 to 12).\n"); - LADMIN_LOG("Invalid month for the date ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the month (from 1 to 12).\n"_fmt); + LADMIN_LOG("Invalid month for the date ('banset' or 'ban' command).\n"_fmt); return; } month = month - 1; if (day < 1 || day > 31) { - PRINTF("Please give a correct value for the day (from 1 to 31).\n"); - LADMIN_LOG("Invalid day for the date ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the day (from 1 to 31).\n"_fmt); + LADMIN_LOG("Invalid day for the date ('banset' or 'ban' command).\n"_fmt); return; } if (((month == 3 || month == 5 || month == 8 || month == 10) && day > 30) || (month == 1 && day > 29)) { - PRINTF("Please give a correct value for a day of this month (%d).\n", + PRINTF("Please give a correct value for a day of this month (%d).\n"_fmt, month); - LADMIN_LOG("Invalid day for this month ('banset' or 'ban' command).\n"); + LADMIN_LOG("Invalid day for this month ('banset' or 'ban' command).\n"_fmt); return; } if (hour < 0 || hour > 23) { - PRINTF("Please give a correct value for the hour (from 0 to 23).\n"); - LADMIN_LOG("Invalid hour for the time ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the hour (from 0 to 23).\n"_fmt); + LADMIN_LOG("Invalid hour for the time ('banset' or 'ban' command).\n"_fmt); return; } if (minute < 0 || minute > 59) { - PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"); - LADMIN_LOG("Invalid minute for the time ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid minute for the time ('banset' or 'ban' command).\n"_fmt); return; } if (second < 0 || second > 59) { - PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"); - LADMIN_LOG("Invalid second for the time ('banset' or 'ban' command).\n"); + PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid second for the time ('banset' or 'ban' command).\n"_fmt); return; } tmtime.tm_year = year; @@ -861,15 +861,15 @@ void bansetaccountsub(AccountName name, XString date, XString time_) ban_until_time = tmtime; if (ban_until_time.error()) { - PRINTF("Invalid date.\n"); - PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"); - PRINTF("You can imput 0 instead of if you use 'banset' command.\n"); - LADMIN_LOG("Invalid date. ('banset' or 'ban' command).\n"); + PRINTF("Invalid date.\n"_fmt); + PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n"_fmt); + PRINTF("You can imput 0 instead of if you use 'banset' command.\n"_fmt); + LADMIN_LOG("Invalid date. ('banset' or 'ban' command).\n"_fmt); return; } } - LADMIN_LOG("Request to login-server to set a ban.\n"); + LADMIN_LOG("Request to login-server to set a ban.\n"_fmt); WFIFOW(login_session, 0) = 0x794a; WFIFO_STRING(login_session, 2, name, 24); @@ -890,18 +890,18 @@ void banaccount(ZString param) if (!qsplit(param, &date, &time_, &name)) { - PRINTF("Please input an account name, a date and a hour.\n"); - PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" banset <account_name> 0 (0 = un-banished)\n"); - PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" unban/unbanish <account name>\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"); + PRINTF("Please input an account name, a date and a hour.\n"_fmt); + PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" banset <account_name> 0 (0 = un-banished)\n"_fmt); + PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" unban/unbanish <account name>\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"_fmt); return; } if (!time_) - time_ = "23:59:59"; + time_ = "23:59:59"_s; bansetaccountsub(name, date, time_); } @@ -919,18 +919,18 @@ void bansetaccount(ZString param) if (!qsplit(param, &name, &date, &time_) && !qsplit(param, &name, &date)) { - PRINTF("Please input an account name, a date and a hour.\n"); - PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" banset <account_name> 0 (0 = un-banished)\n"); - PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" unban/unbanish <account name>\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"); + PRINTF("Please input an account name, a date and a hour.\n"_fmt); + PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" banset <account_name> 0 (0 = un-banished)\n"_fmt); + PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" unban/unbanish <account name>\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n"_fmt); return; } if (!time_) - time_ = "23:59:59"; + time_ = "23:59:59"_s; bansetaccountsub(name, date, time_); } @@ -945,17 +945,17 @@ void unbanaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" banset <account_name> 0 (0 = un-banished)\n"); - PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"); - PRINTF(" unban/unbanish <account name>\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a ban ('unban' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" banset <account_name> 0 (0 = un-banished)\n"_fmt); + PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n"_fmt); + PRINTF(" unban/unbanish <account name>\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a ban ('unban' command).\n"_fmt); return; } - bansetaccountsub(name, "0", ""); + bansetaccountsub(name, "0"_s, ""_s); } //--------------------------------------------------------- @@ -970,9 +970,9 @@ void checkaccount(ZString param) if (!qsplit(param, &name, &password)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> check testname password\n"); - LADMIN_LOG("Incomplete parameters to check the password of an account ('check' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> check testname password\n"_fmt); + LADMIN_LOG("Incomplete parameters to check the password of an account ('check' command).\n"_fmt); return; } @@ -982,7 +982,7 @@ void checkaccount(ZString param) if (!password.is_print()) return; - LADMIN_LOG("Request to login-server to check a password.\n"); + LADMIN_LOG("Request to login-server to check a password.\n"_fmt); WFIFOW(login_session, 0) = 0x793a; WFIFO_STRING(login_session, 2, name, 24); @@ -1001,9 +1001,9 @@ void delaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> delete testnametodelete\n"); - LADMIN_LOG("No name given to delete an account ('delete' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> delete testnametodelete\n"_fmt); + LADMIN_LOG("No name given to delete an account ('delete' command).\n"_fmt); return; } @@ -1013,7 +1013,7 @@ void delaccount(ZString param) char confirm; do { - PRINTF(SGR_BOLD SGR_CYAN " ** Are you really sure to DELETE account [%s]? (y/n) > " SGR_RESET, name); + PRINTF(SGR_BOLD SGR_CYAN " ** Are you really sure to DELETE account [%s]? (y/n) > " SGR_RESET ""_fmt, name); fflush(stdout); int seek = getchar(); confirm = seek; @@ -1023,16 +1023,16 @@ void delaccount(ZString param) while (seek != '\n' && seek != EOF) seek = getchar(); } - while (!XString("yn").contains(confirm)); + while (!"yn"_s.contains(confirm)); if (confirm == 'n') { - PRINTF("Deletion canceled.\n"); - LADMIN_LOG("Deletion canceled by user ('delete' command).\n"); + PRINTF("Deletion canceled.\n"_fmt); + LADMIN_LOG("Deletion canceled by user ('delete' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to delete an acount.\n"); + LADMIN_LOG("Request to login-server to delete an acount.\n"_fmt); WFIFOW(login_session, 0) = 0x7932; WFIFO_STRING(login_session, 2, name, 24); @@ -1050,9 +1050,9 @@ void changeemail(ZString param) XString email_; if (!qsplit(param, &name, &email_)) { - PRINTF("Please input an account name and an email.\n"); - PRINTF("<example> email testname newemail\n"); - LADMIN_LOG("Incomplete parameters to change the email of an account ('email' command).\n"); + PRINTF("Please input an account name and an email.\n"_fmt); + PRINTF("<example> email testname newemail\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the email of an account ('email' command).\n"_fmt); return; } @@ -1061,15 +1061,15 @@ void changeemail(ZString param) if (!e_mail_check(email_)) { - PRINTF("Invalid email [%s]. Please input a valid e-mail.\n", + PRINTF("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); - LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n", + LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n"_fmt, AString(email_)); return; } AccountEmail email = stringish<AccountEmail>(email_); - LADMIN_LOG("Request to login-server to change an email.\n"); + LADMIN_LOG("Request to login-server to change an email.\n"_fmt); WFIFOW(login_session, 0) = 0x7940; WFIFO_STRING(login_session, 2, name, 24); @@ -1084,7 +1084,7 @@ void changeemail(ZString param) static void getlogincount(void) { - LADMIN_LOG("Request to login-server to obtain the # of online players.\n"); + LADMIN_LOG("Request to login-server to obtain the # of online players.\n"_fmt); WFIFOW(login_session, 0) = 0x7938; WFIFOSET(login_session, 2); @@ -1102,9 +1102,9 @@ void changegmlevel(ZString param) if (!qsplit(param, &name, &GM_level)) { - PRINTF("Please input an account name and a GM level.\n"); - PRINTF("<example> gm testname 80\n"); - LADMIN_LOG("Incomplete parameters to change the GM level of an account ('gm' command).\n"); + PRINTF("Please input an account name and a GM level.\n"_fmt); + PRINTF("<example> gm testname 80\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the GM level of an account ('gm' command).\n"_fmt); return; } @@ -1113,14 +1113,14 @@ void changegmlevel(ZString param) if (GM_level < 0 || GM_level > 99) { - PRINTF("Illegal GM level [%d]. Please input a value from 0 to 99.\n", + PRINTF("Illegal GM level [%d]. Please input a value from 0 to 99.\n"_fmt, GM_level); - LADMIN_LOG("Illegal GM level [%d]. The value can be from 0 to 99.\n", + LADMIN_LOG("Illegal GM level [%d]. The value can be from 0 to 99.\n"_fmt, GM_level); return; } - LADMIN_LOG("Request to login-server to change a GM level.\n"); + LADMIN_LOG("Request to login-server to change a GM level.\n"_fmt); WFIFOW(login_session, 0) = 0x793e; WFIFO_STRING(login_session, 2, name, 24); @@ -1139,9 +1139,9 @@ void idaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> id testname\n"); - LADMIN_LOG("No name given to search an account id ('id' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> id testname\n"_fmt); + LADMIN_LOG("No name given to search an account id ('id' command).\n"_fmt); return; } @@ -1150,7 +1150,7 @@ void idaccount(ZString param) return; } - LADMIN_LOG("Request to login-server to know an account id.\n"); + LADMIN_LOG("Request to login-server to know an account id.\n"_fmt); WFIFOW(login_session, 0) = 0x7944; WFIFO_STRING(login_session, 2, name, 24); @@ -1166,12 +1166,12 @@ void infoaccount(int account_id) { if (account_id < 0) { - PRINTF("Please input a positive value for the id.\n"); - LADMIN_LOG("Negative value was given to found the account.\n"); + PRINTF("Please input a positive value for the id.\n"_fmt); + LADMIN_LOG("Negative value was given to found the account.\n"_fmt); return; } - LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n"); + LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n"_fmt); WFIFOW(login_session, 0) = 0x7954; WFIFOL(login_session, 2) = account_id; @@ -1187,11 +1187,11 @@ void sendbroadcast(ZString message) { if (!message) { - PRINTF("Please input a message.\n"); + PRINTF("Please input a message.\n"_fmt); { - PRINTF("<example> kami a message\n"); + PRINTF("<example> kami a message\n"_fmt); } - LADMIN_LOG("The message is void ('kami' command).\n"); + LADMIN_LOG("The message is void ('kami' command).\n"_fmt); return; } @@ -1244,7 +1244,7 @@ void listaccount(ZString param, int type) list_last = 0; } - LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d.\n", + LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d.\n"_fmt, list_first, list_last); WFIFOW(login_session, 0) = 0x7920; @@ -1254,8 +1254,8 @@ void listaccount(ZString param, int type) bytes_to_read = 1; // 0123456789 01 01234567890123456789012301234 012345 0123456789012345678901234567 - Iprintf("account_id GM user_name sex count state\n"); - Iprintf("-------------------------------------------------------------------------------\n"); + Iprintf("account_id GM user_name sex count state\n"_fmt); + Iprintf("-------------------------------------------------------------------------------\n"_fmt); list_count = 0; } @@ -1269,7 +1269,7 @@ int itemfrob(ZString param) if (!extract(param, record<' '>(&source_id, &dest_id))) { - PRINTF("You must provide the source and destination item IDs.\n"); + PRINTF("You must provide the source and destination item IDs.\n"_fmt); return 1; } @@ -1293,9 +1293,9 @@ void changememo(ZString param) if (!qsplit(param, &name, &memo) && !qsplit(param, &name)) { - PRINTF("Please input an account name and a memo.\n"); - PRINTF("<example> memo testname new memo\n"); - LADMIN_LOG("Incomplete parameters to change the memo of an account ('email' command).\n"); + PRINTF("Please input an account name and a memo.\n"_fmt); + PRINTF("<example> memo testname new memo\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the memo of an account ('email' command).\n"_fmt); return; } @@ -1306,14 +1306,14 @@ void changememo(ZString param) size_t len1 = len + 1; if (len > 254) { - PRINTF("Memo is too long (%zu characters).\n", len); - PRINTF("Please input a memo of 254 bytes at the maximum.\n"); - LADMIN_LOG("Email is too long (%zu characters). Please input a memo of 254 bytes at the maximum.\n", + PRINTF("Memo is too long (%zu characters).\n"_fmt, len); + PRINTF("Please input a memo of 254 bytes at the maximum.\n"_fmt); + LADMIN_LOG("Email is too long (%zu characters). Please input a memo of 254 bytes at the maximum.\n"_fmt, len); return; } - LADMIN_LOG("Request to login-server to change a memo.\n"); + LADMIN_LOG("Request to login-server to change a memo.\n"_fmt); WFIFOW(login_session, 0) = 0x7942; WFIFO_STRING(login_session, 2, name, 24); @@ -1331,12 +1331,12 @@ void nameaccount(int id) { if (id < 0) { - PRINTF("Please input a positive value for the id.\n"); - LADMIN_LOG("Negativ id given to search an account name ('name' command).\n"); + PRINTF("Please input a positive value for the id.\n"_fmt); + LADMIN_LOG("Negativ id given to search an account name ('name' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to know an account name.\n"); + LADMIN_LOG("Request to login-server to know an account name.\n"_fmt); WFIFOW(login_session, 0) = 0x7946; WFIFOL(login_session, 2) = id; @@ -1356,9 +1356,9 @@ void changepasswd(ZString param) if (!qsplit(param, &name, &password)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> password testname newpassword\n"); - LADMIN_LOG("Incomplete parameters to change the password of an account ('password' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> password testname newpassword\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the password of an account ('password' command).\n"_fmt); return; } @@ -1370,7 +1370,7 @@ void changepasswd(ZString param) if (!password.is_print()) return; - LADMIN_LOG("Request to login-server to change a password.\n"); + LADMIN_LOG("Request to login-server to change a password.\n"_fmt); WFIFOW(login_session, 0) = 0x7934; WFIFO_STRING(login_session, 2, name, 24); @@ -1390,9 +1390,9 @@ void reloadGM(ZString params) WFIFOSET(login_session, 2); bytes_to_read = 0; - LADMIN_LOG("Request to reload the GM configuration file sended.\n"); - PRINTF("Request to reload the GM configuration file sended.\n"); - PRINTF("Check the actual GM accounts (after reloading):\n"); + LADMIN_LOG("Request to reload the GM configuration file sended.\n"_fmt); + PRINTF("Request to reload the GM configuration file sended.\n"_fmt); + PRINTF("Check the actual GM accounts (after reloading):\n"_fmt); listaccount(params, 1); // 1: to list only GM } @@ -1407,27 +1407,27 @@ void changesex(ZString param) if (!qsplit(param, &name, &sex_)) { - PRINTF("Please input an account name and a sex.\n"); - PRINTF("<example> sex testname Male\n"); - LADMIN_LOG("Incomplete parameters to change the sex of an account ('sex' command).\n"); + PRINTF("Please input an account name and a sex.\n"_fmt); + PRINTF("<example> sex testname Male\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the sex of an account ('sex' command).\n"_fmt); return; } char sex = sex_.front(); if (!name.is_print()) { - PRINTF("bad name\n"); + PRINTF("bad name\n"_fmt); return; } - if (!XString("MF").contains(sex)) + if (!"MF"_s.contains(sex)) { - PRINTF("Illegal gender [%c]. Please input M or F.\n", sex); - LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n", sex); + PRINTF("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); + LADMIN_LOG("Illegal gender [%c]. Please input M or F.\n"_fmt, sex); return; } - LADMIN_LOG("Request to login-server to change a sex.\n"); + LADMIN_LOG("Request to login-server to change a sex.\n"_fmt); WFIFOW(login_session, 0) = 0x793c; WFIFO_STRING(login_session, 2, name, 24); @@ -1445,18 +1445,18 @@ void changestatesub(AccountName name, int state, XString error_message) { if ((state < 0 || state > 9) && state != 100) { // Valid values: 0: ok, or value of the 0x006a packet + 1 - PRINTF("Please input one of these states:\n"); - PRINTF(" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n"); - PRINTF(" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n"); - PRINTF(" 2 = Incorrect Password 8 = Server is jammed due to over populated\n"); - PRINTF(" 3 = This ID is expired 9 = No MSG\n"); - PRINTF(" 4 = Rejected from Server 100 = This ID has been totally erased\n"); - PRINTF(" 5 = You have been blocked by the GM Team\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n"); + PRINTF("Please input one of these states:\n"_fmt); + PRINTF(" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n"_fmt); + PRINTF(" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n"_fmt); + PRINTF(" 2 = Incorrect Password 8 = Server is jammed due to over populated\n"_fmt); + PRINTF(" 3 = This ID is expired 9 = No MSG\n"_fmt); + PRINTF(" 4 = Rejected from Server 100 = This ID has been totally erased\n"_fmt); + PRINTF(" 5 = You have been blocked by the GM Team\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n"_fmt); return; } @@ -1465,25 +1465,25 @@ void changestatesub(AccountName name, int state, XString error_message) if (state != 7) { - error_message = "-"; + error_message = "-"_s; } else { if (error_message.size() < 1) { - PRINTF("Error message is too short. Please input a message of 1-19 bytes.\n"); - LADMIN_LOG("Error message is too short. Please input a message of 1-19 bytes.\n"); + PRINTF("Error message is too short. Please input a message of 1-19 bytes.\n"_fmt); + LADMIN_LOG("Error message is too short. Please input a message of 1-19 bytes.\n"_fmt); return; } if (error_message.size() > 19) { - PRINTF("Error message is too long. Please input a message of 1-19 bytes.\n"); - LADMIN_LOG("Error message is too long. Please input a message of 1-19 bytes.\n"); + PRINTF("Error message is too long. Please input a message of 1-19 bytes.\n"_fmt); + LADMIN_LOG("Error message is too long. Please input a message of 1-19 bytes.\n"_fmt); return; } } - LADMIN_LOG("Request to login-server to change a state.\n"); + LADMIN_LOG("Request to login-server to change a state.\n"_fmt); WFIFOW(login_session, 0) = 0x7936; WFIFO_STRING(login_session, 2, name, 24); @@ -1505,12 +1505,12 @@ void changestate(ZString param) if (!qsplit(param, &name, &state, &error_message) && !qsplit(param, &name, &state)) { - PRINTF("Please input an account name and a state.\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Incomplete parameters to change the state of an account ('state' command).\n"); + PRINTF("Please input an account name and a state.\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the state of an account ('state' command).\n"_fmt); return; } @@ -1527,16 +1527,16 @@ void unblockaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Incomplete parameters to change the state of an account ('unblock' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the state of an account ('unblock' command).\n"_fmt); return; } - changestatesub(name, 0, "-"); // state 0, no error message + changestatesub(name, 0, "-"_s); // state 0, no error message } //------------------------------------------- @@ -1549,16 +1549,16 @@ void blockaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<examples> state testname 5\n"); - PRINTF(" state testname 7 end of your ban\n"); - PRINTF(" block <account name>\n"); - PRINTF(" unblock <account name>\n"); - LADMIN_LOG("Incomplete parameters to change the state of an account ('block' command).\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<examples> state testname 5\n"_fmt); + PRINTF(" state testname 7 end of your ban\n"_fmt); + PRINTF(" block <account name>\n"_fmt); + PRINTF(" unblock <account name>\n"_fmt); + LADMIN_LOG("Incomplete parameters to change the state of an account ('block' command).\n"_fmt); return; } - changestatesub(name, 5, "-"); // state 5, no error message + changestatesub(name, 5, "-"_s); // state 5, no error message } //--------------------------------------------------------------------- @@ -1572,11 +1572,11 @@ void timeaddaccount(ZString param) if (!qsplit(param, &name, &modif)) { - PRINTF("Please input an account name and a modifier.\n"); - PRINTF(" <example>: timeadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("Incomplete parameters to modify a limit time ('timeadd' command).\n"); + PRINTF("Please input an account name and a modifier.\n"_fmt); + PRINTF(" <example>: timeadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("Incomplete parameters to modify a limit time ('timeadd' command).\n"_fmt); return; } if (name.is_print()) @@ -1586,23 +1586,23 @@ void timeaddaccount(ZString param) if (!modif) { - PRINTF("Please give an adjustment with this command:\n"); - PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"); - PRINTF(" Modified element:\n"); - PRINTF(" a or y: year\n"); - PRINTF(" m: month\n"); - PRINTF(" j or d: day\n"); - PRINTF(" h: hour\n"); - PRINTF(" mn: minute\n"); - PRINTF(" s: second\n"); - PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"); - PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"); - PRINTF(" and 6 years at the same time.\n"); - LADMIN_LOG("No adjustment isn't an adjustment ('timeadd' command).\n"); + PRINTF("Please give an adjustment with this command:\n"_fmt); + PRINTF(" Adjustment value (-1, 1, +1, etc...)\n"_fmt); + PRINTF(" Modified element:\n"_fmt); + PRINTF(" a or y: year\n"_fmt); + PRINTF(" m: month\n"_fmt); + PRINTF(" j or d: day\n"_fmt); + PRINTF(" h: hour\n"_fmt); + PRINTF(" mn: minute\n"_fmt); + PRINTF(" s: second\n"_fmt); + PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n"_fmt); + PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n"_fmt); + PRINTF(" and 6 years at the same time.\n"_fmt); + LADMIN_LOG("No adjustment isn't an adjustment ('timeadd' command).\n"_fmt); return; } - LADMIN_LOG("Request to login-server to modify a time limit.\n"); + LADMIN_LOG("Request to login-server to modify a time limit.\n"_fmt); WFIFOW(login_session, 0) = 0x7950; WFIFO_STRING(login_session, 2, name, 24); @@ -1631,31 +1631,31 @@ void timesetaccount(ZString param) if (!qsplit(param, &name, &date, &time_) && !qsplit(param, &name, &date)) { - PRINTF("Please input an account name, a date and a hour.\n"); - PRINTF("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"); - PRINTF(" timeset <account_name> 0 (0 = unlimited)\n"); - PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"); - LADMIN_LOG("Incomplete parameters to set a limit time ('timeset' command).\n"); + PRINTF("Please input an account name, a date and a hour.\n"_fmt); + PRINTF("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n"_fmt); + PRINTF(" timeset <account_name> 0 (0 = unlimited)\n"_fmt); + PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n"_fmt); + LADMIN_LOG("Incomplete parameters to set a limit time ('timeset' command).\n"_fmt); return; } if (!name.is_print()) return; if (!time_) - time_ = "23:59:59"; + time_ = "23:59:59"_s; - if (date != "0" + if (date != "0"_s && ((!extract(date, record<'/'>(&year, &month, &day)) && !extract(date, record<'-'>(&year, &month, &day)) && !extract(date, record<'.'>(&year, &month, &day))) || !extract(time_, record<':'>(&hour, &minute, &second)))) { - PRINTF("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"); - LADMIN_LOG("Invalid format for the date/time ('timeset' command).\n"); + PRINTF("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"_fmt); + LADMIN_LOG("Invalid format for the date/time ('timeset' command).\n"_fmt); return; } - if (date == "0") + if (date == "0"_s) { connect_until_time = TimeT(); } @@ -1671,41 +1671,41 @@ void timesetaccount(ZString param) } if (month < 1 || month > 12) { - PRINTF("Please give a correct value for the month (from 1 to 12).\n"); - LADMIN_LOG("Invalid month for the date ('timeset' command).\n"); + PRINTF("Please give a correct value for the month (from 1 to 12).\n"_fmt); + LADMIN_LOG("Invalid month for the date ('timeset' command).\n"_fmt); return; } month = month - 1; if (day < 1 || day > 31) { - PRINTF("Please give a correct value for the day (from 1 to 31).\n"); - LADMIN_LOG("Invalid day for the date ('timeset' command).\n"); + PRINTF("Please give a correct value for the day (from 1 to 31).\n"_fmt); + LADMIN_LOG("Invalid day for the date ('timeset' command).\n"_fmt); return; } if (((month == 3 || month == 5 || month == 8 || month == 10) && day > 30) ||(month == 1 && day > 29)) { - PRINTF("Please give a correct value for a day of this month (%d).\n", + PRINTF("Please give a correct value for a day of this month (%d).\n"_fmt, month); - LADMIN_LOG("Invalid day for this month ('timeset' command).\n"); + LADMIN_LOG("Invalid day for this month ('timeset' command).\n"_fmt); return; } if (hour < 0 || hour > 23) { - PRINTF("Please give a correct value for the hour (from 0 to 23).\n"); - LADMIN_LOG("Invalid hour for the time ('timeset' command).\n"); + PRINTF("Please give a correct value for the hour (from 0 to 23).\n"_fmt); + LADMIN_LOG("Invalid hour for the time ('timeset' command).\n"_fmt); return; } if (minute < 0 || minute > 59) { - PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"); - LADMIN_LOG("Invalid minute for the time ('timeset' command).\n"); + PRINTF("Please give a correct value for the minutes (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid minute for the time ('timeset' command).\n"_fmt); return; } if (second < 0 || second > 59) { - PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"); - LADMIN_LOG("Invalid second for the time ('timeset' command).\n"); + PRINTF("Please give a correct value for the seconds (from 0 to 59).\n"_fmt); + LADMIN_LOG("Invalid second for the time ('timeset' command).\n"_fmt); return; } tmtime.tm_year = year; @@ -1718,14 +1718,14 @@ void timesetaccount(ZString param) connect_until_time = tmtime; if (connect_until_time.error()) { - PRINTF("Invalid date.\n"); - PRINTF("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"); - LADMIN_LOG("Invalid date. ('timeset' command).\n"); + PRINTF("Invalid date.\n"_fmt); + PRINTF("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n"_fmt); + LADMIN_LOG("Invalid date. ('timeset' command).\n"_fmt); return; } } - LADMIN_LOG("Request to login-server to set a time limit.\n"); + LADMIN_LOG("Request to login-server to set a time limit.\n"_fmt); WFIFOW(login_session, 0) = 0x7948; WFIFO_STRING(login_session, 2, name, 24); @@ -1744,9 +1744,9 @@ void whoaccount(ZString param) if (!qsplit(param, &name)) { - PRINTF("Please input an account name.\n"); - PRINTF("<example> who testname\n"); - LADMIN_LOG("No name was given to found the account.\n"); + PRINTF("Please input an account name.\n"_fmt); + PRINTF("<example> who testname\n"_fmt); + LADMIN_LOG("No name was given to found the account.\n"_fmt); return; } if (!name.is_print()) @@ -1754,7 +1754,7 @@ void whoaccount(ZString param) return; } - LADMIN_LOG("Request to login-server to obtain information about an account (by its name).\n"); + LADMIN_LOG("Request to login-server to obtain information about an account (by its name).\n"_fmt); WFIFOW(login_session, 0) = 0x7952; WFIFO_STRING(login_session, 2, name, 24); @@ -1768,7 +1768,7 @@ void whoaccount(ZString param) static void checkloginversion(void) { - LADMIN_LOG("Request to login-server to obtain its version.\n"); + LADMIN_LOG("Request to login-server to obtain its version.\n"_fmt); WFIFOW(login_session, 0) = 0x7530; WFIFOSET(login_session, 2); @@ -1786,10 +1786,10 @@ void prompt(void) // while we don't wait new packets while (bytes_to_read == 0) { - Iprintf("\n"); - Iprintf(SGR_GREEN "To list the commands, type 'enter'." SGR_RESET "\n"); - Iprintf(SGR_CYAN "Ladmin-> " SGR_RESET); - Iprintf(SGR_BOLD); + Iprintf("\n"_fmt); + Iprintf(SGR_GREEN "To list the commands, type 'enter'." SGR_RESET "\n"_fmt); + Iprintf(SGR_CYAN "Ladmin-> " SGR_RESET ""_fmt); + Iprintf(SGR_BOLD ""_fmt); fflush(stdout); // get command and parameter @@ -1798,7 +1798,7 @@ void prompt(void) AString buf; cin->getline(buf); - Iprintf(SGR_RESET); + Iprintf(SGR_RESET ""_fmt); fflush(stdout); if (!cin->is_open()) @@ -1806,8 +1806,8 @@ void prompt(void) if (!buf.is_print()) { - printf("Cowardly refusing to execute a command that includes control or non-ascii characters\n"); - LADMIN_LOG("Cowardly refusing to execute a command that includes control or non-ascii characters\n"); + PRINTF("Cowardly refusing to execute a command that includes control or non-ascii characters\n"_fmt); + LADMIN_LOG("Cowardly refusing to execute a command that includes control or non-ascii characters\n"_fmt); continue; } @@ -1820,116 +1820,116 @@ void prompt(void) parameters = buf.xislice_t(space); if (!command || command.startswith('?')) - command = "help"; + command = "help"_s; if (!parameters) { - LADMIN_LOG("Command: '%s' (without parameters)\n", + LADMIN_LOG("Command: '%s' (without parameters)\n"_fmt, command); } else { // We don't want passwords in the log - Camel - if (command == "create" || command == "add" || command == "password") { + if (command == "create"_s || command == "add"_s || command == "password"_s) { AString name, email_, password; VString<1> sex_; if (qsplit(parameters, &name, &sex_, &email_, &password)) - LADMIN_LOG("Command: '%s', parameters: '%s %s %s ***'\n", + LADMIN_LOG("Command: '%s', parameters: '%s %s %s ***'\n"_fmt, command, name, sex_, email_); else if (qsplit(parameters, &name, &sex_, &password)) - LADMIN_LOG("Command: '%s', parameters: '%s %s ***'\n", + LADMIN_LOG("Command: '%s', parameters: '%s %s ***'\n"_fmt, command, name, sex_); else if (qsplit(parameters, &name, &password)) - LADMIN_LOG("Command: '%s', parameters: '%s ***'\n", + LADMIN_LOG("Command: '%s', parameters: '%s ***'\n"_fmt, command, name); else - LADMIN_LOG("Command: '%s' (invalid parameters)\n", command); + LADMIN_LOG("Command: '%s' (invalid parameters)\n"_fmt, command); } else { - LADMIN_LOG("Command: '%s', parameters: '%s'\n", + LADMIN_LOG("Command: '%s', parameters: '%s'\n"_fmt, command, parameters); } } // Analyse of the command - if (command == "help") + if (command == "help"_s) display_help(parameters); - else if (command == "add") + else if (command == "add"_s) addaccount(parameters, 0); // 0: no email - else if (command == "ban") + else if (command == "ban"_s) banaccount(parameters); - else if (command == "banadd") + else if (command == "banadd"_s) banaddaccount(parameters); - else if (command == "banset") + else if (command == "banset"_s) bansetaccount(parameters); - else if (command == "block") + else if (command == "block"_s) blockaccount(parameters); - else if (command == "check") + else if (command == "check"_s) checkaccount(parameters); - else if (command == "create") + else if (command == "create"_s) addaccount(parameters, 1); // 1: with email - else if (command == "delete") + else if (command == "delete"_s) delaccount(parameters); - else if (command == "email") + else if (command == "email"_s) changeemail(parameters); - else if (command == "getcount") + else if (command == "getcount"_s) getlogincount(); - else if (command == "gm") + else if (command == "gm"_s) changegmlevel(parameters); - else if (command == "id") + else if (command == "id"_s) idaccount(parameters); - else if (command == "info") + else if (command == "info"_s) infoaccount(atoi(parameters.c_str())); - else if (command == "kami") + else if (command == "kami"_s) sendbroadcast(parameters); // flag for normal - else if (command == "itemfrob") + else if (command == "itemfrob"_s) itemfrob(parameters); // 0: to list all - else if (command == "list") + else if (command == "list"_s) listaccount(parameters, 0); // 0: to list all - else if (command == "listban") + else if (command == "listban"_s) listaccount(parameters, 3); // 3: to list only accounts with state or bannished - else if (command == "listgm") + else if (command == "listgm"_s) listaccount(parameters, 1); // 1: to list only GM - else if (command == "listok") + else if (command == "listok"_s) listaccount(parameters, 4); // 4: to list only accounts without state and not bannished - else if (command == "memo") + else if (command == "memo"_s) changememo(parameters); - else if (command == "name") + else if (command == "name"_s) nameaccount(atoi(parameters.c_str())); - else if (command == "password") + else if (command == "password"_s) changepasswd(parameters); - else if (command == "reloadgm") + else if (command == "reloadgm"_s) reloadGM(parameters); - else if (command == "search") + else if (command == "search"_s) listaccount(parameters, 2); // 2: to list with pattern - else if (command == "sex") + else if (command == "sex"_s) changesex(parameters); - else if (command == "state") + else if (command == "state"_s) changestate(parameters); - else if (command == "timeadd") + else if (command == "timeadd"_s) timeaddaccount(parameters); - else if (command == "timeset") + else if (command == "timeset"_s) timesetaccount(parameters); - else if (command == "unban") + else if (command == "unban"_s) unbanaccount(parameters); - else if (command == "unblock") + else if (command == "unblock"_s) unblockaccount(parameters); - else if (command == "version") + else if (command == "version"_s) checkloginversion(); - else if (command == "who") + else if (command == "who"_s) whoaccount(parameters); - else if (command == "quit" - || command == "exit" - || command == "end") + else if (command == "quit"_s + || command == "exit"_s + || command == "end"_s) { - PRINTF("Bye.\n"); + PRINTF("Bye.\n"_fmt); exit(0); } else { - PRINTF("Unknown command [%s].\n", buf); - LADMIN_LOG("Unknown command [%s].\n", buf); + PRINTF("Unknown command [%s].\n"_fmt, buf); + LADMIN_LOG("Unknown command [%s].\n"_fmt, buf); } } } @@ -1942,16 +1942,14 @@ void parse_fromlogin(Session *s) { if (s->eof) { - PRINTF("Impossible to have a connection with the login-server [%s:%d] !\n", + PRINTF("Impossible to have a connection with the login-server [%s:%d] !\n"_fmt, login_ip, login_port); - LADMIN_LOG("Impossible to have a connection with the login-server [%s:%d] !\n", + LADMIN_LOG("Impossible to have a connection with the login-server [%s:%d] !\n"_fmt, login_ip, login_port); delete_session(s); exit(0); } -// PRINTF("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0)); - while (RFIFOREST(s) >= 2) { switch (RFIFOW(s, 0)) @@ -1961,20 +1959,20 @@ void parse_fromlogin(Session *s) return; if (RFIFOB(s, 2) != 0) { - PRINTF("Error at login:\n"); - PRINTF(" - incorrect password,\n"); - PRINTF(" - administration system not activated, or\n"); - PRINTF(" - unauthorised IP.\n"); - LADMIN_LOG("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n"); + PRINTF("Error at login:\n"_fmt); + PRINTF(" - incorrect password,\n"_fmt); + PRINTF(" - administration system not activated, or\n"_fmt); + PRINTF(" - unauthorised IP.\n"_fmt); + LADMIN_LOG("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n"_fmt); s->eof = 1; //bytes_to_read = 1; // not stop at prompt } else { - Iprintf("Established connection.\n"); - LADMIN_LOG("Established connection.\n"); - Iprintf("Reading of the version of the login-server...\n"); - LADMIN_LOG("Reading of the version of the login-server...\n"); + Iprintf("Established connection.\n"_fmt); + LADMIN_LOG("Established connection.\n"_fmt); + Iprintf("Reading of the version of the login-server...\n"_fmt); + LADMIN_LOG("Reading of the version of the login-server...\n"_fmt); //bytes_to_read = 1; // unchanged checkloginversion(); } @@ -1985,11 +1983,11 @@ void parse_fromlogin(Session *s) if (RFIFOREST(s) < 10) return; { - Iprintf(" Login-Server [%s:%d]\n", + Iprintf(" Login-Server [%s:%d]\n"_fmt, login_ip, login_port); Version version; RFIFO_STRUCT(login_session, 2, version); - Iprintf(" tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n", + Iprintf(" tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n"_fmt, version.major, version.minor, version.patch, version.devel, @@ -2010,23 +2008,23 @@ void parse_fromlogin(Session *s) return; if (RFIFOW(s, 2) < 5) { - LADMIN_LOG(" Receiving of a void accounts list.\n"); + LADMIN_LOG(" Receiving of a void accounts list.\n"_fmt); if (list_count == 0) { - Iprintf("No account found.\n"); + Iprintf("No account found.\n"_fmt); } else if (list_count == 1) { - Iprintf("1 account found.\n"); + Iprintf("1 account found.\n"_fmt); } else - Iprintf("%d accounts found.\n", list_count); + Iprintf("%d accounts found.\n"_fmt, list_count); bytes_to_read = 0; } else { int i; - LADMIN_LOG(" Receiving of a accounts list.\n"); + LADMIN_LOG(" Receiving of a accounts list.\n"_fmt); for (i = 4; i < RFIFOW(s, 2); i += 38) { AccountName userid = stringish<AccountName>(RFIFO_STRING<24>(s, i + 5)); @@ -2039,63 +2037,63 @@ void parse_fromlogin(Session *s) || (list_type == 3 && RFIFOL(s, i + 34) != 0) || (list_type == 4 && RFIFOL(s, i + 34) == 0)) { - PRINTF("%10d ", RFIFOL(s, i)); + PRINTF("%10d "_fmt, RFIFOL(s, i)); if (RFIFOB(s, i + 4) == 0) - PRINTF(" "); + PRINTF(" "_fmt); else - PRINTF("%2d ", RFIFOB(s, i + 4)); - PRINTF("%-24s", userid); + PRINTF("%2d "_fmt, RFIFOB(s, i + 4)); + PRINTF("%-24s"_fmt, userid); if (RFIFOB(s, i + 29) == 0) - PRINTF("%-5s ", "Femal"); + PRINTF("%-5s "_fmt, "Femal"_s); else if (RFIFOB(s, i + 29) == 1) - PRINTF("%-5s ", "Male"); + PRINTF("%-5s "_fmt, "Male"_s); else - PRINTF("%-5s ", "Servr"); - PRINTF("%6d ", RFIFOL(s, i + 30)); + PRINTF("%-5s "_fmt, "Servr"_s); + PRINTF("%6d "_fmt, RFIFOL(s, i + 30)); switch (RFIFOL(s, i + 34)) { case 0: - PRINTF("%-27s\n", "Account OK"); + PRINTF("%-27s\n"_fmt, "Account OK"_s); break; case 1: - PRINTF("%-27s\n", "Unregistered ID"); + PRINTF("%-27s\n"_fmt, "Unregistered ID"_s); break; case 2: - PRINTF("%-27s\n", "Incorrect Password"); + PRINTF("%-27s\n"_fmt, "Incorrect Password"_s); break; case 3: - PRINTF("%-27s\n", "This ID is expired"); + PRINTF("%-27s\n"_fmt, "This ID is expired"_s); break; case 4: - PRINTF("%-27s\n", - "Rejected from Server"); + PRINTF("%-27s\n"_fmt, + "Rejected from Server"_s); break; case 5: - PRINTF("%-27s\n", "Blocked by the GM Team"); // You have been blocked by the GM Team + PRINTF("%-27s\n"_fmt, "Blocked by the GM Team"_s); // You have been blocked by the GM Team break; case 6: - PRINTF("%-27s\n", "Your EXE file is too old"); // Your Game's EXE file is not the latest version + PRINTF("%-27s\n"_fmt, "Your EXE file is too old"_s); // Your Game's EXE file is not the latest version break; case 7: - PRINTF("%-27s\n", "Banishement or"); - PRINTF(" Prohibited to login until...\n"); // You are Prohibited to log in until %s + PRINTF("%-27s\n"_fmt, "Banishement or"_s); + PRINTF(" Prohibited to login until...\n"_fmt); // You are Prohibited to log in until %s break; case 8: - PRINTF("%-27s\n", - "Server is over populated"); + PRINTF("%-27s\n"_fmt, + "Server is over populated"_s); break; case 9: - PRINTF("%-27s\n", "No MSG"); + PRINTF("%-27s\n"_fmt, "No MSG"_s); break; default: // 100 - PRINTF("%-27s\n", "This ID is totally erased"); // This ID has been totally erased + PRINTF("%-27s\n"_fmt, "This ID is totally erased"_s); // This ID has been totally erased break; } list_count++; } } // asking of the following acounts - LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d (complement).\n", + LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d (complement).\n"_fmt, list_first, list_last); WFIFOW(login_session, 0) = 0x7920; WFIFOL(login_session, 2) = list_first; @@ -2114,16 +2112,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (accid == -1) { - PRINTF("Account [%s] creation failed. Same account already exists.\n", + PRINTF("Account [%s] creation failed. Same account already exists.\n"_fmt, name); - LADMIN_LOG("Account [%s] creation failed. Same account already exists.\n", + LADMIN_LOG("Account [%s] creation failed. Same account already exists.\n"_fmt, name); } else { - PRINTF("Account [%s] is successfully created [id: %d].\n", + PRINTF("Account [%s] is successfully created [id: %d].\n"_fmt, name, accid); - LADMIN_LOG("Account [%s] is successfully created [id: %d].\n", + LADMIN_LOG("Account [%s] is successfully created [id: %d].\n"_fmt, name, accid); } bytes_to_read = 0; @@ -2139,16 +2137,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (accid == -1) { - PRINTF("Account [%s] deletion failed. Account doesn't exist.\n", + PRINTF("Account [%s] deletion failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] deletion failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] deletion failed. Account doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] is successfully DELETED.\n", + PRINTF("Account [%s][id: %d] is successfully DELETED.\n"_fmt, name, accid); - LADMIN_LOG("Account [%s][id: %d] is successfully DELETED.\n", + LADMIN_LOG("Account [%s][id: %d] is successfully DELETED.\n"_fmt, name, accid); } bytes_to_read = 0; @@ -2164,18 +2162,18 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (accid == -1) { - PRINTF("Account [%s] password changing failed.\n", + PRINTF("Account [%s] password changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist.\n", + PRINTF("Account [%s] doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account password changing failed. The compte [%s] doesn't exist.\n", + LADMIN_LOG("Account password changing failed. The compte [%s] doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] password successfully changed.\n", + PRINTF("Account [%s][id: %d] password successfully changed.\n"_fmt, name, accid); - LADMIN_LOG("Account [%s][id: %d] password successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] password successfully changed.\n"_fmt, name, accid); } bytes_to_read = 0; @@ -2192,57 +2190,57 @@ void parse_fromlogin(Session *s) int state = RFIFOL(s, 30); if (accid == -1) { - PRINTF("Account [%s] state changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] state changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] state changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] state changing failed. Account doesn't exist.\n"_fmt, name); } else { MString tmpstr; tmpstr += STRPRINTF( - "Account [%s] state successfully changed in [", + "Account [%s] state successfully changed in ["_fmt, name); switch (state) { case 0: - tmpstr += "0: Account OK"; + tmpstr += "0: Account OK"_s; break; case 1: - tmpstr += "1: Unregistered ID"; + tmpstr += "1: Unregistered ID"_s; break; case 2: - tmpstr += "2: Incorrect Password"; + tmpstr += "2: Incorrect Password"_s; break; case 3: - tmpstr += "3: This ID is expired"; + tmpstr += "3: This ID is expired"_s; break; case 4: - tmpstr += "4: Rejected from Server"; + tmpstr += "4: Rejected from Server"_s; break; case 5: - tmpstr += "5: You have been blocked by the GM Team"; + tmpstr += "5: You have been blocked by the GM Team"_s; break; case 6: - tmpstr += "6: [Your Game's EXE file is not the latest version"; + tmpstr += "6: [Your Game's EXE file is not the latest version"_s; break; case 7: - tmpstr += "7: You are Prohibited to log in until..."; + tmpstr += "7: You are Prohibited to log in until..."_s; break; case 8: - tmpstr += "8: Server is jammed due to over populated"; + tmpstr += "8: Server is jammed due to over populated"_s; break; case 9: - tmpstr += "9: No MSG"; + tmpstr += "9: No MSG"_s; break; default: // 100 - tmpstr += "100: This ID is totally erased"; + tmpstr += "100: This ID is totally erased"_s; break; } tmpstr += ']'; AString tmpstr_ = AString(tmpstr); - PRINTF("%s\n", tmpstr_); - LADMIN_LOG("%s\n", tmpstr_); + PRINTF("%s\n"_fmt, tmpstr_); + LADMIN_LOG("%s\n"_fmt, tmpstr_); } bytes_to_read = 0; } @@ -2254,20 +2252,20 @@ void parse_fromlogin(Session *s) return; { // Get length of the received packet - LADMIN_LOG(" Receiving of the number of online players.\n"); + LADMIN_LOG(" Receiving of the number of online players.\n"_fmt); // Read information of the servers if (RFIFOW(s, 2) < 5) { - PRINTF(" No server is connected to the login-server.\n"); + PRINTF(" No server is connected to the login-server.\n"_fmt); } else { - PRINTF(" Number of online players (server: number).\n"); + PRINTF(" Number of online players (server: number).\n"_fmt); // Displaying of result for (int i = 4; i < RFIFOW(s, 2); i += 32) { ServerName name = stringish<ServerName>(RFIFO_STRING<20>(s, i + 6)); - PRINTF(" %-20s : %5d\n", name, + PRINTF(" %-20s : %5d\n"_fmt, name, RFIFOW(s, i + 26)); } } @@ -2284,16 +2282,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("The account [%s] doesn't exist or the password is incorrect.\n", + PRINTF("The account [%s] doesn't exist or the password is incorrect.\n"_fmt, name); - LADMIN_LOG("The account [%s] doesn't exist or the password is incorrect.\n", + LADMIN_LOG("The account [%s] doesn't exist or the password is incorrect.\n"_fmt, name); } else { - PRINTF("The proposed password is correct for the account [%s][id: %d].\n", + PRINTF("The proposed password is correct for the account [%s][id: %d].\n"_fmt, name, account_id); - LADMIN_LOG("The proposed password is correct for the account [%s][id: %d].\n", + LADMIN_LOG("The proposed password is correct for the account [%s][id: %d].\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2309,18 +2307,18 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] sex changing failed.\n", + PRINTF("Account [%s] sex changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist or the sex is already the good sex.\n", + PRINTF("Account [%s] doesn't exist or the sex is already the good sex.\n"_fmt, name); - LADMIN_LOG("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n", + LADMIN_LOG("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] sex successfully changed.\n", + PRINTF("Account [%s][id: %d] sex successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] sex successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] sex successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2336,19 +2334,19 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] GM level changing failed.\n", + PRINTF("Account [%s] GM level changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist, the GM level is already the good GM level\n", + PRINTF("Account [%s] doesn't exist, the GM level is already the good GM level\n"_fmt, name); - PRINTF("or it's impossible to modify the GM accounts file.\n"); - LADMIN_LOG("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n", + PRINTF("or it's impossible to modify the GM accounts file.\n"_fmt); + LADMIN_LOG("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] GM level successfully changed.\n", + PRINTF("Account [%s][id: %d] GM level successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] GM level successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] GM level successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2364,18 +2362,18 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] e-mail changing failed.\n", + PRINTF("Account [%s] e-mail changing failed.\n"_fmt, name); - PRINTF("Account [%s] doesn't exist.\n", + PRINTF("Account [%s] doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account e-mail changing failed. The compte [%s] doesn't exist.\n", + LADMIN_LOG("Account e-mail changing failed. The compte [%s] doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] e-mail successfully changed.\n", + PRINTF("Account [%s][id: %d] e-mail successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] e-mail successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] e-mail successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2391,16 +2389,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] memo changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] memo changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] memo changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] memo changing failed. Account doesn't exist.\n"_fmt, name); } else { - PRINTF("Account [%s][id: %d] memo successfully changed.\n", + PRINTF("Account [%s][id: %d] memo successfully changed.\n"_fmt, name, account_id); - LADMIN_LOG("Account [%s][id: %d] memo successfully changed.\n", + LADMIN_LOG("Account [%s][id: %d] memo successfully changed.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2416,16 +2414,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Unable to find the account [%s] id. Account doesn't exist.\n", + PRINTF("Unable to find the account [%s] id. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Unable to find the account [%s] id. Account doesn't exist.\n", + LADMIN_LOG("Unable to find the account [%s] id. Account doesn't exist.\n"_fmt, name); } else { - PRINTF("The account [%s] have the id: %d.\n", + PRINTF("The account [%s] have the id: %d.\n"_fmt, name, account_id); - LADMIN_LOG("The account [%s] have the id: %d.\n", + LADMIN_LOG("The account [%s] have the id: %d.\n"_fmt, name, account_id); } bytes_to_read = 0; @@ -2441,16 +2439,16 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (!name) { - PRINTF("Unable to find the account [%d] name. Account doesn't exist.\n", + PRINTF("Unable to find the account [%d] name. Account doesn't exist.\n"_fmt, account_id); - LADMIN_LOG("Unable to find the account [%d] name. Account doesn't exist.\n", + LADMIN_LOG("Unable to find the account [%d] name. Account doesn't exist.\n"_fmt, account_id); } else { - PRINTF("The account [id: %d] have the name: %s.\n", + PRINTF("The account [id: %d] have the name: %s.\n"_fmt, account_id, name); - LADMIN_LOG("The account [id: %d] have the name: %s.\n", + LADMIN_LOG("The account [id: %d] have the name: %s.\n"_fmt, account_id, name); } bytes_to_read = 0; @@ -2466,9 +2464,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (RFIFOL(s, 2) == -1) { - PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2476,18 +2474,18 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n", + PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n"_fmt, name, account_id); - LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n", + LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); - LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); } @@ -2505,9 +2503,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2515,18 +2513,18 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, RFIFOL(s, 2), tmpstr); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, RFIFOL(s, 2), tmpstr); } @@ -2544,9 +2542,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2554,19 +2552,19 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); } @@ -2581,13 +2579,13 @@ void parse_fromlogin(Session *s) return; if (RFIFOW(s, 2) == static_cast<uint16_t>(-1)) { - PRINTF("Message sending failed. No online char-server.\n"); - LADMIN_LOG("Message sending failed. No online char-server.\n"); + PRINTF("Message sending failed. No online char-server.\n"_fmt); + LADMIN_LOG("Message sending failed. No online char-server.\n"_fmt); } else { - PRINTF("Message successfully sended to login-server.\n"); - LADMIN_LOG("Message successfully sended to login-server.\n"); + PRINTF("Message successfully sended to login-server.\n"_fmt); + LADMIN_LOG("Message successfully sended to login-server.\n"_fmt); } bytes_to_read = 0; RFIFOSKIP(s, 4); @@ -2601,9 +2599,9 @@ void parse_fromlogin(Session *s) AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); if (account_id == -1) { - PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n", + PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); - LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n", + LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n"_fmt, name); } else @@ -2611,21 +2609,21 @@ void parse_fromlogin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); if (!timestamp) { - PRINTF("Validity limit of the account [%s][id: %d] unchanged.\n", + PRINTF("Validity limit of the account [%s][id: %d] unchanged.\n"_fmt, name, account_id); - PRINTF("The account have an unlimited validity limit or\n"); - PRINTF("the changing is impossible with the proposed adjustments.\n"); - LADMIN_LOG("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n", + PRINTF("The account have an unlimited validity limit or\n"_fmt); + PRINTF("the changing is impossible with the proposed adjustments.\n"_fmt); + LADMIN_LOG("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n"_fmt, name, account_id); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, ×tamp); - PRINTF("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n", + PRINTF("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); - LADMIN_LOG("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n", + LADMIN_LOG("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n"_fmt, name, account_id, tmpstr); } @@ -2655,107 +2653,107 @@ void parse_fromlogin(Session *s) AString memo = RFIFO_STRING(s, 150, RFIFOW(s, 148)); if (account_id == -1) { - PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n", + PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n"_fmt, userid); - LADMIN_LOG("Unabled to find the account [%s]. Account doesn't exist.\n", + LADMIN_LOG("Unabled to find the account [%s]. Account doesn't exist.\n"_fmt, userid); } else if (!userid) { - PRINTF("Unabled to find the account [id: %d]. Account doesn't exist.\n", + PRINTF("Unabled to find the account [id: %d]. Account doesn't exist.\n"_fmt, account_id); - LADMIN_LOG("Unabled to find the account [id: %d]. Account doesn't exist.\n", + LADMIN_LOG("Unabled to find the account [id: %d]. Account doesn't exist.\n"_fmt, account_id); } else { - LADMIN_LOG("Receiving information about an account.\n"); - PRINTF("The account is set with:\n"); + LADMIN_LOG("Receiving information about an account.\n"_fmt); + PRINTF("The account is set with:\n"_fmt); if (!gm) { - PRINTF(" Id: %d (non-GM)\n", account_id); + PRINTF(" Id: %d (non-GM)\n"_fmt, account_id); } else { - PRINTF(" Id: %d (GM level %d)\n", + PRINTF(" Id: %d (GM level %d)\n"_fmt, account_id, gm); } - PRINTF(" Name: '%s'\n", userid); + PRINTF(" Name: '%s'\n"_fmt, userid); if (sex == 0) - PRINTF(" Sex: Female\n"); + PRINTF(" Sex: Female\n"_fmt); else if (sex == 1) - PRINTF(" Sex: Male\n"); + PRINTF(" Sex: Male\n"_fmt); else - PRINTF(" Sex: Server\n"); - PRINTF(" E-mail: %s\n", email); + PRINTF(" Sex: Server\n"_fmt); + PRINTF(" E-mail: %s\n"_fmt, email); switch (state) { case 0: - PRINTF(" Statut: 0 [Account OK]\n"); + PRINTF(" Statut: 0 [Account OK]\n"_fmt); break; case 1: - PRINTF(" Statut: 1 [Unregistered ID]\n"); + PRINTF(" Statut: 1 [Unregistered ID]\n"_fmt); break; case 2: - PRINTF(" Statut: 2 [Incorrect Password]\n"); + PRINTF(" Statut: 2 [Incorrect Password]\n"_fmt); break; case 3: - PRINTF(" Statut: 3 [This ID is expired]\n"); + PRINTF(" Statut: 3 [This ID is expired]\n"_fmt); break; case 4: - PRINTF(" Statut: 4 [Rejected from Server]\n"); + PRINTF(" Statut: 4 [Rejected from Server]\n"_fmt); break; case 5: - PRINTF(" Statut: 5 [You have been blocked by the GM Team]\n"); + PRINTF(" Statut: 5 [You have been blocked by the GM Team]\n"_fmt); break; case 6: - PRINTF(" Statut: 6 [Your Game's EXE file is not the latest version]\n"); + PRINTF(" Statut: 6 [Your Game's EXE file is not the latest version]\n"_fmt); break; case 7: - PRINTF(" Statut: 7 [You are Prohibited to log in until %s]\n", + PRINTF(" Statut: 7 [You are Prohibited to log in until %s]\n"_fmt, error_message); break; case 8: - PRINTF(" Statut: 8 [Server is jammed due to over populated]\n"); + PRINTF(" Statut: 8 [Server is jammed due to over populated]\n"_fmt); break; case 9: - PRINTF(" Statut: 9 [No MSG]\n"); + PRINTF(" Statut: 9 [No MSG]\n"_fmt); break; default: // 100 - PRINTF(" Statut: %d [This ID is totally erased]\n", + PRINTF(" Statut: %d [This ID is totally erased]\n"_fmt, state); break; } if (!ban_until_time) { - PRINTF(" Banishment: not banished.\n"); + PRINTF(" Banishment: not banished.\n"_fmt); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, &ban_until_time); - PRINTF(" Banishment: until %s.\n", tmpstr); + PRINTF(" Banishment: until %s.\n"_fmt, tmpstr); } if (connections > 1) - PRINTF(" Count: %d connections.\n", + PRINTF(" Count: %d connections.\n"_fmt, connections); else - PRINTF(" Count: %d connection.\n", + PRINTF(" Count: %d connection.\n"_fmt, connections); - PRINTF(" Last connection at: %s (ip: %s)\n", + PRINTF(" Last connection at: %s (ip: %s)\n"_fmt, lastlogin, last_ip_); if (!connect_until_time) { - PRINTF(" Validity limit: unlimited.\n"); + PRINTF(" Validity limit: unlimited.\n"_fmt); } else { timestamp_seconds_buffer tmpstr; stamp_time(tmpstr, &connect_until_time); - PRINTF(" Validity limit: until %s.\n", + PRINTF(" Validity limit: until %s.\n"_fmt, tmpstr); } - PRINTF(" Memo: '%s'\n", memo); + PRINTF(" Memo: '%s'\n"_fmt, memo); } } bytes_to_read = 0; @@ -2763,8 +2761,8 @@ void parse_fromlogin(Session *s) break; default: - PRINTF("Remote administration has been disconnected (unknown packet).\n"); - LADMIN_LOG("'End of connection, unknown packet.\n"); + PRINTF("Remote administration has been disconnected (unknown packet).\n"_fmt); + LADMIN_LOG("'End of connection, unknown packet.\n"_fmt); s->eof = 1; return; } @@ -2780,8 +2778,8 @@ void parse_fromlogin(Session *s) static int Connect_login_server(void) { - Iprintf("Attempt to connect to login-server...\n"); - LADMIN_LOG("Attempt to connect to login-server...\n"); + Iprintf("Attempt to connect to login-server...\n"_fmt); + LADMIN_LOG("Attempt to connect to login-server...\n"_fmt); login_session = make_connection(login_ip, login_port); if (!login_session) @@ -2794,8 +2792,8 @@ int Connect_login_server(void) WFIFOSET(login_session, 28); bytes_to_read = 1; - Iprintf("Sending of the password...\n"); - LADMIN_LOG("Sending of the password...\n"); + Iprintf("Sending of the password...\n"_fmt); + LADMIN_LOG("Sending of the password...\n"_fmt); } return 0; @@ -2805,12 +2803,12 @@ static bool admin_confs(XString w1, ZString w2) { { - if (w1 == "login_ip") + if (w1 == "login_ip"_s) { struct hostent *h = gethostbyname(w2.c_str()); if (h != NULL) { - Iprintf("Login server IP address: %s -> %s\n", + Iprintf("Login server IP address: %s -> %s\n"_fmt, w2, login_ip); login_ip = IP4Address({ static_cast<uint8_t>(h->h_addr[0]), @@ -2820,21 +2818,21 @@ bool admin_confs(XString w1, ZString w2) }); } } - else if (w1 == "login_port") + else if (w1 == "login_port"_s) { login_port = atoi(w2.c_str()); } - else if (w1 == "admin_pass") + else if (w1 == "admin_pass"_s) { admin_pass = stringish<AccountPass>(w2); } - else if (w1 == "ladmin_log_filename") + else if (w1 == "ladmin_log_filename"_s) { ladmin_log_filename = w2; } else { - PRINTF("WARNING: unknown ladmin config key: %s\n", AString(w1)); + PRINTF("WARNING: unknown ladmin config key: %s\n"_fmt, AString(w1)); return false; } } @@ -2851,8 +2849,8 @@ void term_func(void) { delete_session(login_session); - Iprintf(SGR_RESET "----End of Ladmin (normal end with closing of all files).\n"); - LADMIN_LOG("----End of Ladmin (normal end with closing of all files).\n"); + Iprintf(SGR_RESET "----End of Ladmin (normal end with closing of all files).\n"_fmt); + LADMIN_LOG("----End of Ladmin (normal end with closing of all files).\n"_fmt); already_exit_function = 1; } @@ -2870,20 +2868,20 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -2895,26 +2893,26 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-admin.conf", admin_confs); + runflag &= load_config_file("conf/tmwa-admin.conf"_s, admin_confs); eathena_interactive_session = isatty(0); - LADMIN_LOG(""); - LADMIN_LOG("Configuration file readed.\n"); + LADMIN_LOG(""_fmt); + LADMIN_LOG("Configuration file readed.\n"_fmt); set_defaultparse(parse_fromlogin); - Iprintf("EAthena login-server administration tool.\n"); + Iprintf("EAthena login-server administration tool.\n"_fmt); Version version = CURRENT_LOGIN_SERVER_VERSION; - Iprintf("for tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n", + Iprintf("for tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n"_fmt, version.major, version.minor, version.patch, version.devel, version.flags, version.which, version.vend); - LADMIN_LOG("Ladmin is ready.\n"); - Iprintf("Ladmin is " SGR_BOLD SGR_GREEN "ready" SGR_RESET ".\n\n"); + LADMIN_LOG("Ladmin is ready.\n"_fmt); + Iprintf("Ladmin is " SGR_BOLD SGR_GREEN "ready" SGR_RESET ".\n\n"_fmt); Connect_login_server(); diff --git a/src/char/char.cpp b/src/char/char.cpp index d7849af..123ce3c 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -91,7 +91,7 @@ AccountPass passwd; static ServerName server_name; static -CharName wisp_server_name = stringish<CharName>("Server"); +CharName wisp_server_name = stringish<CharName>("Server"_s); static IP4Address login_ip; static @@ -103,9 +103,9 @@ int char_port = 6121; static AString char_txt; static -CharName unknown_char_name = stringish<CharName>("Unknown"); +CharName unknown_char_name = stringish<CharName>("Unknown"_s); static -AString char_log_filename = "log/char.log"; +AString char_log_filename = "log/char.log"_s; //Added for lan support static IP4Address lan_map_ip = IP4_LOCALHOST; @@ -160,16 +160,16 @@ std::chrono::milliseconds autosave_time = DEFAULT_AUTOSAVE_INTERVAL; // Initial position (it's possible to set it in conf file) static -struct point start_point = { {"001-1.gat"}, 273, 354 }; +struct point start_point = { {"001-1.gat"_s}, 273, 354 }; static std::vector<GM_Account> gm_accounts; // online players by [Yor] static -AString online_txt_filename = "online.txt"; +AString online_txt_filename = "online.txt"_s; static -AString online_html_filename = "online.html"; +AString online_html_filename = "online.html"_s; static int online_sorting_option = 0; // sorting option to display online players in online files static @@ -285,7 +285,7 @@ AString mmo_char_tostr(struct CharPair *cp) "%d,%d,%d\t" "%d,%d,%d,%d,%d\t" "%s,%d,%d\t" - "%s,%d,%d,%d\t", + "%s,%d,%d,%d\t"_fmt, k->char_id, k->account_id, k->char_num, k->name, @@ -307,7 +307,7 @@ AString mmo_char_tostr(struct CharPair *cp) for (int i = 0; i < MAX_INVENTORY; i++) if (p->inventory[i].nameid) { - str_p += STRPRINTF("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", + str_p += STRPRINTF("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d "_fmt, p->inventory[i].id, p->inventory[i].nameid, p->inventory[i].amount, @@ -329,7 +329,7 @@ AString mmo_char_tostr(struct CharPair *cp) for (SkillID i : erange(SkillID(), MAX_SKILL)) if (p->skill[i].lv) { - str_p += STRPRINTF("%d,%d ", + str_p += STRPRINTF("%d,%d "_fmt, i, p->skill[i].lv | (uint16_t(p->skill[i].flags) << 16)); } @@ -338,7 +338,7 @@ AString mmo_char_tostr(struct CharPair *cp) assert (p->global_reg_num < GLOBAL_REG_NUM); for (int i = 0; i < p->global_reg_num; i++) if (p->global_reg[i].str) - str_p += STRPRINTF("%s,%d ", + str_p += STRPRINTF("%s,%d "_fmt, p->global_reg[i].str, p->global_reg[i].value); str_p += '\t'; @@ -467,9 +467,9 @@ int mmo_char_init(void) io::ReadFile in(char_txt); if (!in.is_open()) { - PRINTF("Characters file not found: %s.\n", char_txt); - CHAR_LOG("Characters file not found: %s.\n", char_txt); - CHAR_LOG("Id for the next created character: %d.\n", + PRINTF("Characters file not found: %s.\n"_fmt, char_txt); + CHAR_LOG("Characters file not found: %s.\n"_fmt, char_txt); + CHAR_LOG("Id for the next created character: %d.\n"_fmt, char_id_count); return 0; } @@ -485,7 +485,7 @@ int mmo_char_init(void) { int i, j = 0; - if (SSCANF(line, "%d\t%%newid%%%n", &i, &j) == 1 && j > 0) + if (SSCANF(line, "%d\t%%newid%%%n"_fmt, &i, &j) == 1 && j > 0) { if (char_id_count < i) char_id_count = i; @@ -496,7 +496,7 @@ int mmo_char_init(void) CharPair cd; if (!extract(line, &cd)) { - CHAR_LOG("Char skipped\n%s", line); + CHAR_LOG("Char skipped\n%s"_fmt, line); continue; } if (cd.key.char_id >= char_id_count) @@ -505,12 +505,12 @@ int mmo_char_init(void) online_chars.push_back(nullptr); } - PRINTF("mmo_char_init: %zu characters read in %s.\n", + PRINTF("mmo_char_init: %zu characters read in %s.\n"_fmt, char_keys.size(), char_txt); - CHAR_LOG("mmo_char_init: %zu characters read in %s.\n", + CHAR_LOG("mmo_char_init: %zu characters read in %s.\n"_fmt, char_keys.size(), char_txt); - CHAR_LOG("Id for the next created character: %d.\n", + CHAR_LOG("Id for the next created character: %d.\n"_fmt, char_id_count); return 0; @@ -525,8 +525,8 @@ void mmo_char_sync(void) io::WriteLock fp(char_txt); if (!fp.is_open()) { - PRINTF("WARNING: Server can't not save characters.\n"); - CHAR_LOG("WARNING: Server can't not save characters.\n"); + PRINTF("WARNING: Server can't not save characters.\n"_fmt); + CHAR_LOG("WARNING: Server can't not save characters.\n"_fmt); return; } { @@ -536,7 +536,7 @@ void mmo_char_sync(void) AString line = mmo_char_tostr(&cd); fp.put_line(line); } - FPRINTF(fp, "%d\t%%newid%%\n", char_id_count); + FPRINTF(fp, "%d\t%%newid%%\n"_fmt, char_id_count); } } @@ -588,7 +588,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui // remove control characters from the name if (!name.to__actual().is_print()) { - CHAR_LOG("Make new char error (control char received in the name): (connection #%d, account: %d).\n", + CHAR_LOG("Make new char error (control char received in the name): (connection #%d, account: %d).\n"_fmt, s, sd->account_id); return nullptr; } @@ -596,7 +596,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui // Eliminate whitespace if (name.to__actual() != name.to__actual().strip()) { - CHAR_LOG("Make new char error (leading/trailing whitespace): (connection #%d, account: %d, name: '%s'.\n", + CHAR_LOG("Make new char error (leading/trailing whitespace): (connection #%d, account: %d, name: '%s'.\n"_fmt, s, sd->account_id, name); return nullptr; } @@ -604,7 +604,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui // check lenght of character name if (name.to__actual().size() < 4) { - CHAR_LOG("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n", + CHAR_LOG("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n"_fmt, s, sd->account_id, name); return nullptr; } @@ -616,7 +616,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui for (uint8_t c : name.to__actual()) if (!char_name_letters[c]) { - CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n", + CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n"_fmt, s, sd->account_id, name, c); return nullptr; } @@ -627,7 +627,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui for (uint8_t c : name.to__actual()) if (char_name_letters[c]) { - CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n", + CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n"_fmt, s, sd->account_id, name, c); return nullptr; } @@ -639,7 +639,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui hair_style >= 20 || hair_color >= 12) { - CHAR_LOG("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n", + CHAR_LOG("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n"_fmt, s, sd->account_id, slot, name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -652,7 +652,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui { if (stats[i] < 1 || stats[i] > 9) { - CHAR_LOG("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n", + CHAR_LOG("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n"_fmt, s, sd->account_id, slot, name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -665,7 +665,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui { if (cd.key.name == name) { - CHAR_LOG("Make new char error (name already exists): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n", + CHAR_LOG("Make new char error (name already exists): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n"_fmt, s, sd->account_id, slot, name, cd.key.name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -675,7 +675,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui if (cd.key.account_id == sd->account_id && cd.key.char_num == slot) { - CHAR_LOG("Make new char error (slot already used): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n", + CHAR_LOG("Make new char error (slot already used): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n"_fmt, s, sd->account_id, slot, name, cd.key.name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -686,7 +686,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui if (wisp_server_name == name) { - CHAR_LOG("Make new char error (name used is wisp name for server): (connection #%d, account: %d) slot %d, name: %s (actual name whisper server: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n", + CHAR_LOG("Make new char error (name used is wisp name for server): (connection #%d, account: %d) slot %d, name: %s (actual name whisper server: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n"_fmt, s, sd->account_id, slot, name, wisp_server_name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -696,7 +696,7 @@ CharPair *make_new_char(Session *s, CharName name, const uint8_t (&stats)[6], ui IP4Address ip = s->client_ip; - CHAR_LOG("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n", + CHAR_LOG("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n"_fmt, s, sd->account_id, slot, name, stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[0] + stats[1] + stats[2] + stats[3] + stats[4] + stats[5], @@ -767,17 +767,17 @@ void create_online_files(void) timestamp_seconds_buffer timetemp; stamp_time(timetemp); // write heading - FPRINTF(fp2, "<HTML>\n"); - FPRINTF(fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n", online_refresh_html); // update on client explorer every x seconds - FPRINTF(fp2, " <HEAD>\n"); - FPRINTF(fp2, " <TITLE>Online Players on %s</TITLE>\n", + FPRINTF(fp2, "<HTML>\n"_fmt); + FPRINTF(fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n"_fmt, online_refresh_html); // update on client explorer every x seconds + FPRINTF(fp2, " <HEAD>\n"_fmt); + FPRINTF(fp2, " <TITLE>Online Players on %s</TITLE>\n"_fmt, server_name); - FPRINTF(fp2, " </HEAD>\n"); - FPRINTF(fp2, " <BODY>\n"); - FPRINTF(fp2, " <H3>Online Players on %s (%s):</H3>\n", + FPRINTF(fp2, " </HEAD>\n"_fmt); + FPRINTF(fp2, " <BODY>\n"_fmt); + FPRINTF(fp2, " <H3>Online Players on %s (%s):</H3>\n"_fmt, server_name, timetemp); - FPRINTF(fp, "Online Players on %s (%s):\n", server_name, timetemp); - FPRINTF(fp, "\n"); + FPRINTF(fp, "Online Players on %s (%s):\n"_fmt, server_name, timetemp); + FPRINTF(fp, "\n"_fmt); int players = 0; // This used to be conditional on having any players, @@ -785,20 +785,20 @@ void create_online_files(void) //if (players > 0) { int j = 0; // count the number of characters for the txt version and to set the separate line - FPRINTF(fp2, " <table border=\"1\" cellspacing=\"1\">\n"); - FPRINTF(fp2, " <tr>\n"); + FPRINTF(fp2, " <table border=\"1\" cellspacing=\"1\">\n"_fmt); + FPRINTF(fp2, " <tr>\n"_fmt); { - FPRINTF(fp2, " <th>Name</th>\n"); + FPRINTF(fp2, " <th>Name</th>\n"_fmt); { - FPRINTF(fp, "Name "); // 30 + FPRINTF(fp, "Name "_fmt); // 30 j += 30; } } - FPRINTF(fp2, " </tr>\n"); - FPRINTF(fp, "\n"); + FPRINTF(fp2, " </tr>\n"_fmt); + FPRINTF(fp, "\n"_fmt); for (int k = 0; k < j; k++) - FPRINTF(fp, "-"); - FPRINTF(fp, "\n"); + FPRINTF(fp, "-"_fmt); + FPRINTF(fp, "\n"_fmt); // display each player. for (CharPair& cd : char_keys) @@ -806,55 +806,55 @@ void create_online_files(void) if (!server_for(&cd)) continue; players++; - FPRINTF(fp2, " <tr>\n"); + FPRINTF(fp2, " <tr>\n"_fmt); // displaying the character name { // without/with 'GM' display int gml = isGM(cd.key.account_id); { if (gml >= online_gm_display_min_level) - FPRINTF(fp, "%-24s (GM) ", cd.key.name); + FPRINTF(fp, "%-24s (GM) "_fmt, cd.key.name); else - FPRINTF(fp, "%-24s ", cd.key.name); + FPRINTF(fp, "%-24s "_fmt, cd.key.name); } // name of the character in the html (no < >, because that create problem in html code) - FPRINTF(fp2, " <td>"); + FPRINTF(fp2, " <td>"_fmt); if (gml >= online_gm_display_min_level) - FPRINTF(fp2, "<b>"); + FPRINTF(fp2, "<b>"_fmt); for (char c : cd.key.name.to__actual()) { switch (c) { case '&': - FPRINTF(fp2, "&"); + FPRINTF(fp2, "&"_fmt); break; case '<': - FPRINTF(fp2, "<"); + FPRINTF(fp2, "<"_fmt); break; case '>': - FPRINTF(fp2, ">"); + FPRINTF(fp2, ">"_fmt); break; default: - FPRINTF(fp2, "%c", c); + FPRINTF(fp2, "%c"_fmt, c); break; }; } if (gml >= online_gm_display_min_level) - FPRINTF(fp2, "</b> (GM)"); - FPRINTF(fp2, "</td>\n"); + FPRINTF(fp2, "</b> (GM)"_fmt); + FPRINTF(fp2, "</td>\n"_fmt); } - FPRINTF(fp, "\n"); - FPRINTF(fp2, " </tr>\n"); + FPRINTF(fp, "\n"_fmt); + FPRINTF(fp2, " </tr>\n"_fmt); } - FPRINTF(fp2, " </table>\n"); - FPRINTF(fp, "\n"); + FPRINTF(fp2, " </table>\n"_fmt); + FPRINTF(fp, "\n"_fmt); } // Displaying number of online players if (players == 0) { - FPRINTF(fp2, " <p>No user is online.</p>\n"); - FPRINTF(fp, "No user is online.\n"); + FPRINTF(fp2, " <p>No user is online.</p>\n"_fmt); + FPRINTF(fp, "No user is online.\n"_fmt); } else if (players == 1) { @@ -862,11 +862,11 @@ void create_online_files(void) } else { - FPRINTF(fp2, " <p>%d users are online.</p>\n", players); - FPRINTF(fp, "%d users are online.\n", players); + FPRINTF(fp2, " <p>%d users are online.</p>\n"_fmt, players); + FPRINTF(fp, "%d users are online.\n"_fmt, players); } - FPRINTF(fp2, " </BODY>\n"); - FPRINTF(fp2, "</HTML>\n"); + FPRINTF(fp2, " </BODY>\n"_fmt); + FPRINTF(fp2, "</HTML>\n"_fmt); } } @@ -1120,7 +1120,7 @@ void parse_tologin(Session *ls) { if (ls == login_session) { - PRINTF("Char-server can't connect to login-server (connection #%d).\n", + PRINTF("Char-server can't connect to login-server (connection #%d).\n"_fmt, ls); login_session = nullptr; } @@ -1132,8 +1132,6 @@ void parse_tologin(Session *ls) while (RFIFOREST(ls) >= 2) { -// PRINTF("parse_tologin: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd)); - switch (RFIFOW(ls, 0)) { case 0x2711: @@ -1141,16 +1139,15 @@ void parse_tologin(Session *ls) return; if (RFIFOB(ls, 2)) { -// PRINTF("connect login server error : %d\n", RFIFOB(fd,2)); - PRINTF("Can not connect to login-server.\n"); - PRINTF("The server communication passwords (default s1/p1) is probably invalid.\n"); - PRINTF("Also, please make sure your accounts file (default: accounts.txt) has those values present.\n"); - PRINTF("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n"); + PRINTF("Can not connect to login-server.\n"_fmt); + PRINTF("The server communication passwords (default s1/p1) is probably invalid.\n"_fmt); + PRINTF("Also, please make sure your accounts file (default: accounts.txt) has those values present.\n"_fmt); + PRINTF("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n"_fmt); exit(1); } else { - PRINTF("Connected to login-server (connection #%d).\n", + PRINTF("Connected to login-server (connection #%d).\n"_fmt, ls); // if no map-server already connected, display a message... int i; @@ -1158,7 +1155,7 @@ void parse_tologin(Session *ls) if (server_session[i] && server[i].maps[0]) // if map-server online and at least 1 map break; if (i == MAX_MAP_SERVERS) - PRINTF("Awaiting maps from map-server.\n"); + PRINTF("Awaiting maps from map-server.\n"_fmt); } RFIFOSKIP(ls, 3); break; @@ -1166,7 +1163,6 @@ void parse_tologin(Session *ls) case 0x2713: if (RFIFOREST(ls) < 51) return; -// PRINTF("parse_tologin 2713 : %d\n", RFIFOB(fd,6)); for (io::FD i : iter_fds()) { Session *s2 = get_session(i); @@ -1184,10 +1180,6 @@ void parse_tologin(Session *ls) else if (max_connect_user == 0 || count_users() < max_connect_user) { -// if (max_connect_user == 0) -// PRINTF("max_connect_user (unlimited) -> accepted.\n"); -// else -// PRINTF("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user); sd->email = stringish<AccountEmail>(RFIFO_STRING<40>(ls, 7)); if (!e_mail_check(sd->email)) sd->email = DEFAULT_EMAIL; @@ -1198,7 +1190,6 @@ void parse_tologin(Session *ls) else { // refuse connection: too much online players -// PRINTF("count_users(): %d < max_connect_use (%d) -> fail...\n", count_users(), max_connect_user); WFIFOW(s2, 0) = 0x6c; WFIFOB(s2, 2) = 0; WFIFOSET(s2, 3); @@ -1243,7 +1234,6 @@ void parse_tologin(Session *ls) WBUFL(buf, 2) = RFIFOL(ls, 2); // account WBUFL(buf, 6) = RFIFOL(ls, 6); // GM level mapif_sendall(buf, 10); -// PRINTF("parse_tologin: To become GM answer: char -> map.\n"); } RFIFOSKIP(ls, 10); break; @@ -1295,7 +1285,7 @@ void parse_tologin(Session *ls) || RFIFOREST(ls) < (8 + RFIFOL(ls, 4))) return; if (RFIFOL(ls, 4) < 1) - CHAR_LOG("Receiving a message for broadcast, but message is void.\n"); + CHAR_LOG("Receiving a message for broadcast, but message is void.\n"_fmt); else { int i; @@ -1304,18 +1294,18 @@ void parse_tologin(Session *ls) if (server_session[i]) break; if (i == MAX_MAP_SERVERS) - CHAR_LOG("'ladmin': Receiving a message for broadcast, but no map-server is online.\n"); + CHAR_LOG("'ladmin': Receiving a message for broadcast, but no map-server is online.\n"_fmt); else { size_t len = RFIFOL(ls, 4); AString message = RFIFO_STRING(ls, 8, len).to_print().lstrip(); // if message is only composed of spaces if (!message) - CHAR_LOG("Receiving a message for broadcast, but message is only a lot of spaces.\n"); + CHAR_LOG("Receiving a message for broadcast, but message is only a lot of spaces.\n"_fmt); // else send message to all map-servers else { - CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n", + CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n"_fmt, message); // send broadcast to all map-servers uint8_t buf[4 + len]; @@ -1351,7 +1341,6 @@ void parse_tologin(Session *ls) RFIFO_BUF_CLONE(ls, buf, len); WBUFW(buf, 0) = 0x2b11; mapif_sendall(buf, len); -// PRINTF("char: save_account_reg_reply\n"); } RFIFOSKIP(ls, RFIFOW(ls, 2)); break; @@ -1392,7 +1381,7 @@ void parse_tologin(Session *ls) FIX(s->storage_[j].nameid); #undef FIX if (changes) - CHAR_LOG("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n", + CHAR_LOG("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n"_fmt, source_id, dest_id, k->name, k->char_id, k->account_id, changes); @@ -1478,9 +1467,9 @@ void parse_tologin(Session *ls) { gm_accounts.push_back({static_cast<int>(RFIFOL(ls, i)), RFIFOB(ls, i + 4)}); } - PRINTF("From login-server: receiving of %zu GM accounts information.\n", + PRINTF("From login-server: receiving of %zu GM accounts information.\n"_fmt, gm_accounts.size()); - CHAR_LOG("From login-server: receiving of %zu GM accounts information.\n", + CHAR_LOG("From login-server: receiving of %zu GM accounts information.\n"_fmt, gm_accounts.size()); create_online_files(); // update online players files (perhaps some online players change of GM level) // send new gm acccounts level to map-servers @@ -1534,17 +1523,15 @@ void map_anti_freeze_system(TimerData *, tick_t) { int i; - //PRINTF("Entering in map_anti_freeze_system function to check freeze of servers.\n"); for (i = 0; i < MAX_MAP_SERVERS; i++) { if (server_session[i]) { // if map-server is online - //PRINTF("map_anti_freeze_system: server #%d, flag: %d.\n", i, server_freezeflag[i]); if (server_freezeflag[i]-- < 1) { // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed - PRINTF("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n", + PRINTF("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n"_fmt, i); - CHAR_LOG("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n", + CHAR_LOG("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n"_fmt, i); server_session[i]->eof = 1; } @@ -1563,7 +1550,7 @@ void parse_frommap(Session *ms) { if (id < MAX_MAP_SERVERS) { - PRINTF("Map-server %d (session #%d) has disconnected.\n", id, + PRINTF("Map-server %d (session #%d) has disconnected.\n"_fmt, id, ms); server[id] = mmo_map_server{}; server_session[id] = nullptr; @@ -1578,8 +1565,6 @@ void parse_frommap(Session *ms) while (RFIFOREST(ms) >= 2) { -// PRINTF("parse_frommap: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd)); - switch (RFIFOW(ms, 0)) { // request from map-server to reload GM accounts. Transmission to login-server (by Yor) @@ -1606,10 +1591,10 @@ void parse_frommap(Session *ms) j++; } { - PRINTF("Map-Server %d connected: %d maps, from IP %s port %d.\n", + PRINTF("Map-Server %d connected: %d maps, from IP %s port %d.\n"_fmt, id, j, server[id].ip, server[id].port); - PRINTF("Map-server %d loading complete.\n", id); - CHAR_LOG("Map-Server %d connected: %d maps, from IP %s port %d. Map-server %d loading complete.\n", + PRINTF("Map-server %d loading complete.\n"_fmt, id); + CHAR_LOG("Map-Server %d connected: %d maps, from IP %s port %d. Map-server %d loading complete.\n"_fmt, id, j, server[id].ip, server[id].port, id); } @@ -1621,8 +1606,8 @@ void parse_frommap(Session *ms) unsigned char buf[16384]; if (j == 0) { - PRINTF("WARNING: Map-Server %d have NO map.\n", id); - CHAR_LOG("WARNING: Map-Server %d have NO map.\n", + PRINTF("WARNING: Map-Server %d have NO map.\n"_fmt, id); + CHAR_LOG("WARNING: Map-Server %d have NO map.\n"_fmt, id); // Transmitting maps information to the other map-servers } @@ -1671,7 +1656,6 @@ void parse_frommap(Session *ms) int login_id1 = RFIFOL(ms, 10); int login_id2 = RFIFOL(ms, 14); IP4Address ip = RFIFOIP(ms, 18); - //PRINTF("auth_fifo search: account: %d, char: %d, secure: %08x-%08x\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14)); for (AuthFifoEntry& afi : auth_fifo) { if (afi.account_id == account_id && @@ -1691,7 +1675,7 @@ void parse_frommap(Session *ms) break; } } - assert (cp && "uh-oh - deleted while in queue?"); + assert (cp && "uh-oh - deleted while in queue?"_s); CharKey *ck = &cp->key; CharData *cd = cp->data.get(); @@ -1705,12 +1689,11 @@ void parse_frommap(Session *ms) cd->sex = afi.sex; WFIFOW(ms, 16) = afi.packet_tmw_version; FPRINTF(stderr, - "From queue index %zd: recalling packet version %d\n", + "From queue index %zd: recalling packet version %d\n"_fmt, (&afi - &auth_fifo.front()), afi.packet_tmw_version); WFIFO_STRUCT(ms, 18, *ck); WFIFO_STRUCT(ms, 18 + sizeof(*ck), *cd); WFIFOSET(ms, WFIFOW(ms, 2)); - //PRINTF("auth_fifo search success (auth #%d, account %d, character: %d).\n", i, RFIFOL(fd,2), RFIFOL(fd,6)); goto x2afc_out; } } @@ -1718,7 +1701,7 @@ void parse_frommap(Session *ms) WFIFOW(ms, 0) = 0x2afe; WFIFOL(ms, 2) = account_id; WFIFOSET(ms, 6); - PRINTF("auth_fifo search error! account %d not authentified.\n", + PRINTF("auth_fifo search error! account %d not authentified.\n"_fmt, account_id); } } @@ -2055,7 +2038,7 @@ void parse_frommap(Session *ms) return; } // inter server処理でもない場合は切断 - PRINTF("char: unknown packet 0x%04x (%zu bytes to read in buffer)! (from map).\n", + PRINTF("char: unknown packet 0x%04x (%zu bytes to read in buffer)! (from map).\n"_fmt, RFIFOW(ms, 0), RFIFOREST(ms)); ms->eof = 1; return; @@ -2089,8 +2072,8 @@ int lan_ip_check(IP4Address addr) { bool lancheck = lan_subnet.covers(addr); - PRINTF("LAN test (result): %s.\n", - (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET); + PRINTF("LAN test (result): %s.\n"_fmt, + (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET ""_s : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET ""_s); return lancheck; } @@ -2112,7 +2095,7 @@ void handle_x0066(Session *s, struct char_session_data *sd, uint8_t rfifob_2, IP CharKey *ck = &cp->key; CharData *cd = cp->data.get(); - CHAR_LOG("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n", + CHAR_LOG("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n"_fmt, sd->account_id, rfifob_2, ck->name, ip); // searching map server @@ -2129,7 +2112,7 @@ void handle_x0066(Session *s, struct char_session_data *sd, uint8_t rfifob_2, IP { // change save point to one of map found on the server (the first) i = j; cd->last_point.map_ = server[j].maps[0]; - PRINTF("Map-server #%d found with a map: '%s'.\n", + PRINTF("Map-server #%d found with a map: '%s'.\n"_fmt, j, server[j].maps[0]); // coordonates are unknown break; @@ -2146,10 +2129,10 @@ void handle_x0066(Session *s, struct char_session_data *sd, uint8_t rfifob_2, IP WFIFOW(s, 0) = 0x71; WFIFOL(s, 2) = ck->char_id; WFIFO_STRING(s, 6, cd->last_point.map_, 16); - PRINTF("Character selection '%s' (account: %d, slot: %d) [%s]\n", + PRINTF("Character selection '%s' (account: %d, slot: %d) [%s]\n"_fmt, ck->name, sd->account_id, ck->char_num, ip); - PRINTF("--Send IP of map-server. "); + PRINTF("--Send IP of map-server. "_fmt); if (lan_ip_check(ip)) WFIFOIP(s, 22) = lan_map_ip; else @@ -2189,9 +2172,6 @@ void parse_char(Session *s) while (RFIFOREST(s) >= 2) { -// if (RFIFOW(fd,0) < 30000) -// PRINTF("parse_char: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd)); - switch (RFIFOW(s, 0)) { case 0x20b: //20040622暗号化ragexe対応 @@ -2222,16 +2202,16 @@ void parse_char(Session *s) int account_id = RFIFOL(s, 2); int GM_value = isGM(account_id); if (GM_value) - PRINTF("Account Logged On; Account ID: %d (GM level %d).\n", + PRINTF("Account Logged On; Account ID: %d (GM level %d).\n"_fmt, account_id, GM_value); else - PRINTF("Account Logged On; Account ID: %d.\n", + PRINTF("Account Logged On; Account ID: %d.\n"_fmt, account_id); if (sd == NULL) { s->session_data = make_unique<char_session_data, SessionDeleter>(); sd = static_cast<char_session_data *>(s->session_data.get()); - sd->email = stringish<AccountEmail>("no mail"); // put here a mail without '@' to refuse deletion if we don't receive the e-mail + sd->email = stringish<AccountEmail>("no mail"_s); // put here a mail without '@' to refuse deletion if we don't receive the e-mail sd->connect_until_time = TimeT(); // unknow or illimited (not displaying on map-server) } sd->account_id = account_id; @@ -2585,7 +2565,7 @@ void check_connect_login_server(TimerData *, tick_t) { if (!login_session) { - PRINTF("Attempt to connect to login-server...\n"); + PRINTF("Attempt to connect to login-server...\n"_fmt); login_session = make_connection(login_ip, login_port); if (!login_session) return; @@ -2615,7 +2595,7 @@ bool char_lan_config(XString w1, ZString w2) struct hostent *h = NULL; { - if (w1 == "lan_map_ip") + if (w1 == "lan_map_ip"_s) { // Read map-server Lan IP Address h = gethostbyname(w2.c_str()); @@ -2630,20 +2610,20 @@ bool char_lan_config(XString w1, ZString w2) } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } - PRINTF("LAN IP of map-server: %s.\n", lan_map_ip); + PRINTF("LAN IP of map-server: %s.\n"_fmt, lan_map_ip); } - else if (w1 == "subnet" /*backward compatibility*/ - || w1 == "lan_subnet") + else if (w1 == "subnet"_s /*backward compatibility*/ + || w1 == "lan_subnet"_s) { if (!extract(w2, &lan_subnet)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } - PRINTF("Sub-network of the map-server: %s.\n", + PRINTF("Sub-network of the map-server: %s.\n"_fmt, lan_subnet); } else @@ -2659,10 +2639,10 @@ bool lan_check() { // sub-network check of the map-server { - PRINTF("LAN test of LAN IP of the map-server: "); + PRINTF("LAN test of LAN IP of the map-server: "_fmt); if (!lan_ip_check(lan_map_ip)) { - PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network." SGR_RESET "\n"); + PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network." SGR_RESET "\n"_fmt); return false; } } @@ -2676,21 +2656,21 @@ bool char_config(XString w1, ZString w2) struct hostent *h = NULL; { - if (w1 == "userid") + if (w1 == "userid"_s) userid = stringish<AccountName>(w2); - else if (w1 == "passwd") + else if (w1 == "passwd"_s) passwd = stringish<AccountPass>(w2); - else if (w1 == "server_name") + else if (w1 == "server_name"_s) { server_name = stringish<ServerName>(w2); - PRINTF("%s server has been intialized\n", w2); + PRINTF("%s server has been intialized\n"_fmt, w2); } - else if (w1 == "wisp_server_name") + else if (w1 == "wisp_server_name"_s) { if (w2.size() >= 4) wisp_server_name = stringish<CharName>(w2); } - else if (w1 == "login_ip") + else if (w1 == "login_ip"_s) { h = gethostbyname(w2.c_str()); if (h != NULL) @@ -2701,20 +2681,20 @@ bool char_config(XString w1, ZString w2) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Login server IP address : %s -> %s\n", + PRINTF("Login server IP address : %s -> %s\n"_fmt, w2, login_ip); } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } } - else if (w1 == "login_port") + else if (w1 == "login_port"_s) { login_port = atoi(w2.c_str()); } - else if (w1 == "char_ip") + else if (w1 == "char_ip"_s) { h = gethostbyname(w2.c_str()); if (h != NULL) @@ -2725,56 +2705,56 @@ bool char_config(XString w1, ZString w2) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Character server IP address : %s -> %s\n", + PRINTF("Character server IP address : %s -> %s\n"_fmt, w2, char_ip); } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } } - else if (w1 == "char_port") + else if (w1 == "char_port"_s) { char_port = atoi(w2.c_str()); } - else if (w1 == "char_txt") + else if (w1 == "char_txt"_s) { char_txt = w2; } - else if (w1 == "max_connect_user") + else if (w1 == "max_connect_user"_s) { max_connect_user = atoi(w2.c_str()); if (max_connect_user < 0) max_connect_user = 0; // unlimited online players } - else if (w1 == "check_ip_flag") + else if (w1 == "check_ip_flag"_s) { check_ip_flag = config_switch(w2); } - else if (w1 == "autosave_time") + else if (w1 == "autosave_time"_s) { autosave_time = std::chrono::seconds(atoi(w2.c_str())); if (autosave_time <= std::chrono::seconds::zero()) autosave_time = DEFAULT_AUTOSAVE_INTERVAL; } - else if (w1 == "start_point") + else if (w1 == "start_point"_s) { extract(w2, &start_point); } - else if (w1 == "unknown_char_name") + else if (w1 == "unknown_char_name"_s) { unknown_char_name = stringish<CharName>(w2); } - else if (w1 == "char_log_filename") + else if (w1 == "char_log_filename"_s) { char_log_filename = w2; } - else if (w1 == "char_name_option") + else if (w1 == "char_name_option"_s) { char_name_option = atoi(w2.c_str()); } - else if (w1 == "char_name_letters") + else if (w1 == "char_name_letters"_s) { if (!w2) char_name_letters.reset(); @@ -2782,35 +2762,35 @@ bool char_config(XString w1, ZString w2) for (uint8_t c : w2) char_name_letters[c] = true; } - else if (w1 == "online_txt_filename") + else if (w1 == "online_txt_filename"_s) { online_txt_filename = w2; } - else if (w1 == "online_html_filename") + else if (w1 == "online_html_filename"_s) { online_html_filename = w2; } - else if (w1 == "online_sorting_option") + else if (w1 == "online_sorting_option"_s) { online_sorting_option = atoi(w2.c_str()); } - else if (w1 == "online_gm_display_min_level") + else if (w1 == "online_gm_display_min_level"_s) { // minimum GM level to display 'GM' when we want to display it online_gm_display_min_level = atoi(w2.c_str()); if (online_gm_display_min_level < 5) // send online file every 5 seconds to player is enough online_gm_display_min_level = 5; } - else if (w1 == "online_refresh_html") + else if (w1 == "online_refresh_html"_s) { online_refresh_html = atoi(w2.c_str()); if (online_refresh_html < 1) online_refresh_html = 1; } - else if (w1 == "anti_freeze_enable") + else if (w1 == "anti_freeze_enable"_s) { anti_freeze_enable = config_switch(w2); } - else if (w1 == "anti_freeze_interval") + else if (w1 == "anti_freeze_interval"_s) { anti_freeze_interval = std::max( std::chrono::seconds(atoi(w2.c_str())), @@ -2841,7 +2821,7 @@ void term_func(void) delete_session(login_session); delete_session(char_session); - CHAR_LOG("----End of char-server (normal end with closing of all files).\n"); + CHAR_LOG("----End of char-server (normal end with closing of all files).\n"_fmt); } static @@ -2866,20 +2846,20 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -2891,11 +2871,11 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-char.conf", char_confs); + runflag &= load_config_file("conf/tmwa-char.conf"_s, char_confs); // a newline in the log... - CHAR_LOG(""); - CHAR_LOG("The char-server starting...\n"); + CHAR_LOG(""_fmt); + CHAR_LOG("The char-server starting...\n"_fmt); runflag &= lan_check(); @@ -2931,10 +2911,10 @@ int do_init(Slice<ZString> argv) ).detach(); } - CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n", + CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n"_fmt, char_port); - PRINTF("The char-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n", + PRINTF("The char-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n"_fmt, char_port); return 0; diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index c9965dc..952788c 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -42,7 +42,7 @@ #include "../poison.hpp" -AString party_txt = "save/party.txt"; +AString party_txt = "save/party.txt"_s; static Map<int, struct party> party_db; @@ -64,7 +64,7 @@ AString inter_party_tostr(struct party *p) str += STRPRINTF( "%d\t" "%s\t" - "%d,%d\t", + "%d,%d\t"_fmt, p->party_id, p->name, p->exp, p->item); @@ -75,7 +75,7 @@ AString inter_party_tostr(struct party *p) continue; str += STRPRINTF( "%d,%d\t" - "%s\t", + "%s\t"_fmt, m->account_id, m->leader, m->name); } @@ -132,10 +132,10 @@ void party_check_deleted_init(struct party *p) const CharPair *c = search_character(p->member[i].name); if (!c || c->key.account_id != p->member[i].account_id) { - CHAR_LOG("WARNING: deleting obsolete party member %d %s of %d %s\n", + CHAR_LOG("WARNING: deleting obsolete party member %d %s of %d %s\n"_fmt, p->member[i].account_id, p->member[i].name, p->party_id, p->name); - PRINTF("WARNING: deleting obsolete party member %d %s of %d %s\n", + PRINTF("WARNING: deleting obsolete party member %d %s of %d %s\n"_fmt, p->member[i].account_id, p->member[i].name, p->party_id, p->name); p->member[i] = party_member{}; @@ -156,7 +156,7 @@ void inter_party_init(void) while (in.getline(line)) { int i, j = 0; - if (SSCANF(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0 + if (SSCANF(line, "%d\t%%newid%%\n%n"_fmt, &i, &j) == 1 && j > 0 && party_newid <= i) { party_newid = i; @@ -174,7 +174,7 @@ void inter_party_init(void) } else { - PRINTF("int_party: broken data [%s] line %d\n", party_txt, + PRINTF("int_party: broken data [%s] line %d\n"_fmt, party_txt, c + 1); } c++; @@ -195,7 +195,7 @@ int inter_party_save(void) io::WriteLock fp(party_txt); if (!fp.is_open()) { - PRINTF("int_party: cant write [%s] !!! data is lost !!!\n", + PRINTF("int_party: cant write [%s] !!! data is lost !!!\n"_fmt, party_txt); return 1; } @@ -251,10 +251,8 @@ int party_check_empty(struct party *p) { int i; -// PRINTF("party check empty %08X\n", (int)p); for (i = 0; i < MAX_PARTY; i++) { -// PRINTF("%d acc=%d\n", i, p->member[i].account_id); if (p->member[i].account_id > 0) { return 0; @@ -283,7 +281,7 @@ void party_check_conflict_sub(struct party *p, && p->member[i].name == nick) { // 別のパーティに偽の所属データがあるので脱退 - PRINTF("int_party: party conflict! %d %d %d\n", account_id, + PRINTF("int_party: party conflict! %d %d %d\n"_fmt, account_id, party_id, p->party_id); mapif_parse_PartyLeave(nullptr, p->party_id, account_id); } @@ -313,13 +311,13 @@ void mapif_party_created(Session *s, int account_id, struct party *p) WFIFOB(s, 6) = 0; WFIFOL(s, 7) = p->party_id; WFIFO_STRING(s, 11, p->name, 24); - PRINTF("int_party: created! %d %s\n", p->party_id, p->name); + PRINTF("int_party: created! %d %s\n"_fmt, p->party_id, p->name); } else { WFIFOB(s, 6) = 1; WFIFOL(s, 7) = 0; - WFIFO_STRING(s, 11, "error", 24); + WFIFO_STRING(s, 11, "error"_s, 24); } WFIFOSET(s, 35); } @@ -332,7 +330,7 @@ void mapif_party_noinfo(Session *s, int party_id) WFIFOW(s, 2) = 8; WFIFOL(s, 4) = party_id; WFIFOSET(s, 8); - PRINTF("int_party: info not found %d\n", party_id); + PRINTF("int_party: info not found %d\n"_fmt, party_id); } // パーティ情報まとめ送り @@ -348,7 +346,6 @@ void mapif_party_info(Session *s, struct party *p) mapif_sendall(buf, WBUFW(buf, 2)); else mapif_send(s, buf, WBUFW(buf, 2)); -// PRINTF("int_party: info %d %s\n", p->party_id, p->name); } // パーティメンバ追加可否 @@ -379,7 +376,7 @@ void mapif_party_optionchanged(Session *s, struct party *p, int account_id, mapif_sendall(buf, 15); else mapif_send(s, buf, 15); - PRINTF("int_party: option changed %d %d %d %d %d\n", p->party_id, + PRINTF("int_party: option changed %d %d %d %d %d\n"_fmt, p->party_id, account_id, p->exp, p->item, flag); } @@ -394,7 +391,7 @@ void mapif_party_leaved(int party_id, int account_id, CharName name) WBUFL(buf, 6) = account_id; WBUF_STRING(buf, 10, name.to__actual(), 24); mapif_sendall(buf, 34); - PRINTF("int_party: party leaved %d %d %s\n", party_id, account_id, name); + PRINTF("int_party: party leaved %d %d %s\n"_fmt, party_id, account_id, name); } // パーティマップ更新通知 @@ -421,8 +418,8 @@ void mapif_party_broken(int party_id, int flag) WBUFL(buf, 2) = party_id; WBUFB(buf, 6) = flag; mapif_sendall(buf, 7); - PRINTF("int_party: broken %d\n", party_id); - CHAR_LOG("int_party: broken %d\n", party_id); + PRINTF("int_party: broken %d\n"_fmt, party_id); + CHAR_LOG("int_party: broken %d\n"_fmt, party_id); } // パーティ内発言 @@ -451,7 +448,7 @@ void mapif_parse_CreateParty(Session *s, int account_id, PartyName name, CharNam { if (!name.is_print()) { - PRINTF("int_party: illegal party name [%s]\n", name); + PRINTF("int_party: illegal party name [%s]\n"_fmt, name); mapif_party_created(s, account_id, NULL); return; } @@ -459,7 +456,7 @@ void mapif_parse_CreateParty(Session *s, int account_id, PartyName name, CharNam if (search_partyname(name) != NULL) { - PRINTF("int_party: same name party exists [%s]\n", name); + PRINTF("int_party: same name party exists [%s]\n"_fmt, name); mapif_party_created(s, account_id, NULL); return; } diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index c7c1343..6021d54 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -43,7 +43,7 @@ // ファイル名のデフォルト // inter_config_read()で再設定される -AString storage_txt = "save/storage.txt"; +AString storage_txt = "save/storage.txt"_s; static Map<int, struct storage> storage_db; @@ -54,7 +54,7 @@ AString storage_tostr(struct storage *p) { MString str; str += STRPRINTF( - "%d,%d\t", + "%d,%d\t"_fmt, p->account_id, p->storage_amount); int f = 0; @@ -62,7 +62,7 @@ AString storage_tostr(struct storage *p) if (p->storage_[i].nameid && p->storage_[i].amount) { str += STRPRINTF( - "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ", + "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d "_fmt, p->storage_[i].id, p->storage_[i].nameid, p->storage_[i].amount, @@ -106,7 +106,7 @@ bool extract(XString str, struct storage *p) std::copy(storage_items.begin(), storage_items.end(), p->storage_.begin()); if (p->storage_amount != storage_items.size()) - PRINTF("WARNING: storage desync for %d\n", p->account_id); + PRINTF("WARNING: storage desync for %d\n"_fmt, p->account_id); return true; } @@ -131,7 +131,7 @@ void inter_storage_init(void) io::ReadFile in(storage_txt); if (!in.is_open()) { - PRINTF("cant't read : %s\n", storage_txt); + PRINTF("cant't read : %s\n"_fmt, storage_txt); return; } @@ -145,7 +145,7 @@ void inter_storage_init(void) } else { - PRINTF("int_storage: broken data [%s] line %d\n", + PRINTF("int_storage: broken data [%s] line %d\n"_fmt, storage_txt, c); } c++; @@ -168,7 +168,7 @@ int inter_storage_save(void) if (!fp.is_open()) { - PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n", + PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n"_fmt, storage_txt); return 1; } @@ -227,7 +227,7 @@ void mapif_parse_SaveStorage(Session *ss) int len = RFIFOW(ss, 2); if (sizeof(struct storage) != len - 8) { - PRINTF("inter storage: data size error %zu %d\n", + PRINTF("inter storage: data size error %zu %d\n"_fmt, sizeof(struct storage), len - 8); } else diff --git a/src/char/inter.cpp b/src/char/inter.cpp index 204a0e2..f7b3184 100644 --- a/src/char/inter.cpp +++ b/src/char/inter.cpp @@ -50,7 +50,7 @@ #include "../poison.hpp" static -AString accreg_txt = "save/accreg.txt"; +AString accreg_txt = "save/accreg.txt"_s; struct accreg { @@ -85,9 +85,9 @@ AString inter_accreg_tostr(struct accreg *reg) { assert(reg->reg_num < ACCOUNT_REG_NUM); MString str; - str += STRPRINTF("%d\t", reg->account_id); + str += STRPRINTF("%d\t"_fmt, reg->account_id); for (int j = 0; j < reg->reg_num; j++) - str += STRPRINTF("%s,%d ", reg->reg[j].str, reg->reg[j].value); + str += STRPRINTF("%s,%d "_fmt, reg->reg[j].str, reg->reg[j].value); return AString(str); } @@ -130,7 +130,7 @@ void inter_accreg_init(void) } else { - PRINTF("inter: accreg: broken data [%s] line %d\n", accreg_txt, + PRINTF("inter: accreg: broken data [%s] line %d\n"_fmt, accreg_txt, c); } c++; @@ -155,7 +155,7 @@ int inter_accreg_save(void) io::WriteLock fp(accreg_txt); if (!fp.is_open()) { - PRINTF("int_accreg: cant write [%s] !!! data is lost !!!\n", + PRINTF("int_accreg: cant write [%s] !!! data is lost !!!\n"_fmt, accreg_txt); return 1; } @@ -168,19 +168,19 @@ int inter_accreg_save(void) bool inter_config(XString w1, ZString w2) { { - if (w1 == "storage_txt") + if (w1 == "storage_txt"_s) { storage_txt = w2; } - else if (w1 == "party_txt") + else if (w1 == "party_txt"_s) { party_txt = w2; } - else if (w1 == "accreg_txt") + else if (w1 == "accreg_txt"_s) { accreg_txt = w2; } - else if (w1 == "party_share_level") + else if (w1 == "party_share_level"_s) { party_share_level = atoi(w2.c_str()); if (party_share_level < 0) @@ -316,7 +316,7 @@ void mapif_parse_WisRequest(Session *sms) { if (RFIFOW(sms, 2) - 52 <= 0) { // normaly, impossible, but who knows... - PRINTF("inter: Wis message doesn't exist.\n"); + PRINTF("inter: Wis message doesn't exist.\n"_fmt); return; } diff --git a/src/generic/intern-pool_test.cpp b/src/generic/intern-pool_test.cpp index b72ab04..3207792 100644 --- a/src/generic/intern-pool_test.cpp +++ b/src/generic/intern-pool_test.cpp @@ -28,13 +28,13 @@ TEST(InternPool, whydoesthisalwaysneedasecondname) { InternPool p; EXPECT_EQ(0, p.size()); - EXPECT_EQ(0, p.intern("hello")); - EXPECT_EQ(0, p.intern("hello")); + EXPECT_EQ(0, p.intern("hello"_s)); + EXPECT_EQ(0, p.intern("hello"_s)); EXPECT_EQ(1, p.size()); - EXPECT_EQ(1, p.intern("world")); - EXPECT_EQ(0, p.intern("hello")); - EXPECT_EQ(1, p.intern("world")); + EXPECT_EQ(1, p.intern("world"_s)); + EXPECT_EQ(0, p.intern("hello"_s)); + EXPECT_EQ(1, p.intern("world"_s)); EXPECT_EQ(2, p.size()); - EXPECT_EQ("hello", p.outtern(0)); - EXPECT_EQ("world", p.outtern(1)); + EXPECT_EQ("hello"_s, p.outtern(0)); + EXPECT_EQ("world"_s, p.outtern(1)); } diff --git a/src/generic/md5_test.cpp b/src/generic/md5_test.cpp index f6a2324..047b082 100644 --- a/src/generic/md5_test.cpp +++ b/src/generic/md5_test.cpp @@ -38,11 +38,11 @@ VString<32> MD5(XString in) TEST(md5calc, rfc1321) { - EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", MD5("")); - EXPECT_EQ("0cc175b9c0f1b6a831c399e269772661", MD5("a")); - EXPECT_EQ("900150983cd24fb0d6963f7d28e17f72", MD5("abc")); - EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0", MD5("message digest")); - EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b", MD5("abcdefghijklmnopqrstuvwxyz")); - EXPECT_EQ("d174ab98d277d9f5a5611c2c9f419d9f", MD5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")); - EXPECT_EQ("57edf4a22be3c955ac49da2e2107b67a", MD5("12345678901234567890123456789012345678901234567890123456789012345678901234567890")); + EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e"_s, MD5(""_s)); + EXPECT_EQ("0cc175b9c0f1b6a831c399e269772661"_s, MD5("a"_s)); + EXPECT_EQ("900150983cd24fb0d6963f7d28e17f72"_s, MD5("abc"_s)); + EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0"_s, MD5("message digest"_s)); + EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b"_s, MD5("abcdefghijklmnopqrstuvwxyz"_s)); + EXPECT_EQ("d174ab98d277d9f5a5611c2c9f419d9f"_s, MD5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"_s)); + EXPECT_EQ("57edf4a22be3c955ac49da2e2107b67a"_s, MD5("12345678901234567890123456789012345678901234567890123456789012345678901234567890"_s)); } diff --git a/src/io/cxxstdio.hpp b/src/io/cxxstdio.hpp index 66419df..a2faa18 100644 --- a/src/io/cxxstdio.hpp +++ b/src/io/cxxstdio.hpp @@ -192,7 +192,7 @@ namespace cxxstdio int print(T&& t, A&&... a) { constexpr static - const char *print_format = Format::print_format(); + const char *print_format = Format::print_format().format_string(); return do_print(std::forward<T>(t), print_format, decay_for_printf(convert_for_printf(std::forward<A>(a)))...); } @@ -207,7 +207,7 @@ namespace cxxstdio int scan(T&& t, A&&... a) { constexpr static - const char *scan_format = Format::scan_format(); + const char *scan_format = Format::scan_format().format_string(); return do_scan(std::forward<T>(t), scan_format, &convert_for_scanf(*a)...); } @@ -218,7 +218,7 @@ namespace cxxstdio struct format_impl \ { \ constexpr static \ - const char *print_format() { return fmt; } \ + FormatString print_format() { return fmt; } \ }; \ cxxstdio::PrintFormatter<format_impl>::print(out, ## __VA_ARGS__); \ }) @@ -228,7 +228,7 @@ namespace cxxstdio struct format_impl \ { \ constexpr static \ - const char *scan_format() { return fmt; } \ + FormatString scan_format() { return fmt; } \ }; \ cxxstdio::ScanFormatter<format_impl>::scan(out, ## __VA_ARGS__); \ }) diff --git a/src/io/line.cpp b/src/io/line.cpp index f7470a6..8451b87 100644 --- a/src/io/line.cpp +++ b/src/io/line.cpp @@ -36,26 +36,26 @@ namespace io { MString out; if (column) - out += STRPRINTF("%s:%u:%u: %s: %s\n", + out += STRPRINTF("%s:%u:%u: %s: %s\n"_fmt, filename, line, column, cat, msg); else - out += STRPRINTF("%s:%u: %s: %s\n", + out += STRPRINTF("%s:%u: %s: %s\n"_fmt, filename, line, cat, msg); - out += STRPRINTF("%s\n", text); - out += STRPRINTF("%*c\n", column, '^'); + out += STRPRINTF("%s\n"_fmt, text); + out += STRPRINTF("%*c\n"_fmt, column, '^'); return AString(out); } void Line::message(ZString cat, ZString msg) const { if (column) - FPRINTF(stderr, "%s:%u:%u: %s: %s\n", + FPRINTF(stderr, "%s:%u:%u: %s: %s\n"_fmt, filename, line, column, cat, msg); else - FPRINTF(stderr, "%s:%u: %s: %s\n", + FPRINTF(stderr, "%s:%u: %s: %s\n"_fmt, filename, line, cat, msg); - FPRINTF(stderr, "%s\n", text); - FPRINTF(stderr, "%*c\n", column, '^'); + FPRINTF(stderr, "%s\n"_fmt, text); + FPRINTF(stderr, "%*c\n"_fmt, column, '^'); } AString LineSpan::message_str(ZString cat, ZString msg) const @@ -67,24 +67,24 @@ namespace io MString out; if (begin.line == end.line) { - out += STRPRINTF("%s:%u:%u: %s: %s\n", + out += STRPRINTF("%s:%u:%u: %s: %s\n"_fmt, begin.filename, begin.line, begin.column, cat, msg); - out += STRPRINTF("%s\n", begin.text); - out += STRPRINTF("%*c", begin.column, '^'); + out += STRPRINTF("%s\n"_fmt, begin.text); + out += STRPRINTF("%*c"_fmt, begin.column, '^'); for (unsigned c = begin.column; c != end.column; ++c) out += '~'; out += '\n'; } else { - out += STRPRINTF("%s:%u:%u: %s: %s\n", + out += STRPRINTF("%s:%u:%u: %s: %s\n"_fmt, begin.filename, begin.line, begin.column, cat, msg); - out += STRPRINTF("%s\n", begin.text); - out += STRPRINTF("%*c", begin.column, '^'); + out += STRPRINTF("%s\n"_fmt, begin.text); + out += STRPRINTF("%*c"_fmt, begin.column, '^'); for (unsigned c = begin.column; c != begin.text.size(); ++c) out += '~'; - out += " ...\n"; - out += STRPRINTF("%s\n", end.text); + out += " ...\n"_s; + out += STRPRINTF("%s\n"_fmt, end.text); for (unsigned c = 0; c != end.column; ++c) out += '~'; out += '\n'; @@ -94,7 +94,7 @@ namespace io void LineSpan::message(ZString cat, ZString msg) const { - FPRINTF(stderr, "%s", message_str(cat, msg)); + FPRINTF(stderr, "%s"_fmt, message_str(cat, msg)); } LineReader::LineReader(ZString name) diff --git a/src/io/line.hpp b/src/io/line.hpp index a9e8944..bb002b8 100644 --- a/src/io/line.hpp +++ b/src/io/line.hpp @@ -42,9 +42,9 @@ namespace io AString message_str(ZString cat, ZString msg) const; void message(ZString cat, ZString msg) const; - void note(ZString msg) const { message("note", msg); } - void warning(ZString msg) const { message("warning", msg); } - void error(ZString msg) const { message("error", msg); } + void note(ZString msg) const { message("note"_s, msg); } + void warning(ZString msg) const { message("warning"_s, msg); } + void error(ZString msg) const { message("error"_s, msg); } }; // psst, don't tell anyone @@ -65,9 +65,9 @@ namespace io AString message_str(ZString cat, ZString msg) const; void message(ZString cat, ZString msg) const; - void note(ZString msg) const { message("note", msg); } - void warning(ZString msg) const { message("warning", msg); } - void error(ZString msg) const { message("error", msg); } + void note(ZString msg) const { message("note"_s, msg); } + void warning(ZString msg) const { message("warning"_s, msg); } + void error(ZString msg) const { message("error"_s, msg); } }; class LineReader diff --git a/src/io/line_test.cpp b/src/io/line_test.cpp index feee1fb..921e4c8 100644 --- a/src/io/line_test.cpp +++ b/src/io/line_test.cpp @@ -42,80 +42,80 @@ io::FD string_pipe(ZString sz) TEST(io, line1) { - io::LineReader lr("<string1>", string_pipe("Hello World\n")); + io::LineReader lr("<string1>"_s, string_pipe("Hello World\n"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello World"); - EXPECT_EQ(hi.filename, "<string1>"); + EXPECT_EQ(hi.text, "Hello World"_s); + EXPECT_EQ(hi.filename, "<string1>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line2) { - io::LineReader lr("<string2>", string_pipe("Hello\nWorld")); + io::LineReader lr("<string2>"_s, string_pipe("Hello\nWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string2>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string2>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string2>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string2>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line3) { - io::LineReader lr("<string3>", string_pipe("Hello\rWorld")); + io::LineReader lr("<string3>"_s, string_pipe("Hello\rWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string3>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string3>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string3>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string3>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line4) { - io::LineReader lr("<string4>", string_pipe("Hello\r\nWorld")); + io::LineReader lr("<string4>"_s, string_pipe("Hello\r\nWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string4>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string4>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string4>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string4>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); } TEST(io, line5) { - io::LineReader lr("<string5>", string_pipe("Hello\n\rWorld")); + io::LineReader lr("<string5>"_s, string_pipe("Hello\n\rWorld"_s)); io::Line hi; EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "Hello"); - EXPECT_EQ(hi.filename, "<string5>"); + EXPECT_EQ(hi.text, "Hello"_s); + EXPECT_EQ(hi.filename, "<string5>"_s); EXPECT_EQ(hi.line, 1); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, ""); - EXPECT_EQ(hi.filename, "<string5>"); + EXPECT_EQ(hi.text, ""_s); + EXPECT_EQ(hi.filename, "<string5>"_s); EXPECT_EQ(hi.line, 2); EXPECT_EQ(hi.column, 0); EXPECT_TRUE(lr.read_line(hi)); - EXPECT_EQ(hi.text, "World"); - EXPECT_EQ(hi.filename, "<string5>"); + EXPECT_EQ(hi.text, "World"_s); + EXPECT_EQ(hi.filename, "<string5>"_s); EXPECT_EQ(hi.line, 3); EXPECT_EQ(hi.column, 0); EXPECT_FALSE(lr.read_line(hi)); @@ -123,47 +123,47 @@ TEST(io, line5) TEST(io, linechar1) { - io::LineCharReader lr("<stringchar1>", string_pipe("Hi Wu\n")); + io::LineCharReader lr("<stringchar1>"_s, string_pipe("Hi Wu\n"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), ' '); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 4); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 5); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi Wu"); - EXPECT_EQ(c.filename, "<stringchar1>"); + EXPECT_EQ(c.text, "Hi Wu"_s); + EXPECT_EQ(c.filename, "<stringchar1>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 6); lr.adv(); @@ -171,47 +171,47 @@ TEST(io, linechar1) } TEST(io, linechar2) { - io::LineCharReader lr("<stringchar2>", string_pipe("Hi\nWu")); + io::LineCharReader lr("<stringchar2>"_s, string_pipe("Hi\nWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar2>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar2>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 3); lr.adv(); @@ -219,47 +219,47 @@ TEST(io, linechar2) } TEST(io, linechar3) { - io::LineCharReader lr("<stringchar3>", string_pipe("Hi\rWu")); + io::LineCharReader lr("<stringchar3>"_s, string_pipe("Hi\rWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar3>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar3>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 3); lr.adv(); @@ -267,47 +267,47 @@ TEST(io, linechar3) } TEST(io, linechar4) { - io::LineCharReader lr("<stringchar4>", string_pipe("Hi\r\nWu")); + io::LineCharReader lr("<stringchar4>"_s, string_pipe("Hi\r\nWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar4>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar4>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 3); lr.adv(); @@ -315,54 +315,54 @@ TEST(io, linechar4) } TEST(io, linechar5) { - io::LineCharReader lr("<stringchar5>", string_pipe("Hi\n\rWu")); + io::LineCharReader lr("<stringchar5>"_s, string_pipe("Hi\n\rWu"_s)); io::LineChar c; EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'H'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'i'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Hi"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Hi"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 1); EXPECT_EQ(c.column, 3); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, ""); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, ""_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 2); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'W'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 3); EXPECT_EQ(c.column, 1); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), 'u'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 3); EXPECT_EQ(c.column, 2); lr.adv(); EXPECT_TRUE(lr.get(c)); EXPECT_EQ(c.ch(), '\n'); - EXPECT_EQ(c.text, "Wu"); - EXPECT_EQ(c.filename, "<stringchar5>"); + EXPECT_EQ(c.text, "Wu"_s); + EXPECT_EQ(c.filename, "<stringchar5>"_s); EXPECT_EQ(c.line, 3); EXPECT_EQ(c.column, 3); lr.adv(); @@ -371,7 +371,7 @@ TEST(io, linechar5) TEST(io, linespan) { - io::LineCharReader lr("<span>", string_pipe("Hello,\nWorld!\n")); + io::LineCharReader lr("<span>"_s, string_pipe("Hello,\nWorld!\n"_s)); io::LineSpan span; do { @@ -385,10 +385,10 @@ TEST(io, linespan) lr.adv(); } while (span.end.ch() != 'o'); - EXPECT_EQ(span.message_str("info", "meh"), + EXPECT_EQ(span.message_str("info"_s, "meh"_s), "<span>:1:2: info: meh\n" "Hello,\n" - " ^~~~\n" + " ^~~~\n"_s ); span.begin = span.end; do @@ -398,21 +398,21 @@ TEST(io, linespan) } while (span.end.ch() != 'r'); - EXPECT_EQ(span.begin.message_str("note", "foo"), + EXPECT_EQ(span.begin.message_str("note"_s, "foo"_s), "<span>:1:5: note: foo\n" "Hello,\n" - " ^\n" + " ^\n"_s ); - EXPECT_EQ(span.end.message_str("warning", "bar"), + EXPECT_EQ(span.end.message_str("warning"_s, "bar"_s), "<span>:2:3: warning: bar\n" "World!\n" - " ^\n" + " ^\n"_s ); - EXPECT_EQ(span.message_str("error", "qux"), + EXPECT_EQ(span.message_str("error"_s, "qux"_s), "<span>:1:5: error: qux\n" "Hello,\n" " ^~ ...\n" "World!\n" - "~~~\n" + "~~~\n"_s ); } diff --git a/src/io/lock.cpp b/src/io/lock.cpp index 96c3649..1342915 100644 --- a/src/io/lock.cpp +++ b/src/io/lock.cpp @@ -49,7 +49,7 @@ namespace io AString newfile; do { - newfile = STRPRINTF("%s_%d.tmp", filename, no++); + newfile = STRPRINTF("%s_%d.tmp"_fmt, filename, no++); fd = FD::open(newfile, O_WRONLY | O_CREAT | O_EXCL, 0666); } while (fd == FD() && errno == EEXIST); @@ -67,21 +67,21 @@ namespace io if (!WriteFile::close()) { // leave partial file - FPRINTF(stderr, "Warning: failed to write replacement for %s\n", filename); + FPRINTF(stderr, "Warning: failed to write replacement for %s\n"_fmt, filename); abort(); } int n = backup_count; - AString old_filename = STRPRINTF("%s.%d", filename, n); + AString old_filename = STRPRINTF("%s.%d"_fmt, filename, n); while (--n) { - AString newer_filename = STRPRINTF("%s.%d", filename, n); + AString newer_filename = STRPRINTF("%s.%d"_fmt, filename, n); rename(newer_filename.c_str(), old_filename.c_str()); old_filename = std::move(newer_filename); } rename(filename.c_str(), old_filename.c_str()); - AString tmpfile = STRPRINTF("%s_%d.tmp", filename, tmp_suffix); + AString tmpfile = STRPRINTF("%s_%d.tmp"_fmt, filename, tmp_suffix); rename(tmpfile.c_str(), filename.c_str()); } } // namespace io diff --git a/src/io/read.cpp b/src/io/read.cpp index 2ef35cc..61a6256 100644 --- a/src/io/read.cpp +++ b/src/io/read.cpp @@ -105,12 +105,12 @@ namespace io if (unhappy) { if (happy) - PRINTF("warning: file contains CR\n"); + PRINTF("warning: file contains CR\n"_fmt); else - PRINTF("warning: file contains bare CR\n"); + PRINTF("warning: file contains bare CR\n"_fmt); } else if (!happy && anything) - PRINTF("warning: file does not contain a trailing newline\n"); + PRINTF("warning: file does not contain a trailing newline\n"_fmt); line = AString(tmp); return anything; } diff --git a/src/io/read_test.cpp b/src/io/read_test.cpp index 87f95ba..398c01e 100644 --- a/src/io/read_test.cpp +++ b/src/io/read_test.cpp @@ -42,42 +42,42 @@ io::FD string_pipe(ZString sz) TEST(io, read1) { - io::ReadFile rf(string_pipe("Hello")); + io::ReadFile rf(string_pipe("Hello"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read2) { - io::ReadFile rf(string_pipe("Hello\n")); + io::ReadFile rf(string_pipe("Hello\n"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read3) { - io::ReadFile rf(string_pipe("Hello\r")); + io::ReadFile rf(string_pipe("Hello\r"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read4) { - io::ReadFile rf(string_pipe("Hello\r\n")); + io::ReadFile rf(string_pipe("Hello\r\n"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_FALSE(rf.getline(hi)); } TEST(io, read5) { - io::ReadFile rf(string_pipe("Hello\n\r")); + io::ReadFile rf(string_pipe("Hello\n\r"_s)); AString hi; EXPECT_TRUE(rf.getline(hi)); - EXPECT_EQ(hi, "Hello"); + EXPECT_EQ(hi, "Hello"_s); EXPECT_TRUE(rf.getline(hi)); EXPECT_FALSE(hi); EXPECT_FALSE(rf.getline(hi)); diff --git a/src/io/write_test.cpp b/src/io/write_test.cpp index ae8eccd..5419501 100644 --- a/src/io/write_test.cpp +++ b/src/io/write_test.cpp @@ -65,7 +65,7 @@ public: if (rv == -1) { if (errno != EAGAIN) - return {"Error, read failed :("}; + return "Error, read failed :("_s; rv = 0; } if (rv == 0) @@ -81,11 +81,11 @@ TEST(io, write1) PipeWriter pw(false); io::WriteFile& wf = pw.wf; wf.really_put("Hello, ", 7); - EXPECT_EQ("", pw.slurp()); - wf.put_line("World!\n"); - EXPECT_EQ("", pw.slurp()); + EXPECT_EQ(""_s, pw.slurp()); + wf.put_line("World!\n"_s); + EXPECT_EQ(""_s, pw.slurp()); EXPECT_TRUE(wf.close()); - EXPECT_EQ("Hello, World!\n", pw.slurp()); + EXPECT_EQ("Hello, World!\n"_s, pw.slurp()); } TEST(io, write2) @@ -93,10 +93,10 @@ TEST(io, write2) PipeWriter pw(true); io::WriteFile& wf = pw.wf; wf.really_put("Hello, ", 7); - EXPECT_EQ("", pw.slurp()); - wf.put_line("World!"); + EXPECT_EQ(""_s, pw.slurp()); + wf.put_line("World!"_s); wf.really_put("XXX", 3); - EXPECT_EQ("Hello, World!\n", pw.slurp()); + EXPECT_EQ("Hello, World!\n"_s, pw.slurp()); EXPECT_TRUE(wf.close()); - EXPECT_EQ("XXX", pw.slurp()); + EXPECT_EQ("XXX"_s, pw.slurp()); } diff --git a/src/login/login.cpp b/src/login/login.cpp index f784c6a..e061e63 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -114,13 +114,13 @@ static ServerName main_server; static -AString account_filename = "save/account.txt"; +AString account_filename = "save/account.txt"_s; static -AString gm_account_filename = "save/gm_account.txt"; +AString gm_account_filename = "save/gm_account.txt"_s; static -AString login_log_filename = "log/login.log"; +AString login_log_filename = "log/login.log"_s; static -AString login_log_unknown_packets_filename = "log/login_unknown_packets.log"; +AString login_log_unknown_packets_filename = "log/login_unknown_packets.log"_s; static int save_unknown_packets = 0; static @@ -175,7 +175,7 @@ int check_ip_flag = 1; // It's to check IP of a player between login-ser #pragma GCC diagnostic ignored "-Wmissing-noreturn" void SessionDeleter::operator()(SessionData *) { - assert(false && "login server does not have sessions anymore"); + assert(false && "login server does not have sessions anymore"_s); } #pragma GCC diagnostic pop @@ -285,12 +285,12 @@ int read_gm_account(void) io::ReadFile fp(gm_account_filename); if (!fp.is_open()) { - PRINTF("read_gm_account: GM accounts file [%s] not found.\n", + PRINTF("read_gm_account: GM accounts file [%s] not found.\n"_fmt, gm_account_filename); - PRINTF(" Actually, there is no GM accounts on the server.\n"); - LOGIN_LOG("read_gm_account: GM accounts file [%s] not found.\n", + PRINTF(" Actually, there is no GM accounts on the server.\n"_fmt); + LOGIN_LOG("read_gm_account: GM accounts file [%s] not found.\n"_fmt, gm_account_filename); - LOGIN_LOG(" Actually, there is no GM accounts on the server.\n"); + LOGIN_LOG(" Actually, there is no GM accounts on the server.\n"_fmt); return 1; } // limited to 4000, because we send information to char-servers (more than 4000 GM accounts???) @@ -302,48 +302,47 @@ int read_gm_account(void) continue; GM_Account p {}; if (!extract(line, record<' '>(&p.account_id, &p.level))) - PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format: '%s'\n", + PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format: '%s'\n"_fmt, gm_account_filename, line); else if (p.level <= 0) - PRINTF("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n", + PRINTF("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n"_fmt, gm_account_filename, c + 1, p.level); else { if (p.level > 99) { - PRINTF("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n", + PRINTF("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n"_fmt, gm_account_filename, c + 1, p.level); p.level = 99; } if ((GM_level = isGM(p.account_id)) > 0) { // if it's not a new account if (GM_level == p.level) - PRINTF("read_gm_account: GM account %d defined twice (same level: %d).\n", + PRINTF("read_gm_account: GM account %d defined twice (same level: %d).\n"_fmt, p.account_id, p.level); else - PRINTF("read_gm_account: GM account %d defined twice (levels: %d and %d).\n", + PRINTF("read_gm_account: GM account %d defined twice (levels: %d and %d).\n"_fmt, p.account_id, GM_level, p.level); } if (GM_level != p.level) { // if new account or new level gm_account_db.insert(p.account_id, p); - //PRINTF("GM account:%d, level: %d->%d\n", p.account_id, GM_level, p.level); if (GM_level == 0) { // if new account c++; if (c >= 4000) { - PRINTF("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"); - LOGIN_LOG("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"); + PRINTF("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"_fmt); + LOGIN_LOG("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n"_fmt); } } } } } - PRINTF("read_gm_account: file '%s' readed (%d GM accounts found).\n", + PRINTF("read_gm_account: file '%s' readed (%d GM accounts found).\n"_fmt, gm_account_filename, c); - LOGIN_LOG("read_gm_account: file '%s' readed (%d GM accounts found).\n", + LOGIN_LOG("read_gm_account: file '%s' readed (%d GM accounts found).\n"_fmt, gm_account_filename, c); return 0; @@ -456,7 +455,7 @@ AString mmo_auth_tostr(const AuthData *p) "%lld\t" "%s\t" "%s\t" - "%lld\t", + "%lld\t"_fmt, p->account_id, p->userid, p->pass, @@ -474,7 +473,7 @@ AString mmo_auth_tostr(const AuthData *p) assert (p->account_reg2_num < ACCOUNT_REG2_NUM); for (int i = 0; i < p->account_reg2_num; i++) if (p->account_reg2[i].str) - str += STRPRINTF("%s,%d ", + str += STRPRINTF("%s,%d "_fmt, p->account_reg2[i].str, p->account_reg2[i].value); return AString(str); @@ -504,7 +503,7 @@ bool extract(XString line, AuthData *ad) vrec<' '>(&vars)))) return false; ad->last_ip = IP4Address(); - if (ip != "-" && !extract(ip, &ad->last_ip)) + if (ip != "-"_s && !extract(ip, &ad->last_ip)) return false; if (ad->account_id > END_ACCOUNT_NUM) return false; @@ -543,7 +542,7 @@ bool extract(XString line, AuthData *ad) if (!ad->error_message || ad->state != 7) // 7, because state is packet 0x006a value + 1 - ad->error_message = stringish<timestamp_seconds_buffer>("-"); + ad->error_message = stringish<timestamp_seconds_buffer>("-"_s); if (vars.size() > ACCOUNT_REG2_NUM) return false; @@ -566,7 +565,7 @@ int mmo_auth_init(void) { // no account file -> no account -> no login, including char-server (ERROR) // not anymore! :-) - PRINTF(SGR_BOLD SGR_RED "mmo_auth_init: Accounts file [%s] not found." SGR_RESET "\n", + PRINTF(SGR_BOLD SGR_RED "mmo_auth_init: Accounts file [%s] not found." SGR_RESET "\n"_fmt, account_filename); return 0; } @@ -585,11 +584,11 @@ int mmo_auth_init(void) if (!extract(line, &ad)) { int i = 0; - if (SSCANF(line, "%d\t%%newid%%\n%n", &ad.account_id, &i) == 1 + if (SSCANF(line, "%d\t%%newid%%\n%n"_fmt, &ad.account_id, &i) == 1 && i > 0 && ad.account_id > account_id_count) account_id_count = ad.account_id; else - LOGIN_LOG("Account skipped\n%s", line); + LOGIN_LOG("Account skipped\n%s"_fmt, line); continue; } @@ -602,10 +601,10 @@ int mmo_auth_init(void) account_id_count = ad.account_id + 1; } - AString str = STRPRINTF("%s has %zu accounts (%d GMs)\n", + AString str = STRPRINTF("%s has %zu accounts (%d GMs)\n"_fmt, account_filename, auth_data.size(), gm_count); - PRINTF("%s: %s\n", __PRETTY_FUNCTION__, str); - LOGIN_LOG("%s\n", line); + PRINTF("%s: %s\n"_fmt, __PRETTY_FUNCTION__, str); + LOGIN_LOG("%s\n"_fmt, line); return 0; } @@ -620,30 +619,30 @@ void mmo_auth_sync(void) if (!fp.is_open()) { - PRINTF("uh-oh - unable to save accounts\n"); + PRINTF("uh-oh - unable to save accounts\n"_fmt); return; } FPRINTF(fp, - "// Accounts file: here are saved all information about the accounts.\n"); + "// Accounts file: here are saved all information about the accounts.\n"_fmt); FPRINTF(fp, - "// Structure: ID, account name, password, last login time, sex, # of logins, state, email, error message for state 7, validity time, last (accepted) login ip, memo field, ban timestamp, repeated(register text, register value)\n"); - FPRINTF(fp, "// Some explanations:\n"); + "// Structure: ID, account name, password, last login time, sex, # of logins, state, email, error message for state 7, validity time, last (accepted) login ip, memo field, ban timestamp, repeated(register text, register value)\n"_fmt); + FPRINTF(fp, "// Some explanations:\n"_fmt); FPRINTF(fp, - "// account name : between 4 to 23 char for a normal account (standard client can't send less than 4 char).\n"); - FPRINTF(fp, "// account password: between 4 to 23 char\n"); + "// account name : between 4 to 23 char for a normal account (standard client can't send less than 4 char).\n"_fmt); + FPRINTF(fp, "// account password: between 4 to 23 char\n"_fmt); FPRINTF(fp, - "// sex : M or F for normal accounts, S for server accounts\n"); + "// sex : M or F for normal accounts, S for server accounts\n"_fmt); FPRINTF(fp, - "// state : 0: account is ok, 1 to 256: error code of packet 0x006a + 1\n"); + "// state : 0: account is ok, 1 to 256: error code of packet 0x006a + 1\n"_fmt); FPRINTF(fp, - "// email : between 3 to 39 char (a@a.com is like no email)\n"); + "// email : between 3 to 39 char (a@a.com is like no email)\n"_fmt); FPRINTF(fp, - "// error message : text for the state 7: 'Your are Prohibited to login until <text>'. Max 19 char\n"); + "// error message : text for the state 7: 'Your are Prohibited to login until <text>'. Max 19 char\n"_fmt); FPRINTF(fp, - "// valitidy time : 0: unlimited account, <other value>: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"); - FPRINTF(fp, "// memo field : max 254 char\n"); + "// valitidy time : 0: unlimited account, <other value>: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"_fmt); + FPRINTF(fp, "// memo field : max 254 char\n"_fmt); FPRINTF(fp, - "// ban time : 0: no ban, <other value>: banned until the date: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"); + "// ban time : 0: no ban, <other value>: banned until the date: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n"_fmt); for (const AuthData& ad : auth_data) { if (ad.account_id < 0) @@ -652,7 +651,7 @@ void mmo_auth_sync(void) AString line = mmo_auth_tostr(&ad); fp.put_line(line); } - FPRINTF(fp, "%d\t%%newid%%\n", account_id_count); + FPRINTF(fp, "%d\t%%newid%%\n"_fmt, account_id_count); } // We want to sync the DB to disk as little as possible as it's fairly @@ -767,7 +766,7 @@ int mmo_auth_new(struct mmo_account *account, SEX sex, AccountEmail email) ad.userid = account->userid; ad.pass = MD5_saltcrypt(account->passwd, make_salt()); - ad.lastlogin = stringish<timestamp_milliseconds_buffer>("-"); + ad.lastlogin = stringish<timestamp_milliseconds_buffer>("-"_s); ad.sex = sex; ad.logincount = 0; ad.state = 0; @@ -777,7 +776,7 @@ int mmo_auth_new(struct mmo_account *account, SEX sex, AccountEmail email) else ad.email = email; - ad.error_message = stringish<timestamp_seconds_buffer>("-"); + ad.error_message = stringish<timestamp_seconds_buffer>("-"_s); ad.ban_until_time = TimeT(); if (start_limited_time < 0) @@ -792,7 +791,7 @@ int mmo_auth_new(struct mmo_account *account, SEX sex, AccountEmail email) } ad.last_ip = IP4Address(); - ad.memo = "!"; + ad.memo = "!"_s; ad.account_reg2_num = 0; auth_data.push_back(ad); @@ -811,7 +810,7 @@ int mmo_auth(struct mmo_account *account, Session *s) // Account creation with _M/_F if (account->passwdenc == 0 - && (account->userid.endswith("_F") || account->userid.endswith("_M")) + && (account->userid.endswith("_F"_s) || account->userid.endswith("_M"_s)) && new_account == 1 && account_id_count <= END_ACCOUNT_NUM && (account->userid.size() - 2) >= 4 && account->passwd.size() >= 4) { @@ -827,14 +826,14 @@ int mmo_auth(struct mmo_account *account, Session *s) int encpasswdok = 0; if (new_account_sex) { - LOGIN_LOG("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n", + LOGIN_LOG("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n"_fmt, account->userid, new_account_sex, ip); return 9; // 9 = Account already exists } if ((!pass_ok(account->passwd, ad->pass)) && !encpasswdok) { if (account->passwdenc == 0) - LOGIN_LOG("Invalid password (account: %s, ip: %s)\n", + LOGIN_LOG("Invalid password (account: %s, ip: %s)\n"_fmt, account->userid, ip); return 1; // 1 = Incorrect Password @@ -842,7 +841,7 @@ int mmo_auth(struct mmo_account *account, Session *s) if (ad->state) { - LOGIN_LOG("Connection refused (account: %s, state: %d, ip: %s)\n", + LOGIN_LOG("Connection refused (account: %s, state: %d, ip: %s)\n"_fmt, account->userid, ad->state, ip); switch (ad->state) @@ -871,14 +870,14 @@ int mmo_auth(struct mmo_account *account, Session *s) if (ad->ban_until_time > TimeT::now()) { // always banned - LOGIN_LOG("Connection refused (account: %s, banned until %s, ip: %s)\n", + LOGIN_LOG("Connection refused (account: %s, banned until %s, ip: %s)\n"_fmt, account->userid, tmpstr, ip); return 6; // 6 = Your are Prohibited to log in until %s } else { // ban is finished - LOGIN_LOG("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n", + LOGIN_LOG("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n"_fmt, account->userid, tmpstr, ip); ad->ban_until_time = TimeT(); // reset the ban time } @@ -887,26 +886,26 @@ int mmo_auth(struct mmo_account *account, Session *s) if (ad->connect_until_time && ad->connect_until_time < TimeT::now()) { - LOGIN_LOG("Connection refused (account: %s, expired ID, ip: %s)\n", + LOGIN_LOG("Connection refused (account: %s, expired ID, ip: %s)\n"_fmt, account->userid, ip); return 2; // 2 = This ID is expired } - LOGIN_LOG("Authentification accepted (account: %s (id: %d), ip: %s)\n", + LOGIN_LOG("Authentification accepted (account: %s (id: %d), ip: %s)\n"_fmt, account->userid, ad->account_id, ip); } else { if (new_account_sex == '\0') { - LOGIN_LOG("Unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("Unknown account (account: %s, ip: %s)\n"_fmt, account->userid, ip); return 0; // 0 = Unregistered ID } else { int new_id = mmo_auth_new(account, sex_from_char(new_account_sex), DEFAULT_EMAIL); - LOGIN_LOG("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n", + LOGIN_LOG("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n"_fmt, account->userid, new_id, new_account_sex, ip); ad = &auth_data.back(); @@ -936,17 +935,15 @@ void char_anti_freeze_system(TimerData *, tick_t) { int i; - //PRINTF("Entering in char_anti_freeze_system function to check freeze of servers.\n"); for (i = 0; i < MAX_SERVERS; i++) { if (server_session[i]) { // if char-server is online - //PRINTF("char_anti_freeze_system: server #%d '%s', flag: %d.\n", i, server[i].name, server_freezeflag[i]); if (server_freezeflag[i]-- < 1) { // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed - PRINTF("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n", + PRINTF("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n"_fmt, i, server[i].name); - LOGIN_LOG("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n", + LOGIN_LOG("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n"_fmt, i, server[i].name); server_session[i]->eof = 1; } @@ -970,8 +967,8 @@ void parse_fromchar(Session *s) { if (id < MAX_SERVERS) { - PRINTF("Char-server '%s' has disconnected.\n", server[id].name); - LOGIN_LOG("Char-server '%s' has disconnected (ip: %s).\n", + PRINTF("Char-server '%s' has disconnected.\n"_fmt, server[id].name); + LOGIN_LOG("Char-server '%s' has disconnected (ip: %s).\n"_fmt, server[id].name, ip); server_session[id] = nullptr; server[id] = mmo_char_server{}; @@ -983,14 +980,14 @@ void parse_fromchar(Session *s) while (RFIFOREST(s) >= 2) { if (display_parse_fromchar == 2 || (display_parse_fromchar == 1 && RFIFOW(s, 0) != 0x2714)) // 0x2714 is done very often (number of players) - PRINTF("parse_fromchar: connection #%d, packet: 0x%x (with being read: %zu bytes).\n", + PRINTF("parse_fromchar: connection #%d, packet: 0x%x (with being read: %zu bytes).\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s)); switch (RFIFOW(s, 0)) { // request from map-server via char-server to reload GM accounts (by Yor). case 0x2709: - LOGIN_LOG("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n", + LOGIN_LOG("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n"_fmt, server[id].name, ip); read_gm_account(); // send GM accounts to all char-servers @@ -1016,7 +1013,7 @@ void parse_fromchar(Session *s) { int p; auth_fifo[i].delflag = 1; - LOGIN_LOG("Char-server '%s': authentification of the account %d accepted (ip: %s).\n", + LOGIN_LOG("Char-server '%s': authentification of the account %d accepted (ip: %s).\n"_fmt, server[id].name, acc, ip); for (const AuthData& ad : auth_data) { @@ -1034,7 +1031,6 @@ void parse_fromchar(Session *s) } WFIFOW(s, 2) = p; WFIFOSET(s, p); -// PRINTF("parse_fromchar: Sending of account_reg2: login->char (auth fifo)\n"); WFIFOW(s, 0) = 0x2713; WFIFOL(s, 2) = acc; WFIFOB(s, 6) = 0; @@ -1050,7 +1046,7 @@ void parse_fromchar(Session *s) // authentification not found if (i == AUTH_FIFO_SIZE) { - LOGIN_LOG("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n", + LOGIN_LOG("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n"_fmt, server[id].name, acc, ip); WFIFOW(s, 0) = 0x2713; WFIFOL(s, 2) = acc; @@ -1066,7 +1062,6 @@ void parse_fromchar(Session *s) case 0x2714: if (RFIFOREST(s) < 6) return; - //PRINTF("parse_fromchar: Receiving of the users number of the server '%s': %d\n", server[id].name, RFIFOL(fd,2)); server[id].users = RFIFOL(s, 2); if (anti_freeze_enable) server_freezeflag[id] = 5; // Char anti-freeze system. Counter. 5 ok, 4...0 freezed @@ -1081,7 +1076,7 @@ void parse_fromchar(Session *s) int acc = RFIFOL(s, 2); AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 6)); if (!e_mail_check(email)) - LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else { @@ -1091,12 +1086,12 @@ void parse_fromchar(Session *s) && (ad.email == DEFAULT_EMAIL || !ad.email)) { ad.email = email; - LOGIN_LOG("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n"_fmt, server[id].name, acc, email, ip); goto x2715_out; } } - LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); } x2715_out: @@ -1110,12 +1105,11 @@ void parse_fromchar(Session *s) return; { int account_id = RFIFOL(s, 2); - //PRINTF("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2)); for (const AuthData& ad : auth_data) { if (ad.account_id == account_id) { - LOGIN_LOG("Char-server '%s': e-mail of the account %d found (ip: %s).\n", + LOGIN_LOG("Char-server '%s': e-mail of the account %d found (ip: %s).\n"_fmt, server[id].name, account_id, ip); WFIFOW(s, 0) = 0x2717; WFIFOL(s, 2) = account_id; @@ -1125,7 +1119,7 @@ void parse_fromchar(Session *s) goto x2716_end; } } - LOGIN_LOG("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n", + LOGIN_LOG("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n"_fmt, server[id].name, account_id, ip); } x2716_end: @@ -1139,7 +1133,6 @@ void parse_fromchar(Session *s) int acc; unsigned char buf[10]; acc = RFIFOL(s, 4); - //PRINTF("parse_fromchar: Request to become a GM acount from %d account.\n", acc); WBUFW(buf, 0) = 0x2721; WBUFL(buf, 2) = acc; WBUFL(buf, 6) = 0; @@ -1161,51 +1154,51 @@ void parse_fromchar(Session *s) timestamp_seconds_buffer tmpstr; stamp_time(tmpstr); FPRINTF(fp, - "\n// %s: @GM command on account %d\n%d %d\n", + "\n// %s: @GM command on account %d\n%d %d\n"_fmt, tmpstr, acc, acc, level_new_gm); if (!fp.close()) { - PRINTF("warning: didn't actually save GM file\n"); + PRINTF("warning: didn't actually save GM file\n"_fmt); } WBUFL(buf, 6) = level_new_gm; read_gm_account(); send_GM_accounts(); - PRINTF("GM Change of the account %d: level 0 -> %d.\n", + PRINTF("GM Change of the account %d: level 0 -> %d.\n"_fmt, acc, level_new_gm); - LOGIN_LOG("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n", + LOGIN_LOG("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n"_fmt, server[id].name, acc, level_new_gm, ip); } else { - PRINTF("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n", + PRINTF("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - PRINTF("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n", + PRINTF("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - PRINTF("Error of GM change (suggested account: %d (already GM), correct password).\n", + PRINTF("Error of GM change (suggested account: %d (already GM), correct password).\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - PRINTF("Error of GM change (suggested account: %d, invalid password).\n", + PRINTF("Error of GM change (suggested account: %d, invalid password).\n"_fmt, acc); - LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n"_fmt, server[id].name, acc, ip); } charif_sendallwos(nullptr, buf, 10); @@ -1222,13 +1215,13 @@ void parse_fromchar(Session *s) AccountEmail actual_email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 6).to_print()); AccountEmail new_email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 46)); if (!e_mail_check(actual_email)) - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else if (!e_mail_check(new_email)) - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else if (new_email == DEFAULT_EMAIL) - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n"_fmt, server[id].name, acc, ip); else { @@ -1239,19 +1232,19 @@ void parse_fromchar(Session *s) if (ad.email == actual_email) { ad.email = new_email; - LOGIN_LOG("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n"_fmt, server[id].name, acc, ad.userid, new_email, ip); } else - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n"_fmt, server[id].name, acc, ad.userid, ad.email, actual_email, ip); goto x2722_out; } } - LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); } } @@ -1273,7 +1266,7 @@ void parse_fromchar(Session *s) { if (ad.state != statut) { - LOGIN_LOG("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n"_fmt, server[id].name, acc, statut, ip); if (statut != 0) @@ -1291,13 +1284,13 @@ void parse_fromchar(Session *s) ad.state = statut; } else - LOGIN_LOG("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n"_fmt, server[id].name, acc, statut, ip); goto x2724_out; } } - LOGIN_LOG("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n"_fmt, server[id].name, acc, statut, ip); x2724_out: RFIFOSKIP(s, 10); @@ -1343,7 +1336,7 @@ void parse_fromchar(Session *s) timestamp_seconds_buffer tmpstr; if (timestamp) stamp_time(tmpstr, ×tamp); - LOGIN_LOG("Char-server '%s': Ban request (account: %d, new final date of banishment: %lld (%s), ip: %s).\n", + LOGIN_LOG("Char-server '%s': Ban request (account: %d, new final date of banishment: %lld (%s), ip: %s).\n"_fmt, server[id].name, acc, timestamp, tmpstr, @@ -1360,7 +1353,7 @@ void parse_fromchar(Session *s) } else { - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n"_fmt, server[id].name, acc, ip); } @@ -1368,19 +1361,19 @@ void parse_fromchar(Session *s) } else { - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n"_fmt, server[id].name, acc, ip); } } else { - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n"_fmt, server[id].name, acc, ip); } goto x2725_out; } } - LOGIN_LOG("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n"_fmt, server[id].name, acc, ip); x2725_out: RFIFOSKIP(s, 18); @@ -1404,7 +1397,7 @@ void parse_fromchar(Session *s) sex = SEX::MALE; else sex = SEX::FEMALE; - LOGIN_LOG("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n"_fmt, server[id].name, acc, sex_to_char(sex), ip); @@ -1420,7 +1413,7 @@ void parse_fromchar(Session *s) goto x2727_out; } } - LOGIN_LOG("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n"_fmt, server[id].name, acc, ip); x2727_out: RFIFOSKIP(s, 6); @@ -1437,7 +1430,7 @@ void parse_fromchar(Session *s) { if (ad.account_id == acc) { - LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); size_t len = RFIFOW(s, 2); int j; @@ -1454,11 +1447,10 @@ void parse_fromchar(Session *s) RFIFO_BUF_CLONE(s, buf, len); WBUFW(buf, 0) = 0x2729; charif_sendallwos(s, buf, WBUFW(buf, 2)); -// PRINTF("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc); goto x2728_out; } } - LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n", + LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n"_fmt, server[id].name, acc, ip); } x2728_out: @@ -1477,18 +1469,18 @@ void parse_fromchar(Session *s) if (ad.ban_until_time) { ad.ban_until_time = TimeT(); - LOGIN_LOG("Char-server '%s': UnBan request (account: %d, ip: %s).\n", + LOGIN_LOG("Char-server '%s': UnBan request (account: %d, ip: %s).\n"_fmt, server[id].name, acc, ip); } else { - LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n"_fmt, server[id].name, acc, ip); } goto x272a_out; } } - LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n", + LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n"_fmt, server[id].name, acc, ip); x272a_out: RFIFOSKIP(s, 6); @@ -1518,7 +1510,7 @@ void parse_fromchar(Session *s) { status = 1; ad.pass = MD5_saltcrypt(new_pass, make_salt()); - LOGIN_LOG("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n", + LOGIN_LOG("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n"_fmt, server[id].name, acc, ad.userid, ip); } @@ -1526,7 +1518,7 @@ void parse_fromchar(Session *s) else { status = 2; - LOGIN_LOG("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n", + LOGIN_LOG("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n"_fmt, server[id].name, acc, ad.userid, ip); } @@ -1551,30 +1543,30 @@ void parse_fromchar(Session *s) timestamp_milliseconds_buffer timestr; stamp_time(timestr); FPRINTF(logfp, - "%s: receiving of an unknown packet -> disconnection\n", + "%s: receiving of an unknown packet -> disconnection\n"_fmt, timestr); FPRINTF(logfp, - "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n", + "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n"_fmt, s, ip, RFIFOW(s, 0), RFIFOREST(s)); - FPRINTF(logfp, "Detail (in hex):\n"); + FPRINTF(logfp, "Detail (in hex):\n"_fmt); FPRINTF(logfp, - "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"); + "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"_fmt); char tmpstr[16 + 1] {}; int i; for (i = 0; i < RFIFOREST(s); i++) { if ((i & 15) == 0) - FPRINTF(logfp, "%04X ", i); - FPRINTF(logfp, "%02x ", RFIFOB(s, i)); + FPRINTF(logfp, "%04X "_fmt, i); + FPRINTF(logfp, "%02x "_fmt, RFIFOB(s, i)); if (RFIFOB(s, i) > 0x1f) tmpstr[i % 16] = RFIFOB(s, i); else tmpstr[i % 16] = '.'; if ((i - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); else if ((i + 1) % 16 == 0) { - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); std::fill(tmpstr + 0, tmpstr + 17, '\0'); } } @@ -1582,19 +1574,19 @@ void parse_fromchar(Session *s) { for (int j = i; j % 16 != 0; j++) { - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); if ((j - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); } - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); } - FPRINTF(logfp, "\n"); + FPRINTF(logfp, "\n"_fmt); } } - PRINTF("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n", + PRINTF("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n"_fmt, RFIFOW(s, 0)); s->eof = 1; - PRINTF("Char-server has been disconnected (unknown packet).\n"); + PRINTF("Char-server has been disconnected (unknown packet).\n"_fmt); return; } } @@ -1612,7 +1604,7 @@ void parse_admin(Session *s) if (s->eof) { delete_session(s); - PRINTF("Remote administration has disconnected (session #%d).\n", + PRINTF("Remote administration has disconnected (session #%d).\n"_fmt, s); return; } @@ -1620,13 +1612,13 @@ void parse_admin(Session *s) while (RFIFOREST(s) >= 2) { if (display_parse_admin == 1) - PRINTF("parse_admin: connection #%d, packet: 0x%x (with being read: %zu).\n", + PRINTF("parse_admin: connection #%d, packet: 0x%x (with being read: %zu).\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s)); switch (RFIFOW(s, 0)) { case 0x7530: // Request of the server version - LOGIN_LOG("'ladmin': Sending of the server version (ip: %s)\n", + LOGIN_LOG("'ladmin': Sending of the server version (ip: %s)\n"_fmt, ip); WFIFOW(s, 0) = 0x7531; WFIFO_STRUCT(s, 2, CURRENT_LOGIN_SERVER_VERSION); @@ -1635,7 +1627,7 @@ void parse_admin(Session *s) break; case 0x7532: // Request of end of connection - LOGIN_LOG("'ladmin': End of connection (ip: %s)\n", + LOGIN_LOG("'ladmin': End of connection (ip: %s)\n"_fmt, ip); RFIFOSKIP(s, 2); s->eof = 1; @@ -1654,7 +1646,7 @@ void parse_admin(Session *s) st = 0; if (ed > END_ACCOUNT_NUM || ed < st || ed <= 0) ed = END_ACCOUNT_NUM; - LOGIN_LOG("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n"_fmt, st, ed, ip); // Sending accounts information len = 4; @@ -1703,24 +1695,24 @@ void parse_admin(Session *s) struct mmo_account ma; ma.userid = stringish<AccountName>(RFIFO_STRING<24>(s, 2).to_print()); ma.passwd = stringish<AccountPass>(RFIFO_STRING<24>(s, 26).to_print()); - ma.lastlogin = stringish<timestamp_milliseconds_buffer>("-"); + ma.lastlogin = stringish<timestamp_milliseconds_buffer>("-"_s); ma.sex = sex_from_char(RFIFOB(s, 50)); WFIFOW(s, 0) = 0x7931; WFIFOL(s, 2) = -1; WFIFO_STRING(s, 6, ma.userid, 24); if (ma.userid.size() < 4 || ma.passwd.size() < 4) { - LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n"_fmt, ip); } else if (ma.sex != SEX::FEMALE && ma.sex != SEX::MALE) { - LOGIN_LOG("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n"_fmt, ma.userid, ip); } else if (account_id_count > END_ACCOUNT_NUM) { - LOGIN_LOG("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n"_fmt, ma.userid, ma.sex, ip); } else @@ -1729,7 +1721,7 @@ void parse_admin(Session *s) { if (ad.userid == ma.userid) { - LOGIN_LOG("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n"_fmt, ad.userid, ip); goto x7930_out; } @@ -1737,7 +1729,7 @@ void parse_admin(Session *s) { AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 51)); int new_id = mmo_auth_new(&ma, ma.sex, email); - LOGIN_LOG("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n"_fmt, ma.userid, new_id, ma.sex, auth_data.back().email, ip); WFIFOL(s, 2) = new_id; @@ -1768,12 +1760,12 @@ void parse_admin(Session *s) WFIFO_STRING(s, 6, ad->userid, 24); WFIFOL(s, 2) = ad->account_id; // save deleted account in log file - LOGIN_LOG("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n", + LOGIN_LOG("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n"_fmt, ad->userid, ad->account_id, ip); { AString buf2 = mmo_auth_tostr(ad); - LOGIN_LOG("%s\n", buf2); + LOGIN_LOG("%s\n"_fmt, buf2); } // delete account ad->userid = AccountName(); @@ -1782,7 +1774,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -1804,13 +1796,13 @@ void parse_admin(Session *s) AccountPass plain = stringish<AccountPass>(RFIFO_STRING<24>(s, 26)); ad->pass = MD5_saltcrypt(plain, make_salt()); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n"_fmt, ad->userid, ad->pass, ip); } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -1830,7 +1822,7 @@ void parse_admin(Session *s) if (statut != 7 || !error_message) { // 7: // 6 = Your are Prohibited to log in until %s - error_message = stringish<timestamp_seconds_buffer>("-"); + error_message = stringish<timestamp_seconds_buffer>("-"_s); } AuthData *ad = search_account(account_name); if (ad) @@ -1839,16 +1831,16 @@ void parse_admin(Session *s) WFIFOL(s, 2) = ad->account_id; if (ad->state == statut && ad->error_message == error_message) - LOGIN_LOG("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n"_fmt, account_name, statut, ip); else { if (statut == 7) - LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n"_fmt, ad->userid, statut, error_message, ip); else - LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n"_fmt, ad->userid, statut, ip); if (ad->state == 0) { @@ -1870,7 +1862,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n"_fmt, account_name, statut, ip); } WFIFOL(s, 30) = statut; @@ -1880,7 +1872,7 @@ void parse_admin(Session *s) break; case 0x7938: // Request for servers list and # of online players - LOGIN_LOG("'ladmin': Sending of servers list (ip: %s)\n", ip); + LOGIN_LOG("'ladmin': Sending of servers list (ip: %s)\n"_fmt, ip); server_num = 0; for (int i = 0; i < MAX_SERVERS; i++) { @@ -1916,20 +1908,20 @@ void parse_admin(Session *s) if (pass_ok(pass, ad->pass)) { WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n"_fmt, ad->userid, ad->pass, ip); } else { - LOGIN_LOG("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n"_fmt, ad->userid, pass.to_print(), ip); } } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -1949,7 +1941,7 @@ void parse_admin(Session *s) SEX sex = sex_from_char(RFIFOB(s, 26)); if (sex != SEX::FEMALE && sex != SEX::MALE) { - LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n"_fmt, account_name, sex_to_char(sex), ip); } else @@ -1967,7 +1959,7 @@ void parse_admin(Session *s) ad->account_id) auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification) ad->sex = sex; - LOGIN_LOG("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n"_fmt, ad->userid, sex_to_char(sex), ip); // send to all char-server the change WBUFW(buf, 0) = 0x2723; @@ -1977,13 +1969,13 @@ void parse_admin(Session *s) } else { - LOGIN_LOG("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n"_fmt, ad->userid, sex_to_char(sex), ip); } } else { - LOGIN_LOG("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n"_fmt, account_name, sex_to_char(sex), ip); } } @@ -2007,7 +1999,7 @@ void parse_admin(Session *s) new_gm_level = RFIFOB(s, 26); if (new_gm_level < 0 || new_gm_level > 99) { - LOGIN_LOG("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n"_fmt, account_name, new_gm_level, ip); } else @@ -2046,7 +2038,7 @@ void parse_admin(Session *s) else if (new_gm_level == 0) { FPRINTF(fp2, - "// %s: 'ladmin' GM level removed on account %d '%s' (previous level: %d)\n//%d %d\n", + "// %s: 'ladmin' GM level removed on account %d '%s' (previous level: %d)\n//%d %d\n"_fmt, tmpstr, acc, ad->userid, @@ -2057,7 +2049,7 @@ void parse_admin(Session *s) else { FPRINTF(fp2, - "// %s: 'ladmin' GM level on account %d '%s' (previous level: %d)\n%d %d\n", + "// %s: 'ladmin' GM level on account %d '%s' (previous level: %d)\n%d %d\n"_fmt, tmpstr, acc, ad->userid, @@ -2069,40 +2061,40 @@ void parse_admin(Session *s) } if (modify_flag == 0) FPRINTF(fp2, - "// %s: 'ladmin' GM level on account %d '%s' (previous level: 0)\n%d %d\n", + "// %s: 'ladmin' GM level on account %d '%s' (previous level: 0)\n%d %d\n"_fmt, tmpstr, acc, ad->userid, acc, new_gm_level); } else { - LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); } WFIFOL(s, 2) = acc; - LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); reread = true; } else { - LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); } } else { - LOGIN_LOG("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n"_fmt, ad->userid, acc, new_gm_level, ip); } } else { - LOGIN_LOG("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n"_fmt, account_name, new_gm_level, ip); } @@ -2131,7 +2123,7 @@ void parse_admin(Session *s) AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 26)); if (!e_mail_check(email)) { - LOGIN_LOG("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n"_fmt, account_name, ip); } else @@ -2142,12 +2134,12 @@ void parse_admin(Session *s) WFIFO_STRING(s, 6, ad->userid, 24); ad->email = email; WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n"_fmt, ad->userid, email, ip); } else { - LOGIN_LOG("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n"_fmt, account_name, email, ip); } } @@ -2169,10 +2161,10 @@ void parse_admin(Session *s) if (ad) { WFIFO_STRING(s, 6, ad->userid, 24); - ad->memo = ""; + ad->memo = ""_s; if (RFIFOW(s, 26) == 0) { - ad->memo = "!"; + ad->memo = "!"_s; } else { @@ -2182,13 +2174,13 @@ void parse_admin(Session *s) } ad->memo = ad->memo.to_print(); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n"_fmt, ad->userid, ad->memo, ip); } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -2208,14 +2200,14 @@ void parse_admin(Session *s) { WFIFO_STRING(s, 6, ad->userid, 24); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n"_fmt, ad->userid, ad->account_id, ip); } else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); } WFIFOSET(s, 30); @@ -2236,14 +2228,14 @@ void parse_admin(Session *s) if (ad.account_id == account_id) { WFIFO_STRING(s, 6, ad.userid, 24); - LOGIN_LOG("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n"_fmt, ad.userid, account_id, ip); goto x7946_out; } } - LOGIN_LOG("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n"_fmt, account_id, ip); - WFIFO_STRING(s, 6, "", 24); + WFIFO_STRING(s, 6, ""_s, 24); x7946_out: WFIFOSET(s, 30); } @@ -2258,14 +2250,14 @@ void parse_admin(Session *s) WFIFOL(s, 2) = -1; AccountName account_name = stringish<AccountName>(RFIFO_STRING<24>(s, 2).to_print()); TimeT timestamp = static_cast<time_t>(RFIFOL(s, 26)); - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"_s); if (timestamp) stamp_time(tmpstr, ×tamp); AuthData *ad = search_account(account_name); if (ad) { WFIFO_STRING(s, 6, ad->userid, 24); - LOGIN_LOG("'ladmin': Change of a validity limit (account: %s, new validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Change of a validity limit (account: %s, new validity: %lld (%s), ip: %s)\n"_fmt, ad->userid, timestamp, tmpstr, @@ -2276,7 +2268,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %lld (%s), ip: %s)\n"_fmt, account_name, timestamp, tmpstr, @@ -2298,7 +2290,7 @@ void parse_admin(Session *s) TimeT timestamp = static_cast<time_t>(RFIFOL(s, 26)); if (timestamp <= TimeT::now()) timestamp = TimeT(); - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"_s); if (timestamp) stamp_time(tmpstr, ×tamp); AuthData *ad = search_account(account_name); @@ -2306,7 +2298,7 @@ void parse_admin(Session *s) { WFIFO_STRING(s, 6, ad->userid, 24); WFIFOL(s, 2) = ad->account_id; - LOGIN_LOG("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %lld (%s), ip: %s)\n"_fmt, ad->userid, timestamp, tmpstr, ip); @@ -2331,7 +2323,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %lld (%s), ip: %s)\n"_fmt, account_name, timestamp, tmpstr, ip); @@ -2375,10 +2367,10 @@ void parse_admin(Session *s) { if (timestamp <= now) timestamp = TimeT(); - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"_s); if (timestamp) stamp_time(tmpstr, ×tamp); - LOGIN_LOG("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n"_fmt, ad->userid, ban_diff.year, ban_diff.month, ban_diff.day, ban_diff.hour, @@ -2406,10 +2398,10 @@ void parse_admin(Session *s) } else { - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("no banishment"_s); if (ad->ban_until_time) stamp_time(tmpstr, &ad->ban_until_time); - LOGIN_LOG("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", + LOGIN_LOG("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n"_fmt, ad->userid, ad->ban_until_time, tmpstr, @@ -2423,7 +2415,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); WFIFOL(s, 30) = 0; } @@ -2440,7 +2432,7 @@ void parse_admin(Session *s) WFIFOW(s, 2) = -1; if (RFIFOL(s, 4) < 1) { - LOGIN_LOG("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n", + LOGIN_LOG("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n"_fmt, ip); } else @@ -2449,7 +2441,7 @@ void parse_admin(Session *s) for (int i = 0; i < MAX_SERVERS; i++) if (server_session[i]) goto x794e_have_server; - LOGIN_LOG("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n", + LOGIN_LOG("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n"_fmt, ip); goto x794e_have_no_server; { @@ -2459,7 +2451,7 @@ void parse_admin(Session *s) size_t len = RFIFOL(s, 4); AString message = RFIFO_STRING(s, 8, len).to_print(); - LOGIN_LOG("'ladmin': Receiving a message for broadcast (message: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Receiving a message for broadcast (message: %s, ip: %s)\n"_fmt, message, ip); // send same message to all char-servers (no answer) uint8_t buf[len + 8]; @@ -2487,7 +2479,7 @@ void parse_admin(Session *s) WFIFO_STRING(s, 6, ad->userid, 24); if (add_to_unlimited_account == 0 && !ad->connect_until_time) { - LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n"_fmt, ad->userid, ip); WFIFOL(s, 30) = 0; } @@ -2509,13 +2501,13 @@ void parse_admin(Session *s) timestamp = tmtime; if (timestamp.okay()) { - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"); - timestamp_seconds_buffer tmpstr2 = stringish<timestamp_seconds_buffer>("unlimited"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"_s); + timestamp_seconds_buffer tmpstr2 = stringish<timestamp_seconds_buffer>("unlimited"_s); if (ad->connect_until_time) stamp_time(tmpstr, &ad->connect_until_time); if (timestamp) stamp_time(tmpstr2, ×tamp); - LOGIN_LOG("'ladmin': Adjustment of a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n", + LOGIN_LOG("'ladmin': Adjustment of a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %lld (%s), ip: %s)\n"_fmt, ad->userid, ad->connect_until_time, tmpstr, @@ -2533,10 +2525,10 @@ void parse_admin(Session *s) } else { - timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"); + timestamp_seconds_buffer tmpstr = stringish<timestamp_seconds_buffer>("unlimited"_s); if (ad->connect_until_time) stamp_time(tmpstr, &ad->connect_until_time); - LOGIN_LOG("'ladmin': Impossible to adjust a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n", + LOGIN_LOG("'ladmin': Impossible to adjust a validity limit (account: %s, %lld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n"_fmt, ad->userid, ad->connect_until_time, tmpstr, @@ -2554,7 +2546,7 @@ void parse_admin(Session *s) else { WFIFO_STRING(s, 6, account_name, 24); - LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); WFIFOL(s, 30) = 0; } @@ -2588,7 +2580,7 @@ void parse_admin(Session *s) size_t len = ad->memo.size() + 1; WFIFOW(s, 148) = len; WFIFO_STRING(s, 150, ad->memo, len); - LOGIN_LOG("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n"_fmt, ad->userid, ad->account_id, ip); WFIFOSET(s, 150 + len); @@ -2597,7 +2589,7 @@ void parse_admin(Session *s) { WFIFO_STRING(s, 7, account_name, 24); WFIFOW(s, 148) = 0; - LOGIN_LOG("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n"_fmt, account_name, ip); WFIFOSET(s, 150); } @@ -2617,7 +2609,7 @@ void parse_admin(Session *s) { if (ad.account_id == account_id) { - LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n"_fmt, ad.userid, RFIFOL(s, 2), ip); WFIFOB(s, 6) = isGM(ad.account_id); WFIFO_STRING(s, 7, ad.userid, 24); @@ -2638,9 +2630,9 @@ void parse_admin(Session *s) } } { - LOGIN_LOG("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n", + LOGIN_LOG("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n"_fmt, RFIFOL(s, 2), ip); - WFIFO_STRING(s, 7, "", 24); + WFIFO_STRING(s, 7, ""_s, 24); WFIFOW(s, 148) = 0; WFIFOSET(s, 150); } @@ -2650,7 +2642,7 @@ void parse_admin(Session *s) break; case 0x7955: // Request to reload GM file (no answer) - LOGIN_LOG("'ladmin': Request to re-load GM configuration file (ip: %s).\n", + LOGIN_LOG("'ladmin': Request to re-load GM configuration file (ip: %s).\n"_fmt, ip); read_gm_account(); // send GM accounts to all char-servers @@ -2666,30 +2658,30 @@ void parse_admin(Session *s) timestamp_milliseconds_buffer timestr; stamp_time(timestr); FPRINTF(logfp, - "%s: receiving of an unknown packet -> disconnection\n", + "%s: receiving of an unknown packet -> disconnection\n"_fmt, timestr); FPRINTF(logfp, - "parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n", + "parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n"_fmt, s, ip, RFIFOW(s, 0), RFIFOREST(s)); - FPRINTF(logfp, "Detail (in hex):\n"); + FPRINTF(logfp, "Detail (in hex):\n"_fmt); FPRINTF(logfp, - "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"); + "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"_fmt); char tmpstr[16 + 1] {}; int i; for (i = 0; i < RFIFOREST(s); i++) { if ((i & 15) == 0) - FPRINTF(logfp, "%04X ", i); - FPRINTF(logfp, "%02x ", RFIFOB (s, i)); + FPRINTF(logfp, "%04X "_fmt, i); + FPRINTF(logfp, "%02x "_fmt, RFIFOB (s, i)); if (RFIFOB(s, i) > 0x1f) tmpstr[i % 16] = RFIFOB(s, i); else tmpstr[i % 16] = '.'; if ((i - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); else if ((i + 1) % 16 == 0) { - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); std::fill(tmpstr + 0, tmpstr + 17, '\0'); } } @@ -2697,19 +2689,19 @@ void parse_admin(Session *s) { for (int j = i; j % 16 != 0; j++) { - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); if ((j - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); } - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); } - FPRINTF(logfp, "\n"); + FPRINTF(logfp, "\n"_fmt); } } - LOGIN_LOG("'ladmin': End of connection, unknown packet (ip: %s)\n", + LOGIN_LOG("'ladmin': End of connection, unknown packet (ip: %s)\n"_fmt, ip); s->eof = 1; - PRINTF("Remote administration has been disconnected (unknown packet).\n"); + PRINTF("Remote administration has been disconnected (unknown packet).\n"_fmt); return; } //WFIFOW(fd,0) = 0x791f; @@ -2726,7 +2718,7 @@ bool lan_ip_check(IP4Address p) { bool lancheck = lan_subnet.covers(p); - PRINTF("LAN test (result): %s.\n", + PRINTF("LAN test (result): %s.\n"_fmt, (lancheck) ? SGR_BOLD SGR_CYAN "LAN source" SGR_RESET : SGR_BOLD SGR_GREEN "WAN source" SGR_RESET); return lancheck; } @@ -2757,7 +2749,7 @@ void parse_login(Session *s) if (RFIFOREST(s) >= ((RFIFOW(s, 0) == 0x64) ? 55 : 47)) { AccountName account_name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), account: %s.\n", + PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), account: %s.\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s), account_name); } @@ -2767,13 +2759,13 @@ void parse_login(Session *s) if (RFIFOREST(s) >= 86) { ServerName server_name = stringish<ServerName>(RFIFO_STRING<20>(s, 60)); - PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), server: %s.\n", + PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu), server: %s.\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s), server_name); } } else - PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu).\n", + PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %zu).\n"_fmt, s, RFIFOW(s, 0), RFIFOREST(s)); } @@ -2799,12 +2791,12 @@ void parse_login(Session *s) account.passwd = stringish<AccountPass>(RFIFO_STRING<24>(s, 30).to_print()); account.passwdenc = 0; - LOGIN_LOG("Request for connection (non encryption mode) of %s (ip: %s).\n", + LOGIN_LOG("Request for connection (non encryption mode) of %s (ip: %s).\n"_fmt, account.userid, ip); if (!check_ip(ip)) { - LOGIN_LOG("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n", + LOGIN_LOG("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n"_fmt, ip); WFIFOW(s, 0) = 0x6a; WFIFOB(s, 2) = 0x03; @@ -2827,7 +2819,7 @@ void parse_login(Session *s) int gm_level = isGM(account.account_id); if (min_level_to_connect > gm_level) { - LOGIN_LOG("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n", + LOGIN_LOG("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n"_fmt, min_level_to_connect, account.userid, gm_level, ip); WFIFOW(s, 0) = 0x81; @@ -2839,10 +2831,10 @@ void parse_login(Session *s) // int version_2 = RFIFOB(fd, 54); // version 2 if (gm_level) - PRINTF("Connection of the GM (level:%d) account '%s' accepted.\n", + PRINTF("Connection of the GM (level:%d) account '%s' accepted.\n"_fmt, gm_level, account.userid); else - PRINTF("Connection of the account '%s' accepted.\n", + PRINTF("Connection of the account '%s' accepted.\n"_fmt, account.userid); /* @@ -2916,7 +2908,7 @@ void parse_login(Session *s) } else { - LOGIN_LOG("Connection refused: there is no char-server online (account: %s, ip: %s).\n", + LOGIN_LOG("Connection refused: there is no char-server online (account: %s, ip: %s).\n"_fmt, account.userid, ip); WFIFOW(s, 0) = 0x81; WFIFOB(s, 2) = 1; // 01 = Server closed @@ -2962,7 +2954,7 @@ void parse_login(Session *s) account.passwd = stringish<AccountPass>(RFIFO_STRING<24>(s, 26).to_print()); account.passwdenc = 0; ServerName server_name = stringish<ServerName>(RFIFO_STRING<20>(s, 60).to_print()); - LOGIN_LOG("Connection request of the char-server '%s' @ %s:%d (ip: %s)\n", + LOGIN_LOG("Connection request of the char-server '%s' @ %s:%d (ip: %s)\n"_fmt, server_name, RFIFOIP(s, 54), RFIFOW(s, 58), ip); if (account.userid == userid && account.passwd == passwd) { @@ -2990,10 +2982,10 @@ void parse_login(Session *s) { x2710_okay: - LOGIN_LOG("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n", + LOGIN_LOG("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n"_fmt, server_name, account.userid, account.passwd, ip); - PRINTF("Connection of the char-server '%s' accepted.\n", + PRINTF("Connection of the char-server '%s' accepted.\n"_fmt, server_name); server[account.account_id] = mmo_char_server{}; server[account.account_id].ip = RFIFOIP(s, 54); @@ -3027,7 +3019,7 @@ void parse_login(Session *s) } { x2710_refused: - LOGIN_LOG("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n", + LOGIN_LOG("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n"_fmt, server_name, account.userid, account.passwd, ip); WFIFOW(s, 0) = 0x2711; @@ -3040,7 +3032,7 @@ void parse_login(Session *s) return; case 0x7530: // Request of the server version - LOGIN_LOG("Sending of the server version (ip: %s)\n", + LOGIN_LOG("Sending of the server version (ip: %s)\n"_fmt, ip); WFIFOW(s, 0) = 0x7531; { @@ -3053,7 +3045,7 @@ void parse_login(Session *s) break; case 0x7532: // Request to end connection - LOGIN_LOG("End of connection (ip: %s)\n", ip); + LOGIN_LOG("End of connection (ip: %s)\n"_fmt, ip); s->eof = 1; return; @@ -3065,7 +3057,7 @@ void parse_login(Session *s) WFIFOB(s, 2) = 1; if (!check_ladminip(s->client_ip)) { - LOGIN_LOG("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n"_fmt, ip); } else @@ -3078,24 +3070,24 @@ void parse_login(Session *s) if ((admin_state == 1) && (password == admin_pass)) { - LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n"_fmt, password, ip); - PRINTF("Connection of a remote administration accepted (non encrypted password).\n"); + PRINTF("Connection of a remote administration accepted (non encrypted password).\n"_fmt); WFIFOB(s, 2) = 0; s->func_parse = parse_admin; } else if (admin_state != 1) - LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n"_fmt, password, ip); else - LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n"_fmt, password, ip); } else { // encrypted password { - LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - encrypted login is disabled (ip: %s)\n", + LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - encrypted login is disabled (ip: %s)\n"_fmt, ip); } } @@ -3113,15 +3105,15 @@ void parse_login(Session *s) timestamp_milliseconds_buffer timestr; stamp_time(timestr); FPRINTF(logfp, - "%s: receiving of an unknown packet -> disconnection\n", + "%s: receiving of an unknown packet -> disconnection\n"_fmt, timestr); FPRINTF(logfp, - "parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n", + "parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n"_fmt, s, ip, RFIFOW(s, 0), RFIFOREST(s)); - FPRINTF(logfp, "Detail (in hex):\n"); + FPRINTF(logfp, "Detail (in hex):\n"_fmt); FPRINTF(logfp, - "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"); + "---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n"_fmt); char tmpstr[16 + 1] {}; @@ -3129,17 +3121,17 @@ void parse_login(Session *s) for (i = 0; i < RFIFOREST(s); i++) { if ((i & 15) == 0) - FPRINTF(logfp, "%04X ", i); - FPRINTF(logfp, "%02x ", RFIFOB(s, i)); + FPRINTF(logfp, "%04X "_fmt, i); + FPRINTF(logfp, "%02x "_fmt, RFIFOB(s, i)); if (RFIFOB(s, i) > 0x1f) tmpstr[i % 16] = RFIFOB(s, i); else tmpstr[i % 16] = '.'; if ((i - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); else if ((i + 1) % 16 == 0) { - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); std::fill(tmpstr + 0, tmpstr + 17, '\0'); } } @@ -3147,16 +3139,16 @@ void parse_login(Session *s) { for (j = i; j % 16 != 0; j++) { - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); if ((j - 7) % 16 == 0) // -8 + 1 - FPRINTF(logfp, " "); + FPRINTF(logfp, " "_fmt); } - FPRINTF(logfp, " %s\n", tmpstr); + FPRINTF(logfp, " %s\n"_fmt, tmpstr); } - FPRINTF(logfp, "\n"); + FPRINTF(logfp, "\n"_fmt); } } - LOGIN_LOG("End of connection, unknown packet (ip: %s)\n", ip); + LOGIN_LOG("End of connection, unknown packet (ip: %s)\n"_fmt, ip); s->eof = 1; return; } @@ -3173,7 +3165,7 @@ bool login_lan_config(XString w1, ZString w2) struct hostent *h = NULL; { - if (w1 == "lan_char_ip") + if (w1 == "lan_char_ip"_s) { // Read Char-Server Lan IP Address h = gethostbyname(w2.c_str()); @@ -3188,20 +3180,20 @@ bool login_lan_config(XString w1, ZString w2) } else { - PRINTF("Bad IP value: %s\n", w2); + PRINTF("Bad IP value: %s\n"_fmt, w2); return false; } - PRINTF("LAN IP of char-server: %s.\n", lan_char_ip); + PRINTF("LAN IP of char-server: %s.\n"_fmt, lan_char_ip); } - else if (w1 == "subnet" /*backward compatibility*/ - || w1 == "lan_subnet") + else if (w1 == "subnet"_s /*backward compatibility*/ + || w1 == "lan_subnet"_s) { if (!extract(w2, &lan_subnet)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } - PRINTF("Sub-network of the char-server: %s.\n", + PRINTF("Sub-network of the char-server: %s.\n"_fmt, lan_subnet); } else @@ -3216,18 +3208,18 @@ static bool lan_check() { // log the LAN configuration - LOGIN_LOG("The LAN configuration of the server is set:\n"); - LOGIN_LOG("- with LAN IP of char-server: %s.\n", lan_char_ip); - LOGIN_LOG("- with the sub-network of the char-server: %s.\n", + LOGIN_LOG("The LAN configuration of the server is set:\n"_fmt); + LOGIN_LOG("- with LAN IP of char-server: %s.\n"_fmt, lan_char_ip); + LOGIN_LOG("- with the sub-network of the char-server: %s.\n"_fmt, lan_subnet); // sub-network check of the char-server { - PRINTF("LAN test of LAN IP of the char-server: "); + PRINTF("LAN test of LAN IP of the char-server: "_fmt); if (!lan_ip_check(lan_char_ip)) { - PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network" SGR_RESET "\n"); - LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n"); + PRINTF(SGR_BOLD SGR_RED "***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network"_fmt SGR_RESET "\n"); + LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n"_fmt); return false; } } @@ -3242,24 +3234,24 @@ static bool login_config(XString w1, ZString w2) { { - if (w1 == "admin_state") + if (w1 == "admin_state"_s) { admin_state = config_switch(w2); } - else if (w1 == "admin_pass") + else if (w1 == "admin_pass"_s) { admin_pass = stringish<AccountPass>(w2); } - else if (w1 == "ladminallowip") + else if (w1 == "ladminallowip"_s) { - if (w2 == "clear") + if (w2 == "clear"_s) { access_ladmin.clear(); } else { // a.b.c.d/0.0.0.0 (canonically, 0.0.0.0/0) covers all - if (w2 == "all") + if (w2 == "all"_s) { // reset all previous values access_ladmin.clear(); @@ -3274,104 +3266,104 @@ bool login_config(XString w1, ZString w2) IP4Mask n; if (!extract(w2, &n)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } access_ladmin.push_back(n); } } } - else if (w1 == "gm_pass") + else if (w1 == "gm_pass"_s) { gm_pass = w2; } - else if (w1 == "level_new_gm") + else if (w1 == "level_new_gm"_s) { level_new_gm = atoi(w2.c_str()); } - else if (w1 == "new_account") + else if (w1 == "new_account"_s) { new_account = config_switch(w2); } - else if (w1 == "login_port") + else if (w1 == "login_port"_s) { login_port = atoi(w2.c_str()); } - else if (w1 == "account_filename") + else if (w1 == "account_filename"_s) { account_filename = w2; } - else if (w1 == "gm_account_filename") + else if (w1 == "gm_account_filename"_s) { gm_account_filename = w2; } - else if (w1 == "gm_account_filename_check_timer") + else if (w1 == "gm_account_filename_check_timer"_s) { gm_account_filename_check_timer = std::chrono::seconds(atoi(w2.c_str())); } - else if (w1 == "login_log_filename") + else if (w1 == "login_log_filename"_s) { login_log_filename = w2; } - else if (w1 == "login_log_unknown_packets_filename") + else if (w1 == "login_log_unknown_packets_filename"_s) { login_log_unknown_packets_filename = w2; } - else if (w1 == "save_unknown_packets") + else if (w1 == "save_unknown_packets"_s) { save_unknown_packets = config_switch(w2); } - else if (w1 == "display_parse_login") + else if (w1 == "display_parse_login"_s) { display_parse_login = config_switch(w2); // 0: no, 1: yes } - else if (w1 == "display_parse_admin") + else if (w1 == "display_parse_admin"_s) { display_parse_admin = config_switch(w2); // 0: no, 1: yes } - else if (w1 == "display_parse_fromchar") + else if (w1 == "display_parse_fromchar"_s) { display_parse_fromchar = config_switch(w2); // 0: no, 1: yes (without packet 0x2714), 2: all packets } - else if (w1 == "min_level_to_connect") + else if (w1 == "min_level_to_connect"_s) { min_level_to_connect = atoi(w2.c_str()); } - else if (w1 == "add_to_unlimited_account") + else if (w1 == "add_to_unlimited_account"_s) { add_to_unlimited_account = config_switch(w2); } - else if (w1 == "start_limited_time") + else if (w1 == "start_limited_time"_s) { start_limited_time = atoi(w2.c_str()); } - else if (w1 == "check_ip_flag") + else if (w1 == "check_ip_flag"_s) { check_ip_flag = config_switch(w2); } - else if (w1 == "order") + else if (w1 == "order"_s) { - if (w2 == "deny,allow" || w2 == "deny, allow") + if (w2 == "deny,allow"_s || w2 == "deny, allow"_s) access_order = ACO::DENY_ALLOW; - else if (w2 == "allow,deny" || w2 == "allow, deny") + else if (w2 == "allow,deny"_s || w2 == "allow, deny"_s) access_order = ACO::ALLOW_DENY; - else if (w2 == "mutual-failture" || w2 == "mutual-failure") + else if (w2 == "mutual-failture"_s || w2 == "mutual-failure"_s) access_order = ACO::MUTUAL_FAILURE; else { - PRINTF("Bad order: %s\n", w2); + PRINTF("Bad order: %s\n"_fmt, w2); return false; } } - else if (w1 == "allow") + else if (w1 == "allow"_s) { - if (w2 == "clear") + if (w2 == "clear"_s) { access_allow.clear(); } else { - if (w2 == "all") + if (w2 == "all"_s) { // reset all previous values access_allow.clear(); @@ -3386,22 +3378,22 @@ bool login_config(XString w1, ZString w2) IP4Mask n; if (!extract(w2, &n)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } access_allow.push_back(n); } } } - else if (w1 == "deny") + else if (w1 == "deny"_s) { - if (w2 == "clear") + if (w2 == "clear"_s) { access_deny.clear(); } else { - if (w2 == "all") + if (w2 == "all"_s) { // reset all previous values access_deny.clear(); @@ -3416,36 +3408,36 @@ bool login_config(XString w1, ZString w2) IP4Mask n; if (!extract(w2, &n)) { - PRINTF("Bad IP mask: %s\n", w2); + PRINTF("Bad IP mask: %s\n"_fmt, w2); return false; } access_deny.push_back(n); } } } - else if (w1 == "anti_freeze_enable") + else if (w1 == "anti_freeze_enable"_s) { anti_freeze_enable = config_switch(w2); } - else if (w1 == "anti_freeze_interval") + else if (w1 == "anti_freeze_interval"_s) { anti_freeze_interval = std::max( std::chrono::seconds(atoi(w2.c_str())), std::chrono::seconds(5)); } - else if (w1 == "update_host") + else if (w1 == "update_host"_s) { update_host = w2; } - else if (w1 == "main_server") + else if (w1 == "main_server"_s) { main_server = stringish<ServerName>(w2); } - else if (w1 == "userid") + else if (w1 == "userid"_s) { userid = stringish<AccountName>(w2); } - else if (w1 == "passwd") + else if (w1 == "passwd"_s) { passwd = stringish<AccountPass>(w2); } @@ -3467,7 +3459,7 @@ bool display_conf_warnings(void) bool rv = true; if (admin_state != 0 && admin_state != 1) { - PRINTF("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n"); + PRINTF("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n"_fmt); admin_state = 0; rv = false; } @@ -3476,132 +3468,132 @@ bool display_conf_warnings(void) { if (!admin_pass) { - PRINTF("***WARNING: Administrator password is void (admin_pass).\n"); + PRINTF("***WARNING: Administrator password is void (admin_pass).\n"_fmt); rv = false; } - else if (admin_pass == stringish<AccountPass>("admin")) + else if (admin_pass == stringish<AccountPass>("admin"_s)) { - PRINTF("***WARNING: You are using the default administrator password (admin_pass).\n"); - PRINTF(" We highly recommend that you change it.\n"); + PRINTF("***WARNING: You are using the default administrator password (admin_pass).\n"_fmt); + PRINTF(" We highly recommend that you change it.\n"_fmt); } } if (!gm_pass) { - PRINTF("***WARNING: 'To GM become' password is void (gm_pass).\n"); - PRINTF(" We highly recommend that you set one password.\n"); + PRINTF("***WARNING: 'To GM become' password is void (gm_pass).\n"_fmt); + PRINTF(" We highly recommend that you set one password.\n"_fmt); rv = false; } - else if (gm_pass == "gm") + else if (gm_pass == "gm"_s) { - PRINTF("***WARNING: You are using the default GM password (gm_pass).\n"); - PRINTF(" We highly recommend that you change it.\n"); + PRINTF("***WARNING: You are using the default GM password (gm_pass).\n"_fmt); + PRINTF(" We highly recommend that you change it.\n"_fmt); } if (level_new_gm < 0 || level_new_gm > 99) { - PRINTF("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n"); + PRINTF("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n"_fmt); level_new_gm = 60; rv = false; } if (new_account != 0 && new_account != 1) { - PRINTF("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n"); + PRINTF("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n"_fmt); new_account = 0; rv = false; } if (login_port < 1024 || login_port > 65535) { - PRINTF("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n"); + PRINTF("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n"_fmt); login_port = 6900; rv = false; } if (gm_account_filename_check_timer.count() < 0) { - PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"); - PRINTF(" -> set to 15 sec (default).\n"); + PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"_fmt); + PRINTF(" -> set to 15 sec (default).\n"_fmt); gm_account_filename_check_timer = std::chrono::seconds(15); rv = false; } else if (gm_account_filename_check_timer == std::chrono::seconds(1)) { - PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"); - PRINTF(" -> set to 2 sec (minimum value).\n"); + PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"_fmt); + PRINTF(" -> set to 2 sec (minimum value).\n"_fmt); gm_account_filename_check_timer = std::chrono::seconds(2); rv = false; } if (save_unknown_packets != 0 && save_unknown_packets != 1) { - PRINTF("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n"); + PRINTF("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n"_fmt); save_unknown_packets = 0; rv = false; } if (display_parse_login != 0 && display_parse_login != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for display_parse_login parameter\n"); - PRINTF(" -> set to 0 (no display).\n"); + PRINTF("***WARNING: Invalid value for display_parse_login parameter\n"_fmt); + PRINTF(" -> set to 0 (no display).\n"_fmt); display_parse_login = 0; rv = false; } if (display_parse_admin != 0 && display_parse_admin != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for display_parse_admin parameter\n"); - PRINTF(" -> set to 0 (no display).\n"); + PRINTF("***WARNING: Invalid value for display_parse_admin parameter\n"_fmt); + PRINTF(" -> set to 0 (no display).\n"_fmt); display_parse_admin = 0; rv = false; } if (display_parse_fromchar < 0 || display_parse_fromchar > 2) { // 0: no, 1: yes (without packet 0x2714), 2: all packets - PRINTF("***WARNING: Invalid value for display_parse_fromchar parameter\n"); - PRINTF(" -> set to 0 (no display).\n"); + PRINTF("***WARNING: Invalid value for display_parse_fromchar parameter\n"_fmt); + PRINTF(" -> set to 0 (no display).\n"_fmt); display_parse_fromchar = 0; rv = false; } if (min_level_to_connect < 0) { // 0: all players, 1-99 at least gm level x - PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n", + PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n"_fmt, min_level_to_connect); - PRINTF(" -> set to 0 (any player).\n"); + PRINTF(" -> set to 0 (any player).\n"_fmt); min_level_to_connect = 0; rv = false; } else if (min_level_to_connect > 99) { // 0: all players, 1-99 at least gm level x - PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n", + PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n"_fmt, min_level_to_connect); - PRINTF(" -> set to 99 (only GM level 99).\n"); + PRINTF(" -> set to 99 (only GM level 99).\n"_fmt); min_level_to_connect = 99; rv = false; } if (add_to_unlimited_account != 0 && add_to_unlimited_account != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for add_to_unlimited_account parameter\n"); - PRINTF(" -> set to 0 (impossible to add a time to an unlimited account).\n"); + PRINTF("***WARNING: Invalid value for add_to_unlimited_account parameter\n"_fmt); + PRINTF(" -> set to 0 (impossible to add a time to an unlimited account).\n"_fmt); add_to_unlimited_account = 0; rv = false; } if (start_limited_time < -1) { // -1: create unlimited account, 0 or more: additionnal sec from now to create limited time - PRINTF("***WARNING: Invalid value for start_limited_time parameter\n"); - PRINTF(" -> set to -1 (new accounts are created with unlimited time).\n"); + PRINTF("***WARNING: Invalid value for start_limited_time parameter\n"_fmt); + PRINTF(" -> set to -1 (new accounts are created with unlimited time).\n"_fmt); start_limited_time = -1; rv = false; } if (check_ip_flag != 0 && check_ip_flag != 1) { // 0: no, 1: yes - PRINTF("***WARNING: Invalid value for check_ip_flag parameter\n"); - PRINTF(" -> set to 1 (check players ip between login-server & char-server).\n"); + PRINTF("***WARNING: Invalid value for check_ip_flag parameter\n"_fmt); + PRINTF(" -> set to 1 (check players ip between login-server & char-server).\n"_fmt); check_ip_flag = 1; rv = false; } @@ -3610,8 +3602,8 @@ bool display_conf_warnings(void) { if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - PRINTF("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n"); - PRINTF(" And you refuse ALL IP.\n"); + PRINTF("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n"_fmt); + PRINTF(" And you refuse ALL IP.\n"_fmt); rv = false; } } @@ -3619,8 +3611,8 @@ bool display_conf_warnings(void) { if (access_allow.empty()) { - PRINTF("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n"); - PRINTF(" But, NO IP IS AUTHORISED!\n"); + PRINTF("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n"_fmt); + PRINTF(" But, NO IP IS AUTHORISED!\n"_fmt); rv = false; } } @@ -3629,16 +3621,16 @@ bool display_conf_warnings(void) // ACO::MUTUAL_FAILURE if (access_allow.empty()) { - PRINTF("***WARNING: The IP security order is 'mutual-failture'\n"); - PRINTF(" (allow if in the allow list and not in the deny list).\n"); - PRINTF(" But, NO IP IS AUTHORISED!\n"); + PRINTF("***WARNING: The IP security order is 'mutual-failture'\n"_fmt); + PRINTF(" (allow if in the allow list and not in the deny list).\n"_fmt); + PRINTF(" But, NO IP IS AUTHORISED!\n"_fmt); rv = false; } else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - PRINTF("***WARNING: The IP security order is mutual-failture\n"); - PRINTF(" (allow if in the allow list and not in the deny list).\n"); - PRINTF(" But, you refuse ALL IP!\n"); + PRINTF("***WARNING: The IP security order is mutual-failture\n"_fmt); + PRINTF(" (allow if in the allow list and not in the deny list).\n"_fmt); + PRINTF(" But, you refuse ALL IP!\n"_fmt); rv = false; } } @@ -3652,168 +3644,168 @@ static void save_config_in_log(void) { // a newline in the log... - LOGIN_LOG(""); - LOGIN_LOG("The login-server starting...\n"); + LOGIN_LOG(""_fmt); + LOGIN_LOG("The login-server starting...\n"_fmt); // save configuration in log file - LOGIN_LOG("The configuration of the server is set:\n"); + LOGIN_LOG("The configuration of the server is set:\n"_fmt); if (admin_state != 1) - LOGIN_LOG("- with no remote administration.\n"); + LOGIN_LOG("- with no remote administration.\n"_fmt); else if (!admin_pass) - LOGIN_LOG("- with a remote administration with a VOID password.\n"); - else if (admin_pass == stringish<AccountPass>("admin")) - LOGIN_LOG("- with a remote administration with the DEFAULT password.\n"); + LOGIN_LOG("- with a remote administration with a VOID password.\n"_fmt); + else if (admin_pass == stringish<AccountPass>("admin"_s)) + LOGIN_LOG("- with a remote administration with the DEFAULT password.\n"_fmt); else - LOGIN_LOG("- with a remote administration with the password of %zu character(s).\n", + LOGIN_LOG("- with a remote administration with the password of %zu character(s).\n"_fmt, admin_pass.size()); if (access_ladmin.empty() || (access_ladmin.size() == 1 && access_ladmin.front().mask() == IP4Address())) { - LOGIN_LOG("- to accept any IP for remote administration\n"); + LOGIN_LOG("- to accept any IP for remote administration\n"_fmt); } else { - LOGIN_LOG("- to accept following IP for remote administration:\n"); + LOGIN_LOG("- to accept following IP for remote administration:\n"_fmt); for (const IP4Mask& ae : access_ladmin) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } if (!gm_pass) - LOGIN_LOG("- with a VOID 'To GM become' password (gm_pass).\n"); - else if (gm_pass == "gm") - LOGIN_LOG("- with the DEFAULT 'To GM become' password (gm_pass).\n"); + LOGIN_LOG("- with a VOID 'To GM become' password (gm_pass).\n"_fmt); + else if (gm_pass == "gm"_s) + LOGIN_LOG("- with the DEFAULT 'To GM become' password (gm_pass).\n"_fmt); else - LOGIN_LOG("- with a 'To GM become' password (gm_pass) of %zu character(s).\n", + LOGIN_LOG("- with a 'To GM become' password (gm_pass) of %zu character(s).\n"_fmt, gm_pass.size()); if (level_new_gm == 0) - LOGIN_LOG("- to refuse any creation of GM with @gm.\n"); + LOGIN_LOG("- to refuse any creation of GM with @gm.\n"_fmt); else - LOGIN_LOG("- to create GM with level '%d' when @gm is used.\n", + LOGIN_LOG("- to create GM with level '%d' when @gm is used.\n"_fmt, level_new_gm); if (new_account == 1) - LOGIN_LOG("- to ALLOW new users (with _F/_M).\n"); + LOGIN_LOG("- to ALLOW new users (with _F/_M).\n"_fmt); else - LOGIN_LOG("- to NOT ALLOW new users (with _F/_M).\n"); - LOGIN_LOG("- with port: %d.\n", login_port); - LOGIN_LOG("- with the accounts file name: '%s'.\n", + LOGIN_LOG("- to NOT ALLOW new users (with _F/_M).\n"_fmt); + LOGIN_LOG("- with port: %d.\n"_fmt, login_port); + LOGIN_LOG("- with the accounts file name: '%s'.\n"_fmt, account_filename); - LOGIN_LOG("- with the GM accounts file name: '%s'.\n", + LOGIN_LOG("- with the GM accounts file name: '%s'.\n"_fmt, gm_account_filename); if (gm_account_filename_check_timer == interval_t::zero()) - LOGIN_LOG("- to NOT check GM accounts file modifications.\n"); + LOGIN_LOG("- to NOT check GM accounts file modifications.\n"_fmt); else - LOGIN_LOG("- to check GM accounts file modifications every %lld seconds.\n", + LOGIN_LOG("- to check GM accounts file modifications every %lld seconds.\n"_fmt, maybe_cast<long long>(gm_account_filename_check_timer.count())); // not necessary to log the 'login_log_filename', we are inside :) - LOGIN_LOG("- with the unknown packets file name: '%s'.\n", + LOGIN_LOG("- with the unknown packets file name: '%s'.\n"_fmt, login_log_unknown_packets_filename); if (save_unknown_packets) - LOGIN_LOG("- to SAVE all unkown packets.\n"); + LOGIN_LOG("- to SAVE all unkown packets.\n"_fmt); else - LOGIN_LOG("- to SAVE only unkown packets sending by a char-server or a remote administration.\n"); + LOGIN_LOG("- to SAVE only unkown packets sending by a char-server or a remote administration.\n"_fmt); if (display_parse_login) - LOGIN_LOG("- to display normal parse packets on console.\n"); + LOGIN_LOG("- to display normal parse packets on console.\n"_fmt); else - LOGIN_LOG("- to NOT display normal parse packets on console.\n"); + LOGIN_LOG("- to NOT display normal parse packets on console.\n"_fmt); if (display_parse_admin) - LOGIN_LOG("- to display administration parse packets on console.\n"); + LOGIN_LOG("- to display administration parse packets on console.\n"_fmt); else - LOGIN_LOG("- to NOT display administration parse packets on console.\n"); + LOGIN_LOG("- to NOT display administration parse packets on console.\n"_fmt); if (display_parse_fromchar) - LOGIN_LOG("- to display char-server parse packets on console.\n"); + LOGIN_LOG("- to display char-server parse packets on console.\n"_fmt); else - LOGIN_LOG("- to NOT display char-server parse packets on console.\n"); + LOGIN_LOG("- to NOT display char-server parse packets on console.\n"_fmt); if (min_level_to_connect == 0) // 0: all players, 1-99 at least gm level x - LOGIN_LOG("- with no minimum level for connection.\n"); + LOGIN_LOG("- with no minimum level for connection.\n"_fmt); else if (min_level_to_connect == 99) - LOGIN_LOG("- to accept only GM with level 99.\n"); + LOGIN_LOG("- to accept only GM with level 99.\n"_fmt); else - LOGIN_LOG("- to accept only GM with level %d or more.\n", + LOGIN_LOG("- to accept only GM with level %d or more.\n"_fmt, min_level_to_connect); if (add_to_unlimited_account) - LOGIN_LOG("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n"); + LOGIN_LOG("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n"_fmt); else - LOGIN_LOG("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n"); + LOGIN_LOG("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n"_fmt); if (start_limited_time < 0) - LOGIN_LOG("- to create new accounts with an unlimited time.\n"); + LOGIN_LOG("- to create new accounts with an unlimited time.\n"_fmt); else if (start_limited_time == 0) - LOGIN_LOG("- to create new accounts with a limited time: time of creation.\n"); + LOGIN_LOG("- to create new accounts with a limited time: time of creation.\n"_fmt); else - LOGIN_LOG("- to create new accounts with a limited time: time of creation + %d second(s).\n", + LOGIN_LOG("- to create new accounts with a limited time: time of creation + %d second(s).\n"_fmt, start_limited_time); if (check_ip_flag) - LOGIN_LOG("- with control of players IP between login-server and char-server.\n"); + LOGIN_LOG("- with control of players IP between login-server and char-server.\n"_fmt); else - LOGIN_LOG("- to not check players IP between login-server and char-server.\n"); + LOGIN_LOG("- to not check players IP between login-server and char-server.\n"_fmt); if (access_order == ACO::DENY_ALLOW) { if (access_deny.empty()) { - LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n"); + LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n"_fmt); } else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n"); + LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n"_fmt); } else { - LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n"); + LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n"_fmt); for (IP4Mask ae : access_deny) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } } else if (access_order == ACO::ALLOW_DENY) { if (access_allow.empty()) { - LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n"); + LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n"_fmt); } else if (access_allow.size() == 1 && access_allow.front().mask() == IP4Address()) { - LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n"); + LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n"_fmt); } else { - LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n"); + LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n"_fmt); for (IP4Mask ae : access_allow) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } } else { // ACO_MUTUAL_FAILTURE - LOGIN_LOG("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n"); + LOGIN_LOG("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n"_fmt); if (access_allow.empty()) { - LOGIN_LOG(" But, NO IP IS AUTHORISED!\n"); + LOGIN_LOG(" But, NO IP IS AUTHORISED!\n"_fmt); } else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address()) { - LOGIN_LOG(" But, you refuse ALL IP!\n"); + LOGIN_LOG(" But, you refuse ALL IP!\n"_fmt); } else { if (access_allow.size() == 1 && access_allow.front().mask() == IP4Address()) { - LOGIN_LOG(" You authorise ALL IP.\n"); + LOGIN_LOG(" You authorise ALL IP.\n"_fmt); } else { - LOGIN_LOG(" Authorised IP are:\n"); + LOGIN_LOG(" Authorised IP are:\n"_fmt); for (IP4Mask ae : access_allow) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } - LOGIN_LOG(" Refused IP are:\n"); + LOGIN_LOG(" Refused IP are:\n"_fmt); for (IP4Mask ae : access_deny) - LOGIN_LOG(" %s\n", ae); + LOGIN_LOG(" %s\n"_fmt, ae); } } } @@ -3835,7 +3827,7 @@ void term_func(void) } delete_session(login_session); - LOGIN_LOG("----End of login-server (normal end with closing of all files).\n"); + LOGIN_LOG("----End of login-server (normal end with closing of all files).\n"_fmt); } static @@ -3861,20 +3853,20 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -3886,7 +3878,7 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-login.conf", login_confs); + runflag &= load_config_file("conf/tmwa-login.conf"_s, login_confs); // not in login_config_read, because we can use 'import' option, and display same message twice or more // (why is that bad?) @@ -3929,10 +3921,10 @@ int do_init(Slice<ZString> argv) check_GM_file, j).detach(); - LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n", + LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n"_fmt, login_port); - PRINTF("The login-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n", + PRINTF("The login-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n"_fmt, login_port); return 0; diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 240df8b..f721aaa 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -121,11 +121,11 @@ void atcommand_config_write(ZString cfgName) if (!out.is_open()) { - FPRINTF(stderr, "Failed to write atcommand config: %s\n", cfgName); + FPRINTF(stderr, "Failed to write atcommand config: %s\n"_fmt, cfgName); return; } - FPRINTF(out, "// Generated by %s\n", CURRENT_VERSION_STRING); + FPRINTF(out, "// Generated by %s\n"_fmt, CURRENT_VERSION_STRING); for (const auto& pair : atcommand_info) { // This XString is really a ZString, but not declared as one @@ -137,7 +137,7 @@ void atcommand_config_write(ZString cfgName) "\n" "// %s\n" "// Usage: @%s %s\n" - "%s: %d\n", + "%s: %d\n"_fmt, info.help, cmd, info.args, cmd, info.level); @@ -198,8 +198,8 @@ void log_atcommand(dumb_ptr<map_session_data> sd, ZString cmd) stamp_time(tmpstr); MapName map = (sd->bl_m ? sd->bl_m->name_ - : stringish<MapName>("undefined.gat")); - FPRINTF(*fp, "[%s] %s(%d,%d) %s(%d) : %s\n", + : stringish<MapName>("undefined.gat"_s)); + FPRINTF(*fp, "[%s] %s(%d,%d) %s(%d) : %s\n"_fmt, tmpstr, map, sd->bl_x, sd->bl_y, sd->status_key.name, sd->status_key.account_id, @@ -225,7 +225,7 @@ io::AppendFile *get_gm_log() return gm_logfile.get(); last_logfile_nr = logfile_nr; - AString fullname = STRPRINTF("%s.%04d-%02d", + AString fullname = STRPRINTF("%s.%04d-%02d"_fmt, gm_log, year, month); if (gm_logfile) @@ -259,14 +259,14 @@ bool is_atcommand(Session *s, dumb_ptr<map_session_data> sd, gmlvl = pc_isGM(sd); if (battle_config.atcommand_gm_only != 0 && !gmlvl) { - AString output = STRPRINTF("GM command is level 0, but this server disables level 0 commands: %s", + AString output = STRPRINTF("GM command is level 0, but this server disables level 0 commands: %s"_fmt, AString(command)); clif_displaymessage(s, output); return true; } if (!info) { - AString output = STRPRINTF("GM command not found: %s", + AString output = STRPRINTF("GM command not found: %s"_fmt, AString(command)); clif_displaymessage(s, output); return true; @@ -274,7 +274,7 @@ bool is_atcommand(Session *s, dumb_ptr<map_session_data> sd, } if (info->level > gmlvl) { - AString output = STRPRINTF("GM command is level %d, but you are level %d: %s", + AString output = STRPRINTF("GM command is level %d, but you are level %d: %s"_fmt, info->level, gmlvl, AString(command)); clif_displaymessage(s, output); @@ -292,17 +292,17 @@ bool is_atcommand(Session *s, dumb_ptr<map_session_data> sd, log_atcommand(sd, message); break; case ATCE::USAGE: - clif_displaymessage(s, "Command failed: usage error"); - clif_displaymessage(s, STRPRINTF("Usage: %s %s", AString(command), info->args)); + clif_displaymessage(s, "Command failed: usage error"_s); + clif_displaymessage(s, STRPRINTF("Usage: %s %s"_fmt, AString(command), info->args)); break; case ATCE::EXIST: - clif_displaymessage(s, "Command failed: something does not exist (or already exists)"); + clif_displaymessage(s, "Command failed: something does not exist (or already exists)"_s); break; case ATCE::RANGE: - clif_displaymessage(s, "Command failed: value out of range"); + clif_displaymessage(s, "Command failed: value out of range"_s); break; case ATCE::PERM: - clif_displaymessage(s, "Command failed: permission denied"); + clif_displaymessage(s, "Command failed: permission denied"_s); break; default: abort(); @@ -347,7 +347,7 @@ bool atcommand_config_read(ZString cfgName) io::ReadFile in(cfgName); if (!in.is_open()) { - PRINTF("At commands configuration file not found: %s\n", cfgName); + PRINTF("At commands configuration file not found: %s\n"_fmt, cfgName); return false; } @@ -361,7 +361,7 @@ bool atcommand_config_read(ZString cfgName) ZString w2; if (!config_split(line, &w1, &w2)) { - PRINTF("Bad config line: %s\n", line); + PRINTF("Bad config line: %s\n"_fmt, line); rv = false; continue; } @@ -374,11 +374,11 @@ bool atcommand_config_read(ZString cfgName) else if (p->level < 0) p->level = 0; } - else if (w1 == "import") + else if (w1 == "import"_s) rv &= atcommand_config_read(w2); else { - PRINTF("%s: bad line: %s\n", cfgName, line); + PRINTF("%s: bad line: %s\n"_fmt, cfgName, line); rv = false; } } @@ -391,7 +391,7 @@ bool atcommand_config_read(ZString cfgName) static void atc_do_help(Session *s, const char *cmd, const AtCommandInfo& info) { - auto msg = STRPRINTF("\u2007\u2007%d: @%s %s", info.level, cmd, info.args); + auto msg = STRPRINTF("\u2007\u2007%d: @%s %s"_fmt, info.level, cmd, info.args); // manually padding because *space* size_t ll = 1; if (info.level >= 10) @@ -407,9 +407,9 @@ ATCE atcommand_help(Session *s, dumb_ptr<map_session_data>, { if (!message) { - clif_displaymessage(s, "There is too much help to display it all at once"); - clif_displaymessage(s, "Try @help <@command> or @help <category> or @help <level[-level]>"); - clif_displaymessage(s, "Right now the only category is 'all'"); + clif_displaymessage(s, "There is too much help to display it all at once"_s); + clif_displaymessage(s, "Try @help <@command> or @help <category> or @help <level[-level]>"_s); + clif_displaymessage(s, "Right now the only category is 'all'"_s); return ATCE::OKAY; } @@ -419,14 +419,14 @@ ATCE atcommand_help(Session *s, dumb_ptr<map_session_data>, const AtCommandInfo *info = atcommand_info.search(cmd); if (!info) return ATCE::EXIST; - clif_displaymessage(s, STRPRINTF("Usage: @%s %s", cmd, info->args)); + clif_displaymessage(s, STRPRINTF("Usage: @%s %s"_fmt, cmd, info->args)); clif_displaymessage(s, info->help); return ATCE::OKAY; } - if (message == "all") + if (message == "all"_s) { - clif_displaymessage(s, "Synopses of GM commands in category 'all':"); + clif_displaymessage(s, "Synopses of GM commands in category 'all':"_s); for (const auto& pair : atcommand_info) { const char *cmd = &*pair.first.begin(); @@ -444,7 +444,7 @@ ATCE atcommand_help(Session *s, dumb_ptr<map_session_data>, if (low < 0 || high > 100 || low >= high) return ATCE::RANGE; - clif_displaymessage(s, STRPRINTF("Synopses of GM commands in level [%d, %d):", low, high)); + clif_displaymessage(s, STRPRINTF("Synopses of GM commands in level [%d, %d):"_fmt, low, high)); for (const auto& pair : atcommand_info) { const char *cmd = &*pair.first.begin(); @@ -467,25 +467,25 @@ ATCE atcommand_setup(Session *s, dumb_ptr<map_session_data> sd, level--; AString buf; - buf = STRPRINTF("-255 %s", character); + buf = STRPRINTF("-255 %s"_fmt, character); atcommand_character_baselevel(s, sd, buf); - buf = STRPRINTF("%d %s", level, character); + buf = STRPRINTF("%d %s"_fmt, level, character); atcommand_character_baselevel(s, sd, buf); // Emote skill - buf = STRPRINTF("1 1 %s", character); + buf = STRPRINTF("1 1 %s"_fmt, character); atcommand_skill_learn(s, sd, buf); // Trade skill - buf = STRPRINTF("2 1 %s", character); + buf = STRPRINTF("2 1 %s"_fmt, character); atcommand_skill_learn(s, sd, buf); // Party skill - STRPRINTF("2 2 %s", character); + STRPRINTF("2 2 %s"_fmt, character); atcommand_skill_learn(s, sd, buf); - STRPRINTF("018-1.gat 24 98 %s", character); + STRPRINTF("018-1.gat 24 98 %s"_fmt, character); atcommand_charwarp(s, sd, buf); return ATCE::OKAY; @@ -520,42 +520,42 @@ ATCE atcommand_charwarp(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp someone to this map."); + "You are not authorised to warp someone to this map."_s); return ATCE::PERM; } if (pl_sd->bl_m && pl_sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp this player from its actual map."); + "You are not authorised to warp this player from its actual map."_s); return ATCE::PERM; } if (pc_setpos(pl_sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) { - clif_displaymessage(pl_sd->sess, "Warped."); - clif_displaymessage(s, "Player warped (message sends to player too)."); + clif_displaymessage(pl_sd->sess, "Warped."_s); + clif_displaymessage(s, "Player warped (message sends to player too)."_s); } else { - clif_displaymessage(s, "Map not found."); + clif_displaymessage(s, "Map not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -573,7 +573,7 @@ ATCE atcommand_warp(Session *s, dumb_ptr<map_session_data> sd, || !extract(message, record<' ', 1>(&map_name, &x, &y))) { clif_displaymessage(s, - "Please, enter a map (usage: @warp <mapname> <x> <y>)."); + "Please, enter a map (usage: @warp <mapname> <x> <y>)."_s); return ATCE::USAGE; } @@ -589,27 +589,27 @@ ATCE atcommand_warp(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to this map."); + "You are not authorised to warp you to this map."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } if (pc_setpos(sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) - clif_displaymessage(s, "Warped."); + clif_displaymessage(s, "Warped."_s); else { - clif_displaymessage(s, "Map not found."); + clif_displaymessage(s, "Map not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."_s); return ATCE::RANGE; } @@ -630,14 +630,14 @@ ATCE atcommand_where(Session *s, dumb_ptr<map_session_data> sd, && (pc_isGM(pl_sd) > pc_isGM(sd)))) { // you can look only lower or same level - AString output = STRPRINTF("%s: %s (%d,%d)", + AString output = STRPRINTF("%s: %s (%d,%d)"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -653,7 +653,7 @@ ATCE atcommand_goto(Session *s, dumb_ptr<map_session_data> sd, if (!asplit(message, &character)) { clif_displaymessage(s, - "Please, enter a player name (usage: @jumpto/@warpto/@goto <char name>)."); + "Please, enter a player name (usage: @jumpto/@warpto/@goto <char name>)."_s); return ATCE::USAGE; } @@ -664,23 +664,23 @@ ATCE atcommand_goto(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to the map of this player."); + "You are not authorised to warp you to the map of this player."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } pc_setpos(sd, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); - AString output = STRPRINTF("Jump to %s", character); + AString output = STRPRINTF("Jump to %s"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -705,23 +705,23 @@ ATCE atcommand_jump(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to your actual map."); + "You are not authorised to warp you to your actual map."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } pc_setpos(sd, sd->mapname_, x, y, BeingRemoveWhy::WARPED); - AString output = STRPRINTF("Jump to %d %d", x, y); + AString output = STRPRINTF("Jump to %d %d"_fmt, x, y); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."_s); return ATCE::RANGE; } @@ -761,12 +761,12 @@ ATCE atcommand_who(Session *s, dumb_ptr<map_session_data> sd, AString output; if (pl_GM_level > 0) output = STRPRINTF( - "Name: %s (GM:%d) | Location: %s %d %d", + "Name: %s (GM:%d) | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_GM_level, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); else output = STRPRINTF( - "Name: %s | Location: %s %d %d", + "Name: %s | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); @@ -777,12 +777,12 @@ ATCE atcommand_who(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) - clif_displaymessage(s, "No player found."); + clif_displaymessage(s, "No player found."_s); else if (count == 1) - clif_displaymessage(s, "1 player found."); + clif_displaymessage(s, "1 player found."_s); else { - AString output = STRPRINTF("%d players found.", count); + AString output = STRPRINTF("%d players found."_fmt, count); clif_displaymessage(s, output); } @@ -822,11 +822,11 @@ ATCE atcommand_whogroup(Session *s, dumb_ptr<map_session_data> sd, { // search with no case sensitive p = party_search(pl_sd->status.party_id); - PartyName temp0 = p ? p->name : stringish<PartyName>("None"); + PartyName temp0 = p ? p->name : stringish<PartyName>("None"_s); AString output; if (pl_GM_level > 0) output = STRPRINTF( - "Name: %s (GM:%d) | Party: '%s'", + "Name: %s (GM:%d) | Party: '%s'"_fmt, pl_sd->status_key.name, pl_GM_level, temp0); clif_displaymessage(s, output); count++; @@ -836,12 +836,12 @@ ATCE atcommand_whogroup(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) - clif_displaymessage(s, "No player found."); + clif_displaymessage(s, "No player found."_s); else if (count == 1) - clif_displaymessage(s, "1 player found."); + clif_displaymessage(s, "1 player found."_s); else { - AString output = STRPRINTF("%d players found.", count); + AString output = STRPRINTF("%d players found."_fmt, count); clif_displaymessage(s, output); } @@ -886,12 +886,12 @@ ATCE atcommand_whomap(Session *s, dumb_ptr<map_session_data> sd, AString output; if (pl_GM_level > 0) output = STRPRINTF( - "Name: %s (GM:%d) | Location: %s %d %d", + "Name: %s (GM:%d) | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_GM_level, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); else output = STRPRINTF( - "Name: %s | Location: %s %d %d", + "Name: %s | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); @@ -901,7 +901,7 @@ ATCE atcommand_whomap(Session *s, dumb_ptr<map_session_data> sd, } } - AString output = STRPRINTF("%d players found in map '%s'.", + AString output = STRPRINTF("%d players found in map '%s'."_fmt, count, map_id->name_); clif_displaymessage(s, output); @@ -945,13 +945,13 @@ ATCE atcommand_whomapgroup(Session *s, dumb_ptr<map_session_data> sd, if (pl_sd->bl_m == map_id) { p = party_search(pl_sd->status.party_id); - PartyName temp0 = p ? p->name : stringish<PartyName>("None"); + PartyName temp0 = p ? p->name : stringish<PartyName>("None"_s); AString output; if (pl_GM_level > 0) - output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'", + output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'"_fmt, pl_sd->status_key.name, pl_GM_level, temp0); else - output = STRPRINTF("Name: %s | Party: '%s'", + output = STRPRINTF("Name: %s | Party: '%s'"_fmt, pl_sd->status_key.name, temp0); clif_displaymessage(s, output); count++; @@ -962,12 +962,12 @@ ATCE atcommand_whomapgroup(Session *s, dumb_ptr<map_session_data> sd, AString output; if (count == 0) - output = STRPRINTF("No player found in map '%s'.", map_id->name_); + output = STRPRINTF("No player found in map '%s'."_fmt, map_id->name_); else if (count == 1) - output = STRPRINTF("1 player found in map '%s'.", map_id->name_); + output = STRPRINTF("1 player found in map '%s'."_fmt, map_id->name_); else { - output = STRPRINTF("%d players found in map '%s'.", count, map_id->name_); + output = STRPRINTF("%d players found in map '%s'."_fmt, count, map_id->name_); } clif_displaymessage(s, output); @@ -1010,20 +1010,20 @@ ATCE atcommand_whogm(Session *s, dumb_ptr<map_session_data> sd, // search with no case sensitive AString output; output = STRPRINTF( - "Name: %s (GM:%d) | Location: %s %d %d", + "Name: %s (GM:%d) | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_GM_level, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); output = STRPRINTF( - " BLvl: %d | Job: %s (Lvl: %d)", + " BLvl: %d | Job: %s (Lvl: %d)"_fmt, pl_sd->status.base_level, - "Novice/Human", + "Novice/Human"_s, pl_sd->status.job_level); clif_displaymessage(s, output); p = party_search(pl_sd->status.party_id); - PartyName temp0 = p ? p->name : stringish<PartyName>("None"); + PartyName temp0 = p ? p->name : stringish<PartyName>("None"_s); output = STRPRINTF( - " Party: '%s'", + " Party: '%s'"_fmt, temp0); clif_displaymessage(s, output); count++; @@ -1034,12 +1034,12 @@ ATCE atcommand_whogm(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) - clif_displaymessage(s, "No GM found."); + clif_displaymessage(s, "No GM found."_s); else if (count == 1) - clif_displaymessage(s, "1 GM found."); + clif_displaymessage(s, "1 GM found."_s); else { - AString output = STRPRINTF("%d GMs found.", count); + AString output = STRPRINTF("%d GMs found."_fmt, count); clif_displaymessage(s, output); } @@ -1053,7 +1053,7 @@ ATCE atcommand_save(Session *s, dumb_ptr<map_session_data> sd, pc_setsavepoint(sd, sd->mapname_, sd->bl_x, sd->bl_y); pc_makesavestatus(sd); chrif_save(sd); - clif_displaymessage(s, "Character data respawn point saved."); + clif_displaymessage(s, "Character data respawn point saved."_s); return ATCE::OKAY; } @@ -1067,14 +1067,14 @@ ATCE atcommand_load(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to your save map."); + "You are not authorised to warp you to your save map."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } @@ -1089,7 +1089,7 @@ ATCE atcommand_load(Session *s, dumb_ptr<map_session_data> sd, pc_setpos(sd, sd->status.save_point.map_, sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::GONE); } - clif_displaymessage(s, "Warping to respawn point."); + clif_displaymessage(s, "Warping to respawn point."_s); return ATCE::OKAY; } @@ -1101,7 +1101,7 @@ ATCE atcommand_speed(Session *s, dumb_ptr<map_session_data> sd, if (!message) { AString output = STRPRINTF( - "Please, enter a speed value (usage: @speed <%d-%d>).", + "Please, enter a speed value (usage: @speed <%d-%d>)."_fmt, static_cast<uint32_t>(MIN_WALK_SPEED.count()), static_cast<uint32_t>(MAX_WALK_SPEED.count())); clif_displaymessage(s, output); @@ -1115,12 +1115,12 @@ ATCE atcommand_speed(Session *s, dumb_ptr<map_session_data> sd, //sd->walktimer = x; //この文を追加 by れ clif_updatestatus(sd, SP::SPEED); - clif_displaymessage(s, "Speed changed."); + clif_displaymessage(s, "Speed changed."_s); } else { AString output = STRPRINTF( - "Please, enter a valid speed value (usage: @speed <%d-%d>).", + "Please, enter a valid speed value (usage: @speed <%d-%d>)."_fmt, static_cast<uint32_t>(MIN_WALK_SPEED.count()), static_cast<uint32_t>(MAX_WALK_SPEED.count())); clif_displaymessage(s, output); @@ -1138,14 +1138,14 @@ ATCE atcommand_storage(Session *s, dumb_ptr<map_session_data> sd, if (sd->state.storage_open) { - clif_displaymessage(s, "msg_table[250]"); + clif_displaymessage(s, "msg_table[250]"_s); return ATCE::EXIST; } if ((stor = account2storage2(sd->status_key.account_id)) != NULL && stor->storage_status == 1) { - clif_displaymessage(s, "msg_table[250]"); + clif_displaymessage(s, "msg_table[250]"_s); return ATCE::EXIST; } @@ -1171,7 +1171,7 @@ ATCE atcommand_option(Session *s, dumb_ptr<map_session_data> sd, clif_changeoption(sd); pc_calcstatus(sd, 0); - clif_displaymessage(s, "Options changed."); + clif_displaymessage(s, "Options changed."_s); return ATCE::OKAY; } @@ -1183,12 +1183,12 @@ ATCE atcommand_hide(Session *s, dumb_ptr<map_session_data> sd, if (bool(sd->status.option & Option::HIDE)) { sd->status.option &= ~Option::HIDE; - clif_displaymessage(s, "Invisible: Off."); + clif_displaymessage(s, "Invisible: Off."_s); } else { sd->status.option |= Option::HIDE; - clif_displaymessage(s, "Invisible: On."); + clif_displaymessage(s, "Invisible: On."_s); } clif_changeoption(sd); @@ -1200,7 +1200,7 @@ ATCE atcommand_die(Session *s, dumb_ptr<map_session_data> sd, ZString) { pc_damage(NULL, sd, sd->status.hp + 1); - clif_displaymessage(s, "A pity! You've died."); + clif_displaymessage(s, "A pity! You've died."_s); return ATCE::OKAY; } @@ -1221,17 +1221,17 @@ ATCE atcommand_kill(Session *s, dumb_ptr<map_session_data> sd, { // you can kill only lower or same level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(s, "Character killed."); + clif_displaymessage(s, "Character killed."_s); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -1250,7 +1250,7 @@ ATCE atcommand_alive(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, SP::HP); clif_updatestatus(sd, SP::SP); clif_resurrection(sd, 1); - clif_displaymessage(s, "You've been revived! It's a miracle!"); + clif_displaymessage(s, "You've been revived! It's a miracle!"_s); return ATCE::OKAY; } @@ -1304,13 +1304,13 @@ ATCE atcommand_heal(Session *s, dumb_ptr<map_session_data> sd, { pc_heal(sd, hp, sp); if (hp >= 0 && sp >= 0) - clif_displaymessage(s, "HP, SP recovered."); + clif_displaymessage(s, "HP, SP recovered."_s); else - clif_displaymessage(s, "HP or/and SP modified."); + clif_displaymessage(s, "HP or/and SP modified."_s); } else { - clif_displaymessage(s, "HP and SP are already with the good value."); + clif_displaymessage(s, "HP and SP are already with the good value."_s); return ATCE::RANGE; } @@ -1329,7 +1329,7 @@ ATCE atcommand_item(Session *s, dumb_ptr<map_session_data> sd, if (!extract(message, record<' ', 1>(&item_name, &number))) { clif_displaymessage(s, - "Please, enter an item name/id (usage: @item <item name or ID> [quantity])."); + "Please, enter an item name/id (usage: @item <item name or ID> [quantity])."_s); return ATCE::USAGE; } @@ -1363,11 +1363,11 @@ ATCE atcommand_item(Session *s, dumb_ptr<map_session_data> sd, != PickupFail::OKAY) clif_additem(sd, 0, 0, flag); } - clif_displaymessage(s, "Item created."); + clif_displaymessage(s, "Item created."_s); } else { - clif_displaymessage(s, "Invalid item ID or name."); + clif_displaymessage(s, "Invalid item ID or name."_s); return ATCE::EXIST; } @@ -1386,7 +1386,7 @@ ATCE atcommand_itemreset(Session *s, dumb_ptr<map_session_data> sd, && sd->status.inventory[i].equip == EPOS::ZERO) pc_delitem(sd, i, sd->status.inventory[i].amount, 0); } - clif_displaymessage(s, "All of your items have been removed."); + clif_displaymessage(s, "All of your items have been removed."_s); return ATCE::OKAY; } @@ -1409,7 +1409,7 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, if (!extract(message, &level) || !level) { clif_displaymessage(s, - "Please, enter a level adjustement (usage: @blvl <number of levels>)."); + "Please, enter a level adjustement (usage: @blvl <number of levels>)."_s); return ATCE::USAGE; } @@ -1417,7 +1417,7 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, { if (sd->status.base_level == battle_config.maximum_level) { - clif_displaymessage(s, "Base level can't go any higher."); + clif_displaymessage(s, "Base level can't go any higher."_s); return ATCE::RANGE; } if (level > battle_config.maximum_level || level > (battle_config.maximum_level - sd->status.base_level)) @@ -1432,13 +1432,13 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, pc_calcstatus(sd, 0); pc_heal(sd, sd->status.max_hp, sd->status.max_sp); clif_misceffect(sd, 0); - clif_displaymessage(s, "Base level raised."); + clif_displaymessage(s, "Base level raised."_s); } else { if (sd->status.base_level == 1) { - clif_displaymessage(s, "Base level can't go any lower."); + clif_displaymessage(s, "Base level can't go any lower."_s); return ATCE::USAGE; } if (level < -battle_config.maximum_level || level < (1 - sd->status.base_level)) @@ -1458,7 +1458,7 @@ ATCE atcommand_baselevelup(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, SP::BASELEVEL); clif_updatestatus(sd, SP::NEXTBASEEXP); pc_calcstatus(sd, 0); - clif_displaymessage(s, "Base level lowered."); + clif_displaymessage(s, "Base level lowered."_s); } return ATCE::OKAY; @@ -1481,7 +1481,7 @@ ATCE atcommand_joblevelup(Session *s, dumb_ptr<map_session_data> sd, { if (sd->status.job_level == up_level) { - clif_displaymessage(s, "Job level can't go any higher."); + clif_displaymessage(s, "Job level can't go any higher."_s); return ATCE::RANGE; } if (level > up_level || level > (up_level - sd->status.job_level)) @@ -1494,13 +1494,13 @@ ATCE atcommand_joblevelup(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); clif_misceffect(sd, 1); - clif_displaymessage(s, "Job level raised."); + clif_displaymessage(s, "Job level raised."_s); } else { if (sd->status.job_level == 1) { - clif_displaymessage(s, "Job level can't go any lower."); + clif_displaymessage(s, "Job level can't go any lower."_s); return ATCE::RANGE; } if (level < -up_level || level < (1 - sd->status.job_level)) @@ -1518,7 +1518,7 @@ ATCE atcommand_joblevelup(Session *s, dumb_ptr<map_session_data> sd, } // to add: remove status points from skills pc_calcstatus(sd, 0); - clif_displaymessage(s, "Job level lowered."); + clif_displaymessage(s, "Job level lowered."_s); } return ATCE::OKAY; @@ -1534,7 +1534,7 @@ ATCE atcommand_gm(Session *s, dumb_ptr<map_session_data> sd, if (pc_isGM(sd)) { // a GM can not use this function. only a normal player (become gm is not for gm!) - clif_displaymessage(s, "You already have some GM powers."); + clif_displaymessage(s, "You already have some GM powers."_s); return ATCE::PERM; } else @@ -1550,7 +1550,7 @@ ATCE atcommand_pvpoff(Session *s, dumb_ptr<map_session_data> sd, if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] - clif_displaymessage(s, "This option cannot be used in PK Mode."); + clif_displaymessage(s, "This option cannot be used in PK Mode."_s); return ATCE::EXIST; } @@ -1571,11 +1571,11 @@ ATCE atcommand_pvpoff(Session *s, dumb_ptr<map_session_data> sd, } } } - clif_displaymessage(s, "PvP: Off."); + clif_displaymessage(s, "PvP: Off."_s); } else { - clif_displaymessage(s, "PvP is already Off."); + clif_displaymessage(s, "PvP is already Off."_s); return ATCE::EXIST; } @@ -1589,7 +1589,7 @@ ATCE atcommand_pvpon(Session *s, dumb_ptr<map_session_data> sd, if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] - clif_displaymessage(s, "This option cannot be used in PK Mode."); + clif_displaymessage(s, "This option cannot be used in PK Mode."_s); return ATCE::EXIST; } @@ -1614,11 +1614,11 @@ ATCE atcommand_pvpon(Session *s, dumb_ptr<map_session_data> sd, } } } - clif_displaymessage(s, "PvP: On."); + clif_displaymessage(s, "PvP: On."_s); } else { - clif_displaymessage(s, "PvP is already On."); + clif_displaymessage(s, "PvP is already On."_s); return ATCE::EXIST; } @@ -1642,7 +1642,7 @@ ATCE atcommand_model(Session *s, dumb_ptr<map_session_data> sd, pc_changelook(sd, LOOK::HAIR, hair_style); pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1664,7 +1664,7 @@ ATCE atcommand_dye(Session *s, dumb_ptr<map_session_data> sd, { { pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1686,7 +1686,7 @@ ATCE atcommand_hair_style(Session *s, dumb_ptr<map_session_data> sd, { { pc_changelook(sd, LOOK::HAIR, hair_style); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1708,7 +1708,7 @@ ATCE atcommand_hair_color(Session *s, dumb_ptr<map_session_data> sd, { { pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -1749,7 +1749,7 @@ ATCE atcommand_spawn(Session *s, dumb_ptr<map_session_data> sd, number = battle_config.atcommand_spawn_quantity_limit; if (battle_config.etc_log) - PRINTF("@spawn monster='%s' id=%d count=%d (%d,%d)\n", + PRINTF("@spawn monster='%s' id=%d count=%d (%d,%d)\n"_fmt, monster, mob_id, number, x, y); count = 0; @@ -1778,16 +1778,16 @@ ATCE atcommand_spawn(Session *s, dumb_ptr<map_session_data> sd, if (count != 0) if (number == count) - clif_displaymessage(s, "All monster summoned!"); + clif_displaymessage(s, "All monster summoned!"_s); else { - AString output = STRPRINTF("%d monster(s) summoned!", + AString output = STRPRINTF("%d monster(s) summoned!"_fmt, count); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Invalid monster ID or name."); + clif_displaymessage(s, "Invalid monster ID or name."_s); return ATCE::EXIST; } @@ -1813,7 +1813,7 @@ void atcommand_killmonster_sub(Session *s, dumb_ptr<map_session_data> sd, map_id->xs, map_id->ys, BL::MOB); - clif_displaymessage(s, "All monsters killed!"); + clif_displaymessage(s, "All monsters killed!"_s); } static @@ -1830,7 +1830,7 @@ void atlist_nearby_sub(dumb_ptr<block_list> bl, Session *s) { nullpo_retv(bl); - AString buf = STRPRINTF(" - \"%s\"", + AString buf = STRPRINTF(" - \"%s\""_fmt, bl->is_player()->status_key.name); clif_displaymessage(s, buf); } @@ -1839,7 +1839,7 @@ static ATCE atcommand_list_nearby(Session *s, dumb_ptr<map_session_data> sd, ZString) { - clif_displaymessage(s, "Nearby players:"); + clif_displaymessage(s, "Nearby players:"_s); map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, s), sd->bl_m, sd->bl_x - 1, sd->bl_y - 1, @@ -1867,7 +1867,7 @@ ATCE atcommand_gat(Session *s, dumb_ptr<map_session_data> sd, for (y = 2; y >= -2; y--) { AString output = STRPRINTF( - "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", + "%s (x= %d, y= %d) %02X %02X %02X %02X %02X"_fmt, sd->bl_m->name_, sd->bl_x - 2, sd->bl_y + y, map_getcell(sd->bl_m, sd->bl_x - 2, sd->bl_y + y), map_getcell(sd->bl_m, sd->bl_x - 1, sd->bl_y + y), @@ -1916,7 +1916,7 @@ ATCE atcommand_statuspoint(Session *s, dumb_ptr<map_session_data> sd, { sd->status.status_point = new_status_point; clif_updatestatus(sd, SP::STATUSPOINT); - clif_displaymessage(s, "Number of status points changed!"); + clif_displaymessage(s, "Number of status points changed!"_s); } else return ATCE::RANGE; @@ -1945,7 +1945,7 @@ ATCE atcommand_skillpoint(Session *s, dumb_ptr<map_session_data> sd, { sd->status.skill_point = new_skill_point; clif_updatestatus(sd, SP::SKILLPOINT); - clif_displaymessage(s, "Number of skill points changed!"); + clif_displaymessage(s, "Number of skill points changed!"_s); } else return ATCE::RANGE; @@ -1974,7 +1974,7 @@ ATCE atcommand_zeny(Session *s, dumb_ptr<map_session_data> sd, { sd->status.zeny = new_zeny; clif_updatestatus(sd, SP::ZENY); - clif_displaymessage(s, "Number of zenys changed!"); + clif_displaymessage(s, "Number of zenys changed!"_s); } else return ATCE::RANGE; @@ -2006,7 +2006,7 @@ ATCE atcommand_param(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(sd, attr_to_sp(attr)); clif_updatestatus(sd, attr_to_usp(attr)); pc_calcstatus(sd, 0); - clif_displaymessage(s, "Stat changed."); + clif_displaymessage(s, "Stat changed."_s); } else return ATCE::RANGE; @@ -2047,7 +2047,7 @@ ATCE atcommand_all_stats(Session *s, dumb_ptr<map_session_data> sd, if (count > 0) // if at least 1 stat modified - clif_displaymessage(s, "All stats changed!"); + clif_displaymessage(s, "All stats changed!"_s); else return ATCE::RANGE; @@ -2073,29 +2073,29 @@ ATCE atcommand_recall(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp somenone to your actual map."); + "You are not authorised to warp somenone to your actual map."_s); return ATCE::PERM; } if (pl_sd->bl_m && pl_sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp this player from its actual map."); + "You are not authorised to warp this player from its actual map."_s); return ATCE::PERM; } pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT); - AString output = STRPRINTF("%s recalled!", character); + AString output = STRPRINTF("%s recalled!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2121,11 +2121,11 @@ ATCE atcommand_revive(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(pl_sd, SP::HP); clif_updatestatus(pl_sd, SP::SP); clif_resurrection(pl_sd, 1); - clif_displaymessage(s, "Character revived."); + clif_displaymessage(s, "Character revived."_s); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2145,38 +2145,38 @@ ATCE atcommand_character_stats(Session *s, dumb_ptr<map_session_data>, if (pl_sd != NULL) { AString output; - output = STRPRINTF("'%s' stats:", pl_sd->status_key.name); + output = STRPRINTF("'%s' stats:"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); - output = STRPRINTF("Base Level - %d", pl_sd->status.base_level), + output = STRPRINTF("Base Level - %d"_fmt, pl_sd->status.base_level), clif_displaymessage(s, output); - output = STRPRINTF("Job - Novice/Human (level %d)", pl_sd->status.job_level); + output = STRPRINTF("Job - Novice/Human (level %d)"_fmt, pl_sd->status.job_level); clif_displaymessage(s, output); - output = STRPRINTF("Hp - %d", pl_sd->status.hp); + output = STRPRINTF("Hp - %d"_fmt, pl_sd->status.hp); clif_displaymessage(s, output); - output = STRPRINTF("MaxHp - %d", pl_sd->status.max_hp); + output = STRPRINTF("MaxHp - %d"_fmt, pl_sd->status.max_hp); clif_displaymessage(s, output); - output = STRPRINTF("Sp - %d", pl_sd->status.sp); + output = STRPRINTF("Sp - %d"_fmt, pl_sd->status.sp); clif_displaymessage(s, output); - output = STRPRINTF("MaxSp - %d", pl_sd->status.max_sp); + output = STRPRINTF("MaxSp - %d"_fmt, pl_sd->status.max_sp); clif_displaymessage(s, output); - output = STRPRINTF("Str - %3d", pl_sd->status.attrs[ATTR::STR]); + output = STRPRINTF("Str - %3d"_fmt, pl_sd->status.attrs[ATTR::STR]); clif_displaymessage(s, output); - output = STRPRINTF("Agi - %3d", pl_sd->status.attrs[ATTR::AGI]); + output = STRPRINTF("Agi - %3d"_fmt, pl_sd->status.attrs[ATTR::AGI]); clif_displaymessage(s, output); - output = STRPRINTF("Vit - %3d", pl_sd->status.attrs[ATTR::VIT]); + output = STRPRINTF("Vit - %3d"_fmt, pl_sd->status.attrs[ATTR::VIT]); clif_displaymessage(s, output); - output = STRPRINTF("Int - %3d", pl_sd->status.attrs[ATTR::INT]); + output = STRPRINTF("Int - %3d"_fmt, pl_sd->status.attrs[ATTR::INT]); clif_displaymessage(s, output); - output = STRPRINTF("Dex - %3d", pl_sd->status.attrs[ATTR::DEX]); + output = STRPRINTF("Dex - %3d"_fmt, pl_sd->status.attrs[ATTR::DEX]); clif_displaymessage(s, output); - output = STRPRINTF("Luk - %3d", pl_sd->status.attrs[ATTR::LUK]); + output = STRPRINTF("Luk - %3d"_fmt, pl_sd->status.attrs[ATTR::LUK]); clif_displaymessage(s, output); - output = STRPRINTF("Zeny - %d", pl_sd->status.zeny); + output = STRPRINTF("Zeny - %d"_fmt, pl_sd->status.zeny); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2200,19 +2200,19 @@ ATCE atcommand_character_stats_all(Session *s, dumb_ptr<map_session_data>, { AString gmlevel; if (pc_isGM(pl_sd) > 0) - gmlevel = STRPRINTF("| GM Lvl: %d", pc_isGM(pl_sd)); + gmlevel = STRPRINTF("| GM Lvl: %d"_fmt, pc_isGM(pl_sd)); else - gmlevel = " "; + gmlevel = " "_s; AString output; output = STRPRINTF( - "Name: %s | BLvl: %d | Job: Novice/Human (Lvl: %d) | HP: %d/%d | SP: %d/%d", + "Name: %s | BLvl: %d | Job: Novice/Human (Lvl: %d) | HP: %d/%d | SP: %d/%d"_fmt, pl_sd->status_key.name, pl_sd->status.base_level, pl_sd->status.job_level, pl_sd->status.hp, pl_sd->status.max_hp, pl_sd->status.sp, pl_sd->status.max_sp); clif_displaymessage(s, output); - output = STRPRINTF("STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s", + output = STRPRINTF("STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s"_fmt, pl_sd->status.attrs[ATTR::STR], pl_sd->status.attrs[ATTR::AGI], pl_sd->status.attrs[ATTR::VIT], @@ -2222,18 +2222,18 @@ ATCE atcommand_character_stats_all(Session *s, dumb_ptr<map_session_data>, pl_sd->status.zeny, gmlevel); clif_displaymessage(s, output); - clif_displaymessage(s, "--------"); + clif_displaymessage(s, "--------"_s); count++; } } if (count == 0) - clif_displaymessage(s, "No player found."); + clif_displaymessage(s, "No player found."_s); else if (count == 1) - clif_displaymessage(s, "1 player found."); + clif_displaymessage(s, "1 player found."_s); else { - AString output = STRPRINTF("%d players found.", count); + AString output = STRPRINTF("%d players found."_fmt, count); clif_displaymessage(s, output); } @@ -2263,17 +2263,17 @@ ATCE atcommand_character_option(Session *s, dumb_ptr<map_session_data> sd, clif_changeoption(pl_sd); pc_calcstatus(pl_sd, 0); - clif_displaymessage(s, "Character's options changed."); + clif_displaymessage(s, "Character's options changed."_s); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2292,7 +2292,7 @@ ATCE atcommand_char_change_sex(Session *s, dumb_ptr<map_session_data> sd, { chrif_char_ask_name(sd->status_key.account_id, character, 5, HumanTimeDiff()); // type: 5 - changesex - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2310,7 +2310,7 @@ ATCE atcommand_char_block(Session *s, dumb_ptr<map_session_data> sd, { chrif_char_ask_name(sd->status_key.account_id, character, 1, HumanTimeDiff()); // type: 1 - block - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2330,7 +2330,7 @@ ATCE atcommand_char_ban(Session *s, dumb_ptr<map_session_data> sd, { chrif_char_ask_name(sd->status_key.account_id, character, 2, modif); // type: 2 - ban - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2349,7 +2349,7 @@ ATCE atcommand_char_unblock(Session *s, dumb_ptr<map_session_data> sd, // send answer to login server via char-server chrif_char_ask_name(sd->status_key.account_id, character, 3, HumanTimeDiff()); // type: 3 - unblock - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2368,7 +2368,7 @@ ATCE atcommand_char_unban(Session *s, dumb_ptr<map_session_data> sd, // send answer to login server via char-server chrif_char_ask_name(sd->status_key.account_id, character, 4, HumanTimeDiff()); // type: 4 - unban - clif_displaymessage(s, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."_s); } return ATCE::OKAY; @@ -2395,7 +2395,7 @@ ATCE atcommand_character_save(Session *s, dumb_ptr<map_session_data> sd, map_local *m = map_mapname2mapid(map_name); if (m == nullptr) { - clif_displaymessage(s, "Map not found."); + clif_displaymessage(s, "Map not found."_s); return ATCE::EXIST; } else @@ -2404,22 +2404,22 @@ ATCE atcommand_character_save(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to set this map as a save map."); + "You are not authorised to set this map as a save map."_s); return ATCE::PERM; } pc_setsavepoint(pl_sd, map_name, x, y); - clif_displaymessage(s, "Character's respawn point changed."); + clif_displaymessage(s, "Character's respawn point changed."_s); } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2442,10 +2442,10 @@ ATCE atcommand_doom(Session *s, dumb_ptr<map_session_data> sd, { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."_s); } } - clif_displaymessage(s, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."_s); return ATCE::OKAY; } @@ -2466,10 +2466,10 @@ ATCE atcommand_doommap(Session *s, dumb_ptr<map_session_data> sd, { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."_s); } } - clif_displaymessage(s, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."_s); return ATCE::OKAY; } @@ -2485,7 +2485,7 @@ void atcommand_raise_sub(dumb_ptr<map_session_data> sd) clif_updatestatus(sd, SP::HP); clif_updatestatus(sd, SP::SP); clif_resurrection(sd, 1); - clif_displaymessage(sd->sess, "Mercy has been shown."); + clif_displaymessage(sd->sess, "Mercy has been shown."_s); } } @@ -2501,7 +2501,7 @@ ATCE atcommand_raise(Session *s, dumb_ptr<map_session_data>, dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(s2->session_data.get())); atcommand_raise_sub(pl_sd); } - clif_displaymessage(s, "Mercy has been granted."); + clif_displaymessage(s, "Mercy has been granted."_s); return ATCE::OKAY; } @@ -2520,7 +2520,7 @@ ATCE atcommand_raisemap(Session *s, dumb_ptr<map_session_data> sd, && pl_sd->state.auth && sd->bl_m == pl_sd->bl_m) atcommand_raise_sub(pl_sd); } - clif_displaymessage(s, "Mercy has been granted."); + clif_displaymessage(s, "Mercy has been granted."_s); return ATCE::OKAY; } @@ -2546,7 +2546,7 @@ ATCE atcommand_character_baselevel(Session *s, dumb_ptr<map_session_data> sd, { if (pl_sd->status.base_level == battle_config.maximum_level) { - clif_displaymessage(s, "Character's base level can't go any higher."); + clif_displaymessage(s, "Character's base level can't go any higher."_s); return ATCE::RANGE; } if (level > battle_config.maximum_level || level > (battle_config.maximum_level - pl_sd->status.base_level)) @@ -2564,13 +2564,13 @@ ATCE atcommand_character_baselevel(Session *s, dumb_ptr<map_session_data> sd, pc_calcstatus(pl_sd, 0); pc_heal(pl_sd, pl_sd->status.max_hp, pl_sd->status.max_sp); clif_misceffect(pl_sd, 0); - clif_displaymessage(s, "Character's base level raised."); + clif_displaymessage(s, "Character's base level raised."_s); } else { if (pl_sd->status.base_level == 1) { - clif_displaymessage(s, "Character's base level can't go any lower."); + clif_displaymessage(s, "Character's base level can't go any lower."_s); return ATCE::RANGE; } if (level < -battle_config.maximum_level || level < (1 - pl_sd->status.base_level)) @@ -2592,20 +2592,20 @@ ATCE atcommand_character_baselevel(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(pl_sd, SP::NEXTBASEEXP); clif_updatestatus(pl_sd, SP::BASEEXP); pc_calcstatus(pl_sd, 0); - clif_displaymessage(s, "Character's base level lowered."); + clif_displaymessage(s, "Character's base level lowered."_s); } // Reset their stat points to prevent extra points from stacking atcommand_charstreset(s, sd, character.to__actual()); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2635,7 +2635,7 @@ ATCE atcommand_character_joblevel(Session *s, dumb_ptr<map_session_data> sd, { if (pl_sd->status.job_level == max_level) { - clif_displaymessage(s, "Character's job level can't go any higher."); + clif_displaymessage(s, "Character's job level can't go any higher."_s); return ATCE::RANGE; } if (pl_sd->status.job_level + level > max_level) @@ -2647,13 +2647,13 @@ ATCE atcommand_character_joblevel(Session *s, dumb_ptr<map_session_data> sd, clif_updatestatus(pl_sd, SP::SKILLPOINT); pc_calcstatus(pl_sd, 0); clif_misceffect(pl_sd, 1); - clif_displaymessage(s, "character's job level raised."); + clif_displaymessage(s, "character's job level raised."_s); } else { if (pl_sd->status.job_level == 1) { - clif_displaymessage(s, "Character's job level can't go any lower."); + clif_displaymessage(s, "Character's job level can't go any lower."_s); return ATCE::RANGE; } if (pl_sd->status.job_level + level < 1) @@ -2670,18 +2670,18 @@ ATCE atcommand_character_joblevel(Session *s, dumb_ptr<map_session_data> sd, } // to add: remove status points from skills pc_calcstatus(pl_sd, 0); - clif_displaymessage(s, "Character's job level lowered."); + clif_displaymessage(s, "Character's job level lowered."_s); } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2705,13 +2705,13 @@ ATCE atcommand_kick(Session *s, dumb_ptr<map_session_data> sd, clif_GM_kick(sd, pl_sd, 1); else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -2737,7 +2737,7 @@ ATCE atcommand_kickall(Session *s, dumb_ptr<map_session_data> sd, } } - clif_displaymessage(s, "All players have been kicked!"); + clif_displaymessage(s, "All players have been kicked!"_s); return ATCE::OKAY; } @@ -2758,23 +2758,23 @@ ATCE atcommand_questskill(Session *s, dumb_ptr<map_session_data> sd, if (pc_checkskill(sd, skill_id) == 0) { pc_skill(sd, skill_id, 1, 0); - clif_displaymessage(s, "You have learned the skill."); + clif_displaymessage(s, "You have learned the skill."_s); } else { - clif_displaymessage(s, "You already have this quest skill."); + clif_displaymessage(s, "You already have this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2801,29 +2801,29 @@ ATCE atcommand_charquestskill(Session *s, dumb_ptr<map_session_data>, if (pc_checkskill(pl_sd, skill_id) == 0) { pc_skill(pl_sd, skill_id, 1, 0); - clif_displaymessage(s, "This player has learned the skill."); + clif_displaymessage(s, "This player has learned the skill."_s); } else { - clif_displaymessage(s, "This player already has this quest skill."); + clif_displaymessage(s, "This player already has this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2848,23 +2848,23 @@ ATCE atcommand_lostskill(Session *s, dumb_ptr<map_session_data> sd, sd->status.skill[skill_id].lv = 0; sd->status.skill[skill_id].flags = SkillFlags::ZERO; clif_skillinfoblock(sd); - clif_displaymessage(s, "You have forgotten the skill."); + clif_displaymessage(s, "You have forgotten the skill."_s); } else { - clif_displaymessage(s, "You don't have this quest skill."); + clif_displaymessage(s, "You don't have this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2893,29 +2893,29 @@ ATCE atcommand_charlostskill(Session *s, dumb_ptr<map_session_data>, pl_sd->status.skill[skill_id].lv = 0; pl_sd->status.skill[skill_id].flags = SkillFlags::ZERO; clif_skillinfoblock(pl_sd); - clif_displaymessage(s, "This player has forgotten the skill."); + clif_displaymessage(s, "This player has forgotten the skill."_s); } else { - clif_displaymessage(s, "This player doesn't have this quest skill."); + clif_displaymessage(s, "This player doesn't have this quest skill."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."_s); return ATCE::RANGE; } } else { - clif_displaymessage(s, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."_s); return ATCE::RANGE; } @@ -2970,7 +2970,7 @@ ATCE atcommand_idsearch(Session *s, dumb_ptr<map_session_data>, if (!extract(message, &item_name) || !item_name) return ATCE::USAGE; - AString output = STRPRINTF("The reference result of '%s' (name: id):", item_name); + AString output = STRPRINTF("The reference result of '%s' (name: id):"_fmt, item_name); clif_displaymessage(s, output); match = 0; for (i = 0; i < 20000; i++) @@ -2979,11 +2979,11 @@ ATCE atcommand_idsearch(Session *s, dumb_ptr<map_session_data>, && item->jname.contains_seq(item_name)) { match++; - output = STRPRINTF("%s: %d", item->jname, item->nameid); + output = STRPRINTF("%s: %d"_fmt, item->jname, item->nameid); clif_displaymessage(s, output); } } - output = STRPRINTF("It is %d affair above.", match); + output = STRPRINTF("It is %d affair above."_fmt, match); clif_displaymessage(s, output); return ATCE::OKAY; @@ -3006,18 +3006,18 @@ ATCE atcommand_charskreset(Session *s, dumb_ptr<map_session_data> sd, // you can reset skill points only lower or same gm level pc_resetskill(pl_sd); AString output = STRPRINTF( - "'%s' skill points reseted!", character); + "'%s' skill points reseted!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3041,19 +3041,19 @@ ATCE atcommand_charstreset(Session *s, dumb_ptr<map_session_data> sd, // you can reset stats points only lower or same gm level pc_resetstate(pl_sd); AString output = STRPRINTF( - "'%s' stats points reseted!", + "'%s' stats points reseted!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3077,23 +3077,23 @@ ATCE atcommand_charreset(Session *s, dumb_ptr<map_session_data> sd, // you can reset a character only for lower or same GM level pc_resetstate(pl_sd); pc_resetskill(pl_sd); - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"_s), 0); // [Fate] Reset magic quest variables - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"_s), 0); // [Fate] Reset magic experience AString output = STRPRINTF( - "'%s' skill and stats points reseted!", character); + "'%s' skill and stats points reseted!"_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3157,23 +3157,23 @@ ATCE atcommand_char_wipe(Session *s, dumb_ptr<map_session_data> sd, pc_calcstatus(pl_sd, 0); pc_resetstate(pl_sd); pc_resetskill(pl_sd); - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_FLAGS"_s), 0); // [Fate] Reset magic quest variables - pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"), 0); + pc_setglobalreg(pl_sd, stringish<VarName>("MAGIC_EXP"_s), 0); // [Fate] Reset magic experience - AString output = STRPRINTF("%s: wiped.", character); + AString output = STRPRINTF("%s: wiped."_fmt, character); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3201,7 +3201,7 @@ ATCE atcommand_charmodel(Session *s, dumb_ptr<map_session_data>, pc_changelook(pl_sd, LOOK::HAIR, hair_style); pc_changelook(pl_sd, LOOK::HAIR_COLOR, hair_color); pc_changelook(pl_sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(s, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."_s); } } else @@ -3209,7 +3209,7 @@ ATCE atcommand_charmodel(Session *s, dumb_ptr<map_session_data>, } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3242,14 +3242,14 @@ ATCE atcommand_charskpoint(Session *s, dumb_ptr<map_session_data>, { pl_sd->status.skill_point = new_skill_point; clif_updatestatus(pl_sd, SP::SKILLPOINT); - clif_displaymessage(s, "Character's number of skill points changed!"); + clif_displaymessage(s, "Character's number of skill points changed!"_s); } else return ATCE::RANGE; } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3282,14 +3282,14 @@ ATCE atcommand_charstpoint(Session *s, dumb_ptr<map_session_data>, { pl_sd->status.status_point = new_status_point; clif_updatestatus(pl_sd, SP::STATUSPOINT); - clif_displaymessage(s, "Character's number of status points changed!"); + clif_displaymessage(s, "Character's number of status points changed!"_s); } else return ATCE::RANGE; } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3320,14 +3320,14 @@ ATCE atcommand_charzeny(Session *s, dumb_ptr<map_session_data>, { pl_sd->status.zeny = new_zeny; clif_updatestatus(pl_sd, SP::ZENY); - clif_displaymessage(s, "Character's number of zenys changed!"); + clif_displaymessage(s, "Character's number of zenys changed!"_s); } else return ATCE::RANGE; } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3344,7 +3344,7 @@ ATCE atcommand_recallall(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp somenone to your actual map."); + "You are not authorised to warp somenone to your actual map."_s); return ATCE::PERM; } @@ -3369,11 +3369,11 @@ ATCE atcommand_recallall(Session *s, dumb_ptr<map_session_data> sd, } } - clif_displaymessage(s, "All characters recalled!"); + clif_displaymessage(s, "All characters recalled!"_s); if (count) { AString output = STRPRINTF( - "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", + "Because you are not authorised to warp from some maps, %d player(s) have not been recalled."_fmt, count); clif_displaymessage(s, output); } @@ -3396,7 +3396,7 @@ ATCE atcommand_partyrecall(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp somenone to your actual map."); + "You are not authorised to warp somenone to your actual map."_s); return ATCE::PERM; } @@ -3422,19 +3422,19 @@ ATCE atcommand_partyrecall(Session *s, dumb_ptr<map_session_data> sd, pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT); } } - AString output = STRPRINTF("All online characters of the %s party are near you.", p->name); + AString output = STRPRINTF("All online characters of the %s party are near you."_fmt, p->name); clif_displaymessage(s, output); if (count) { output = STRPRINTF( - "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", + "Because you are not authorised to warp from some maps, %d player(s) have not been recalled."_fmt, count); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."); + clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."_s); return ATCE::EXIST; } @@ -3447,7 +3447,7 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, { dumb_ptr<npc_data> nd = NULL; MapName map_name; - const char *direction = NULL; + LString direction = ""_s; int list = 0; extract(message, record<' '>(&list, &map_name)); @@ -3462,35 +3462,35 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, if (m_id != nullptr) return ATCE::EXIST; - clif_displaymessage(s, "------ Map Info ------"); - AString output = STRPRINTF("Map Name: %s", map_name); + clif_displaymessage(s, "------ Map Info ------"_s); + AString output = STRPRINTF("Map Name: %s"_fmt, map_name); clif_displaymessage(s, output); - output = STRPRINTF("Players In Map: %d", m_id->users); + output = STRPRINTF("Players In Map: %d"_fmt, m_id->users); clif_displaymessage(s, output); - output = STRPRINTF("NPCs In Map: %d", m_id->npc_num); + output = STRPRINTF("NPCs In Map: %d"_fmt, m_id->npc_num); clif_displaymessage(s, output); - clif_displaymessage(s, "------ Map Flags ------"); - output = STRPRINTF("Player vs Player: %s | No Party: %s", - (m_id->flag.get(MapFlag::PVP)) ? "True" : "False", - (m_id->flag.get(MapFlag::PVP_NOPARTY)) ? "True" : "False"); + clif_displaymessage(s, "------ Map Flags ------"_s); + output = STRPRINTF("Player vs Player: %s | No Party: %s"_fmt, + (m_id->flag.get(MapFlag::PVP)) ? "True"_s : "False"_s, + (m_id->flag.get(MapFlag::PVP_NOPARTY)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Penalty: %s", - (m_id->flag.get(MapFlag::NOPENALTY)) ? "True" : "False"); + output = STRPRINTF("No Penalty: %s"_fmt, + (m_id->flag.get(MapFlag::NOPENALTY)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Return: %s", - (m_id->flag.get(MapFlag::NORETURN)) ? "True" : "False"); + output = STRPRINTF("No Return: %s"_fmt, + (m_id->flag.get(MapFlag::NORETURN)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Save: %s", - (m_id->flag.get(MapFlag::NOSAVE)) ? "True" : "False"); + output = STRPRINTF("No Save: %s"_fmt, + (m_id->flag.get(MapFlag::NOSAVE)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("Re Save: %s", - (m_id->flag.get(MapFlag::RESAVE)) ? "True" : "False"); + output = STRPRINTF("Re Save: %s"_fmt, + (m_id->flag.get(MapFlag::RESAVE)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Teleport: %s", - (m_id->flag.get(MapFlag::NOTELEPORT)) ? "True" : "False"); + output = STRPRINTF("No Teleport: %s"_fmt, + (m_id->flag.get(MapFlag::NOTELEPORT)) ? "True"_s : "False"_s); clif_displaymessage(s, output); - output = STRPRINTF("No Monster Teleport: %s", - (m_id->flag.get(MapFlag::MONSTER_NOTELEPORT)) ? "True" : "False"); + output = STRPRINTF("No Monster Teleport: %s"_fmt, + (m_id->flag.get(MapFlag::MONSTER_NOTELEPORT)) ? "True"_s : "False"_s); clif_displaymessage(s, output); switch (list) @@ -3499,7 +3499,7 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, // Do nothing. It's list 0, no additional display. break; case 1: - clif_displaymessage(s, "----- Players in Map -----"); + clif_displaymessage(s, "----- Players in Map -----"_s); for (io::FD i : iter_fds()) { Session *s2 = get_session(i); @@ -3510,54 +3510,54 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, && pl_sd->mapname_ == map_name) { output = STRPRINTF( - "Player '%s' (session #%d) | Location: %d,%d", + "Player '%s' (session #%d) | Location: %d,%d"_fmt, pl_sd->status_key.name, s2, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); } } break; case 2: - clif_displaymessage(s, "----- NPCs in Map -----"); + clif_displaymessage(s, "----- NPCs in Map -----"_s); for (int i = 0; i < m_id->npc_num;) { nd = m_id->npc[i]; switch (nd->dir) { case DIR::S: - direction = "North"; + direction = "North"_s; break; case DIR::SW: - direction = "North West"; + direction = "North West"_s; break; case DIR::W: - direction = "West"; + direction = "West"_s; break; case DIR::NW: - direction = "South West"; + direction = "South West"_s; break; case DIR::N: - direction = "South"; + direction = "South"_s; break; case DIR::NE: - direction = "South East"; + direction = "South East"_s; break; case DIR::E: - direction = "East"; + direction = "East"_s; break; case DIR::SE: - direction = "North East"; + direction = "North East"_s; break; #if 0 case 9: - direction = "North"; + direction = "North"_s; break; #endif default: - direction = "Unknown"; + direction = "Unknown"_s; break; } output = STRPRINTF( - "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d", + "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d"_fmt, ++i, nd->name, direction, nd->npc_class, nd->bl_x, nd->bl_y); clif_displaymessage(s, output); @@ -3566,7 +3566,7 @@ ATCE atcommand_mapinfo(Session *s, dumb_ptr<map_session_data> sd, default: // normally impossible to arrive here clif_displaymessage(s, - "Please, enter at least a valid list number (usage: @mapinfo <0-2> [map])."); + "Please, enter at least a valid list number (usage: @mapinfo <0-2> [map])."_s); return ATCE::USAGE; } @@ -3590,19 +3590,19 @@ ATCE atcommand_partyspy(Session *s, dumb_ptr<map_session_data> sd, if (sd->partyspy == p->party_id) { sd->partyspy = 0; - AString output = STRPRINTF("No longer spying on the %s party.", p->name); + AString output = STRPRINTF("No longer spying on the %s party."_fmt, p->name); clif_displaymessage(s, output); } else { sd->partyspy = p->party_id; - AString output = STRPRINTF("Spying on the %s party.", p->name); + AString output = STRPRINTF("Spying on the %s party."_fmt, p->name); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."); + clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."_s); return ATCE::EXIST; } @@ -3621,11 +3621,11 @@ ATCE atcommand_enablenpc(Session *s, dumb_ptr<map_session_data>, if (npc_name2id(NPCname) != NULL) { npc_enable(NPCname, 1); - clif_displaymessage(s, "Npc Enabled."); + clif_displaymessage(s, "Npc Enabled."_s); } else { - clif_displaymessage(s, "This NPC doesn't exist."); + clif_displaymessage(s, "This NPC doesn't exist."_s); return ATCE::EXIST; } @@ -3644,11 +3644,11 @@ ATCE atcommand_disablenpc(Session *s, dumb_ptr<map_session_data>, if (npc_name2id(NPCname) != NULL) { npc_enable(NPCname, 0); - clif_displaymessage(s, "Npc Disabled."); + clif_displaymessage(s, "Npc Disabled."_s); } else { - clif_displaymessage(s, "This NPC doesn't exist."); + clif_displaymessage(s, "This NPC doesn't exist."_s); return ATCE::EXIST; } @@ -3661,7 +3661,7 @@ ATCE atcommand_servertime(Session *s, dumb_ptr<map_session_data>, { timestamp_seconds_buffer tsbuf; stamp_time(tsbuf); - AString temp = STRPRINTF("Server time: %s", tsbuf); + AString temp = STRPRINTF("Server time: %s"_fmt, tsbuf); clif_displaymessage(s, temp); return ATCE::OKAY; @@ -3707,37 +3707,37 @@ ATCE atcommand_chardelitem(Session *s, dumb_ptr<map_session_data> sd, // for next loop } AString output = STRPRINTF( - "%d item(s) removed by a GM.", + "%d item(s) removed by a GM."_fmt, count); clif_displaymessage(pl_sd->sess, output); if (number == count) - output = STRPRINTF("%d item(s) removed from the player.", count); + output = STRPRINTF("%d item(s) removed from the player."_fmt, count); else - output = STRPRINTF("%d item(s) removed. Player had only %d on %d items.", count, count, number); + output = STRPRINTF("%d item(s) removed. Player had only %d on %d items."_fmt, count, count, number); clif_displaymessage(s, output); } else { - clif_displaymessage(s, "Character does not have the item."); + clif_displaymessage(s, "Character does not have the item."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } } else { - clif_displaymessage(s, "Invalid item ID or name."); + clif_displaymessage(s, "Invalid item ID or name."_s); return ATCE::RANGE; } @@ -3751,7 +3751,7 @@ ATCE atcommand_broadcast(Session *, dumb_ptr<map_session_data> sd, if (!message) return ATCE::USAGE; - AString output = STRPRINTF("%s : %s", sd->status_key.name, message); + AString output = STRPRINTF("%s : %s"_fmt, sd->status_key.name, message); intif_GMmessage(output); return ATCE::OKAY; @@ -3764,7 +3764,7 @@ ATCE atcommand_localbroadcast(Session *, dumb_ptr<map_session_data> sd, if (!message) return ATCE::USAGE; - AString output = STRPRINTF("%s : %s", sd->status_key.name, message); + AString output = STRPRINTF("%s : %s"_fmt, sd->status_key.name, message); clif_GMmessage(sd, output, 1); @@ -3783,28 +3783,28 @@ ATCE atcommand_email(Session *s, dumb_ptr<map_session_data> sd, if (!e_mail_check(actual_email)) { - clif_displaymessage(s, "Invalid actual email. If you have default e-mail, type a@a.com."); + clif_displaymessage(s, "Invalid actual email. If you have default e-mail, type a@a.com."_s); return ATCE::RANGE; } else if (!e_mail_check(new_email)) { - clif_displaymessage(s, "Invalid new email. Please enter a real e-mail."); + clif_displaymessage(s, "Invalid new email. Please enter a real e-mail."_s); return ATCE::RANGE; } else if (new_email == DEFAULT_EMAIL) { - clif_displaymessage(s, "New email must be a real e-mail."); + clif_displaymessage(s, "New email must be a real e-mail."_s); return ATCE::RANGE; } else if (actual_email == new_email) { - clif_displaymessage(s, "New email must be different of the actual e-mail."); + clif_displaymessage(s, "New email must be different of the actual e-mail."_s); return ATCE::RANGE; } else { chrif_changeemail(sd->status_key.account_id, actual_email, new_email); - clif_displaymessage(s, "Information sended to login-server via char-server."); + clif_displaymessage(s, "Information sended to login-server via char-server."_s); } return ATCE::OKAY; @@ -3821,7 +3821,7 @@ ATCE atcommand_effect(Session *s, dumb_ptr<map_session_data> sd, if (flag <= 0) { clif_specialeffect(sd, type, flag); - clif_displaymessage(s, "Your Effect Has Changed."); + clif_displaymessage(s, "Your Effect Has Changed."_s); } else { @@ -3834,7 +3834,7 @@ ATCE atcommand_effect(Session *s, dumb_ptr<map_session_data> sd, if (pl_sd && pl_sd->state.auth) { clif_specialeffect(pl_sd, type, flag); - clif_displaymessage(pl_sd->sess, "Your Effect Has Changed."); + clif_displaymessage(pl_sd->sess, "Your Effect Has Changed."_s); } } } @@ -3873,7 +3873,7 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, if (count == 1) { AString output = STRPRINTF( - "------ Items list of '%s' ------", + "------ Items list of '%s' ------"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); } @@ -3881,35 +3881,35 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, MString equipstr; if (bool(equip)) { - equipstr += "| equiped: "; + equipstr += "| equiped: "_s; if (bool(equip & EPOS::GLOVES)) - equipstr += "robe/gargment, "; + equipstr += "robe/gargment, "_s; if (bool(equip & EPOS::CAPE)) - equipstr += "left accessory, "; + equipstr += "left accessory, "_s; if (bool(equip & EPOS::MISC1)) - equipstr += "body/armor, "; + equipstr += "body/armor, "_s; if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::WEAPON) - equipstr += "right hand, "; + equipstr += "right hand, "_s; if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::SHIELD) - equipstr += "left hand, "; + equipstr += "left hand, "_s; if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == (EPOS::WEAPON | EPOS::SHIELD)) - equipstr += "both hands, "; + equipstr += "both hands, "_s; if (bool(equip & EPOS::SHOES)) - equipstr += "feet, "; + equipstr += "feet, "_s; if (bool(equip & EPOS::MISC2)) - equipstr += "right accessory, "; + equipstr += "right accessory, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::LEGS) - equipstr += "lower head, "; + equipstr += "lower head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::HAT) - equipstr += "top head, "; + equipstr += "top head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::HAT | EPOS::LEGS)) - equipstr += "lower/top head, "; + equipstr += "lower/top head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::TORSO) - equipstr += "mid head, "; + equipstr += "mid head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::LEGS)) - equipstr += "lower/mid head, "; + equipstr += "lower/mid head, "_s; if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) - equipstr += "lower/mid/top head, "; + equipstr += "lower/mid/top head, "_s; // remove final ', ' equipstr.pop_back(2); } @@ -3918,7 +3918,7 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, AString output; if (true) - output = STRPRINTF("%d %s (%s, id: %d) %s", + output = STRPRINTF("%d %s (%s, id: %d) %s"_fmt, pl_sd->status.inventory[i].amount, item_data->name, item_data->jname, pl_sd->status.inventory[i].nameid, @@ -3929,24 +3929,24 @@ ATCE atcommand_character_item_list(Session *s, dumb_ptr<map_session_data> sd, } } if (count == 0) - clif_displaymessage(s, "No item found on this player."); + clif_displaymessage(s, "No item found on this player."_s); else { AString output = STRPRINTF( - "%d item(s) found in %d kind(s) of items.", + "%d item(s) found in %d kind(s) of items."_fmt, counter, count); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -3986,13 +3986,13 @@ ATCE atcommand_character_storage_list(Session *s, dumb_ptr<map_session_data> sd, if (count == 1) { AString output = STRPRINTF( - "------ Storage items list of '%s' ------", + "------ Storage items list of '%s' ------"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); } AString output; if (true) - output = STRPRINTF("%d %s (%s, id: %d)", + output = STRPRINTF("%d %s (%s, id: %d)"_fmt, stor->storage_[i].amount, item_data->name, item_data->jname, stor->storage_[i].nameid); @@ -4001,30 +4001,30 @@ ATCE atcommand_character_storage_list(Session *s, dumb_ptr<map_session_data> sd, } if (count == 0) clif_displaymessage(s, - "No item found in the storage of this player."); + "No item found in the storage of this player."_s); else { AString output = STRPRINTF( - "%d item(s) found in %d kind(s) of items.", + "%d item(s) found in %d kind(s) of items."_fmt, counter, count); clif_displaymessage(s, output); } } else { - clif_displaymessage(s, "This player has no storage."); + clif_displaymessage(s, "This player has no storage."_s); return ATCE::OKAY; } } else { - clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."_s); return ATCE::PERM; } } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4038,9 +4038,9 @@ ATCE atcommand_killer(Session *s, dumb_ptr<map_session_data> sd, sd->special_state.killer = !sd->special_state.killer; if (sd->special_state.killer) - clif_displaymessage(s, "You be a killa..."); + clif_displaymessage(s, "You be a killa..."_s); else - clif_displaymessage(s, "You gonna be own3d..."); + clif_displaymessage(s, "You gonna be own3d..."_s); return ATCE::OKAY; } @@ -4062,13 +4062,13 @@ ATCE atcommand_charkiller(Session *s, dumb_ptr<map_session_data>, if (pl_sd->special_state.killer) { - clif_displaymessage(s, "The player is now a killer"); - clif_displaymessage(pl_sd->sess, "You are now a killer"); + clif_displaymessage(s, "The player is now a killer"_s); + clif_displaymessage(pl_sd->sess, "You are now a killer"_s); } else { - clif_displaymessage(s, "The player is no longer a killer"); - clif_displaymessage(pl_sd->sess, "You are no longer a killer"); + clif_displaymessage(s, "The player is no longer a killer"_s); + clif_displaymessage(pl_sd->sess, "You are no longer a killer"_s); } return ATCE::OKAY; @@ -4081,9 +4081,9 @@ ATCE atcommand_killable(Session *s, dumb_ptr<map_session_data> sd, sd->special_state.killable = !sd->special_state.killable; if (sd->special_state.killable) - clif_displaymessage(s, "You gonna be own3d..."); + clif_displaymessage(s, "You gonna be own3d..."_s); else - clif_displaymessage(s, "You be a killa..."); + clif_displaymessage(s, "You be a killa..."_s); return ATCE::OKAY; } @@ -4104,9 +4104,9 @@ ATCE atcommand_charkillable(Session *s, dumb_ptr<map_session_data>, pl_sd->special_state.killable = !pl_sd->special_state.killable; if (pl_sd->special_state.killable) - clif_displaymessage(s, "The player is now killable"); + clif_displaymessage(s, "The player is now killable"_s); else - clif_displaymessage(s, "The player is no longer killable"); + clif_displaymessage(s, "The player is no longer killable"_s); return ATCE::OKAY; } @@ -4146,17 +4146,17 @@ ATCE atcommand_addwarp(Session *s, dumb_ptr<map_session_data> sd, if (!extract(message, record<' '>(&mapname, &x, &y))) return ATCE::USAGE; - AString w1 = STRPRINTF("%s,%d,%d", sd->mapname_, sd->bl_x, sd->bl_y); - AString w3 = STRPRINTF("%s%d%d%d%d", mapname, sd->bl_x, sd->bl_y, x, y); - AString w4 = STRPRINTF("1,1,%s.gat,%d,%d", mapname, x, y); + AString w1 = STRPRINTF("%s,%d,%d"_fmt, sd->mapname_, sd->bl_x, sd->bl_y); + AString w3 = STRPRINTF("%s%d%d%d%d"_fmt, mapname, sd->bl_x, sd->bl_y, x, y); + AString w4 = STRPRINTF("1,1,%s.gat,%d,%d"_fmt, mapname, x, y); NpcName w3name = stringish<NpcName>(w3); - int ret = npc_parse_warp(w1, ZString("warp"), w3name, w4); + int ret = npc_parse_warp(w1, "warp"_s, w3name, w4); if (ret) // warp failed return ATCE::RANGE; - AString output = STRPRINTF("New warp NPC => %s", w3); + AString output = STRPRINTF("New warp NPC => %s"_fmt, w3); clif_displaymessage(s, output); return ATCE::OKAY; @@ -4177,7 +4177,7 @@ ATCE atcommand_chareffect(Session *s, dumb_ptr<map_session_data>, return ATCE::EXIST; clif_specialeffect(pl_sd, type, 0); - clif_displaymessage(s, "Your Effect Has Changed."); + clif_displaymessage(s, "Your Effect Has Changed."_s); return ATCE::OKAY; } @@ -4220,9 +4220,8 @@ ATCE atcommand_chardropall(Session *s, dumb_ptr<map_session_data>, } } - clif_displaymessage(pl_sd->sess, "Ever play 52 card pickup?"); - clif_displaymessage(s, "It is done"); - //clif_displaymessage(s, "It is offical.. your a jerk"); + clif_displaymessage(pl_sd->sess, "Ever play 52 card pickup?"_s); + clif_displaymessage(s, "It is official.. you're a jerk."_s); return ATCE::OKAY; } @@ -4240,12 +4239,12 @@ ATCE atcommand_storeall(Session *s, dumb_ptr<map_session_data> sd, { case 2: //Try again - clif_displaymessage(s, "run this command again.."); + clif_displaymessage(s, "run this command again.."_s); return ATCE::OKAY; case 1: //Failure clif_displaymessage(s, - "You can't open the storage currently."); + "You can't open the storage currently."_s); return ATCE::EXIST; } } @@ -4260,7 +4259,7 @@ ATCE atcommand_storeall(Session *s, dumb_ptr<map_session_data> sd, } storage_storageclose(sd); - clif_displaymessage(s, "It is done"); + clif_displaymessage(s, "It is done"_s); return ATCE::OKAY; } @@ -4281,8 +4280,8 @@ ATCE atcommand_charstoreall(Session *s, dumb_ptr<map_session_data> sd, // TODO figure out what the hell this is talking about, // and especially why it's different from the other one. clif_displaymessage(s, - "Had to open the characters storage window..."); - clif_displaymessage(s, "run this command again.."); + "Had to open the characters storage window..."_s); + clif_displaymessage(s, "run this command again.."_s); return ATCE::OKAY; } for (int i = 0; i < MAX_INVENTORY; i++) @@ -4297,12 +4296,12 @@ ATCE atcommand_charstoreall(Session *s, dumb_ptr<map_session_data> sd, storage_storageclose(pl_sd); clif_displaymessage(pl_sd->sess, - "Everything you own has been put away for safe keeping."); + "Everything you own has been put away for safe keeping."_s); clif_displaymessage(pl_sd->sess, - "go to the nearest kafka to retrieve it.."); - clif_displaymessage(pl_sd->sess, " -- the management"); + "go to the nearest kafka to retrieve it.."_s); + clif_displaymessage(pl_sd->sess, " -- the management"_s); - clif_displaymessage(s, "It is done"); + clif_displaymessage(s, "It is done"_s); return ATCE::OKAY; } @@ -4425,7 +4424,7 @@ ATCE atcommand_adjcmdlvl(Session *s, dumb_ptr<map_session_data>, if (!extract(message, record<' '>(&newlev, &cmd))) { - clif_displaymessage(s, "usage: @adjcmdlvl <lvl> <command>."); + clif_displaymessage(s, "usage: @adjcmdlvl <lvl> <command>."_s); return ATCE::USAGE; } @@ -4434,12 +4433,12 @@ ATCE atcommand_adjcmdlvl(Session *s, dumb_ptr<map_session_data>, if (it) { it->level = newlev; - clif_displaymessage(s, "@command level changed."); + clif_displaymessage(s, "@command level changed."_s); return ATCE::OKAY; } } - clif_displaymessage(s, "@command not found."); + clif_displaymessage(s, "@command not found."_s); return ATCE::EXIST; } @@ -4453,7 +4452,7 @@ ATCE atcommand_adjgmlvl(Session *s, dumb_ptr<map_session_data>, if (!asplit(message, &newlev, &user) || newlev < 0 || newlev > 99) { - clif_displaymessage(s, "usage: @adjgmlvl <lvl> <user>."); + clif_displaymessage(s, "usage: @adjgmlvl <lvl> <user>."_s); return ATCE::USAGE; } @@ -4501,14 +4500,14 @@ constexpr size_t magic_skills_nr = sizeof(magic_skills) / sizeof(magic_skills[0]); static -ZString magic_skill_names[magic_skills_nr] = +LString magic_skill_names[magic_skills_nr] = { - {"magic"}, - {"life"}, - {"war"}, - {"transmute"}, - {"nature"}, - {"astral"}, + "magic"_s, + "life"_s, + "war"_s, + "transmute"_s, + "nature"_s, + "astral"_s, }; static @@ -4524,7 +4523,7 @@ ATCE atcommand_magic_info(Session *s, dumb_ptr<map_session_data>, if (pl_sd) { AString buf = STRPRINTF( - "`%s' has the following magic skills:", + "`%s' has the following magic skills:"_fmt, character); clif_displaymessage(s, buf); @@ -4532,7 +4531,7 @@ ATCE atcommand_magic_info(Session *s, dumb_ptr<map_session_data>, { SkillID sk = magic_skills[i]; buf = STRPRINTF( - "%d in %s", + "%d in %s"_fmt, pl_sd->status.skill[sk].lv, magic_skill_names[i]); if (pl_sd->status.skill[sk].lv) @@ -4542,7 +4541,7 @@ ATCE atcommand_magic_info(Session *s, dumb_ptr<map_session_data>, return ATCE::OKAY; } - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4563,12 +4562,12 @@ ATCE atcommand_set_magic(Session *s, dumb_ptr<map_session_data>, if (!asplit(message, &magic_type, &value, &character)) { clif_displaymessage(s, - "Usage: @setmagic <school> <value> <char-name>, where <school> is either `magic', one of the school names, or `all'."); + "Usage: @setmagic <school> <value> <char-name>, where <school> is either `magic', one of the school names, or `all'."_s); return ATCE::USAGE; } SkillID skill_index = SkillID::NEGATIVE; - if ("all" == magic_type) + if ("all"_s == magic_type) skill_index = SkillID::ZERO; else { @@ -4585,7 +4584,7 @@ ATCE atcommand_set_magic(Session *s, dumb_ptr<map_session_data>, if (skill_index == SkillID::NEGATIVE) { clif_displaymessage(s, - "Incorrect school of magic. Use `magic', `nature', `life', `war', `transmute', `ether', or `all'."); + "Incorrect school of magic. Use `magic', `nature', `life', `war', `transmute', `ether', or `all'."_s); return ATCE::RANGE; } @@ -4602,7 +4601,7 @@ ATCE atcommand_set_magic(Session *s, dumb_ptr<map_session_data>, return ATCE::OKAY; } - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4664,18 +4663,18 @@ ATCE atcommand_jump_iterate(Session *s, dumb_ptr<map_session_data> sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you to the map of this player."); + "You are not authorised to warp you to the map of this player."_s); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.get(MapFlag::NOWARP) && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(s, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."_s); return ATCE::PERM; } pc_setpos(sd, pl_sd->bl_m->name_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); - AString output = STRPRINTF("Jump to %s", pl_sd->status_key.name); + AString output = STRPRINTF("Jump to %s"_fmt, pl_sd->status_key.name); clif_displaymessage(s, output); sd->followtarget = pl_sd->bl_id; @@ -4702,9 +4701,9 @@ ATCE atcommand_wgm(Session *s, dumb_ptr<map_session_data> sd, if (tmw_CheckChatSpam(sd, message)) return ATCE::OKAY; - tmw_GmHackMsg(STRPRINTF("[GM] %s: %s", sd->status_key.name, message)); + tmw_GmHackMsg(STRPRINTF("[GM] %s: %s"_fmt, sd->status_key.name, message)); if (!pc_isGM(sd)) - clif_displaymessage(s, "Message sent."); + clif_displaymessage(s, "Message sent."_s); return ATCE::OKAY; } @@ -4727,19 +4726,19 @@ ATCE atcommand_skillpool_info(Session *s, dumb_ptr<map_session_data>, int i; AString buf = STRPRINTF( - "Active skills %d out of %d for %s:", + "Active skills %d out of %d for %s:"_fmt, pool_skills_nr, skill_pool_max(pl_sd), character); clif_displaymessage(s, buf); for (i = 0; i < pool_skills_nr; ++i) { - buf = STRPRINTF(" - %s [%d]: power %d", + buf = STRPRINTF(" - %s [%d]: power %d"_fmt, skill_name(pool_skills[i]), pool_skills[i], skill_power(pl_sd, pool_skills[i])); clif_displaymessage(s, buf); } - buf = STRPRINTF("Learned skills out of %d for %s:", + buf = STRPRINTF("Learned skills out of %d for %s:"_fmt, skill_pool_skills_size, character); clif_displaymessage(s, buf); @@ -4750,7 +4749,7 @@ ATCE atcommand_skillpool_info(Session *s, dumb_ptr<map_session_data>, if (lvl) { - buf = STRPRINTF(" - %s [%d]: lvl %d", + buf = STRPRINTF(" - %s [%d]: lvl %d"_fmt, name, skill_pool_skills[i], lvl); clif_displaymessage(s, buf); } @@ -4759,7 +4758,7 @@ ATCE atcommand_skillpool_info(Session *s, dumb_ptr<map_session_data>, } else { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4775,7 +4774,7 @@ ATCE atcommand_skillpool_focus(Session *s, dumb_ptr<map_session_data>, if (!asplit(message, &skill, &character)) { - clif_displaymessage(s, "Usage: @sp-focus <skill-nr> <char_name>"); + clif_displaymessage(s, "Usage: @sp-focus <skill-nr> <char_name>"_s); return ATCE::USAGE; } @@ -4783,12 +4782,12 @@ ATCE atcommand_skillpool_focus(Session *s, dumb_ptr<map_session_data>, if (pl_sd != NULL) { if (skill_pool_activate(pl_sd, skill)) - clif_displaymessage(s, "Activation failed."); + clif_displaymessage(s, "Activation failed."_s); else - clif_displaymessage(s, "Activation successful."); + clif_displaymessage(s, "Activation successful."_s); } else - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::OKAY; } @@ -4807,12 +4806,12 @@ ATCE atcommand_skillpool_unfocus(Session *s, dumb_ptr<map_session_data>, if (pl_sd != NULL) { if (skill_pool_deactivate(pl_sd, skill)) - clif_displaymessage(s, "Deactivation failed."); + clif_displaymessage(s, "Deactivation failed."_s); else - clif_displaymessage(s, "Deactivation successful."); + clif_displaymessage(s, "Deactivation successful."_s); } else - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::OKAY; } @@ -4835,7 +4834,7 @@ ATCE atcommand_skill_learn(Session *s, dumb_ptr<map_session_data>, clif_skillinfoblock(pl_sd); } else - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::OKAY; } @@ -4852,7 +4851,7 @@ ATCE atcommand_ipcheck(Session *s, dumb_ptr<map_session_data>, dumb_ptr<map_session_data> pl_sd = map_nick2sd(character); if (pl_sd == NULL) { - clif_displaymessage(s, "Character not found."); + clif_displaymessage(s, "Character not found."_s); return ATCE::EXIST; } @@ -4873,7 +4872,7 @@ ATCE atcommand_ipcheck(Session *s, dumb_ptr<map_session_data>, if (ip == pl_sd->get_ip()) { AString output = STRPRINTF( - "Name: %s | Location: %s %d %d", + "Name: %s | Location: %s %d %d"_fmt, pl_sd->status_key.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(s, output); @@ -4881,7 +4880,7 @@ ATCE atcommand_ipcheck(Session *s, dumb_ptr<map_session_data>, } } - clif_displaymessage(s, "End of list"); + clif_displaymessage(s, "End of list"_s); return ATCE::OKAY; } @@ -4902,10 +4901,10 @@ ATCE atcommand_doomspot(Session *s, dumb_ptr<map_session_data> sd, { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."_s); } } - clif_displaymessage(s, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."_s); return ATCE::OKAY; } @@ -4915,13 +4914,13 @@ ATCE atcommand_source(Session *s, dumb_ptr<map_session_data>, ZString) { clif_displaymessage(s, - "This server code consists of Free Software under GPL3&AGPL3"); + "This server code consists of Free Software under GPL3&AGPL3"_s); clif_displaymessage(s, - "This is commit " VERSION_HASH ", also known as " VERSION_FULL); + "This is commit " VERSION_HASH ", also known as " VERSION_FULL ""_s); clif_displaymessage(s, - "The version is " VERSION_STRING); + "The version is " VERSION_STRING ""_s); clif_displaymessage(s, - "For source, see " VENDOR_SOURCE); + "For source, see " VENDOR_SOURCE ""_s); return ATCE::OKAY; } @@ -4931,424 +4930,424 @@ ATCE atcommand_source(Session *s, dumb_ptr<map_session_data>, // declared extern above Map<XString, AtCommandInfo> atcommand_info = { - {"help", {"[level[-level]|category|@command]", + {"help"_s, {"[level[-level]|category|@command]"_s, 0, atcommand_help, - "Show help"}}, - {"setup", {"<level> <charname>", + "Show help"_s}}, + {"setup"_s, {"<level> <charname>"_s, 40, atcommand_setup, - "Safely set a chars levels and warp them to a special place (for TAW)"}}, - {"charwarp", {"<mapname> <x> <y> <charname>", + "Safely set a chars levels and warp them to a special place (for TAW)"_s}}, + {"charwarp"_s, {"<mapname> <x> <y> <charname>"_s, 60, atcommand_charwarp, - "Warp a character to a point on another map"}}, - {"warp", {"<mapname> [x] [y]", + "Warp a character to a point on another map"_s}}, + {"warp"_s, {"<mapname> [x] [y]"_s, 40, atcommand_warp, - "Warp yourself to another map"}}, - {"where", {"[charname]", + "Warp yourself to another map"_s}}, + {"where"_s, {"[charname]"_s, 40, atcommand_where, - "Show location of a character or yourself"}}, - {"goto", {"<charname>", + "Show location of a character or yourself"_s}}, + {"goto"_s, {"<charname>"_s, 40, atcommand_goto, - "Warp yourself to another character"}}, - {"jump", {"[x] [y]", + "Warp yourself to another character"_s}}, + {"jump"_s, {"[x] [y]"_s, 40, atcommand_jump, - "Warp yourself within a map"}}, - {"who", {"[subsequence]", + "Warp yourself within a map"_s}}, + {"who"_s, {"[subsequence]"_s, 40, atcommand_who, - "List matching players online, with location info"}}, - {"whogroup", {"[subsequence]", + "List matching players online, with location info"_s}}, + {"whogroup"_s, {"[subsequence]"_s, 40, atcommand_whogroup, - "List matching players online, with party info"}}, - {"whomap", {"[mapname]", + "List matching players online, with party info"_s}}, + {"whomap"_s, {"[mapname]"_s, 40, atcommand_whomap, - "List all players on the map, with location info"}}, - {"whomapgroup", {"[mapname]", + "List all players on the map, with location info"_s}}, + {"whomapgroup"_s, {"[mapname]"_s, 40, atcommand_whomapgroup, - "List all players on the map, with party info"}}, - {"whogm", {"[subsequence]", + "List all players on the map, with party info"_s}}, + {"whogm"_s, {"[subsequence]"_s, 40, atcommand_whogm, - "List matching GM players, with location, level, and party info"}}, - {"save", {"", + "List matching GM players, with location, level, and party info"_s}}, + {"save"_s, {""_s, 40, atcommand_save, - "Set your respawn point to your current location"}}, - {"return", {"", + "Set your respawn point to your current location"_s}}, + {"return"_s, {""_s, 40, atcommand_load, - "Return to your respawn point"}}, - {"load", {"", + "Return to your respawn point"_s}}, + {"load"_s, {""_s, 40, atcommand_load, - "Return to your respawn point"}}, - {"speed", {"<rate>", + "Return to your respawn point"_s}}, + {"speed"_s, {"<rate>"_s, 60, atcommand_speed, - "Set walk rate"}}, - {"storage", {"", + "Set walk rate"_s}}, + {"storage"_s, {""_s, 99, atcommand_storage, - "Open your storage"}}, - {"option", {"<opt1> [opt2] [option]", + "Open your storage"_s}}, + {"option"_s, {"<opt1> [opt2] [option]"_s, 80, atcommand_option, - "Set your 'option' status flags"}}, - {"hide", {"", + "Set your 'option' status flags"_s}}, + {"hide"_s, {""_s, 40, atcommand_hide, - "Toggle invisibility from monsters and certain commands"}}, - {"die", {"", + "Toggle invisibility from monsters and certain commands"_s}}, + {"die"_s, {""_s, 40, atcommand_die, - "Cause fatal damage to yourself"}}, - {"kill", {"<charname>", + "Cause fatal damage to yourself"_s}}, + {"kill"_s, {"<charname>"_s, 60, atcommand_kill, - "Cause fatal damage to another player"}}, - {"alive", {"", + "Cause fatal damage to another player"_s}}, + {"alive"_s, {""_s, 60, atcommand_alive, - "Restore life to yourself"}}, - {"kami", {"<message ...>", + "Restore life to yourself"_s}}, + {"kami"_s, {"<message ...>"_s, 99, atcommand_kami, - "Send an anonymous broadcast"}}, - {"heal", {"[hp] [sp]", + "Send an anonymous broadcast"_s}}, + {"heal"_s, {"[hp] [sp]"_s, 40, atcommand_heal, - "Restore or destroy your health"}}, - {"item", {"<item-name-or-id> [count]", + "Restore or destroy your health"_s}}, + {"item"_s, {"<item-name-or-id> [count]"_s, 80, atcommand_item, - "Summon items out of the void"}}, - {"itemreset", {"", + "Summon items out of the void"_s}}, + {"itemreset"_s, {""_s, 40, atcommand_itemreset, - "Cast all of your itens into the void (why would you ever want this?)"}}, - {"itemcheck", {"", + "Cast all of your itens into the void (why would you ever want this?)"_s}}, + {"itemcheck"_s, {""_s, 80, atcommand_itemcheck, - "Perform an internal integrity check on your items"}}, - {"blvl", {"<delta>", + "Perform an internal integrity check on your items"_s}}, + {"blvl"_s, {"<delta>"_s, 60, atcommand_baselevelup, - "Adjust your level"}}, - {"jlvl", {"<delta>", + "Adjust your level"_s}}, + {"jlvl"_s, {"<delta>"_s, 60, atcommand_joblevelup, - "Adjust your job level"}}, - {"gm", {"<password>", + "Adjust your job level"_s}}, + {"gm"_s, {"<password>"_s, 100, atcommand_gm, - "Receive GM powers"}}, - {"pvpoff", {"", + "Receive GM powers"_s}}, + {"pvpoff"_s, {""_s, 60, atcommand_pvpoff, - "Enable PvP on your map"}}, - {"pvpon", {"", + "Enable PvP on your map"_s}}, + {"pvpon"_s, {""_s, 60, atcommand_pvpon, - "Disable PvP on your map"}}, - {"model", {"<style> [color] [dye]", + "Disable PvP on your map"_s}}, + {"model"_s, {"<style> [color] [dye]"_s, 99, atcommand_model, - "Change your hairstyle and hair color"}}, - {"spawn", {"<mob-name-or-id> [count] [x] [y]", + "Change your hairstyle and hair color"_s}}, + {"spawn"_s, {"<mob-name-or-id> [count] [x] [y]"_s, 50, atcommand_spawn, - "Spawn normal monsters at location."}}, - {"killmonster", {"[map]", + "Spawn normal monsters at location."_s}}, + {"killmonster"_s, {"[map]"_s, 60, atcommand_killmonster, - "Kill all monsters (with drops)"}}, - {"killmonster2", {"[map]", + "Kill all monsters (with drops)"_s}}, + {"killmonster2"_s, {"[map]"_s, 60, atcommand_killmonster2, - "Kill all monsters (no drops)"}}, - {"gat", {"", + "Kill all monsters (no drops)"_s}}, + {"gat"_s, {""_s, 99, atcommand_gat, - "Dump the local walkmap"}}, - {"packet", {"<type> <flag>", + "Dump the local walkmap"_s}}, + {"packet"_s, {"<type> <flag>"_s, 99, atcommand_packet, - "Force a status change"}}, - {"stpoint", {"<amount>", + "Force a status change"_s}}, + {"stpoint"_s, {"<amount>"_s, 60, atcommand_statuspoint, - "Increase your stat points"}}, - {"skpoint", {"<amount>", + "Increase your stat points"_s}}, + {"skpoint"_s, {"<amount>"_s, 60, atcommand_skillpoint, - "Increase your skill points"}}, - {"zeny", {"<amount>", + "Increase your skill points"_s}}, + {"zeny"_s, {"<amount>"_s, 80, atcommand_zeny, - "Change how much money you have"}}, - {"str", {"<delta>", + "Change how much money you have"_s}}, + {"str"_s, {"<delta>"_s, 60, atcommand_param<ATTR::STR>, - "Adjust your strength"}}, - {"agi", {"<delta>", + "Adjust your strength"_s}}, + {"agi"_s, {"<delta>"_s, 60, atcommand_param<ATTR::AGI>, - "Adjust your agility"}}, - {"vit", {"<delta>", + "Adjust your agility"_s}}, + {"vit"_s, {"<delta>"_s, 60, atcommand_param<ATTR::VIT>, - "Adjust your vitality"}}, - {"int", {"<delta>", + "Adjust your vitality"_s}}, + {"int"_s, {"<delta>"_s, 60, atcommand_param<ATTR::INT>, - "Adjust your intelligence\0(TODO make this work in real life, I'm lonely)"}}, - {"dex", {"<delta>", + "Adjust your intelligence\0(TODO make this work in real life, I'm lonely)"_s}}, + {"dex"_s, {"<delta>"_s, 60, atcommand_param<ATTR::DEX>, - "Adjust your dexterity"}}, - {"luk", {"<delta>", + "Adjust your dexterity"_s}}, + {"luk"_s, {"<delta>"_s, 60, atcommand_param<ATTR::LUK>, - "Adjust your luck"}}, - {"recall", {"<charname>", + "Adjust your luck"_s}}, + {"recall"_s, {"<charname>"_s, 60, atcommand_recall, - "Warp a player to you"}}, - {"revive", {"<charname>", + "Warp a player to you"_s}}, + {"revive"_s, {"<charname>"_s, 60, atcommand_revive, - "Restore a player to full health"}}, - {"charstats", {"<charname>", + "Restore a player to full health"_s}}, + {"charstats"_s, {"<charname>"_s, 40, atcommand_character_stats, - "Show a bunch of stats about a single user"}}, - {"charstatsall", {"", + "Show a bunch of stats about a single user"_s}}, + {"charstatsall"_s, {""_s, 60, atcommand_character_stats_all, - "Show a bunch of stats about all online users"}}, - {"charoption", {"<opt1> <opt2> <opt3> <charname>", + "Show a bunch of stats about all online users"_s}}, + {"charoption"_s, {"<opt1> <opt2> <opt3> <charname>"_s, 80, atcommand_character_option, - "Set option flags on another character"}}, - {"charsave", {"<map> <x> <y> <charname>", + "Set option flags on another character"_s}}, + {"charsave"_s, {"<map> <x> <y> <charname>"_s, 60, atcommand_character_save, - "Set another character's save point"}}, - {"doom", {"", + "Set another character's save point"_s}}, + {"doom"_s, {""_s, 80, atcommand_doom, - "Kill everyone on the server"}}, - {"doommap", {"", + "Kill everyone on the server"_s}}, + {"doommap"_s, {""_s, 80, atcommand_doommap, - "Kill everyone on your map"}}, - {"raise", {"", + "Kill everyone on your map"_s}}, + {"raise"_s, {""_s, 80, atcommand_raise, - "Resurrect all players on the server"}}, - {"raisemap", {"", + "Resurrect all players on the server"_s}}, + {"raisemap"_s, {""_s, 80, atcommand_raisemap, - "Resurrect all players on your map"}}, - {"charbaselvl", {"<delta> <charname>", + "Resurrect all players on your map"_s}}, + {"charbaselvl"_s, {"<delta> <charname>"_s, 60, atcommand_character_baselevel, - "Adjust another character's level"}}, - {"charjlvl", {"<delta> <charname>", + "Adjust another character's level"_s}}, + {"charjlvl"_s, {"<delta> <charname>"_s, 60, atcommand_character_joblevel, - "Adjust another character's job level"}}, - {"kick", {"<charname>", + "Adjust another character's job level"_s}}, + {"kick"_s, {"<charname>"_s, 40, atcommand_kick, - "Transiently kick a player off the server"}}, - {"kickall", {"", + "Transiently kick a player off the server"_s}}, + {"kickall"_s, {""_s, 99, atcommand_kickall, - "Transiently kick all players off the server"}}, - {"questskill", {"<skill-id>", + "Transiently kick all players off the server"_s}}, + {"questskill"_s, {"<skill-id>"_s, 99, atcommand_questskill, - "Give yourself a quest (?) skill"}}, - {"charquestskill", {"<skill-id> <charname>", + "Give yourself a quest (?) skill"_s}}, + {"charquestskill"_s, {"<skill-id> <charname>"_s, 99, atcommand_charquestskill, - "Give another player a quest (?) skill"}}, - {"lostskill", {"<skill-id>", + "Give another player a quest (?) skill"_s}}, + {"lostskill"_s, {"<skill-id>"_s, 80, atcommand_lostskill, - "Take away one of your quest (?) skills"}}, - {"charlostskill", {"<skill-id> <charname>", + "Take away one of your quest (?) skills"_s}}, + {"charlostskill"_s, {"<skill-id> <charname>"_s, 99, atcommand_charlostskill, - "Take away one of another player's quest (?) skills"}}, - {"party", {"<name>", + "Take away one of another player's quest (?) skills"_s}}, + {"party"_s, {"<name>"_s, 99, atcommand_party, - "Create a new party"}}, - {"mapexit", {"", + "Create a new party"_s}}, + {"mapexit"_s, {""_s, 99, atcommand_mapexit, - "Try to kill the server kindly"}}, - {"idsearch", {"<item-subseq>", + "Try to kill the server kindly"_s}}, + {"idsearch"_s, {"<item-subseq>"_s, 80, atcommand_idsearch, - "Search for some items that might match"}}, - {"mapmove", {"<mapname> [x] [y]", + "Search for some items that might match"_s}}, + {"mapmove"_s, {"<mapname> [x] [y]"_s, 40, atcommand_warp, - "Warp to a different map"}}, - {"broadcast", {"<message ...>", + "Warp to a different map"_s}}, + {"broadcast"_s, {"<message ...>"_s, 40, atcommand_broadcast, - "Broadcast a message from you"}}, - {"localbroadcast", {"<message ...>", + "Broadcast a message from you"_s}}, + {"localbroadcast"_s, {"<message ...>"_s, 40, atcommand_localbroadcast, - "Broadcast a message from you locally"}}, - {"recallall", {"", + "Broadcast a message from you locally"_s}}, + {"recallall"_s, {""_s, 80, atcommand_recallall, - "Warp every online player to your current map"}}, - {"charskreset", {"<charname>", + "Warp every online player to your current map"_s}}, + {"charskreset"_s, {"<charname>"_s, 60, atcommand_charskreset, - "Reset a player's skill points"}}, - {"charstreset", {"<charname>", + "Reset a player's skill points"_s}}, + {"charstreset"_s, {"<charname>"_s, 60, atcommand_charstreset, - "Reset a player's stat points"}}, - {"charreset", {"<charname>", + "Reset a player's stat points"_s}}, + {"charreset"_s, {"<charname>"_s, 60, atcommand_charreset, - "Reset a player's skills, stats, and magic"}}, - {"charmodel", {"<hairstyle> <hair-color> <dye> <charname>", + "Reset a player's skills, stats, and magic"_s}}, + {"charmodel"_s, {"<hairstyle> <hair-color> <dye> <charname>"_s, 99, atcommand_charmodel, - "Change another character's appearance"}}, - {"charskpoint", {"<amount> <charname>", + "Change another character's appearance"_s}}, + {"charskpoint"_s, {"<amount> <charname>"_s, 60, atcommand_charskpoint, - "Adjust another player's skill points"}}, - {"charstpoint", {"<amount> <charname>", + "Adjust another player's skill points"_s}}, + {"charstpoint"_s, {"<amount> <charname>"_s, 60, atcommand_charstpoint, - "Adjust another player's stat points"}}, - {"charzeny", {"<delta> <charname>", + "Adjust another player's stat points"_s}}, + {"charzeny"_s, {"<delta> <charname>"_s, 80, atcommand_charzeny, - "Adjust another player's money"}}, - {"mapinfo", {"<0-2> [map]", + "Adjust another player's money"_s}}, + {"mapinfo"_s, {"<0-2> [map]"_s, 99, atcommand_mapinfo, - "Show some stats for the map. 1 also shows players, 2 also shows NPCs"}}, - {"dye", {"<dye>", + "Show some stats for the map. 1 also shows players, 2 also shows NPCs"_s}}, + {"dye"_s, {"<dye>"_s, 40, atcommand_dye, - "Don't use"}}, - {"ccolor", {"<dye>", + "Don't use"_s}}, + {"ccolor"_s, {"<dye>"_s, 40, atcommand_dye, - "Don't use"}}, - {"hairstyle", {"<style>", + "Don't use"_s}}, + {"hairstyle"_s, {"<style>"_s, 40, atcommand_hair_style, - "Change your hairstyle"}}, - {"haircolor", {"<color>", + "Change your hairstyle"_s}}, + {"haircolor"_s, {"<color>"_s, 40, atcommand_hair_color, - "Change your hair color"}}, - {"allstats", {"[value]", + "Change your hair color"_s}}, + {"allstats"_s, {"[value]"_s, 60, atcommand_all_stats, - "Adjust all stats by value (or maximum)"}}, - {"charchangesex", {"<charname>", + "Adjust all stats by value (or maximum)"_s}}, + {"charchangesex"_s, {"<charname>"_s, 60, atcommand_char_change_sex, - "Flip a characters sex and disconnect them"}}, - {"block", {"<charname>", + "Flip a characters sex and disconnect them"_s}}, + {"block"_s, {"<charname>"_s, 60, atcommand_char_block, - "Permanently block a player's account from the server"}}, - {"unblock", {"<charname>", + "Permanently block a player's account from the server"_s}}, + {"unblock"_s, {"<charname>"_s, 60, atcommand_char_unblock, - "Remove a permanent block from a player's account"}}, - {"ban", {"<timedelta> <charname>", + "Remove a permanent block from a player's account"_s}}, + {"ban"_s, {"<timedelta> <charname>"_s, 60, atcommand_char_ban, - "Ban a player's account from the server for a limited time"}}, - {"unban", {"<timedelta> <charname>", + "Ban a player's account from the server for a limited time"_s}}, + {"unban"_s, {"<timedelta> <charname>"_s, 60, atcommand_char_unban, - "Remove a limited ban from a player's account"}}, - {"partyspy", {"<party-name-or-id>", + "Remove a limited ban from a player's account"_s}}, + {"partyspy"_s, {"<party-name-or-id>"_s, 99, atcommand_partyspy, - "Listen to all chat within a party"}}, - {"partyrecall", {"<party-name-or-id>", + "Listen to all chat within a party"_s}}, + {"partyrecall"_s, {"<party-name-or-id>"_s, 99, atcommand_partyrecall, - "Warp all members of a party to you"}}, - {"enablenpc", {"<npc-name>", + "Warp all members of a party to you"_s}}, + {"enablenpc"_s, {"<npc-name>"_s, 80, atcommand_enablenpc, - "Enable an NPC for visibility"}}, - {"disablenpc", {"<npc-name>", + "Enable an NPC for visibility"_s}}, + {"disablenpc"_s, {"<npc-name>"_s, 80, atcommand_disablenpc, - "Disable an NPC for visibility"}}, - {"servertime", {"", + "Disable an NPC for visibility"_s}}, + {"servertime"_s, {""_s, 0, atcommand_servertime, - "Print the server's idea of the current time"}}, - {"chardelitem", {"<item-name-or-id> <count> <charname>", + "Print the server's idea of the current time"_s}}, + {"chardelitem"_s, {"<item-name-or-id> <count> <charname>"_s, 60, atcommand_chardelitem, - "Delete items from a player's inventory"}}, - {"listnearby", {"", + "Delete items from a player's inventory"_s}}, + {"listnearby"_s, {""_s, 40, atcommand_list_nearby, - "Print name of all nearby players"}}, - {"email", {"<actual@email> <new@email>", + "Print name of all nearby players"_s}}, + {"email"_s, {"<actual@email> <new@email>"_s, 0, atcommand_email, - "Changed your account's email"}}, - {"effect", {"<type> <flag>", + "Changed your account's email"_s}}, + {"effect"_s, {"<type> <flag>"_s, 99, atcommand_effect, - "Apply a special effect to yourself (or everyone! wtf?)"}}, - {"charitemlist", {"<charname>", + "Apply a special effect to yourself (or everyone! wtf?)"_s}}, + {"charitemlist"_s, {"<charname>"_s, 99, atcommand_character_item_list, - "List a player's items"}}, - {"charstoragelist", {"<charname>", + "List a player's items"_s}}, + {"charstoragelist"_s, {"<charname>"_s, 99, atcommand_character_storage_list, - "List a player's storage"}}, - {"addwarp", {"<mapname> <x> <y>", + "List a player's storage"_s}}, + {"addwarp"_s, {"<mapname> <x> <y>"_s, 80, atcommand_addwarp, - "Create a new permanent warp"}}, - {"killer", {"", + "Create a new permanent warp"_s}}, + {"killer"_s, {""_s, 60, atcommand_killer, - "Toggle whether you are a killer"}}, - {"charkiller", {"<charname>", + "Toggle whether you are a killer"_s}}, + {"charkiller"_s, {"<charname>"_s, 60, atcommand_charkiller, - "Toggle whether a player is a killer"}}, - {"npcmove", {"<x> <y> <npc-name>", + "Toggle whether a player is a killer"_s}}, + {"npcmove"_s, {"<x> <y> <npc-name>"_s, 80, atcommand_npcmove, - "Force an NPC to move on the map"}}, - {"killable", {"", + "Force an NPC to move on the map"_s}}, + {"killable"_s, {""_s, 60, atcommand_killable, - "Toggle whether you are killable"}}, - {"charkillable", {"<charname>", + "Toggle whether you are killable"_s}}, + {"charkillable"_s, {"<charname>"_s, 60, atcommand_charkillable, - "Toggle whether a player is killable"}}, - {"chareffect", {"<type> <target>", + "Toggle whether a player is killable"_s}}, + {"chareffect"_s, {"<type> <target>"_s, 40, atcommand_chareffect, - "Apply effect type with arg 0 to a player"}}, - {"dropall", {"", + "Apply effect type with arg 0 to a player"_s}}, + {"dropall"_s, {""_s, 99, atcommand_dropall, - "Drop all of your items"}}, - {"chardropall", {"<charname>", + "Drop all of your items"_s}}, + {"chardropall"_s, {"<charname>"_s, 60, atcommand_chardropall, - "Force a player to drop all of their items"}}, - {"storeall", {"", + "Force a player to drop all of their items"_s}}, + {"storeall"_s, {""_s, 60, atcommand_storeall, - "Store all of your items"}}, - {"charstoreall", {"<charname>", + "Store all of your items"_s}}, + {"charstoreall"_s, {"<charname>"_s, 60, atcommand_charstoreall, - "Store all of a player's items"}}, - {"rain", {"", + "Store all of a player's items"_s}}, + {"rain"_s, {""_s, 99, atcommand_rain, - "Enable the rain mapflag"}}, - {"snow", {"", + "Enable the rain mapflag"_s}}, + {"snow"_s, {""_s, 99, atcommand_snow, - "Enable the snow mapflag"}}, - {"sakura", {"", + "Enable the snow mapflag"_s}}, + {"sakura"_s, {""_s, 99, atcommand_sakura, - "Enable the sakura mapflag"}}, - {"fog", {"", + "Enable the sakura mapflag"_s}}, + {"fog"_s, {""_s, 99, atcommand_fog, - "Enable the fog mapflag"}}, - {"leaves", {"", + "Enable the fog mapflag"_s}}, + {"leaves"_s, {""_s, 99, atcommand_leaves, - "Enable the leaves mapflag"}}, - {"summon", {"<mob-id-or-name>", + "Enable the leaves mapflag"_s}}, + {"summon"_s, {"<mob-id-or-name>"_s, 50, atcommand_summon, - "Summon a slave monster temporarily"}}, - {"adjgmlvl", {"<level> <cmd>", + "Summon a slave monster temporarily"_s}}, + {"adjgmlvl"_s, {"<level> <cmd>"_s, 99, atcommand_adjgmlvl, - "Temporarily adjust the GM level of a command"}}, - {"adjcmdlvl", {"<level> <charname>", + "Temporarily adjust the GM level of a command"_s}}, + {"adjcmdlvl"_s, {"<level> <charname>"_s, 99, atcommand_adjcmdlvl, - "Temporarily adjust the GM level of a player"}}, - {"trade", {"<charname>", + "Temporarily adjust the GM level of a player"_s}}, + {"trade"_s, {"<charname>"_s, 60, atcommand_trade, - "Initiate trade with a player anywhere"}}, - {"charwipe", {"<charname>", + "Initiate trade with a player anywhere"_s}}, + {"charwipe"_s, {"<charname>"_s, 60, atcommand_char_wipe, - "Reset a character almost completely"}}, - {"setmagic", {"<school> <value> <charname>", + "Reset a character almost completely"_s}}, + {"setmagic"_s, {"<school> <value> <charname>"_s, 80, atcommand_set_magic, - "Force magic skill level"}}, - {"magicinfo", {"<charname>", + "Force magic skill level"_s}}, + {"magicinfo"_s, {"<charname>"_s, 80, atcommand_magic_info, - "Show magic skills of a palyer"}}, - {"log", {"<message ...>", + "Show magic skills of a palyer"_s}}, + {"log"_s, {"<message ...>"_s, 40, atcommand_log, - "Write something directly to the log"}}, - {"l", {"<message ...>", + "Write something directly to the log"_s}}, + {"l"_s, {"<message ...>"_s, 40, atcommand_log, - "Write something directly to the log"}}, - {"tee", {"<message ...>", + "Write something directly to the log"_s}}, + {"tee"_s, {"<message ...>"_s, 40, atcommand_tee, - "Duplicate a message to the log and public chat"}}, - {"t", {"<message ...>", + "Duplicate a message to the log and public chat"_s}}, + {"t"_s, {"<message ...>"_s, 40, atcommand_tee, - "Duplicate a message to the log and public chat"}}, - {"invisible", {"", + "Duplicate a message to the log and public chat"_s}}, + {"invisible"_s, {""_s, 50, atcommand_invisible, - "Make yourself invisible to players"}}, - {"visible", {"", + "Make yourself invisible to players"_s}}, + {"visible"_s, {""_s, 50, atcommand_visible, - "Make yourself visible to players"}}, - {"hugo", {"", + "Make yourself visible to players"_s}}, + {"hugo"_s, {""_s, 60, atcommand_iterate_forward_over_players, - "Jump to the next player"}}, - {"linus", {"", + "Jump to the next player"_s}}, + {"linus"_s, {""_s, 60, atcommand_iterate_backwards_over_players, - "Jump to the previous player"}}, - {"sp-info", {"<charname>", + "Jump to the previous player"_s}}, + {"sp-info"_s, {"<charname>"_s, 40, atcommand_skillpool_info, - "Show info about pool skills"}}, - {"sp-focus", {"<skill-id> <charname>", + "Show info about pool skills"_s}}, + {"sp-focus"_s, {"<skill-id> <charname>"_s, 80, atcommand_skillpool_focus, - "Focus on a pool skill"}}, - {"sp-unfocus", {"<skill-id> <charname>", + "Focus on a pool skill"_s}}, + {"sp-unfocus"_s, {"<skill-id> <charname>"_s, 80, atcommand_skillpool_unfocus, - "Unfocus off of a pool skill"}}, - {"skill-learn", {"<skill-id> <level> <charname>", + "Unfocus off of a pool skill"_s}}, + {"skill-learn"_s, {"<skill-id> <level> <charname>"_s, 80, atcommand_skill_learn, - "Change a skill level"}}, - {"wgm", {"<message ...>", + "Change a skill level"_s}}, + {"wgm"_s, {"<message ...>"_s, 0, atcommand_wgm, - "Send a message to online GMs"}}, - {"ipcheck", {"<charname>", + "Send a message to online GMs"_s}}, + {"ipcheck"_s, {"<charname>"_s, 60, atcommand_ipcheck, - "List players on the same IP address"}}, - {"doomspot", {"", + "List players on the same IP address"_s}}, + {"doomspot"_s, {""_s, 60, atcommand_doomspot, - "Kill all players on the same tile"}}, - {"source", {"", + "Kill all players on the same tile"_s}}, + {"source"_s, {""_s, 0, atcommand_source, - "Legal information about source code (must be a level 0 command!)"}}, + "Legal information about source code (must be a level 0 command!)"_s}}, }; diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 8e4d435..f67414f 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -1965,7 +1965,7 @@ struct Damage battle_calc_attack(BF attack_type, flag); default: if (battle_config.error_log) - PRINTF("battle_calc_attack: unknwon attack type ! %d\n", + PRINTF("battle_calc_attack: unknwon attack type ! %d\n"_fmt, attack_type); break; } @@ -2040,7 +2040,7 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, wd.damage -= reduction; MAP_LOG_PC(target->is_player(), - "MAGIC-ABSORB-DMG %d", reduction); + "MAGIC-ABSORB-DMG %d"_fmt, reduction); } { @@ -2064,9 +2064,9 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON)) weapon = sd->inventory_data[weapon_index]->nameid; - MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d", + MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d"_fmt, sd->status_key.char_id, src->bl_m->name_, src->bl_x, src->bl_y, - (target->bl_type == BL::PC) ? "PC" : "MOB", + (target->bl_type == BL::PC) ? "PC"_s : "MOB"_s, (target->bl_type == BL::PC) ? target->is_player()-> status_key.char_id : target->bl_id, @@ -2077,9 +2077,9 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, if (target->bl_type == BL::PC) { dumb_ptr<map_session_data> sd2 = target->is_player(); - MAP_LOG("PC%d %s:%d,%d WPNINJURY %s%d %d FOR %d", + MAP_LOG("PC%d %s:%d,%d WPNINJURY %s%d %d FOR %d"_fmt, sd2->status_key.char_id, target->bl_m->name_, target->bl_x, target->bl_y, - (src->bl_type == BL::PC) ? "PC" : "MOB", + (src->bl_type == BL::PC) ? "PC"_s : "MOB"_s, (src->bl_type == BL::PC) ? src->is_player()->status_key.char_id : src->bl_id, @@ -2246,9 +2246,6 @@ int battle_check_target(dumb_ptr<block_list> src, dumb_ptr<block_list> target, return 0; } -//PRINTF("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->bl_id,src->bl_id,target->bl_id,flag,src->bl_type,target->bl_type); -//PRINTF("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g); - if (ss->bl_type == BL::PC && target->bl_type == BL::PC) { // 両方PVPモードなら否定(敵) if (ss->bl_m->flag.get(MapFlag::PVP) @@ -2430,17 +2427,17 @@ bool battle_config_read(ZString cfgName) io::ReadFile in(cfgName); if (!in.is_open()) { - PRINTF("file not found: %s\n", cfgName); + PRINTF("file not found: %s\n"_fmt, cfgName); return false; } AString line; while (in.getline(line)) { -#define BATTLE_CONFIG_VAR(name) {{#name}, &battle_config.name} +#define BATTLE_CONFIG_VAR(name) {#name##_s, &battle_config.name} const struct { - ZString str; + LString str; int *val; } data[] = { @@ -2550,12 +2547,12 @@ bool battle_config_read(ZString cfgName) ZString w2; if (!config_split(line, &w1, &w2)) { - PRINTF("Bad config line: %s\n", line); + PRINTF("Bad config line: %s\n"_fmt, line); rv = false; continue; } - if (w1 == "import") + if (w1 == "import"_s) { battle_config_read(w2); continue; @@ -2568,7 +2565,7 @@ bool battle_config_read(ZString cfgName) goto continue_outer; } - PRINTF("WARNING: unknown battle conf key: %s\n", AString(w1)); + PRINTF("WARNING: unknown battle conf key: %s\n"_fmt, AString(w1)); rv = false; continue_outer: diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 9a70d63..04e82ca 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -209,7 +209,7 @@ int chrif_recvmap(Session *s) map_setipport(map, ip, port); } if (battle_config.etc_log) - PRINTF("recv map on %s:%d (%d maps)\n", + PRINTF("recv map on %s:%d (%d maps)\n"_fmt, ip, port, j); return 0; @@ -270,7 +270,7 @@ int chrif_changemapserverack(Session *s) if (RFIFOL(s, 6) == 1) { if (battle_config.error_log) - PRINTF("map server change failed.\n"); + PRINTF("map server change failed.\n"_fmt); pc_authfail(sd->status_key.account_id); return 0; } @@ -293,21 +293,18 @@ int chrif_connectack(Session *s) { if (RFIFOB(s, 2)) { - PRINTF("Connected to char-server failed %d.\n", RFIFOB(s, 2)); + PRINTF("Connected to char-server failed %d.\n"_fmt, RFIFOB(s, 2)); exit(1); } - PRINTF("Connected to char-server (connection #%d).\n", s); + PRINTF("Connected to char-server (connection #%d).\n"_fmt, s); chrif_state = 1; chrif_sendmap(s); - PRINTF("chrif: OnCharIfInit event done. (%d events)\n", - npc_event_doall(stringish<ScriptLabel>("OnCharIfInit"))); - PRINTF("chrif: OnInterIfInit event done. (%d events)\n", - npc_event_doall(stringish<ScriptLabel>("OnInterIfInit"))); - - // <Agit> Run Event [AgitInit] -// PRINTF("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit")); + PRINTF("chrif: OnCharIfInit event done. (%d events)\n"_fmt, + npc_event_doall(stringish<ScriptLabel>("OnCharIfInit"_s))); + PRINTF("chrif: OnInterIfInit event done. (%d events)\n"_fmt, + npc_event_doall(stringish<ScriptLabel>("OnInterIfInit"_s))); return 0; } @@ -321,7 +318,7 @@ int chrif_sendmapack(Session *s) { if (RFIFOB(s, 2)) { - PRINTF("chrif : send map list to char server failed %d\n", + PRINTF("chrif : send map list to char server failed %d\n"_fmt, RFIFOB(s, 2)); exit(1); } @@ -408,7 +405,7 @@ int chrif_charselectreq(dumb_ptr<map_session_data> sd) void chrif_changegm(int id, ZString pass) { if (battle_config.etc_log) - PRINTF("chrif_changegm: account: %d, password: '%s'.\n", id, pass); + PRINTF("chrif_changegm: account: %d, password: '%s'.\n"_fmt, id, pass); size_t len = pass.size() + 1; WFIFOW(char_session, 0) = 0x2b0a; @@ -426,7 +423,7 @@ void chrif_changeemail(int id, AccountEmail actual_email, AccountEmail new_email) { if (battle_config.etc_log) - PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n", + PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n"_fmt, id, actual_email, new_email); WFIFOW(char_session, 0) = 0x2b0c; @@ -456,7 +453,7 @@ void chrif_char_ask_name(int id, CharName character_name, short operation_type, WFIFOW(char_session, 30) = operation_type; // type of operation if (operation_type == 2) WFIFO_STRUCT(char_session, 32, modif); - PRINTF("chrif : sended 0x2b0e\n"); + PRINTF("chrif : sended 0x2b0e\n"_fmt); WFIFOSET(char_session, 44); } @@ -487,7 +484,7 @@ int chrif_char_ask_name_answer(Session *s) { AString output; if (RFIFOW(s, 32) == 1) // player not found - output = STRPRINTF("The player '%s' doesn't exist.", + output = STRPRINTF("The player '%s' doesn't exist."_fmt, player_name); else { @@ -498,18 +495,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to block the player '%s'.", + "Login-server has been asked to block the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to block the player '%s'.", + "Your GM level don't authorise you to block the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to block the the player '%s'.", + "Login-server is offline. Impossible to block the the player '%s'."_fmt, player_name); break; } @@ -519,18 +516,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to ban the player '%s'.", + "Login-server has been asked to ban the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to ban the player '%s'.", + "Your GM level don't authorise you to ban the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to ban the the player '%s'.", + "Login-server is offline. Impossible to ban the the player '%s'."_fmt, player_name); break; } @@ -540,18 +537,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to unblock the player '%s'.", + "Login-server has been asked to unblock the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to unblock the player '%s'.", + "Your GM level don't authorise you to unblock the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to unblock the the player '%s'.", + "Login-server is offline. Impossible to unblock the the player '%s'."_fmt, player_name); break; } @@ -561,18 +558,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to unban the player '%s'.", + "Login-server has been asked to unban the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to unban the player '%s'.", + "Your GM level don't authorise you to unban the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to unban the the player '%s'.", + "Login-server is offline. Impossible to unban the the player '%s'."_fmt, player_name); break; } @@ -582,18 +579,18 @@ int chrif_char_ask_name_answer(Session *s) { case 0: // login-server resquest done output = STRPRINTF( - "Login-server has been asked to change the sex of the player '%s'.", + "Login-server has been asked to change the sex of the player '%s'."_fmt, player_name); break; //case 1: // player not found case 2: // gm level too low output = STRPRINTF( - "Your GM level don't authorise you to change the sex of the player '%s'.", + "Your GM level don't authorise you to change the sex of the player '%s'."_fmt, player_name); break; case 3: // login-server offline output = STRPRINTF( - "Login-server is offline. Impossible to change the sex of the the player '%s'.", + "Login-server is offline. Impossible to change the sex of the the player '%s'."_fmt, player_name); break; } @@ -604,7 +601,7 @@ int chrif_char_ask_name_answer(Session *s) clif_displaymessage(sd->sess, output); } else - PRINTF("chrif_char_ask_name_answer failed - player not online.\n"); + PRINTF("chrif_char_ask_name_answer failed - player not online.\n"_fmt); return 0; } @@ -625,14 +622,14 @@ void chrif_changedgm(Session *s) sd = map_id2sd(acc); if (battle_config.etc_log) - PRINTF("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc, + PRINTF("chrif_changedgm: account: %d, GM level 0 -> %d.\n"_fmt, acc, level); if (sd != NULL) { if (level > 0) - clif_displaymessage(sd->sess, "GM modification success."); + clif_displaymessage(sd->sess, "GM modification success."_s); else - clif_displaymessage(sd->sess, "Failure of GM modification."); + clif_displaymessage(sd->sess, "Failure of GM modification."_s); } } @@ -649,7 +646,7 @@ void chrif_changedsex(Session *s) acc = RFIFOL(s, 2); SEX sex = static_cast<SEX>(RFIFOB(s, 6)); if (battle_config.etc_log) - PRINTF("chrif_changedsex %d.\n", acc); + PRINTF("chrif_changedsex %d.\n"_fmt, acc); sd = map_id2sd(acc); if (acc > 0) { @@ -671,7 +668,7 @@ void chrif_changedsex(Session *s) sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters // do same modify in login-server for the account, but no in char-server (it ask again login_id1 to login, and don't remember it) clif_displaymessage(sd->sess, - "Your sex has been changed (need disconexion by the server)..."); + "Your sex has been changed (need disconexion by the server)..."_s); clif_setwaitclose(sd->sess); // forced to disconnect for the change } } @@ -679,7 +676,7 @@ void chrif_changedsex(Session *s) { if (sd != NULL) { - PRINTF("chrif_changedsex failed.\n"); + PRINTF("chrif_changedsex failed.\n"_fmt); } } } @@ -797,7 +794,7 @@ int chrif_accountdeletion(Session *s) acc = RFIFOL(s, 2); if (battle_config.etc_log) - PRINTF("chrif_accountdeletion %d.\n", acc); + PRINTF("chrif_accountdeletion %d.\n"_fmt, acc); sd = map_id2sd(acc); if (acc > 0) { @@ -805,14 +802,14 @@ int chrif_accountdeletion(Session *s) { sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters clif_displaymessage(sd->sess, - "Your account has been deleted (disconnection)..."); + "Your account has been deleted (disconnection)..."_s); clif_setwaitclose(sd->sess); // forced to disconnect for the change } } else { if (sd != NULL) - PRINTF("chrif_accountdeletion failed - player not online.\n"); + PRINTF("chrif_accountdeletion failed - player not online.\n"_fmt); } return 0; @@ -830,7 +827,7 @@ int chrif_accountban(Session *s) acc = RFIFOL(s, 2); if (battle_config.etc_log) - PRINTF("chrif_accountban %d.\n", acc); + PRINTF("chrif_accountban %d.\n"_fmt, acc); sd = map_id2sd(acc); if (acc > 0) { @@ -843,57 +840,58 @@ int chrif_accountban(Session *s) { // status or final date of a banishment case 1: // 0 = Unregistered ID clif_displaymessage(sd->sess, - "Your account has 'Unregistered'."); + "Your account has 'Unregistered'."_s); break; case 2: // 1 = Incorrect Password clif_displaymessage(sd->sess, - "Your account has an 'Incorrect Password'..."); + "Your account has an 'Incorrect Password'..."_s); break; case 3: // 2 = This ID is expired clif_displaymessage(sd->sess, - "Your account has expired."); + "Your account has expired."_s); break; case 4: // 3 = Rejected from Server clif_displaymessage(sd->sess, - "Your account has been rejected from server."); + "Your account has been rejected from server."_s); break; case 5: // 4 = You have been blocked by the GM Team clif_displaymessage(sd->sess, - "Your account has been blocked by the GM Team."); + "Your account has been blocked by the GM Team."_s); break; case 6: // 5 = Your Game's EXE file is not the latest version clif_displaymessage(sd->sess, - "Your Game's EXE file is not the latest version."); + "Your Game's EXE file is not the latest version."_s); break; case 7: // 6 = Your are Prohibited to log in until %s clif_displaymessage(sd->sess, - "Your account has been prohibited to log in."); + "Your account has been prohibited to log in."_s); break; case 8: // 7 = Server is jammed due to over populated clif_displaymessage(sd->sess, - "Server is jammed due to over populated."); + "Server is jammed due to over populated."_s); break; case 9: // 8 = No MSG (actually, all states after 9 except 99 are No MSG, use only this) clif_displaymessage(sd->sess, - "Your account has not more authorised."); + "Your account has not more authorised."_s); break; case 100: // 99 = This ID has been totally erased clif_displaymessage(sd->sess, - "Your account has been totally erased."); + "Your account has been totally erased."_s); break; default: clif_displaymessage(sd->sess, - "Your account has not more authorised."); + "Your account has not more authorised."_s); break; } } else if (RFIFOB(s, 6) == 1) { // 0: change of statut, 1: ban - TimeT timestamp = static_cast<time_t>(RFIFOL(s, 7)); // status or final date of a banishment - char tmpstr[] = WITH_TIMESTAMP("Your account has been banished until "); - REPLACE_TIMESTAMP(tmpstr, timestamp); - clif_displaymessage(sd->sess, const_(tmpstr)); + const TimeT timestamp = static_cast<time_t>(RFIFOL(s, 7)); // status or final date of a banishment + timestamp_seconds_buffer buffer; + stamp_time(buffer, ×tamp); + AString tmpstr = STRPRINTF("Your account has been banished until %s"_fmt, buffer); + clif_displaymessage(sd->sess, tmpstr); } clif_setwaitclose(sd->sess); // forced to disconnect for the change } @@ -901,7 +899,7 @@ int chrif_accountban(Session *s) else { if (sd != NULL) - PRINTF("chrif_accountban failed - player not online.\n"); + PRINTF("chrif_accountban failed - player not online.\n"_fmt); } return 0; @@ -914,7 +912,7 @@ int chrif_accountban(Session *s) static int chrif_recvgmaccounts(Session *s) { - PRINTF("From login-server: receiving of %d GM accounts information.\n", + PRINTF("From login-server: receiving of %d GM accounts information.\n"_fmt, pc_read_gm_account(s)); return 0; @@ -1052,7 +1050,7 @@ void chrif_parse(Session *s) { if (s == char_session) { - PRINTF("Map-server can't connect to char-server (connection #%d).\n", + PRINTF("Map-server can't connect to char-server (connection #%d).\n"_fmt, s); char_session = nullptr; } @@ -1158,7 +1156,7 @@ void chrif_parse(Session *s) default: if (battle_config.error_log) - PRINTF("chrif_parse : unknown packet %d %d\n", s, + PRINTF("chrif_parse : unknown packet %d %d\n"_fmt, s, RFIFOW(s, 0)); s->eof = 1; return; @@ -1211,7 +1209,7 @@ void check_connect_char_server(TimerData *, tick_t) { if (!char_session) { - PRINTF("Attempt to connect to char-server...\n"); + PRINTF("Attempt to connect to char-server...\n"_fmt); chrif_state = 0; char_session = make_connection(char_ip, char_port); if (!char_session) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index a7dcb52..2eae52b 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -464,7 +464,7 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type default: if (battle_config.error_log) - PRINTF("clif_send まだ作ってないよー\n"); + PRINTF("clif_send まだ作ってないよー\n"_fmt); return -1; } @@ -1770,7 +1770,7 @@ int clif_updatestatus(dumb_ptr<map_session_data> sd, SP type) default: if (battle_config.error_log) - PRINTF("clif_updatestatus : make %d routine\n", + PRINTF("clif_updatestatus : make %d routine\n"_fmt, type); return 1; } @@ -2557,7 +2557,7 @@ void clif_getareachar(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> sd) break; default: if (battle_config.error_log) - PRINTF("get area char ??? %d\n", + PRINTF("get area char ??? %d\n"_fmt, bl->bl_type); break; } @@ -3070,8 +3070,6 @@ void clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag) nullpo_retv(p); -// if(battle_config.etc_log) -// PRINTF("clif_party_option: %d %d %d\n",p->exp,p->item,flag); if (sd == NULL && flag == 0) { int i; @@ -3174,8 +3172,6 @@ int clif_party_xy(struct party *, dumb_ptr<map_session_data> sd) WBUFW(buf, 6) = sd->bl_x; WBUFW(buf, 8) = sd->bl_y; clif_send(buf, clif_parse_func_table[0x107].len, sd, SendWho::PARTY_SAMEMAP_WOS); -// if(battle_config.etc_log) -// PRINTF("clif_party_xy %d\n",sd->status_key.account_id); return 0; } @@ -3195,8 +3191,6 @@ int clif_party_hp(struct party *, dumb_ptr<map_session_data> sd) WBUFW(buf, 8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp; clif_send(buf, clif_parse_func_table[0x106].len, sd, SendWho::PARTY_AREA_WOS); -// if(battle_config.etc_log) -// PRINTF("clif_party_hp %d\n",sd->status_key.account_id); return 0; } @@ -3374,7 +3368,7 @@ void clif_parse_WantToConnection(Session *s, dumb_ptr<map_session_data> sd) if (sd) { if (battle_config.error_log) - PRINTF("clif_parse_WantToConnection : invalid request?\n"); + PRINTF("clif_parse_WantToConnection : invalid request?\n"_fmt); return; } @@ -3394,7 +3388,7 @@ void clif_parse_WantToConnection(Session *s, dumb_ptr<map_session_data> sd) { clif_authfail_fd(s, 2); // same id clif_authfail_fd(old_sd->sess, 2); // same id - PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n", + PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n"_fmt, account_id, s, old_sd->sess); } else @@ -3623,7 +3617,7 @@ void clif_parse_GetCharNameRequest(Session *s, dumb_ptr<map_session_data> sd) nullpo_retv(ssd); if (ssd->state.shroud_active) - WFIFO_STRING(s, 6, "", 24); + WFIFO_STRING(s, 6, ""_s, 24); else WFIFO_STRING(s, 6, ssd->status_key.name.to__actual(), 24); WFIFOSET(s, clif_parse_func_table[0x95].len); @@ -3645,9 +3639,9 @@ void clif_parse_GetCharNameRequest(Session *s, dumb_ptr<map_session_data> sd) WFIFOW(s, 0) = 0x195; WFIFOL(s, 2) = account_id; WFIFO_STRING(s, 6, party_name, 24); - WFIFO_STRING(s, 30, "", 24); - WFIFO_STRING(s, 54, "", 24); - WFIFO_STRING(s, 78, "", 24); // We send this value twice because the client expects it + WFIFO_STRING(s, 30, ""_s, 24); + WFIFO_STRING(s, 54, ""_s, 24); + WFIFO_STRING(s, 78, ""_s, 24); // We send this value twice because the client expects it WFIFOSET(s, clif_parse_func_table[0x195].len); } @@ -3689,7 +3683,7 @@ void clif_parse_GetCharNameRequest(Session *s, dumb_ptr<map_session_data> sd) break; default: if (battle_config.error_log) - PRINTF("clif_parse_GetCharNameRequest : bad type %d (%d)\n", + PRINTF("clif_parse_GetCharNameRequest : bad type %d (%d)\n"_fmt, bl->bl_type, account_id); break; } @@ -3710,7 +3704,7 @@ void clif_parse_GlobalMessage(Session *s, dumb_ptr<map_session_data> sd) AString mbuf = clif_validate_chat(sd, ChatType::Global); if (!mbuf) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -3722,7 +3716,7 @@ void clif_parse_GlobalMessage(Session *s, dumb_ptr<map_session_data> sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -3975,7 +3969,7 @@ void clif_parse_Wis(Session *s, dumb_ptr<map_session_data> sd) AString mbuf = clif_validate_chat(sd, ChatType::Whisper); if (!mbuf) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -3987,7 +3981,7 @@ void clif_parse_Wis(Session *s, dumb_ptr<map_session_data> sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -4006,7 +4000,7 @@ void clif_parse_Wis(Session *s, dumb_ptr<map_session_data> sd) /* Refuse messages addressed to self. */ if (dstsd->sess == s) { - ZString mes = "You cannot page yourself."; + ZString mes = "You cannot page yourself."_s; clif_wis_message(s, wisp_server_name, mes); } else @@ -4079,13 +4073,13 @@ void clif_parse_DropItem(Session *s, dumb_ptr<map_session_data> sd) } if (sd->bl_m->flag.get(MapFlag::NO_PLAYER_DROPS)) { - clif_displaymessage(sd->sess, "Can't drop items here."); + clif_displaymessage(sd->sess, "Can't drop items here."_s); return; } if (sd->npc_id != 0 || sd->opt1 != Opt1::ZERO) { - clif_displaymessage(sd->sess, "Can't drop items right now."); + clif_displaymessage(sd->sess, "Can't drop items right now."_s); return; } @@ -4572,7 +4566,7 @@ void clif_parse_PartyMessage(Session *s, dumb_ptr<map_session_data> sd) AString mbuf = clif_validate_chat(sd, ChatType::Party); if (!mbuf) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -4582,7 +4576,7 @@ void clif_parse_PartyMessage(Session *s, dumb_ptr<map_session_data> sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(s, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."_s); return; } @@ -5202,7 +5196,7 @@ int clif_check_packet_flood(Session *s, int cmd) if (sd->packet_flood_in >= battle_config.packet_spam_flood) { - PRINTF("packet flood detected from %s [0x%x]\n", sd->status_key.name, cmd); + PRINTF("packet flood detected from %s [0x%x]\n"_fmt, sd->status_key.name, cmd); if (battle_config.packet_spam_kick) { s->eof = 1; // Kick @@ -5219,9 +5213,9 @@ int clif_check_packet_flood(Session *s, int cmd) } inline -void WARN_MALFORMED_MSG(dumb_ptr<map_session_data> sd, const char *msg) +void WARN_MALFORMED_MSG(dumb_ptr<map_session_data> sd, ZString msg) { - PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed message: %s.\n", + PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed message: %s.\n"_fmt, sd->status_key.name, sd->status_key.account_id, msg); } /** @@ -5266,14 +5260,14 @@ AString clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) /* The player just sent the header (2) and length (2) words. */ if (!msg_len) { - WARN_MALFORMED_MSG(sd, "no message sent"); + WARN_MALFORMED_MSG(sd, "no message sent"_s); return AString(); } /* The client sent (or claims to have sent) an empty message. */ if (msg_len == min_len) { - WARN_MALFORMED_MSG(sd, "empty message"); + WARN_MALFORMED_MSG(sd, "empty message"_s); return AString(); } @@ -5282,7 +5276,7 @@ AString clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) { /* Disallow malformed messages. */ clif_setwaitclose(s); - WARN_MALFORMED_MSG(sd, "illegal target name"); + WARN_MALFORMED_MSG(sd, "illegal target name"_s); return AString(); } @@ -5304,18 +5298,18 @@ AString clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) */ if (buf_len >= battle_config.chat_maxline) { - WARN_MALFORMED_MSG(sd, "exceeded maximum message length"); + WARN_MALFORMED_MSG(sd, "exceeded maximum message length"_s); return AString(); } if (type == ChatType::Global) { XString p = pbuf; - if (!(p.startswith(sd->status_key.name.to__actual()) && p.xslice_t(name_len).startswith(" : "))) + if (!(p.startswith(sd->status_key.name.to__actual()) && p.xslice_t(name_len).startswith(" : "_s))) { /* Disallow malformed/spoofed messages. */ clif_setwaitclose(s); - WARN_MALFORMED_MSG(sd, "spoofed name/invalid format"); + WARN_MALFORMED_MSG(sd, "spoofed name/invalid format"_s); return AString(); } /* Step beyond the separator. */ @@ -5357,11 +5351,11 @@ void clif_parse(Session *s) pc_logout(sd); clif_quitsave(s, sd); - PRINTF("Player [%s] has logged off your server.\n", sd->status_key.name); // Player logout display [Valaris] + PRINTF("Player [%s] has logged off your server.\n"_fmt, sd->status_key.name); // Player logout display [Valaris] } else if (sd) { // not authentified! (refused by char-server or disconnect before to be authentified) - PRINTF("Player with account [%d] has logged off your server (not auth account).\n", sd->bl_id); // Player logout display [Yor] + PRINTF("Player with account [%d] has logged off your server (not auth account).\n"_fmt, sd->bl_id); // Player logout display [Yor] map_deliddb(sd); // account_id has been included in the DB before auth answer } if (s) @@ -5436,32 +5430,32 @@ void clif_parse(Session *s) if (battle_config.error_log) { if (s) - PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n", + PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n"_fmt, s, cmd, packet_len); #ifdef DUMP_UNKNOWN_PACKET { int i; - ZString packet_txt = "save/packet.txt"; - PRINTF("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"); + ZString packet_txt = "save/packet.txt"_s; + PRINTF("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"_fmt); for (i = 0; i < packet_len; i++) { if ((i & 15) == 0) - PRINTF("\n%04X ", i); - PRINTF("%02X ", RFIFOB(s, i)); + PRINTF("\n%04X "_fmt, i); + PRINTF("%02X "_fmt, RFIFOB(s, i)); } if (sd && sd->state.auth) { - PRINTF("\nAccount ID %d, character ID %d, player name %s.\n", + PRINTF("\nAccount ID %d, character ID %d, player name %s.\n"_fmt, sd->status_key.account_id, sd->status_key.char_id, sd->status_key.name); } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified) - PRINTF("\nAccount ID %d.\n", sd->bl_id); + PRINTF("\nAccount ID %d.\n"_fmt, sd->bl_id); io::AppendFile fp(packet_txt); if (!fp.is_open()) { - PRINTF("clif.c: cant write [%s] !!! data is lost !!!\n", + PRINTF("clif.c: cant write [%s] !!! data is lost !!!\n"_fmt, packet_txt); return; } @@ -5472,25 +5466,25 @@ void clif_parse(Session *s) if (sd && sd->state.auth) { FPRINTF(fp, - "%s\nPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n", + "%s\nPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n"_fmt, now, sd->status_key.account_id, sd->status_key.char_id, sd->status_key.name); } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified) FPRINTF(fp, - "%s\nPlayer with account ID %d sent wrong packet:\n", + "%s\nPlayer with account ID %d sent wrong packet:\n"_fmt, now, sd->bl_id); FPRINTF(fp, - "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"); + "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"_fmt); for (i = 0; i < packet_len; i++) { if ((i & 15) == 0) - FPRINTF(fp, "\n\t%04X ", i); - FPRINTF(fp, "%02X ", RFIFOB(s, i)); + FPRINTF(fp, "\n\t%04X "_fmt, i); + FPRINTF(fp, "%02X "_fmt, RFIFOB(s, i)); } - FPRINTF(fp, "\n\n"); + FPRINTF(fp, "\n\n"_fmt); } } #endif diff --git a/src/map/grfio.cpp b/src/map/grfio.cpp index c3d1e40..b03456c 100644 --- a/src/map/grfio.cpp +++ b/src/map/grfio.cpp @@ -50,7 +50,7 @@ bool load_resnametable(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - FPRINTF(stderr, "Missing %s\n", filename); + FPRINTF(stderr, "Missing %s\n"_fmt, filename); return false; } @@ -63,7 +63,7 @@ bool load_resnametable(ZString filename) if (!extract(line, record<'#'>(&key, &value))) { - PRINTF("Bad resnametable line: %s\n", line); + PRINTF("Bad resnametable line: %s\n"_fmt, line); rv = false; continue; } @@ -85,7 +85,7 @@ std::vector<uint8_t> grfio_reads(MapName rname) { MString lfname_; // TODO ... instead of here - lfname_ += "data/"; + lfname_ += "data/"_s; lfname_ += grfio_resnametable(rname); AString lfname = AString(lfname_); @@ -93,7 +93,7 @@ std::vector<uint8_t> grfio_reads(MapName rname) int fd = open(lfname.c_str(), O_RDONLY); if (fd == -1) { - FPRINTF(stderr, "Resource %s (file %s) not found\n", + FPRINTF(stderr, "Resource %s (file %s) not found\n"_fmt, rname, lfname); return {}; } diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 2cae2ad..3395974 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -85,7 +85,7 @@ void intif_wis_message(dumb_ptr<map_session_data> sd, CharName nick, ZString mes WFIFOSET(char_session, WFIFOW(char_session, 2)); if (battle_config.etc_log) - PRINTF("intif_wis_message from %s to %s)\n", + PRINTF("intif_wis_message from %s to %s)\n"_fmt, sd->status_key.name, nick); } @@ -99,7 +99,7 @@ void intif_wis_replay(int id, int flag) WFIFOSET(char_session, 7); if (battle_config.etc_log) - PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag); + PRINTF("intif_wis_replay: id: %d, flag:%d\n"_fmt, id, flag); } // The transmission of GM only Wisp/Page from server to inter-server @@ -114,7 +114,7 @@ void intif_wis_message_to_gm(CharName Wisp_name, int min_gm_level, ZString mes) WFIFOSET(char_session, WFIFOW(char_session, 2)); if (battle_config.etc_log) - PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", + PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n"_fmt, Wisp_name, min_gm_level, mes); } @@ -280,7 +280,7 @@ int intif_parse_WisMessage(Session *s) if (battle_config.etc_log) { - PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s\n", + PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s\n"_fmt, RFIFOL(s, 4), from, to); @@ -312,7 +312,7 @@ int intif_parse_WisEnd(Session *s) uint8_t flag = RFIFOB(s, 26); if (battle_config.etc_log) // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - PRINTF("intif_parse_wisend: player: %s, flag: %d\n", + PRINTF("intif_parse_wisend: player: %s, flag: %d\n"_fmt, name, flag); sd = map_nick2sd(name); if (sd != NULL) @@ -366,7 +366,6 @@ int intif_parse_AccountReg(Session *s) sd->status.account_reg[j].value = RFIFOL(s, p + 32); } sd->status.account_reg_num = j; -// PRINTF("intif: accountreg\n"); return 0; } @@ -382,7 +381,7 @@ int intif_parse_LoadStorage(Session *s) if (sd == NULL) { if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: user not found %d\n", + PRINTF("intif_parse_LoadStorage: user not found %d\n"_fmt, RFIFOL(s, 4)); return 1; } @@ -390,14 +389,14 @@ int intif_parse_LoadStorage(Session *s) if (stor->storage_status == 1) { // Already open.. lets ignore this update if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n", + PRINTF("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n"_fmt, sd->status_key.account_id, sd->status_key.char_id); return 1; } if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex] if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", + PRINTF("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n"_fmt, sd->status_key.account_id, sd->status_key.char_id); return 1; } @@ -405,12 +404,12 @@ int intif_parse_LoadStorage(Session *s) if (RFIFOW(s, 2) - 8 != sizeof(struct storage)) { if (battle_config.error_log) - PRINTF("intif_parse_LoadStorage: data size error %d %zu\n", + PRINTF("intif_parse_LoadStorage: data size error %d %zu\n"_fmt, RFIFOW(s, 2) - 8, sizeof(struct storage)); return 1; } if (battle_config.save_log) - PRINTF("intif_openstorage: %d\n", RFIFOL(s, 4)); + PRINTF("intif_openstorage: %d\n"_fmt, RFIFOL(s, 4)); RFIFO_STRUCT(s, 8, *stor); stor->dirty = 0; stor->storage_status = 1; @@ -427,7 +426,7 @@ static void intif_parse_SaveStorage(Session *s) { if (battle_config.save_log) - PRINTF("intif_savestorage: done %d %d\n", RFIFOL(s, 2), + PRINTF("intif_savestorage: done %d %d\n"_fmt, RFIFOL(s, 2), RFIFOB(s, 6)); storage_storage_saved(RFIFOL(s, 2)); } @@ -437,7 +436,7 @@ static void intif_parse_PartyCreated(Session *s) { if (battle_config.etc_log) - PRINTF("intif: party created\n"); + PRINTF("intif: party created\n"_fmt); int account_id = RFIFOL(s, 2); int fail = RFIFOB(s, 6); int party_id = RFIFOL(s, 7); @@ -452,16 +451,15 @@ void intif_parse_PartyInfo(Session *s) if (RFIFOW(s, 2) == 8) { if (battle_config.error_log) - PRINTF("intif: party noinfo %d\n", RFIFOL(s, 4)); + PRINTF("intif: party noinfo %d\n"_fmt, RFIFOL(s, 4)); party_recv_noinfo(RFIFOL(s, 4)); return; } -// PRINTF("intif: party info %d\n",RFIFOL(fd,4)); if (RFIFOW(s, 2) != sizeof(struct party) + 4) { if (battle_config.error_log) - PRINTF("intif: party info : data size error %d %d %zu\n", + PRINTF("intif: party info : data size error %d %d %zu\n"_fmt, RFIFOL(s, 4), RFIFOW(s, 2), sizeof(struct party) + 4); } @@ -475,7 +473,7 @@ static void intif_parse_PartyMemberAdded(Session *s) { if (battle_config.etc_log) - PRINTF("intif: party member added %d %d %d\n", RFIFOL(s, 2), + PRINTF("intif: party member added %d %d %d\n"_fmt, RFIFOL(s, 2), RFIFOL(s, 6), RFIFOB(s, 10)); party_member_added(RFIFOL(s, 2), RFIFOL(s, 6), RFIFOB(s, 10)); } @@ -496,7 +494,7 @@ void intif_parse_PartyMemberLeaved(Session *s) int account_id = RFIFOL(s, 6); CharName name = stringish<CharName>(RFIFO_STRING<24>(s, 10)); if (battle_config.etc_log) - PRINTF("intif: party member leaved %d %d %s\n", + PRINTF("intif: party member leaved %d %d %s\n"_fmt, party_id, account_id, name); party_member_leaved(party_id, account_id, name); } @@ -553,8 +551,6 @@ int intif_parse(Session *s) return 2; packet_len = RFIFOW(s, 2); } -// if(battle_config.etc_log) -// PRINTF("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd)); if (RFIFOREST(s) < packet_len) { return 2; @@ -612,7 +608,7 @@ int intif_parse(Session *s) break; default: if (battle_config.error_log) - PRINTF("intif_parse : unknown packet %d %x\n", s, + PRINTF("intif_parse : unknown packet %d %x\n"_fmt, s, RFIFOW(s, 0)); return 0; } diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index 4ebb52c..2cc9e49 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -174,7 +174,7 @@ bool itemdb_readdb(ZString filename) if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } @@ -220,7 +220,7 @@ bool itemdb_readdb(ZString filename) ) ) { - PRINTF("%s:%d: error: bad item line: %s\n", + PRINTF("%s:%d: error: bad item line: %s\n"_fmt, filename, lines, line); rv = false; continue; @@ -254,7 +254,7 @@ bool itemdb_readdb(ZString filename) continue; id->equip_script = parse_script(tail_part, lines, true); } - PRINTF("read %s done (count=%d)\n", filename, ln); + PRINTF("read %s done (count=%d)\n"_fmt, filename, ln); } return rv; diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 42ff3a7..786f870 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -125,38 +125,38 @@ AString show_entity(dumb_ptr<block_list> entity) case BL::MOB: return entity->is_mob()->name; case BL::ITEM: - assert (0 && "There is no way this code did what it was supposed to do!"); + assert (0 && "There is no way this code did what it was supposed to do!"_s); /* Sorry about this one... */ // WTF? item_data is a struct item, not a struct item_data // return ((struct item_data *) (&entity->is_item()->item_data))->name; abort(); case BL::SPELL: - return {"%invocation(ERROR:this-should-not-be-an-entity)"}; + return "%invocation(ERROR:this-should-not-be-an-entity)"_s; default: - return {"%unknown-entity"}; + return "%unknown-entity"_s; } } static void stringify(val_t *v, int within_op) { - static earray<ZString, DIR, DIR::COUNT> dirs //= + static earray<LString, DIR, DIR::COUNT> dirs //= {{ - {"south"}, {"south-west"}, - {"west"}, {"north-west"}, - {"north"}, {"north-east"}, - {"east"}, {"south-east"}, + "south"_s, "south-west"_s, + "west"_s, "north-west"_s, + "north"_s, "north-east"_s, + "east"_s, "south-east"_s, }}; AString buf; switch (v->ty) { case TYPE::UNDEF: - buf = "UNDEF"; + buf = "UNDEF"_s; break; case TYPE::INT: - buf = STRPRINTF("%i", v->v.v_int); + buf = STRPRINTF("%i"_fmt, v->v.v_int); break; case TYPE::STRING: @@ -171,14 +171,14 @@ void stringify(val_t *v, int within_op) break; case TYPE::LOCATION: - buf = STRPRINTF("<\"%s\", %d, %d>", + buf = STRPRINTF("<\"%s\", %d, %d>"_fmt, v->v.v_location.m->name_, v->v.v_location.x, v->v.v_location.y); break; case TYPE::AREA: - buf = "%area"; + buf = "%area"_s; free_area(v->v.v_area); break; @@ -196,7 +196,7 @@ void stringify(val_t *v, int within_op) break; default: - FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n", + FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n"_fmt, v->ty); return; } @@ -590,7 +590,7 @@ void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, default: FPRINTF(stderr, - "Error: Trying to compute area of NE/SE/NW/SW-facing bar"); + "Error: Trying to compute area of NE/SE/NW/SW-facing bar"_fmt); *x = tx; *y = ty; *width = *height = 1; @@ -619,7 +619,7 @@ int magic_location_in_area(map_local *m, int x, int y, dumb_ptr<area_t> area) && (x < ax + awidth) && (y < ay + aheight)); } default: - FPRINTF(stderr, "INTERNAL ERROR: Invalid area\n"); + FPRINTF(stderr, "INTERNAL ERROR: Invalid area\n"_fmt); return 0; } } @@ -1034,7 +1034,7 @@ void magic_random_location(location_t *dest, dumb_ptr<area_t> area) } default: - FPRINTF(stderr, "Unknown area type %d\n", + FPRINTF(stderr, "Unknown area type %d\n"_fmt, area->ty); } } @@ -1282,89 +1282,89 @@ int fun_extract_healer_xp(dumb_ptr<env_t>, val_t *result, Slice<val_t> args) return 0; } -#define MAGIC_FUNCTION(name, args, ret, impl) {{name}, {{name}, {args}, ret, impl}} -#define MAGIC_FUNCTION1(name, args, ret) MAGIC_FUNCTION(#name, args, ret, fun_##name) -static +#define MAGIC_FUNCTION(name, args, ret, impl) {name, {name, args, ret, impl}} +#define MAGIC_FUNCTION1(name, args, ret) MAGIC_FUNCTION(#name##_s, args, ret, fun_##name) +static // should be LString, but no heterogenous lookup yet std::map<ZString, fun_t> functions = { - MAGIC_FUNCTION("+", "..", '.', fun_add), - MAGIC_FUNCTION("-", "ii", 'i', fun_sub), - MAGIC_FUNCTION("*", "ii", 'i', fun_mul), - MAGIC_FUNCTION("/", "ii", 'i', fun_div), - MAGIC_FUNCTION("%", "ii", 'i', fun_mod), - MAGIC_FUNCTION("||", "ii", 'i', fun_or), - MAGIC_FUNCTION("&&", "ii", 'i', fun_and), - MAGIC_FUNCTION("<", "..", 'i', fun_lt), - MAGIC_FUNCTION(">", "..", 'i', fun_gt), - MAGIC_FUNCTION("<=", "..", 'i', fun_lte), - MAGIC_FUNCTION(">=", "..", 'i', fun_gte), - MAGIC_FUNCTION("==", "..", 'i', fun_eq), - MAGIC_FUNCTION("!=", "..", 'i', fun_ne), - MAGIC_FUNCTION("|", "..", 'i', fun_bitor), - MAGIC_FUNCTION("&", "ii", 'i', fun_bitand), - MAGIC_FUNCTION("^", "ii", 'i', fun_bitxor), - MAGIC_FUNCTION("<<", "ii", 'i', fun_bitshl), - MAGIC_FUNCTION(">>", "ii", 'i', fun_bitshr), - MAGIC_FUNCTION1(not, "i", 'i'), - MAGIC_FUNCTION1(neg, "i", 'i'), - MAGIC_FUNCTION1(max, "ii", 'i'), - MAGIC_FUNCTION1(min, "ii", 'i'), - MAGIC_FUNCTION1(is_in, "la", 'i'), - MAGIC_FUNCTION1(if_then_else, "i__", '_'), - MAGIC_FUNCTION1(skill, "ei", 'i'), - MAGIC_FUNCTION("str", "e", 'i', fun_get_str), - MAGIC_FUNCTION("agi", "e", 'i', fun_get_agi), - MAGIC_FUNCTION("vit", "e", 'i', fun_get_vit), - MAGIC_FUNCTION("dex", "e", 'i', fun_get_dex), - MAGIC_FUNCTION("luk", "e", 'i', fun_get_luk), - MAGIC_FUNCTION("int", "e", 'i', fun_get_int), - MAGIC_FUNCTION("level", "e", 'i', fun_get_lv), - MAGIC_FUNCTION("mdef", "e", 'i', fun_get_mdef), - MAGIC_FUNCTION("def", "e", 'i', fun_get_def), - MAGIC_FUNCTION("hp", "e", 'i', fun_get_hp), - MAGIC_FUNCTION("max_hp", "e", 'i', fun_get_max_hp), - MAGIC_FUNCTION("sp", "e", 'i', fun_get_sp), - MAGIC_FUNCTION("max_sp", "e", 'i', fun_get_max_sp), - MAGIC_FUNCTION("dir", "e", 'd', fun_get_dir), - MAGIC_FUNCTION1(name_of, ".", 's'), - MAGIC_FUNCTION1(mob_id, "e", 'i'), - MAGIC_FUNCTION1(location, "e", 'l'), - MAGIC_FUNCTION1(random, "i", 'i'), - MAGIC_FUNCTION1(random_dir, "i", 'd'), - MAGIC_FUNCTION1(hash_entity, "e", 'i'), - MAGIC_FUNCTION1(is_married, "e", 'i'), - MAGIC_FUNCTION1(partner, "e", 'e'), - MAGIC_FUNCTION1(awayfrom, "ldi", 'l'), - MAGIC_FUNCTION1(failed, "_", 'i'), - MAGIC_FUNCTION1(pc, "s", 'e'), - MAGIC_FUNCTION1(npc, "s", 'e'), - MAGIC_FUNCTION1(distance, "ll", 'i'), - MAGIC_FUNCTION1(rdistance, "ll", 'i'), - MAGIC_FUNCTION1(anchor, "s", 'a'), - MAGIC_FUNCTION("random_location", "a", 'l', fun_pick_location), - MAGIC_FUNCTION("script_int", "es", 'i', fun_read_script_int), - MAGIC_FUNCTION("script_str", "es", 's', fun_read_script_str), - MAGIC_FUNCTION1(rbox, "li", 'a'), - MAGIC_FUNCTION1(count_item, "e.", 'i'), - MAGIC_FUNCTION1(line_of_sight, "ll", 'i'), - MAGIC_FUNCTION1(running_status_update, "ei", 'i'), - MAGIC_FUNCTION1(status_option, "ei", 'i'), - MAGIC_FUNCTION1(element, "e", 'i'), - MAGIC_FUNCTION1(element_level, "e", 'i'), - MAGIC_FUNCTION1(his_shroud, "e", 'i'), - MAGIC_FUNCTION1(is_equipped, "e.", 'i'), - MAGIC_FUNCTION1(is_exterior, "l", 'i'), - MAGIC_FUNCTION1(contains_string, "ss", 'i'), - MAGIC_FUNCTION1(strstr, "ss", 'i'), - MAGIC_FUNCTION1(strlen, "s", 'i'), - MAGIC_FUNCTION1(substr, "sii", 's'), - MAGIC_FUNCTION1(sqrt, "i", 'i'), - MAGIC_FUNCTION1(map_level, "l", 'i'), - MAGIC_FUNCTION1(map_nr, "l", 'i'), - MAGIC_FUNCTION1(dir_towards, "lli", 'd'), - MAGIC_FUNCTION1(is_dead, "e", 'i'), - MAGIC_FUNCTION1(is_pc, "e", 'i'), - MAGIC_FUNCTION("extract_healer_experience", "ei", 'i', fun_extract_healer_xp), + MAGIC_FUNCTION("+"_s, ".."_s, '.', fun_add), + MAGIC_FUNCTION("-"_s, "ii"_s, 'i', fun_sub), + MAGIC_FUNCTION("*"_s, "ii"_s, 'i', fun_mul), + MAGIC_FUNCTION("/"_s, "ii"_s, 'i', fun_div), + MAGIC_FUNCTION("%"_s, "ii"_s, 'i', fun_mod), + MAGIC_FUNCTION("||"_s, "ii"_s, 'i', fun_or), + MAGIC_FUNCTION("&&"_s, "ii"_s, 'i', fun_and), + MAGIC_FUNCTION("<"_s, ".."_s, 'i', fun_lt), + MAGIC_FUNCTION(">"_s, ".."_s, 'i', fun_gt), + MAGIC_FUNCTION("<="_s, ".."_s, 'i', fun_lte), + MAGIC_FUNCTION(">="_s, ".."_s, 'i', fun_gte), + MAGIC_FUNCTION("=="_s, ".."_s, 'i', fun_eq), + MAGIC_FUNCTION("!="_s, ".."_s, 'i', fun_ne), + MAGIC_FUNCTION("|"_s, ".."_s, 'i', fun_bitor), + MAGIC_FUNCTION("&"_s, "ii"_s, 'i', fun_bitand), + MAGIC_FUNCTION("^"_s, "ii"_s, 'i', fun_bitxor), + MAGIC_FUNCTION("<<"_s, "ii"_s, 'i', fun_bitshl), + MAGIC_FUNCTION(">>"_s, "ii"_s, 'i', fun_bitshr), + MAGIC_FUNCTION1(not, "i"_s, 'i'), + MAGIC_FUNCTION1(neg, "i"_s, 'i'), + MAGIC_FUNCTION1(max, "ii"_s, 'i'), + MAGIC_FUNCTION1(min, "ii"_s, 'i'), + MAGIC_FUNCTION1(is_in, "la"_s, 'i'), + MAGIC_FUNCTION1(if_then_else, "i__"_s, '_'), + MAGIC_FUNCTION1(skill, "ei"_s, 'i'), + MAGIC_FUNCTION("str"_s, "e"_s, 'i', fun_get_str), + MAGIC_FUNCTION("agi"_s, "e"_s, 'i', fun_get_agi), + MAGIC_FUNCTION("vit"_s, "e"_s, 'i', fun_get_vit), + MAGIC_FUNCTION("dex"_s, "e"_s, 'i', fun_get_dex), + MAGIC_FUNCTION("luk"_s, "e"_s, 'i', fun_get_luk), + MAGIC_FUNCTION("int"_s, "e"_s, 'i', fun_get_int), + MAGIC_FUNCTION("level"_s, "e"_s, 'i', fun_get_lv), + MAGIC_FUNCTION("mdef"_s, "e"_s, 'i', fun_get_mdef), + MAGIC_FUNCTION("def"_s, "e"_s, 'i', fun_get_def), + MAGIC_FUNCTION("hp"_s, "e"_s, 'i', fun_get_hp), + MAGIC_FUNCTION("max_hp"_s, "e"_s, 'i', fun_get_max_hp), + MAGIC_FUNCTION("sp"_s, "e"_s, 'i', fun_get_sp), + MAGIC_FUNCTION("max_sp"_s, "e"_s, 'i', fun_get_max_sp), + MAGIC_FUNCTION("dir"_s, "e"_s, 'd', fun_get_dir), + MAGIC_FUNCTION1(name_of, "."_s, 's'), + MAGIC_FUNCTION1(mob_id, "e"_s, 'i'), + MAGIC_FUNCTION1(location, "e"_s, 'l'), + MAGIC_FUNCTION1(random, "i"_s, 'i'), + MAGIC_FUNCTION1(random_dir, "i"_s, 'd'), + MAGIC_FUNCTION1(hash_entity, "e"_s, 'i'), + MAGIC_FUNCTION1(is_married, "e"_s, 'i'), + MAGIC_FUNCTION1(partner, "e"_s, 'e'), + MAGIC_FUNCTION1(awayfrom, "ldi"_s, 'l'), + MAGIC_FUNCTION1(failed, "_"_s, 'i'), + MAGIC_FUNCTION1(pc, "s"_s, 'e'), + MAGIC_FUNCTION1(npc, "s"_s, 'e'), + MAGIC_FUNCTION1(distance, "ll"_s, 'i'), + MAGIC_FUNCTION1(rdistance, "ll"_s, 'i'), + MAGIC_FUNCTION1(anchor, "s"_s, 'a'), + MAGIC_FUNCTION("random_location"_s, "a"_s, 'l', fun_pick_location), + MAGIC_FUNCTION("script_int"_s, "es"_s, 'i', fun_read_script_int), + MAGIC_FUNCTION("script_str"_s, "es"_s, 's', fun_read_script_str), + MAGIC_FUNCTION1(rbox, "li"_s, 'a'), + MAGIC_FUNCTION1(count_item, "e."_s, 'i'), + MAGIC_FUNCTION1(line_of_sight, "ll"_s, 'i'), + MAGIC_FUNCTION1(running_status_update, "ei"_s, 'i'), + MAGIC_FUNCTION1(status_option, "ei"_s, 'i'), + MAGIC_FUNCTION1(element, "e"_s, 'i'), + MAGIC_FUNCTION1(element_level, "e"_s, 'i'), + MAGIC_FUNCTION1(his_shroud, "e"_s, 'i'), + MAGIC_FUNCTION1(is_equipped, "e."_s, 'i'), + MAGIC_FUNCTION1(is_exterior, "l"_s, 'i'), + MAGIC_FUNCTION1(contains_string, "ss"_s, 'i'), + MAGIC_FUNCTION1(strstr, "ss"_s, 'i'), + MAGIC_FUNCTION1(strlen, "s"_s, 'i'), + MAGIC_FUNCTION1(substr, "sii"_s, 's'), + MAGIC_FUNCTION1(sqrt, "i"_s, 'i'), + MAGIC_FUNCTION1(map_level, "l"_s, 'i'), + MAGIC_FUNCTION1(map_nr, "l"_s, 'i'), + MAGIC_FUNCTION1(dir_towards, "lli"_s, 'd'), + MAGIC_FUNCTION1(is_dead, "e"_s, 'i'), + MAGIC_FUNCTION1(is_pc, "e"_s, 'i'), + MAGIC_FUNCTION("extract_healer_experience"_s, "ei"_s, 'i', fun_extract_healer_xp), }; fun_t *magic_get_fun(ZString name) @@ -1512,7 +1512,7 @@ dumb_ptr<area_t> eval_area(dumb_ptr<env_t> env, e_area_t& expr_) } default: - FPRINTF(stderr, "INTERNAL ERROR: Unknown area type %d\n", + FPRINTF(stderr, "INTERNAL ERROR: Unknown area type %d\n"_fmt, area->ty); area.delete_(); return NULL; @@ -1573,7 +1573,7 @@ int magic_signature_check(ZString opname, ZString funname, ZString signature, if (!ty_key) { FPRINTF(stderr, - "[magic-eval]: L%d:%d: Too many arguments (%zu) to %s `%s'\n", + "[magic-eval]: L%d:%d: Too many arguments (%zu) to %s `%s'\n"_fmt, line, column, args.size(), opname, funname); return 1; } @@ -1587,7 +1587,7 @@ int magic_signature_check(ZString opname, ZString funname, ZString signature, if (ty == TYPE::UNDEF) { FPRINTF(stderr, - "[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n", + "[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n"_fmt, line, column, i + 1, opname, funname); return 1; } @@ -1619,7 +1619,7 @@ int magic_signature_check(ZString opname, ZString funname, ZString signature, { /* Coercion failed? */ if (ty != TYPE::FAIL) FPRINTF(stderr, - "[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n", + "[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n"_fmt, line, column, i + 1, opname, funname, ty); return 1; @@ -1660,7 +1660,7 @@ void magic_eval(dumb_ptr<env_t> env, val_t *dest, dumb_ptr<expr_t> expr) for (i = 0; i < args_nr; ++i) magic_eval(env, &arguments[i], expr->e.e_funapp.args[i]); - if (magic_signature_check("function", f->name, f->signature, Slice<val_t>(arguments, args_nr), + if (magic_signature_check("function"_s, f->name, f->signature, Slice<val_t>(arguments, args_nr), expr->e.e_funapp.line_nr, expr->e.e_funapp.column) || f->fun(env, dest, Slice<val_t>(arguments, args_nr))) dest->ty = TYPE::FAIL; @@ -1713,7 +1713,7 @@ void magic_eval(dumb_ptr<env_t> env, val_t *dest, dumb_ptr<expr_t> expr) else { FPRINTF(stderr, - "[magic] Attempt to access field %s on non-spell\n", + "[magic] Attempt to access field %s on non-spell\n"_fmt, env->base_env->varv[id].name); dest->ty = TYPE::FAIL; } @@ -1722,7 +1722,7 @@ void magic_eval(dumb_ptr<env_t> env, val_t *dest, dumb_ptr<expr_t> expr) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: Unknown expression type %d\n", + "[magic] INTERNAL ERROR: Unknown expression type %d\n"_fmt, expr->ty); break; } @@ -1747,7 +1747,7 @@ AString magic_eval_str(dumb_ptr<env_t> env, dumb_ptr<expr_t> expr) magic_eval(env, &result, expr); if (result.ty == TYPE::FAIL || result.ty == TYPE::UNDEF) - return {"?"}; + return "?"_s; stringify(&result, 0); diff --git a/src/map/magic-expr.hpp b/src/map/magic-expr.hpp index 58f6596..4d78bab 100644 --- a/src/map/magic-expr.hpp +++ b/src/map/magic-expr.hpp @@ -44,8 +44,8 @@ */ struct fun_t { - ZString name; - ZString signature; + LString name; + LString signature; char ret_ty; int (*fun)(dumb_ptr<env_t> env, val_t *result, Slice<val_t> arga); }; diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index d86f595..c734908 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -187,7 +187,7 @@ dumb_ptr<env_t> spell_create_env(magic_conf_t *conf, dumb_ptr<spell_t> spell, break; default: - FPRINTF(stderr, "Unexpected spellarg type %d\n", + FPRINTF(stderr, "Unexpected spellarg type %d\n"_fmt, spell->spellarg_ty); } @@ -370,7 +370,7 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check, return NULL; default: - FPRINTF(stderr, "Unexpected spellguard type %d\n", + FPRINTF(stderr, "Unexpected spellguard type %d\n"_fmt, guard->ty); return NULL; } @@ -519,7 +519,7 @@ void spell_bind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invocat { int *i = NULL; FPRINTF(stderr, - "[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n", + "[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n"_fmt, invocation->spell->name); *i = 1; return; diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index ba99409..ddadf03 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -58,19 +58,19 @@ void print_val(val_t *v) switch (v->ty) { case TYPE::UNDEF: - FPRINTF(stderr, "UNDEF"); + FPRINTF(stderr, "UNDEF"_fmt); break; case TYPE::INT: - FPRINTF(stderr, "%d", v->v.v_int); + FPRINTF(stderr, "%d"_fmt, v->v.v_int); break; case TYPE::DIR: - FPRINTF(stderr, "dir%d", v->v.v_int); + FPRINTF(stderr, "dir%d"_fmt, v->v.v_int); break; case TYPE::STRING: - FPRINTF(stderr, "`%s'", v->v.v_string); + FPRINTF(stderr, "`%s'"_fmt, v->v.v_string); break; default: - FPRINTF(stderr, "ty%d", v->ty); + FPRINTF(stderr, "ty%d"_fmt, v->ty); break; } } @@ -84,11 +84,11 @@ void dump_env(env_t *env) val_t *v = &env->vars[i]; val_t *bv = &env->base_env->vars[i]; - FPRINTF(stderr, "%02x %30s ", i, env->base_env->var_name[i]); + FPRINTF(stderr, "%02x %30s "_fmt, i, env->base_env->var_name[i]); print_val(v); - FPRINTF(stderr, "\t("); + FPRINTF(stderr, "\t("_fmt); print_val(bv); - FPRINTF(stderr, ")\n"); + FPRINTF(stderr, ")\n"_fmt); } } #endif @@ -286,7 +286,7 @@ void magic_unshroud(dumb_ptr<map_session_data> other_char) other_char->state.shroud_active = 0; // Now warp the caster out of and back into here to refresh everyone's display char_update(other_char); - clif_displaymessage(other_char->sess, "Your shroud has been dispelled!"); + clif_displaymessage(other_char->sess, "Your shroud has been dispelled!"_s); // entity_effect(other_char, MAGIC_EFFECT_REVEAL); } @@ -304,7 +304,7 @@ dumb_ptr<npc_data> local_spell_effect(map_local *m, int x, int y, int effect, /* 1 minute should be enough for all interesting spell effects, I hope */ std::chrono::seconds delay = std::chrono::seconds(30); dumb_ptr<npc_data> effect_npc = npc_spawn_text(m, x, y, - INVISIBLE_NPC, NpcName(), "?"); + INVISIBLE_NPC, NpcName(), "?"_s); int effect_npc_id = effect_npc->bl_id; entity_effect(effect_npc, effect, tdelay); @@ -350,7 +350,7 @@ int op_instaheal(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<map_session_data> caster_pc = caster->is_player(); dumb_ptr<map_session_data> subject_pc = subject->is_player(); - MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d", + MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d"_fmt, subject_pc->status_key.char_id, ARGINT(1)); } @@ -770,18 +770,18 @@ int op_spawn(dumb_ptr<env_t>, Slice<val_t> args) } static -const char *get_invocation_name(dumb_ptr<env_t> env) +ZString get_invocation_name(dumb_ptr<env_t> env) { dumb_ptr<invocation> invocation_; if (env->VAR(VAR_INVOCATION).ty != TYPE::INVOCATION) - return "?"; + return "?"_s; invocation_ = map_id_is_spell(env->VAR(VAR_INVOCATION).v.v_int); if (invocation_) - return invocation_->spell->name.c_str(); + return invocation_->spell->name; else - return "??"; + return "??"_s; } static @@ -824,7 +824,7 @@ int op_injure(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<mob_data> mob = target->is_mob(); - MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s", + MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s"_fmt, mob->bl_id, mob->mob_class, damage_caused, get_invocation_name(env)); } @@ -940,35 +940,35 @@ int op_gain_exp(dumb_ptr<env_t>, Slice<val_t> args) } #define MAGIC_OPERATION(name, args, impl) {{name}, {{name}, {args}, impl}} -#define MAGIC_OPERATION1(name, args) MAGIC_OPERATION(#name, args, op_##name) +#define MAGIC_OPERATION1(name, args) MAGIC_OPERATION(#name##_s, args, op_##name) static std::map<ZString, op_t> operations = { - MAGIC_OPERATION1(sfx, ".ii"), - MAGIC_OPERATION1(instaheal, "eii"), - MAGIC_OPERATION1(itemheal, "eii"), - MAGIC_OPERATION1(shroud, "ei"), - MAGIC_OPERATION("unshroud", "e", op_reveal), - MAGIC_OPERATION1(message, "es"), - MAGIC_OPERATION1(messenger_npc, "lissi"), - MAGIC_OPERATION1(move, "ed"), - MAGIC_OPERATION1(warp, "el"), - MAGIC_OPERATION1(banish, "e"), - MAGIC_OPERATION1(status_change, "eiiiiii"), - MAGIC_OPERATION1(stop_status_change, "ei"), - MAGIC_OPERATION1(override_attack, "eiiiiii"), - MAGIC_OPERATION1(create_item, "e.i"), - MAGIC_OPERATION1(aggravate, "eie"), - MAGIC_OPERATION1(spawn, "aeiiii"), - MAGIC_OPERATION1(injure, "eeii"), - MAGIC_OPERATION1(emote, "ei"), - MAGIC_OPERATION1(set_script_variable, "esi"), - MAGIC_OPERATION1(set_script_str, "ess"), - MAGIC_OPERATION1(set_hair_colour, "ei"), - MAGIC_OPERATION1(set_hair_style, "ei"), - MAGIC_OPERATION("drop_item", "l.ii", op_drop_item_for), - MAGIC_OPERATION1(drop_item_for, "l.iiei"), - MAGIC_OPERATION("gain_experience", "eiii", op_gain_exp), + MAGIC_OPERATION1(sfx, ".ii"_s), + MAGIC_OPERATION1(instaheal, "eii"_s), + MAGIC_OPERATION1(itemheal, "eii"_s), + MAGIC_OPERATION1(shroud, "ei"_s), + MAGIC_OPERATION("unshroud"_s, "e"_s, op_reveal), + MAGIC_OPERATION1(message, "es"_s), + MAGIC_OPERATION1(messenger_npc, "lissi"_s), + MAGIC_OPERATION1(move, "ed"_s), + MAGIC_OPERATION1(warp, "el"_s), + MAGIC_OPERATION1(banish, "e"_s), + MAGIC_OPERATION1(status_change, "eiiiiii"_s), + MAGIC_OPERATION1(stop_status_change, "ei"_s), + MAGIC_OPERATION1(override_attack, "eiiiiii"_s), + MAGIC_OPERATION1(create_item, "e.i"_s), + MAGIC_OPERATION1(aggravate, "eie"_s), + MAGIC_OPERATION1(spawn, "aeiiii"_s), + MAGIC_OPERATION1(injure, "eeii"_s), + MAGIC_OPERATION1(emote, "ei"_s), + MAGIC_OPERATION1(set_script_variable, "esi"_s), + MAGIC_OPERATION1(set_script_str, "ess"_s), + MAGIC_OPERATION1(set_hair_colour, "ei"_s), + MAGIC_OPERATION1(set_hair_style, "ei"_s), + MAGIC_OPERATION("drop_item"_s, "l.ii"_s, op_drop_item_for), + MAGIC_OPERATION1(drop_item_for, "l.iiei"_s), + MAGIC_OPERATION("gain_experience"_s, "eiii"_s, op_gain_exp), }; op_t *magic_get_op(ZString name) @@ -1004,7 +1004,7 @@ void spell_effect_report_termination(int invocation_id, int bl_id, dumb_ptr<block_list> entity = map_id2bl(bl_id); if (entity->bl_type == BL::PC) FPRINTF(stderr, - "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n", + "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n"_fmt, bl_id, sc_id); return; } @@ -1089,7 +1089,7 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n", + "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n"_fmt, invocation_->spell->name); return NULL; } @@ -1105,7 +1105,7 @@ cont_activation_record_t *add_stack_entry(dumb_ptr<invocation> invocation_, if (invocation_->stack_size >= MAX_STACK_SIZE) { FPRINTF(stderr, - "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n", + "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n"_fmt, invocation_->spell->name); invocation_->stack_size--; return NULL; @@ -1221,7 +1221,7 @@ dumb_ptr<effect_t> run_foreach(dumb_ptr<invocation> invocation, { magic_clear_var(&area); FPRINTF(stderr, - "[magic] Error in spell `%s': FOREACH loop over non-area\n", + "[magic] Error in spell `%s': FOREACH loop over non-area\n"_fmt, invocation->spell->name.c_str()); return return_location; } @@ -1271,7 +1271,7 @@ dumb_ptr<effect_t> run_for (dumb_ptr<invocation> invocation, magic_clear_var(&start); magic_clear_var(&stop); FPRINTF(stderr, - "[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n", + "[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n"_fmt, invocation->spell->name); return return_location; } @@ -1319,9 +1319,9 @@ void print_cfg(int i, effect_t *e) { int j; for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); - PRINTF("%p: ", e); + PRINTF("%p: "_fmt, e); if (!e) { @@ -1354,11 +1354,11 @@ void print_cfg(int i, effect_t *e) case EFFECT::IF: puts("IF"); for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); puts("THEN"); print_cfg(i + 1, e->e.e_if.true_branch); for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); puts("ELSE"); print_cfg(i + 1, e->e.e_if.false_branch); break; @@ -1395,7 +1395,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) #define REFRESH_INVOCATION invocation_ = map_id_is_spell(invocation_id); if (!invocation_) return interval_t::zero(); #ifdef DEBUG - FPRINTF(stderr, "Resuming execution: invocation of `%s'\n", + FPRINTF(stderr, "Resuming execution: invocation of `%s'\n"_fmt, invocation_->spell->name); print_cfg(1, invocation_->current_effect); #endif @@ -1406,7 +1406,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) int i; #ifdef DEBUG - FPRINTF(stderr, "Next step of type %d\n", e->ty); + FPRINTF(stderr, "Next step of type %d\n"_fmt, e->ty); dump_env(invocation_->env); #endif @@ -1464,9 +1464,9 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) ZString caster_name = (caster ? caster->status_key.name : CharName()).to__actual(); argrec_t arg[3] = { - {"@target", env->VAR(VAR_TARGET).ty == TYPE::ENTITY ? 0 : env->VAR(VAR_TARGET).v.v_int}, - {"@caster", invocation_->caster}, - {"@caster_name$", caster_name}, + {"@target"_s, env->VAR(VAR_TARGET).ty == TYPE::ENTITY ? 0 : env->VAR(VAR_TARGET).v.v_int}, + {"@caster"_s, invocation_->caster}, + {"@caster_name$"_s, caster_name}, }; int message_recipient = env->VAR(VAR_SCRIPTTARGET).ty == @@ -1516,7 +1516,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) for (i = 0; i < e->e.e_op.args_nr; i++) magic_eval(invocation_->env, &args[i], e->e.e_op.args[i]); - if (!magic_signature_check("effect", op->name, op->signature, + if (!magic_signature_check("effect"_s, op->name, op->signature, Slice<val_t>(args, e->e.e_op.args_nr), e->e.e_op.line_nr, e->e.e_op.column)) @@ -1535,7 +1535,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: Unknown effect %d\n", + "[magic] INTERNAL ERROR: Unknown effect %d\n"_fmt, e->ty); } diff --git a/src/map/magic-v2.cpp b/src/map/magic-v2.cpp index 41d29cd..20abc00 100644 --- a/src/map/magic-v2.cpp +++ b/src/map/magic-v2.cpp @@ -61,7 +61,7 @@ namespace magic_v2 if (zid != id) { FPRINTF(stderr, - "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", + "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n"_fmt, name, zid, id); } return zid == id; @@ -72,15 +72,15 @@ namespace magic_v2 { bool ok = true; - ok &= INTERN_ASSERT("min_casttime", VAR_MIN_CASTTIME); - ok &= INTERN_ASSERT("obscure_chance", VAR_OBSCURE_CHANCE); - ok &= INTERN_ASSERT("caster", VAR_CASTER); - ok &= INTERN_ASSERT("spellpower", VAR_SPELLPOWER); - ok &= INTERN_ASSERT("self_spell", VAR_SPELL); - ok &= INTERN_ASSERT("self_invocation", VAR_INVOCATION); - ok &= INTERN_ASSERT("target", VAR_TARGET); - ok &= INTERN_ASSERT("script_target", VAR_SCRIPTTARGET); - ok &= INTERN_ASSERT("location", VAR_LOCATION); + ok &= INTERN_ASSERT("min_casttime"_s, VAR_MIN_CASTTIME); + ok &= INTERN_ASSERT("obscure_chance"_s, VAR_OBSCURE_CHANCE); + ok &= INTERN_ASSERT("caster"_s, VAR_CASTER); + ok &= INTERN_ASSERT("spellpower"_s, VAR_SPELLPOWER); + ok &= INTERN_ASSERT("self_spell"_s, VAR_SPELL); + ok &= INTERN_ASSERT("self_invocation"_s, VAR_INVOCATION); + ok &= INTERN_ASSERT("target"_s, VAR_TARGET); + ok &= INTERN_ASSERT("script_target"_s, VAR_SCRIPTTARGET); + ok &= INTERN_ASSERT("location"_s, VAR_LOCATION); return ok; } @@ -91,7 +91,7 @@ namespace magic_v2 { if (!const_defm.insert({name, *val}).second) { - span.error(STRPRINTF("Redefinition of constant '%s'", name)); + span.error(STRPRINTF("Redefinition of constant '%s'"_fmt, name)); return false; } return true; @@ -184,14 +184,14 @@ namespace magic_v2 auto pair1 = magic_conf.spells_by_name.insert({spell->name, spell}); if (!pair1.second) { - span.error(STRPRINTF("Attempt to redefine spell '%s'", spell->name)); + span.error(STRPRINTF("Attempt to redefine spell '%s'"_fmt, spell->name)); return false; } auto pair2 = magic_conf.spells_by_invocation.insert({spell->invocation, spell}); if (!pair2.second) { - span.error(STRPRINTF("Attempt to redefine spell invocation '%s'", spell->invocation)); + span.error(STRPRINTF("Attempt to redefine spell invocation '%s'"_fmt, spell->invocation)); magic_conf.spells_by_name.erase(pair1.first); return false; } @@ -203,14 +203,14 @@ namespace magic_v2 auto pair1 = magic_conf.anchors_by_name.insert({anchor->name, anchor}); if (!pair1.second) { - span.error(STRPRINTF("Attempt to redefine teleport anchor '%s'", anchor->name)); + span.error(STRPRINTF("Attempt to redefine teleport anchor '%s'"_fmt, anchor->name)); return false; } auto pair2 = magic_conf.anchors_by_invocation.insert({anchor->name, anchor}); if (!pair2.second) { - span.error(STRPRINTF("Attempt to redefine anchor invocation '%s'", anchor->invocation)); + span.error(STRPRINTF("Attempt to redefine anchor invocation '%s'"_fmt, anchor->invocation)); magic_conf.anchors_by_name.erase(pair1.first); return false; } @@ -223,7 +223,7 @@ namespace magic_v2 RString name = proc->name; if (!procs.insert({name, std::move(*proc)}).second) { - span.error("procedure already exists"); + span.error("procedure already exists"_s); return false; } return true; @@ -234,7 +234,7 @@ namespace magic_v2 auto pi = procs.find(name); if (pi == procs.end()) { - span.error(STRPRINTF("Unknown procedure '%s'", name)); + span.error(STRPRINTF("Unknown procedure '%s'"_fmt, name)); return false; } @@ -242,7 +242,7 @@ namespace magic_v2 if (p->argv.size() != argvp->size()) { - span.error(STRPRINTF("Procedure %s/%zu invoked with %zu parameters", + span.error(STRPRINTF("Procedure %s/%zu invoked with %zu parameters"_fmt, name, p->argv.size(), argvp->size())); return false; } @@ -259,12 +259,12 @@ namespace magic_v2 op_t *op = magic_get_op(name); if (!op) { - span.error(STRPRINTF("Unknown operation '%s'", name)); + span.error(STRPRINTF("Unknown operation '%s'"_fmt, name)); return false; } if (op->signature.size() != argv.size()) { - span.error(STRPRINTF("Incorrect number of arguments to operation '%s': Expected %zu, found %zu", + span.error(STRPRINTF("Incorrect number of arguments to operation '%s': Expected %zu, found %zu"_fmt, name, op->signature.size(), argv.size())); return false; } @@ -295,12 +295,12 @@ namespace magic_v2 fun_t *fun = magic_get_fun(name); if (!fun) { - span.error(STRPRINTF("Unknown function '%s'", name)); + span.error(STRPRINTF("Unknown function '%s'"_fmt, name)); return false; } if (fun->signature.size() != argv.size()) { - span.error(STRPRINTF("Incorrect number of arguments to function '%s': Expected %zu, found %zu", + span.error(STRPRINTF("Incorrect number of arguments to function '%s': Expected %zu, found %zu"_fmt, name, fun->signature.size(), argv.size())); return false; } @@ -362,20 +362,20 @@ namespace magic_v2 return false; if (s._list[0]._type != sexpr::TOKEN) return false; - return s._list[0]._str == "DISABLED"; + return s._list[0]._str == "DISABLED"_s; } static bool parse_loc(const SExpr& s, e_location_t& loc) { if (s._type != sexpr::LIST) - return fail(s, "loc not list"); + return fail(s, "loc not list"_s); if (s._list.size() != 4) - return fail(s, "loc not 3 args"); + return fail(s, "loc not 3 args"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "loc cmd not tok"); - if (s._list[0]._str != "@") - return fail(s._list[0], "loc cmd not cmd"); + return fail(s._list[0], "loc cmd not tok"_s); + if (s._list[0]._str != "@"_s) + return fail(s._list[0], "loc cmd not cmd"_s); return parse_expression(s._list[1], loc.m) && parse_expression(s._list[2], loc.x) && parse_expression(s._list[3], loc.y); @@ -392,7 +392,7 @@ namespace magic_v2 val.ty = TYPE::INT; val.v.v_int = x._int; if (val.v.v_int != x._int) - return fail(x, "integer too large"); + return fail(x, "integer too large"_s); out = magic_new_expr(EXPR::VAL); out->e.e_val = val; @@ -410,9 +410,11 @@ namespace magic_v2 } case sexpr::TOKEN: { - ZString dirs[8] = { - ZString("S"), ZString("SW"), ZString("W"), ZString("NW"), ZString("N"), ZString("NE"), ZString("E"), ZString("SE"), - }; + earray<LString, DIR, DIR::COUNT> dirs //= + {{ + "S"_s, "SW"_s, "W"_s, "NW"_s, + "N"_s, "NE"_s, "E"_s, "SE"_s, + }}; auto begin = std::begin(dirs); auto end = std::end(dirs); auto it = std::find(begin, end, x._str); @@ -444,13 +446,13 @@ namespace magic_v2 break; case sexpr::LIST: if (x._list.empty()) - return fail(x, "empty list"); + return fail(x, "empty list"_s); { if (x._list[0]._type != sexpr::TOKEN) - return fail(x._list[0], "op not token"); + return fail(x._list[0], "op not token"_s); ZString op = x._list[0]._str; // area - if (op == "@") + if (op == "@"_s) { e_location_t loc; if (!parse_loc(x, loc)) @@ -460,7 +462,7 @@ namespace magic_v2 out->e.e_area.a.a_loc = loc; return true; } - if (op == "@+") + if (op == "@+"_s) { e_location_t loc; dumb_ptr<expr_t> width; @@ -478,7 +480,7 @@ namespace magic_v2 out->e.e_area.a.a_rect.height = height; return true; } - if (op == "TOWARDS") + if (op == "TOWARDS"_s) { e_location_t loc; dumb_ptr<expr_t> dir; @@ -500,33 +502,33 @@ namespace magic_v2 out->e.e_area.a.a_bar.depth = depth; return true; } - if (op == ".") + if (op == "."_s) { if (x._list.size() != 3) - return fail(x, ". not 2"); + return fail(x, ". not 2"_s); dumb_ptr<expr_t> expr; if (!parse_expression(x._list[1], expr)) return false; if (x._list[2]._type != sexpr::TOKEN) - return fail(x._list[2], ".elem not name"); + return fail(x._list[2], ".elem not name"_s); ZString elem = x._list[2]._str; out = dot_expr(expr, intern_id(elem)); return true; } - static + static // TODO LString std::set<ZString> ops = { - "<", ">", "<=", ">=", "==", "!=", - "+", "-", "*", "%", "/", - "&", "^", "|", "<<", ">>", - "&&", "||", + "<"_s, ">"_s, "<="_s, ">="_s, "=="_s, "!="_s, + "+"_s, "-"_s, "*"_s, "%"_s, "/"_s, + "&"_s, "^"_s, "|"_s, "<<"_s, ">>"_s, + "&&"_s, "||"_s, }; // TODO implement unary operators if (ops.count(op)) { // operators are n-ary and left-associative if (x._list.size() < 3) - return fail(x, "operator not at least 2 args"); + return fail(x, "operator not at least 2 args"_s); auto begin = x._list.begin() + 1; auto end = x._list.end(); if (!parse_expression(*begin, out)) @@ -565,23 +567,23 @@ namespace magic_v2 item_data *item = itemdb_searchname(s._str); if (!item) - return fail(s, "no such item"); + return fail(s, "no such item"_s); id = item->nameid; return true; } if (s._type != sexpr::LIST) - return fail(s, "item not string or list"); + return fail(s, "item not string or list"_s); if (s._list.size() != 2) - return fail(s, "item list is not pair"); + return fail(s, "item list is not pair"_s); if (s._list[0]._type != sexpr::INT) - return fail(s._list[0], "item pair first not int"); + return fail(s._list[0], "item pair first not int"_s); count = s._list[0]._int; if (s._list[1]._type != sexpr::STRING) - return fail(s._list[1], "item pair second not name"); + return fail(s._list[1], "item pair second not name"_s); item_data *item = itemdb_searchname(s._list[1]._str); if (!item) - return fail(s, "no such item"); + return fail(s, "no such item"_s); id = item->nameid; return true; } @@ -590,18 +592,18 @@ namespace magic_v2 bool parse_spellguard(const SExpr& s, dumb_ptr<spellguard_t>& out) { if (s._type != sexpr::LIST) - return fail(s, "not list"); + return fail(s, "not list"_s); if (s._list.empty()) - return fail(s, "empty list"); + return fail(s, "empty list"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "not token"); + return fail(s._list[0], "not token"_s); ZString cmd = s._list[0]._str; - if (cmd == "OR") + if (cmd == "OR"_s) { auto begin = s._list.begin() + 1; auto end = s._list.end(); if (begin == end) - return fail(s, "missing arguments"); + return fail(s, "missing arguments"_s); if (!parse_spellguard(*begin, out)) return false; ++begin; @@ -617,14 +619,14 @@ namespace magic_v2 } return true; } - if (cmd == "GUARD") + if (cmd == "GUARD"_s) { auto begin = s._list.begin() + 1; auto end = s._list.end(); while (is_comment(end[-1])) --end; if (begin == end) - return fail(s, "missing arguments"); + return fail(s, "missing arguments"_s); if (!parse_spellguard(end[-1], out)) return false; --end; @@ -639,10 +641,10 @@ namespace magic_v2 } return true; } - if (cmd == "REQUIRE") + if (cmd == "REQUIRE"_s) { if (s._list.size() != 2) - return fail(s, "not one argument"); + return fail(s, "not one argument"_s); dumb_ptr<expr_t> condition; if (!parse_expression(s._list[1], condition)) return false; @@ -650,10 +652,10 @@ namespace magic_v2 out->s.s_condition = condition; return true; } - if (cmd == "MANA") + if (cmd == "MANA"_s) { if (s._list.size() != 2) - return fail(s, "not one argument"); + return fail(s, "not one argument"_s); dumb_ptr<expr_t> mana; if (!parse_expression(s._list[1], mana)) return false; @@ -661,10 +663,10 @@ namespace magic_v2 out->s.s_mana = mana; return true; } - if (cmd == "CASTTIME") + if (cmd == "CASTTIME"_s) { if (s._list.size() != 2) - return fail(s, "not one argument"); + return fail(s, "not one argument"_s); dumb_ptr<expr_t> casttime; if (!parse_expression(s._list[1], casttime)) return false; @@ -672,7 +674,7 @@ namespace magic_v2 out->s.s_casttime = casttime; return true; } - if (cmd == "CATALYSTS") + if (cmd == "CATALYSTS"_s) { dumb_ptr<component_t> items = nullptr; for (auto it = s._list.begin() + 1, end = s._list.end(); it != end; ++it) @@ -686,7 +688,7 @@ namespace magic_v2 out->s.s_catalysts = items; return true; } - if (cmd == "COMPONENTS") + if (cmd == "COMPONENTS"_s) { dumb_ptr<component_t> items = nullptr; for (auto it = s._list.begin() + 1, end = s._list.end(); it != end; ++it) @@ -700,7 +702,7 @@ namespace magic_v2 out->s.s_components = items; return true; } - return fail(s._list[0], "unknown guard"); + return fail(s._list[0], "unknown guard"_s); } static @@ -727,25 +729,25 @@ namespace magic_v2 bool parse_effect(const SExpr& s, dumb_ptr<effect_t>& out) { if (s._type != sexpr::LIST) - return fail(s, "not list"); + return fail(s, "not list"_s); if (s._list.empty()) - return fail(s, "empty list"); + return fail(s, "empty list"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "not token"); + return fail(s._list[0], "not token"_s); ZString cmd = s._list[0]._str; - if (cmd == "BLOCK") + if (cmd == "BLOCK"_s) { return build_effect_list(s._list.begin() + 1, s._list.end(), out); } - if (cmd == "SET") + if (cmd == "SET"_s) { if (s._list.size() != 3) - return fail(s, "not 2 args"); + return fail(s, "not 2 args"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "not token"); + return fail(s._list[1], "not token"_s); ZString name = s._list[1]._str; if (find_constant(name)) - return fail(s._list[1], "assigning to constant"); + return fail(s._list[1], "assigning to constant"_s); dumb_ptr<expr_t> expr; if (!parse_expression(s._list[2], expr)) return false; @@ -755,72 +757,72 @@ namespace magic_v2 out->e.e_assign.expr = expr; return true; } - if (cmd == "SCRIPT") + if (cmd == "SCRIPT"_s) { if (s._list.size() != 2) - return fail(s, "not 1 arg"); + return fail(s, "not 1 arg"_s); if (s._list[1]._type != sexpr::STRING) - return fail(s._list[1], "not string"); + return fail(s._list[1], "not string"_s); ZString body = s._list[1]._str; std::unique_ptr<const ScriptBuffer> script = parse_script(body, s._list[1]._span.begin.line, true); if (!script) - return fail(s._list[1], "script does not compile"); + return fail(s._list[1], "script does not compile"_s); out = new_effect(EFFECT::SCRIPT); out->e.e_script = dumb_ptr<const ScriptBuffer>(script.release()); return true; } - if (cmd == "SKIP") + if (cmd == "SKIP"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::SKIP); return true; } - if (cmd == "ABORT") + if (cmd == "ABORT"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::ABORT); return true; } - if (cmd == "END") + if (cmd == "END"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::END); return true; } - if (cmd == "BREAK") + if (cmd == "BREAK"_s) { if (s._list.size() != 1) - return fail(s, "not 0 arg"); + return fail(s, "not 0 arg"_s); out = new_effect(EFFECT::BREAK); return true; } - if (cmd == "FOREACH") + if (cmd == "FOREACH"_s) { if (s._list.size() != 5) - return fail(s, "not 4 arg"); + return fail(s, "not 4 arg"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "foreach type not token"); + return fail(s._list[1], "foreach type not token"_s); ZString type = s._list[1]._str; FOREACH_FILTER filter; - if (type == "PC") + if (type == "PC"_s) filter = FOREACH_FILTER::PC; - else if (type == "MOB") + else if (type == "MOB"_s) filter = FOREACH_FILTER::MOB; - else if (type == "ENTITY") + else if (type == "ENTITY"_s) filter = FOREACH_FILTER::ENTITY; - else if (type == "SPELL") + else if (type == "SPELL"_s) filter = FOREACH_FILTER::SPELL; - else if (type == "TARGET") + else if (type == "TARGET"_s) filter = FOREACH_FILTER::TARGET; - else if (type == "NPC") + else if (type == "NPC"_s) filter = FOREACH_FILTER::NPC; else - return fail(s._list[1], "unknown foreach filter"); + return fail(s._list[1], "unknown foreach filter"_s); if (s._list[2]._type != sexpr::TOKEN) - return fail(s._list[2], "foreach var not token"); + return fail(s._list[2], "foreach var not token"_s); ZString var = s._list[2]._str; dumb_ptr<expr_t> area; dumb_ptr<effect_t> effect; @@ -835,12 +837,12 @@ namespace magic_v2 out->e.e_foreach.filter = filter; return true; } - if (cmd == "FOR") + if (cmd == "FOR"_s) { if (s._list.size() != 5) - return fail(s, "not 4 arg"); + return fail(s, "not 4 arg"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "for var not token"); + return fail(s._list[1], "for var not token"_s); ZString var = s._list[1]._str; dumb_ptr<expr_t> low; dumb_ptr<expr_t> high; @@ -858,10 +860,10 @@ namespace magic_v2 out->e.e_for.body = effect; return true; } - if (cmd == "IF") + if (cmd == "IF"_s) { if (s._list.size() != 3 && s._list.size() != 4) - return fail(s, "not 2 or 3 args"); + return fail(s, "not 2 or 3 args"_s); dumb_ptr<expr_t> cond; dumb_ptr<effect_t> if_true; dumb_ptr<effect_t> if_false; @@ -882,10 +884,10 @@ namespace magic_v2 out->e.e_if.false_branch = if_false; return true; } - if (cmd == "WAIT") + if (cmd == "WAIT"_s) { if (s._list.size() != 2) - return fail(s, "not 1 arg"); + return fail(s, "not 1 arg"_s); dumb_ptr<expr_t> expr; if (!parse_expression(s._list[1], expr)) return false; @@ -893,12 +895,12 @@ namespace magic_v2 out->e.e_sleep = expr; return true; } - if (cmd == "CALL") + if (cmd == "CALL"_s) { if (s._list.size() < 2) - return fail(s, "call what?"); + return fail(s, "call what?"_s); if (s._list[1]._type != sexpr::TOKEN) - return fail(s._list[1], "call token please"); + return fail(s._list[1], "call token please"_s); ZString func = s._list[1]._str; auto argvp = dumb_ptr<std::vector<dumb_ptr<expr_t>>>::make(); for (auto it = s._list.begin() + 2, end = s._list.end(); it != end; ++it) @@ -925,16 +927,16 @@ namespace magic_v2 bool parse_spellbody(const SExpr& s, dumb_ptr<spellguard_t>& out) { if (s._type != sexpr::LIST) - return fail(s, "not list"); + return fail(s, "not list"_s); if (s._list.empty()) - return fail(s, "empty list"); + return fail(s, "empty list"_s); if (s._list[0]._type != sexpr::TOKEN) - return fail(s._list[0], "not token"); + return fail(s._list[0], "not token"_s); ZString cmd = s._list[0]._str; - if (cmd == "=>") + if (cmd == "=>"_s) { if (s._list.size() != 3) - return fail(s, "list does not have exactly 2 arguments"); + return fail(s, "list does not have exactly 2 arguments"_s); dumb_ptr<spellguard_t> guard; if (!parse_spellguard(s._list[1], guard)) return false; @@ -944,10 +946,10 @@ namespace magic_v2 out = spellguard_implication(guard, body); return true; } - if (cmd == "|") + if (cmd == "|"_s) { if (s._list.size() == 1) - return fail(s, "spellbody choice empty"); + return fail(s, "spellbody choice empty"_s); auto begin = s._list.begin() + 1; auto end = s._list.end(); if (!parse_spellbody(*begin, out)) @@ -965,7 +967,7 @@ namespace magic_v2 } return true; } - if (cmd == "EFFECT") + if (cmd == "EFFECT"_s) { auto begin = s._list.begin() + 1; auto end = s._list.end(); @@ -978,7 +980,7 @@ namespace magic_v2 --end; if (end[-1]._type == sexpr::LIST && !end[-1]._list.empty() && end[-1]._list[0]._type == sexpr::TOKEN - && end[-1]._list[0]._str == "ATEND") + && end[-1]._list[0]._str == "ATEND"_s) { auto atb = end[-1]._list.begin() + 1; auto ate = end[-1]._list.end(); @@ -995,7 +997,7 @@ namespace magic_v2 } if (end[-1]._type == sexpr::LIST && !end[-1]._list.empty() && end[-1]._list[0]._type == sexpr::TOKEN - && end[-1]._list[0]._str == "ATTRIGGER") + && end[-1]._list[0]._str == "ATTRIGGER"_s) { auto atb = end[-1]._list.begin() + 1; auto ate = end[-1]._list.end(); @@ -1015,20 +1017,20 @@ namespace magic_v2 out->s.s_effect.at_end = atend; return true; } - return fail(s._list[0], "unknown spellbody"); + return fail(s._list[0], "unknown spellbody"_s); } static bool parse_top_set(const std::vector<SExpr>& in) { if (in.size() != 3) - return fail(in[0], "not 2 arguments"); + return fail(in[0], "not 2 arguments"_s); ZString name = in[1]._str; dumb_ptr<expr_t> expr; if (!parse_expression(in[2], expr)) return false; if (find_constant(name)) - return fail(in[1], "assign constant"); + return fail(in[1], "assign constant"_s); size_t var_id = intern_id(name); magic_eval(dumb_ptr<env_t>(&magic_default_env), &magic_conf.varv[var_id].val, expr); return true; @@ -1037,9 +1039,9 @@ namespace magic_v2 bool parse_const(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() != 3) - return fail(in[0], "not 2 arguments"); + return fail(in[0], "not 2 arguments"_s); if (in[1]._type != sexpr::TOKEN) - return fail(in[1], "not token"); + return fail(in[1], "not token"_s); ZString name = in[1]._str; dumb_ptr<expr_t> expr; if (!parse_expression(in[2], expr)) @@ -1052,13 +1054,13 @@ namespace magic_v2 bool parse_anchor(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() != 4) - return fail(in[0], "not 3 arguments"); + return fail(in[0], "not 3 arguments"_s); auto anchor = dumb_ptr<teleport_anchor_t>::make(); if (in[1]._type != sexpr::TOKEN) - return fail(in[1], "not token"); + return fail(in[1], "not token"_s); anchor->name = in[1]._str; if (in[2]._type != sexpr::STRING) - return fail(in[2], "not string"); + return fail(in[2], "not string"_s); anchor->invocation = in[2]._str; dumb_ptr<expr_t> expr; if (!parse_expression(in[3], expr)) @@ -1070,17 +1072,17 @@ namespace magic_v2 bool parse_proc(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() < 4) - return fail(in[0], "not at least 3 arguments"); + return fail(in[0], "not at least 3 arguments"_s); auto proc = dumb_ptr<proc_t>::make(); if (in[1]._type != sexpr::TOKEN) - return fail(in[1], "name not token"); + return fail(in[1], "name not token"_s); proc->name = in[1]._str; if (in[2]._type != sexpr::LIST) - return fail(in[2], "args not list"); + return fail(in[2], "args not list"_s); for (const SExpr& arg : in[2]._list) { if (arg._type != sexpr::TOKEN) - return fail(arg, "arg not token"); + return fail(arg, "arg not token"_s); proc->argv.push_back(intern_id(arg._str)); } if (!build_effect_list(in.begin() + 3, in.end(), proc->body)) @@ -1091,37 +1093,37 @@ namespace magic_v2 bool parse_spell(io::LineSpan span, const std::vector<SExpr>& in) { if (in.size() < 6) - return fail(in[0], "not at least 5 arguments"); + return fail(in[0], "not at least 5 arguments"_s); if (in[1]._type != sexpr::LIST) - return fail(in[1], "flags not list"); + return fail(in[1], "flags not list"_s); auto spell = dumb_ptr<spell_t>::make(); for (const SExpr& s : in[1]._list) { if (s._type != sexpr::TOKEN) - return fail(s, "flag not token"); + return fail(s, "flag not token"_s); SPELL_FLAG flag = SPELL_FLAG::ZERO; - if (s._str == "LOCAL") + if (s._str == "LOCAL"_s) flag = SPELL_FLAG::LOCAL; - else if (s._str == "NONMAGIC") + else if (s._str == "NONMAGIC"_s) flag = SPELL_FLAG::NONMAGIC; - else if (s._str == "SILENT") + else if (s._str == "SILENT"_s) flag = SPELL_FLAG::SILENT; else - return fail(s, "unknown flag"); + return fail(s, "unknown flag"_s); if (bool(spell->flags & flag)) - return fail(s, "duplicate flag"); + return fail(s, "duplicate flag"_s); spell->flags |= flag; } if (in[2]._type != sexpr::TOKEN) - return fail(in[2], "name not token"); + return fail(in[2], "name not token"_s); spell->name = in[2]._str; if (in[3]._type != sexpr::STRING) - return fail(in[3], "invoc not string"); + return fail(in[3], "invoc not string"_s); spell->invocation = in[3]._str; if (in[4]._type != sexpr::LIST) - return fail(in[4], "spellarg not list"); + return fail(in[4], "spellarg not list"_s); if (in[4]._list.size() == 0) { spell->spellarg_ty = SPELLARG::NONE; @@ -1129,18 +1131,18 @@ namespace magic_v2 else { if (in[4]._list.size() != 2) - return fail(in[4], "spellarg not empty list or pair"); + return fail(in[4], "spellarg not empty list or pair"_s); if (in[4]._list[0]._type != sexpr::TOKEN) - return fail(in[4]._list[0], "spellarg type not token"); + return fail(in[4]._list[0], "spellarg type not token"_s); if (in[4]._list[1]._type != sexpr::TOKEN) - return fail(in[4]._list[1], "spellarg name not token"); + return fail(in[4]._list[1], "spellarg name not token"_s); ZString ty = in[4]._list[0]._str; - if (ty == "PC") + if (ty == "PC"_s) spell->spellarg_ty = SPELLARG::PC; - else if (ty == "STRING") + else if (ty == "STRING"_s) spell->spellarg_ty = SPELLARG::STRING; else - return fail(in[4]._list[0], "unknown spellarg type"); + return fail(in[4]._list[0], "unknown spellarg type"_s); ZString an = in[4]._list[1]._str; spell->arg = intern_id(an); } @@ -1148,19 +1150,19 @@ namespace magic_v2 for (;; ++it) { if (it == in.end()) - return fail(it[-1], "end of list scanning LET defs"); + return fail(it[-1], "end of list scanning LET defs"_s); if (is_comment(*it)) continue; if (it->_type != sexpr::LIST || it->_list.empty()) break; - if (it->_list[0]._type != sexpr::TOKEN || it->_list[0]._str != "LET") + if (it->_list[0]._type != sexpr::TOKEN || it->_list[0]._str != "LET"_s) break; if (it->_list[1]._type != sexpr::TOKEN) - return fail(it->_list[1], "let name not token"); + return fail(it->_list[1], "let name not token"_s); ZString name = it->_list[1]._str; if (find_constant(name)) - return fail(it->_list[1], "constant exists"); + return fail(it->_list[1], "constant exists"_s); dumb_ptr<expr_t> expr; if (!parse_expression(it->_list[2], expr)) return false; @@ -1170,7 +1172,7 @@ namespace magic_v2 spell->letdefv.push_back(let); } if (it + 1 != in.end()) - return fail(*it, "expected only one body entry besides LET"); + return fail(*it, "expected only one body entry besides LET"_s); // formally, 'guard' only refers to the first argument of '=>' // but internally, spellbodies use the same thing @@ -1186,23 +1188,23 @@ namespace magic_v2 { if (vs.empty()) { - span.error("Empty list at top"); + span.error("Empty list at top"_s); return false; } if (vs[0]._type != sexpr::TOKEN) - return fail(vs[0], "top not token"); + return fail(vs[0], "top not token"_s); ZString cmd = vs[0]._str; - if (cmd == "CONST") + if (cmd == "CONST"_s) return parse_const(span, vs); - if (cmd == "PROCEDURE") + if (cmd == "PROCEDURE"_s) return parse_proc(span, vs); - if (cmd == "SET") + if (cmd == "SET"_s) return parse_top_set(vs); - if (cmd == "SPELL") + if (cmd == "SPELL"_s) return parse_spell(span, vs); - if (cmd == "TELEPORT-ANCHOR") + if (cmd == "TELEPORT-ANCHOR"_s) return parse_anchor(span, vs); - return fail(vs[0], "Unknown top-level command"); + return fail(vs[0], "Unknown top-level command"_s); } static @@ -1214,14 +1216,14 @@ namespace magic_v2 if (is_comment(s)) continue; if (s._type != sexpr::LIST) - return fail(s, "top-level entity not a list or comment"); + return fail(s, "top-level entity not a list or comment"_s); if (!parse_top(s._span, s._list)) return false; } // handle low-level errors if (in.peek() != sexpr::TOK_EOF) { - in.span().error("parser gave up before end of file"); + in.span().error("parser gave up before end of file"_s); return false; } return true; @@ -1239,7 +1241,7 @@ bool load_magic_file_v2(ZString filename) bool rv = magic_v2::loop(in); if (!rv) { - in.span().error(STRPRINTF("next token: %s '%s'", sexpr::token_name(in.peek()), in.val_string())); + in.span().error(STRPRINTF("next token: %s '%s'"_fmt, sexpr::token_name(in.peek()), in.val_string())); } return rv; } diff --git a/src/map/magic.cpp b/src/map/magic.cpp index 9896b26..4ca5c4f 100644 --- a/src/map/magic.cpp +++ b/src/map/magic.cpp @@ -98,12 +98,12 @@ int magic_message(dumb_ptr<map_session_data> caster, XString source_invocation) effects = NULL; #ifdef DEBUG - FPRINTF(stderr, "Found spell `%s', triggered = %d\n", spell_, + FPRINTF(stderr, "Found spell `%s', triggered = %d\n"_fmt, spell_, effects != NULL); #endif - MAP_LOG_PC(caster, "CAST %s %s", - spell->name, effects ? "SUCCESS" : "FAILURE"); + MAP_LOG_PC(caster, "CAST %s %s"_fmt, + spell->name, effects ? "SUCCESS"_s : "FAILURE"_s); if (effects) { diff --git a/src/map/map.cpp b/src/map/map.cpp index b49b225..7c14e9e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -100,9 +100,9 @@ int first_free_object_id = 0, last_object_id = 0; interval_t autosave_time = DEFAULT_AUTOSAVE_INTERVAL; int save_settings = 0xFFFF; -AString motd_txt = "conf/motd.txt"; +AString motd_txt = "conf/motd.txt"_s; -CharName wisp_server_name = stringish<CharName>("Server"); // can be modified in char-server configuration file +CharName wisp_server_name = stringish<CharName>("Server"_s); // can be modified in char-server configuration file static void map_delmap(MapName mapname); @@ -186,7 +186,7 @@ int map_addblock(dumb_ptr<block_list> bl) if (bl->bl_prev) { if (battle_config.error_log) - PRINTF("map_addblock error : bl->bl_prev!=NULL\n"); + PRINTF("map_addblock error : bl->bl_prev!=NULL\n"_fmt); return 0; } @@ -235,7 +235,7 @@ int map_delblock(dumb_ptr<block_list> bl) { // prevがNULLでnextがNULLでないのは有ってはならない if (battle_config.error_log) - PRINTF("map_delblock error : bl->bl_next!=NULL\n"); + PRINTF("map_delblock error : bl->bl_next!=NULL\n"_fmt); } return 0; } @@ -538,7 +538,7 @@ int map_addobject(dumb_ptr<block_list> bl) int i; if (!bl) { - PRINTF("map_addobject nullpo?\n"); + PRINTF("map_addobject nullpo?\n"_fmt); return 0; } if (first_free_object_id < 2 || first_free_object_id >= MAX_FLOORITEM) @@ -549,7 +549,7 @@ int map_addobject(dumb_ptr<block_list> bl) if (i >= MAX_FLOORITEM) { if (battle_config.error_log) - PRINTF("no free object id\n"); + PRINTF("no free object id\n"_fmt); return 0; } first_free_object_id = i; @@ -573,7 +573,7 @@ int map_delobjectnofree(int id, BL type) if (object[id]->bl_type != type) { - FPRINTF(stderr, "Incorrect type: expected %d, got %d\n", + FPRINTF(stderr, "Incorrect type: expected %d, got %d\n"_fmt, type, object[id]->bl_type); abort(); @@ -1052,7 +1052,7 @@ int map_addnpc(map_local *m, dumb_ptr<npc_data> nd) if (i == MAX_NPC_PER_MAP) { if (battle_config.error_log) - PRINTF("too many NPCs in one map %s\n", m->name_); + PRINTF("too many NPCs in one map %s\n"_fmt, m->name_); return -1; } if (i == m->npc_num) @@ -1096,7 +1096,7 @@ void map_removenpc(void) } } } - PRINTF("%d NPCs removed.\n", n); + PRINTF("%d NPCs removed.\n"_fmt, n); } /*========================================== @@ -1244,7 +1244,7 @@ int map_setipport(MapName name, IP4Address ip, int port) // local -> check data if (ip != clif_getip() || port != clif_getport()) { - PRINTF("from char server : %s -> %s:%d\n", + PRINTF("from char server : %s -> %s:%d\n"_fmt, name, ip, port); return 1; } @@ -1275,7 +1275,7 @@ bool map_readmap(map_local *m, size_t num, MapName fn) int xs = m->xs = gat_v[0] | gat_v[1] << 8; int ys = m->ys = gat_v[2] | gat_v[3] << 8; - PRINTF("\rLoading Maps [%zu/%zu]: %-30s (%i, %i)", + PRINTF("\rLoading Maps [%zu/%zu]: %-30s (%i, %i)"_fmt, num, maps_db.size(), fn, xs, ys); fflush(stdout); @@ -1328,10 +1328,10 @@ bool map_readallmap(void) } } - PRINTF("\rMaps Loaded: %-65zu\n", maps_db.size()); + PRINTF("\rMaps Loaded: %-65zu\n"_fmt, maps_db.size()); if (maps_removed) { - PRINTF("Cowardly refusing to keep going after removing %d maps.\n", + PRINTF("Cowardly refusing to keep going after removing %d maps.\n"_fmt, maps_removed); return false; } @@ -1346,7 +1346,7 @@ bool map_readallmap(void) static void map_addmap(MapName mapname) { - if (mapname == "clear") + if (mapname == "clear"_s) { maps_db.clear(); return; @@ -1366,7 +1366,7 @@ void map_addmap(MapName mapname) */ void map_delmap(MapName mapname) { - if (mapname == "all") + if (mapname == "all"_s) { maps_db.clear(); return; @@ -1389,7 +1389,7 @@ void map_close_logfile(void) { if (map_logfile) { - AString filename = STRPRINTF("%s.%ld", map_logfile_name, map_logfile_index); + AString filename = STRPRINTF("%s.%ld"_fmt, map_logfile_name, map_logfile_index); const char *args[] = { "gzip", @@ -1416,7 +1416,7 @@ void map_start_logfile(long index) map_logfile_index = index; AString filename_buf = STRPRINTF( - "%s.%ld", + "%s.%ld"_fmt, map_logfile_name, map_logfile_index); map_logfile = make_unique<io::AppendFile>(filename_buf); @@ -1437,7 +1437,7 @@ void map_set_logfile(AString filename) map_start_logfile(tv.tv_sec >> LOGFILE_SECONDS_PER_CHUNK_SHIFT); - MAP_LOG("log-start v5"); + MAP_LOG("log-start v5"_fmt); } void map_log(XString line) @@ -1469,7 +1469,7 @@ bool map_config_read(ZString cfgName) io::ReadFile in(cfgName); if (!in.is_open()) { - PRINTF("Map configuration file not found at: %s\n", cfgName); + PRINTF("Map configuration file not found at: %s\n"_fmt, cfgName); return false; } @@ -1483,21 +1483,21 @@ bool map_config_read(ZString cfgName) ZString w2; if (!config_split(line, &w1, &w2)) { - PRINTF("Bad config line: %s\n", line); + PRINTF("Bad config line: %s\n"_fmt, line); rv = false; continue; } - if (w1 == "userid") + if (w1 == "userid"_s) { AccountName name = stringish<AccountName>(w2); chrif_setuserid(name); } - else if (w1 == "passwd") + else if (w1 == "passwd"_s) { AccountPass pass = stringish<AccountPass>(w2); chrif_setpasswd(pass); } - else if (w1 == "char_ip") + else if (w1 == "char_ip"_s) { h = gethostbyname(w2.c_str()); IP4Address w2ip; @@ -1509,21 +1509,21 @@ bool map_config_read(ZString cfgName) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Character server IP address : %s -> %s\n", + PRINTF("Character server IP address : %s -> %s\n"_fmt, w2, w2ip); } else { - PRINTF("Bad IP value: %s\n", line); + PRINTF("Bad IP value: %s\n"_fmt, line); return false; } chrif_setip(w2ip); } - else if (w1 == "char_port") + else if (w1 == "char_port"_s) { chrif_setport(atoi(w2.c_str())); } - else if (w1 == "map_ip") + else if (w1 == "map_ip"_s) { h = gethostbyname(w2.c_str()); IP4Address w2ip; @@ -1535,61 +1535,61 @@ bool map_config_read(ZString cfgName) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Map server IP address : %s -> %s\n", + PRINTF("Map server IP address : %s -> %s\n"_fmt, w2, w2ip); } else { - PRINTF("Bad IP value: %s\n", line); + PRINTF("Bad IP value: %s\n"_fmt, line); return false; } clif_setip(w2ip); } - else if (w1 == "map_port") + else if (w1 == "map_port"_s) { clif_setport(atoi(w2.c_str())); } - else if (w1 == "map") + else if (w1 == "map"_s) { MapName name = VString<15>(w2); map_addmap(name); } - else if (w1 == "delmap") + else if (w1 == "delmap"_s) { MapName name = VString<15>(w2); map_delmap(name); } - else if (w1 == "npc") + else if (w1 == "npc"_s) { npc_addsrcfile(w2); } - else if (w1 == "delnpc") + else if (w1 == "delnpc"_s) { npc_delsrcfile(w2); } - else if (w1 == "autosave_time") + else if (w1 == "autosave_time"_s) { autosave_time = std::chrono::seconds(atoi(w2.c_str())); if (autosave_time <= interval_t::zero()) autosave_time = DEFAULT_AUTOSAVE_INTERVAL; } - else if (w1 == "motd_txt") + else if (w1 == "motd_txt"_s) { motd_txt = w2; } - else if (w1 == "mapreg_txt") + else if (w1 == "mapreg_txt"_s) { mapreg_txt = w2; } - else if (w1 == "gm_log") + else if (w1 == "gm_log"_s) { gm_log = std::move(w2); } - else if (w1 == "log_file") + else if (w1 == "log_file"_s) { map_set_logfile(w2); } - else if (w1 == "import") + else if (w1 == "import"_s) { rv &= map_config_read(w2); } @@ -1664,29 +1664,29 @@ int compare_item(struct item *a, struct item *b) static bool map_confs(XString key, ZString value) { - if (key == "map_conf") + if (key == "map_conf"_s) return map_config_read(value); - if (key == "battle_conf") + if (key == "battle_conf"_s) return battle_config_read(value); - if (key == "atcommand_conf") + if (key == "atcommand_conf"_s) return atcommand_config_read(value); - if (key == "item_db") + if (key == "item_db"_s) return itemdb_readdb(value); - if (key == "mob_db") + if (key == "mob_db"_s) return mob_readdb(value); - if (key == "mob_skill_db") + if (key == "mob_skill_db"_s) return mob_readskilldb(value); - if (key == "skill_db") + if (key == "skill_db"_s) return skill_readdb(value); - if (key == "magic_conf") + if (key == "magic_conf"_s) return load_magic_file_v2(value); - if (key == "resnametable") + if (key == "resnametable"_s) return load_resnametable(value); - if (key == "const_db") + if (key == "const_db"_s) return read_constdb(value); - PRINTF("unknown map conf key: %s\n", AString(key)); + PRINTF("unknown map conf key: %s\n"_fmt, AString(key)); return false; } @@ -1705,22 +1705,22 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [--write_atcommand_config outfile] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [--write_atcommand_config outfile] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } - else if (argvi == "--write-atcommand-config") + else if (argvi == "--write-atcommand-config"_s) { if (!argv) { - PRINTF("Missing argument\n"); + PRINTF("Missing argument\n"_fmt); exit(1); } ZString filename = argv.pop_front(); @@ -1729,7 +1729,7 @@ int do_init(Slice<ZString> argv) } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -1741,7 +1741,7 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-map.conf", map_confs); + runflag &= load_config_file("conf/tmwa-map.conf"_s, map_confs); battle_config_check(); runflag &= map_readallmap(); @@ -1758,9 +1758,9 @@ int do_init(Slice<ZString> argv) npc_event_do_oninit(); // npcのOnInitイベント実行 if (battle_config.pk_mode == 1) - PRINTF("The server is running in " SGR_BOLD SGR_RED "PK Mode" SGR_RESET "\n"); + PRINTF("The server is running in " SGR_BOLD SGR_RED "PK Mode" SGR_RESET "\n"_fmt); - PRINTF("The map-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n", + PRINTF("The map-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n"_fmt, clif_getport()); return 0; diff --git a/src/map/map.hpp b/src/map/map.hpp index 0cec5e8..6d945d0 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -91,7 +91,7 @@ struct NpcEvent friend VString<49> convert_for_printf(NpcEvent ev) { - return STRNPRINTF(50, "%s::%s", ev.npc, ev.label); + return STRNPRINTF(50, "%s::%s"_fmt, ev.npc, ev.label); } }; bool extract(XString str, NpcEvent *ev); @@ -623,7 +623,7 @@ void map_log(XString line); # define MAP_LOG_PC(sd, fmt, ...) \ MAP_LOG("PC%d %s:%d,%d " fmt, \ - sd->status_key.char_id, (sd->bl_m ? sd->bl_m->name_ : stringish<MapName>("undefined.gat")), sd->bl_x, sd->bl_y, ## __VA_ARGS__) + sd->status_key.char_id, (sd->bl_m ? sd->bl_m->name_ : stringish<MapName>("undefined.gat"_s)), sd->bl_x, sd->bl_y, ## __VA_ARGS__) // 床アイテム関連 void map_clearflooritem_timer(TimerData *, tick_t, int); diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp index b73cbdd..59b6ff4 100644 --- a/src/map/map.t.hpp +++ b/src/map/map.t.hpp @@ -103,6 +103,8 @@ enum class NpcSubtype : uint8_t SHOP, SCRIPT, MESSAGE, + + COUNT, }; enum class mob_stat diff --git a/src/map/mapflag.cpp b/src/map/mapflag.cpp index 51af30a..65126d9 100644 --- a/src/map/mapflag.cpp +++ b/src/map/mapflag.cpp @@ -40,41 +40,41 @@ bool extract<MapFlag, void, void>(XString str, MapFlag *mf) { const struct { - ZString str; + LString str; MapFlag id; } flags[] = { - //{ZString("alias"), MapFlag::ALIAS}, - //{ZString("nomemo"), MapFlag::NOMEMO}, - {ZString("noteleport"), MapFlag::NOTELEPORT}, - {ZString("noreturn"), MapFlag::NORETURN}, - {ZString("monster_noteleport"), MapFlag::MONSTER_NOTELEPORT}, - {ZString("nosave"), MapFlag::NOSAVE}, - //{ZString("nobranch"), MapFlag::NOBRANCH}, - {ZString("nopenalty"), MapFlag::NOPENALTY}, - {ZString("pvp"), MapFlag::PVP}, - {ZString("pvp_noparty"), MapFlag::PVP_NOPARTY}, - //{ZString("pvp_noguild"), MapFlag::PVP_NOGUILD}, - //{ZString("pvp_nightmaredrop"), MapFlag::PVP_NIGHTMAREDROP}, - {ZString("pvp_nocalcrank"), MapFlag::PVP_NOCALCRANK}, - //{ZString("gvg"), MapFlag::GVG}, - //{ZString("gvg_noparty"), MapFlag::GVG_NOPARTY}, - //{ZString("nozenypenalty"), MapFlag::NOZENYPENALTY}, - //{ZString("notrade"), MapFlag::NOTRADE}, - //{ZString("noskill"), MapFlag::NOSKILL}, - {ZString("nowarp"), MapFlag::NOWARP}, - {ZString("nowarpto"), MapFlag::NOWARPTO}, - {ZString("nopvp"), MapFlag::NOPVP}, - //{ZString("noicewall"), MapFlag::NOICEWALL}, - {ZString("snow"), MapFlag::SNOW}, - {ZString("fog"), MapFlag::FOG}, - {ZString("sakura"), MapFlag::SAKURA}, - {ZString("leaves"), MapFlag::LEAVES}, - {ZString("rain"), MapFlag::RAIN}, - {ZString("no_player_drops"), MapFlag::NO_PLAYER_DROPS}, - {ZString("town"), MapFlag::TOWN}, - {ZString("outside"), MapFlag::OUTSIDE}, - {ZString("resave"), MapFlag::RESAVE}, + //{"alias"_s, MapFlag::ALIAS}, + //{"nomemo"_s, MapFlag::NOMEMO}, + {"noteleport"_s, MapFlag::NOTELEPORT}, + {"noreturn"_s, MapFlag::NORETURN}, + {"monster_noteleport"_s, MapFlag::MONSTER_NOTELEPORT}, + {"nosave"_s, MapFlag::NOSAVE}, + //{"nobranch"_s, MapFlag::NOBRANCH}, + {"nopenalty"_s, MapFlag::NOPENALTY}, + {"pvp"_s, MapFlag::PVP}, + {"pvp_noparty"_s, MapFlag::PVP_NOPARTY}, + //{"pvp_noguild"_s, MapFlag::PVP_NOGUILD}, + //{"pvp_nightmaredrop"_s, MapFlag::PVP_NIGHTMAREDROP}, + {"pvp_nocalcrank"_s, MapFlag::PVP_NOCALCRANK}, + //{"gvg"_s, MapFlag::GVG}, + //{"gvg_noparty"_s, MapFlag::GVG_NOPARTY}, + //{"nozenypenalty"_s, MapFlag::NOZENYPENALTY}, + //{"notrade"_s, MapFlag::NOTRADE}, + //{"noskill"_s, MapFlag::NOSKILL}, + {"nowarp"_s, MapFlag::NOWARP}, + {"nowarpto"_s, MapFlag::NOWARPTO}, + {"nopvp"_s, MapFlag::NOPVP}, + //{"noicewall"_s, MapFlag::NOICEWALL}, + {"snow"_s, MapFlag::SNOW}, + {"fog"_s, MapFlag::FOG}, + {"sakura"_s, MapFlag::SAKURA}, + {"leaves"_s, MapFlag::LEAVES}, + {"rain"_s, MapFlag::RAIN}, + {"no_player_drops"_s, MapFlag::NO_PLAYER_DROPS}, + {"town"_s, MapFlag::TOWN}, + {"outside"_s, MapFlag::OUTSIDE}, + {"resave"_s, MapFlag::RESAVE}, }; for (auto& pair : flags) if (str == pair.str) diff --git a/src/map/mob.cpp b/src/map/mob.cpp index a96f829..2bf4ad1 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -322,7 +322,7 @@ int mob_gen_exp(mob_db_ *mob) * static_cast<double>(battle_config.base_exp_rate) / 100.); if (xp < 1) xp = 1; - PRINTF("Exp for mob '%s' generated: %d\n", mob->name, xp); + PRINTF("Exp for mob '%s' generated: %d\n"_fmt, mob->name, xp); return xp; } @@ -417,7 +417,7 @@ int mob_once_spawn(dumb_ptr<map_session_data> sd, } else if (x <= 0 || y <= 0) { - PRINTF("mob_once_spawn: ??\n"); + PRINTF("mob_once_spawn: ??\n"_fmt); } for (count = 0; count < amount; count++) @@ -948,7 +948,7 @@ void mob_timer(TimerData *, tick_t tick, int id, unsigned char data) break; default: if (battle_config.error_log == 1) - PRINTF("mob_timer : %d ?\n", + PRINTF("mob_timer : %d ?\n"_fmt, md->state.state); break; } @@ -1115,8 +1115,6 @@ int mob_spawn(int id) if (i >= 50) { - // if(battle_config.error_log==1) - // PRINTF("MOB spawn error %d @ %s\n",id,map[md->bl_m].name); Timer(tick + std::chrono::seconds(5), std::bind(mob_delayspawn, ph::_1, ph::_2, id) @@ -1718,7 +1716,7 @@ int mob_randomwalk(dumb_ptr<mob_data> md, tick_t tick) if (md->move_fail_count > 1000) { if (battle_config.error_log == 1) - PRINTF("MOB cant move. random spawn %d, mob_class = %d\n", + PRINTF("MOB cant move. random spawn %d, mob_class = %d\n"_fmt, md->bl_id, md->mob_class); md->move_fail_count = 0; mob_spawn(md->bl_id); @@ -2358,12 +2356,10 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, mvp_sd = sd; } -// if(battle_config.battle_log) -// PRINTF("mob_damage %d %d %d\n",md->hp,max_hp,damage); if (md->bl_prev == NULL) { if (battle_config.error_log == 1) - PRINTF("mob_damage : BlockError!!\n"); + PRINTF("mob_damage : BlockError!!\n"_fmt); return 0; } @@ -2425,7 +2421,7 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, if (master_bl && master_bl->bl_type == BL::PC) { MAP_LOG_PC(master_bl->is_player(), - "MOB-TO-MOB-DMG FROM MOB%d %d TO MOB%d %d FOR %d", + "MOB-TO-MOB-DMG FROM MOB%d %d TO MOB%d %d FOR %d"_fmt, md2->bl_id, md2->mob_class, md->bl_id, md->mob_class, damage); } @@ -2461,7 +2457,7 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, return 0; } - MAP_LOG("MOB%d DEAD", md->bl_id); + MAP_LOG("MOB%d DEAD"_fmt, md->bl_id); // ----- ここから死亡処理 ----- @@ -2742,7 +2738,6 @@ void mob_warpslave_sub(dumb_ptr<block_list> bl, int id, int x, int y) static int mob_warpslave(dumb_ptr<mob_data> md, int x, int y) { -//PRINTF("warp slave\n"); map_foreachinarea(std::bind(mob_warpslave_sub, ph::_1, md->bl_id, md->bl_x, md->bl_y), md->bl_m, x - AREA_SIZE, y - AREA_SIZE, @@ -2808,7 +2803,7 @@ int mob_warp(dumb_ptr<mob_data> md, map_local *m, int x, int y, BeingRemoveWhy t else { if (battle_config.error_log == 1) - PRINTF("MOB %d warp failed, mob_class = %d\n", md->bl_id, md->mob_class); + PRINTF("MOB %d warp failed, mob_class = %d\n"_fmt, md->bl_id, md->mob_class); } md->target_id = 0; // タゲを解除する @@ -2821,7 +2816,7 @@ int mob_warp(dumb_ptr<mob_data> md, map_local *m, int x, int y, BeingRemoveWhy t && i == 1000) { if (battle_config.battle_log == 1) - PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl_id, x, y, + PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n"_fmt, md->bl_id, x, y, md->mob_class); } @@ -3015,7 +3010,7 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) return; if ((md = mbl->is_mob()) == NULL) { - PRINTF("mobskill_castend_id nullpo mbl->bl_id:%d\n", mbl->bl_id); + PRINTF("mobskill_castend_id nullpo mbl->bl_id:%d\n"_fmt, mbl->bl_id); return; } if (md->bl_type != BL::MOB || md->bl_prev == NULL) @@ -3029,7 +3024,6 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) if ((bl = map_id2bl(md->skilltarget)) == NULL || bl->bl_prev == NULL) { //スキルターゲットが存在しない - //PRINTF("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了 return; } if (md->bl_m != bl->bl_m) @@ -3047,7 +3041,7 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick; if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill castend skill=%d, mob_class = %d\n", + PRINTF("MOB skill castend skill=%d, mob_class = %d\n"_fmt, md->skillid, md->mob_class); mob_stop_walking(md, 0); @@ -3098,7 +3092,7 @@ void mobskill_castend_pos(TimerData *, tick_t tick, int id) md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick; if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill castend skill=%d, mob_class = %d\n", + PRINTF("MOB skill castend skill=%d, mob_class = %d\n"_fmt, md->skillid, md->mob_class); mob_stop_walking(md, 0); } @@ -3148,7 +3142,7 @@ int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target, md->skilldelayup[ms - &mob_db[md->mob_class].skills.front()] = gettick(); if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n", + PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n"_fmt, target->bl_id, skill_id, skill_lv, static_cast<uint32_t>(casttime.count()), md->mob_class); @@ -3219,7 +3213,7 @@ int mobskill_use_pos(dumb_ptr<mob_data> md, md->state.skillcastcancel = ms->cancel; if (battle_config.monster_skill_log == 1) - PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n", + PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n"_fmt, skill_x, skill_y, skill_id, skill_lv, static_cast<uint32_t>(casttime.count()), md->mob_class); @@ -3384,8 +3378,8 @@ int mob_makedummymobdb(int mob_class) { int i; - SNPRINTF(mob_db[mob_class].name, 24, "mob%d", mob_class); - SNPRINTF(mob_db[mob_class].jname, 24, "mob%d", mob_class); + SNPRINTF(mob_db[mob_class].name, 24, "mob%d"_fmt, mob_class); + SNPRINTF(mob_db[mob_class].jname, 24, "mob%d"_fmt, mob_class); mob_db[mob_class].lv = 1; mob_db[mob_class].max_hp = 1000; mob_db[mob_class].max_sp = 1; @@ -3439,7 +3433,7 @@ bool mob_readdb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("Unable to read mob db: %s\n", filename); + PRINTF("Unable to read mob db: %s\n"_fmt, filename); return false; } AString line; @@ -3517,7 +3511,7 @@ bool mob_readdb(ZString filename) if (!okay || mob_class <= 1000 || mob_class > 2000) { - PRINTF("bad mob line: %s\n", line); + PRINTF("bad mob line: %s\n"_fmt, line); rv = false; continue; } @@ -3570,7 +3564,7 @@ bool mob_readdb(ZString filename) if (mob_db[mob_class].base_exp == 0) mob_db[mob_class].base_exp = mob_gen_exp(&mob_db[mob_class]); } - PRINTF("read %s done\n", filename); + PRINTF("read %s done\n"_fmt, filename); } return rv; } @@ -3580,15 +3574,15 @@ bool extract<MobSkillCondition, void, void>(XString str, MobSkillCondition *msc) { const struct { - ZString str; + LString str; MobSkillCondition id; } cond1[] = { - {ZString("always"), MobSkillCondition::MSC_ALWAYS}, - {ZString("myhpltmaxrate"), MobSkillCondition::MSC_MYHPLTMAXRATE}, - {ZString("notintown"), MobSkillCondition::MSC_NOTINTOWN}, - {ZString("slavelt"), MobSkillCondition::MSC_SLAVELT}, - {ZString("slavele"), MobSkillCondition::MSC_SLAVELE}, + {"always"_s, MobSkillCondition::MSC_ALWAYS}, + {"myhpltmaxrate"_s, MobSkillCondition::MSC_MYHPLTMAXRATE}, + {"notintown"_s, MobSkillCondition::MSC_NOTINTOWN}, + {"slavelt"_s, MobSkillCondition::MSC_SLAVELT}, + {"slavele"_s, MobSkillCondition::MSC_SLAVELE}, }; for (auto& pair : cond1) if (str == pair.str) @@ -3604,14 +3598,14 @@ bool extract<MobSkillState, void, void>(XString str, MobSkillState *mss) { const struct { - ZString str; + LString str; MobSkillState id; } state[] = { - {ZString("any"), MobSkillState::ANY}, - {ZString("idle"), MobSkillState::MSS_IDLE}, - {ZString("walk"), MobSkillState::MSS_WALK}, - {ZString("attack"), MobSkillState::MSS_ATTACK}, + {"any"_s, MobSkillState::ANY}, + {"idle"_s, MobSkillState::MSS_IDLE}, + {"walk"_s, MobSkillState::MSS_WALK}, + {"attack"_s, MobSkillState::MSS_ATTACK}, }; for (auto& pair : state) if (str == pair.str) @@ -3627,12 +3621,12 @@ bool extract<MobSkillTarget, void, void>(XString str, MobSkillTarget *mst) { const struct { - ZString str; + LString str; MobSkillTarget id; } target[] = { - {ZString("target"), MobSkillTarget::MST_TARGET}, - {ZString("self"), MobSkillTarget::MST_SELF}, + {"target"_s, MobSkillTarget::MST_TARGET}, + {"self"_s, MobSkillTarget::MST_SELF}, }; for (auto& pair : target) if (str == pair.str) @@ -3650,7 +3644,7 @@ bool mob_readskilldb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } AString line; @@ -3662,7 +3656,7 @@ bool mob_readskilldb(ZString filename) continue; XString blah; - if (extract(line, record<','>(&mob_id, &blah)) && mob_id > 0 && blah == "clear") + if (extract(line, record<','>(&mob_id, &blah)) && mob_id > 0 && blah == "clear"_s) { mob_db[mob_id].skills.clear(); continue; @@ -3699,9 +3693,9 @@ bool mob_readskilldb(ZString filename) ) ) continue; - if (cancellable == "yes") + if (cancellable == "yes"_s) msv.cancel = true; - else if (cancellable == "no") + else if (cancellable == "no"_s) msv.cancel = false; else { @@ -3720,7 +3714,7 @@ bool mob_readskilldb(ZString filename) mob_db[mob_id].skills.push_back(std::move(msv)); } - PRINTF("read %s done\n", filename); + PRINTF("read %s done\n"_fmt, filename); } return rv; } diff --git a/src/map/mob.hpp b/src/map/mob.hpp index e7d81bd..570b5a9 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -34,9 +34,9 @@ # include "map.hpp" # include "skill.t.hpp" -# define ENGLISH_NAME stringish<MobName>("--en--") -# define JAPANESE_NAME stringish<MobName>("--ja--") -# define MOB_THIS_MAP stringish<MapName>("this") +# define ENGLISH_NAME stringish<MobName>("--en--"_s) +# define JAPANESE_NAME stringish<MobName>("--ja--"_s) +# define MOB_THIS_MAP stringish<MapName>("this"_s) struct mob_skill { diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 7fe13f1..3cef7c0 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -107,7 +107,7 @@ void npc_enable_sub(dumb_ptr<block_list> bl, dumb_ptr<npc_data> nd) NpcEvent aname; aname.npc = nd->name; - aname.label = stringish<ScriptLabel>("OnTouch"); + aname.label = stringish<ScriptLabel>("OnTouch"_s); if (sd->areanpc_id == nd->bl_id) return; sd->areanpc_id = nd->bl_id; @@ -120,7 +120,7 @@ int npc_enable(NpcName name, bool flag) dumb_ptr<npc_data> nd = npc_name2id(name); if (nd == NULL) { - PRINTF("npc_enable(%s, %s) failed.\n", name, flag ? "true" : "false"); + PRINTF("npc_enable(%s, %s) failed.\n"_fmt, name, flag ? "true"_s : "false"_s); return 0; } @@ -175,7 +175,7 @@ int npc_event_dequeue(dumb_ptr<map_session_data> sd) { if (!pc_addeventtimer(sd, std::chrono::milliseconds(100), sd->eventqueuel.front())) { - PRINTF("npc_event_dequeue(): Event timer is full.\n"); + PRINTF("npc_event_dequeue(): Event timer is full.\n"_fmt); return 0; } @@ -206,7 +206,7 @@ void npc_timer_event(NpcEvent eventname) if ((ev == NULL || (nd = ev->nd) == NULL)) { - PRINTF("npc_event: event not found [%s]\n", + PRINTF("npc_event: event not found [%s]\n"_fmt, eventname); return; } @@ -283,19 +283,19 @@ void npc_event_do_clock(TimerData *, tick_t) ScriptLabel buf; if (t.tm_min != ev_tm_b.tm_min) { - SNPRINTF(buf, 24, "OnMinute%02d", t.tm_min); + SNPRINTF(buf, 24, "OnMinute%02d"_fmt, t.tm_min); npc_event_doall(buf); - SNPRINTF(buf, 24, "OnClock%02d%02d", t.tm_hour, t.tm_min); + SNPRINTF(buf, 24, "OnClock%02d%02d"_fmt, t.tm_hour, t.tm_min); npc_event_doall(buf); } if (t.tm_hour != ev_tm_b.tm_hour) { - SNPRINTF(buf, 24, "OnHour%02d", t.tm_hour); + SNPRINTF(buf, 24, "OnHour%02d"_fmt, t.tm_hour); npc_event_doall(buf); } if (t.tm_mday != ev_tm_b.tm_mday) { - SNPRINTF(buf, 24, "OnDay%02d%02d", t.tm_mon + 1, t.tm_mday); + SNPRINTF(buf, 24, "OnDay%02d%02d"_fmt, t.tm_mon + 1, t.tm_mday); npc_event_doall(buf); } ev_tm_b = t; @@ -307,8 +307,8 @@ void npc_event_do_clock(TimerData *, tick_t) */ int npc_event_do_oninit(void) { - int c = npc_event_doall(stringish<ScriptLabel>("OnInit")); - PRINTF("npc: OnInit Event done. (%d npc)\n", c); + int c = npc_event_doall(stringish<ScriptLabel>("OnInit"_s)); + PRINTF("npc: OnInit Event done. (%d npc)\n"_fmt, c); Timer(gettick() + std::chrono::milliseconds(100), npc_event_do_clock, @@ -463,10 +463,10 @@ int npc_event(dumb_ptr<map_session_data> sd, NpcEvent eventname, if (sd == NULL) { - PRINTF("npc_event nullpo?\n"); + PRINTF("npc_event nullpo?\n"_fmt); } - if (ev == NULL && eventname.label == stringish<ScriptLabel>("OnTouch")) + if (ev == NULL && eventname.label == stringish<ScriptLabel>("OnTouch"_s)) return 1; if (ev == NULL || (nd = ev->nd) == NULL) @@ -480,7 +480,7 @@ int npc_event(dumb_ptr<map_session_data> sd, NpcEvent eventname, else { if (battle_config.error_log) - PRINTF("npc_event: event not found [%s]\n", + PRINTF("npc_event: event not found [%s]\n"_fmt, eventname); return 0; } @@ -521,7 +521,7 @@ static void npc_command_sub(NpcEvent key, struct event_data *ev, NpcName npcname, XString command) { if (ev->nd->name == npcname - && key.label.startswith("OnCommand")) + && key.label.startswith("OnCommand"_s)) { XString temp = key.label.xslice_t(9); @@ -567,7 +567,7 @@ int npc_touch_areanpc(dumb_ptr<map_session_data> sd, map_local *m, int x, int y) ys = m->npc[i]->is_warp()->warp.ys; break; case NpcSubtype::MESSAGE: - assert (0 && "I'm pretty sure these are never put on a map"); + assert (0 && "I'm pretty sure these are never put on a map"_s); xs = 0; ys = 0; break; @@ -589,7 +589,7 @@ int npc_touch_areanpc(dumb_ptr<map_session_data> sd, map_local *m, int x, int y) if (f) { if (battle_config.error_log) - PRINTF("npc_touch_areanpc : some bug \n"); + PRINTF("npc_touch_areanpc : some bug \n"_fmt); } return 1; } @@ -601,13 +601,13 @@ int npc_touch_areanpc(dumb_ptr<map_session_data> sd, map_local *m, int x, int y) m->npc[i]->is_warp()->warp.x, m->npc[i]->is_warp()->warp.y, BeingRemoveWhy::GONE); break; case NpcSubtype::MESSAGE: - assert (0 && "I'm pretty sure these NPCs are never put on a map."); + assert (0 && "I'm pretty sure these NPCs are never put on a map."_s); break; case NpcSubtype::SCRIPT: { NpcEvent aname; aname.npc = m->npc[i]->name; - aname.label = stringish<ScriptLabel>("OnTouch"); + aname.label = stringish<ScriptLabel>("OnTouch"_s); if (sd->areanpc_id == m->npc[i]->bl_id) return 1; @@ -666,7 +666,7 @@ int npc_click(dumb_ptr<map_session_data> sd, int id) if (sd->npc_id != 0) { if (battle_config.error_log) - PRINTF("npc_click: npc_id != 0\n"); + PRINTF("npc_click: npc_id != 0\n"_fmt); return 1; } @@ -751,7 +751,7 @@ int npc_buysellsel(dumb_ptr<map_session_data> sd, int id, int type) if (nd->npc_subtype != NpcSubtype::SHOP) { if (battle_config.error_log) - PRINTF("no such shop npc : %d\n", id); + PRINTF("no such shop npc : %d\n"_fmt, id); sd->npc_id = 0; return 1; } @@ -927,7 +927,7 @@ void npc_clearsrcfile(void) */ void npc_addsrcfile(AString name) { - if (name == "clear") + if (name == "clear"_s) { npc_clearsrcfile(); return; @@ -942,7 +942,7 @@ void npc_addsrcfile(AString name) */ void npc_delsrcfile(XString name) { - if (name == "all") + if (name == "all"_s) { npc_clearsrcfile(); return; @@ -961,19 +961,19 @@ void npc_delsrcfile(XString name) static void register_npc_name(dumb_ptr<npc_data> nd) { - ZString types[4] = - { - {"WARP"}, - {"SHOP"}, - {"SCRIPT"}, - {"MESSAGE"}, - }; + earray<LString, NpcSubtype, NpcSubtype::COUNT> types //= + {{ + "WARP"_s, + "SHOP"_s, + "SCRIPT"_s, + "MESSAGE"_s, + }}; if (!nd->name) { if (nd->npc_subtype == NpcSubtype::MESSAGE) return; - PRINTF("WARNING: npc with no name:\n%s @ %s,%d,%d\n", - types[static_cast<int>(nd->npc_subtype)], + PRINTF("WARNING: npc with no name:\n%s @ %s,%d,%d\n"_fmt, + types[nd->npc_subtype], nd->bl_m->name_, nd->bl_x, nd->bl_y); return; } @@ -982,12 +982,12 @@ void register_npc_name(dumb_ptr<npc_data> nd) if (nd->npc_subtype != NpcSubtype::WARP || nd_old->npc_subtype != NpcSubtype::WARP) { - PRINTF("WARNING: replacing npc with name: %s\n", nd->name); - PRINTF("old: %s @ %s,%d,%d\n", - types[static_cast<int>(nd_old->npc_subtype)], + PRINTF("WARNING: replacing npc with name: %s\n"_fmt, nd->name); + PRINTF("old: %s @ %s,%d,%d\n"_fmt, + types[nd_old->npc_subtype], nd_old->bl_m->name_, nd_old->bl_x, nd_old->bl_y); - PRINTF("new: %s @ %s,%d,%d\n", - types[static_cast<int>(nd->npc_subtype)], + PRINTF("new: %s @ %s,%d,%d\n"_fmt, + types[nd->npc_subtype], nd->bl_m->name_, nd->bl_x, nd->bl_y); } } @@ -1009,7 +1009,7 @@ int npc_parse_warp(XString w1, XString, NpcName w3, XString w4) if (!extract(w1, record<','>(&mapname, &x, &y)) || !extract(w4, record<','>(&xs, &ys, &to_mapname, &to_x, &to_y))) { - PRINTF("bad warp line : %s\n", w3); + PRINTF("bad warp line : %s\n"_fmt, w3); return 1; } @@ -1059,7 +1059,6 @@ int npc_parse_warp(XString w1, XString, NpcName w3, XString w4) } } -// PRINTF("warp npc %s %d read done\n",mapname,nd->bl_id); npc_warp++; nd->bl_type = BL::NPC; nd->npc_subtype = NpcSubtype::WARP; @@ -1116,7 +1115,7 @@ int npc_parse_shop(XString w1, XString, NpcName w3, ZString w4a) || (w4comma = std::find(w4a.begin(), w4a.end(), ',')) == w4a.end() || !extract(w4a.xislice_h(w4comma), &npc_class)) { - PRINTF("bad shop line : %s\n", w3); + PRINTF("bad shop line : %s\n"_fmt, w3); return 1; } dir = static_cast<DIR>(dir_); @@ -1127,8 +1126,8 @@ int npc_parse_shop(XString w1, XString, NpcName w3, ZString w4a) if (!extract(w4b, vrec<','>(&nd->shop_items))) { - PRINTF("bad shop items : %s\n", w3); - PRINTF(" somewhere --> %s\n", w4b); + PRINTF("bad shop items : %s\n"_fmt, w3); + PRINTF(" somewhere --> %s\n"_fmt, w4b); nd->shop_items.clear(); } @@ -1196,7 +1195,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, dumb_ptr<npc_data_script> nd; int evflag = 0; - if (w1 == "-") + if (w1 == "-"_s) { x = 0; y = 0; @@ -1207,16 +1206,16 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, int dir_; // TODO use enum directly in extract if (!extract(w1, record<','>(&mapname, &x, &y, &dir_)) || dir_ < 0 || dir_ >= 8 - || (w2 == "script" && !w4.contains(','))) + || (w2 == "script"_s && !w4.contains(','))) { - PRINTF("bad script line : %s\n", w3); + PRINTF("bad script line : %s\n"_fmt, w3); return 1; } dir = static_cast<DIR>(dir_); m = map_mapname2mapid(mapname); } - if (w2 == "script") + if (w2 == "script"_s) { // may be empty MString srcbuf; @@ -1255,7 +1254,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, } else { - assert(0 && "duplicate() is no longer supported!\n"); + assert(0 && "duplicate() is no longer supported!\n"_s); return 0; } @@ -1307,7 +1306,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, if (w3.contains(':')) { - assert(false && "feature removed"); + assert(false && "feature removed"_s); abort(); } { @@ -1329,7 +1328,6 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, nd->opt2 = Opt2::ZERO; nd->opt3 = Opt3::ZERO; - //PRINTF("script npc %s %d %d read done\n",mapname,nd->bl_id,nd->class); npc_script++; nd->bl_type = BL::NPC; nd->npc_subtype = NpcSubtype::SCRIPT; @@ -1361,7 +1359,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, ScriptLabel lname = el.name; int pos = el.pos; - if (lname.startswith("On")) + if (lname.startswith("On"_s)) { struct event_data ev {}; ev.nd = nd; @@ -1380,7 +1378,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, int t_ = 0; ScriptLabel lname = el.name; int pos = el.pos; - if (lname.startswith("OnTimer") && extract(lname.xslice_t(7), &t_) && t_ > 0) + if (lname.startswith("OnTimer"_s) && extract(lname.xslice_t(7), &t_) && t_ > 0) { interval_t t = static_cast<interval_t>(t_); @@ -1469,7 +1467,7 @@ int npc_parse_mob(XString w1, XString, MobName w3, ZString w4) if (!extract(w1, record<',', 3>(&mapname, &x, &y, &xs, &ys)) || !extract(w4, record<',', 2>(&mob_class, &num, &delay1_, &delay2_, &eventname))) { - PRINTF("bad monster line : %s\n", w3); + PRINTF("bad monster line : %s\n"_fmt, w3); return 1; } interval_t delay1 = std::chrono::milliseconds(delay1_); @@ -1525,7 +1523,6 @@ int npc_parse_mob(XString w1, XString, MobName w3, ZString w4) npc_mob++; } - //PRINTF("warp npc %s %d read done\n",mapname,nd->bl_id); return 0; } @@ -1561,9 +1558,9 @@ int npc_parse_mapflag(XString w1, XString, XString w3, ZString w4) if (mf == MapFlag::NOSAVE) { - if (w4 == "SavePoint") + if (w4 == "SavePoint"_s) { - m->save.map_ = stringish<MapName>("SavePoint"); + m->save.map_ = stringish<MapName>("SavePoint"_s); m->save.x = -1; m->save.y = -1; } @@ -1679,11 +1676,11 @@ bool do_init_npc(void) io::ReadFile fp(nsl); if (!fp.is_open()) { - PRINTF("file not found : %s\n", nsl); + PRINTF("file not found : %s\n"_fmt, nsl); rv = false; continue; } - PRINTF("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM, + PRINTF("\rLoading NPCs [%d]: %-54s"_fmt, npc_id - START_NPC_NUM, nsl); int lines = 0; AString zline; @@ -1698,7 +1695,7 @@ bool do_init_npc(void) if (!extract(zline, record<'|', 3>(&w1, &w2, &w3, &w4x)) || !w1 || !w2 || !w3) { - FPRINTF(stderr, "%s:%d: Broken script line: %s\n", nsl, lines, zline); + FPRINTF(stderr, "%s:%d: Broken script line: %s\n"_fmt, nsl, lines, zline); rv = false; continue; } @@ -1708,7 +1705,7 @@ bool do_init_npc(void) } assert(bool(w4x) == bool(w4z)); - if (w1 != "-" && w1 != "function") + if (w1 != "-"_s && w1 != "function"_s) { auto comma = std::find(w1.begin(), w1.end(), ','); MapName mapname = stringish<MapName>(w1.xislice_h(comma)); @@ -1716,24 +1713,24 @@ bool do_init_npc(void) if (m == nullptr) { // "mapname" is not assigned to this server - FPRINTF(stderr, "%s:%d: Map not found: %s\n", nsl, lines, mapname); + FPRINTF(stderr, "%s:%d: Map not found: %s\n"_fmt, nsl, lines, mapname); rv = false; continue; } } - if (w2 == "warp") + if (w2 == "warp"_s) { NpcName npcname = stringish<NpcName>(w3); npc_parse_warp(w1, w2, npcname, w4z); } - else if (w2 == "shop") + else if (w2 == "shop"_s) { NpcName npcname = stringish<NpcName>(w3); npc_parse_shop(w1, w2, npcname, w4z); } - else if (w2 == "script") + else if (w2 == "script"_s) { - if (w1 == "function") + if (w1 == "function"_s) { npc_parse_function(w1, w2, w3, w4z, w4x, fp, &lines); @@ -1745,29 +1742,29 @@ bool do_init_npc(void) w4x, fp, &lines); } } - else if (w2 == "monster") + else if (w2 == "monster"_s) { MobName mobname = stringish<MobName>(w3); npc_parse_mob(w1, w2, mobname, w4z); } - else if (w2 == "mapflag") + else if (w2 == "mapflag"_s) { npc_parse_mapflag(w1, w2, w3, w4z); } else { - PRINTF("odd script line: %s\n", zline); + PRINTF("odd script line: %s\n"_fmt, zline); script_errors++; } } fflush(stdout); } - PRINTF("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d] %20s\n", - npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, ""); + PRINTF("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d] %20s\n"_fmt, + npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, ""_s); if (script_errors) { - PRINTF("Cowardly refusing to continue after %d errors\n", script_errors); + PRINTF("Cowardly refusing to continue after %d errors\n"_fmt, script_errors); rv = false; } return rv; diff --git a/src/map/party.cpp b/src/map/party.cpp index 75c54cf..876e6bb 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -121,7 +121,7 @@ void party_created(int account_id, int fail, int party_id, PartyName name) struct party *p = party_db.search(party_id); if (p != NULL) { - PRINTF("party_created(): ID already exists!\n"); + PRINTF("party_created(): ID already exists!\n"_fmt); exit(1); } @@ -177,7 +177,7 @@ int party_check_member(struct party *p) { sd->status.party_id = 0; if (battle_config.error_log) - PRINTF("party: check_member %d[%s] is not member\n", + PRINTF("party: check_member %d[%s] is not member\n"_fmt, sd->status_key.account_id, sd->status_key.name); } } @@ -355,7 +355,7 @@ int party_member_added(int party_id, int account_id, int flag) if (flag == 0) { if (battle_config.error_log) - PRINTF("party: member added error %d is not online\n", + PRINTF("party: member added error %d is not online\n"_fmt, account_id); intif_party_leave(party_id, account_id); // キャラ側に登録できなかったため脱退要求を出す } @@ -367,7 +367,7 @@ int party_member_added(int party_id, int account_id, int flag) if (p == NULL) { - PRINTF("party_member_added: party %d not found.\n", party_id); + PRINTF("party_member_added: party %d not found.\n"_fmt, party_id); intif_party_leave(party_id, account_id); return 0; } @@ -537,7 +537,7 @@ void party_recv_movemap(int party_id, int account_id, MapName mapname, struct party_member *m = &p->member[i]; if (m == NULL) { - PRINTF("party_recv_movemap nullpo?\n"); + PRINTF("party_recv_movemap nullpo?\n"_fmt); return; } if (m->account_id == account_id) @@ -551,7 +551,7 @@ void party_recv_movemap(int party_id, int account_id, MapName mapname, if (i == MAX_PARTY) { if (battle_config.error_log) - PRINTF("party: not found member %d on %d[%s]", account_id, + PRINTF("party: not found member %d on %d[%s]"_fmt, account_id, party_id, p->name); return; } diff --git a/src/map/path.cpp b/src/map/path.cpp index f0204a4..5b7ea1f 100644 --- a/src/map/path.cpp +++ b/src/map/path.cpp @@ -60,7 +60,7 @@ void push_heap_path(int *heap, struct tmp_path *tp, int index) if (heap == NULL || tp == NULL) { - PRINTF("push_heap_path nullpo\n"); + PRINTF("push_heap_path nullpo\n"_fmt); return; } @@ -90,7 +90,7 @@ void update_heap_path(int *heap, struct tmp_path *tp, int index) break; if (h == heap[0]) { - FPRINTF(stderr, "update_heap_path bug\n"); + FPRINTF(stderr, "update_heap_path bug\n"_fmt); exit(1); } for (i = (h - 1) / 2; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 0256eff..eecaece 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -86,7 +86,7 @@ constexpr int MAGIC_SKILL_THRESHOLD = 200; MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \ sd->status.base_level, sd->status.base_exp, \ sd->status.job_level, sd->status.job_exp, sd->status.skill_point, \ - sd->status.zeny, pc_readaccountreg(sd, stringish<VarName>("BankAccount"))) + sd->status.zeny, pc_readaccountreg(sd, stringish<VarName>("BankAccount"_s))) #define MAP_LOG_MAGIC(sd, suffix) \ MAP_LOG_PC(sd, "MAGIC %d %d %d %d %d %d EXP %d %d " suffix, \ @@ -96,8 +96,8 @@ constexpr int MAGIC_SKILL_THRESHOLD = 200; sd->status.skill[SkillID::TMW_MAGIC_TRANSMUTE].lv, \ sd->status.skill[SkillID::TMW_MAGIC_NATURE].lv, \ sd->status.skill[SkillID::TMW_MAGIC_ETHER].lv, \ - pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE")) & 0xffff, \ - (pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE")) >> 24) & 0xff) + pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE"_s)) & 0xffff, \ + (pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE"_s)) >> 24) & 0xff) static //const int max_weight_base_0 = 20000; @@ -458,7 +458,7 @@ void pc_makesavestatus(dumb_ptr<map_session_data> sd) if (sd->bl_m->flag.get(MapFlag::NOSAVE)) { map_local *m = sd->bl_m; - if (m->save.map_ == "SavePoint") + if (m->save.map_ == "SavePoint"_s) sd->status.last_point = sd->status.save_point; else sd->status.last_point = m->save; @@ -662,9 +662,9 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, return 1; } - MAP_LOG_STATS(sd, "LOGIN"); - MAP_LOG_XP(sd, "LOGIN"); - MAP_LOG_MAGIC(sd, "LOGIN"); + MAP_LOG_STATS(sd, "LOGIN"_fmt); + MAP_LOG_XP(sd, "LOGIN"_fmt); + MAP_LOG_MAGIC(sd, "LOGIN"_fmt); really_memzero_this(&sd->state); // 基本的な初期化 @@ -702,7 +702,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, // The above is no longer accurate now that we use <chrono>, but // I'm still not reverting this. // -o11c - sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK"); + sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK"_s); // アカウント変数の送信要求 intif_request_accountreg(sd); @@ -725,10 +725,10 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, // This would leak information. // It's better to make it obvious that players can see you. if (false && bool(old_option & Option::INVISIBILITY)) - is_atcommand(sd->sess, sd, "@invisible", 0); + is_atcommand(sd->sess, sd, "@invisible"_s, 0); if (bool(old_option & Option::HIDE)) - is_atcommand(sd->sess, sd, "@hide", 0); + is_atcommand(sd->sess, sd, "@hide"_s, 0); // atcommand_hide might already send it, but also might not clif_changeoption(sd); } @@ -765,19 +765,19 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, map_addchariddb(sd->status_key.char_id, sd->status_key.name); //スパノビ用死にカウンターのスクリプト変数からの読み出しとsdへのセット - sd->die_counter = pc_readglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER")); + sd->die_counter = pc_readglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"_s)); // ステータス初期計算など pc_calcstatus(sd, 1); if (pc_isGM(sd)) { - PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n", + PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n"_fmt, sd->status_key.name, sd->status_key.account_id, pc_isGM(sd)); clif_updatestatus(sd, SP::GM); } else - PRINTF("Connection accepted: Character '%s' (account: %d).\n", + PRINTF("Connection accepted: Character '%s' (account: %d).\n"_fmt, sd->status_key.name, sd->status_key.account_id); sd->auto_ban_info.in_progress = 0; @@ -796,11 +796,11 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, // message of the limited time of the account if (connect_until_time) { - // don't display if it's unlimited or unknow value - char tmpstr[] = WITH_TIMESTAMP("Your account time limit is: "); - REPLACE_TIMESTAMP(tmpstr, connect_until_time); + timestamp_seconds_buffer buffer; + stamp_time(buffer, &connect_until_time); + AString tmpstr = STRPRINTF("Your account time limit is: %s"_fmt, buffer); - clif_wis_message(sd->sess, wisp_server_name, const_(tmpstr)); + clif_wis_message(sd->sess, wisp_server_name, tmpstr); } pc_calcstatus(sd, 1); @@ -817,7 +817,7 @@ void pc_show_motd(dumb_ptr<map_session_data> sd) // If you remove the sending of this message, // the license does not permit you to publicly use this software. - clif_displaymessage(sd->sess, "This server is Free Software, for details type @source in chat or use the tmwa-source tool"); + clif_displaymessage(sd->sess, "This server is Free Software, for details type @source in chat or use the tmwa-source tool"_s); sd->state.seen_motd = true; io::ReadFile in(motd_txt); @@ -1099,8 +1099,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) { argrec_t arg[2] = { - {"@slotId", static_cast<int>(i)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(i)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0), sd->bl_id, 0, @@ -1113,8 +1113,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) //二刀流武器以外 argrec_t arg[2] = { - {"@slotId", static_cast<int>(i)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(i)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; sd->watk += sd->inventory_data[index]->atk; @@ -1128,8 +1128,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) { argrec_t arg[2] = { - {"@slotId", static_cast<int>(i)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(i)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; sd->watk += sd->inventory_data[index]->atk; run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0), @@ -1155,8 +1155,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) { //まだ属性が入っていない argrec_t arg[2] = { - {"@slotId", static_cast<int>(EQUIP::ARROW)}, - {"@itemId", sd->inventory_data[index]->nameid}, + {"@slotId"_s, static_cast<int>(EQUIP::ARROW)}, + {"@itemId"_s, sd->inventory_data[index]->nameid}, }; sd->state.lr_flag = 2; run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0), @@ -1206,7 +1206,6 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) } dstr = str / 10; sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[ATTR::LUK] / 5; -//FPRINTF(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5); sd->matk1 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 5) * (sd->paramc[ATTR::INT] / 5); sd->matk2 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 7) * (sd->paramc[ATTR::INT] / 7); if (sd->matk1 < sd->matk2) @@ -1731,7 +1730,7 @@ int pc_bonus(dumb_ptr<map_session_data> sd, SP type, int val) break; default: if (battle_config.error_log) - PRINTF("pc_bonus: unknown type %d %d !\n", + PRINTF("pc_bonus: unknown type %d %d !\n"_fmt, type, val); break; } @@ -1776,7 +1775,7 @@ int pc_bonus2(dumb_ptr<map_session_data> sd, SP type, int type2, int val) #endif default: if (battle_config.error_log) - PRINTF("pc_bonus2: unknown type %d %d %d!\n", + PRINTF("pc_bonus2: unknown type %d %d %d!\n"_fmt, type, type2, val); break; } @@ -1794,7 +1793,7 @@ int pc_skill(dumb_ptr<map_session_data> sd, SkillID id, int level, int flag) if (level > MAX_SKILL_LEVEL) { if (battle_config.error_log) - PRINTF("support card skill only!\n"); + PRINTF("support card skill only!\n"_fmt); return 0; } if (!flag && (sd->status.skill[id].lv || level == 0)) @@ -1970,7 +1969,7 @@ PickupFail pc_additem(dumb_ptr<map_session_data> sd, struct item *item_data, struct item_data *data; int i, w; - MAP_LOG_PC(sd, "PICKUP %d %d", item_data->nameid, amount); + MAP_LOG_PC(sd, "PICKUP %d %d"_fmt, item_data->nameid, amount); nullpo_retr(PickupFail::BAD_ITEM, sd); nullpo_retr(PickupFail::BAD_ITEM, item_data); @@ -2314,7 +2313,7 @@ int pc_setpos(dumb_ptr<map_session_data> sd, if (x || y) { if (battle_config.error_log) - PRINTF("stacked (%d,%d)\n", x, y); + PRINTF("stacked (%d,%d)\n"_fmt, x, y); } do { @@ -2915,7 +2914,7 @@ int pc_checkbaselevelup(dumb_ptr<map_session_data> sd) //レベルアップしたのでパーティー情報を更新する //(公平範囲チェック) party_send_movemap(sd); - MAP_LOG_XP(sd, "LEVELUP"); + MAP_LOG_XP(sd, "LEVELUP"_fmt); return 1; } @@ -2971,7 +2970,7 @@ int pc_checkjoblevelup(dumb_ptr<map_session_data> sd) clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); - MAP_LOG_PC(sd, "SKILLPOINTS-UP %d", sd->status.skill_point); + MAP_LOG_PC(sd, "SKILLPOINTS-UP %d"_fmt, sd->status.skill_point); if (sd->status.job_level < 250 && sd->status.job_level < sd->status.base_level * 2) @@ -2992,16 +2991,16 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp, if (sd->bl_prev == NULL || pc_isdead(sd)) return 0; - earray<const char *, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //= + earray<LString, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //= {{ - "KILLXP", - "HEALXP", - "SCRIPTXP", - "SHAREXP", + "KILLXP"_s, + "HEALXP"_s, + "SCRIPTXP"_s, + "SHAREXP"_s, /* Insert new types here */ - "UNKNOWNXP" + "UNKNOWNXP"_s }}; - MAP_LOG_PC(sd, "GAINXP %d %d %s", base_exp, job_exp, reasons[reason]); + MAP_LOG_PC(sd, "GAINXP %d %d %s"_fmt, base_exp, job_exp, reasons[reason]); if (!battle_config.multi_level_up && pc_nextbaseafter(sd)) { @@ -3053,7 +3052,7 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp, if (battle_config.disp_experience) { AString output = STRPRINTF( - "Experienced Gained Base:%d Job:%d", + "Experienced Gained Base:%d Job:%d"_fmt, base_exp, job_exp); clif_displaymessage(sd->sess, output); } @@ -3181,7 +3180,7 @@ int pc_statusup(dumb_ptr<map_session_data> sd, SP type) pc_calcstatus(sd, 0); clif_statusupack(sd, type, 1, val); - MAP_LOG_STATS(sd, "STATUP"); + MAP_LOG_STATS(sd, "STATUP"_fmt); return 0; } @@ -3208,7 +3207,7 @@ int pc_statusup2(dumb_ptr<map_session_data> sd, SP type, int val) clif_updatestatus(sd, type); pc_calcstatus(sd, 0); clif_statusupack(sd, type, 1, val); - MAP_LOG_STATS(sd, "STATUP2"); + MAP_LOG_STATS(sd, "STATUP2"_fmt); return 0; } @@ -3232,7 +3231,7 @@ int pc_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num) clif_skillup(sd, skill_num); clif_updatestatus(sd, SP::SKILLPOINT); clif_skillinfoblock(sd); - MAP_LOG_PC(sd, "SKILLUP %d %d %d", + MAP_LOG_PC(sd, "SKILLUP %d %d %d"_fmt, skill_num, sd->status.skill[skill_num].lv, skill_power(sd, skill_num)); } @@ -3323,7 +3322,7 @@ int pc_resetlvl(dumb_ptr<map_session_data> sd, int type) clif_skillinfoblock(sd); pc_calcstatus(sd, 0); - MAP_LOG_STATS(sd, "STATRESET"); + MAP_LOG_STATS(sd, "STATRESET"_fmt); return 0; } @@ -3401,17 +3400,17 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, { if (src->bl_type == BL::PC) { - MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d", + MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d"_fmt, src->is_player()->status_key.char_id, damage); } else { - MAP_LOG_PC(sd, "INJURED-BY MOB%d FOR %d", src->bl_id, damage); + MAP_LOG_PC(sd, "INJURED-BY MOB%d FOR %d"_fmt, src->bl_id, damage); } } else - MAP_LOG_PC(sd, "INJURED-BY null FOR %d", damage); + MAP_LOG_PC(sd, "INJURED-BY null FOR %d"_fmt, damage); pc_stop_walking(sd, 3); // 演奏/ダンスの中断 @@ -3437,7 +3436,7 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, return 0; } - MAP_LOG_PC(sd, "DEAD%s", ""); + MAP_LOG_PC(sd, "DEAD%s"_fmt, ""_s); // Character is dead! @@ -3452,7 +3451,7 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, pc_stop_walking(sd, 0); skill_castcancel(sd, 0); // 詠唱の中止 clif_clearchar(sd, BeingRemoveWhy::DEAD); - pc_setglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"), ++sd->die_counter); //死にカウンター書き込み + pc_setglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"_s), ++sd->die_counter); //死にカウンター書き込み skill_status_change_clear(sd, 0); // ステータス異常を解除する clif_updatestatus(sd, SP::HP); pc_calcstatus(sd, 0); @@ -3544,14 +3543,14 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, // [Fate] PK death, trigger scripts argrec_t arg[3] = { - {"@killerrid", src->bl_id}, - {"@victimrid", sd->bl_id}, - {"@victimlvl", sd->status.base_level}, + {"@killerrid"_s, src->bl_id}, + {"@victimrid"_s, sd->bl_id}, + {"@victimlvl"_s, sd->status.base_level}, }; - npc_event_doall_l(stringish<ScriptLabel>("OnPCKilledEvent"), sd->bl_id, arg); - npc_event_doall_l(stringish<ScriptLabel>("OnPCKillEvent"), src->bl_id, arg); + npc_event_doall_l(stringish<ScriptLabel>("OnPCKilledEvent"_s), sd->bl_id, arg); + npc_event_doall_l(stringish<ScriptLabel>("OnPCKillEvent"_s), src->bl_id, arg); } - npc_event_doall_l(stringish<ScriptLabel>("OnPCDieEvent"), sd->bl_id, nullptr); + npc_event_doall_l(stringish<ScriptLabel>("OnPCDieEvent"_s), sd->bl_id, nullptr); return 0; } @@ -3762,9 +3761,6 @@ int pc_setparam(dumb_ptr<map_session_data> sd, SP type, int val) */ int pc_heal(dumb_ptr<map_session_data> sd, int hp, int sp) { -// if(battle_config.battle_log) -// PRINTF("heal %d %d\n",hp,sp); - nullpo_ret(sd); if (pc_checkoverhp(sd)) @@ -4139,7 +4135,7 @@ int pc_setglobalreg(dumb_ptr<map_session_data> sd, VarName reg, int val) nullpo_ret(sd); //PC_DIE_COUNTERがスクリプトなどで変更された時の処理 - if (reg == stringish<VarName>("PC_DIE_COUNTER") && sd->die_counter != val) + if (reg == stringish<VarName>("PC_DIE_COUNTER"_s) && sd->die_counter != val) { sd->die_counter = val; pc_calcstatus(sd, 0); @@ -4175,7 +4171,7 @@ int pc_setglobalreg(dumb_ptr<map_session_data> sd, VarName reg, int val) return 0; } if (battle_config.error_log) - PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n", + PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n"_fmt, reg, GLOBAL_REG_NUM); return 1; @@ -4244,7 +4240,7 @@ int pc_setaccountreg(dumb_ptr<map_session_data> sd, VarName reg, int val) return 0; } if (battle_config.error_log) - PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n", + PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n"_fmt, reg, ACCOUNT_REG_NUM); return 1; @@ -4312,7 +4308,7 @@ int pc_setaccountreg2(dumb_ptr<map_session_data> sd, VarName reg, int val) return 0; } if (battle_config.error_log) - PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n", + PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n"_fmt, reg, ACCOUNT_REG2_NUM); return 1; @@ -4414,7 +4410,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS) EPOS pos = pc_equippoint(sd, n); if (battle_config.battle_log) - PRINTF("equip %d (%d) %x:%x\n", + PRINTF("equip %d (%d) %x:%x\n"_fmt, nameid, n, id->equip, pos); if (!pc_isequip(sd, n) || pos == EPOS::ZERO) { @@ -4546,7 +4542,7 @@ int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type) // -- moonsoul (if player is berserk then cannot unequip) // if (battle_config.battle_log) - PRINTF("unequip %d %x:%x\n", + PRINTF("unequip %d %x:%x\n"_fmt, n, pc_equippoint(sd, n), sd->status.inventory[n].equip); if (bool(sd->status.inventory[n].equip)) @@ -4804,7 +4800,7 @@ int pc_divorce(dumb_ptr<map_session_data> sd) if (p_sd->status.partner_id != sd->status_key.char_id || sd->status.partner_id != p_sd->status_key.char_id) { - PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n", + PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n"_fmt, sd->status.partner_id, p_sd->status.partner_id); return -1; } @@ -5265,13 +5261,13 @@ int pc_logout(dumb_ptr<map_session_data> sd) // [fate] Player logs out // Removed because it's buggy, see above. if (sd->cast_tick > tick) { - if (pc_setglobalreg(sd, "MAGIC_CAST_TICK", sd->cast_tick - tick)) + if (pc_setglobalreg(sd, "MAGIC_CAST_TICK"_s, sd->cast_tick - tick)) sd->status.sp = 1; } else #endif - pc_setglobalreg(sd, stringish<VarName>("MAGIC_CAST_TICK"), 0); + pc_setglobalreg(sd, stringish<VarName>("MAGIC_CAST_TICK"_s), 0); - MAP_LOG_STATS(sd, "LOGOUT"); + MAP_LOG_STATS(sd, "LOGOUT"_fmt); return 0; } diff --git a/src/map/script.cpp b/src/map/script.cpp index f4dc68f..0cb702b 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -93,7 +93,7 @@ static Map<SIR, RString> mapregstr_db; static int mapreg_dirty = -1; -AString mapreg_txt = "save/mapreg.txt"; +AString mapreg_txt = "save/mapreg.txt"_s; constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = std::chrono::seconds(10); Map<ScriptLabel, int> scriptlabel_db; @@ -102,19 +102,19 @@ std::set<ScriptLabel> probable_labels; UPMap<RString, const ScriptBuffer> userfunc_db; static -Array<ZString, 11> pos_str //= +Array<LString, 11> pos_str //= {{ - ZString("Head"), - ZString("Body"), - ZString("Left hand"), - ZString("Right hand"), - ZString("Robe"), - ZString("Shoes"), - ZString("Accessory 1"), - ZString("Accessory 2"), - ZString("Head 2"), - ZString("Head 3"), - ZString("Not Equipped"), + "Head"_s, + "Body"_s, + "Left hand"_s, + "Right hand"_s, + "Robe"_s, + "Shoes"_s, + "Accessory 1"_s, + "Accessory 2"_s, + "Head 2"_s, + "Head 3"_s, + "Not Equipped"_s, }}; static @@ -150,8 +150,8 @@ void mapreg_setregstr(SIR num, XString str); struct BuiltinFunction { void (*func)(ScriptState *); - ZString name; - ZString arg; + LString name; + LString arg; }; // defined later extern BuiltinFunction builtin_functions[]; @@ -382,15 +382,15 @@ void disp_error_message(ZString mes, ZString::iterator pos_) ZString::iterator lineend = std::find(p, startptr.end(), '\n'); if (pos_ < lineend) { - PRINTF("\n%s\nline %d : ", mes, line); + PRINTF("\n%s\nline %d : "_fmt, mes, line); for (int i = 0; linestart + i != lineend; i++) { if (linestart + i != pos_) - PRINTF("%c", linestart[i]); + PRINTF("%c"_fmt, linestart[i]); else - PRINTF("\'%c\'", linestart[i]); + PRINTF("\'%c\'"_fmt, linestart[i]); } - PRINTF("\a\n"); + PRINTF("\a\n"_fmt); return; } p = lineend + 1; @@ -407,7 +407,7 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) if (*p == ';' || *p == ',') { - disp_error_message("unexpected expr end", p); + disp_error_message("unexpected expr end"_s, p); exit(1); } if (*p == '(') @@ -417,7 +417,7 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) p = skip_space(p); if ((*p++) != ')') { - disp_error_message("unmatch ')'", p); + disp_error_message("unmatch ')'"_s, p); exit(1); } } @@ -438,14 +438,14 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) p++; else if (*p == '\n') { - disp_error_message("unexpected newline @ string", p); + disp_error_message("unexpected newline @ string"_s, p); exit(1); } add_scriptb(*p++); } if (!*p) { - disp_error_message("unexpected eof @ string", p); + disp_error_message("unexpected eof @ string"_s, p); exit(1); } add_scriptb(0); @@ -457,35 +457,35 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) ZString::iterator p2 = skip_word(p); if (p2 == p) { - disp_error_message("unexpected character", p); + disp_error_message("unexpected character"_s, p); exit(1); } XString word(&*p, &*p2, nullptr); - if (word.startswith("On") || word.startswith("L_") || word.startswith("S_")) + if (word.startswith("On"_s) || word.startswith("L_"_s) || word.startswith("S_"_s)) probable_labels.insert(stringish<ScriptLabel>(word)); - if (parse_cmd_if && (word == "callsub" || word == "callfunc" || word == "return")) + if (parse_cmd_if && (word == "callsub"_s || word == "callfunc"_s || word == "return"_s)) { - disp_error_message("Sorry, callsub/callfunc/return have never worked properly in an if statement.", p); + disp_error_message("Sorry, callsub/callfunc/return have never worked properly in an if statement."_s, p); } str_data_t *ld = add_strp(word); parse_cmdp = ld; // warn_*_mismatch_paramnumのために必要 - // why not just check l->str == "if" or std::string(p, p2) == "if"? - if (ld == search_strp("if")) // warn_cmd_no_commaのために必要 + // why not just check l->str == "if"_s or std::string(p, p2) == "if"_s? + if (ld == search_strp("if"_s)) // warn_cmd_no_commaのために必要 parse_cmd_if++; p = p2; if (ld->type != ByteCode::FUNC_ && *p == '[') { // array(name[i] => getelementofarray(name,i) ) - add_scriptl(search_strp("getelementofarray")); + add_scriptl(search_strp("getelementofarray"_s)); add_scriptc(ByteCode::ARG); add_scriptl(ld); p = parse_subexpr(p + 1, -1); p = skip_space(p); if (*p != ']') { - disp_error_message("unmatch ']'", p); + disp_error_message("unmatch ']'"_s, p); exit(1); } p++; @@ -515,7 +515,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) ZString::iterator tmpp = skip_space(p + 1); if (*tmpp == ';' || *tmpp == ',') { - --script_errors; disp_error_message("deprecated: implicit 'next statement' label", p); + --script_errors; disp_error_message("deprecated: implicit 'next statement' label"_s, p); add_scriptl(&LABEL_NEXTLINE_); p++; return p; @@ -560,7 +560,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) if (funcp->type != ByteCode::FUNC_) { - disp_error_message("expect function", tmpp); + disp_error_message("expect function"_s, tmpp); exit(0); } @@ -574,7 +574,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) p++; else if (*p != ')' && script_config.warn_func_no_comma) { - disp_error_message("expect ',' or ')' at func params", + disp_error_message("expect ',' or ')' at func params"_s, p); } p = skip_space(p); @@ -583,7 +583,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) plist[i] = p; if (*p != ')') { - disp_error_message("func request '(' ')'", p); + disp_error_message("func request '(' ')'"_s, p); exit(1); } p++; @@ -598,7 +598,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) break; if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j)) { - disp_error_message("illegal number of parameters", + disp_error_message("illegal number of parameters"_s, plist[std::min(i, j)]); } } @@ -627,7 +627,7 @@ ZString::iterator ScriptBuffer::parse_expr(ZString::iterator p) case '[': case ']': case '}': - disp_error_message("unexpected char", p); + disp_error_message("unexpected char"_s, p); exit(1); } p = parse_subexpr(p, -1); @@ -657,21 +657,22 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) str_data_t *cmd = parse_cmdp; if (cmd->type != ByteCode::FUNC_) { - disp_error_message("expect command", p2); + disp_error_message("expect command"_s, p2); // exit(0); } { + // TODO should be LString, but no heterogenous lookup yet static std::set<ZString> terminators = { - "goto", - "return", - "close", - "menu", - "end", - "mapexit", - "shop", + "goto"_s, + "return"_s, + "close"_s, + "menu"_s, + "end"_s, + "mapexit"_s, + "shop"_s, }; *can_step = terminators.count(cmd->strs) == 0; } @@ -689,7 +690,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) else if (*p != ';' && script_config.warn_cmd_no_comma && parse_cmd_if * 2 <= i) { - disp_error_message("expect ',' or ';' at cmd params", p); + disp_error_message("expect ',' or ';' at cmd params"_s, p); } p = skip_space(p); i++; @@ -697,7 +698,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) plist[i] = p; if (*(p++) != ';') { - disp_error_message("need ';'", p); + disp_error_message("need ';'"_s, p); exit(1); } add_scriptc(ByteCode::FUNC_); @@ -712,7 +713,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) break; if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j)) { - disp_error_message("illegal number of parameters", + disp_error_message("illegal number of parameters"_s, plist[std::min(i, j)]); } } @@ -740,7 +741,7 @@ bool read_constdb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } @@ -755,9 +756,9 @@ bool read_constdb(ZString filename) int val; int type = 0; // if not provided // TODO get rid of SSCANF - this is the last serious use - if (SSCANF(line, "%m[A-Za-z0-9_] %i %i", &name, &val, &type) < 2) + if (SSCANF(line, "%m[A-Za-z0-9_] %i %i"_fmt, &name, &val, &type) < 2) { - PRINTF("Bad const line: %s\n", line); + PRINTF("Bad const line: %s\n"_fmt, line); rv = false; continue; } @@ -815,7 +816,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) p = skip_space(p); if (*p != '{') { - disp_error_message("not found '{'", p); + disp_error_message("not found '{'"_s, p); abort(); } for (p++; *p && *p != '}';) @@ -825,7 +826,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) { if (can_step) { - --script_errors; disp_error_message("deprecated: implicit fallthrough", p); + --script_errors; disp_error_message("deprecated: implicit fallthrough"_s, p); } can_step = true; @@ -838,7 +839,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) assert (e1 == e2 && e2 == e3); if (e3) { - disp_error_message("dup label ", p); + disp_error_message("dup label "_s, p); exit(1); } set_label(ld, script_buf.size()); @@ -849,7 +850,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (!can_step) { - --script_errors; disp_error_message("deprecated: unreachable statement", p); + --script_errors; disp_error_message("deprecated: unreachable statement"_s, p); } // 他は全部一緒くた p = parse_line(p, &can_step); @@ -864,7 +865,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (can_step && !implicit_end) { - --script_errors; disp_error_message("deprecated: implicit end", p); + --script_errors; disp_error_message("deprecated: implicit end"_s, p); } add_scriptc(ByteCode::NOP); @@ -893,17 +894,17 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) for (const auto& pair : scriptlabel_db) { ScriptLabel key = pair.first; - if (key.startswith("On")) + if (key.startswith("On"_s)) continue; - if (!(key.startswith("L_") || key.startswith("S_"))) - PRINTF("Warning: ugly label: %s\n", key); + if (!(key.startswith("L_"_s) || key.startswith("S_"_s))) + PRINTF("Warning: ugly label: %s\n"_fmt, key); else if (!probable_labels.count(key)) - PRINTF("Warning: unused label: %s\n", key); + PRINTF("Warning: unused label: %s\n"_fmt, key); } for (ScriptLabel used : probable_labels) { if (!scriptlabel_db.search(used)) - PRINTF("Warning: no such label: %s\n", used); + PRINTF("Warning: no such label: %s\n"_fmt, used); } probable_labels.clear(); @@ -912,12 +913,12 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) for (size_t i = 0; i < script_buf.size(); i++) { if ((i & 15) == 0) - PRINTF("%04zx : ", i); - PRINTF("%02x ", script_buf[i]); + PRINTF("%04zx : "_fmt, i); + PRINTF("%02x "_fmt, script_buf[i]); if ((i & 15) == 15) - PRINTF("\n"); + PRINTF("\n"_fmt); } - PRINTF("\n"); + PRINTF("\n"_fmt); } // @@ -943,7 +944,7 @@ dumb_ptr<map_session_data> script_rid2sd(ScriptState *st) dumb_ptr<map_session_data> sd = map_id2sd(st->rid); if (!sd) { - PRINTF("script_rid2sd: fatal error ! player not attached!\n"); + PRINTF("script_rid2sd: fatal error ! player not attached!\n"_fmt); } return sd; } @@ -958,7 +959,7 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) if (data->type == ByteCode::PARAM_) { if (sd == NULL) - PRINTF("get_val error param SP::%d\n", data->u.reg.sp()); + PRINTF("get_val error param SP::%d\n"_fmt, data->u.reg.sp()); data->type = ByteCode::INT; if (sd) data->u.numi = pc_readparam(sd, data->u.reg.sp()); @@ -973,7 +974,7 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) if (prefix != '$') { if (sd == NULL) - PRINTF("get_val error name?:%s\n", name); + PRINTF("get_val error name?:%s\n"_fmt, name); } if (postfix == '$') { @@ -990,11 +991,11 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) } else { - PRINTF("script: get_val: illegal scope string variable.\n"); - data->u.str = dumb_string::fake("!!ERROR!!"); + PRINTF("script: get_val: illegal scope string variable.\n"_fmt); + data->u.str = dumb_string::fake("!!ERROR!!"_s); } if (!data->u.str) - data->u.str = dumb_string::fake(""); + data->u.str = dumb_string::fake(""_s); } else { @@ -1085,7 +1086,7 @@ void set_reg(dumb_ptr<map_session_data> sd, ByteCode type, SIR reg, struct scrip } else { - PRINTF("script: set_reg: illegal scope string variable !"); + PRINTF("script: set_reg: illegal scope string variable !"_fmt); } } else @@ -1143,7 +1144,7 @@ dumb_string conv_str(ScriptState *st, struct script_data *data) assert (data->type != ByteCode::RETINFO); if (data->type == ByteCode::INT) { - AString buf = STRPRINTF("%d", data->u.numi); + AString buf = STRPRINTF("%d"_fmt, data->u.numi); data->type = ByteCode::STR; data->u.str = dumb_string::copys(buf); } @@ -1285,7 +1286,7 @@ void builtin_goto(ScriptState *st) { if (AARGO2(2).type != ByteCode::POS) { - PRINTF("script: goto: not label !\n"); + PRINTF("script: goto: not label !\n"_fmt); st->state = ScriptEndState::END; return; } @@ -1324,7 +1325,7 @@ void builtin_callfunc(ScriptState *st) } else { - PRINTF("script:callfunc: function not found! [%s]\n", str); + PRINTF("script:callfunc: function not found! [%s]\n"_fmt, str); st->state = ScriptEndState::END; } } @@ -1442,7 +1443,7 @@ void builtin_menu(ScriptState *st) // not just the displayed number that ends with the "". // (Would it be better to pop the stack before rerunning?) int menu_choices = (st->end - (st->start + 2)) / 2; - pc_setreg(sd, SIR::from(variable_names.intern("@menu")), sd->npc_menu); + pc_setreg(sd, SIR::from(variable_names.intern("@menu"_s)), sd->npc_menu); sd->state.menu_or_input = 0; if (sd->npc_menu > 0 && sd->npc_menu <= menu_choices) { @@ -1532,9 +1533,9 @@ void builtin_warp(ScriptState *st) MapName str = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); x = conv_num(st, &AARGO2(3)); y = conv_num(st, &AARGO2(4)); - if (str == "Random") + if (str == "Random"_s) pc_randomwarp(sd, BeingRemoveWhy::WARPED); - else if (str == "SavePoint" or str == "Save") + else if (str == "SavePoint"_s or str == "Save"_s) { if (sd->bl_m->flag.get(MapFlag::NORETURN)) return; @@ -1554,7 +1555,7 @@ static void builtin_areawarp_sub(dumb_ptr<block_list> bl, MapName mapname, int x, int y) { dumb_ptr<map_session_data> sd = bl->is_player(); - if (mapname == "Random") + if (mapname == "Random"_s) pc_randomwarp(sd, BeingRemoveWhy::WARPED); else pc_setpos(sd, mapname, x, y, BeingRemoveWhy::GONE); @@ -1762,7 +1763,7 @@ void builtin_setarray(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_setarray: illegal scope !\n"); + PRINTF("builtin_setarray: illegal scope !\n"_fmt); return; } if (prefix != '$') @@ -1794,7 +1795,7 @@ void builtin_cleararray(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_cleararray: illegal scope !\n"); + PRINTF("builtin_cleararray: illegal scope !\n"_fmt); return; } if (prefix != '$') @@ -1839,7 +1840,7 @@ void builtin_getarraysize(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_copyarray: illegal scope !\n"); + PRINTF("builtin_copyarray: illegal scope !\n"_fmt); return; } @@ -1858,7 +1859,7 @@ void builtin_getelementofarray(ScriptState *st) int i = conv_num(st, &AARGO2(3)); if (i > 255 || i < 0) { - PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n", + PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n"_fmt, i); push_int(st->stack, ByteCode::INT, 0); } @@ -1870,7 +1871,7 @@ void builtin_getelementofarray(ScriptState *st) } else { - PRINTF("script: getelementofarray (operator[]): param1 not name !\n"); + PRINTF("script: getelementofarray (operator[]): param1 not name !\n"_fmt); push_int(st->stack, ByteCode::INT, 0); } } @@ -1924,7 +1925,7 @@ void builtin_countitem(ScriptState *st) else { if (battle_config.error_log) - PRINTF("wrong item ID : countitem (%i)\n", nameid); + PRINTF("wrong item ID : countitem (%i)\n"_fmt, nameid); } push_int(st->stack, ByteCode::INT, count); @@ -2104,7 +2105,6 @@ void builtin_delitem(ScriptState *st) if (nameid < 500 || amount <= 0) { //by Lupus. Don't run FOR if u got wrong item ID or amount<=0 - //PRINTF("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount); return; } @@ -2231,12 +2231,12 @@ void builtin_strcharinfo(ScriptState *st) if (buf) push_str(st->stack, ByteCode::STR, buf); else - push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake("")); + push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(""_s)); } if (num == 2) { // was: guild name - push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake("")); + push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(""_s)); } } @@ -2273,7 +2273,7 @@ void builtin_getequipid(ScriptState *st) sd = script_rid2sd(st); if (sd == NULL) { - PRINTF("getequipid: sd == NULL\n"); + PRINTF("getequipid: sd == NULL\n"_fmt); return; } num = conv_num(st, &AARGO2(2)); @@ -2312,13 +2312,13 @@ void builtin_getequipname(ScriptState *st) { item = sd->inventory_data[i]; if (item) - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], item->jname); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], item->jname); else - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], pos_str[10]); } else { - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], pos_str[10]); } push_str(st->stack, ByteCode::STR, dumb_string::copys(buf)); @@ -2683,7 +2683,7 @@ void builtin_killmonster(ScriptState *st) MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); ZString event_ = ZString(conv_str(st, &AARGO2(3))); NpcEvent event; - if (event_ != "All") + if (event_ != "All"_s) extract(event_, &event); map_local *m = map_mapname2mapid(mapname); @@ -3151,7 +3151,7 @@ static void builtin_debugmes(ScriptState *st) { dumb_string mes = conv_str(st, &AARGO2(2)); - PRINTF("script debug : %d %d : %s\n", + PRINTF("script debug : %d %d : %s\n"_fmt, st->rid, st->oid, mes); } @@ -3464,7 +3464,7 @@ void builtin_getitemname(ScriptState *st) if (i_data) item_name = dumb_string::copys(i_data->jname); else - item_name = dumb_string::copys("Unknown Item"); + item_name = dumb_string::copys("Unknown Item"_s); push_str(st->stack, ByteCode::STR, item_name); } @@ -3476,7 +3476,7 @@ void builtin_getspellinvocation(ScriptState *st) AString invocation = magic_find_invocation(name.str()); if (!invocation) - invocation = "..."; + invocation = "..."_s; push_str(st->stack, ByteCode::STR, dumb_string::copys(invocation)); } @@ -3505,16 +3505,16 @@ void builtin_getinventorylist(ScriptState *st) if (sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0) { - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_id"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_id"_s), j), sd->status.inventory[i].nameid); - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_amount"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_amount"_s), j), sd->status.inventory[i].amount); - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_equip"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_equip"_s), j), static_cast<uint16_t>(sd->status.inventory[i].equip)); j++; } } - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_count")), j); + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_count"_s)), j); } static @@ -3534,18 +3534,18 @@ void builtin_getactivatedpoolskilllist(ScriptState *st) if (sd->status.skill[skill_id].lv) { - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"_s), count), static_cast<uint16_t>(skill_id)); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"_s), count), sd->status.skill[skill_id].lv); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"_s), count), static_cast<uint16_t>(sd->status.skill[skill_id].flags)); - pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"), count), + pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"_s), count), skill_name(skill_id)); ++count; } } - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count")), count); + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count"_s)), count); } @@ -3565,18 +3565,18 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st) if (sd->status.skill[skill_id].lv && !bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"_s), count), static_cast<uint16_t>(skill_id)); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"_s), count), sd->status.skill[skill_id].lv); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"_s), count), static_cast<uint16_t>(sd->status.skill[skill_id].flags)); - pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"), count), + pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"_s), count), skill_name(skill_id)); ++count; } } - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count")), count); + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count"_s)), count); } static @@ -3775,7 +3775,7 @@ void builtin_npcwarp(ScriptState *st) if (!nd) { - PRINTF("builtin_npcwarp: no such npc: %s\n", npc); + PRINTF("builtin_npcwarp: no such npc: %s\n"_fmt, npc); return; } @@ -3984,7 +3984,7 @@ void builtin_shop(ScriptState *st) nd = npc_name2id(name); if (!nd) { - PRINTF("builtin_shop: no such npc: %s\n", name); + PRINTF("builtin_shop: no such npc: %s\n"_fmt, name); return; } @@ -4017,7 +4017,7 @@ void builtin_fakenpcname(ScriptState *st) dumb_ptr<npc_data> nd = npc_name2id(name); if (!nd) { - PRINTF("builtin_fakenpcname: no such npc: %s\n", name); + PRINTF("builtin_fakenpcname: no such npc: %s\n"_fmt, name); return; } nd->name = newname; @@ -4201,7 +4201,7 @@ void op_2str(ScriptState *st, ByteCode op, dumb_string s1_, dumb_string s2_) a = s1 <= s2; break; default: - PRINTF("illegal string operater\n"); + PRINTF("illegal string operater\n"_fmt); break; } @@ -4304,7 +4304,7 @@ void op_2(ScriptState *st, ByteCode op) else { // si,is => error - PRINTF("script: op_2: int&str, str&int not allow.\n"); + PRINTF("script: op_2: int&str, str&int not allow.\n"_fmt); push_int(st->stack, ByteCode::INT, 0); } } @@ -4347,7 +4347,7 @@ void run_func(ScriptState *st) if (start_sp == 0) { if (battle_config.error_log) - PRINTF("function not found\n"); + PRINTF("function not found\n"_fmt); st->state = ScriptEndState::END; return; } @@ -4360,52 +4360,52 @@ void run_func(ScriptState *st) size_t func = st->stack->stack_datav[st->start].u.numi; if (st->stack->stack_datav[st->start].type != ByteCode::FUNC_REF) { - PRINTF("run_func: not function and command! \n"); + PRINTF("run_func: not function and command! \n"_fmt); st->state = ScriptEndState::END; return; } if (DEBUG_RUN && battle_config.etc_log) { - PRINTF("run_func : %s\n", + PRINTF("run_func : %s\n"_fmt, builtin_functions[func].name); - PRINTF("stack dump :"); + PRINTF("stack dump :"_fmt); for (script_data& d : st->stack->stack_datav) { switch (d.type) { case ByteCode::INT: - PRINTF(" int(%d)", d.u.numi); + PRINTF(" int(%d)"_fmt, d.u.numi); break; case ByteCode::RETINFO: - PRINTF(" retinfo(%p)", static_cast<const void *>(d.u.script)); + PRINTF(" retinfo(%p)"_fmt, static_cast<const void *>(d.u.script)); break; case ByteCode::PARAM_: - PRINTF(" param(%d)", d.u.reg.sp()); + PRINTF(" param(%d)"_fmt, d.u.reg.sp()); break; case ByteCode::VARIABLE: - PRINTF(" name(%s)[%d]", variable_names.outtern(d.u.reg.base()), d.u.reg.index()); + PRINTF(" name(%s)[%d]"_fmt, variable_names.outtern(d.u.reg.base()), d.u.reg.index()); break; case ByteCode::ARG: - PRINTF(" arg"); + PRINTF(" arg"_fmt); break; case ByteCode::POS: - PRINTF(" pos(%d)", d.u.numi); + PRINTF(" pos(%d)"_fmt, d.u.numi); break; case ByteCode::STR: - PRINTF(" str(%s)", d.u.str); + PRINTF(" str(%s)"_fmt, d.u.str); break; case ByteCode::CONSTSTR: - PRINTF(" cstr(%s)", d.u.str); + PRINTF(" cstr(%s)"_fmt, d.u.str); break; case ByteCode::FUNC_REF: - PRINTF(" func(%s)", builtin_functions[d.u.numi].name); + PRINTF(" func(%s)"_fmt, builtin_functions[d.u.numi].name); break; default: - PRINTF(" %d,%d", d.type, d.u.numi); + PRINTF(" %d,%d"_fmt, d.type, d.u.numi); } } - PRINTF("\n"); + PRINTF("\n"_fmt); } builtin_functions[func].func(st); @@ -4420,7 +4420,7 @@ void run_func(ScriptState *st) if (st->defsp < 4 || st->stack->stack_datav[st->defsp - 1].type != ByteCode::RETINFO) { - PRINTF("script:run_func (return) return without callfunc or callsub!\n"); + PRINTF("script:run_func (return) return without callfunc or callsub!\n"_fmt); st->state = ScriptEndState::END; return; } @@ -4445,15 +4445,15 @@ void dump_script(const ScriptBuffer *script) ScriptPointer scriptp(script, 0); while (scriptp.pos < reinterpret_cast<const std::vector<ByteCode> *>(script)->size()) { - PRINTF("%6zu: ", scriptp.pos); + PRINTF("%6zu: "_fmt, scriptp.pos); switch (ByteCode c = get_com(&scriptp)) { case ByteCode::EOL: - PRINTF("EOL\n"); // extra newline between functions + PRINTF("EOL\n"_fmt); // extra newline between functions break; case ByteCode::INT: // synthesized! - PRINTF("INT %d", get_num(&scriptp)); + PRINTF("INT %d"_fmt, get_num(&scriptp)); break; case ByteCode::POS: @@ -4468,103 +4468,103 @@ void dump_script(const ScriptBuffer *script) switch(c) { case ByteCode::POS: - PRINTF("POS %d", arg); + PRINTF("POS %d"_fmt, arg); break; case ByteCode::VARIABLE: - PRINTF("VARIABLE %s", variable_names.outtern(arg)); + PRINTF("VARIABLE %s"_fmt, variable_names.outtern(arg)); break; case ByteCode::FUNC_REF: - PRINTF("FUNC_REF %s", builtin_functions[arg].name); + PRINTF("FUNC_REF %s"_fmt, builtin_functions[arg].name); break; case ByteCode::PARAM_: - PRINTF("PARAM SP::#%d (sorry)", arg); + PRINTF("PARAM SP::#%d (sorry)"_fmt, arg); break; } } break; case ByteCode::ARG: - PRINTF("ARG"); + PRINTF("ARG"_fmt); break; case ByteCode::STR: - PRINTF("STR \"%s\"", scriptp.pops()); + PRINTF("STR \"%s\""_fmt, scriptp.pops()); break; case ByteCode::FUNC_: - PRINTF("FUNC_"); + PRINTF("FUNC_"_fmt); break; case ByteCode::ADD: - PRINTF("ADD"); + PRINTF("ADD"_fmt); break; case ByteCode::SUB: - PRINTF("SUB"); + PRINTF("SUB"_fmt); break; case ByteCode::MUL: - PRINTF("MUL"); + PRINTF("MUL"_fmt); break; case ByteCode::DIV: - PRINTF("DIV"); + PRINTF("DIV"_fmt); break; case ByteCode::MOD: - PRINTF("MOD"); + PRINTF("MOD"_fmt); break; case ByteCode::EQ: - PRINTF("EQ"); + PRINTF("EQ"_fmt); break; case ByteCode::NE: - PRINTF("NE"); + PRINTF("NE"_fmt); break; case ByteCode::GT: - PRINTF("GT"); + PRINTF("GT"_fmt); break; case ByteCode::GE: - PRINTF("GE"); + PRINTF("GE"_fmt); break; case ByteCode::LT: - PRINTF("LT"); + PRINTF("LT"_fmt); break; case ByteCode::LE: - PRINTF("LE"); + PRINTF("LE"_fmt); break; case ByteCode::AND: - PRINTF("AND"); + PRINTF("AND"_fmt); break; case ByteCode::OR: - PRINTF("OR"); + PRINTF("OR"_fmt); break; case ByteCode::XOR: - PRINTF("XOR"); + PRINTF("XOR"_fmt); break; case ByteCode::LAND: - PRINTF("LAND"); + PRINTF("LAND"_fmt); break; case ByteCode::LOR: - PRINTF("LOR"); + PRINTF("LOR"_fmt); break; case ByteCode::R_SHIFT: - PRINTF("R_SHIFT"); + PRINTF("R_SHIFT"_fmt); break; case ByteCode::L_SHIFT: - PRINTF("L_SHIFT"); + PRINTF("L_SHIFT"_fmt); break; case ByteCode::NEG: - PRINTF("NEG"); + PRINTF("NEG"_fmt); break; case ByteCode::NOT: - PRINTF("NOT"); + PRINTF("NOT"_fmt); break; case ByteCode::LNOT: - PRINTF("LNOT"); + PRINTF("LNOT"_fmt); break; case ByteCode::NOP: - PRINTF("NOP"); + PRINTF("NOP"_fmt); break; default: - PRINTF("??? %d", c); + PRINTF("??? %d"_fmt, c); break; } - PRINTF("\n"); + PRINTF("\n"_fmt); } } @@ -4591,7 +4591,7 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) if (stack->stack_datav.size() != st->defsp) { if (battle_config.error_log) - PRINTF("stack.sp (%zu) != default (%d)\n", + PRINTF("stack.sp (%zu) != default (%d)\n"_fmt, stack->stack_datav.size(), st->defsp); stack->stack_datav.resize(st->defsp); @@ -4646,7 +4646,7 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) st->state = ScriptEndState::ZERO; if (gotocount > 0 && (--gotocount) <= 0) { - PRINTF("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; } } @@ -4688,14 +4688,14 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) default: if (battle_config.error_log) - PRINTF("unknown command : %d @ %zu\n", + PRINTF("unknown command : %d @ %zu\n"_fmt, c, st->scriptp.pos); st->state = ScriptEndState::END; break; } if (cmdcount > 0 && (--cmdcount) <= 0) { - PRINTF("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; } } @@ -4842,7 +4842,7 @@ void script_load_mapreg(void) else { borken: - PRINTF("%s: %s broken data !\n", mapreg_txt, AString(buf1)); + PRINTF("%s: %s broken data !\n"_fmt, mapreg_txt, AString(buf1)); continue; } } @@ -4861,9 +4861,9 @@ void script_save_mapreg_intsub(SIR key, int data, io::WriteFile& fp) if (name[1] != '@') { if (i == 0) - FPRINTF(fp, "%s\t%d\n", name, data); + FPRINTF(fp, "%s\t%d\n"_fmt, name, data); else - FPRINTF(fp, "%s,%d\t%d\n", name, i, data); + FPRINTF(fp, "%s,%d\t%d\n"_fmt, name, i, data); } } @@ -4875,9 +4875,9 @@ void script_save_mapreg_strsub(SIR key, ZString data, io::WriteFile& fp) if (name[1] != '@') { if (i == 0) - FPRINTF(fp, "%s\t%s\n", name, data); + FPRINTF(fp, "%s\t%s\n"_fmt, name, data); else - FPRINTF(fp, "%s,%d\t%s\n", name, i, data); + FPRINTF(fp, "%s,%d\t%s\n"_fmt, name, i, data); } } @@ -4929,128 +4929,128 @@ void do_init_script(void) } #define BUILTIN(func, args) \ -{builtin_##func, {#func}, {args}} +{builtin_##func, #func ## _s, {args}} BuiltinFunction builtin_functions[] = { - BUILTIN(mes, "s"), - BUILTIN(next, ""), - BUILTIN(close, ""), - BUILTIN(close2, ""), - BUILTIN(menu, "sL*"), - BUILTIN(goto, "L"), - BUILTIN(callsub, "L"), - BUILTIN(callfunc, "F"), - BUILTIN(return, ""), - BUILTIN(input, "N"), - BUILTIN(warp, "Mxy"), - BUILTIN(isat, "Mxy"), - BUILTIN(areawarp, "MxyxyMxy"), - BUILTIN(setlook, "ii"), - BUILTIN(set, "Ne"), - BUILTIN(setarray, "Ne*"), - BUILTIN(cleararray, "Nei"), - BUILTIN(getarraysize, "N"), - BUILTIN(getelementofarray, "Ni"), - BUILTIN(if, "iF*"), - BUILTIN(getitem, "Ii**"), - BUILTIN(makeitem, "IiMxy"), - BUILTIN(delitem, "Ii"), - BUILTIN(heal, "ii"), - BUILTIN(itemheal, "ii"), - BUILTIN(percentheal, "ii"), - BUILTIN(rand, "i*"), - BUILTIN(pow, "ii"), - BUILTIN(countitem, "I"), - BUILTIN(checkweight, "Ii"), - BUILTIN(readparam, "i*"), - BUILTIN(getcharid, "i*"), - BUILTIN(strcharinfo, "i"), - BUILTIN(getequipid, "i"), - BUILTIN(getequipname, "i"), - BUILTIN(statusup2, "ii"), - BUILTIN(bonus, "ii"), - BUILTIN(bonus2, "iii"), - BUILTIN(skill, "ii*"), - BUILTIN(setskill, "ii"), - BUILTIN(getskilllv, "i"), - BUILTIN(getgmlevel, ""), - BUILTIN(end, ""), - BUILTIN(getopt2, ""), - BUILTIN(setopt2, "i"), - BUILTIN(savepoint, "Mxy"), - BUILTIN(gettimetick, "i"), - BUILTIN(gettime, "i"), - BUILTIN(openstorage, "*"), - BUILTIN(monster, "Mxysmi*"), - BUILTIN(areamonster, "Mxyxysmi*"), - BUILTIN(killmonster, "ME"), - BUILTIN(killmonsterall, "M"), - BUILTIN(donpcevent, "E"), - BUILTIN(addtimer, "tE"), - BUILTIN(initnpctimer, ""), - BUILTIN(stopnpctimer, ""), - BUILTIN(startnpctimer, "*"), - BUILTIN(setnpctimer, "i"), - BUILTIN(getnpctimer, "i"), - BUILTIN(announce, "si"), - BUILTIN(mapannounce, "Msi"), - BUILTIN(getusers, "i"), - BUILTIN(getmapusers, "M"), - BUILTIN(getareausers, "Mxyxy*"), - BUILTIN(getareadropitem, "Mxyxyi*"), - BUILTIN(enablenpc, "s"), - BUILTIN(disablenpc, "s"), - BUILTIN(sc_start, "iTi*"), - BUILTIN(sc_end, "i"), - BUILTIN(sc_check, "i"), - BUILTIN(debugmes, "s"), - BUILTIN(resetstatus, ""), - BUILTIN(changesex, ""), - BUILTIN(attachrid, "i"), - BUILTIN(detachrid, ""), - BUILTIN(isloggedin, "i"), - BUILTIN(setmapflag, "Mi"), - BUILTIN(removemapflag, "Mi"), - BUILTIN(getmapflag, "Mi"), - BUILTIN(pvpon, "M"), - BUILTIN(pvpoff, "M"), - BUILTIN(emotion, "i"), - BUILTIN(marriage, "P"), - BUILTIN(divorce, ""), - BUILTIN(getitemname, "I"), - BUILTIN(getspellinvocation, "s"), - BUILTIN(getpartnerid2, ""), - BUILTIN(getexp, "ii"), - BUILTIN(getinventorylist, ""), - BUILTIN(getactivatedpoolskilllist, ""), - BUILTIN(getunactivatedpoolskilllist, ""), - BUILTIN(poolskill, "i"), - BUILTIN(unpoolskill, "i"), - BUILTIN(misceffect, "i*"), - BUILTIN(specialeffect, "i"), - BUILTIN(specialeffect2, "i"), - BUILTIN(nude, ""), - BUILTIN(mapwarp, "MMxy"), - BUILTIN(cmdothernpc, "ss"), - BUILTIN(gmcommand, "s"), - BUILTIN(npcwarp, "xys"), - BUILTIN(message, "Ps"), - BUILTIN(npctalk, "s"), - BUILTIN(mobcount, "ME"), - BUILTIN(getlook, "i"), - BUILTIN(getsavepoint, "i"), - BUILTIN(areatimer, "MxyxytE"), - BUILTIN(isin, "Mxyxy"), - BUILTIN(shop, "s"), - BUILTIN(isdead, ""), - BUILTIN(unequipbyid, "i"), - BUILTIN(fakenpcname, "ssi"), - BUILTIN(getx, ""), - BUILTIN(gety, ""), - BUILTIN(getmap, ""), - BUILTIN(mapexit, ""), - {nullptr, ZString(), ZString()}, + BUILTIN(mes, "s"_s), + BUILTIN(next, ""_s), + BUILTIN(close, ""_s), + BUILTIN(close2, ""_s), + BUILTIN(menu, "sL*"_s), + BUILTIN(goto, "L"_s), + BUILTIN(callsub, "L"_s), + BUILTIN(callfunc, "F"_s), + BUILTIN(return, ""_s), + BUILTIN(input, "N"_s), + BUILTIN(warp, "Mxy"_s), + BUILTIN(isat, "Mxy"_s), + BUILTIN(areawarp, "MxyxyMxy"_s), + BUILTIN(setlook, "ii"_s), + BUILTIN(set, "Ne"_s), + BUILTIN(setarray, "Ne*"_s), + BUILTIN(cleararray, "Nei"_s), + BUILTIN(getarraysize, "N"_s), + BUILTIN(getelementofarray, "Ni"_s), + BUILTIN(if, "iF*"_s), + BUILTIN(getitem, "Ii**"_s), + BUILTIN(makeitem, "IiMxy"_s), + BUILTIN(delitem, "Ii"_s), + BUILTIN(heal, "ii"_s), + BUILTIN(itemheal, "ii"_s), + BUILTIN(percentheal, "ii"_s), + BUILTIN(rand, "i*"_s), + BUILTIN(pow, "ii"_s), + BUILTIN(countitem, "I"_s), + BUILTIN(checkweight, "Ii"_s), + BUILTIN(readparam, "i*"_s), + BUILTIN(getcharid, "i*"_s), + BUILTIN(strcharinfo, "i"_s), + BUILTIN(getequipid, "i"_s), + BUILTIN(getequipname, "i"_s), + BUILTIN(statusup2, "ii"_s), + BUILTIN(bonus, "ii"_s), + BUILTIN(bonus2, "iii"_s), + BUILTIN(skill, "ii*"_s), + BUILTIN(setskill, "ii"_s), + BUILTIN(getskilllv, "i"_s), + BUILTIN(getgmlevel, ""_s), + BUILTIN(end, ""_s), + BUILTIN(getopt2, ""_s), + BUILTIN(setopt2, "i"_s), + BUILTIN(savepoint, "Mxy"_s), + BUILTIN(gettimetick, "i"_s), + BUILTIN(gettime, "i"_s), + BUILTIN(openstorage, "*"_s), + BUILTIN(monster, "Mxysmi*"_s), + BUILTIN(areamonster, "Mxyxysmi*"_s), + BUILTIN(killmonster, "ME"_s), + BUILTIN(killmonsterall, "M"_s), + BUILTIN(donpcevent, "E"_s), + BUILTIN(addtimer, "tE"_s), + BUILTIN(initnpctimer, ""_s), + BUILTIN(stopnpctimer, ""_s), + BUILTIN(startnpctimer, "*"_s), + BUILTIN(setnpctimer, "i"_s), + BUILTIN(getnpctimer, "i"_s), + BUILTIN(announce, "si"_s), + BUILTIN(mapannounce, "Msi"_s), + BUILTIN(getusers, "i"_s), + BUILTIN(getmapusers, "M"_s), + BUILTIN(getareausers, "Mxyxy*"_s), + BUILTIN(getareadropitem, "Mxyxyi*"_s), + BUILTIN(enablenpc, "s"_s), + BUILTIN(disablenpc, "s"_s), + BUILTIN(sc_start, "iTi*"_s), + BUILTIN(sc_end, "i"_s), + BUILTIN(sc_check, "i"_s), + BUILTIN(debugmes, "s"_s), + BUILTIN(resetstatus, ""_s), + BUILTIN(changesex, ""_s), + BUILTIN(attachrid, "i"_s), + BUILTIN(detachrid, ""_s), + BUILTIN(isloggedin, "i"_s), + BUILTIN(setmapflag, "Mi"_s), + BUILTIN(removemapflag, "Mi"_s), + BUILTIN(getmapflag, "Mi"_s), + BUILTIN(pvpon, "M"_s), + BUILTIN(pvpoff, "M"_s), + BUILTIN(emotion, "i"_s), + BUILTIN(marriage, "P"_s), + BUILTIN(divorce, ""_s), + BUILTIN(getitemname, "I"_s), + BUILTIN(getspellinvocation, "s"_s), + BUILTIN(getpartnerid2, ""_s), + BUILTIN(getexp, "ii"_s), + BUILTIN(getinventorylist, ""_s), + BUILTIN(getactivatedpoolskilllist, ""_s), + BUILTIN(getunactivatedpoolskilllist, ""_s), + BUILTIN(poolskill, "i"_s), + BUILTIN(unpoolskill, "i"_s), + BUILTIN(misceffect, "i*"_s), + BUILTIN(specialeffect, "i"_s), + BUILTIN(specialeffect2, "i"_s), + BUILTIN(nude, ""_s), + BUILTIN(mapwarp, "MMxy"_s), + BUILTIN(cmdothernpc, "ss"_s), + BUILTIN(gmcommand, "s"_s), + BUILTIN(npcwarp, "xys"_s), + BUILTIN(message, "Ps"_s), + BUILTIN(npctalk, "s"_s), + BUILTIN(mobcount, "ME"_s), + BUILTIN(getlook, "i"_s), + BUILTIN(getsavepoint, "i"_s), + BUILTIN(areatimer, "MxyxytE"_s), + BUILTIN(isin, "Mxyxy"_s), + BUILTIN(shop, "s"_s), + BUILTIN(isdead, ""_s), + BUILTIN(unequipbyid, "i"_s), + BUILTIN(fakenpcname, "ssi"_s), + BUILTIN(getx, ""_s), + BUILTIN(gety, ""_s), + BUILTIN(getmap, ""_s), + BUILTIN(mapexit, ""_s), + {nullptr, ""_s, ""_s}, }; void set_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e, int val) @@ -5075,7 +5075,7 @@ int get_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e) get_val(sd, &dat); if (dat.type == ByteCode::INT) return dat.u.numi; - PRINTF("Warning: you lied about the type and I'm too lazy to fix it!"); + PRINTF("Warning: you lied about the type and I'm too lazy to fix it!"_fmt); return 0; } ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e) @@ -5088,6 +5088,6 @@ ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e) get_val(sd, &dat); if (dat.type == ByteCode::CONSTSTR) return dat.u.str; - PRINTF("Warning: you lied about the type and I can't fix it!"); + PRINTF("Warning: you lied about the type and I can't fix it!"_fmt); return ZString(); } diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp index 6b46d79..49496bb 100644 --- a/src/map/skill-pools.cpp +++ b/src/map/skill-pools.cpp @@ -34,7 +34,7 @@ void skill_pool_register(SkillID id) if (skill_pool_skills_size + 1 >= MAX_POOL_SKILLS) { FPRINTF(stderr, - "Too many pool skills! Increase MAX_POOL_SKILLS and recompile."); + "Too many pool skills! Increase MAX_POOL_SKILLS and recompile."_fmt); return; } @@ -78,7 +78,7 @@ int skill_pool_activate(dumb_ptr<map_session_data> sd, SkillID skill_id) { sd->status.skill[skill_id].flags |= SkillFlags::POOL_ACTIVATED; pc_calcstatus(sd, 0); - MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d", + MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d"_fmt, skill_id, sd->status.skill[skill_id].lv, skill_power(sd, skill_id)); return 0; @@ -97,7 +97,7 @@ int skill_pool_deactivate(dumb_ptr<map_session_data> sd, SkillID skill_id) if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { sd->status.skill[skill_id].flags &= ~SkillFlags::POOL_ACTIVATED; - MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d", skill_id); + MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d"_fmt, skill_id); pc_calcstatus(sd, 0); return 0; } diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 37a3b44..5b8f2a3 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -54,34 +54,34 @@ struct skill_name_db skill_names[] = { - {SkillID::AC_OWL, "OWL", "Owl's_Eye"}, - - {SkillID::NPC_EMOTION, "EMOTION", "NPC_EMOTION"}, - {SkillID::NPC_POISON, "POISON", "NPC_POISON"}, - {SkillID::NPC_SELFDESTRUCTION, "SELFDESTRUCTION", "Kabooooom!"}, - {SkillID::NPC_SUMMONSLAVE, "SUMMONSLAVE", "NPC_SUMMONSLAVE"}, - - {SkillID::NV_EMOTE, "EMOTE", "Emote_Skill"}, - {SkillID::NV_TRADE, "TRADE", "Trade_Skill"}, - {SkillID::NV_PARTY, "PARTY", "Party_Skill"}, - - {SkillID::TMW_MAGIC, "MAGIC", "General Magic"}, - {SkillID::TMW_MAGIC_LIFE, "MAGIC_LIFE", "Life Magic"}, - {SkillID::TMW_MAGIC_WAR, "MAGIC_WAR", "War Magic"}, - {SkillID::TMW_MAGIC_TRANSMUTE, "MAGIC_TRANSMUTE", "Transmutation Magic"}, - {SkillID::TMW_MAGIC_NATURE, "MAGIC_NATURE", "Nature Magic"}, - {SkillID::TMW_MAGIC_ETHER, "MAGIC_ETHER", "Astral Magic"}, - {SkillID::TMW_MAGIC_DARK, "MAGIC_DARK", "Dark Magic"}, - {SkillID::TMW_MAGIC_LIGHT, "MAGIC_LIGHT", "Light Magic"}, - - {SkillID::TMW_BRAWLING, "BRAWLING", "Brawling"}, - {SkillID::TMW_LUCKY_COUNTER, "LUCKY_COUNTER", "Lucky Counter"}, - {SkillID::TMW_SPEED, "SPEED", "Speed"}, - {SkillID::TMW_RESIST_POISON, "RESIST_POISON", "Resist Poison"}, - {SkillID::TMW_ASTRAL_SOUL, "ASTRAL_SOUL", "Astral Soul"}, - {SkillID::TMW_RAGING, "RAGING", "Raging"}, - - {SkillID::ZERO, "", ""} + {SkillID::AC_OWL, "OWL"_s, "Owl's_Eye"_s}, + + {SkillID::NPC_EMOTION, "EMOTION"_s, "NPC_EMOTION"_s}, + {SkillID::NPC_POISON, "POISON"_s, "NPC_POISON"_s}, + {SkillID::NPC_SELFDESTRUCTION, "SELFDESTRUCTION"_s, "Kabooooom!"_s}, + {SkillID::NPC_SUMMONSLAVE, "SUMMONSLAVE"_s, "NPC_SUMMONSLAVE"_s}, + + {SkillID::NV_EMOTE, "EMOTE"_s, "Emote_Skill"_s}, + {SkillID::NV_TRADE, "TRADE"_s, "Trade_Skill"_s}, + {SkillID::NV_PARTY, "PARTY"_s, "Party_Skill"_s}, + + {SkillID::TMW_MAGIC, "MAGIC"_s, "General Magic"_s}, + {SkillID::TMW_MAGIC_LIFE, "MAGIC_LIFE"_s, "Life Magic"_s}, + {SkillID::TMW_MAGIC_WAR, "MAGIC_WAR"_s, "War Magic"_s}, + {SkillID::TMW_MAGIC_TRANSMUTE, "MAGIC_TRANSMUTE"_s, "Transmutation Magic"_s}, + {SkillID::TMW_MAGIC_NATURE, "MAGIC_NATURE"_s, "Nature Magic"_s}, + {SkillID::TMW_MAGIC_ETHER, "MAGIC_ETHER"_s, "Astral Magic"_s}, + {SkillID::TMW_MAGIC_DARK, "MAGIC_DARK"_s, "Dark Magic"_s}, + {SkillID::TMW_MAGIC_LIGHT, "MAGIC_LIGHT"_s, "Light Magic"_s}, + + {SkillID::TMW_BRAWLING, "BRAWLING"_s, "Brawling"_s}, + {SkillID::TMW_LUCKY_COUNTER, "LUCKY_COUNTER"_s, "Lucky Counter"_s}, + {SkillID::TMW_SPEED, "SPEED"_s, "Speed"_s}, + {SkillID::TMW_RESIST_POISON, "RESIST_POISON"_s, "Resist Poison"_s}, + {SkillID::TMW_ASTRAL_SOUL, "ASTRAL_SOUL"_s, "Astral Soul"_s}, + {SkillID::TMW_RAGING, "RAGING"_s, "Raging"_s}, + + {SkillID::ZERO, ""_s, ""_s} }; earray<skill_db_, SkillID, SkillID::MAX_SKILL_DB> skill_db; @@ -690,7 +690,7 @@ int skill_status_change_active(dumb_ptr<block_list> bl, StatusChange type) if (bl->bl_type != BL::PC && bl->bl_type != BL::MOB) { if (battle_config.error_log) - PRINTF("skill_status_change_active: neither MOB nor PC !\n"); + PRINTF("skill_status_change_active: neither MOB nor PC !\n"_fmt); return 0; } @@ -715,7 +715,7 @@ void skill_status_change_end(dumb_ptr<block_list> bl, StatusChange type, TimerDa if (bl->bl_type != BL::PC && bl->bl_type != BL::MOB) { if (battle_config.error_log) - PRINTF("skill_status_change_end: neither MOB nor PC !\n"); + PRINTF("skill_status_change_end: neither MOB nor PC !\n"_fmt); return; } sc_data = battle_get_sc_data(bl); @@ -971,7 +971,7 @@ int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type, else { if (battle_config.error_log) - PRINTF("skill_status_change_start: neither MOB nor PC !\n"); + PRINTF("skill_status_change_start: neither MOB nor PC !\n"_fmt); return 0; } @@ -1045,7 +1045,7 @@ int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type, break; default: if (battle_config.error_log) - PRINTF("UnknownStatusChange [%d]\n", type); + PRINTF("UnknownStatusChange [%d]\n"_fmt, type); return 0; } @@ -1175,22 +1175,22 @@ void skill_unit_timer_sub_ondelete(dumb_ptr<block_list> bl, static SP scan_stat(XString statname) { - if (statname == "str") + if (statname == "str"_s) return SP::STR; - if (statname == "dex") + if (statname == "dex"_s) return SP::DEX; - if (statname == "agi") + if (statname == "agi"_s) return SP::AGI; - if (statname == "vit") + if (statname == "vit"_s) return SP::VIT; - if (statname == "int") + if (statname == "int"_s) return SP::INT; - if (statname == "luk") + if (statname == "luk"_s) return SP::LUK; - if (statname == "none") + if (statname == "none"_s) return SP::ZERO; - FPRINTF(stderr, "Unknown stat `%s'\n", AString(statname)); + FPRINTF(stderr, "Unknown stat `%s'\n"_fmt, AString(statname)); return SP::ZERO; } @@ -1199,7 +1199,7 @@ bool skill_readdb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } @@ -1209,7 +1209,7 @@ bool skill_readdb(ZString filename) { // is_comment only works for whole-line comments // that could change once the Z dependency is dropped ... - XString comment = "//"; + LString comment = "//"_s; XString line = line_.xislice_h(std::search(line_.begin(), line_.end(), comment.begin(), comment.end())).rstrip(); if (!line) continue; @@ -1251,9 +1251,9 @@ bool skill_readdb(ZString filename) continue; } - if (castcancel == "yes") + if (castcancel == "yes"_s) skdb.castcancel = true; - else if (castcancel == "no") + else if (castcancel == "no"_s) skdb.castcancel = false; else { @@ -1261,17 +1261,17 @@ bool skill_readdb(ZString filename) continue; } - if (flags == "passive") + if (flags == "passive"_s) { skill_pool_register(i); skdb.poolflags = SkillFlags::POOL_FLAG; } - else if (flags == "active") + else if (flags == "active"_s) { skill_pool_register(i); skdb.poolflags = SkillFlags::POOL_FLAG | SkillFlags::POOL_ACTIVE; } - else if (flags == "no") + else if (flags == "no"_s) skdb.poolflags = SkillFlags::ZERO; else { @@ -1290,7 +1290,7 @@ bool skill_readdb(ZString filename) skill_db[i] = skdb; skill_lookup_by_id(i).desc = RString(tmp); } - PRINTF("read %s done\n", filename); + PRINTF("read %s done\n"_fmt, filename); return rv; } diff --git a/src/map/skill.hpp b/src/map/skill.hpp index 1a615c1..91fa070 100644 --- a/src/map/skill.hpp +++ b/src/map/skill.hpp @@ -61,11 +61,11 @@ earray<skill_db_, SkillID, SkillID::MAX_SKILL_DB> skill_db; struct skill_name_db { SkillID id; // skill id - RString name; // search strings + LString name; // search strings RString desc; // description that shows up for searches // this makes const char(&)[] not decay into const char * in {} - skill_name_db(SkillID i, RString n, RString d) + skill_name_db(SkillID i, LString n, LString d) : id(i), name(n), desc(d) {} }; diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp index 46128d1..7874e8e 100644 --- a/src/map/tmw.cpp +++ b/src/map/tmw.cpp @@ -91,7 +91,7 @@ int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, XString message) { sd->chat_lines_in = sd->chat_total_repeats = 0; - tmw_AutoBan(sd, "chat", battle_config.chat_spam_ban); + tmw_AutoBan(sd, "chat"_s, battle_config.chat_spam_ban); return 1; } @@ -100,8 +100,8 @@ int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, XString message) (sd->chat_lines_in >= battle_config.chat_spam_warn || sd->chat_total_repeats >= battle_config.chat_spam_warn)) { - clif_displaymessage(sd->sess, "WARNING: You are about to be automatically banned for spam!"); - clif_displaymessage(sd->sess, "WARNING: Please slow down, do not repeat, and do not SHOUT!"); + clif_displaymessage(sd->sess, "WARNING: You are about to be automatically banned for spam!"_s); + clif_displaymessage(sd->sess, "WARNING: Please slow down, do not repeat, and do not SHOUT!"_s); } return 0; @@ -114,16 +114,16 @@ void tmw_AutoBan(dumb_ptr<map_session_data> sd, ZString reason, int length) sd->auto_ban_info.in_progress = 1; - AString hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam", + AString hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam"_fmt, sd->status_key.name, reason); tmw_GmHackMsg(hack_msg); - AString fake_command = STRPRINTF("@autoban %s %dh (%s spam)", + AString fake_command = STRPRINTF("@autoban %s %dh (%s spam)"_fmt, sd->status_key.name, length, reason); log_atcommand(sd, fake_command); - AString anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam.", + AString anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam."_fmt, reason); clif_displaymessage(sd->sess, anotherbuf); diff --git a/src/map/trade.cpp b/src/map/trade.cpp index f358d90..7fbfbec 100644 --- a/src/map/trade.cpp +++ b/src/map/trade.cpp @@ -345,7 +345,7 @@ void trade_tradecommit(dumb_ptr<map_session_data> sd) if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) { - MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d", + MAP_LOG_PC(sd, " TRADECOMMIT WITH %d GIVE %d GET %d"_fmt, target_sd->status_key.char_id, sd->deal_zeny, target_sd->deal_zeny); if ((sd->deal_locked >= 1) && (target_sd->deal_locked >= 1)) @@ -360,14 +360,14 @@ void trade_tradecommit(dumb_ptr<map_session_data> sd) { sd->deal_zeny = 0; trade_tradecancel(sd); - MAP_LOG_PC(sd, " TRADECANCEL"); + MAP_LOG_PC(sd, " TRADECANCEL"_fmt); return; } if (target_sd->deal_zeny > target_sd->status.zeny) { target_sd->deal_zeny = 0; trade_tradecancel(sd); - MAP_LOG_PC(sd, " TRADECANCEL"); + MAP_LOG_PC(sd, " TRADECANCEL"_fmt); return; } sd->trade_partner = 0; @@ -431,7 +431,7 @@ void trade_tradecommit(dumb_ptr<map_session_data> sd) target_sd->deal_locked = 0; clif_tradecompleted(sd, 0); clif_tradecompleted(target_sd, 0); - MAP_LOG_PC(sd, " TRADEOK"); + MAP_LOG_PC(sd, " TRADEOK"_fmt); } } } diff --git a/src/mmo/config_parse.cpp b/src/mmo/config_parse.cpp index b954e8b..a6dfd6e 100644 --- a/src/mmo/config_parse.cpp +++ b/src/mmo/config_parse.cpp @@ -30,7 +30,7 @@ bool is_comment(XString line) { - return not line or line.startswith("//"); + return not line or line.startswith("//"_s); } template<class ZS> @@ -72,7 +72,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) io::LineReader in(filename); if (!in.is_open()) { - PRINTF("Unable to open file: %s\n", filename); + PRINTF("Unable to open file: %s\n"_fmt, filename); return false; } io::Line line; @@ -85,16 +85,16 @@ bool load_config_file(ZString filename, ConfigItemParser slave) ZString value; if (!config_split(line.text, &key, &value)) { - line.error("Bad config line"); + line.error("Bad config line"_s); rv = false; continue; } - if (key == "import") + if (key == "import"_s) { rv &= load_config_file(value, slave); continue; } - else if (key == "version-lt") + else if (key == "version-lt"_s) { Version vers; if (!extract(value, &vers)) @@ -106,7 +106,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) continue; break; } - else if (key == "version-le") + else if (key == "version-le"_s) { Version vers; if (!extract(value, &vers)) @@ -118,7 +118,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) continue; break; } - else if (key == "version-gt") + else if (key == "version-gt"_s) { Version vers; if (!extract(value, &vers)) @@ -130,7 +130,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) continue; break; } - else if (key == "version-ge") + else if (key == "version-ge"_s) { Version vers; if (!extract(value, &vers)) @@ -144,7 +144,7 @@ bool load_config_file(ZString filename, ConfigItemParser slave) } else if (!slave(key, value)) { - line.error("Bad config key or value"); + line.error("Bad config key or value"_s); rv = false; continue; } diff --git a/src/mmo/core.cpp b/src/mmo/core.cpp index 68b7823..8b3690a 100644 --- a/src/mmo/core.cpp +++ b/src/mmo/core.cpp @@ -107,7 +107,7 @@ int main(int argc, char **argv) if (!runflag) { - PRINTF("Fatal error during startup; exiting\n"); + PRINTF("Fatal error during startup; exiting\n"_fmt); return 1; } // set up exit handlers *after* the initialization has happened. diff --git a/src/mmo/extract_test.cpp b/src/mmo/extract_test.cpp index 60ab49e..c405de1 100644 --- a/src/mmo/extract_test.cpp +++ b/src/mmo/extract_test.cpp @@ -28,154 +28,154 @@ TEST(extract, record_int) { int x, y, z; x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4 ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3 ", record<' '>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3", record<' '>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1 "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract("1"_s, record<' '>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract(" ", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract(" "_s, record<' '>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("", record<' '>(&x, &y, &z))); + EXPECT_FALSE(extract(""_s, record<' '>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 ", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2", record<' ', 2>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 ", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1 "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract("1"_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract(" ", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract(" "_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("", record<' ', 2>(&x, &y, &z))); + EXPECT_FALSE(extract(""_s, record<' ', 2>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 3", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(3, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2 ", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1 2", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 2"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(2, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1 ", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1 "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_TRUE(extract("1", record<' ', 1>(&x, &y, &z))); + EXPECT_TRUE(extract("1"_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(1, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract(" ", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract(" "_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); x = y = z = 0; - EXPECT_FALSE(extract("", record<' ', 1>(&x, &y, &z))); + EXPECT_FALSE(extract(""_s, record<' ', 1>(&x, &y, &z))); EXPECT_EQ(0, x); EXPECT_EQ(0, y); EXPECT_EQ(0, z); @@ -185,170 +185,170 @@ TEST(extract, record_int) TEST(extract, record_str) { XString x, y, z; - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 ", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1", record<' '>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract(" ", record<' '>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("", record<' '>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1"_s, record<' '>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract(" "_s, record<' '>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract(""_s, record<' '>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("1", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract(" ", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_FALSE(extract("", record<' ', 2>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1"_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract(" "_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract(""_s, record<' ', 2>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; - EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_FALSE(extract("1 2 3 4", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 3", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("3", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 2", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("2", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1 ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("1", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("1", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract(" ", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; - EXPECT_TRUE(extract("", record<' ', 1>(&x, &y, &z))); - EXPECT_EQ("", x); - EXPECT_EQ("", y); - EXPECT_EQ("", z); - x = y = z = ""; + EXPECT_FALSE(extract("1 2 3 4 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_FALSE(extract("1 2 3 4"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 3"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ("3"_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 2"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ("2"_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1 "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract("1"_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ("1"_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract(" "_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; + EXPECT_TRUE(extract(""_s, record<' ', 1>(&x, &y, &z))); + EXPECT_EQ(""_s, x); + EXPECT_EQ(""_s, y); + EXPECT_EQ(""_s, z); + x = y = z = ""_s; } TEST(extract, mapname) { MapName map; - EXPECT_TRUE(extract("abc", &map)); - EXPECT_EQ(map, "abc"); - EXPECT_TRUE(extract("abc.gat", &map)); - EXPECT_EQ(map, "abc"); - EXPECT_TRUE(extract("abcdefghijklmno", &map)); - EXPECT_EQ(map, "abcdefghijklmno"); - EXPECT_TRUE(extract("abcdefghijklmno.gat", &map)); - EXPECT_EQ(map, "abcdefghijklmno"); + EXPECT_TRUE(extract("abc"_s, &map)); + EXPECT_EQ(map, "abc"_s); + EXPECT_TRUE(extract("abc.gat"_s, &map)); + EXPECT_EQ(map, "abc"_s); + EXPECT_TRUE(extract("abcdefghijklmno"_s, &map)); + EXPECT_EQ(map, "abcdefghijklmno"_s); + EXPECT_TRUE(extract("abcdefghijklmno.gat"_s, &map)); + EXPECT_EQ(map, "abcdefghijklmno"_s); } diff --git a/src/mmo/human_time_diff.hpp b/src/mmo/human_time_diff.hpp index 689b8d9..aace438 100644 --- a/src/mmo/human_time_diff.hpp +++ b/src/mmo/human_time_diff.hpp @@ -61,21 +61,21 @@ bool extract(XString str, HumanTimeDiff *iv) str = str.xislice_t(it2); short *ptr = nullptr; - if (suffix == "y" || suffix == "a") + if (suffix == "y"_s || suffix == "a"_s) ptr = &iv->year; - else if (suffix == "m") + else if (suffix == "m"_s) ptr = &iv->month; - else if (suffix == "j" || suffix == "d") + else if (suffix == "j"_s || suffix == "d"_s) ptr = &iv->day; - else if (suffix == "h") + else if (suffix == "h"_s) ptr = &iv->hour; - else if (suffix == "mn") + else if (suffix == "mn"_s) ptr = &iv->minute; - else if (suffix == "s") + else if (suffix == "s"_s) ptr = &iv->second; else return false; - if (number.startswith('+') && !number.startswith("+-")) + if (number.startswith('+') && !number.startswith("+-"_s)) number = number.xslice_t(1); if (*ptr || !extract(number, ptr)) return false; diff --git a/src/mmo/human_time_diff_test.cpp b/src/mmo/human_time_diff_test.cpp index 138849b..fb9522e 100644 --- a/src/mmo/human_time_diff_test.cpp +++ b/src/mmo/human_time_diff_test.cpp @@ -28,7 +28,7 @@ TEST(humantimediff, single) { HumanTimeDiff diff; - EXPECT_TRUE(extract("42y", &diff)); + EXPECT_TRUE(extract("42y"_s, &diff)); EXPECT_EQ(42, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -36,7 +36,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42m", &diff)); + EXPECT_TRUE(extract("42m"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(42, diff.month); EXPECT_EQ(0, diff.day); @@ -44,7 +44,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42d", &diff)); + EXPECT_TRUE(extract("42d"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(42, diff.day); @@ -52,7 +52,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42h", &diff)); + EXPECT_TRUE(extract("42h"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -60,7 +60,7 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42mn", &diff)); + EXPECT_TRUE(extract("42mn"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -68,7 +68,7 @@ TEST(humantimediff, single) EXPECT_EQ(42, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_TRUE(extract("42s", &diff)); + EXPECT_TRUE(extract("42s"_s, &diff)); EXPECT_EQ(0, diff.year); EXPECT_EQ(0, diff.month); EXPECT_EQ(0, diff.day); @@ -76,28 +76,28 @@ TEST(humantimediff, single) EXPECT_EQ(0, diff.minute); EXPECT_EQ(42, diff.second); - EXPECT_TRUE(extract("+42y", &diff)); + EXPECT_TRUE(extract("+42y"_s, &diff)); EXPECT_EQ(42, diff.year); - EXPECT_TRUE(extract("-42y", &diff)); + EXPECT_TRUE(extract("-42y"_s, &diff)); EXPECT_EQ(-42, diff.year); - EXPECT_FALSE(extract("++42y", &diff)); - EXPECT_FALSE(extract("+-42y", &diff)); - EXPECT_FALSE(extract("-+42y", &diff)); - EXPECT_FALSE(extract("--42y", &diff)); - EXPECT_FALSE(extract("4+2y", &diff)); - EXPECT_FALSE(extract("42z", &diff)); + EXPECT_FALSE(extract("++42y"_s, &diff)); + EXPECT_FALSE(extract("+-42y"_s, &diff)); + EXPECT_FALSE(extract("-+42y"_s, &diff)); + EXPECT_FALSE(extract("--42y"_s, &diff)); + EXPECT_FALSE(extract("4+2y"_s, &diff)); + EXPECT_FALSE(extract("42z"_s, &diff)); } TEST(humantimediff, multiple) { HumanTimeDiff diff; - EXPECT_TRUE(extract("42y23m-2d", &diff)); + EXPECT_TRUE(extract("42y23m-2d"_s, &diff)); EXPECT_EQ(42, diff.year); EXPECT_EQ(23, diff.month); EXPECT_EQ(-2, diff.day); EXPECT_EQ(0, diff.hour); EXPECT_EQ(0, diff.minute); EXPECT_EQ(0, diff.second); - EXPECT_FALSE(extract("1y2y", &diff)); + EXPECT_FALSE(extract("1y2y"_s, &diff)); } diff --git a/src/mmo/ip.cpp b/src/mmo/ip.cpp index 146734a..67d6435 100644 --- a/src/mmo/ip.cpp +++ b/src/mmo/ip.cpp @@ -104,11 +104,11 @@ bool extract(XString str, IP4Mask *rv) VString<15> convert_for_printf(IP4Address a_) { const uint8_t *a = a_.bytes(); - return STRNPRINTF(16, "%hhu.%hhu.%hhu.%hhu", a[0], a[1], a[2], a[3]); + return STRNPRINTF(16, "%hhu.%hhu.%hhu.%hhu"_fmt, a[0], a[1], a[2], a[3]); } VString<31> convert_for_printf(IP4Mask a) { - return STRNPRINTF(32, "%s/%s", + return STRNPRINTF(32, "%s/%s"_fmt, a.addr(), a.mask()); } diff --git a/src/mmo/ip_test.cpp b/src/mmo/ip_test.cpp index 8e50453..01f714e 100644 --- a/src/mmo/ip_test.cpp +++ b/src/mmo/ip_test.cpp @@ -66,32 +66,32 @@ TEST(ip4addr, cmp) TEST(ip4addr, str) { IP4Address a; - EXPECT_EQ("0.0.0.0", STRNPRINTF(17, "%s", a)); - EXPECT_EQ("127.0.0.1", STRNPRINTF(17, "%s", IP4_LOCALHOST)); - EXPECT_EQ("255.255.255.255", STRNPRINTF(17, "%s", IP4_BROADCAST)); + EXPECT_EQ("0.0.0.0"_s, STRNPRINTF(17, "%s"_fmt, a)); + EXPECT_EQ("127.0.0.1"_s, STRNPRINTF(17, "%s"_fmt, IP4_LOCALHOST)); + EXPECT_EQ("255.255.255.255"_s, STRNPRINTF(17, "%s"_fmt, IP4_BROADCAST)); } TEST(ip4addr, extract) { IP4Address a; - EXPECT_TRUE(extract("0.0.0.0", &a)); - EXPECT_EQ("0.0.0.0", STRNPRINTF(16, "%s", a)); - EXPECT_TRUE(extract("127.0.0.1", &a)); - EXPECT_EQ("127.0.0.1", STRNPRINTF(16, "%s", a)); - EXPECT_TRUE(extract("255.255.255.255", &a)); - EXPECT_EQ("255.255.255.255", STRNPRINTF(16, "%s", a)); - EXPECT_TRUE(extract("1.2.3.4", &a)); - EXPECT_EQ("1.2.3.4", STRNPRINTF(16, "%s", a)); + EXPECT_TRUE(extract("0.0.0.0"_s, &a)); + EXPECT_EQ("0.0.0.0"_s, STRNPRINTF(16, "%s"_fmt, a)); + EXPECT_TRUE(extract("127.0.0.1"_s, &a)); + EXPECT_EQ("127.0.0.1"_s, STRNPRINTF(16, "%s"_fmt, a)); + EXPECT_TRUE(extract("255.255.255.255"_s, &a)); + EXPECT_EQ("255.255.255.255"_s, STRNPRINTF(16, "%s"_fmt, a)); + EXPECT_TRUE(extract("1.2.3.4"_s, &a)); + EXPECT_EQ("1.2.3.4"_s, STRNPRINTF(16, "%s"_fmt, a)); - EXPECT_FALSE(extract("1.2.3.4.5", &a)); - EXPECT_FALSE(extract("1.2.3.4.", &a)); - EXPECT_FALSE(extract("1.2.3.", &a)); - EXPECT_FALSE(extract("1.2.3", &a)); - EXPECT_FALSE(extract("1.2.", &a)); - EXPECT_FALSE(extract("1.2", &a)); - EXPECT_FALSE(extract("1.", &a)); - EXPECT_FALSE(extract("1", &a)); - EXPECT_FALSE(extract("", &a)); + EXPECT_FALSE(extract("1.2.3.4.5"_s, &a)); + EXPECT_FALSE(extract("1.2.3.4."_s, &a)); + EXPECT_FALSE(extract("1.2.3."_s, &a)); + EXPECT_FALSE(extract("1.2.3"_s, &a)); + EXPECT_FALSE(extract("1.2."_s, &a)); + EXPECT_FALSE(extract("1.2"_s, &a)); + EXPECT_FALSE(extract("1."_s, &a)); + EXPECT_FALSE(extract("1"_s, &a)); + EXPECT_FALSE(extract(""_s, &a)); } @@ -108,139 +108,139 @@ TEST(ip4mask, body) TEST(ip4mask, str) { IP4Mask m; - EXPECT_EQ("0.0.0.0/0.0.0.0", STRNPRINTF(33, "%s", m)); + EXPECT_EQ("0.0.0.0/0.0.0.0"_s, STRNPRINTF(33, "%s"_fmt, m)); m = IP4Mask(IP4_LOCALHOST, IP4_BROADCAST); - EXPECT_EQ("127.0.0.1/255.255.255.255", STRNPRINTF(33, "%s", m)); + EXPECT_EQ("127.0.0.1/255.255.255.255"_s, STRNPRINTF(33, "%s"_fmt, m)); } TEST(ip4mask, extract) { IP4Mask m; - EXPECT_FALSE(extract("9.8.7.6/33", &m)); - EXPECT_FALSE(extract("9.8.7.6.5", &m)); - EXPECT_FALSE(extract("9.8.7.6/", &m)); - EXPECT_FALSE(extract("9.8.7", &m)); - EXPECT_FALSE(extract("9.8", &m)); - EXPECT_FALSE(extract("9", &m)); + EXPECT_FALSE(extract("9.8.7.6/33"_s, &m)); + EXPECT_FALSE(extract("9.8.7.6.5"_s, &m)); + EXPECT_FALSE(extract("9.8.7.6/"_s, &m)); + EXPECT_FALSE(extract("9.8.7"_s, &m)); + EXPECT_FALSE(extract("9.8"_s, &m)); + EXPECT_FALSE(extract("9"_s, &m)); - EXPECT_TRUE(extract("127.0.0.1", &m)); - EXPECT_EQ("127.0.0.1/255.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.0.0.1.", &m)); - EXPECT_EQ("127.0.0.1/255.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.0.0.", &m)); - EXPECT_EQ("127.0.0.0/255.255.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.0.", &m)); - EXPECT_EQ("127.0.0.0/255.255.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("127.", &m)); - EXPECT_EQ("127.0.0.0/255.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("127.0.0.1"_s, &m)); + EXPECT_EQ("127.0.0.1/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127.0.0.1."_s, &m)); + EXPECT_EQ("127.0.0.1/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127.0.0."_s, &m)); + EXPECT_EQ("127.0.0.0/255.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127.0."_s, &m)); + EXPECT_EQ("127.0.0.0/255.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("127."_s, &m)); + EXPECT_EQ("127.0.0.0/255.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("1.2.3.4/255.255.255.255", &m)); - EXPECT_EQ("1.2.3.4/255.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.2.3.0/255.255.255.0", &m)); - EXPECT_EQ("1.2.3.0/255.255.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.2.0.4/255.255.0.255", &m)); - EXPECT_EQ("1.2.0.4/255.255.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.2.0.0/255.255.0.0", &m)); - EXPECT_EQ("1.2.0.0/255.255.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.3.4/255.0.255.255", &m)); - EXPECT_EQ("1.0.3.4/255.0.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.3.0/255.0.255.0", &m)); - EXPECT_EQ("1.0.3.0/255.0.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.0.4/255.0.0.255", &m)); - EXPECT_EQ("1.0.0.4/255.0.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("1.0.0.0/255.0.0.0", &m)); - EXPECT_EQ("1.0.0.0/255.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.3.4/0.255.255.255", &m)); - EXPECT_EQ("0.2.3.4/0.255.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.3.0/0.255.255.0", &m)); - EXPECT_EQ("0.2.3.0/0.255.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.0.4/0.255.0.255", &m)); - EXPECT_EQ("0.2.0.4/0.255.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.2.0.0/0.255.0.0", &m)); - EXPECT_EQ("0.2.0.0/0.255.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.3.4/0.0.255.255", &m)); - EXPECT_EQ("0.0.3.4/0.0.255.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.3.0/0.0.255.0", &m)); - EXPECT_EQ("0.0.3.0/0.0.255.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.4/0.0.0.255", &m)); - EXPECT_EQ("0.0.0.4/0.0.0.255", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/0.0.0.0", &m)); - EXPECT_EQ("0.0.0.0/0.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("1.2.3.4/255.255.255.255"_s, &m)); + EXPECT_EQ("1.2.3.4/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.2.3.0/255.255.255.0"_s, &m)); + EXPECT_EQ("1.2.3.0/255.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.2.0.4/255.255.0.255"_s, &m)); + EXPECT_EQ("1.2.0.4/255.255.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.2.0.0/255.255.0.0"_s, &m)); + EXPECT_EQ("1.2.0.0/255.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.3.4/255.0.255.255"_s, &m)); + EXPECT_EQ("1.0.3.4/255.0.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.3.0/255.0.255.0"_s, &m)); + EXPECT_EQ("1.0.3.0/255.0.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.0.4/255.0.0.255"_s, &m)); + EXPECT_EQ("1.0.0.4/255.0.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("1.0.0.0/255.0.0.0"_s, &m)); + EXPECT_EQ("1.0.0.0/255.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.3.4/0.255.255.255"_s, &m)); + EXPECT_EQ("0.2.3.4/0.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.3.0/0.255.255.0"_s, &m)); + EXPECT_EQ("0.2.3.0/0.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.0.4/0.255.0.255"_s, &m)); + EXPECT_EQ("0.2.0.4/0.255.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.2.0.0/0.255.0.0"_s, &m)); + EXPECT_EQ("0.2.0.0/0.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.3.4/0.0.255.255"_s, &m)); + EXPECT_EQ("0.0.3.4/0.0.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.3.0/0.0.255.0"_s, &m)); + EXPECT_EQ("0.0.3.0/0.0.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.4/0.0.0.255"_s, &m)); + EXPECT_EQ("0.0.0.4/0.0.0.255"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/0.0.0.0"_s, &m)); + EXPECT_EQ("0.0.0.0/0.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); // please don't do this - EXPECT_TRUE(extract("120.248.200.217/89.57.126.5", &m)); - EXPECT_EQ("88.56.72.1/89.57.126.5", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("120.248.200.217/89.57.126.5"_s, &m)); + EXPECT_EQ("88.56.72.1/89.57.126.5"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/32", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.255", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/32"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.255"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/31", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.254", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/30", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.252", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/29", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.248", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/28", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.240", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/27", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.224", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/26", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.192", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/25", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.128", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/24", &m)); - EXPECT_EQ("0.0.0.0/255.255.255.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/31"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.254"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/30"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.252"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/29"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.248"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/28"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.240"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/27"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.224"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/26"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.192"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/25"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.128"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/24"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.255.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/23", &m)); - EXPECT_EQ("0.0.0.0/255.255.254.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/22", &m)); - EXPECT_EQ("0.0.0.0/255.255.252.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/21", &m)); - EXPECT_EQ("0.0.0.0/255.255.248.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/20", &m)); - EXPECT_EQ("0.0.0.0/255.255.240.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/19", &m)); - EXPECT_EQ("0.0.0.0/255.255.224.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/18", &m)); - EXPECT_EQ("0.0.0.0/255.255.192.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/17", &m)); - EXPECT_EQ("0.0.0.0/255.255.128.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/16", &m)); - EXPECT_EQ("0.0.0.0/255.255.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/23"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.254.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/22"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.252.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/21"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.248.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/20"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.240.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/19"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.224.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/18"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.192.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/17"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.128.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/16"_s, &m)); + EXPECT_EQ("0.0.0.0/255.255.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/15", &m)); - EXPECT_EQ("0.0.0.0/255.254.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/14", &m)); - EXPECT_EQ("0.0.0.0/255.252.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/13", &m)); - EXPECT_EQ("0.0.0.0/255.248.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/12", &m)); - EXPECT_EQ("0.0.0.0/255.240.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/11", &m)); - EXPECT_EQ("0.0.0.0/255.224.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/10", &m)); - EXPECT_EQ("0.0.0.0/255.192.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/9", &m)); - EXPECT_EQ("0.0.0.0/255.128.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/8", &m)); - EXPECT_EQ("0.0.0.0/255.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/15"_s, &m)); + EXPECT_EQ("0.0.0.0/255.254.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/14"_s, &m)); + EXPECT_EQ("0.0.0.0/255.252.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/13"_s, &m)); + EXPECT_EQ("0.0.0.0/255.248.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/12"_s, &m)); + EXPECT_EQ("0.0.0.0/255.240.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/11"_s, &m)); + EXPECT_EQ("0.0.0.0/255.224.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/10"_s, &m)); + EXPECT_EQ("0.0.0.0/255.192.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/9"_s, &m)); + EXPECT_EQ("0.0.0.0/255.128.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/8"_s, &m)); + EXPECT_EQ("0.0.0.0/255.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); - EXPECT_TRUE(extract("0.0.0.0/7", &m)); - EXPECT_EQ("0.0.0.0/254.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/6", &m)); - EXPECT_EQ("0.0.0.0/252.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/5", &m)); - EXPECT_EQ("0.0.0.0/248.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/4", &m)); - EXPECT_EQ("0.0.0.0/240.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/3", &m)); - EXPECT_EQ("0.0.0.0/224.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/2", &m)); - EXPECT_EQ("0.0.0.0/192.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/1", &m)); - EXPECT_EQ("0.0.0.0/128.0.0.0", STRNPRINTF(32, "%s", m)); - EXPECT_TRUE(extract("0.0.0.0/0", &m)); - EXPECT_EQ("0.0.0.0/0.0.0.0", STRNPRINTF(32, "%s", m)); + EXPECT_TRUE(extract("0.0.0.0/7"_s, &m)); + EXPECT_EQ("0.0.0.0/254.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/6"_s, &m)); + EXPECT_EQ("0.0.0.0/252.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/5"_s, &m)); + EXPECT_EQ("0.0.0.0/248.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/4"_s, &m)); + EXPECT_EQ("0.0.0.0/240.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/3"_s, &m)); + EXPECT_EQ("0.0.0.0/224.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/2"_s, &m)); + EXPECT_EQ("0.0.0.0/192.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/1"_s, &m)); + EXPECT_EQ("0.0.0.0/128.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); + EXPECT_TRUE(extract("0.0.0.0/0"_s, &m)); + EXPECT_EQ("0.0.0.0/0.0.0.0"_s, STRNPRINTF(32, "%s"_fmt, m)); } TEST(ip4mask, cover) @@ -344,7 +344,7 @@ TEST(ip4mask, cover) EXPECT_FALSE(m.covers(IP4Address({192, 169, 0, 0}))); // OTOH this is crazy - EXPECT_TRUE(extract("120.248.200.217/89.57.126.5", &m)); + EXPECT_TRUE(extract("120.248.200.217/89.57.126.5"_s, &m)); EXPECT_TRUE(m.covers(IP4Address({120, 248, 200, 217}))); EXPECT_TRUE(m.covers(IP4Address({88, 56, 72, 1}))); EXPECT_FALSE(m.covers(IP4Address({88, 56, 72, 0}))); diff --git a/src/mmo/md5more.cpp b/src/mmo/md5more.cpp index 3fce5c7..cc17d37 100644 --- a/src/mmo/md5more.cpp +++ b/src/mmo/md5more.cpp @@ -103,7 +103,7 @@ AccountCrypt MD5_saltcrypt(AccountPass key, SaltString salt) VString<31> obuf; // This truncates the string, but we have to keep it like that for compatibility - SNPRINTF(obuf, 32, "!%s$%s", salt, tbuf3); + SNPRINTF(obuf, 32, "!%s$%s"_fmt, salt, tbuf3); return stringish<AccountCrypt>(obuf); } @@ -134,7 +134,7 @@ IP4Address MD5_ip(IP4Address ip) // MD5sum a secret + the IP address VString<31> ipbuf; - SNPRINTF(ipbuf, 32, "%s %s", ip, secret); + SNPRINTF(ipbuf, 32, "%s %s"_fmt, ip, secret); md5_binary obuf; MD5_to_bin(MD5_from_string(ipbuf), obuf); diff --git a/src/mmo/mmo.hpp b/src/mmo/mmo.hpp index c9d62ca..3fba7e6 100644 --- a/src/mmo/mmo.hpp +++ b/src/mmo/mmo.hpp @@ -85,7 +85,7 @@ struct ServerName : VString<19> {}; struct PartyName : VString<23> {}; struct VarName : VString<31> {}; -# define DEFAULT_EMAIL stringish<AccountEmail>("a@a.com") +# define DEFAULT_EMAIL stringish<AccountEmail>("a@a.com"_s) // It is decreed: a mapname shall not contain an extension class MapName : public strings::_crtp_string<MapName, MapName, strings::ZPair> diff --git a/src/mmo/socket.cpp b/src/mmo/socket.cpp index 48cd149..364e769 100644 --- a/src/mmo/socket.cpp +++ b/src/mmo/socket.cpp @@ -158,7 +158,7 @@ void send_from_fifo(Session *s) static void null_parse(Session *s) { - PRINTF("null_parse : %d\n", s); + PRINTF("null_parse : %d\n"_fmt, s); RFIFOSKIP(s, RFIFOREST(s)); } @@ -177,7 +177,7 @@ void connect_client(Session *ls) } if (fd.uncast_dammit() >= SOFT_LIMIT) { - FPRINTF(stderr, "softlimit reached, disconnecting : %d\n", fd.uncast_dammit()); + FPRINTF(stderr, "softlimit reached, disconnecting : %d\n"_fmt, fd.uncast_dammit()); fd.shutdown(SHUT_RDWR); fd.close(); return; @@ -389,12 +389,12 @@ void WFIFOSET(Session *s, size_t len) if (s->wdata_size + len + 16384 > s->max_wdata) { realloc_fifo(s, s->max_rdata, s->max_wdata << 1); - PRINTF("socket: %d wdata expanded to %zu bytes.\n", s, s->max_wdata); + PRINTF("socket: %d wdata expanded to %zu bytes.\n"_fmt, s, s->max_wdata); } if (s->wdata_size + len + 2048 < s->max_wdata) s->wdata_size += len; else - FPRINTF(stderr, "socket: %d wdata lost !!\n", s), abort(); + FPRINTF(stderr, "socket: %d wdata lost !!\n"_fmt, s), abort(); } void do_sendrecv(interval_t next_ms) @@ -415,7 +415,7 @@ void do_sendrecv(interval_t next_ms) { if (!has_timers()) { - PRINTF("Shutting down - nothing to do\n"); + PRINTF("Shutting down - nothing to do\n"_fmt); runflag = false; } return; @@ -460,7 +460,7 @@ void do_parsepacket(void) if (!s->connected && static_cast<time_t>(TimeT::now()) - static_cast<time_t>(s->created) > CONNECT_TIMEOUT) { - PRINTF("Session #%d timed out\n", s); + PRINTF("Session #%d timed out\n"_fmt, s); s->eof = 1; } if (!s->rdata_size && !s->eof) @@ -489,7 +489,7 @@ void RFIFOSKIP(Session *s, size_t len) if (s->rdata_size < s->rdata_pos) { - FPRINTF(stderr, "too many skip\n"); + FPRINTF(stderr, "too many skip\n"_fmt); abort(); } } diff --git a/src/mmo/utils.cpp b/src/mmo/utils.cpp index a1316d1..5765eaf 100644 --- a/src/mmo/utils.cpp +++ b/src/mmo/utils.cpp @@ -57,9 +57,9 @@ bool e_mail_check(XString email) return 0; if (hostname.front() == '.' || hostname.back() == '.') return 0; - if (hostname.contains_seq("..")) + if (hostname.contains_seq(".."_s)) return 0; - if (email.contains_any(" ;")) + if (email.contains_any(" ;"_s)) return 0; return email.is_print(); } @@ -70,18 +70,18 @@ bool e_mail_check(XString email) //------------------------------------------------- int config_switch(ZString str) { - if (str == "true" || str == "on" || str == "yes" - || str == "oui" || str == "ja" - || str == "si") + if (str == "true"_s || str == "on"_s || str == "yes"_s + || str == "oui"_s || str == "ja"_s + || str == "si"_s) return 1; - if (str == "false" || str == "off" || str == "no" - || str == "non" || str == "nein") + if (str == "false"_s || str == "off"_s || str == "no"_s + || str == "non"_s || str == "nein"_s) return 0; int rv; if (extract(str, &rv)) return rv; - FPRINTF(stderr, "Fatal: bad option value %s", str); + FPRINTF(stderr, "Fatal: bad option value %s"_fmt, str); abort(); } @@ -93,7 +93,7 @@ void stamp_time(timestamp_seconds_buffer& out, const TimeT *t) struct tm when = t ? *t : TimeT::now(); char buf[20]; strftime(buf, 20, "%Y-%m-%d %H:%M:%S", &when); - out = stringish<timestamp_seconds_buffer>(const_(buf)); + out = stringish<timestamp_seconds_buffer>(VString<19>(strings::really_construct_from_a_pointer, buf)); } void stamp_time(timestamp_milliseconds_buffer& out) { @@ -103,7 +103,7 @@ void stamp_time(timestamp_milliseconds_buffer& out) char buf[24]; strftime(buf, 20, "%Y-%m-%d %H:%M:%S", &when); sprintf(buf + 19, ".%03d", static_cast<int>(tv.tv_usec / 1000)); - out = stringish<timestamp_milliseconds_buffer>(const_(buf)); + out = stringish<timestamp_milliseconds_buffer>(VString<23>(strings::really_construct_from_a_pointer, buf)); } void log_with_timestamp(io::WriteFile& out, XString line) diff --git a/src/monitor/main.cpp b/src/monitor/main.cpp index c882105..21d6065 100644 --- a/src/monitor/main.cpp +++ b/src/monitor/main.cpp @@ -39,10 +39,10 @@ #include "../poison.hpp" -#define LOGIN_SERVER "./login-server" -#define MAP_SERVER "./map-server" -#define CHAR_SERVER "./char-server" -#define CONFIG "conf/eathena-monitor.conf" +#define LOGIN_SERVER "./login-server"_s +#define MAP_SERVER "./map-server"_s +#define CHAR_SERVER "./char-server"_s +#define CONFIG "conf/eathena-monitor.conf"_s // initialiized to $HOME/tmwserver @@ -72,17 +72,17 @@ AString make_path(XString base, XString path) static bool parse_option(XString name, ZString value) { - if (name == "login_server") + if (name == "login_server"_s) login_server = value; - else if (name == "map_server") + else if (name == "map_server"_s) map_server = value; - else if (name == "char_server") + else if (name == "char_server"_s) char_server = value; - else if (name == "workdir") + else if (name == "workdir"_s) workdir = value; else { - FPRINTF(stderr, "WARNING: ingnoring invalid option '%s' : '%s'\n", + FPRINTF(stderr, "WARNING: ingnoring invalid option '%s' : '%s'\n"_fmt, AString(name), value); return false; } @@ -96,7 +96,7 @@ bool read_config(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - FPRINTF(stderr, "Monitor config file not found: %s\n", filename); + FPRINTF(stderr, "Monitor config file not found: %s\n"_fmt, filename); exit(1); } @@ -109,14 +109,14 @@ bool read_config(ZString filename) ZString value; if (!config_split(line, &name, &value)) { - PRINTF("Bad line: %s\n", line); + PRINTF("Bad line: %s\n"_fmt, line); rv = false; continue; } if (!parse_option(name, value)) { - PRINTF("Bad key/value: %s\n", line); + PRINTF("Bad key/value: %s\n"_fmt, line); rv = false; continue; } @@ -131,7 +131,7 @@ pid_t start_process(ZString exec) pid_t pid = fork(); if (pid == -1) { - FPRINTF(stderr, "Failed to fork"); + FPRINTF(stderr, "Failed to fork"_fmt); return 0; } if (pid == 0) @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) signal(SIGQUIT, stop_process); signal(SIGABRT, stop_process); - workdir = make_path(ZString(strings::really_construct_from_a_pointer, getenv("HOME"), nullptr), "tmwserver"); + workdir = make_path(ZString(strings::really_construct_from_a_pointer, getenv("HOME"), nullptr), "tmwserver"_s); ZString config = CONFIG; if (argc > 1) @@ -186,11 +186,11 @@ int main(int argc, char *argv[]) exit(1); } - PRINTF("Starting:\n"); - PRINTF("* workdir: %s\n", workdir); - PRINTF("* login_server: %s\n", login_server); - PRINTF("* char_server: %s\n", char_server); - PRINTF("* map_server: %s\n", map_server); + PRINTF("Starting:\n"_fmt); + PRINTF("* workdir: %s\n"_fmt, workdir); + PRINTF("* login_server: %s\n"_fmt, login_server); + PRINTF("* char_server: %s\n"_fmt, char_server); + PRINTF("* map_server: %s\n"_fmt, map_server); { //make sure all possible file descriptors are free for use by the servers //if there are file descriptors higher than the max open from before the limit dropped, that's not our problem @@ -198,9 +198,9 @@ int main(int argc, char *argv[]) while ((fd = fd.prev()) > io::FD::stderr()) { if (fd.close() == 0) - FPRINTF(stderr, "close fd %d\n", fd.uncast_dammit()); + FPRINTF(stderr, "close fd %d\n"_fmt, fd.uncast_dammit()); } - fd = io::FD::open("/dev/null", O_RDWR); + fd = io::FD::open("/dev/null"_s, O_RDWR); if (fd == io::FD()) { perror("open /dev/null"); @@ -219,19 +219,19 @@ int main(int argc, char *argv[]) if (!pid_login) { pid_login = start_process(login_server); - FPRINTF(stderr, "[%s] forked login server: %lu\n", + FPRINTF(stderr, "[%s] forked login server: %lu\n"_fmt, timestamp, static_cast<unsigned long>(pid_login)); } if (!pid_char) { pid_char = start_process(char_server); - FPRINTF(stderr, "[%s] forked char server: %lu\n", + FPRINTF(stderr, "[%s] forked char server: %lu\n"_fmt, timestamp, static_cast<unsigned long>(pid_char)); } if (!pid_map) { pid_map = start_process(map_server); - FPRINTF(stderr, "[%s] forked map server: %lu\n", + FPRINTF(stderr, "[%s] forked map server: %lu\n"_fmt, timestamp, static_cast<unsigned long>(pid_map)); } pid_t dead = wait(NULL); diff --git a/src/sanity.hpp b/src/sanity.hpp index f29a7c3..70ee8fe 100644 --- a/src/sanity.hpp +++ b/src/sanity.hpp @@ -34,16 +34,17 @@ # if __GNUC__ == 4 // clang identifies as GCC 4.2, but is mostly okay. // Until a bug-free release of it happens, though, I won't recommend it. -// (patched) clang 3.1 would be the requirement -# if __GNUC_MINOR__ < 6 && !defined(__clang__) -# error "Please upgrade to at least GCC 4.6" -# endif // __GNUC_MINOR__ < 6 && !defined(__clang__) +// clang 3.2 is the minimum that the CI builds are using +# if __GNUC_MINOR__ < 7 && !defined(__clang__) +# error "Please upgrade to at least GCC 4.7" +# endif // __GNUC_MINOR__ < 7 && !defined(__clang__) # endif // __GNUC__ == 4 # if not defined(__i386__) and not defined(__x86_64__) // Known platform dependencies: // endianness for the [RW]FIFO.* macros // possibly, some signal-handling +// some integer sizes (partially fixed for the x32 ABI) # error "Unsupported platform, we use x86 / amd64 only" # endif // not __i386__ diff --git a/src/sexpr/lexer.cpp b/src/sexpr/lexer.cpp index 8c1c380..cc7087b 100644 --- a/src/sexpr/lexer.cpp +++ b/src/sexpr/lexer.cpp @@ -28,14 +28,14 @@ namespace sexpr { Lexeme Lexer::_adv() { - XString whitespace = " \t\n\r\v\f"; + LString whitespace = " \t\n\r\v\f"_s; while (true) { if (!_in.get(_span.begin)) { if (!_depth.empty()) { - _depth.back().error("Unmatched '('"); + _depth.back().error("Unmatched '('"_s); return TOK_ERROR; } return TOK_EOF; @@ -52,14 +52,14 @@ namespace sexpr switch (co) { case '(': - _string = "("; + _string = "("_s; _depth.push_back(_span.end); return TOK_OPEN; case ')': - _string = ")"; + _string = ")"_s; if (_depth.empty()) { - _span.end.error("Unmatched ')'"); + _span.end.error("Unmatched ')'"_s); return TOK_ERROR; } _depth.pop_back(); @@ -73,7 +73,7 @@ namespace sexpr { if (!_in.get(_span.end)) { - _span.error("EOF in string literal"); + _span.error("EOF in string literal"_s); return TOK_ERROR; } char ch = _span.end.ch(); @@ -89,7 +89,7 @@ namespace sexpr if (!_in.get(_span.end)) { - _span.end.error("EOF at backslash in string"); + _span.end.error("EOF at backslash in string"_s); return TOK_ERROR; } ch = _span.end.ch(); @@ -97,7 +97,7 @@ namespace sexpr switch (ch) { default: - _span.end.error("Unknown backslash sequence"); + _span.end.error("Unknown backslash sequence"_s); return TOK_ERROR; case 'a': collect += '\a'; break; case 'b': collect += '\b'; break; @@ -117,7 +117,7 @@ namespace sexpr tmp *= 16; if (!_in.get(_span.end)) { - _span.end.error("EOF after \\x in string"); + _span.end.error("EOF after \\x in string"_s); return TOK_ERROR; } char cx = _span.end.ch(); @@ -130,7 +130,7 @@ namespace sexpr tmp += cx - 'a' + 10; else { - _span.end.error("Non-hex char after \\x"); + _span.end.error("Non-hex char after \\x"_s); return TOK_ERROR; } } @@ -143,7 +143,7 @@ namespace sexpr } case '\'': case '\\': - _span.end.error("forbidden character"); + _span.end.error("forbidden character"_s); return TOK_ERROR; default: // this includes integers - they are differentiated in parsing @@ -168,7 +168,7 @@ namespace sexpr } _string = AString(collect); if (!_string.is_print()) - _span.error("String is not entirely printable"); + _span.error("String is not entirely printable"_s); return TOK_TOKEN; } } @@ -178,23 +178,23 @@ namespace sexpr { switch (c) { - case '\a': return {"\\a"}; - case '\b': return {"\\b"}; - case '\e': return {"\\e"}; - case '\f': return {"\\f"}; - //case '\n': return {"\\n"}; - case '\r': return {"\\r"}; - case '\t': return {"\\t"}; - case '\v': return {"\\v"}; - case '\\': return {"\\\\"}; - case '\"': return {"\\\""}; + case '\a': return "\\a"_s; + case '\b': return "\\b"_s; + case '\e': return "\\e"_s; + case '\f': return "\\f"_s; + //case '\n': return "\\n"_s; + case '\r': return "\\r"_s; + case '\t': return "\\t"_s; + case '\v': return "\\v"_s; + case '\\': return "\\\\"_s; + case '\"': return "\\\""_s; default: if (c == '\n') return c; if (' ' <= c && c <= '~') return c; else - return STRNPRINTF(5, "\\x%02x", static_cast<uint8_t>(c)); + return STRNPRINTF(5, "\\x%02x"_fmt, static_cast<uint8_t>(c)); } } AString escape(XString s) @@ -207,22 +207,22 @@ namespace sexpr return AString(m); } - ZString token_name(Lexeme tok) + LString token_name(Lexeme tok) { switch (tok) { case TOK_EOF: - return ZString("EOF"); + return "EOF"_s; case TOK_OPEN: - return ZString("OPEN"); + return "OPEN"_s; case TOK_CLOSE: - return ZString("CLOSE"); + return "CLOSE"_s; case TOK_STRING: - return ZString("STRING"); + return "STRING"_s; case TOK_TOKEN: - return ZString("TOKEN"); + return "TOKEN"_s; default: - return ZString("ERROR"); + return "ERROR"_s; } } } // namespace sexpr diff --git a/src/sexpr/lexer.hpp b/src/sexpr/lexer.hpp index 7bce620..84c9e1d 100644 --- a/src/sexpr/lexer.hpp +++ b/src/sexpr/lexer.hpp @@ -67,7 +67,7 @@ namespace sexpr VString<4> escape(char c); AString escape(XString s); - ZString token_name(Lexeme tok); + LString token_name(Lexeme tok); } // namespace sexpr #endif // TMWA_SEXPR_LEXER_HPP diff --git a/src/sexpr/lexer_test.cpp b/src/sexpr/lexer_test.cpp index ade79af..fbff0d8 100644 --- a/src/sexpr/lexer_test.cpp +++ b/src/sexpr/lexer_test.cpp @@ -40,69 +40,69 @@ io::FD string_pipe(ZString sz) TEST(sexpr, escape) { - EXPECT_EQ(sexpr::escape('\0'), "\\x00"); - EXPECT_EQ(sexpr::escape('\x1f'), "\\x1f"); - EXPECT_EQ(sexpr::escape('\x20'), " "); - EXPECT_EQ(sexpr::escape('\x7e'), "~"); - EXPECT_EQ(sexpr::escape('\x7f'), "\\x7f"); - EXPECT_EQ(sexpr::escape('\x80'), "\\x80"); - EXPECT_EQ(sexpr::escape('\xff'), "\\xff"); - EXPECT_EQ(sexpr::escape('\a'), "\\a"); - EXPECT_EQ(sexpr::escape('\b'), "\\b"); - EXPECT_EQ(sexpr::escape('\e'), "\\e"); - EXPECT_EQ(sexpr::escape('\f'), "\\f"); - //EXPECT_EQ(sexpr::escape('\n'), "\\n"); - EXPECT_EQ(sexpr::escape('\n'), "\n"); - EXPECT_EQ(sexpr::escape('\r'), "\\r"); - EXPECT_EQ(sexpr::escape('\t'), "\\t"); - EXPECT_EQ(sexpr::escape('\v'), "\\v"); - EXPECT_EQ(sexpr::escape('\\'), "\\\\"); - EXPECT_EQ(sexpr::escape('\"'), "\\\""); + EXPECT_EQ(sexpr::escape('\0'), "\\x00"_s); + EXPECT_EQ(sexpr::escape('\x1f'), "\\x1f"_s); + EXPECT_EQ(sexpr::escape('\x20'), " "_s); + EXPECT_EQ(sexpr::escape('\x7e'), "~"_s); + EXPECT_EQ(sexpr::escape('\x7f'), "\\x7f"_s); + EXPECT_EQ(sexpr::escape('\x80'), "\\x80"_s); + EXPECT_EQ(sexpr::escape('\xff'), "\\xff"_s); + EXPECT_EQ(sexpr::escape('\a'), "\\a"_s); + EXPECT_EQ(sexpr::escape('\b'), "\\b"_s); + EXPECT_EQ(sexpr::escape('\e'), "\\e"_s); + EXPECT_EQ(sexpr::escape('\f'), "\\f"_s); + //EXPECT_EQ(sexpr::escape('\n'), "\\n"_s); + EXPECT_EQ(sexpr::escape('\n'), "\n"_s); + EXPECT_EQ(sexpr::escape('\r'), "\\r"_s); + EXPECT_EQ(sexpr::escape('\t'), "\\t"_s); + EXPECT_EQ(sexpr::escape('\v'), "\\v"_s); + EXPECT_EQ(sexpr::escape('\\'), "\\\\"_s); + EXPECT_EQ(sexpr::escape('\"'), "\\\""_s); - EXPECT_EQ(sexpr::escape("\x1f\x20\x7e\x7f\x80\xff\a\b\e\f\r\t\v\\\""), - "\"\\x1f ~\\x7f\\x80\\xff\\a\\b\\e\\f\\r\\t\\v\\\\\\\"\""); + EXPECT_EQ(sexpr::escape("\x1f\x20\x7e\x7f\x80\xff\a\b\e\f\r\t\v\\\""_s), + "\"\\x1f ~\\x7f\\x80\\xff\\a\\b\\e\\f\\r\\t\\v\\\\\\\"\""_s); } TEST(sexpr, lexer) { io::LineSpan span; - sexpr::Lexer lexer("<lexer-test1>", string_pipe(" foo( ) 123\"\" \n")); + sexpr::Lexer lexer("<lexer-test1>"_s, string_pipe(" foo( ) 123\"\" \n"_s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_TOKEN); - EXPECT_EQ(lexer.val_string(), "foo"); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.val_string(), "foo"_s); + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:2: error: test\n" " foo( ) 123\"\" \n" - " ^~~\n" + " ^~~\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_OPEN); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:5: error: test\n" " foo( ) 123\"\" \n" - " ^\n" + " ^\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_CLOSE); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:7: error: test\n" " foo( ) 123\"\" \n" - " ^\n" + " ^\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_TOKEN); - EXPECT_EQ(lexer.val_string(), "123"); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.val_string(), "123"_s); + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:9: error: test\n" " foo( ) 123\"\" \n" - " ^~~\n" + " ^~~\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_STRING); - EXPECT_EQ(lexer.val_string(), ""); - EXPECT_EQ(lexer.span().message_str("error", "test"), + EXPECT_EQ(lexer.val_string(), ""_s); + EXPECT_EQ(lexer.span().message_str("error"_s, "test"_s), "<lexer-test1>:1:12: error: test\n" " foo( ) 123\"\" \n" - " ^~\n" + " ^~\n"_s ); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_EOF); @@ -112,22 +112,22 @@ TEST(sexpr, lexbad) { { io::LineSpan span; - sexpr::Lexer lexer("<lexer-bad>", string_pipe("(\n")); + sexpr::Lexer lexer("<lexer-bad>"_s, string_pipe("(\n"_s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_OPEN); lexer.adv(); EXPECT_EQ(lexer.peek(), sexpr::TOK_ERROR); } for (ZString bad : { - ZString(")\n"), - ZString("\"\n"), - ZString("'\n"), - ZString("\\\n"), - ZString("\"\\"), - ZString("\"\\z\""), + ZString(")\n"_s), + ZString("\"\n"_s), + ZString("'\n"_s), + ZString("\\\n"_s), + ZString("\"\\"_s), + ZString("\"\\z\""_s), }) { io::LineSpan span; - sexpr::Lexer lexer("<lexer-bad>", string_pipe(bad)); + sexpr::Lexer lexer("<lexer-bad>"_s, string_pipe(bad)); EXPECT_EQ(lexer.peek(), sexpr::TOK_ERROR); } } diff --git a/src/sexpr/parser_test.cpp b/src/sexpr/parser_test.cpp index d67d041..0be333b 100644 --- a/src/sexpr/parser_test.cpp +++ b/src/sexpr/parser_test.cpp @@ -42,11 +42,11 @@ TEST(sexpr, parser) { sexpr::SExpr s; io::LineSpan span; - sexpr::Lexer lexer("<parser-test1>", string_pipe(" foo( ) 123\"\" \n")); + sexpr::Lexer lexer("<parser-test1>"_s, string_pipe(" foo( ) 123\"\" \n"_s)); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::TOKEN); - EXPECT_EQ(s._str, "foo"); + EXPECT_EQ(s._str, "foo"_s); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::LIST); @@ -58,7 +58,7 @@ TEST(sexpr, parser) EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::STRING); - EXPECT_EQ(s._str, ""); + EXPECT_EQ(s._str, ""_s); EXPECT_FALSE(sexpr::parse(lexer, s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_EOF); @@ -67,19 +67,19 @@ TEST(sexpr, parser) TEST(sexpr, parselist) { sexpr::SExpr s; - sexpr::Lexer lexer("<parser-test1>", string_pipe("(foo)(bar)\n")); + sexpr::Lexer lexer("<parser-test1>"_s, string_pipe("(foo)(bar)\n"_s)); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::LIST); EXPECT_EQ(s._list.size(), 1); EXPECT_EQ(s._list[0]._type, sexpr::TOKEN); - EXPECT_EQ(s._list[0]._str, "foo"); + EXPECT_EQ(s._list[0]._str, "foo"_s); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::LIST); EXPECT_EQ(s._list.size(), 1); EXPECT_EQ(s._list[0]._type, sexpr::TOKEN); - EXPECT_EQ(s._list[0]._str, "bar"); + EXPECT_EQ(s._list[0]._str, "bar"_s); EXPECT_FALSE(sexpr::parse(lexer, s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_EOF); @@ -87,22 +87,22 @@ TEST(sexpr, parselist) TEST(sexpr, parsebad) { - for (ZString bad : { - ZString("(\n"), - ZString(")\n"), - ZString("\"\n"), - ZString("'\n"), - ZString("\\\n"), - ZString("\"\\"), - ZString("\"\\z\""), - ZString("(()\n"), - ZString("((\n"), - ZString("((\"\n"), + for (LString bad : { + "(\n"_s, + ")\n"_s, + "\"_s\n"_s, + "'\n"_s, + "\\\n"_s, + "\"_s\\"_s, + "\"_s\\z\""_s, + "(()\n"_s, + "((\n"_s, + "((\"\n"_s, }) { sexpr::SExpr s; io::LineSpan span; - sexpr::Lexer lexer("<parse-bad>", string_pipe(bad)); + sexpr::Lexer lexer("<parse-bad>"_s, string_pipe(bad)); EXPECT_FALSE(sexpr::parse(lexer, s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_ERROR); } diff --git a/src/strings/astring.cpp b/src/strings/astring.cpp index f1e9030..0906584 100644 --- a/src/strings/astring.cpp +++ b/src/strings/astring.cpp @@ -156,6 +156,13 @@ namespace strings special = 255 - x.size(); } } + AString::AString(LString l) + : data{}, special() + { + new(r_ptr()) RString(); + special = 255; + *this = XString(l); + } AString::iterator AString::begin() const { diff --git a/src/strings/astring.hpp b/src/strings/astring.hpp index aab14cf..b0fb196 100644 --- a/src/strings/astring.hpp +++ b/src/strings/astring.hpp @@ -49,12 +49,6 @@ namespace strings explicit AString(const MString& s); - template<size_t n> - AString(char (&s)[n]) = delete; - - template<size_t n> - AString(const char (&s)[n]); - template<class It> AString(It b, It e); @@ -66,6 +60,7 @@ namespace strings AString(XString); template<uint8_t n> AString(const VString<n>& v); + AString(LString s); iterator begin() const; iterator end() const; diff --git a/src/strings/astring.tcc b/src/strings/astring.tcc index ed07bd9..f9606d8 100644 --- a/src/strings/astring.tcc +++ b/src/strings/astring.tcc @@ -21,23 +21,6 @@ namespace strings { - template<size_t n> - AString::AString(const char (&s)[n]) - : data{}, special() - { - XPair x = s; - if (x.size() > 255 || x.size() == 0) - { - new(r_ptr()) RString(x); - special = 255; - } - else - { - *std::copy(x.begin(), x.end(), data) = '\0'; - special = 255 - x.size(); - } - } - template<class It> AString::AString(It b, It e) : data{}, special() diff --git a/src/strings/base_test.cpp b/src/strings/base_test.cpp index 52c44dc..524450d 100644 --- a/src/strings/base_test.cpp +++ b/src/strings/base_test.cpp @@ -31,18 +31,18 @@ using namespace strings; struct _test : VString<1> {}; struct _test2 : VString<1> {}; -static_assert(string_comparison_allowed<_test, _test>::value, "tt"); -static_assert(string_comparison_allowed<VString<1>, VString<1>>::value, "vv"); -static_assert(!string_comparison_allowed<_test, XString>::value, "tx"); -static_assert(!string_comparison_allowed<_test, VString<1>>::value, "tv"); -static_assert(!string_comparison_allowed<_test, _test2>::value, "t2"); -static_assert(string_comparison_allowed<VString<1>, XString>::value, "vx"); -static_assert(string_comparison_allowed<XString, XString>::value, "xx"); -static_assert(string_comparison_allowed<XString, RString>::value, "xf"); +static_assert(string_comparison_allowed<_test, _test>::value, "tt"_s); +static_assert(string_comparison_allowed<VString<1>, VString<1>>::value, "vv"_s); +static_assert(!string_comparison_allowed<_test, XString>::value, "tx"_s); +static_assert(!string_comparison_allowed<_test, VString<1>>::value, "tv"_s); +static_assert(!string_comparison_allowed<_test, _test2>::value, "t2"_s); +static_assert(string_comparison_allowed<VString<1>, XString>::value, "vx"_s); +static_assert(string_comparison_allowed<XString, XString>::value, "xx"_s); +static_assert(string_comparison_allowed<XString, RString>::value, "xf"_s); TEST(strings, contains) { - XString hi = "Hello"; - EXPECT_TRUE(hi.contains_any("Hi")); - EXPECT_FALSE(hi.contains_any("hi")); + XString hi = "Hello"_s; + EXPECT_TRUE(hi.contains_any("Hi"_s)); + EXPECT_FALSE(hi.contains_any("hi"_s)); } diff --git a/src/strings/fwd.hpp b/src/strings/fwd.hpp index 4c58e03..0e824c8 100644 --- a/src/strings/fwd.hpp +++ b/src/strings/fwd.hpp @@ -21,6 +21,7 @@ # include "../sanity.hpp" +# include <cstddef> # include <cstdint> // It is a common mistake to assume that one string class for everything. @@ -40,12 +41,18 @@ namespace strings class XString; // semi-owning + class LString; + class FormatString; template<uint8_t len> class VString; // refactor this into a function? enum _type_that_just_has_a_name_to_fix_linkage { really_construct_from_a_pointer }; + + LString operator "" _s(const char *, size_t); + constexpr + FormatString operator "" _fmt(const char *, size_t); } // namespace strings using strings::MString; @@ -57,6 +64,11 @@ using strings::SString; using strings::ZString; using strings::XString; +using strings::LString; +using strings::FormatString; using strings::VString; +using strings::operator "" _s; +using strings::operator "" _fmt; + #endif // TMWA_STRINGS_FWD_HPP diff --git a/src/strings/literal.cpp b/src/strings/literal.cpp new file mode 100644 index 0000000..974a8bd --- /dev/null +++ b/src/strings/literal.cpp @@ -0,0 +1,56 @@ +#include "literal.hpp" +// strings/literal.cpp - A string stored in the readonly data segment. +// +// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> +// +// This file is part of The Mana World (Athena server) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +#include "../poison.hpp" + +namespace strings +{ + LString::LString(const char *b, const char *e) + : _b(b), _e(e) + {} + + LString::iterator LString::begin() const + { + return _b; + } + LString::iterator LString::end() const + { + return _e; + } + const RString *LString::base() const + { + return nullptr; + } + const char *LString::c_str() const + { + return &*begin(); + } + + const char *decay_for_printf(const LString& zs) + { + return zs.c_str(); + } + + __attribute__((format(scanf, 2, 0))) + int do_vscan(LString in, const char *fmt, va_list ap) + { + return vsscanf(in.c_str(), fmt, ap); + } +} // namespace strings diff --git a/src/strings/literal.hpp b/src/strings/literal.hpp new file mode 100644 index 0000000..c5b9938 --- /dev/null +++ b/src/strings/literal.hpp @@ -0,0 +1,82 @@ +#ifndef TMWA_STRINGS_LITERAL_HPP +#define TMWA_STRINGS_LITERAL_HPP +// strings/literal.hpp - A string stored in the readonly data segment. +// +// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> +// +// This file is part of The Mana World (Athena server) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +# include "../sanity.hpp" + +# include <cstring> + +# include "base.hpp" + +namespace strings +{ + /// A statically owned string that is guaranteed to be NUL-terminated. + /// This is a more permissive lifetime than anybody else has. + class LString : public _crtp_string<LString, AString, LPair> + { + iterator _b, _e; + // optional + const RString *_base; + private: + LString(const char *b, const char *e); + friend LString operator "" _s(const char *, size_t); + public: + + iterator begin() const; + iterator end() const; + const RString *base() const; + const char *c_str() const; + }; + + class FormatString + { + const char *_format; + + friend constexpr FormatString operator "" _fmt(const char *, size_t); + constexpr explicit + FormatString(const char *f) : _format(f) {} + public: + constexpr + const char *format_string() { return _format; } + }; + + + // cxxstdio helpers + // I think the conversion will happen automatically. TODO test this. + // Nope, it doesn't, since there's a template + // Actually, it might now. + const char *decay_for_printf(const LString& zs); + + __attribute__((format(scanf, 2, 0))) + int do_vscan(LString in, const char *fmt, va_list ap); + + inline + LString operator "" _s(const char *s, size_t) + { + return LString(s, s + __builtin_strlen(s)); + } + constexpr + FormatString operator "" _fmt(const char *s, size_t) + { + return FormatString(s); + } +} // namespace strings + +#endif // TMWA_STRINGS_LSTRING_HPP diff --git a/src/strings/pair.hpp b/src/strings/pair.hpp index a592a91..24537de 100644 --- a/src/strings/pair.hpp +++ b/src/strings/pair.hpp @@ -2,7 +2,7 @@ #define TMWA_STRINGS_PAIR_HPP // strings/pair.hpp - Internal contiguous range. // -// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com> +// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com> // // This file is part of The Mana World (Athena server) // @@ -40,12 +40,6 @@ namespace strings XPair(const char *b, const char *e) : _begin(b), _end(e) {} - template<size_t n> - XPair(char (&arr)[n]) = delete; - template<size_t n> - XPair(const char (&arr)[n]) - : _begin(arr), _end(arr + strlen(arr)) - {} const char *begin() const { return _begin; } const char *end() const { return _end; } @@ -59,11 +53,14 @@ namespace strings ZPair(const char *b, const char *e) : XPair(b, e) {} - template<size_t n> - ZPair(char (&arr)[n]) = delete; - template<size_t n> - ZPair(const char (&arr)[n]) - : XPair(arr) + }; + struct LPair : ZPair + { + typedef LString TailSlice; + typedef XString FullSlice; + + LPair(const char *b, const char *e) + : ZPair(b, e) {} }; } // namespace strings diff --git a/src/strings/rstring.cpp b/src/strings/rstring.cpp index c0e231e..671e7b0 100644 --- a/src/strings/rstring.cpp +++ b/src/strings/rstring.cpp @@ -125,6 +125,11 @@ namespace strings else _assign(x.begin(), x.end()); } + RString::RString(LString l) + : owned(nullptr) + { + *this = XString(l); + } RString::iterator RString::begin() const { diff --git a/src/strings/rstring.hpp b/src/strings/rstring.hpp index 7cb19d6..1de4db0 100644 --- a/src/strings/rstring.hpp +++ b/src/strings/rstring.hpp @@ -56,12 +56,6 @@ namespace strings explicit RString(const MString& s); - template<size_t n> - RString(char (&s)[n]) = delete; - - template<size_t n> - RString(const char (&s)[n]); - template<class It> RString(It b, It e); @@ -73,6 +67,7 @@ namespace strings RString(XString); template<uint8_t n> RString(const VString<n>& v); + RString(LString s); iterator begin() const; iterator end() const; diff --git a/src/strings/rstring.tcc b/src/strings/rstring.tcc index 8b4c0c0..6bfc7b0 100644 --- a/src/strings/rstring.tcc +++ b/src/strings/rstring.tcc @@ -47,12 +47,6 @@ namespace strings owned->body[diff] = '\0'; } - template<size_t n> - RString::RString(const char (&s)[n]) - { - _assign(s, s + strlen(s)); - } - template<class It> RString::RString(It b, It e) { diff --git a/src/strings/sstring.cpp b/src/strings/sstring.cpp index 76f0994..8de8655 100644 --- a/src/strings/sstring.cpp +++ b/src/strings/sstring.cpp @@ -54,6 +54,10 @@ namespace strings else *this = RString(x); } + SString::SString(const LString& l) + { + *this = XString(l); + } SString::SString(RString r, size_t b, size_t e) : _s(std::move(r)), _b(b), _e(e) diff --git a/src/strings/sstring.hpp b/src/strings/sstring.hpp index 7166e94..0594499 100644 --- a/src/strings/sstring.hpp +++ b/src/strings/sstring.hpp @@ -42,10 +42,7 @@ namespace strings SString(const XString&); template<uint8_t n> SString(const VString<n>& v); - template<size_t n> - SString(char (&s)[n]) = delete; - template<size_t n> - SString(const char (&s)[n]); + SString(const LString&); //template<class It> //SString(It b, It e) : _s(b, e), _b(0), _e(_s.size()) {} SString(RString f, size_t b, size_t e); diff --git a/src/strings/sstring.tcc b/src/strings/sstring.tcc index 4be33dd..89effbc 100644 --- a/src/strings/sstring.tcc +++ b/src/strings/sstring.tcc @@ -25,9 +25,4 @@ namespace strings SString::SString(const VString<n>& v) : _s(v), _b(0), _e(_s.size()) {} - - template<size_t n> - SString::SString(const char (&s)[n]) - : _s(s), _b(0), _e(_s.size()) - {} } // namespace strings diff --git a/src/strings/strings2_test.cpp b/src/strings/strings2_test.cpp index e5d5281..8c4a343 100644 --- a/src/strings/strings2_test.cpp +++ b/src/strings/strings2_test.cpp @@ -25,23 +25,23 @@ TEST(StringTests, traits2) { - ZString print_non = "\t\e"; - ZString print_mix = "n\t"; - RString print_all = "n "; + ZString print_non = "\t\e"_s; + ZString print_mix = "n\t"_s; + RString print_all = "n "_s; EXPECT_FALSE(print_non.has_print()); EXPECT_TRUE(print_mix.has_print()); EXPECT_TRUE(print_all.has_print()); EXPECT_FALSE(print_non.is_print()); EXPECT_FALSE(print_mix.is_print()); EXPECT_TRUE(print_all.is_print()); - EXPECT_EQ("__", print_non.to_print()); - EXPECT_EQ("n_", print_mix.to_print()); - EXPECT_EQ("n ", print_all.to_print()); + EXPECT_EQ("__"_s, print_non.to_print()); + EXPECT_EQ("n_"_s, print_mix.to_print()); + EXPECT_EQ("n "_s, print_all.to_print()); EXPECT_EQ(print_all.begin(), print_all.to_print().begin()); - ZString graph_non = " \e"; - ZString graph_mix = "n "; - RString graph_all = "n."; + ZString graph_non = " \e"_s; + ZString graph_mix = "n "_s; + RString graph_all = "n."_s; EXPECT_FALSE(graph_non.has_graph()); EXPECT_TRUE(graph_mix.has_graph()); EXPECT_TRUE(graph_all.has_graph()); @@ -49,37 +49,37 @@ TEST(StringTests, traits2) EXPECT_FALSE(graph_mix.is_graph()); EXPECT_TRUE(graph_all.is_graph()); - ZString lower_non = "0A"; - ZString lower_mix = "Oa"; - RString lower_all = "oa"; + ZString lower_non = "0A"_s; + ZString lower_mix = "Oa"_s; + RString lower_all = "oa"_s; EXPECT_FALSE(lower_non.has_lower()); EXPECT_TRUE(lower_mix.has_lower()); EXPECT_TRUE(lower_all.has_lower()); EXPECT_FALSE(lower_non.is_lower()); EXPECT_FALSE(lower_mix.is_lower()); EXPECT_TRUE(lower_all.is_lower()); - EXPECT_EQ("0a", lower_non.to_lower()); - EXPECT_EQ("oa", lower_mix.to_lower()); - EXPECT_EQ("oa", lower_all.to_lower()); + EXPECT_EQ("0a"_s, lower_non.to_lower()); + EXPECT_EQ("oa"_s, lower_mix.to_lower()); + EXPECT_EQ("oa"_s, lower_all.to_lower()); EXPECT_EQ(lower_all.begin(), lower_all.to_lower().begin()); - ZString upper_non = "0a"; - ZString upper_mix = "oA"; - RString upper_all = "OA"; + ZString upper_non = "0a"_s; + ZString upper_mix = "oA"_s; + RString upper_all = "OA"_s; EXPECT_FALSE(upper_non.has_upper()); EXPECT_TRUE(upper_mix.has_upper()); EXPECT_TRUE(upper_all.has_upper()); EXPECT_FALSE(upper_non.is_upper()); EXPECT_FALSE(upper_mix.is_upper()); EXPECT_TRUE(upper_all.is_upper()); - EXPECT_EQ("0A", upper_non.to_upper()); - EXPECT_EQ("OA", upper_mix.to_upper()); - EXPECT_EQ("OA", upper_all.to_upper()); + EXPECT_EQ("0A"_s, upper_non.to_upper()); + EXPECT_EQ("OA"_s, upper_mix.to_upper()); + EXPECT_EQ("OA"_s, upper_all.to_upper()); EXPECT_EQ(upper_all.begin(), upper_all.to_upper().begin()); - ZString alpha_non = " 0"; - ZString alpha_mix = "n "; - RString alpha_all = "nA"; + ZString alpha_non = " 0"_s; + ZString alpha_mix = "n "_s; + RString alpha_all = "nA"_s; EXPECT_FALSE(alpha_non.has_alpha()); EXPECT_TRUE(alpha_mix.has_alpha()); EXPECT_TRUE(alpha_all.has_alpha()); @@ -87,9 +87,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(alpha_mix.is_alpha()); EXPECT_TRUE(alpha_all.is_alpha()); - ZString digit2_non = "a9"; - ZString digit2_mix = "20"; - RString digit2_all = "01"; + ZString digit2_non = "a9"_s; + ZString digit2_mix = "20"_s; + RString digit2_all = "01"_s; EXPECT_FALSE(digit2_non.has_digit2()); EXPECT_TRUE(digit2_mix.has_digit2()); EXPECT_TRUE(digit2_all.has_digit2()); @@ -97,9 +97,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit2_mix.is_digit2()); EXPECT_TRUE(digit2_all.is_digit2()); - ZString digit8_non = "a9"; - ZString digit8_mix = "80"; - RString digit8_all = "37"; + ZString digit8_non = "a9"_s; + ZString digit8_mix = "80"_s; + RString digit8_all = "37"_s; EXPECT_FALSE(digit8_non.has_digit8()); EXPECT_TRUE(digit8_mix.has_digit8()); EXPECT_TRUE(digit8_all.has_digit8()); @@ -107,9 +107,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit8_mix.is_digit8()); EXPECT_TRUE(digit8_all.is_digit8()); - ZString digit10_non = "az"; - ZString digit10_mix = "a9"; - RString digit10_all = "42"; + ZString digit10_non = "az"_s; + ZString digit10_mix = "a9"_s; + RString digit10_all = "42"_s; EXPECT_FALSE(digit10_non.has_digit10()); EXPECT_TRUE(digit10_mix.has_digit10()); EXPECT_TRUE(digit10_all.has_digit10()); @@ -117,9 +117,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit10_mix.is_digit10()); EXPECT_TRUE(digit10_all.is_digit10()); - ZString digit16_non = "gz"; - ZString digit16_mix = "ao"; - RString digit16_all = "be"; + ZString digit16_non = "gz"_s; + ZString digit16_mix = "ao"_s; + RString digit16_all = "be"_s; EXPECT_FALSE(digit16_non.has_digit16()); EXPECT_TRUE(digit16_mix.has_digit16()); EXPECT_TRUE(digit16_all.has_digit16()); @@ -127,9 +127,9 @@ TEST(StringTests, traits2) EXPECT_FALSE(digit16_mix.is_digit16()); EXPECT_TRUE(digit16_all.is_digit16()); - ZString alnum_non = " ."; - ZString alnum_mix = "n "; - RString alnum_all = "n0"; + ZString alnum_non = " ."_s; + ZString alnum_mix = "n "_s; + RString alnum_all = "n0"_s; EXPECT_FALSE(alnum_non.has_alnum()); EXPECT_TRUE(alnum_mix.has_alnum()); EXPECT_TRUE(alnum_all.has_alnum()); @@ -140,7 +140,7 @@ TEST(StringTests, traits2) TEST(StringTests, rempty) { - const char empty_text[] = ""; + LString empty_text = ""_s; RString r = empty_text; EXPECT_EQ(r.size(), 0); AString a = empty_text; @@ -166,7 +166,7 @@ TEST(StringTests, rempty) } TEST(StringTests, rshort) { - const char short_text[] = "0123456789"; + LString short_text = "0123456789"_s; RString r = short_text; EXPECT_EQ(r.size(), 10); AString a = short_text; @@ -193,13 +193,13 @@ TEST(StringTests, rshort) TEST(StringTests, rlong) { - const char long_text[] = + LString long_text = "01234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345 100" "01234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345 200" "01234567890123456789012345678901234567890123456789" - "0123456789012345678901234567890123456789012345 300"; + "0123456789012345678901234567890123456789012345 300"_s; RString r = long_text; EXPECT_EQ(r.size(), 300); AString a = long_text; diff --git a/src/strings/strings_test.cpp b/src/strings/strings_test.cpp index dca463d..3abb5e1 100644 --- a/src/strings/strings_test.cpp +++ b/src/strings/strings_test.cpp @@ -32,10 +32,10 @@ TYPED_TEST_CASE_P(StringTest); TYPED_TEST_P(StringTest, basic) { - TypeParam hi("Hello"); + TypeParam hi("Hello"_s); EXPECT_EQ(5, hi.size()); EXPECT_EQ(hi, hi); - const char hi2[] = "Hello\0random garbage"; + LString hi2 = "Hello\0random garbage"_s; EXPECT_EQ(hi, hi2); TypeParam hi0; EXPECT_EQ(0, hi0.size()); @@ -47,9 +47,9 @@ TYPED_TEST_P(StringTest, basic) TYPED_TEST_P(StringTest, order) { TypeParam a; - TypeParam b("Hello"); - TypeParam c("Hello,"); - TypeParam d("World!"); + TypeParam b("Hello"_s); + TypeParam c("Hello,"_s); + TypeParam d("World!"_s); // not using EXPECT_LT, etc. for better visibility @@ -158,7 +158,7 @@ TYPED_TEST_P(StringTest, order) TYPED_TEST_P(StringTest, iterators) { - TypeParam hi("Hello"); + TypeParam hi("Hello"_s); EXPECT_EQ(hi.begin(), hi.begin()); EXPECT_NE(hi.begin(), hi.end()); EXPECT_EQ(5, std::distance(hi.begin(), hi.end())); @@ -168,19 +168,19 @@ TYPED_TEST_P(StringTest, iterators) TYPED_TEST_P(StringTest, xslice) { - TypeParam hi("Hello, World!"); - EXPECT_EQ(" World!", hi.xslice_t(6)); - EXPECT_EQ("Hello,", hi.xslice_h(6)); - EXPECT_EQ("World!", hi.xrslice_t(6)); - EXPECT_EQ("Hello, ", hi.xrslice_h(6)); + TypeParam hi("Hello, World!"_s); + EXPECT_EQ(" World!"_s, hi.xslice_t(6)); + EXPECT_EQ("Hello,"_s, hi.xslice_h(6)); + EXPECT_EQ("World!"_s, hi.xrslice_t(6)); + EXPECT_EQ("Hello, "_s, hi.xrslice_h(6)); typename TypeParam::iterator it = std::find(hi.begin(), hi.end(), ' '); - EXPECT_EQ(" World!", hi.xislice_t(it)); - EXPECT_EQ("Hello,", hi.xislice_h(it)); - EXPECT_EQ("World", hi.xlslice(7, 5)); - EXPECT_EQ("World", hi.xpslice(7, 12)); - EXPECT_EQ("World", hi.xislice(hi.begin() + 7, hi.begin() + 12)); - EXPECT_TRUE(hi.startswith("Hello")); - EXPECT_TRUE(hi.endswith("World!")); + EXPECT_EQ(" World!"_s, hi.xislice_t(it)); + EXPECT_EQ("Hello,"_s, hi.xislice_h(it)); + EXPECT_EQ("World"_s, hi.xlslice(7, 5)); + EXPECT_EQ("World"_s, hi.xpslice(7, 12)); + EXPECT_EQ("World"_s, hi.xislice(hi.begin() + 7, hi.begin() + 12)); + EXPECT_TRUE(hi.startswith("Hello"_s)); + EXPECT_TRUE(hi.endswith("World!"_s)); } TYPED_TEST_P(StringTest, convert) @@ -188,15 +188,15 @@ TYPED_TEST_P(StringTest, convert) constexpr bool is_zstring = std::is_same<TypeParam, ZString>::value; typedef typename std::conditional<is_zstring, TString, SString>::type Sstring; typedef typename std::conditional<is_zstring, ZString, XString>::type Xstring; - RString r = "r"; - AString a = "a"; - TString t = "t"; - Sstring s = "s"; - ZString z = "z"; - Xstring x = "x"; - VString<255> v = "v"; - const char l[] = "l"; - VString<5> hi = "hello"; + RString r = "r"_s; + AString a = "a"_s; + TString t = "t"_s; + Sstring s = "s"_s; + ZString z = "z"_s; + Xstring x = "x"_s; + VString<255> v = "v"_s; + LString l = "l"_s; + VString<5> hi = "hello"_s; TypeParam r2 = r; TypeParam a2 = a; @@ -270,7 +270,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(StringStuff, StringTest, MostStringTypes); TEST(VStringTest, basic) { - VString<5> hi = "Hello"; + VString<5> hi = "Hello"_s; EXPECT_EQ(5, hi.size()); EXPECT_EQ(hi, hi); // truncation @@ -278,7 +278,7 @@ TEST(VStringTest, basic) EXPECT_EQ(5, hi2.size()); EXPECT_EQ(hi, hi2); // short - hi = "hi"; + hi = "hi"_s; EXPECT_EQ(2, hi.size()); VString<5> hi0; EXPECT_EQ(0, hi0.size()); @@ -292,7 +292,7 @@ TYPED_TEST_CASE_P(NulStringTest); TYPED_TEST_P(NulStringTest, basic) { - TypeParam hi("hello"); + TypeParam hi("hello"_s); EXPECT_EQ(hi.size(), strlen(hi.c_str())); EXPECT_STREQ("hello", hi.c_str()); } diff --git a/src/strings/tstring.cpp b/src/strings/tstring.cpp index 5f463ca..27e8052 100644 --- a/src/strings/tstring.cpp +++ b/src/strings/tstring.cpp @@ -67,6 +67,10 @@ namespace strings else *this = RString(x); } + TString::TString(const LString& l) + { + *this = XString(l); + } TString::TString(XPair p) : _s(p), _o(0) diff --git a/src/strings/tstring.hpp b/src/strings/tstring.hpp index 7003d37..38f41cd 100644 --- a/src/strings/tstring.hpp +++ b/src/strings/tstring.hpp @@ -43,10 +43,7 @@ namespace strings TString(const XString&); template<uint8_t n> TString(const VString<n>& v); - template<size_t n> - TString(char (&s)[n]) = delete; - template<size_t n> - TString(const char (&s)[n]); + TString(const LString&); //template<class It> //TString(It b, It e) : _s(b, e), _o(0) {} TString(XPair p); diff --git a/src/strings/tstring.tcc b/src/strings/tstring.tcc index 4eba13f..c62987b 100644 --- a/src/strings/tstring.tcc +++ b/src/strings/tstring.tcc @@ -25,8 +25,4 @@ namespace strings TString::TString(const VString<n>& v) : _s(v), _o(0) {} - template<size_t n> - TString::TString(const char (&s)[n]) - : _s(s), _o(0) - {} } // namespace strings diff --git a/src/strings/vstring.hpp b/src/strings/vstring.hpp index 9952ff9..33dfb10 100644 --- a/src/strings/vstring.hpp +++ b/src/strings/vstring.hpp @@ -40,10 +40,7 @@ namespace strings VString(ZString z); template<uint8_t m> VString(VString<m> v); - template<size_t m> - VString(char (&s)[m]) = delete; - template<size_t m> - VString(const char (&s)[m]); + VString(LString l); VString(decltype(really_construct_from_a_pointer) e, const char *s); VString(char c); VString(); diff --git a/src/strings/vstring.tcc b/src/strings/vstring.tcc index 1aa163d..ac3dc19 100644 --- a/src/strings/vstring.tcc +++ b/src/strings/vstring.tcc @@ -76,11 +76,9 @@ namespace strings *this = XString(v); } template<uint8_t n> - template<size_t m> - VString<n>::VString(const char (&s)[m]) + VString<n>::VString(LString l) { - static_assert(m <= n + 1, "string would truncate"); - *this = XString(s); + *this = XString(l); } template<uint8_t n> VString<n>::VString(decltype(really_construct_from_a_pointer) e, const char *s) @@ -143,7 +141,7 @@ namespace strings char buffer[len + 1]; vsnprintf(buffer, len + 1, fmt, ap); - out = const_(buffer); + out = VString<len>(strings::really_construct_from_a_pointer, buffer); return len; } } // namespace strings diff --git a/src/strings/xstring.cpp b/src/strings/xstring.cpp index 0808104..5312445 100644 --- a/src/strings/xstring.cpp +++ b/src/strings/xstring.cpp @@ -40,6 +40,9 @@ namespace strings XString::XString(const ZString& s) : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) {} + XString::XString(const LString& s) + : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) + {} XString::XString(const char *b, const char *e, const RString *base_) : _b(b), _e(e), _base(base_) diff --git a/src/strings/xstring.hpp b/src/strings/xstring.hpp index 8f6eac5..ad7c40d 100644 --- a/src/strings/xstring.hpp +++ b/src/strings/xstring.hpp @@ -22,6 +22,7 @@ # include "../sanity.hpp" # include "base.hpp" +# include "literal.hpp" namespace strings { @@ -44,10 +45,7 @@ namespace strings XString(const ZString& s); template<uint8_t n> XString(const VString<n>& s); - template<size_t n> - XString(char (&s)[n]) = delete; - template<size_t n> - XString(const char (&s)[n]); + XString(const LString& s); // mostly internal XString(const char *b, const char *e, const RString *base_); XString(decltype(really_construct_from_a_pointer) e, const char *s, const RString *base_); diff --git a/src/strings/xstring.tcc b/src/strings/xstring.tcc index aee87f8..8115d23 100644 --- a/src/strings/xstring.tcc +++ b/src/strings/xstring.tcc @@ -25,8 +25,4 @@ namespace strings XString::XString(const VString<n>& s) : _b(&*s.begin()), _e(&*s.end()), _base(nullptr) {} - template<size_t n> - XString::XString(const char (&s)[n]) - : _b(s), _e(s + strlen(s)), _base(nullptr) - {} } // namespace strings diff --git a/src/strings/zstring.cpp b/src/strings/zstring.cpp index e2a763f..323ba5f 100644 --- a/src/strings/zstring.cpp +++ b/src/strings/zstring.cpp @@ -26,7 +26,7 @@ namespace strings { ZString::ZString() { - *this = ZString(""); + *this = ZString(""_s); } ZString::ZString(const RString& s) : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) @@ -37,6 +37,9 @@ namespace strings ZString::ZString(const TString& s) : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) {} + ZString::ZString(const LString& s) + : _b(&*s.begin()), _e(&*s.end()), _base(s.base()) + {} ZString::ZString(const char *b, const char *e, const RString *base_) : _b(b), _e(e), _base(base_) {} diff --git a/src/strings/zstring.hpp b/src/strings/zstring.hpp index 717da88..c75c7c9 100644 --- a/src/strings/zstring.hpp +++ b/src/strings/zstring.hpp @@ -24,6 +24,7 @@ # include <cstring> # include "base.hpp" +# include "literal.hpp" namespace strings { @@ -45,13 +46,10 @@ namespace strings ZString(const XString&) = delete; template<uint8_t n> ZString(const VString<n>& s); + ZString(const LString& s); // dangerous ZString(const char *b, const char *e, const RString *base_); ZString(decltype(really_construct_from_a_pointer), const char *s, const RString *base_); - template<size_t n> - ZString(char (&s)[n]) = delete; - template<size_t n> - ZString(const char (&s)[n], const RString *base_=nullptr); iterator begin() const; iterator end() const; diff --git a/src/strings/zstring.tcc b/src/strings/zstring.tcc index fe0e9f3..3ff7374 100644 --- a/src/strings/zstring.tcc +++ b/src/strings/zstring.tcc @@ -27,9 +27,4 @@ namespace strings ZString::ZString(const VString<n>& s) : _b(&*s.begin()), _e(&*s.end()), _base(nullptr) {} - - template<size_t n> - ZString::ZString(const char (&s)[n], const RString *base_) - : _b(s), _e(s + strlen(s)), _base(base_) - {} } // namespace strings |