diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index e9ae1ee5..af04a53b 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -1530,14 +1530,32 @@ ChatCommandDefinition cc_ln( ChatCommandDefinition cc_loadchar( {"$loadchar"}, +[](const Args& a) -> asio::awaitable { - a.check_is_proxy(false); + if (a.c->proxy_session && (a.c->version() == Version::BB_V4)) { + throw precondition_failed("$C6This command cannot\nbe used in proxy\nsessions in BB games"); + } a.check_is_game(false); if (a.check_permissions && a.c->login->account->check_flag(Account::Flag::IS_SHARED_ACCOUNT)) { throw precondition_failed("$C7This command cannot\nbe used on a shared\naccount"); } auto s = a.c->require_server_state(); - auto l = a.c->require_lobby(); + shared_ptr l; + if (a.c->proxy_session) { + if (!a.c->proxy_session->is_in_lobby) { + throw precondition_failed("$C6This command can\nonly be used from\nthe lobby"); + } + } else { + l = a.c->require_lobby(); + } + + auto send_proxy_lobby_refresh = [&]() { + auto temp_l = make_shared(s, 0xFFFFFFFF, false); + temp_l->block = 1; + temp_l->event = a.c->proxy_session ? a.c->proxy_session->lobby_event : 0; + temp_l->leader_id = a.c->lobby_client_id; + temp_l->clients.at(a.c->lobby_client_id) = a.c; + send_join_lobby(a.c, temp_l); + }; size_t index = stoull(a.text, nullptr, 0) - 1; if (index >= s->num_backup_character_slots) { @@ -1570,7 +1588,7 @@ ChatCommandDefinition cc_loadchar( throw precondition_failed("Can\'t load character\ndata on this game\nversion"); } - auto send_set_extended_player_info = [&a, &s](const CharT& char_file) -> asio::awaitable { + auto send_set_extended_player_info = [&a, &s, &send_proxy_lobby_refresh](const CharT& char_file) -> asio::awaitable { co_await prepare_client_for_patches(a.c); try { auto fn = s->function_code_index->get_patch("SetExtendedPlayerInfo", a.c->specific_version); @@ -1579,6 +1597,8 @@ ChatCommandDefinition cc_loadchar( if (l) { send_player_leave_notification(l, a.c->lobby_client_id); s->send_lobby_join_notifications(l, a.c); + } else if (a.c->proxy_session) { + send_proxy_lobby_refresh(); } } catch (const exception& e) { a.c->log.warning_f("Failed to set extended player info: {}", e.what()); @@ -1613,11 +1633,15 @@ ChatCommandDefinition cc_loadchar( } } else { - // On v1 and v2, the client will assign its character data from the lobby join command, so it suffices to just - // resend the join notification. - auto s = a.c->require_server_state(); - send_player_leave_notification(l, a.c->lobby_client_id); - s->send_lobby_join_notifications(l, a.c); + // On PC V2 and older DC versions, the client will assign its character data + // from the lobby join command, so resend a lobby join notification. + if (a.c->proxy_session) { + send_proxy_lobby_refresh(); + } else { + auto s = a.c->require_server_state(); + send_player_leave_notification(l, a.c->lobby_client_id); + s->send_lobby_join_notifications(l, a.c); + } } co_return; });