Exemplo n.º 1
0
        public void OnRequesting(MsgPackSession session, BinaryRequestInfo requestInfo)
        {
            Client client = Session2ClientTable[session];
            MyData data   = null;

            try
            {
                data = PacketTranslator.Unpack(requestInfo.Body);
            }
            catch (Exception e)
            {
                Debug(string.Format("error at parse client request {0} {1}", e.Message, e.TargetSite));
                Debug(string.Format("error messsage {0} {1}", requestInfo?.ToString(), requestInfo.Body?.ToString()));
                session.Close();
                return;
            }
            TransferType request = PacketTranslator.GetTransferType(requestInfo.Key);

            //OutPut(string.Format("请求协议为{0}, 内容为{1}", data.Protocol.ToString(), data.Body[0]));
            if (client.UserName == null && !request.Equals(TransferType.TypeLogin))
            {
                OutPut(string.Format("{0} 未登录客户端,关闭连接", client.IP));
                session.Close();
                return;
            }

            if (data.Description == PacketDescription.Client2Hall)
            {
                switch (request)
                {
                case TransferType.TypeLogin:                              //登录相关
                    switch (data.Protocol)
                    {
                    case protocol.Login:
                        client.CheckUserName(data);
                        break;

                    case protocol.Register:                               //用户注册
                        client.Register(data);
                        break;

                    case protocol.PasswordChange:                         //密码修改
                        break;

                    default:
                        return;
                    }
                    break;

                case TransferType.TypeMessage:                            //公共事件 比如 聊天
                    MessageForward(client, data);
                    break;

                case TransferType.TypeSwitch:                               //切换room和hall
                    RoomSwitch(client, data);
                    break;

                case TransferType.TypeUserProfile:                          //修改个人信息
                    client.UpDateProfile(data);
                    break;

                default:
                    Debug(string.Format("{0} 对聊天大厅无效的请求", client.UserName));
                    break;;
                }
            }
            else if (data.Description == PacketDescription.Client2Room)
            {
                switch (request)
                {
                case TransferType.TypeMessage:                            //公共事件 比如 聊天
                    MessageForward(client, data);
                    break;

                case TransferType.TypeGameControll:                       //游戏内各操作
                    client.ControlGame(data);
                    break;

                case TransferType.TypeSwitch:                               //切换room和hall
                    RoomSwitch(client, data);
                    break;

                default:
                    Debug(string.Format("{0} 对ROOM无效的请求", client.UserName));
                    break;;
                }
            }
            else
            {
                OutPut("无效的客户端请求");
            }
        }