mirror of
https://github.com/SoDOff-Project/sodoff-mmo.git
synced 2025-10-11 00:08:50 -07:00
fix race condition issues - WorldEvent and others
This commit is contained in:
parent
c909d07462
commit
cf41c0175a
@ -3,16 +3,19 @@ using sodoffmmo.Data;
|
||||
|
||||
namespace sodoffmmo.Core;
|
||||
public class GauntletRoom : Room {
|
||||
static object NextRoomLock = new object();
|
||||
static GauntletRoom? NextRoom = null;
|
||||
|
||||
public static GauntletRoom Get() {
|
||||
if (NextRoom != null && NextRoom.ClientsCount == 1) {
|
||||
var ret = NextRoom!;
|
||||
NextRoom = null;
|
||||
return ret;
|
||||
} else {
|
||||
NextRoom = new GauntletRoom();
|
||||
return NextRoom!;
|
||||
lock(NextRoomLock) {
|
||||
if (NextRoom != null && NextRoom.ClientsCount == 1) {
|
||||
var ret = NextRoom!;
|
||||
NextRoom = null;
|
||||
return ret;
|
||||
} else {
|
||||
NextRoom = new GauntletRoom();
|
||||
return NextRoom!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,9 +71,11 @@ public class Room {
|
||||
public static Room Get(string name) => rooms[name];
|
||||
|
||||
public static Room GetOrAdd(string name) {
|
||||
if (!Room.Exists(name))
|
||||
return new Room(name);
|
||||
return rooms[name];
|
||||
lock(RoomsListLock) {
|
||||
if (!Room.Exists(name))
|
||||
return new Room(name);
|
||||
return rooms[name];
|
||||
}
|
||||
}
|
||||
|
||||
public static Room[] AllRooms() {
|
||||
|
@ -10,15 +10,17 @@ 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() {
|
||||
if (_instance == null) {
|
||||
_instance = new WorldEvent();
|
||||
lock(EventLock) {
|
||||
if (_instance == null) {
|
||||
_instance = new WorldEvent();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
private WorldEvent() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user