/// <summary> /// Proxy function that causes a game update on every connected screen /// </summary> /// <returns></returns> public async Task Update() { ServerGameSession game = MvcApplication.Manager.FindSessionByClientConnectionId(Context.ConnectionId); if (game != null) { await game.UpdateAll(); } else { await Clients.Caller.endSession("unkown game id was passed to the server."); } }
/// <summary> /// Proxy funtion that causes an update on all connected screens. /// </summary> /// <returns></returns> public async Task Update() { ServerGameSession game = MvcApplication.Manager.FindSessionByConnectionId(Context.ConnectionId); if (game != null) { await game.UpdateAll(); PlayerObject pObject = game.game.Players.FirstOrDefault(n => n.id == game.game.CurrentPlayer); await game.UpdateCurrentPlayingName(pObject); } else { Clients.Caller.endSession("unkown game id was passed to the server."); } }
/// <summary> /// Proxy function that connects this client with a Game host /// </summary> /// <param name="hostId">id of the host</param> /// <param name="clientId">id of the current client (not connection id)</param> /// <param name="playername">the name provided by the client.</param> /// <returns></returns> public async Task SubscribeToHost(string hostId, string clientId, string playername) { string connId = Context.ConnectionId; //find the session in memory ServerGameSession game = MvcApplication.Manager.FindSession(hostId); if (game != null) { //check if game is at max players if (game.game.Players.Where(n => n.connid != "").Count() < game.MaxClients) { if (game.game.Players.First(n => n.id == clientId).connid != "") { //game slot is in use await Clients.Caller.endSession("This place has already been taken by another player."); } else { lock (PlayerSelectionLock) { PlayerObject p = game.game.Players.First(n => n.id == clientId); p.connid = connId; p.name = playername; } await game.UpdateAll(); } } else { await Clients.Caller.endSession("This game is already at its max players."); } } else { await Clients.Caller.endSession("This game does not exist"); } }
/// <summary> /// Proxy and local function that syncs the JS and C# backend with eachother. /// </summary> /// <param name="game"></param> /// <returns></returns> public async Task PushGame(UnoGame game) { ServerGameSession sGame = MvcApplication.Manager.FindSessionByConnectionId(Context.ConnectionId); if (sGame != null) { if (sGame.game.FullDeck.Count == 0 || sGame.game.CurrentPlayer == null) { //new game, select first player from list. sGame.game = game; sGame.game.CurrentPlayer = sGame.game.Players[0].id; } else { sGame.game = game; } await sGame.UpdateAll(); } else { await Clients.Caller.endSession("unkown game id was passed to the server."); } }