mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2025-10-11 08:18:49 -07:00
fix race condition issues - WorldEvent and others
This commit is contained in:
parent
c909d07462
commit
cf41c0175a
@ -3,9 +3,11 @@ using sodoffmmo.Data;
|
||||
|
||||
namespace sodoffmmo.Core;
|
||||
public class GauntletRoom : Room {
|
||||
static object NextRoomLock = new object();
|
||||
static GauntletRoom? NextRoom = null;
|
||||
|
||||
public static GauntletRoom Get() {
|
||||
lock(NextRoomLock) {
|
||||
if (NextRoom != null && NextRoom.ClientsCount == 1) {
|
||||
var ret = NextRoom!;
|
||||
NextRoom = null;
|
||||
@ -15,6 +17,7 @@ public class GauntletRoom : Room {
|
||||
return NextRoom!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GauntletRoom() : base (null, "GauntletDO", true) {
|
||||
base.RoomVariables.Add(NetworkArray.VlElement("IS_RACE_ROOM", true));
|
||||
|
@ -4,6 +4,7 @@ using sodoffmmo.Data;
|
||||
namespace sodoffmmo.Core;
|
||||
public class Room {
|
||||
public static int MaxId { get; private set; } = 2;
|
||||
static object RoomsListLock = new object();
|
||||
protected static Dictionary<string, Room> rooms = new();
|
||||
|
||||
List<Client> clients = new();
|
||||
@ -70,10 +71,12 @@ public class Room {
|
||||
public static Room Get(string name) => rooms[name];
|
||||
|
||||
public static Room GetOrAdd(string name) {
|
||||
lock(RoomsListLock) {
|
||||
if (!Room.Exists(name))
|
||||
return new Room(name);
|
||||
return rooms[name];
|
||||
}
|
||||
}
|
||||
|
||||
public static Room[] AllRooms() {
|
||||
return rooms.Values.ToArray();
|
||||
|
@ -10,16 +10,18 @@ class WorldEvent {
|
||||
NotActive
|
||||
}
|
||||
private static WorldEvent? _instance = null;
|
||||
private object EventLock = new object();
|
||||
private static object EventLock = new object();
|
||||
private Random random = new Random();
|
||||
private System.Timers.Timer? timer = null;
|
||||
|
||||
public static WorldEvent Get() {
|
||||
lock(EventLock) {
|
||||
if (_instance == null) {
|
||||
_instance = new WorldEvent();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private WorldEvent() {
|
||||
startTime = DateTime.UtcNow.AddMinutes(-60);
|
||||
|
Loading…
x
Reference in New Issue
Block a user