mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2025-10-11 08:18:49 -07:00
RespondJoinRoom in AddClient as atomic operation
to avoid missed player in rooms due to joining race condition
This commit is contained in:
parent
fb2596d3be
commit
bfbd9adb82
@ -47,7 +47,7 @@ class SetUserVariablesHandler : ICommandHandler {
|
||||
client.PlayerData.Fp = suvData.Get<string>("FP");
|
||||
|
||||
Console.WriteLine($"SUV {client.Room.Name} IID: {client.ClientID}");
|
||||
client.Room.AddClient(client);
|
||||
|
||||
UpdatePlayersInRoom();
|
||||
SendSUVToPlayerInRoom();
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class Client {
|
||||
LeaveRoom();
|
||||
InvalidatePlayerData();
|
||||
Room = room;
|
||||
Send(Room.RespondJoinRoom());
|
||||
Room.AddClient(this);
|
||||
Send(Room.SubscribeRoom());
|
||||
UpdatePlayerUserVariables();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ public class Room {
|
||||
static Dictionary<string, Room> rooms = new();
|
||||
|
||||
List<Client> clients = new();
|
||||
public object roomLock = new object();
|
||||
protected object roomLock = new object();
|
||||
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
@ -38,6 +38,9 @@ public class Room {
|
||||
|
||||
public void AddClient(Client client) {
|
||||
lock (roomLock) {
|
||||
client.Send(RespondJoinRoom());
|
||||
// NOTE: send RespondJoinRoom() and add client to clients as atomic operation
|
||||
// to make sure to client get full list of players in room
|
||||
clients.Add(client);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user