コード例 #1
0
 public void AddChatMsg(ChatResponceCommMessage msg)
 {
     Dispatcher.Invoke(DispatcherPriority.Normal,
                       new Action(delegate()
     {
         if (msg.chatType == CommunicationMessage.ActionType.PlayerBrodcast)
         {
             ListViewItem toAdd = new ListViewItem();
             toAdd.Content      = string.Concat("Player Broadcast message from  ", msg.senderngUsername, ": ", msg.msgToSend);
             chatListView.Items.Add(toAdd);
         }
         else if (msg.chatType == CommunicationMessage.ActionType.PlayerWhisper)
         {
             ListViewItem toAdd = new ListViewItem();
             toAdd.Content      = string.Concat("Player Whisper message from  ", msg.senderngUsername, ": ", msg.msgToSend);
             chatListView.Items.Add(toAdd);
         }
         else if (msg.chatType == CommunicationMessage.ActionType.SpectetorBrodcast)
         {
             ListViewItem toAdd = new ListViewItem();
             toAdd.Content      = string.Concat("Spectetor Broadcast message from  ", msg.senderngUsername, ": ", msg.msgToSend);
             chatListView.Items.Add(toAdd);
         }
         else if (msg.chatType == CommunicationMessage.ActionType.SpectetorWhisper)
         {
             ListViewItem toAdd = new ListViewItem();
             toAdd.Content      = string.Concat("Spectetor Whisper message from  ", msg.senderngUsername, ": ", msg.msgToSend);
             chatListView.Items.Add(toAdd);
         }
     }
                                  ));
 }
コード例 #2
0
ファイル: ClientLogic.cs プロジェクト: shoferb/OYAOB
 public void GotMsg(ChatResponceCommMessage msg)
 {
     foreach (GameScreen game in _games)
     {
         if (game.RoomId == msg.roomId)
         {
             game.AddChatMsg(msg);
         }
     }
 }
コード例 #3
0
 private void SendBroadcastSpec(IEnumerator <int> iterator, int senderId, ChatCommMessage msg, string usernameSender)
 {
     while (iterator.MoveNext())
     {
         var curr = iterator.Current;
         var res  = new ChatResponceCommMessage(msg.RoomId, curr, msg.SessionId, usernameSender, msg.ChatType,
                                                msg.MsgToSend, curr, true, msg);
         if (curr != senderId)
         {
             _commHandler.AddMsgToSend(_parser.SerializeMsg(res, ShouldUseDelim), curr);
         }
     }
 }
コード例 #4
0
        public ResponeCommMessage HandleEvent(ChatCommMessage msg)
        {
            if (_sessionIdHandler != null)
            {
                bool   success        = false;
                int    idReciver      = 0;
                string usernameSender = _userService.GetUserById(msg.IdSender).MemberName(); //to get from id;
                switch (msg.ChatType)
                {
                case CommunicationMessage.ActionType.PlayerBrodcast:
                    var enumerator = _gameService.CanSendPlayerBrodcast(msg.IdSender, msg.RoomId);
                    success = enumerator != null;
                    SendBroadcast(enumerator, msg.UserId, msg, usernameSender);
                    idReciver = msg.IdSender;
                    return(new ChatResponceCommMessage(msg.RoomId, idReciver, _sessionIdHandler.GetSessionIdByUserId(msg.UserId), usernameSender, msg.ChatType, msg.MsgToSend, msg.UserId, success, msg));

                    break;

                case CommunicationMessage.ActionType.PlayerWhisper:
                    IUser reciver = _userService.GetIUserByUserName(msg.ReciverUsername);
                    var   res     = new ChatResponceCommMessage(msg.RoomId, reciver.Id(), msg.SessionId, usernameSender, msg.ChatType,
                                                                msg.MsgToSend, reciver.Id(), true, msg);
                    if (reciver.Id() != msg.IdSender)
                    {
                        _commHandler.AddMsgToSend(_parser.SerializeMsg(res, ShouldUseDelim), reciver.Id());
                    }
                    idReciver = msg.IdSender;
                    break;

                case CommunicationMessage.ActionType.SpectetorBrodcast:
                    var enumeratorSpec = _gameService.CanSendSpectetorBrodcast(msg.IdSender, msg.RoomId);
                    success = enumeratorSpec != null;
                    SendBroadcastSpec(enumeratorSpec, msg.UserId, msg, usernameSender);
                    idReciver = msg.IdSender;
                    return(new ChatResponceCommMessage(msg.RoomId, idReciver, _sessionIdHandler.GetSessionIdByUserId(msg.UserId), usernameSender, msg.ChatType, msg.MsgToSend, msg.UserId, success, msg));

                    break;

                case CommunicationMessage.ActionType.SpectetorWhisper:
                    var enumeratorSpecWhisper = _gameService.CanSendSpectetorBrodcast(msg.IdSender, msg.RoomId);
                    success = enumeratorSpecWhisper != null;
                    SendBroadcastSpec(enumeratorSpecWhisper, msg.UserId, msg, usernameSender);
                    idReciver = msg.IdSender;
                    break;
                }
            }
            return(new ResponeCommMessage(msg.UserId, msg.SessionId, false, msg));
        }