mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2025-10-11 08:18:49 -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 int ClientID { get; private set; }
|
||||||
public PlayerData PlayerData { get; set; } = new();
|
public PlayerData PlayerData { get; set; } = new();
|
||||||
public Room Room { get; set; }
|
public Room Room { get; private set; }
|
||||||
|
|
||||||
private readonly Socket socket;
|
private readonly Socket socket;
|
||||||
SocketBuffer socketBuffer = new();
|
SocketBuffer socketBuffer = new();
|
||||||
private volatile bool scheduledDisconnect = false;
|
private volatile bool scheduledDisconnect = false;
|
||||||
|
private object ClientLock = new();
|
||||||
|
|
||||||
public Client(Socket clientSocket) {
|
public Client(Socket clientSocket) {
|
||||||
socket = clientSocket;
|
socket = clientSocket;
|
||||||
@ -60,10 +61,12 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void JoinRoom(Room room) {
|
public void JoinRoom(Room room) {
|
||||||
LeaveRoom();
|
lock(ClientLock) {
|
||||||
InvalidatePlayerData();
|
LeaveRoom();
|
||||||
Room = room;
|
PlayerData.IsValid = false;
|
||||||
Room.AddClient(this);
|
Room.AddClient(this);
|
||||||
|
Room = room;
|
||||||
|
}
|
||||||
Send(Room.SubscribeRoom());
|
Send(Room.SubscribeRoom());
|
||||||
UpdatePlayerUserVariables();
|
UpdatePlayerUserVariables();
|
||||||
}
|
}
|
||||||
@ -79,10 +82,6 @@ public class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InvalidatePlayerData() {
|
|
||||||
PlayerData.IsValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Disconnect() {
|
public void Disconnect() {
|
||||||
try {
|
try {
|
||||||
socket.Shutdown(SocketShutdown.Both);
|
socket.Shutdown(SocketShutdown.Both);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user