diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index 66eb0c250d..ebdc1192e5 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -86,7 +86,8 @@ SceNetAdhocctlScanInfo * networks = NULL; SceNetAdhocctlScanInfo * newnetworks = NULL; u64 adhocctlStartTime = 0; u64 gameModeEnterTimeUs = 0; -bool dropLateGroupReply = false; +bool groupJoinInFlight = false; +int abandonedGroupJoins = 0; std::atomic isAdhocctlNeedLogin = false; bool isAdhocctlBusy = false; int adhocctlState = ADHOCCTL_STATE_DISCONNECTED; @@ -1377,6 +1378,9 @@ void killAdhocctlClient(bool due_to_error, const std::lock_guard &lo destroy_adhocctl_session(adhocctlHandle); adhocctlHandle = NULL; + // Nothing more comes from that session. + groupJoinInFlight = false; + abandonedGroupJoins = 0; // Mark all friends as timedout since we won't be able to detects disconnected friends anymore without being connected to Adhoc Server peerlock.lock(); @@ -1697,12 +1701,12 @@ void friendFinderPoll() { break; case ADHOCCTL_CLIENT_EVENT_LEADER_MAC:{ INFO_LOG(Log::sceNet, "FriendFinder: Incoming OPCODE_CONNECT_BSSID [%s]", mac2str((SceNetEtherAddr *)adhocctl_event.leader_mac.mac).c_str()); - if (dropLateGroupReply) { - // The game mode it was for has timed out (we've already left the group again). - dropLateGroupReply = false; - INFO_LOG(Log::sceNet, "FriendFinder: Ignoring the group BSSID, game mode timed out before it came"); + if (abandonedGroupJoins > 0) { + abandonedGroupJoins--; + INFO_LOG(Log::sceNet, "FriendFinder: Ignoring the BSSID of an abandoned group join"); break; } + groupJoinInFlight = false; // Update Group BSSID memcpy(parameter.bssid.mac_addr.data, adhocctl_event.leader_mac.mac, 6); // This packet seems to contains Adhoc Group Creator's BSSID (similar to AP's BSSID) so it shouldn't get mixed up with local MAC address. Note: On JPCSP + prx files params.bssid is hardcoded to "Jpcsp\0" and doesn't match to any of player's mac @@ -1762,6 +1766,11 @@ void friendFinderPoll() { case ADHOCCTL_CLIENT_EVENT_CONNECT:{ u32_le ipaddr = adhocctl_event.connect.id; INFO_LOG(Log::sceNet, "FriendFinder: Incoming OPCODE_CONNECT [%s][%s][%s]", mac2str((SceNetEtherAddr *)adhocctl_event.connect.mac).c_str(), ip2str(*(in_addr*)&ipaddr).c_str(), adhocctl_event.connect.nickname); + // A player of an abandoned join's group, or of one we've left (the server didn't know yet). + if (abandonedGroupJoins > 0 || !NetAdhocctl_InServerGroup()) { + INFO_LOG(Log::sceNet, "FriendFinder: Ignoring a player of a group we're not joining"); + break; + } // Add User addFriend(adhocctl_event.connect); diff --git a/Core/HLE/proAdhoc.h b/Core/HLE/proAdhoc.h index 77e57b995a..f9ffe2c504 100644 --- a/Core/HLE/proAdhoc.h +++ b/Core/HLE/proAdhoc.h @@ -820,9 +820,16 @@ extern SceNetAdhocctlScanInfo * networks; extern u64 adhocctlStartTime; // When CreateEnterGameMode or JoinEnterGameMode was called, in emulated time: its timeout is a PSP-side one. extern u64 gameModeEnterTimeUs; -// Set when entering game mode timed out, until the next group join is sent: the server's answer to the -// timed-out join may still be on its way, and must not connect us to the group. -extern bool dropLateGroupReply; +// The server answers a group join with a CONNECT for each player already in the group, then the group's +// BSSID. A join the game has given up on (game mode timed out, or it disconnected) before the BSSID came +// is abandoned: what's left of its answer must not put us in the group. +extern bool groupJoinInFlight; +extern int abandonedGroupJoins; +// Gives up on the join being made, if any: one still queued isn't sent, and the answer to one already +// sent is dropped. +void AbandonGroupJoin(); +// Whether we've asked the server to put us in a group, and haven't left it since. +bool NetAdhocctl_InServerGroup(); extern std::atomic isAdhocctlNeedLogin; extern bool isAdhocctlBusy; extern int adhocctlState; diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 523976cbe1..eacd799935 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -626,7 +626,7 @@ static void __AdhocctlNotify(u64 userdata, int cyclesLate) { call_status = adhocctl_connect(adhocctlHandle, (char *)req.group.data); if (call_status == ADHOCCTL_CALL_SUCCESS) { adhocctlInServerGroup = true; - dropLateGroupReply = false; + groupJoinInFlight = true; } break; } @@ -866,6 +866,24 @@ static bool offAdhocNetwork() { return !adhocctlInServerGroup; } +bool NetAdhocctl_InServerGroup() { + return adhocctlInServerGroup; +} + +void AbandonGroupJoin() { + // A queued join completes like a login, sending nothing. (The requests are saved in savestates, so + // it keeps the format.) + for (auto &it : adhocctlRequests) { + if (it.second.opcode == OPCODE_CONNECT) { + it.second.opcode = OPCODE_LOGIN; + } + } + if (groupJoinInFlight) { + groupJoinInFlight = false; + abandonedGroupJoins++; + } +} + static bool isLocalMac(const SceNetEtherAddr *mac) { SceNetEtherAddr localMac; getLocalMac(&localMac); @@ -2272,8 +2290,7 @@ void __UpdateAdhocctlHandlers(u32 flag, u32 error) { } void NetAdhocctl_GameModeTimedOut() { - // If the server's BSSID came in time, there's nothing to drop, and the next join clears this. - dropLateGroupReply = true; + AbandonGroupJoin(); if (adhocctlInServerGroup) { const std::lock_guard adhocctl_guard(adhocctlMutex); if (adhocctlHandle != NULL) { @@ -3996,6 +4013,7 @@ static u32 NetAdhocctl_Disconnect(bool fromGameMode = false) { // or 650 ms after ExitGameMode (net/adhoc/pair/gamemodetiming). adhocctlRequestTimeUs = CoreTiming::GetGlobalTimeUs(); adhocctlDisconnectFromGameMode = fromGameMode; + AbandonGroupJoin(); // Connected State (Adhoc Mode). Attempting to leave a group while not in a group will be kicked out by Adhoc Server (ie. some games tries to disconnect more than once within a short time) if (adhocctlState != ADHOCCTL_STATE_DISCONNECTED || adhocctlInServerGroup) {