Properly handle multiple lobby joins by the same peer.

merge-requests/31/head
Mr_Goldberg 2020-05-23 09:12:16 -04:00
parent 4882344673
commit 6cccdd2b16
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
1 changed files with 24 additions and 16 deletions

View File

@ -504,12 +504,13 @@ CSteamID GetLobbyByIndex( int iLobby )
return id; return id;
} }
static void enter_lobby(Lobby *lobby, CSteamID id) static bool enter_lobby(Lobby *lobby, CSteamID id)
{ {
if (get_lobby_member(lobby, id)) return; if (get_lobby_member(lobby, id)) return false;
Lobby_Member *member = lobby->add_members(); Lobby_Member *member = lobby->add_members();
member->set_id(id.ConvertToUint64()); member->set_id(id.ConvertToUint64());
return true;
} }
static bool leave_lobby(Lobby *lobby, CSteamID id) static bool leave_lobby(Lobby *lobby, CSteamID id)
@ -1303,8 +1304,9 @@ void Callback(Common_Message *msg)
if (!member) { if (!member) {
if (m.id() == settings->get_local_steam_id().ConvertToUint64()) { if (m.id() == settings->get_local_steam_id().ConvertToUint64()) {
CSteamID id((uint64)lobby->room_id()); CSteamID id((uint64)lobby->room_id());
auto pd = std::find_if(pending_joins.begin(), pending_joins.end(), [&id](Pending_Joins const& item) { return item.lobby_id == id; }); auto pd = pending_joins.begin();
if (pd != pending_joins.end()) { while (pd != pending_joins.end()) {
if (pd->lobby_id == id) {
bool success = true; bool success = true;
LobbyEnter_t data; LobbyEnter_t data;
data.m_ulSteamIDLobby = lobby->room_id(); data.m_ulSteamIDLobby = lobby->room_id();
@ -1313,10 +1315,15 @@ void Callback(Common_Message *msg)
data.m_EChatRoomEnterResponse = success ? k_EChatRoomEnterResponseSuccess : k_EChatRoomEnterResponseError; data.m_EChatRoomEnterResponse = success ? k_EChatRoomEnterResponseSuccess : k_EChatRoomEnterResponseError;
callback_results->addCallResult(pd->api_id, data.k_iCallback, &data, sizeof(data)); callback_results->addCallResult(pd->api_id, data.k_iCallback, &data, sizeof(data));
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
pending_joins.erase(pd); pd = pending_joins.erase(pd);
joined = true;
} else {
++pd;
}
}
if (joined) {
on_self_enter_leave_lobby((uint64)lobby->room_id(), lobby->type(), false); on_self_enter_leave_lobby((uint64)lobby->room_id(), lobby->type(), false);
trigger_lobby_dataupdate((uint64)lobby->room_id(), (uint64)lobby->room_id(), true); trigger_lobby_dataupdate((uint64)lobby->room_id(), (uint64)lobby->room_id(), true);
joined = true;
} }
} else { } else {
if (we_are_in_lobby) trigger_lobby_member_join_leave((uint64)lobby->room_id(), (uint64)m.id(), false, true); if (we_are_in_lobby) trigger_lobby_member_join_leave((uint64)lobby->room_id(), (uint64)m.id(), false, true);
@ -1357,9 +1364,10 @@ void Callback(Common_Message *msg)
if (lobby->owner() == settings->get_local_steam_id().ConvertToUint64()) { if (lobby->owner() == settings->get_local_steam_id().ConvertToUint64()) {
if (msg->lobby_messages().type() == Lobby_Messages::JOIN) { if (msg->lobby_messages().type() == Lobby_Messages::JOIN) {
PRINT_DEBUG("LOBBY MESSAGE: JOIN\n"); PRINT_DEBUG("LOBBY MESSAGE: JOIN\n");
enter_lobby(lobby, (uint64)msg->source_id()); if (enter_lobby(lobby, (uint64)msg->source_id())) {
trigger_lobby_member_join_leave((uint64)lobby->room_id(), (uint64)msg->source_id(), false, true, 0.01); trigger_lobby_member_join_leave((uint64)lobby->room_id(), (uint64)msg->source_id(), false, true, 0.01);
} }
}
if (msg->lobby_messages().type() == Lobby_Messages::MEMBER_DATA) { if (msg->lobby_messages().type() == Lobby_Messages::MEMBER_DATA) {
PRINT_DEBUG("LOBBY MESSAGE: MEMBER_DATA\n"); PRINT_DEBUG("LOBBY MESSAGE: MEMBER_DATA\n");