diff options
Diffstat (limited to 'src/admin/ladmin.cpp')
-rw-r--r-- | src/admin/ladmin.cpp | 2119 |
1 files changed, 1088 insertions, 1031 deletions
diff --git a/src/admin/ladmin.cpp b/src/admin/ladmin.cpp index 9bbd710..9dae089 100644 --- a/src/admin/ladmin.cpp +++ b/src/admin/ladmin.cpp @@ -1,4 +1,4 @@ -#include <arpa/inet.h> +#include "ladmin.hpp" // ladmin.cpp - Local administration tool. // // Copyright © ????-2004 Athena Dev Teams @@ -26,30 +26,37 @@ #include <cassert> +#include <algorithm> + #include "../strings/mstring.hpp" #include "../strings/astring.hpp" #include "../strings/zstring.hpp" #include "../strings/xstring.hpp" #include "../strings/vstring.hpp" -#include "../generic/md5.hpp" - #include "../io/cxxstdio.hpp" #include "../io/read.hpp" #include "../io/tty.hpp" #include "../io/write.hpp" +#include "../net/ip.hpp" +#include "../net/packets.hpp" + +#include "../proto2/any-user.hpp" +#include "../proto2/login-admin.hpp" + #include "../mmo/config_parse.hpp" #include "../mmo/core.hpp" #include "../mmo/human_time_diff.hpp" #include "../mmo/mmo.hpp" -#include "../mmo/socket.hpp" #include "../mmo/utils.hpp" #include "../mmo/version.hpp" #include "../poison.hpp" +namespace tmwa +{ static int eathena_interactive_session; #define Iprintf if (eathena_interactive_session) PRINTF @@ -68,9 +75,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. @@ -259,17 +266,19 @@ static TString parameters; // needs to be global since it's passed to the parse function // really should be added to session data static -int list_first, list_last, list_type, list_count; // parameter to display a list of accounts +AccountId list_first, list_last; +static +int list_type, list_count; // parameter to display a list of accounts static int already_exit_function = 0; // sometimes, the exit function is called twice... so, don't log twice the message -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmissing-noreturn" +DIAG_PUSH(); +DIAG_I(missing_noreturn); void SessionDeleter::operator()(SessionData *) { - assert(false && "ladmin does not have sessions"); + assert(false && "ladmin does not have sessions"_s); } -#pragma GCC diagnostic pop +DIAG_POP(); //------------------------------ // Writing function of logs file @@ -285,13 +294,14 @@ void ladmin_log(XString line) log_with_timestamp(logfp, line); } -static +static __attribute__((noreturn)) void delete_fromlogin(Session *) { + login_session = nullptr; { - 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); exit(0); } @@ -352,315 +362,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", - 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("Unknown command [%s] for help. Displaying of all commands.\n"_fmt, + AString(command)); + 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); } } @@ -680,9 +690,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; @@ -692,9 +702,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; } } @@ -702,18 +712,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; } @@ -722,14 +732,14 @@ 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); - WFIFO_STRING(login_session, 26, password, 24); - WFIFOB(login_session, 50) = sex; - WFIFO_STRING(login_session, 51, email, 40); - WFIFOSET(login_session, 91); + Packet_Fixed<0x7930> fixed_30; + fixed_30.account_name = name; + fixed_30.password = password; + fixed_30.sex = sex_from_char(sex); + fixed_30.email = email; + send_fpacket<0x7930, 91>(login_session, fixed_30); bytes_to_read = 1; } @@ -744,11 +754,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()) @@ -756,28 +766,28 @@ 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); - WFIFO_STRUCT(login_session, 26, modif); - WFIFOSET(login_session, 38); + Packet_Fixed<0x794c> fixed_4c; + fixed_4c.account_name = name; + fixed_4c.ban_add = modif; + send_fpacket<0x794c, 38>(login_session, fixed_4c); bytes_to_read = 1; } @@ -798,19 +808,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(); } @@ -826,41 +836,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", - month); - LADMIN_LOG("Invalid day for this month ('banset' or 'ban' command).\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"_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; @@ -873,20 +883,20 @@ 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); - WFIFOL(login_session, 26) = static_cast<time_t>(ban_until_time); - WFIFOSET(login_session, 30); + Packet_Fixed<0x794a> fixed_4a; + fixed_4a.account_name = name; + fixed_4a.ban_until = ban_until_time; + send_fpacket<0x794a, 30>(login_session, fixed_4a); bytes_to_read = 1; } @@ -902,18 +912,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_); } @@ -931,18 +941,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_); } @@ -957,17 +967,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); } //--------------------------------------------------------- @@ -982,9 +992,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; } @@ -994,12 +1004,12 @@ 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); - WFIFO_STRING(login_session, 26, password, 24); - WFIFOSET(login_session, 50); + Packet_Fixed<0x793a> fixed_3a; + fixed_3a.account_name = name; + fixed_3a.password = password; + send_fpacket<0x793a, 50>(login_session, fixed_3a); bytes_to_read = 1; } @@ -1013,9 +1023,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; } @@ -1025,7 +1035,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; @@ -1035,20 +1045,20 @@ 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); - WFIFOSET(login_session, 26); + Packet_Fixed<0x7932> fixed_32; + fixed_32.account_name = name; + send_fpacket<0x7932, 26>(login_session, fixed_32); bytes_to_read = 1; } @@ -1062,9 +1072,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; } @@ -1073,20 +1083,20 @@ 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); - WFIFO_STRING(login_session, 26, email, 40); - WFIFOSET(login_session, 66); + Packet_Fixed<0x7940> fixed_40; + fixed_40.account_name = name; + fixed_40.email = email; + send_fpacket<0x7940, 66>(login_session, fixed_40); bytes_to_read = 1; } @@ -1096,10 +1106,10 @@ 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); + Packet_Fixed<0x7938> fixed_38; + send_fpacket<0x7938, 2>(login_session, fixed_38); bytes_to_read = 1; } @@ -1110,34 +1120,25 @@ static void changegmlevel(ZString param) { AccountName name; - int GM_level = 0; + GmLevel GM_level; 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; } if (!name.is_print()) return; - if (GM_level < 0 || GM_level > 99) - { - PRINTF("Illegal GM level [%d]. Please input a value from 0 to 99.\n", - GM_level); - LADMIN_LOG("Illegal GM level [%d]. The value can be from 0 to 99.\n", - 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); - WFIFOB(login_session, 26) = GM_level; - WFIFOSET(login_session, 27); + Packet_Fixed<0x793e> fixed_3e; + fixed_3e.account_name = name; + fixed_3e.gm_level = GM_level; + send_fpacket<0x793e, 27>(login_session, fixed_3e); bytes_to_read = 1; } @@ -1151,9 +1152,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; } @@ -1162,11 +1163,11 @@ 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); - WFIFOSET(login_session, 26); + Packet_Fixed<0x7944> fixed_44; + fixed_44.account_name = name; + send_fpacket<0x7944, 26>(login_session, fixed_44); bytes_to_read = 1; } @@ -1174,20 +1175,13 @@ void idaccount(ZString param) // Sub-function: Asking to displaying information about an account (by its id) //---------------------------------------------------------------------------- static -void infoaccount(int account_id) +void infoaccount(AccountId 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"); - return; - } + LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n"_fmt); - LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n"); - - WFIFOW(login_session, 0) = 0x7954; - WFIFOL(login_session, 2) = account_id; - WFIFOSET(login_session, 6); + Packet_Fixed<0x7954> fixed_54; + fixed_54.account_id = account_id; + send_fpacket<0x7954, 6>(login_session, fixed_54); bytes_to_read = 1; } @@ -1199,20 +1193,17 @@ 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; } - WFIFOW(login_session, 0) = 0x794e; - WFIFOW(login_session, 2) = 0; - size_t len = message.size() + 1; - WFIFOL(login_session, 4) = len; - WFIFO_STRING(login_session, 8, message, len); - WFIFOSET(login_session, 8 + len); + Packet_Head<0x794e> head_4e; + head_4e.unused = 0; + send_vpacket<0x794e, 8, 1>(login_session, head_4e, message); bytes_to_read = 1; } @@ -1227,8 +1218,8 @@ void listaccount(ZString param, int type) list_type = type; // set default values - list_first = 0; - list_last = 0; + list_first = AccountId(); + list_last = AccountId(); if (list_type == 1) { // if listgm @@ -1250,24 +1241,22 @@ void listaccount(ZString param, int type) { // if list (list_type == 0) extract(param, record<' '>(&list_first, &list_last)); - if (list_first < 0) - list_first = 0; - if (list_last < list_first || list_last < 0) - list_last = 0; + if (list_last < list_first) + list_last = AccountId(); } - LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d.\n", - list_first, list_last); + 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; - WFIFOL(login_session, 2) = list_first; - WFIFOL(login_session, 6) = list_last; - WFIFOSET(login_session, 10); + Packet_Fixed<0x7920> fixed_20; + fixed_20.start_account_id = list_first; + fixed_20.end_account_id = list_last; + send_fpacket<0x7920, 10>(login_session, fixed_20); 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; } @@ -1277,18 +1266,18 @@ void listaccount(ZString param, int type) static int itemfrob(ZString param) { - int source_id, dest_id; + ItemNameId source_id, dest_id; 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; } - WFIFOW(login_session, 0) = 0x7924; - WFIFOL(login_session, 2) = source_id; - WFIFOL(login_session, 6) = dest_id; - WFIFOSET(login_session, 10); + Packet_Fixed<0x7924> fixed_24; + fixed_24.source_item_id = source_id; + fixed_24.dest_item_id = dest_id; + send_fpacket<0x7924, 10>(login_session, fixed_24); bytes_to_read = 1; // all logging is done to the three main servers return 0; @@ -1305,9 +1294,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; } @@ -1315,23 +1304,20 @@ void changememo(ZString param) return; size_t len = memo.size(); - 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", - len); + 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); - WFIFOW(login_session, 26) = len1; - WFIFO_STRING(login_session, 28, memo, len); - WFIFOSET(login_session, 28 + len1); + Packet_Head<0x7942> head_42; + head_42.account_name = name; + send_vpacket<0x7942, 28, 1>(login_session, head_42, memo); bytes_to_read = 1; } @@ -1339,20 +1325,13 @@ void changememo(ZString param) // Sub-function: Asking to obtain an account name //----------------------------------------------- static -void nameaccount(int id) +void nameaccount(AccountId 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"); - 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; - WFIFOSET(login_session, 6); + Packet_Fixed<0x7946> fixed_46; + fixed_46.account_id = id; + send_fpacket<0x7946, 6>(login_session, fixed_46); bytes_to_read = 1; } @@ -1368,9 +1347,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; } @@ -1382,12 +1361,12 @@ 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); - WFIFO_STRING(login_session, 26, password, 24); - WFIFOSET(login_session, 50); + Packet_Fixed<0x7934> fixed_34; + fixed_34.account_name = name; + fixed_34.password = password; + send_fpacket<0x7934, 50>(login_session, fixed_34); bytes_to_read = 1; } @@ -1398,13 +1377,13 @@ void changepasswd(ZString param) static void reloadGM(ZString params) { - WFIFOW(login_session, 0) = 0x7955; - WFIFOSET(login_session, 2); + Packet_Fixed<0x7955> fixed_55; + send_fpacket<0x7955, 2>(login_session, fixed_55); 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 } @@ -1419,32 +1398,32 @@ 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); - WFIFOB(login_session, 26) = sex; - WFIFOSET(login_session, 27); + Packet_Fixed<0x793c> fixed_3c; + fixed_3c.account_name = name; + fixed_3c.sex = sex_from_char(sex); + send_fpacket<0x793c, 27>(login_session, fixed_3c); bytes_to_read = 1; } @@ -1457,18 +1436,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; } @@ -1477,31 +1456,31 @@ 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); - WFIFOL(login_session, 26) = state; - WFIFO_STRING(login_session, 30, error_message, 20); - WFIFOSET(login_session, 50); + Packet_Fixed<0x7936> fixed_36; + fixed_36.account_name = name; + fixed_36.status = state; + fixed_36.error_message = stringish<timestamp_seconds_buffer>(error_message); + send_fpacket<0x7936, 50>(login_session, fixed_36); bytes_to_read = 1; } @@ -1517,12 +1496,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; } @@ -1539,16 +1518,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 } //------------------------------------------- @@ -1561,16 +1540,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 } //--------------------------------------------------------------------- @@ -1584,11 +1563,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()) @@ -1598,28 +1577,28 @@ 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); - WFIFO_STRUCT(login_session, 26, modif); - WFIFOSET(login_session, 38); + Packet_Fixed<0x7950> fixed_50; + fixed_50.account_name = name; + fixed_50.valid_add = modif; + send_fpacket<0x7950, 38>(login_session, fixed_50); bytes_to_read = 1; } @@ -1643,31 +1622,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(); } @@ -1683,41 +1662,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", - month); - LADMIN_LOG("Invalid day for this month ('timeset' command).\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"_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; @@ -1730,19 +1709,19 @@ 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); - WFIFOL(login_session, 26) = static_cast<time_t>(connect_until_time); - WFIFOSET(login_session, 30); + Packet_Fixed<0x7948> fixed_48; + fixed_48.account_name = name; + fixed_48.valid_until = connect_until_time; + send_fpacket<0x7948, 30>(login_session, fixed_48); bytes_to_read = 1; } @@ -1756,9 +1735,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()) @@ -1766,11 +1745,11 @@ 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); - WFIFOSET(login_session, 26); + Packet_Fixed<0x7952> fixed_52; + fixed_52.account_name = name; + send_fpacket<0x7952, 26>(login_session, fixed_52); bytes_to_read = 1; } @@ -1780,10 +1759,10 @@ 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); + Packet_Fixed<0x7530> fixed_30; + send_fpacket<0x7530, 2>(login_session, fixed_30); bytes_to_read = 1; } @@ -1798,10 +1777,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 @@ -1810,7 +1789,7 @@ void prompt(void) AString buf; cin->getline(buf); - Iprintf(SGR_RESET); + Iprintf(SGR_RESET ""_fmt); fflush(stdout); if (!cin->is_open()) @@ -1818,8 +1797,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; } @@ -1832,116 +1811,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") - infoaccount(atoi(parameters.c_str())); - else if (command == "kami") + else if (command == "info"_s) + infoaccount(wrap<AccountId>(static_cast<uint32_t>(atoi(parameters.c_str())))); + 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") - nameaccount(atoi(parameters.c_str())); - else if (command == "password") + else if (command == "name"_s) + nameaccount(wrap<AccountId>(static_cast<uint32_t>(atoi(parameters.c_str())))); + 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); } } } @@ -1952,828 +1931,905 @@ void prompt(void) static void parse_fromlogin(Session *s) { -// PRINTF("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0)); - - while (RFIFOREST(s) >= 2) + RecvResult rv = RecvResult::Complete; + uint16_t packet_id; + while (rv == RecvResult::Complete && packet_peek_id(s, &packet_id)) { - switch (RFIFOW(s, 0)) + switch (packet_id) { case 0x7919: // answer of a connection request - if (RFIFOREST(s) < 3) - return; - if (RFIFOB(s, 2) != 0) + { + Packet_Fixed<0x7919> fixed; + rv = recv_fpacket<0x7919, 3>(s, fixed); + if (rv != RecvResult::Complete) + break; + + if (fixed.error != 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->set_eof(); //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(); } - RFIFOSKIP(s, 3); break; + } case 0x7531: // Displaying of the version of the login-server - if (RFIFOREST(s) < 10) - return; { - Iprintf(" Login-Server [%s:%d]\n", + Packet_Fixed<0x7531> fixed; + rv = recv_fpacket<0x7531, 10>(s, fixed); + if (rv != RecvResult::Complete) + break; + + 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", + Version version = fixed.version; + Iprintf(" 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); - } bytes_to_read = 0; - RFIFOSKIP(s, 10); break; + } case 0x7925: // Itemfrob-OK - RFIFOSKIP(s, 2); + { + Packet_Fixed<0x7925> fixed; + rv = recv_fpacket<0x7925, 2>(s, fixed); + if (rv != RecvResult::Complete) + break; + bytes_to_read = 0; break; + } case 0x7921: // Displaying of the list of accounts - if (RFIFOREST(s) < 4 || RFIFOREST(s) < RFIFOW(s, 2)) - return; - if (RFIFOW(s, 2) < 5) + { + std::vector<Packet_Repeat<0x7921>> repeat; + rv = recv_packet_repeatonly<0x7921, 4, 38>(s, repeat); + if (rv != RecvResult::Complete) + break; + + // the admin client resends the request with a shrunken + // range until an empty reply is given + if (repeat.empty()) { - 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"); - for (i = 4; i < RFIFOW(s, 2); i += 38) + LADMIN_LOG(" Receiving of a accounts list.\n"_fmt); + for (const Packet_Repeat<0x7921>& info : repeat) { - AccountName userid = stringish<AccountName>(RFIFO_STRING<24>(s, i + 5)); + AccountName userid = info.account_name; VString<23> lower_userid = userid.to_lower(); - list_first = RFIFOL(s, i) + 1; + // this is ad-hoc block streaming + // (with a global variable) + list_first = next(info.account_id); // here are checks... if (list_type == 0 - || (list_type == 1 && RFIFOB(s, i + 4) > 0) + || (list_type == 1 && info.gm_level) || (list_type == 2 && lower_userid.contains_seq(parameters)) - || (list_type == 3 && RFIFOL(s, i + 34) != 0) - || (list_type == 4 && RFIFOL(s, i + 34) == 0)) + || (list_type == 3 && info.status != 0) + || (list_type == 4 && info.status == 0)) { - PRINTF("%10d ", RFIFOL(s, i)); - if (RFIFOB(s, i + 4) == 0) - PRINTF(" "); + PRINTF("%10d "_fmt, info.account_id); + if (!info.gm_level) + PRINTF(" "_fmt); else - PRINTF("%2d ", RFIFOB(s, i + 4)); - PRINTF("%-24s", userid); - if (RFIFOB(s, i + 29) == 0) - PRINTF("%-5s ", "Femal"); - else if (RFIFOB(s, i + 29) == 1) - PRINTF("%-5s ", "Male"); + PRINTF("%2d "_fmt, info.gm_level); + PRINTF("%-24s"_fmt, userid); + if (info.sex == SEX::FEMALE) + PRINTF("%-5s "_fmt, "Femal"_s); + else if (info.sex == SEX::MALE) + PRINTF("%-5s "_fmt, "Male"_s); else - PRINTF("%-5s ", "Servr"); - PRINTF("%6d ", RFIFOL(s, i + 30)); - switch (RFIFOL(s, i + 34)) + PRINTF("%-5s "_fmt, "Servr"_s); + PRINTF("%6d "_fmt, info.login_count); + switch (info.status) { 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", - list_first, list_last); - WFIFOW(login_session, 0) = 0x7920; - WFIFOL(login_session, 2) = list_first; - WFIFOL(login_session, 6) = list_last; - WFIFOSET(login_session, 10); + LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d (complement).\n"_fmt, + list_first, list_last); + Packet_Fixed<0x7920> fixed_20; + fixed_20.start_account_id = list_first; + fixed_20.end_account_id = list_last; + send_fpacket<0x7920, 10>(login_session, fixed_20); bytes_to_read = 1; } - RFIFOSKIP(s, RFIFOW(s, 2)); break; + } case 0x7931: // Answer of login-server about an account creation - if (RFIFOREST(s) < 30) - return; { - int accid = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (accid == -1) + Packet_Fixed<0x7931> fixed; + rv = recv_fpacket<0x7931, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId accid = fixed.account_id; + AccountName name = fixed.account_name; + if (!accid) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7933: // Answer of login-server about an account deletion - if (RFIFOREST(s) < 30) - return; { - int accid = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (accid == -1) + Packet_Fixed<0x7933> fixed; + rv = recv_fpacket<0x7933, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId accid = fixed.account_id; + AccountName name = fixed.account_name; + if (!accid) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7935: // answer of the change of an account password - if (RFIFOREST(s) < 30) - return; { - int accid = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (accid == -1) + Packet_Fixed<0x7935> fixed; + rv = recv_fpacket<0x7935, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId accid = fixed.account_id; + AccountName name = fixed.account_name; + if (!accid) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7937: // answer of the change of an account state - if (RFIFOREST(s) < 34) - return; { - int accid = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - int state = RFIFOL(s, 30); - if (accid == -1) + Packet_Fixed<0x7937> fixed; + rv = recv_fpacket<0x7937, 34>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId accid = fixed.account_id; + AccountName name = fixed.account_name; + int state = fixed.status; + if (!accid) { - 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; - } - RFIFOSKIP(s, 34); break; + } case 0x7939: // answer of the number of online players - if (RFIFOREST(s) < 4 || RFIFOREST(s) < RFIFOW(s, 2)) - return; + { + std::vector<Packet_Repeat<0x7939>> repeat; + rv = recv_packet_repeatonly<0x7939, 4, 32>(s, repeat); + if (rv != RecvResult::Complete) + break; + { // 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) + if (repeat.empty()) { - 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) + for (const Packet_Repeat<0x7939>& info : repeat) { - ServerName name = stringish<ServerName>(RFIFO_STRING<20>(s, i + 6)); - PRINTF(" %-20s : %5d\n", name, - RFIFOW(s, i + 26)); + // info.ip + // info.port + ServerName name = info.name; + PRINTF(" %-20s : %5d\n"_fmt, name, + info.users); + // info.maintenance + // info.is_new } } } bytes_to_read = 0; - RFIFOSKIP(s, RFIFOW(s, 2)); break; + } case 0x793b: // answer of the check of a password - if (RFIFOREST(s) < 30) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x793b> fixed; + rv = recv_fpacket<0x793b, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x793d: // answer of the change of an account sex - if (RFIFOREST(s) < 30) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x793d> fixed; + rv = recv_fpacket<0x793d, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x793f: // answer of the change of an account GM level - if (RFIFOREST(s) < 30) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x793f> fixed; + rv = recv_fpacket<0x793f, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7941: // answer of the change of an account email - if (RFIFOREST(s) < 30) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x7941> fixed; + rv = recv_fpacket<0x7941, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7943: // answer of the change of an account memo - if (RFIFOREST(s) < 30) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x7943> fixed; + rv = recv_fpacket<0x7943, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7945: // answer of an account id search - if (RFIFOREST(s) < 30) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x7945> fixed; + rv = recv_fpacket<0x7945, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7947: // answer of an account name search - if (RFIFOREST(s) < 30) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); + Packet_Fixed<0x7947> fixed; + rv = recv_fpacket<0x7947, 30>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; 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; - } - RFIFOSKIP(s, 30); break; + } case 0x7949: // answer of an account validity limit set - if (RFIFOREST(s) < 34) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (RFIFOL(s, 2) == -1) + Packet_Fixed<0x7949> fixed; + rv = recv_fpacket<0x7949, 34>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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 { - TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); + TimeT timestamp = fixed.valid_until; 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); } } bytes_to_read = 0; - } - RFIFOSKIP(s, 34); break; + } case 0x794b: // answer of an account ban set - if (RFIFOREST(s) < 34) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x794b> fixed; + rv = recv_fpacket<0x794b, 34>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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 { - TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); + TimeT timestamp = fixed.ban_until; 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", - name, RFIFOL(s, 2), tmpstr); - LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n", - name, RFIFOL(s, 2), + 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"_fmt, + name, account_id, tmpstr); } } bytes_to_read = 0; - } - RFIFOSKIP(s, 34); break; + } case 0x794d: // answer of an account ban date/time changing - if (RFIFOREST(s) < 34) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x794d> fixed; + rv = recv_fpacket<0x794d, 34>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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 { - TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); + TimeT timestamp = fixed.ban_until; 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); } } bytes_to_read = 0; - } - RFIFOSKIP(s, 34); break; + } case 0x794f: // answer of a broadcast - if (RFIFOREST(s) < 4) - return; - if (RFIFOW(s, 2) == static_cast<uint16_t>(-1)) + { + Packet_Fixed<0x794f> fixed; + rv = recv_fpacket<0x794f, 4>(s, fixed); + if (rv != RecvResult::Complete) + break; + + if (fixed.error == 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); break; + } case 0x7951: // answer of an account validity limit changing - if (RFIFOREST(s) < 34) - return; { - int account_id = RFIFOL(s, 2); - AccountName name = stringish<AccountName>(RFIFO_STRING<24>(s, 6)); - if (account_id == -1) + Packet_Fixed<0x7951> fixed; + rv = recv_fpacket<0x7951, 34>(s, fixed); + if (rv != RecvResult::Complete) + break; + + AccountId account_id = fixed.account_id; + AccountName name = fixed.account_name; + if (!account_id) { - 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 { - TimeT timestamp = static_cast<time_t>(RFIFOL(s, 30)); + TimeT timestamp = fixed.valid_until; 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); } } bytes_to_read = 0; - } - RFIFOSKIP(s, 34); break; + } case 0x7953: // answer of a request about informations of an account (by account name/id) - if (RFIFOREST(s) < 150 - || RFIFOREST(s) < (150 + RFIFOW(s, 148))) - return; + { + Packet_Head<0x7953> head; + AString repeat; + rv = recv_vpacket<0x7953, 150, 1>(s, head, repeat); + if (rv != RecvResult::Complete) + break; + { - int account_id = RFIFOL(s, 2); - uint8_t gm = RFIFOB(s, 6); - AccountName userid = stringish<AccountName>(RFIFO_STRING<24>(s, 7)); - uint8_t sex = RFIFOB(s, 31); - int connections = RFIFOL(s, 32); - int state = RFIFOL(s, 36); - timestamp_seconds_buffer error_message = stringish<timestamp_seconds_buffer>(RFIFO_STRING<20>(s, 40)); - timestamp_milliseconds_buffer lastlogin = stringish<timestamp_milliseconds_buffer>(RFIFO_STRING<24>(s, 60)); - VString<15> last_ip_ = RFIFO_STRING<16>(s, 84); - AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(s, 100)); - TimeT connect_until_time = static_cast<time_t>(RFIFOL(s, 140)); - TimeT ban_until_time = static_cast<time_t>(RFIFOL(s, 144)); - AString memo = RFIFO_STRING(s, 150, RFIFOW(s, 148)); - if (account_id == -1) + AccountId account_id = head.account_id; + // TODO fix size (there's a lot of other stuff wrong with this packet too + GmLevel gm = head.gm_level; + AccountName userid = head.account_name; + SEX sex = head.sex; + int connections = head.login_count; + int state = head.state; + timestamp_seconds_buffer error_message = head.error_message; + timestamp_milliseconds_buffer lastlogin = head.last_login_string; + VString<15> last_ip_ = head.ip_string; + AccountEmail email = head.email; + TimeT connect_until_time = head.connect_until; + TimeT ban_until_time = head.ban_until; + AString& memo = repeat; + if (!account_id) { - 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); - if (sex == 0) - PRINTF(" Sex: Female\n"); - else if (sex == 1) - PRINTF(" Sex: Male\n"); - else - PRINTF(" Sex: Server\n"); - PRINTF(" E-mail: %s\n", email); + PRINTF(" Name: '%s'\n"_fmt, userid); + if (sex == SEX::FEMALE) + PRINTF(" Sex: Female\n"_fmt); + else if (sex == SEX::MALE) + PRINTF(" Sex: Male\n"_fmt); + else // doesn't happen anymore + 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", - error_message); + 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; - RFIFOSKIP(s, 150 + RFIFOW(s, 148)); 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->set_eof(); return; + } } } + if (rv == RecvResult::Error) + { + s->set_eof(); + return; + } + + // The following was almost certainly wrong and only worked because + // localhost is a fast enough network to never split byte 1 vs byte 2 + // if we don't wait new packets, do the prompt - prompt(); + if (bytes_to_read == 0) + prompt(); } //------------------------------------ @@ -2782,23 +2838,23 @@ 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, SessionParsers{func_parse: parse_fromlogin, func_delete: delete_fromlogin}); + login_session = make_connection(login_ip, login_port, SessionParsers{.func_parse= parse_fromlogin, .func_delete= delete_fromlogin}); if (!login_session) return 0; { - WFIFOW(login_session, 0) = 0x7918; // Request for administation login - WFIFOW(login_session, 2) = 0; // no encrypted - WFIFO_STRING(login_session, 4, admin_pass, 24); - WFIFOSET(login_session, 28); + Packet_Fixed<0x7918> fixed_18; + fixed_18.encryption_zero = 0; + fixed_18.account_pass = admin_pass; + send_fpacket<0x7918, 28>(login_session, fixed_18); 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; @@ -2808,12 +2864,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) + if (h != nullptr) { - 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]), @@ -2823,21 +2879,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; } } @@ -2854,8 +2910,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; } @@ -2873,20 +2929,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; } } @@ -2898,26 +2954,27 @@ 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); - 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(); return 0; } +} // namespace tmwa |