public void RemovePlayer(PlayerState state) { otherPlayersRWLock.EnterWriteLock(); try { OtherPlayers.Remove(state); } catch (Exception) { throw; } finally { otherPlayersRWLock.ExitWriteLock(); } }
public List<PlayerState> GetPlayerList(PlayerState exclude = null) { List<PlayerState> list = new List<PlayerState>(PlayerCount); if (Master != null && Master != exclude) list.Add(Master); otherPlayersRWLock.EnterReadLock(); try { foreach (PlayerState s in OtherPlayers) if (s != exclude) list.Add(s); } catch (Exception) { throw; } finally { otherPlayersRWLock.ExitReadLock(); } return list; }
public bool AddPlayer(PlayerState state) { otherPlayersRWLock.EnterWriteLock(); try { if (OtherPlayers.Count < _maxOtherPlayers) { OtherPlayers.Add(state); return true; } else { return false; } } catch (Exception) { throw; } finally { otherPlayersRWLock.ExitWriteLock(); } }
public void ForEach(ForEachPlayerAction action, PlayerState skip = null) { if (Master != null && Master != skip) action(Master); otherPlayersRWLock.EnterReadLock(); try { foreach (PlayerState s in OtherPlayers) if (s != skip) action(s); } catch (Exception) { throw; } finally { otherPlayersRWLock.ExitReadLock(); } }
public Room(PlayerState master = null) { if (master != null) { this._master = master; master.CurrentRoom = this; } }