/// <summary> /// Set of admin dashboard status information pushed at regular intervals /// </summary> /// <returns>A admin status view</returns> public AdminView GetAdminStatus() { List<AdminGridView> gridViews = new List<AdminGridView>(); var grids = db.Grids.Where(g => g.GridState >= 4 & g.GridState <= 7); foreach (var g in grids) { var gv = new AdminGridView { GridId = g.GridId, GridName = g.GridName, GridGuid = g.GridGuid, GridState = g.GridState, PlayerCount = db.Players.Count(x => x.GridId == g.GridId & x.Connected & !x.IsAdmin), Round = g.Round, ReadyCount = db.Players.Count(x => x.GridId == g.GridId & x.Connected & !x.IsAdmin & x.IsReady), TimeoutCount = db.Players.Count(x => x.GridId == g.GridId & x.Connected & !x.IsAdmin & x.HasTimeout), MoveCount = db.Players.Count(x => x.GridId == g.GridId & x.Connected & !x.IsAdmin & x.RequestMove), TypeChangeCount = db.Players.Count(x => x.GridId == x.GridId & x.Connected & !x.IsAdmin & x.RequestTypeChange), Segreg = 0 }; gridViews.Add(gv); } var adminStatus = new AdminView { ServerTime = DateTime.Now.ToString("HH:mm:ss"), ConnectedCount = db.Players.Count(x => x.Connected & !x.IsBot & !x.IsAdmin), LobbyCount = db.Players.Count(x => x.GridId == 1 & x.Connected & !x.IsAdmin & !x.IsBot), WaitingCount = db.Players.Count(x => x.GridId == 2 & x.Connected & !x.IsAdmin & !x.IsBot), GridCount = db.Grids.Count(g => g.GridState > 1 & g.GridState < 8), PlayingCount = db.Players.Count(x => x.GridId > 2 & x.Connected & !x.IsAdmin & !x.IsBot), Grids = gridViews }; return adminStatus; }
/// <summary> /// Set of grid status information pushed at regular intervals /// </summary> /// <param name="gridId"></param> /// <returns></returns> public GridView GetGridViewStatus(int gridId) { var gv = new GridView(); var grid = db.Grids.FirstOrDefault(g => g.GridId == gridId); if (grid != null) { // Add list of cells List<CellView> cvList = new List<CellView>(); var cells = db.Cells.Where(c => c.GridId == gridId); foreach (var c in cells) { if (c.Player == null) { cvList.Add(new CellView { X = c.X, Y = c.Y, PlayerNr = 0, PlayerType = 0, IsBot = false }); } else { cvList.Add(new CellView { X = c.X, Y = c.Y, PlayerNr = c.Player.PlayerNr, PlayerType = c.Player.PlayerType, IsBot = c.Player.IsBot }); } } // Add list of players List<PlayerView> pvList = new List<PlayerView>(); var players = db.Players.Where(p => p.GridId == gridId).ToList(); foreach (var p in players) { //If grid is static, we remove disconnected players if(grid.IsStatic) { if (!p.IsAdmin & p.Connected) pvList.Add(new PlayerView(grid, p)); } else { if (!p.IsAdmin) pvList.Add(new PlayerView(grid, p)); } } // Add grid history List<AdminGridView> ghvList = new List<AdminGridView>(); var gridHistories = db.GridLogs.Where(g => g.GridId == gridId).OrderByDescending(g => g.Round); foreach (var g in gridHistories) { var gsv = new AdminGridView { GridId = g.GridId, //GridName = g.GridName, //GridGuid = g.GridGuid, GridState = g.GridState, Round = g.Round, MoveCount = g.GridStats.MoveCount, TypeChangeCount = g.GridStats.TypeChangeCount, TimeoutCount = g.GridStats.TimeoutCount, Segreg = Math.Round(g.GridStats.SegregAvg, 3) }; ghvList.Add(gsv); } // Add all grids List<AdminGridView> gsvList = new List<AdminGridView>(); var grids = db.Grids.Where(g => g.GridState >= 4 & g.GridState < 8); foreach (var g in grids) { var gsv = new AdminGridView { GridId = g.GridId, GridName = g.GridName, GridGuid = g.GridGuid, GridState = g.GridState, Round = g.Round, ReadyCount = db.Players.Count(x => x.GridId == g.GridId & x.Connected & !x.IsAdmin & x.IsReady), MoveCount = db.Players.Count(x => x.GridId == g.GridId & x.Connected & !x.IsAdmin & x.RequestMove), TypeChangeCount = db.Players.Count(x => x.GridId == x.GridId & x.Connected & !x.IsAdmin & x.RequestTypeChange), TimeoutCount = 0, Segreg = 0 }; gsvList.Add(gsv); } gv = new GridView { GridId = grid.GridId, GridGuid = grid.GridGuid, X = grid.SizeX, Y = grid.SizeY, Cells = cvList, Players = pvList, AllGrids = gsvList, GridHistory = ghvList }; } return gv; }