From 8582e18861111a9e93cd776ad299e9e288e2994a Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 4 Feb 2023 19:51:00 -0800 Subject: [PATCH] add $exit on game server --- README.md | 2 +- src/ChatCommands.cc | 30 ++++++++++++++++++++++++++++-- src/ProxyServer.cc | 4 +--- src/ReceiveCommands.cc | 12 +++--------- src/SendCommands.cc | 4 +--- src/Version.cc | 7 +++++++ src/Version.hh | 7 +++++++ 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c7c79d48..a5e02f36 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ Some commands only work on the game server and not on the proxy server. The chat * `$arrow `: Changes your lobby arrow color. * `$secid `: Sets your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. To revert to your actual section id, run `$secid` with no name after it. * `$rand `: Sets your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies. This also makes item drops deterministic in Blue Burst games hosted by newserv. On the proxy server, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. - * `$exit` (proxy server only): Ends your proxy session and returns you to the main menu. Can only be used from the lobby. + * `$exit`: If you're in a lobby, sends you to the main menu (which ends your proxy session, if you're in one). If you're in an Episode 3 game, sends you to the lobby (but does not end your proxy session if you're in one). * Blue Burst player commands (game server only) * `$bbchar <1-4>`: Use this command when playing on a non-BB version of PSO. If the username and password are correct, this command converts your current character to BB format and saves it on the server in the given slot. Any character already in that slot is overwritten. diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index c10521af..d147c7f4 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -295,11 +295,37 @@ static void server_command_persist(shared_ptr, shared_ptr l, } } +static void server_command_exit(shared_ptr s, shared_ptr l, + shared_ptr c, const std::u16string&) { + if (l->is_game()) { + if (c->flags & Client::Flag::IS_EPISODE_3) { + c->channel.send(0xED, 0x00); + } else { + send_text_message(c, u"$C6You must return to\nthe lobby first"); + } + } else { + send_self_leave_notification(c); + if (!(c->flags & Client::Flag::NO_D6)) { + send_message_box(c, u""); + } + + const auto& port_name = version_to_login_port_name.at( + static_cast(c->version())); + send_reconnect(c, s->connect_address_for_client(c), + s->name_to_port_config.at(port_name)->port); + } +} + static void proxy_command_exit(shared_ptr, ProxyServer::LinkedSession& session, const std::u16string&) { if (session.is_in_game) { - send_text_message(session.client_channel, u"$C6You must return to\nthe lobby first"); + if (session.newserv_client_config.cfg.flags & Client::Flag::IS_EPISODE_3) { + session.client_channel.send(0xED, 0x00); + } else { + send_text_message(session.client_channel, u"$C6You must return to\nthe lobby first"); + } } else { + session.close_on_disconnect = true; session.send_to_game_server(); } } @@ -1154,7 +1180,7 @@ static const unordered_map chat_commands({ {u"$dbgid", {server_command_dbgid, nullptr, u"Usage:\ndbgid"}}, {u"$edit", {server_command_edit, nullptr , u"Usage:\nedit "}}, {u"$event", {server_command_lobby_event, proxy_command_lobby_event, u"Usage:\nevent "}}, - {u"$exit", {nullptr, proxy_command_exit, u"Usage:\nexit"}}, + {u"$exit", {server_command_exit, proxy_command_exit, u"Usage:\nexit"}}, {u"$gc", {server_command_get_self_card, proxy_command_get_player_card, u"Usage:\ngc"}}, {u"$infhp", {server_command_infinite_hp, proxy_command_infinite_hp, u"Usage:\ninfhp"}}, {u"$inftp", {server_command_infinite_tp, proxy_command_infinite_tp, u"Usage:\ninftp"}}, diff --git a/src/ProxyServer.cc b/src/ProxyServer.cc index 58fd8c62..e277dda7 100644 --- a/src/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -715,9 +715,7 @@ void ProxyServer::LinkedSession::send_to_game_server(const char* error_message) update_client_config_cmd.cfg = this->newserv_client_config.cfg; this->client_channel.send(0x04, 0x00, &update_client_config_cmd, sizeof(update_client_config_cmd)); - static const vector version_to_port_name({ - "bb-patch", "console-login", "pc-login", "console-login", "console-login", "bb-init"}); - const auto& port_name = version_to_port_name.at(static_cast( + const auto& port_name = version_to_login_port_name.at(static_cast( this->version)); S_Reconnect_19 reconnect_cmd = {{ diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 979d5cab..c3d05b42 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -126,17 +126,13 @@ static vector proxy_options_menu_for_client( static void send_client_to_lobby_server(shared_ptr s, shared_ptr c) { - static const vector version_to_port_name({ - "bb-lobby", "console-lobby", "pc-lobby", "console-lobby", "console-lobby", "bb-lobby"}); - const auto& port_name = version_to_port_name.at(static_cast(c->version())); + const auto& port_name = version_to_lobby_port_name.at(static_cast(c->version())); send_reconnect(c, s->connect_address_for_client(c), s->name_to_port_config.at(port_name)->port); } static void send_client_to_proxy_server(shared_ptr s, shared_ptr c) { - static const vector version_to_port_name({ - "", "dc-proxy", "pc-proxy", "gc-proxy", "xb-proxy", "bb-proxy"}); - const auto& port_name = version_to_port_name.at(static_cast(c->version())); + const auto& port_name = version_to_proxy_port_name.at(static_cast(c->version())); uint16_t local_port = s->name_to_port_config.at(port_name)->port; s->proxy_server->delete_session(c->license->serial_number); @@ -2215,9 +2211,7 @@ static void on_A0(shared_ptr s, shared_ptr c, send_message_box(c, u""); } - static const vector version_to_port_name({ - "bb-patch", "console-login", "pc-login", "console-login", "console-login", "bb-init"}); - const auto& port_name = version_to_port_name.at(static_cast(c->version())); + const auto& port_name = version_to_login_port_name.at(static_cast(c->version())); send_reconnect(c, s->connect_address_for_client(c), s->name_to_port_config.at(port_name)->port); diff --git a/src/SendCommands.cc b/src/SendCommands.cc index bf4f446d..f9c64ea5 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -875,9 +875,7 @@ void send_card_search_result_t( shared_ptr c, shared_ptr result, shared_ptr result_lobby) { - static const vector version_to_port_name({ - "bb-lobby", "console-lobby", "pc-lobby", "console-lobby", "console-lobby", "bb-lobby"}); - const auto& port_name = version_to_port_name.at(static_cast(c->version())); + const auto& port_name = version_to_lobby_port_name.at(static_cast(c->version())); S_GuildCardSearchResult cmd; cmd.player_tag = 0x00010000; diff --git a/src/Version.cc b/src/Version.cc index e1a53c90..47aa8455 100644 --- a/src/Version.cc +++ b/src/Version.cc @@ -10,6 +10,13 @@ using namespace std; +const vector version_to_login_port_name({ + "bb-patch", "console-login", "pc-login", "console-login", "console-login", "bb-init"}); +const vector version_to_lobby_port_name({ + "bb-patch", "console-lobby", "pc-lobby", "console-lobby", "console-lobby", "bb-lobby"}); +const vector version_to_proxy_port_name({ + "", "dc-proxy", "pc-proxy", "gc-proxy", "xb-proxy", "bb-proxy"}); + uint16_t flags_for_version(GameVersion version, int64_t sub_version) { switch (sub_version) { case -1: // Initial check (before sub_version recognition) diff --git a/src/Version.hh b/src/Version.hh index 8be4dbd2..307a5300 100644 --- a/src/Version.hh +++ b/src/Version.hh @@ -2,6 +2,9 @@ #include +#include +#include + enum class GameVersion { @@ -23,6 +26,10 @@ enum class ServerBehavior { PROXY_SERVER, }; +extern const std::vector version_to_login_port_name; +extern const std::vector version_to_lobby_port_name; +extern const std::vector version_to_proxy_port_name; + uint16_t flags_for_version(GameVersion version, int64_t sub_version); const char* name_for_version(GameVersion version); GameVersion version_for_name(const char* name);