예제 #1
0
        public void InvitePlayer(InvitationMessage message)
        {
            try
            {
                if (!ConnectedPlayers[message.ReceiverNick].Client.AcceptInvitation(message))
                {
                    return;
                }

                message.GameId    = _internalGameId++;
                message.GameCards = GenerateGameCards(message.GameSize);

                ConnectedPlayers[message.SenderNick].Client.ReceiveGame(message, true);
                ConnectedPlayers[message.ReceiverNick].Client.ReceiveGame(message, false);

                AllGames.Add(message.GameId, CreateGame(message));

                ConnectedPlayers[message.SenderNick].IsPlaying = true;
                SendMessageToAll(new TextMessage {
                    SenderNick = message.SenderNick, Type = MessageType.PlayerStartedMessage
                });
                ConnectedPlayers[message.ReceiverNick].IsPlaying = true;
                SendMessageToAll(new TextMessage {
                    SenderNick = message.ReceiverNick, Type = MessageType.PlayerStartedMessage
                });
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }
        }
예제 #2
0
        private bool OnAcceptInvitationMessage(InvitationMessage message)
        {
            IsEnabled = false;
            var result = MessageBox.Show(
                $"{message.SenderNick} has sent you an invitation to new game of size {message.GameSize.Text()}.",
                $"Invitation from {message.SenderNick} to {message.ReceiverNick}",
                MessageBoxButton.OKCancel, MessageBoxImage.Question) ==
                         MessageBoxResult.OK;

            IsEnabled = true;
            return(result);
        }
예제 #3
0
        private void InitGameBoard(InvitationMessage message)
        {
            Board = new GridCard[message.GameSize.Height(), message.GameSize.Width()];

            var index = 0;

            for (var i = 0; i < message.GameSize.Height(); i++)
            {
                for (var j = 0; j < message.GameSize.Width(); j++)
                {
                    Board[i, j] = new GridCard(i, j, message.GameCards[index++]);
                }
            }
        }
