forked from SoDOff-Project/sodoff-mmo
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");
|
client.PlayerData.Fp = suvData.Get<string>("FP");
|
||||||
|
|
||||||
Console.WriteLine($"SUV {client.Room.Name} IID: {client.ClientID}");
|
Console.WriteLine($"SUV {client.Room.Name} IID: {client.ClientID}");
|
||||||
client.Room.AddClient(client);
|
|
||||||
UpdatePlayersInRoom();
|
UpdatePlayersInRoom();
|
||||||
SendSUVToPlayerInRoom();
|
SendSUVToPlayerInRoom();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public class Client {
|
|||||||
LeaveRoom();
|
LeaveRoom();
|
||||||
InvalidatePlayerData();
|
InvalidatePlayerData();
|
||||||
Room = room;
|
Room = room;
|
||||||
Send(Room.RespondJoinRoom());
|
Room.AddClient(this);
|
||||||
Send(Room.SubscribeRoom());
|
Send(Room.SubscribeRoom());
|
||||||
UpdatePlayerUserVariables();
|
UpdatePlayerUserVariables();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ public class Room {
|
|||||||
static Dictionary<string, Room> rooms = new();
|
static Dictionary<string, Room> rooms = new();
|
||||||
|
|
||||||
List<Client> clients = new();
|
List<Client> clients = new();
|
||||||
public object roomLock = new object();
|
protected object roomLock = new object();
|
||||||
|
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
@ -38,6 +38,9 @@ public class Room {
|
|||||||
|
|
||||||
public void AddClient(Client client) {
|
public void AddClient(Client client) {
|
||||||
lock (roomLock) {
|
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);
|
clients.Add(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user