Compare commits

...

3 Commits

Author SHA1 Message Date
Mr_Goldberg 6cccdd2b16
Properly handle multiple lobby joins by the same peer. 2020-05-23 09:12:16 -04:00
Mr_Goldberg 4882344673
Fix bug. 2020-05-23 09:11:39 -04:00
Mr_Goldberg 1c141783ac
Small mutex fix. 2020-05-23 09:10:56 -04:00
3 changed files with 26 additions and 18 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,20 +1304,26 @@ 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()) {
bool success = true; if (pd->lobby_id == id) {
LobbyEnter_t data; bool success = true;
data.m_ulSteamIDLobby = lobby->room_id(); LobbyEnter_t data;
data.m_rgfChatPermissions = 0; //Unused - Always 0 data.m_ulSteamIDLobby = lobby->room_id();
data.m_bLocked = false; data.m_rgfChatPermissions = 0; //Unused - Always 0
data.m_EChatRoomEnterResponse = success ? k_EChatRoomEnterResponseSuccess : k_EChatRoomEnterResponseError; data.m_bLocked = false;
callback_results->addCallResult(pd->api_id, data.k_iCallback, &data, sizeof(data)); data.m_EChatRoomEnterResponse = success ? k_EChatRoomEnterResponseSuccess : k_EChatRoomEnterResponseError;
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); callback_results->addCallResult(pd->api_id, data.k_iCallback, &data, sizeof(data));
pending_joins.erase(pd); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
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,8 +1364,9 @@ 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) {

View File

@ -138,7 +138,7 @@ void remove_connection(CSteamID id)
auto msg = std::begin(unprocessed_messages); auto msg = std::begin(unprocessed_messages);
while (msg != std::end(unprocessed_messages)) { while (msg != std::end(unprocessed_messages)) {
if (msg->source_id() == id.ConvertToUint64()) { if (msg->source_id() == id.ConvertToUint64()) {
msg = messages.erase(msg); msg = unprocessed_messages.erase(msg);
} else { } else {
++msg; ++msg;
} }

View File

@ -82,7 +82,6 @@ bool BLoggedOn()
CSteamID GetSteamID() CSteamID GetSteamID()
{ {
PRINT_DEBUG("Steam_User::GetSteamID\n"); PRINT_DEBUG("Steam_User::GetSteamID\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
CSteamID id = settings->get_local_steam_id(); CSteamID id = settings->get_local_steam_id();
return id; return id;
@ -110,6 +109,7 @@ CSteamID GetSteamID()
int InitiateGameConnection( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure ) int InitiateGameConnection( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure )
{ {
PRINT_DEBUG("InitiateGameConnection %i %llu %u %u %u\n", cbMaxAuthBlob, steamIDGameServer.ConvertToUint64(), unIPServer, usPortServer, bSecure); PRINT_DEBUG("InitiateGameConnection %i %llu %u %u %u\n", cbMaxAuthBlob, steamIDGameServer.ConvertToUint64(), unIPServer, usPortServer, bSecure);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (cbMaxAuthBlob < INITIATE_GAME_CONNECTION_TICKET_SIZE) return 0; if (cbMaxAuthBlob < INITIATE_GAME_CONNECTION_TICKET_SIZE) return 0;
uint32 out_size = INITIATE_GAME_CONNECTION_TICKET_SIZE; uint32 out_size = INITIATE_GAME_CONNECTION_TICKET_SIZE;
ticket_manager->getTicketData(pAuthBlob, INITIATE_GAME_CONNECTION_TICKET_SIZE, &out_size); ticket_manager->getTicketData(pAuthBlob, INITIATE_GAME_CONNECTION_TICKET_SIZE, &out_size);