implement redirect destinations

This commit is contained in:
Martin Michelsen
2023-10-18 17:22:07 -07:00
parent e8d8b94ffa
commit 2e36cebbcc
6 changed files with 156 additions and 11 deletions
+58 -1
View File
@@ -119,6 +119,11 @@ static void send_proxy_destinations_menu(shared_ptr<Client> c) {
send_menu(c, s->proxy_destinations_menu_for_version(c->version()));
}
static void send_redirect_destinations_menu(shared_ptr<Client> c) {
auto s = c->require_server_state();
send_menu(c, s->redirect_destinations_menu_for_version(c->version()));
}
static bool send_enable_send_function_call_if_applicable(shared_ptr<Client> c) {
auto s = c->require_server_state();
if (function_compiler_available() &&
@@ -206,6 +211,7 @@ static void send_main_menu(shared_ptr<Client> c) {
0);
main_menu->items.emplace_back(MainMenuItemID::INFORMATION, u"Information",
u"View server\ninformation", MenuItem::Flag::INVISIBLE_ON_DCNTE | MenuItem::Flag::REQUIRES_MESSAGE_BOXES);
uint32_t proxy_destinations_menu_item_flags =
// DCNTE doesn't support multiple ship select menus without changing
// servers (via a 19 command) apparently :(
@@ -216,7 +222,24 @@ static void send_main_menu(shared_ptr<Client> c) {
(s->proxy_destinations_xb.empty() ? MenuItem::Flag::INVISIBLE_ON_XB : 0) |
MenuItem::Flag::INVISIBLE_ON_BB;
main_menu->items.emplace_back(MainMenuItemID::PROXY_DESTINATIONS, u"Proxy server",
u"Connect to another\nserver", proxy_destinations_menu_item_flags);
u"Connect to another\nserver through the\nproxy", proxy_destinations_menu_item_flags);
// If the client is on a virtual connection, redirecting will not work
// properly (they'll just be reconencted to newserv), so hide the option
if (!c->channel.is_virtual_connection) {
uint32_t redirect_destinations_menu_item_flags =
// DCNTE doesn't support multiple ship select menus without changing
// servers (via a 19 command) apparently :(
MenuItem::Flag::INVISIBLE_ON_DCNTE |
(s->redirect_destinations_dc.empty() ? MenuItem::Flag::INVISIBLE_ON_DC : 0) |
(s->redirect_destinations_pc.empty() ? MenuItem::Flag::INVISIBLE_ON_PC : 0) |
(s->redirect_destinations_gc.empty() ? MenuItem::Flag::INVISIBLE_ON_GC : 0) |
(s->redirect_destinations_xb.empty() ? MenuItem::Flag::INVISIBLE_ON_XB : 0) |
MenuItem::Flag::INVISIBLE_ON_BB;
main_menu->items.emplace_back(MainMenuItemID::REDIRECT_DESTINATIONS, u"Other servers",
u"Connect to another\nserver directly", redirect_destinations_menu_item_flags);
}
main_menu->items.emplace_back(MainMenuItemID::DOWNLOAD_QUESTS, u"Download quests",
u"Download quests", MenuItem::Flag::INVISIBLE_ON_DCNTE | MenuItem::Flag::INVISIBLE_ON_BB);
if (!s->is_replay) {
@@ -1702,6 +1725,10 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, const string& data)
send_proxy_destinations_menu(c);
break;
case MainMenuItemID::REDIRECT_DESTINATIONS:
send_redirect_destinations_menu(c);
break;
case MainMenuItemID::DOWNLOAD_QUESTS: {
auto s = c->require_server_state();
if (c->flags & Client::Flag::IS_EPISODE_3) {
@@ -1907,6 +1934,36 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, const string& data)
break;
}
case MenuID::REDIRECT_DESTINATIONS: {
if (item_id == RedirectDestinationsMenuItemID::GO_BACK) {
send_main_menu(c);
} else if (item_id == RedirectDestinationsMenuItemID::OPTIONS) {
send_menu(c, proxy_options_menu_for_client(c));
} else {
auto s = c->require_server_state();
const pair<string, uint16_t>* dest = nullptr;
try {
dest = &s->redirect_destinations_for_version(c->version()).at(item_id);
} catch (const out_of_range&) {
}
if (!dest) {
send_message_box(c, u"$C6No such destination exists.");
c->should_disconnect = true;
} else {
// Clear Check Tactics menu so client won't see newserv tournament
// state while logically on another server
if ((c->flags & Client::Flag::IS_EPISODE_3) && !(c->flags & Client::Flag::IS_EP3_TRIAL_EDITION)) {
send_ep3_confirm_tournament_entry(c, nullptr);
}
send_reconnect(c, resolve_ipv4(dest->first), dest->second);
}
}
break;
}
case MenuID::GAME: {
auto s = c->require_server_state();
auto game = s->find_lobby(item_id);