using BOTWM.Server.DTO; namespace BOTWM.Server.ServerClasses { public class Names { public Mutex NMutex = new Mutex(); public Dictionary PlayerNames; public List> Queue; public Names(int playerLimit) { PlayerNames = new Dictionary(); Queue = new List>(); for (int i = 0; i < playerLimit; i++) Queue.Add(new Dictionary()); } public void AddName(byte playerNumber, string name) { NMutex.WaitOne(100); PlayerNames[playerNumber] = name; for(int i = 0; i < Queue.Count; i++) Queue[i][playerNumber] = name; NMutex.ReleaseMutex(); } public void RemoveName(byte playerNumber) { NMutex.WaitOne(100); PlayerNames.Remove(playerNumber); for (int i = 0; i < Queue.Count; i++) Queue[i].Remove(playerNumber); NMutex.ReleaseMutex(); } public void FillQueue(int playerNumber) { NMutex.WaitOne(100); foreach (KeyValuePair kvp in PlayerNames) Queue[playerNumber][kvp.Key] = kvp.Value; NMutex.ReleaseMutex(); } public Dictionary GetQueue(int playerNumber) { Dictionary Data = new Dictionary(); NMutex.WaitOne(100); foreach (KeyValuePair kvp in Queue[playerNumber]) Data.Add(kvp.Key, kvp.Value); Queue[playerNumber].Clear(); NMutex.ReleaseMutex(); return Data; } public NamesDTO GetAllPlayers() { NMutex.WaitOne(100); var result = new NamesDTO() { Names = this.PlayerNames }; NMutex.ReleaseMutex(); return result; } } }