public void PlayerDisconnect(IPlayer player) { Player hanabiPlayer = player as Player; if (hanabiPlayer == null) { return; } if (hanabiPlayer.Room != null) { RequestQuitRoom request = new RequestQuitRoom(); request.RoomIndex = hanabiPlayer.Room.RoomIndex.Index; PlayerQuitRoom(hanabiPlayer, request); } if (player.GameStatus != PlayerGameStatus.Idle) { RequestExitGame request = new RequestExitGame(); request.Nickname = player.Nickname.Value; PlayerExitGame(hanabiPlayer, request); } Players.Remove(player.Nickname); }
private void PlayerExit(Game game, IHanabiPlayer player, NicknameType nickname) { RequestExitGame request = new RequestExitGame(); request.Nickname = nickname.nickname; Command command = new Command(); command.action = ActionType.ExitGame.ToString(); command.payload = JsonConvert.SerializeObject(request); game.DispatchRequest(player, JsonConvert.SerializeObject(command)); }
private void PlayerExitGame(IHanabiPlayer player, RequestExitGame request) { ExitGameResult result = ExitGameResult.Success; if (Players.ContainsKey(player.Nickname)) { player.OnExitGame(); result = ExitGameResult.Success; } ResponseExitGame response = new ResponseExitGame(result); SendCommand(player, ActionType.ExitGame, response); }
public void DispatchRequest(IPlayer player, string message) { IHanabiPlayer hanabiPlayer = player as IHanabiPlayer; if (hanabiPlayer == null) { return; } Command command = JsonConvert.DeserializeObject <Command>(message); ActionType action = ( ActionType )Enum.Parse(typeof(ActionType), command.Action, false); switch (action) { case ActionType.EnterGame: { RequestEnterGame request = JsonConvert.DeserializeObject <RequestEnterGame>(command.Payload); PlayerEnterGame(hanabiPlayer, request); break; } case ActionType.ExitGame: { RequestExitGame request = JsonConvert.DeserializeObject <RequestExitGame>(command.Payload); PlayerExitGame(hanabiPlayer, request); break; } case ActionType.GetRoomList: { PlayerGetRoomList(hanabiPlayer); break; } case ActionType.JoinRoom: { RequestJoinRoom request = JsonConvert.DeserializeObject <RequestJoinRoom>(command.Payload); PlayerJoinRoom(hanabiPlayer, request); break; } case ActionType.QuitRoom: { RequestQuitRoom request = JsonConvert.DeserializeObject <RequestQuitRoom>(command.Payload); PlayerQuitRoom(hanabiPlayer, request); break; } case ActionType.Message: { // TODO: break; } case ActionType.Ready: { PlayerReady(hanabiPlayer); break; } case ActionType.PromptCard: { RequestPromptCard request = JsonConvert.DeserializeObject <RequestPromptCard>(command.Payload); PlayerPrompt(hanabiPlayer, request); break; } case ActionType.PlayCard: { RequestPlayCard request = JsonConvert.DeserializeObject <RequestPlayCard>(command.Payload); PlayerPlayCard(hanabiPlayer, request); break; } case ActionType.DiscardCard: { RequestDiscardCard request = JsonConvert.DeserializeObject <RequestDiscardCard>(command.Payload); PlayerDiscardCard(hanabiPlayer, request); break; } default: break; } }