Ejemplo n.º 1
0
        public void SendInviteAnswer(InviteAnswer answer)
        {
            if (answer == null)
            {
                Clients.Caller.notify(new UserNotification("Error sending invite answer!", UserNotificationType.Red));
                return;
            }

            InviteStatus status = InviteManager.ValidateAnswer(answer);
            Invitation invitation = InviteManager.ExtractInvite(answer.InviteId);

            switch (status.StatusType)
            {
                case InviteStatusType.Invalid:
                case InviteStatusType.Valid:
                case InviteStatusType.Rejected:
                    Clients.Client(invitation.From.Id).notify(new UserNotification(status.Message, UserNotificationType.Red));
                    return;
                case InviteStatusType.Accepted:
                default:
                    //create the new game
                    Game game = GameManager.CreateGame(invitation);

                    if (game != null)
                    {
                        //lets subscribe to game stuff here
                        game.PlayerHasMovedPiece += OnPlayerHasMovedPiece;
                        game.ErrorOccurred += OnErrorOccured;
                        game.UpdateSummary += OnUpdateSummary;
                        game.WonGame += OnWonGame;

                        Player p1 = null;
                        Player p2 = null;
                        _lobby.TryRemove(game.Player1.Id, out p1);
                        _lobby.TryRemove(game.Player2.Id, out p2);

                        GetConnectedPlayers(p1.Nick, p2.Nick);

                        //start the game for the players.
                        Clients.Client(game.Player1.Id.ToString()).clientRenderBoard(GameManager.GetBoardMarkup(game.GameId, game.Player1.Id), game);
                        Clients.Client(game.Player2.Id.ToString()).clientRenderBoard(GameManager.GetBoardMarkup(game.GameId, game.Player2.Id), game);
                    }
                    else
                    {
                        Clients.Caller.notify(new UserNotification("Error occurred when sending game invitation answer.", UserNotificationType.Red));
                    }
                    break;
            }
        }
Ejemplo n.º 2
0
 public AnswerInviteRequest(Guid playerId, InviteAnswer answer) : base("answer_invite")
 {
     PlayerId = playerId;
     Answer   = answer;
 }