示例#1
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));
        }