예제 #4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasId)
            {
                hash ^= Id.GetHashCode();
            }
            if (HasInviterIdentity)
            {
                hash ^= InviterIdentity.GetHashCode();
            }
            if (HasInviteeIdentity)
            {
                hash ^= InviteeIdentity.GetHashCode();
            }
            if (HasInviterName)
            {
                hash ^= InviterName.GetHashCode();
            }
            if (HasInviteeName)
            {
                hash ^= InviteeName.GetHashCode();
            }
            if (HasInvitationMessage)
            {
                hash ^= InvitationMessage.GetHashCode();
            }
            if (HasCreationTime)
            {
                hash ^= CreationTime.GetHashCode();
            }
            if (HasExpirationTime)
            {
                hash ^= ExpirationTime.GetHashCode();
            }
            if (_extensions != null)
            {
                hash ^= _extensions.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #5
0
        private void OnReceiveGame(InvitationMessage message, bool turn)
        {
            GameId = message.GameId;

            InitGameBoard(message);

            OpponentNick          = Client.Nick == message.SenderNick ? message.ReceiverNick : message.SenderNick;
            OpponentNickL.Content = OpponentNick;

            SetTurn(turn);

            InitGridGameBoard();

            MenuPnl.Visibility       = Visibility.Hidden;
            GameScoreGrid.Visibility = Visibility.Visible;
            GameBoardGrid.Visibility = Visibility.Visible;
        }
예제 #6
0
        private Game CreateGame(InvitationMessage message)
        {
            var newGame = new Game
            {
                GameSize = message.GameSize,
                Duration = DateTime.Now.TimeOfDay
            };

            newGame.MyMatches.Add(message.SenderNick, new Match {
                PlayerNick = message.SenderNick
            });
            newGame.MyMatches.Add(message.ReceiverNick, new Match {
                PlayerNick = message.ReceiverNick
            });

            return(newGame);
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uName"></param>
        /// <param name="contacts"></param>
        public void SendInvitation(string uName, string contacts, string languageCode)
        {
            string invitationText;

            string[] delimeter = { "," };
            invitationText       = InvitationMessage.GetLocalizedMessage(languageCode);
            _invitationSenderKey = _invitationSenderKey ?? ConfigurationManager.AppSettings[NeeoConstants.InvitationSenderKey];
            string[]  contactsArray = contacts.Split(delimeter, StringSplitOptions.None);
            ulong     temp          = 0;
            DbManager dbManager     = new DbManager();
            string    profileName   = dbManager.GetUserProfileName(_userID);
            string    msgBody       = invitationText.Replace(_invitationSenderKey,
                                                             (NeeoUtility.IsNullOrEmpty(uName)
                    ? (NeeoUtility.IsNullOrEmpty(profileName)
                        ? "(" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")"
                        : (profileName + " (" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")"))
                    : (uName + " (" + NeeoUtility.FormatAsIntlPhoneNumber(_userID) + ")")));

            for (int i = 0; i < contactsArray.Length; i++)
            {
                if (ulong.TryParse(contactsArray[i], out temp))
                {
                    try
                    {
                        //SmsManager.SendThroughSecondaryApi(NeeoUtility.FormatAsIntlPhoneNumber(contactsArray[i]),msgBody.Replace("!", Environment.NewLine));
                        PowerfulPal.Sms.SmsManager.GetInstance().Twilio.SendSms(new[] { NeeoUtility.FormatAsIntlPhoneNumber(contactsArray[i]) }, msgBody.Replace("!", Environment.NewLine), languageCode != "en");
                    }
                    catch (ApplicationException appEx)
                    {
                        LogManager.CurrentInstance.ErrorLogger.LogError(
                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + " ===> uid : " +
                            _userID + " ===> contact : " + contactsArray[i] + " is invalid.");
                    }
                }
                else
                {
                    LogManager.CurrentInstance.ErrorLogger.LogError(
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + " ===> uid : " +
                        _userID + " ===> contact : " + contactsArray[i] + " is invalid.");
                }
            }
        }
예제 #8
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasInvitationMessage)
            {
                hash ^= InvitationMessage.GetHashCode();
            }
            if (HasExpirationTime)
            {
                hash ^= ExpirationTime.GetHashCode();
            }
            if (_extensions != null)
            {
                hash ^= _extensions.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #9
0
        //------------------------------------------------
        // THREAD WORKER
        //------------------------------------------------
        public void Start()
        {
            while (true)
            {
                // esperem a que el receiver ens indiqui
                ReceiverArgs.notificationSignal.WaitOne();

                // agafem el tipus de missatge del Receiver
                int responseType = ReceiverArgs.responseType;

                // si hem rebut una update de dades (data grid), actualitzem el data grid
                if (responseType == DataGridUpdateRequested)
                {
                    // Actualitzem la llista de connectats
                    if (this.DataGridUpdateRequested == 6)
                    {
                        List <ConnectedUser>  connectedList = ReceiverArgs.connectedList;
                        ConnectedListDelegate gridDelegate  = new ConnectedListDelegate(this.QueriesForm.UpdateConnectedList);
                        QueriesForm.Invoke(gridDelegate, new object[] { connectedList });
                        connectedList = null;
                    }

                    // TODO: Actualitzem la taula de partides
                }
                // La resta de missatges de moment son les queries:

                // Mostra el temps jugat
                else if (responseType == 1)
                {
                    string time = ReceiverArgs.responseStr;
                    TimePlayedPopupDelegate timeDelegate = new TimePlayedPopupDelegate(this.QueriesForm.TimePlayedPopup);
                    QueriesForm.Invoke(timeDelegate, new object[] { time });
                }

                // TODO: la resta de queries

                //Mostra els personatges utilitzats en una partida
                else if (responseType == 3)
                {
                    string CharacterList = ReceiverArgs.responseStr;
                    CharacterListDelegate characterDelegate = new CharacterListDelegate(this.QueriesForm.UpdateCharactersList);

                    int        n_pairs         = Convert.ToInt32(CharacterList.Split('/')[0]);
                    string[]   playerCharPairs = new string[n_pairs];
                    string[][] playerChars     = new string[n_pairs][];
                    for (int i = 0; i < n_pairs; i++)
                    {
                        playerChars[i] = new string[2];
                    }
                    if (n_pairs > 0)
                    {
                        CharacterList = CharacterList.Remove(0, CharacterList.IndexOf("/") + 1); //eliminem el n_chars de la resposta
                        for (int i = 0; i < n_pairs; i++)
                        {
                            playerCharPairs = CharacterList.Split('/');
                            playerChars[i]  = playerCharPairs[i].Split('*');
                        }
                    }

                    QueriesForm.Invoke(characterDelegate, new object[] { playerChars });
                }

                //Mostra el ranking
                else if (responseType == 2)
                {
                    string          response        = ReceiverArgs.responseStr;
                    RankingDelegate rankingDelegate = new RankingDelegate(this.QueriesForm.UpdateRanking);
                    int             n_pairs         = Convert.ToInt32(response.Split('/')[0]);
                    string[]        rankingPairs    = new string[n_pairs];
                    string[][]      ranking         = new string[n_pairs][];
                    for (int i = 0; i < n_pairs; i++)
                    {
                        ranking[i] = new string[2];
                    }
                    if (n_pairs > 0)
                    {
                        response = response.Remove(0, response.IndexOf("/") + 1); //eliminem el n_chars de la resposta
                        for (int i = 0; i < n_pairs; i++)
                        {
                            rankingPairs = response.Split('/');
                            ranking[i]   = rankingPairs[i].Split('*');
                        }
                    }

                    QueriesForm.Invoke(rankingDelegate, new object[] { ranking });
                }
                //Crea un compte amb SignUp
                else if (responseType == 5)
                {
                    string      response       = ReceiverArgs.responseStr;
                    SignUpPopup SignUpDelegate = new SignUpPopup(this.QueriesForm.SignUpPopup);
                    QueriesForm.Invoke(SignUpDelegate, new object[] { response });
                }
                //Mostra la resposta a la partida creada
                else if (responseType == 7)
                {
                    string           response            = ReceiverArgs.responseStr;
                    CreatePartyPopup createPartyDelegate = new CreatePartyPopup(this.QueriesForm.CreatePartyPopup);
                    QueriesForm.Invoke(createPartyDelegate, new object[] { response });
                }
                //Notificació en invitacions
                else if (responseType == 9)
                {
                    string   response      = ReceiverArgs.responseStr;
                    string[] splitResponse = response.Split('/');
                    if (splitResponse[0] == "NOTIFY")
                    {
                        InvitationMessage invitationMessageDelegate = new InvitationMessage(this.QueriesForm.InvitationNotificationMessage);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { splitResponse[1], splitResponse[2] });
                    }

                    else if (splitResponse[0] == "ACCEPTED")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.AcceptedGamePopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }

                    else if (splitResponse[0] == "REJECTED")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.RejectGamePopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }

                    else if (splitResponse[0] == "FAIL")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.FailResponseGamePopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }

                    else if (splitResponse[0] == "LOST")
                    {
                        InvitationMessage invitationMessageDelegate = new InvitationMessage(this.QueriesForm.LoseInvitationPopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { splitResponse[1], splitResponse[2] });
                    }
                }

                //Notificació de l'actualització del GameStateUser
                else if (responseType == 10)
                {
                    List <PreGameStateUser>  gameState         = ReceiverArgs.gameState;
                    PreGameStateUserDelegate userStateDelegate = new PreGameStateUserDelegate(this.QueriesForm.GameStateUpdate);
                    QueriesForm.Invoke(userStateDelegate, new object[] { gameState });
                    gameState = null;
                }
                //Missatges del Xat
                else if (responseType == 11)
                {
                    string      response      = ReceiverArgs.responseStr;
                    string[]    splitResponse = response.Split('/');
                    ChatMessage ChatDelegate  = new ChatMessage(this.QueriesForm.SentMessageChat);
                    QueriesForm.Invoke(ChatDelegate, new object[] { splitResponse[0], splitResponse[1] });
                }

                //Notificacions sobre la selecció de personatges, cancel.lar partides i l'inici d'aquestes
                else if (responseType == 12)
                {
                    string   response      = ReceiverArgs.responseStr;
                    string[] splitResponse = response.Split('/');
                    if (splitResponse[0] == "CHAROK")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.AcceptCharacterPopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }
                    else if (splitResponse[0] == "CHARFAIL")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.FailCharacterPopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }
                    else if (splitResponse[0] == "START")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.StartGamePopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }
                    else if (splitResponse[0] == "NOTALLSELECTED")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.NotAllSelectedPopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }
                    else if (splitResponse[0] == "ALONE")
                    {
                        InvitationMessageConfirmation invitationMessageDelegate = new InvitationMessageConfirmation(this.QueriesForm.AlonePlayerPopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { });
                    }
                    else if (splitResponse[0] == "CANCEL")
                    {
                        InvitationMessage invitationMessageDelegate = new InvitationMessage(this.QueriesForm.CancelGamePopup);
                        QueriesForm.Invoke(invitationMessageDelegate, new object[] { splitResponse[1], splitResponse[2] });
                    }
                }

                //Jugadors en qui ja he jugat
                else if (responseType == 13)
                {
                    string OpponentList = ReceiverArgs.responseStr;
                    CharacterListDelegate opponentDelegate = new CharacterListDelegate(this.QueriesForm.UpdateOpponent);

                    int        n_pairs       = Convert.ToInt32(OpponentList.Split('/')[0]);
                    string[]   opponentPairs = new string[n_pairs];
                    string[][] opponents     = new string[n_pairs][];
                    for (int i = 0; i < n_pairs; i++)
                    {
                        opponents[i] = new string[3];
                    }
                    if (n_pairs > 0)
                    {
                        OpponentList = OpponentList.Remove(0, OpponentList.IndexOf("/") + 1); //eliminem el n_chars de la resposta
                        for (int i = 0; i < n_pairs; i++)
                        {
                            opponentPairs = OpponentList.Split('/');
                            opponents[i]  = opponentPairs[i].Split('*');
                        }
                    }

                    QueriesForm.Invoke(opponentDelegate, new object[] { opponents });
                }

                //Resultat de partides jugades amb altres jugadors
                else if (responseType == 14)
                {
                    string gameResultsList = ReceiverArgs.responseStr;
                    CharacterListDelegate gameResultsDelegate = new CharacterListDelegate(this.QueriesForm.UpdateGameResultsWithOthers);

                    int        n_pairs          = Convert.ToInt32(gameResultsList.Split('/')[0]);
                    string[]   gameResultsPairs = new string[n_pairs];
                    string[][] gameResults      = new string[n_pairs][];
                    for (int i = 0; i < n_pairs; i++)
                    {
                        gameResults[i] = new string[3];
                    }
                    if (n_pairs > 0)
                    {
                        gameResultsList = gameResultsList.Remove(0, gameResultsList.IndexOf("/") + 1); //eliminem el n_chars de la resposta
                        for (int i = 0; i < n_pairs; i++)
                        {
                            gameResultsPairs = gameResultsList.Split('/');
                            gameResults[i]   = gameResultsPairs[i].Split('*');
                        }
                    }

                    QueriesForm.Invoke(gameResultsDelegate, new object[] { gameResults });
                }

                //Resultat de l'interval de partides
                else if (responseType == 15)
                {
                    string gameResultsList = ReceiverArgs.responseStr;
                    CharacterListDelegate gameResultsDelegate = new CharacterListDelegate(this.QueriesForm.UpdateGameInterval);

                    int        n_pairs          = Convert.ToInt32(gameResultsList.Split('/')[0]);
                    string[]   gameResultsPairs = new string[n_pairs];
                    string[][] gameResults      = new string[n_pairs][];
                    for (int i = 0; i < n_pairs; i++)
                    {
                        gameResults[i] = new string[3];
                    }
                    if (n_pairs > 0)
                    {
                        gameResultsList = gameResultsList.Remove(0, gameResultsList.IndexOf("/") + 1); //eliminem el n_chars de la resposta
                        for (int i = 0; i < n_pairs; i++)
                        {
                            gameResultsPairs = gameResultsList.Split('/');
                            gameResults[i]   = gameResultsPairs[i].Split('*');
                        }
                    }

                    QueriesForm.Invoke(gameResultsDelegate, new object[] { gameResults });
                }
            }
        }