/// <summary> /// Broadcasts an error message to the client who caused the error /// </summary> /// <param name="errorMessage">Details of the error</param> /// <param name="context">The user's connection context</param> public void SendError(string errorMessage) { Response response = new Response(ResponseType.ERROR, errorMessage); SendTo(response); }
/// <summary> /// This function sends a response to the Player context /// </summary> /// <param name="json">Takes in a JSON string</param> public void SendTo(Response response) { Send(response.ToJSON()); }
public void Logout() { bool success = false; try { GameQueue.GetInstance().removePlayer(OnlinePlayers.GetInstance().gameList[this]); Player trash; success = OnlinePlayers.GetInstance().gameList.TryRemove(this, out trash); if (success) { Response response = new Response(ResponseType.DISCONNECTED, "You are now logged out!"); SendTo(response); Console.WriteLine("> Client authenticated: " + Context.UserEndPoint); Console.WriteLine("> Online players: " + OnlinePlayers.GetInstance().gameList.Count()); } } catch (Exception exception) // Bad JSON! For shame. { var response = new Response(ResponseType.ERROR, exception.Message); SendTo(response); } }
public void SendDebug(string message) { Response response = new Response(ResponseType.DEBUG, message); Send(response.ToJSON()); }
public void HeartBeat() { string d = this.payload.heartbeat; Response response = new Response(ResponseType.HEARTBEAT_REPLY, JsonConvert.DeserializeObject("{first:" + this.payload.heartbeat + ", last:" + this.payload.last + "}")); SendTo(response); }
/// <summary> /// Sends a message to all clients in this room /// </summary> /// <param name="response"></param> public void Broadcast(Response response) { foreach (ChatPlayer client in clients) { if (client.chatContext == null) continue; client.chatContext.SendTo(response); } }
public void Request_UseCard(Player player) { int slot = player.gameContext.data.Payload.slotId; // This is the slot which is the cards destination int card = player.gameContext.data.Payload.cid; // This is the card which the player has on hand GamePlayer requestPlayer = player.gPlayer; // If opposite players turn if (!requestPlayer.IsPlayerTurn()) { // Screen warning requestPlayer.playerContext.SendTo(new Response(GameService.GameResponseType.GAME_NOT_YOUR_TURN, new Dictionary<string, object> { {"card",card}, {"error","Not your turn!"} })); // Fire releaseCard (to recall the card to origin pos) this.Request_OpponentReleaseCard(player); Console.WriteLine(">[GAME] Not your turn!"); return; } // If cardslot is not empty else if (requestPlayer.boardCards.ContainsKey(slot)) { JObject retObj = new JObject( new JProperty("cid", card) ); //requestPlayer.playerContext.SendTo(new Response(GameService.GameResponseType.GAME_USECARD_OCCUPIED, retObj)); this.Request_OpponentReleaseCard(player); requestPlayer.playerContext.SendTo( new Response(GameService.GameResponseType.GAME_USECARD_OCCUPIED, new JObject( new JProperty("slot", slot), new JProperty("message", "Slot is already occupied!") ))); Console.WriteLine(">[GAME] Slot occupied!"); return; } // Not enough mana to use card else if (!requestPlayer.HasEnoughMana(card)) { requestPlayer.playerContext.SendTo(new Response(GameService.GameResponseType.GAME_USECARD_OOM, "Not enough mana!")); Console.WriteLine(">[GAME] Not enough mana!"); return; } else { // Move a card to the board Card c; requestPlayer.handCards.TryGetValue(card, out c); requestPlayer.handCards.Remove(card); requestPlayer.boardCards.Add(slot, c); // Set the slotId to the card c.slotId = slot; //Next turn requestPlayer.gameRoom.NextTurn(); // Send Reply Response response = new Response(GameService.GameResponseType.GAME_USECARD_PLAYER_OK, new Dictionary<string, int> { {"cid",card}, {"slotId",slot} }); requestPlayer.playerContext.SendTo(response); response.Type = GameService.GameResponseType.GAME_USECARD_OPPONENT_OK; requestPlayer.GetOpponent().playerContext.SendTo(response); Console.WriteLine(">[GAME] Sent!"); } }
public void Request_OpponentReleaseCard(Player player) { GamePlayer requestPlayer = player.gPlayer; JObject retData = new JObject( new JProperty("cid", player.gameContext.data.Payload.cid)); Response response = new Response( GameService.GameResponseType.GAME_PLAYER_RELEASE, retData ); requestPlayer.playerContext.SendTo(response); response.Type = GameService.GameResponseType.GAME_OPPONENT_RELEASE; requestPlayer.GetOpponent().playerContext.SendTo(response); }
public void Request_MoveCard(Player player) { GamePlayer requestPlayer = player.gPlayer; JObject retData = new JObject( new JProperty("cid", player.gameContext.data.Payload.cid), new JProperty("x", player.gameContext.data.Payload.x), new JProperty("y", player.gameContext.data.Payload.y) ); Response response = new Response( GameService.GameResponseType.GAME_OPPONENT_MOVE, retData ); requestPlayer.GetOpponent().playerContext.SendTo(response); }