void SendServerStatusToAllLoginPlayersLoop(object o) { StringBuilder sb = new StringBuilder(); ForEachPlayerAction PrintStateAction = new ForEachPlayerAction( delegate(PlayerState p) { Console.WriteLine(p.Name); }); while (EngineIsActice) { sb.Append(Protocol1Constants.COMMAND_SERVER_STATUS); sb.AppendFormat(" {0} {1} {2} {3}", PlayersByName.Count, MaxPlayers, PlayRooms.Count, MaxRooms); string message = sb.ToString(); lock (PlayersByName) try { foreach (KeyValuePair <string, PlayerState> p in PlayersByName) { p.Value.Connection.Send(message); } } catch (Exception) { continue; } sb.Clear(); Thread.Sleep(2000); //Console.WriteLine("[Lobby]"); //Lobby.ForEach(PrintStateAction); //lock (PlayRooms) // foreach (KeyValuePair<string, Room> p in PlayRooms) // { // Console.WriteLine("[{0}]", p.Key); // p.Value.ForEach(PrintStateAction); // } //lock (PlayersByMacAddress) // foreach (KeyValuePair<string, PlayerState> p in PlayersByMacAddress) // Console.WriteLine("Mac: [{0}] => {1}", p.Key, p.Value); } }
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 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(); } }