mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2025-10-11 00:08:50 -07:00
fix possible race condition in JoinRoom
This commit is contained in:
parent
6a34677ab2
commit
83e56f745d
@ -9,11 +9,12 @@ public class Client {
|
||||
|
||||
public int ClientID { get; private set; }
|
||||
public PlayerData PlayerData { get; set; } = new();
|
||||
public Room Room { get; set; }
|
||||
public Room Room { get; private set; }
|
||||
|
||||
private readonly Socket socket;
|
||||
SocketBuffer socketBuffer = new();
|
||||
private volatile bool scheduledDisconnect = false;
|
||||
private object ClientLock = new();
|
||||
|
||||
public Client(Socket clientSocket) {
|
||||
socket = clientSocket;
|
||||
@ -60,10 +61,12 @@ public class Client {
|
||||
}
|
||||
|
||||
public void JoinRoom(Room room) {
|
||||
LeaveRoom();
|
||||
InvalidatePlayerData();
|
||||
Room = room;
|
||||
Room.AddClient(this);
|
||||
lock(ClientLock) {
|
||||
LeaveRoom();
|
||||
PlayerData.IsValid = false;
|
||||
Room.AddClient(this);
|
||||
Room = room;
|
||||
}
|
||||
Send(Room.SubscribeRoom());
|
||||
UpdatePlayerUserVariables();
|
||||
}
|
||||
@ -79,10 +82,6 @@ public class Client {
|
||||
}
|
||||
}
|
||||
|
||||
public void InvalidatePlayerData() {
|
||||
PlayerData.IsValid = false;
|
||||
}
|
||||
|
||||
public void Disconnect() {
|
||||
try {
|
||||
socket.Shutdown(SocketShutdown.Both);
|
||||
|
Loading…
x
Reference in New Issue
Block a user