Esempio n. 1
0
        public bool NotifyAction(ResponeCommMessage msg)
        {
            ActionCommMessage original = msg.OriginalMsg as ActionCommMessage;

            if (original != null)
            {
                switch (original.MoveType)
                {
                case CommunicationMessage.ActionType.Join:
                    ReceivedJoin((JoinResponseCommMessage)msg);
                    break;

                case CommunicationMessage.ActionType.Spectate:
                    ReceivedSpectate((JoinResponseCommMessage)msg);
                    break;

                case CommunicationMessage.ActionType.Leave:
                    ReceivedLeave(msg);
                    break;

                case CommunicationMessage.ActionType.SpectatorLeave:
                    ReceivedSpectetorLeave(msg);
                    break;

                default:
                    GeneralCase(msg.GameData);
                    break;
                }
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        private ResponeCommMessage SendMessages(int userId, IEnumerator <ActionResultInfo> iterator,
                                                CommunicationMessage originalMsg)
        {
            ResponeCommMessage  response = null;
            GameDataCommMessage gameData = null;
            bool found = false;

            while (iterator.MoveNext())
            {
                var curr = iterator.Current;
                if (curr != null && curr.Id != userId)
                {
                    gameData = curr.GameData;
                    _commHandler.AddMsgToSend(_parser.SerializeMsg(curr.GameData, ShouldUseDelim), curr.Id);
                }
                else if (curr != null)
                {
                    found    = true;
                    response = new ResponeCommMessage(userId, _sessionIdHandler.GetSessionIdByUserId(userId),
                                                      curr.GameData.IsSucceed, originalMsg);
                    response.SetGameData(curr.GameData);
                }
            }
            if (!found && gameData != null)
            {
                response = new ResponeCommMessage(userId, _sessionIdHandler.GetSessionIdByUserId(userId),
                                                  gameData.IsSucceed, originalMsg);
                response.SetGameData(gameData);
            }
            return(response);
        }
Esempio n. 3
0
        public void NotifyChatTest_SpectetorWhisper()
        {
            ChatCommMessage    chatMsg = new ChatCommMessage(1, 1, 1, "Bar", "Hi", ChatCommMessage.ActionType.SpectetorWhisper);
            ResponeCommMessage resMsg  = new ResponeCommMessage(1, 1, true, chatMsg);
            bool ans = rn.NotifyChat(resMsg);

            Assert.IsTrue(ans);
        }
Esempio n. 4
0
 public bool ReceivedJoin(ResponeCommMessage msg)
 {
     if (_logic != null)
     {
         _logic.JoinAsPlayerReceived((JoinResponseCommMessage)msg);
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
 public bool NotifyReturnAsSpec(ResponeCommMessage msg)
 {
     if (_logic != null)
     {
         _logic.SpecReturnsToGame(msg.GameData);
         return(true);
     }
     return(false);
 }
Esempio n. 6
0
 public bool NotifyChat(ResponeCommMessage msg)
 {
     if (((ChatCommMessage)msg.OriginalMsg).ChatType == CommunicationMessage.ActionType.PlayerWhisper ||
         ((ChatCommMessage)msg.OriginalMsg).ChatType == CommunicationMessage.ActionType.SpectetorWhisper)
     {
         return(true);
     }
     return(GeneralCase(msg.GameData));
 }
Esempio n. 7
0
 public bool Default(ResponeCommMessage msg)
 {
     if (msg != null)
     {
         GeneralCase(msg.GameData);
         return(true);
     }
     return(false);
 }
Esempio n. 8
0
 private bool ReceivedSpectetorLeave(ResponeCommMessage msg)
 {
     if (_logic != null)
     {
         _logic.LeaveAsSpectetor(msg);
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
 public ResponeCommMessage HandleEvent(ResponeCommMessage msg)
 {
     if (_sessionIdHandler != null)
     {
         var parsed = _parser.SerializeMsg(msg, ShouldUseDelim);
         _commHandler.AddMsgToSend(parsed, msg.UserId);
         return(new ResponeCommMessage(msg.UserId, msg.SessionId, true, msg)); //is not used
     }
     return(new ResponeCommMessage(msg.UserId, msg.SessionId, false, msg));
 }
Esempio n. 10
0
 public void LeaveAsSpectetor(ResponeCommMessage msg)
 {
     foreach (GameScreen gameScreen in _games)
     {
         if (gameScreen.RoomId == msg.GameData.RoomId)
         {
             gameScreen.LeaveAsSpectetorOk(msg.GameData);
         }
     }
 }
Esempio n. 11
0
 public bool NotifySearch(ResponeCommMessage msg)
 {
     if (_logic != null)
     {
         SearchCommMessage original = (SearchCommMessage)msg.OriginalMsg;
         _logic.SearchResultRecived(((SearchResponseCommMessage)msg).Games, original.IsReturnToGame);
         return(true);
     }
     return(false);
 }
Esempio n. 12
0
 public bool NotifyLogin(ResponeCommMessage msg)
 {
     if (_logic != null)
     {
         LoginResponeCommMessage loginResp = (LoginResponeCommMessage)msg;
         if (((LoginCommMessage)loginResp.OriginalMsg).IsLogin)
         {
             return(_logic.LoginRespReceived(loginResp));
         }
         return(_logic.LogoutRespReceived(loginResp));
     }
     return(false);
 }
Esempio n. 13
0
 public ResponeCommMessage HandleEvent(ResponeCommMessage msg)
 {
     if (SetSetionId(msg.SessionId))
     {
         if (msg.GetType() == typeof(ChatResponceCommMessage))
         {
             _logic.GotMsg((ChatResponceCommMessage)msg);
         }
         else
         {
             _logic.NotifyResponseReceived(msg);
         }
     }
     return(new ResponeCommMessage(msg.UserId, msg.SessionId, false, msg));
 }
Esempio n. 14
0
        public bool ObserverNotify(ResponeCommMessage msg)
        {
            Tuple <CommunicationMessage, bool, bool, ResponeCommMessage> toEdit =
                _messagesSentObserver.Find(x => x.Item1.Equals(msg.OriginalMsg));

            if (toEdit != null)
            {
                _messagesSentObserver.Remove(toEdit);
                var toAdd = new Tuple <CommunicationMessage, bool, bool,
                                       ResponeCommMessage>(toEdit.Item1, true, msg.Success, msg);
                _messagesSentObserver.Add(toAdd);
                return(true);
            }
            return(false);
        }
Esempio n. 15
0
        public void Initialize()
        {
            proxy          = new GameDataProxy(gameCenter);
            _userDataProxy = new UserDataProxy();
            user1          = new User(1, "test1", "mo", "1234", 0, 5000, "*****@*****.**");
            user2          = new User(2, "test2", "no", "1234", 0, 5000, "*****@*****.**");
            user3          = new User(3, "test3", "3test", "1234", 0, 5000, "*****@*****.**");
            _userDataProxy.AddNewUser(user1);
            _userDataProxy.AddNewUser(user2);
            _userDataProxy.AddNewUser(user3);
            useCommunication     = false;
            roomID               = 9999;
            players              = new List <Player>();
            player1              = new Player(user1, 1000, roomID);
            player1.RoundChipBet = 22;
            players.Add(player1);
            Decorator deco = SetDecoratoresNoLimitWithSpectatores();

            gameRoom = new GameRoom(players, roomID, deco, gameCenter, logControl, replayManager, ses);
            Card        c1     = new Card(Suits.Clubs, 1);
            Card        c2     = new Card(Suits.Clubs, 2);
            List <Card> pCards = new List <Card>();

            pCards.Add(c1);
            pCards.Add(c2);
            long sid = 1;

            msg = new GameDataCommMessage(gameRoom.GetPlayersInRoom().First().user.Id(), gameRoom.Id, sid, new Card(Suits.Diamonds, 1), new Card(Suits.Diamonds, 2),
                                          pCards, 3, 4, new List <string>(), new List <string>(), "", "", "", true, "", "", 1,
                                          new CommunicationMessage.ActionType(), "Flop", "");
            var ob = new List <Tuple <CommunicationMessage, bool, bool, TexasHoldemShared.CommMessages.ServerToClient.ResponeCommMessage> >();

            res = new ResponeCommMessage(1, 1, true, msg);
            var t = new Tuple <CommunicationMessage, bool, bool, TexasHoldemShared.CommMessages.ServerToClient.ResponeCommMessage>(msg, false, false, res);

            ob.Add(t);
            rn = new ResponseNotifier(ob, cl);
        }
Esempio n. 16
0
        public ResponeCommMessage HandleEvent(ActionCommMessage msg)
        {
            if (_sessionIdHandler != null)
            {
                ResponeCommMessage             response = null;
                IEnumerator <ActionResultInfo> iter;
                switch (msg.MoveType)
                {
                case CommunicationMessage.ActionType.Bet:
                case CommunicationMessage.ActionType.Fold:
                case CommunicationMessage.ActionType.HandCard:
                case CommunicationMessage.ActionType.Leave:
                case CommunicationMessage.ActionType.StartGame:
                case CommunicationMessage.ActionType.SpectatorLeave:
                    iter     = _gameService.DoAction(msg.UserId, msg.MoveType, msg.Amount, msg.RoomId);
                    response = SendMessages(msg.UserId, iter, msg);
                    break;

                case CommunicationMessage.ActionType.Join:
                    iter = _gameService.DoAction(msg.UserId, msg.MoveType, msg.Amount, msg.RoomId);

                    response = SendMessagesJoin(msg.UserId, iter, msg);
                    break;

                case CommunicationMessage.ActionType.Spectate:
                    iter     = _gameService.AddSpectatorToRoom(msg.UserId, msg.RoomId);
                    response = SendMessagesJoin(msg.UserId, iter, msg);
                    break;
                }
                if (response != null)
                {
                    return(response);
                }
            }
            return(new ResponeCommMessage(msg.UserId, msg.SessionId, false, msg));
        }
Esempio n. 17
0
 public void HandleEvent(ResponeCommMessage msg)
 {
     //notify in GUI
     throw new NotImplementedException();
 }
Esempio n. 18
0
 public bool ReceivedSpectate(ResponeCommMessage msg)
 {
     _logic.JoinAsSpectatorReceived((JoinResponseCommMessage)msg);
     return(true);
 }
Esempio n. 19
0
        public void NotifyResponseReceived(ResponeCommMessage msg)
        {
            if (_notifyDictionary.ContainsKey(msg.OriginalMsg.GetType()))
            {
                var func = _notifyDictionary[msg.OriginalMsg.GetType()];
                func(msg);
            }
            else
            {
                _notifier.Default(msg);
            }

            //var notifier = new ResponseNotifier(MessagesSentObserver, this);
            //msg.Notify(notifier, msg);

            //if (msg.OriginalMsg.GetType() == typeof(ChatCommMessage))
            //{
            //    if (((ChatCommMessage)msg.OriginalMsg).ChatType == CommunicationMessage.ActionType.PlayerWhisper ||
            //     ((ChatCommMessage)msg.OriginalMsg).ChatType == CommunicationMessage.ActionType.SpectetorWhisper)
            //    {
            //        return;
            //    }
            //}
            //if ((msg.OriginalMsg.GetType() == typeof(LoginCommMessage)) ||
            //   (msg.OriginalMsg.GetType()) == typeof(RegisterCommMessage)||
            //      (msg.OriginalMsg.GetType()) == typeof(CreateNewRoomMessage))
            //{
            //    Tuple<CommunicationMessage, bool, bool, ResponeCommMessage> toEdit =
            //        MessagesSentObserver.Find(x => x.Item1.Equals(msg.OriginalMsg));
            //    MessagesSentObserver.Remove(toEdit);
            //    var toAdd = new Tuple<CommunicationMessage, bool, bool, ResponeCommMessage>(toEdit.Item1, true,
            //        msg.Success,
            //        msg);
            //    MessagesSentObserver.Add(toAdd);
            //    return;
            //}
            //if ((msg.OriginalMsg.GetType()) == typeof(ReturnToGameAsPlayerCommMsg) && _returnToGamesScreen != null)
            //{
            //    PlayerReturnsToGame(msg.GameData);
            //    return;
            //}
            //if ((msg.OriginalMsg.GetType()) == typeof(ReturnToGameAsPlayerCommMsg) && _returnToGamesScreen != null)
            //{
            //    return;
            //}
            //if ((msg.OriginalMsg.GetType()) == typeof(SearchCommMessage))
            //{
            //    SearchResultRecived(((SearchResponseCommMessage) msg).Games);
            //    return;
            //}
            //if ((msg.OriginalMsg.GetType() == typeof(ActionCommMessage) &&
            //     (((ActionCommMessage)msg.OriginalMsg).MoveType == CommunicationMessage.ActionType.Join)))
            //{
            //    JoinAsPlayerReceived(msg as JoinResponseCommMessage);
            //    return;
            //}
            //if ((msg.OriginalMsg.GetType() == typeof(ActionCommMessage) &&
            //     (((ActionCommMessage)msg.OriginalMsg).MoveType == CommunicationMessage.ActionType.Spectate)))
            //{
            //    JoinAsSpectatorReceived(msg as JoinResponseCommMessage);
            //    return;
            //}
            //if ((msg.OriginalMsg.GetType() == typeof(ActionCommMessage) &&
            //   (((ActionCommMessage)msg.OriginalMsg).MoveType == CommunicationMessage.ActionType.Leave)))
            //{
            //    GameDataCommMessage gd = (msg).GameData;
            //    foreach (GameScreen game in _games)
            //    {
            //        if (game.RoomId == gd.RoomId)
            //        {
            //            game.LeaveOkay(gd);
            //        }
            //    }
            //    return;
            //}

            //GameUpdateReceived(msg.GameData);
        }