mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
Fix split-screen join failing when connecting to a remote host via UI
When a non-host client connected to a remote server through the in-game
UI (as opposed to the -ip/-port command line flags), the global variables
g_Win64MultiplayerIP and g_Win64MultiplayerPort were never updated from
their defaults ("127.0.0.1" and the default port). JoinSplitScreen()
relies on these globals to open a second TCP connection for the local
split-screen pad, so it would always attempt to connect to localhost,
failing immediately on any remote session.
Fix: update g_Win64MultiplayerIP and g_Win64MultiplayerPort inside
JoinGame() once the primary connection is established. This ensures
subsequent JoinSplitScreen() calls always reach the correct host
regardless of how the session was joined.
Additionally, guard PushFreeSmallId() against recycling smallIds in the
range [0, XUSER_MAX_COUNT), which are permanently reserved for the
host's local controller slots. Previously, if a host-side local pad
disconnected its smallId could re-enter the free pool and be handed
to an incoming remote client, causing that client's IQNetPlayer slot
to collide with a local pad slot on the non-host machine.
This commit is contained in:
parent
0c4f459904
commit
93f2d7335d
|
|
@ -392,6 +392,11 @@ bool WinsockNetLayer::JoinGame(const char* ip, int port)
|
||||||
}
|
}
|
||||||
s_localSmallId = assignedSmallId;
|
s_localSmallId = assignedSmallId;
|
||||||
|
|
||||||
|
// Save the host IP and port so JoinSplitScreen can connect to the same host
|
||||||
|
// regardless of how the connection was initiated (UI vs command line).
|
||||||
|
strncpy_s(g_Win64MultiplayerIP, sizeof(g_Win64MultiplayerIP), ip, _TRUNCATE);
|
||||||
|
g_Win64MultiplayerPort = port;
|
||||||
|
|
||||||
app.DebugPrintf("Win64 LAN: Connected to %s:%d, assigned smallId=%d\n", ip, port, s_localSmallId);
|
app.DebugPrintf("Win64 LAN: Connected to %s:%d, assigned smallId=%d\n", ip, port, s_localSmallId);
|
||||||
|
|
||||||
s_active = true;
|
s_active = true;
|
||||||
|
|
@ -733,6 +738,11 @@ bool WinsockNetLayer::PopDisconnectedSmallId(BYTE* outSmallId)
|
||||||
|
|
||||||
void WinsockNetLayer::PushFreeSmallId(BYTE smallId)
|
void WinsockNetLayer::PushFreeSmallId(BYTE smallId)
|
||||||
{
|
{
|
||||||
|
// SmallIds 0..(XUSER_MAX_COUNT-1) are permanently reserved for the host's
|
||||||
|
// local pads and must never be recycled to remote clients.
|
||||||
|
if (smallId < (BYTE)XUSER_MAX_COUNT)
|
||||||
|
return;
|
||||||
|
|
||||||
EnterCriticalSection(&s_freeSmallIdLock);
|
EnterCriticalSection(&s_freeSmallIdLock);
|
||||||
// Guard against double-recycle: the reconnect path (queueSmallIdForRecycle) and
|
// Guard against double-recycle: the reconnect path (queueSmallIdForRecycle) and
|
||||||
// the DoWork disconnect path can both push the same smallId. If we allow duplicates,
|
// the DoWork disconnect path can both push the same smallId. If we allow duplicates,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue