private void ResetStatistics() { // Delete previous stats _gameStatistics.Clear(); // Create GameStatisticsByPlayer for each player foreach (IPlayer player in _playerManager.Players) { // Init stats GameStatisticsByPlayer stats = new GameStatisticsByPlayer { PlayerName = player.Name, SpecialsUsed = new Dictionary <Specials, Dictionary <string, int> >() }; foreach (SpecialOccurancy occurancy in Options.SpecialOccurancies.Where(x => x.Occurancy > 0)) { Dictionary <string, int> specialsByPlayer = _playerManager.Players.Select(p => p.Name).ToDictionary(x => x, x => 0); stats.SpecialsUsed.Add(occurancy.Value, specialsByPlayer); } // Add stats _gameStatistics.Add(player.Name, stats); } }
private void InitializeFromSelectedPlayer() { // From selected player GameStatisticsByPlayer byPlayer = SelectedGameStatistics.Players.FirstOrDefault(x => x.PlayerName == SelectedPlayer); if (byPlayer?.SpecialsUsed == null) { SpecialsFromSelectedPlayerGrid = null; } else { List <DynamicColumn> columns = byPlayer.SpecialsUsed.SelectMany(kv => kv.Value).Select(x => x.Key).Distinct().Select(x => new DynamicColumn { Name = x, DisplayName = x, Type = typeof(string), IsReadOnly = true, }).ToList(); List <SpecialStatisticsRow> rows = new List <SpecialStatisticsRow>(); foreach (KeyValuePair <Specials, Dictionary <string, int> > specials in byPlayer.SpecialsUsed.OrderBy(kv => kv.Key)) { SpecialStatisticsRow row = new SpecialStatisticsRow { Special = specials.Key }; foreach (DynamicColumn column in columns) { KeyValuePair <string, int> kv = specials.Value.FirstOrDefault(x => x.Key == column.Name); int value = kv.Equals(default(KeyValuePair <string, int>)) ? 0 : kv.Value; row.TryAddProperty(column.Name, value); } rows.Add(row); } SpecialsFromSelectedPlayerGrid = new DynamicGrid <SpecialStatisticsRow, DynamicColumn>(rows, columns); } }
static void Main(string[] args) { Log.Default.Initialize(ConfigurationManager.AppSettings["logpath"], "server.log"); Version version = Assembly.GetEntryAssembly().GetName().Version; string company = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute), false)).Company; string product = ((AssemblyProductAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyProductAttribute), false)).Product; Log.Default.WriteLine(LogLevels.Info, "{0} {1}.{2} by {3}", product, version.Major, version.Minor, company); // IFactory factory = new Factory(); // IBanManager banManager = factory.CreateBanManager(); // IPlayerManager playerManager = factory.CreatePlayerManager(6); ISpectatorManager spectatorManager = factory.CreateSpectatorManager(10); // IHost wcfHost = new Server.WCFHost.WCFHost( playerManager, spectatorManager, banManager, factory) { Port = ConfigurationManager.AppSettings["port"] }; // IHost builtInHost = new BuiltInHostBase( playerManager, spectatorManager, banManager, factory); IHost socketHost = new TCPHostBase(playerManager, spectatorManager, banManager, factory) { Port = 5656 }; // List <DummyBuiltInClient> clients = new List <DummyBuiltInClient> { //new DummyBuiltInClient("BuiltIn-Joel" + Guid.NewGuid().ToString().Substring(0, 5), () => builtInHost), //new DummyBuiltInClient("BuiltIn-Celine" + Guid.NewGuid().ToString().Substring(0, 5), () => builtInHost) }; // IActionQueue actionQueue = factory.CreateActionQueue(); // IPieceProvider pieceProvider = factory.CreatePieceProvider(); // IServer server = new Server.Server(playerManager, spectatorManager, pieceProvider, actionQueue); server.AddHost(wcfHost); server.AddHost(builtInHost); server.AddHost(socketHost); // try { server.StartServer(); } catch (Exception ex) { Log.Default.WriteLine(LogLevels.Error, "Cannot start server. Exception: {0}", ex); return; } DisplayHelp(); bool stopped = false; while (!stopped) { if (Console.KeyAvailable) { ConsoleKeyInfo cki = Console.ReadKey(true); switch (cki.Key) { default: DisplayHelp(); break; case ConsoleKey.X: server.StopServer(); stopped = true; break; case ConsoleKey.S: server.StartGame(); break; case ConsoleKey.T: server.StopGame(); break; case ConsoleKey.P: server.PauseGame(); break; case ConsoleKey.R: server.ResumeGame(); break; case ConsoleKey.Add: clients.Add(new DummyBuiltInClient("BuiltIn-" + Guid.NewGuid().ToString().Substring(0, 5), () => builtInHost)); break; case ConsoleKey.Subtract: { DummyBuiltInClient client = clients.LastOrDefault(); if (client != null) { client.DisconnectFromServer(); clients.Remove(client); } break; } case ConsoleKey.L: { DummyBuiltInClient client = clients.LastOrDefault(); client?.Lose(); break; } case ConsoleKey.D: Console.WriteLine("Players:"); foreach (IPlayer p in playerManager.Players) { Console.WriteLine("{0}) {1} [{2}] {3} {4} {5:HH:mm:ss.fff} {6:HH:mm:ss.fff}", p.Id, p.Name, p.Team, p.State, p.PieceIndex, p.LastActionFromClient, p.LastActionToClient); } Console.WriteLine("Spectators:"); foreach (ISpectator s in spectatorManager.Spectators) { Console.WriteLine("{0}) {1} {2:HH:mm:ss.fff} {3:HH:mm:ss.fff}", s.Id, s.Name, s.LastActionFromClient, s.LastActionToClient); } break; case ConsoleKey.W: foreach (WinEntry e in server.WinList) { Console.WriteLine("{0}[{1}]: {2} pts", e.PlayerName, e.Team, e.Score); } break; case ConsoleKey.Q: server.ResetWinList(); break; case ConsoleKey.O: { GameOptions options = server.Options; foreach (PieceOccurancy occurancy in options.PieceOccurancies) { Console.WriteLine("{0}:{1}", occurancy.Value, occurancy.Occurancy); } foreach (SpecialOccurancy occurancy in options.SpecialOccurancies) { Console.WriteLine("{0}:{1}", occurancy.Value, occurancy.Occurancy); } } break; case ConsoleKey.I: { foreach (KeyValuePair <string, GameStatisticsByPlayer> byPlayer in server.GameStatistics) { GameStatisticsByPlayer stats = byPlayer.Value; string playerName = byPlayer.Key; Console.WriteLine("{0}) {1} : 1:{2} 2:{3} 3:{4} 4:{5}", byPlayer.Key, playerName, stats.SingleCount, stats.DoubleCount, stats.TripleCount, stats.TetrisCount); foreach (KeyValuePair <Specials, Dictionary <string, int> > bySpecial in stats.SpecialsUsed) { Console.WriteLine("Special {0}", bySpecial.Key); foreach (KeyValuePair <string, int> kv in bySpecial.Value) { string otherName = kv.Key; Console.WriteLine("\t{0}:{1}", otherName, kv.Value); } } } break; } } } else { System.Threading.Thread.Sleep(100); Parallel.ForEach( clients, client => client.Test()); } } }