sceNetAdhoc: Don't let an abandoned group join put us in the group

When the game gives up on a join (game mode timed out, or it
disconnected), a join still queued isn't sent anymore, and the rest of
the server's answer to one already sent is dropped: its players, and the
BSSID that came last and connected us. Players joining a group we've
just left (before the server knew) are dropped too, instead of staying
in our peer list.

Replaces the previous fix, which only dropped a late BSSID: on Windows
the join itself was still queued when game mode timed out in
net/adhoc/gamemode, and went out after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-10-30 11:53:44 +01:00
1 parent 9d8ef5e8f5
commit a0669ffbe4
3 files changed
+45 -11

No files matched your search

+14 -5
View File
@@ -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<bool> isAdhocctlNeedLogin = false;
bool isAdhocctlBusy = false;
int adhocctlState = ADHOCCTL_STATE_DISCONNECTED;
@@ -1377,6 +1378,9 @@ void killAdhocctlClient(bool due_to_error, const std::lock_guard<std::mutex> &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);
+10 -3
View File
@@ -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<bool> isAdhocctlNeedLogin;
extern bool isAdhocctlBusy;
extern int adhocctlState;
+21 -3
View File
@@ -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<std::mutex> 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) {