示例#1
0
        public void OnLoginRsp(uint iMessageType, object kParam)
        {
            LoginRsp rsp = kParam as LoginRsp;

            Log4U.LogDebug(rsp.resultCode);
            if (rsp.resultCode == LoginRsp.ResultCode.SUCCESS)
            {
                _isLogin = true;

                GetPersonalInfoReq req = new GetPersonalInfoReq
                {
                    friendInfo = true,
                    userInfo   = true,
                    groupInfo  = true,
                };
                NetworkManager.GetInstance().SendPacket <GetPersonalInfoReq>(ENetworkMessage.GET_PERSONALINFO_REQ, req);

                PlayerPrefs.SetString(GlobalVars.PREF_USER_ID, _userId);
                PlayerPrefs.SetString(GlobalVars.PREF_USER_PASSWORD, _userPassword);

                CreateDir();
            }
            else
            {
                DoLogOut();
            }
        }
示例#2
0
        ////////////////////////////////////// 响应 ////////////////////////////////////
        private void LoginResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            if (send)
            {
                UserStatus.SetStatus(UserStatus.StatusType.Logout);
            }
            var rspWrap1 = res.RspWrap1;
            var rsp      = new LoginRsp();

            rsp.MergeFrom(res.Body);
            var eve = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, rsp);

            NetClient.HandleSuccess(eve.Code, () => {
                if (eve.Code == ErrCode.EcOk)
                {
                    RequestHeader.AuthKey  = rsp.Token;
                    RequestHeader.PlayerId = rsp.PlayerId;
                    var messageData        = rsp;

                    // 更新状态
                    UserStatus.SetStatus(UserStatus.StatusType.Login);

                    // 设置 PlayerInfo
                    if (string.IsNullOrEmpty(GamePlayerInfo.GetInfo().Id))
                    {
                        GamePlayerInfo.SetInfo(messageData.PlayerId);
                    }
                }
            });
            UserStatus.SetErrCode(eve.Code, eve.Msg);
            callback?.Invoke(eve);
        }
示例#3
0
        public void OnLoginRsp(uint iMessageType, object kParam)
        {
            LoginRsp rsp = kParam as LoginRsp;

            if (rsp.resultCode == LoginRsp.ResultCode.SUCCESS)
            {
                LoadLogDict();
            }
        }
    private void OnLoginReq(IMessage msg, object ext)
    {
        int      playerId = (int)ext;
        LoginRsp rsp      = new LoginRsp();

        rsp.PlayerId = playerId;
        ServerUDPMgr.GetInstance().SendMsgToAll(MsgID.LoginRsp, rsp);
        _loginInPlayerCount++;
    }
示例#5
0
    private void Recv()
    {
        byte[]       dataBuff = new byte[1024];
        int          len      = tcpClient.Receive(dataBuff);
        MemoryStream ms       = new MemoryStream(dataBuff, 0, len);

        LoginRsp rsp = Serializer.Deserialize <LoginRsp>(ms);

        Debug.Log(string.Format("recv a message, rsp = {0}, ret={1}", rsp.ToString(), rsp.ret));
    }
示例#6
0
        private void OnLoginRequest(ISession session, uint index, LoginReq req)
        {
            Debuger.Log("session:{0}, index:{1}, name:{2}", session.id, index, req.name);
            bool success = false;

            UserData ud = GetUserData(req.name);

            if (ud == null)
            {
                //正常登录
                //这里简单地使用SessionId作为UserId
                ud = CreateUserData(session.id, req.name);
                ud.svrdata.online            = true;
                ud.svrdata.lastHeartBeatTime = (uint)TimeUtils.GetTotalSecondsSince1970();
                session.SetAuth(ud.id);
                success = true;
            }
            else
            {
                if (req.id == ud.id)
                {
                    //重新登录
                    ud.svrdata.online            = true;
                    ud.svrdata.lastHeartBeatTime = (uint)TimeUtils.GetTotalSecondsSince1970();
                    session.SetAuth(ud.id);
                    success = true;
                }
                else
                {
                    //正常登录,但是尝试占用已有的名字
                    if (!ud.svrdata.online)
                    {
                        //如果该名字已经离线,则可以占用
                        ud.svrdata.online            = true;
                        ud.svrdata.lastHeartBeatTime = (uint)TimeUtils.GetTotalSecondsSince1970();
                        session.SetAuth(ud.id);
                        success = true;
                    }
                }
            }

            if (success)
            {
                LoginRsp rsp = new LoginRsp();
                rsp.ret      = ReturnCode.Success;
                rsp.userdata = ud;
                m_net.Send(session, index, ProtoCmd.LoginRsp, rsp);
            }
            else
            {
                LoginRsp rsp = new LoginRsp();
                rsp.ret = new ReturnCode(1, "名字已经被占用了!");
                m_net.Send(session, index, ProtoCmd.LoginRsp, rsp);
            }
        }
示例#7
0
 private void OnLoginRsp(LoginRsp rsp)
 {
     if (rsp.ret.code == 0)
     {
         Debuger.Log("UserData:{0}", rsp.userdata);
         m_mainUserData = rsp.userdata;
         m_heartbeat.Start();
     }
     else
     {
         Debuger.LogWarning(rsp.ret.info);
     }
 }
 /**
  *
  * @param loginRsp {MsLoginRsp//}
  */
 private void loginResponseInner(LoginRsp loginRsp)
 {
     Debug.Log("loginResponseInner");
     Debug.Log(loginRsp);
     if (loginRsp.Status == ErrorCode.Ok)
     {
         engine.joinRandomRoom(2);
     }
     else
     {
         Debug.LogError(" login failed !");
     }
 }
示例#9
0
    public void SetLoginAccount(Notify notify)
    {
        if (notify.Feedback == FeedBack.Success)
        {
            LoginRsp loginRsp = LoginRsp.Parser.ParseFrom(notify.message);
            GameFacade.RetrieveProxy <PlayerDataProxy>().SetAccount(loginRsp.Account);
            GameFacade.RetrieveProxy <PlayerDataProxy>().SetUser(loginRsp.User);

            GameFacade.SendNotification(notify.Protocol, CmdType.Presenter, loginRsp.Account);
        }
        else
        {
            GameFacade.SendNotification(notify.Protocol, CmdType.Error, notify.Feedback);
        }
    }
示例#10
0
        public void OnLoginRsp(uint iMessageType, object kParam)
        {
            LoginRsp rsp = kParam as LoginRsp;

            Log4U.LogInfo(rsp.resultCode);
            if (rsp.resultCode == LoginRsp.ResultCode.SUCCESS)
            {
                StateManager.GetInstance().ClearStates();
                StateManager.GetInstance().PushState <MainMenuPanel>(EUIType.MainMenuPanel);
            }
            else
            {
                DialogManager.GetInstance().CreateSingleButtonDialog(rsp.resultCode.ToString());
            }
        }
示例#11
0
 /**
  *
  * @param loginRsp {MsLoginRsp//}
  */
 private void loginResponseInner(LoginRsp loginRsp)
 {
     Debug.Log("loginResponseInner");
     Debug.Log(loginRsp);
     if (loginRsp.Status == ErrorCode.Ok)
     {
         GameNetWork.Inst.OnInitRes(true);
         //engine.joinRandomRoom(2);
     }
     else
     {
         GameNetWork.Inst.OnInitRes(false);
         Debug.LogError(" login failed !");
     }
 }
示例#12
0
        //====================================================================================


        private void OnLoginReq(ISession session, uint index, LoginReq req)
        {
            Debuger.Log("session:{0}, index:{1}, name:{2}", session.id, index, req.name);
            bool success = false;

            UserData ud = GetUserData(req.name);

            if (ud == null)
            {
                ud = CreateUserData(session.id, req.name);
                ActiveUser(session, ud);
                success = true;
            }
            else
            {
                if (req.id == ud.id)
                {
                    //重新登录
                    ActiveUser(session, ud);
                    success = true;
                }
                else
                {
                    //正常登录,但是尝试占用已有的名字
                    if (!ud.svrdata.online)
                    {
                        //如果该名字已经离线,则可以占用
                        ActiveUser(session, ud);
                        success = true;
                    }
                }
            }

            if (success)
            {
                LoginRsp rsp = new LoginRsp();
                rsp.ret      = ReturnCode.Success;
                rsp.userdata = ud;
                m_net.Send(session, index, ProtoCmd.LoginRsp, rsp);
            }
            else
            {
                LoginRsp rsp = new LoginRsp();
                rsp.ret = new ReturnCode(1, "名字已经被占用了!");
                m_net.Send(session, index, ProtoCmd.LoginRsp, rsp);
            }
        }
        private void OnLoginRsp(LoginRsp rsp)
        {
            Debuger.Log("ret:{0}, userdata:{1}", rsp.ret, rsp.userdata);
            if (rsp.ret.code == 0)
            {
                m_mainUserData = rsp.userdata;
                AppConfig.Value.mainUserData = m_mainUserData;
                AppConfig.Save();


                //启动心跳
                m_heartbeat.Start();

                GlobalEvent.onLoginSuccess.Invoke();
            }
            else
            {
                GlobalEvent.onLoginFailed.Invoke(rsp.ret.code, rsp.ret.info);
            }
        }
示例#14
0
        private void ReceiveMessage()
        {
            while (true)
            {
                //在接收数据之前  判断一下socket连接是否断开
                if (m_socket.Poll(10, SelectMode.SelectRead))
                {
                    m_socket.Close();
                    Console.WriteLine("a client is close.");
                    break;//跳出循环 终止线程的执行
                }

                byte[] dataBuff = new byte[1024];
                int    len      = m_socket.Receive(dataBuff);
                if (len > 0)
                {
                    MemoryStream msReq = new MemoryStream(dataBuff, 0, len);

                    LoginReq req = Serializer.Deserialize <LoginReq>(msReq);
                    Console.WriteLine("req = {0}, uin={1}", req.ToString(), req.uin);



                    try
                    {
                        LoginRsp rsp    = new LoginRsp();
                        Random   random = new Random();
                        rsp.ret = random.Next(10, 1000);
                        MemoryStream msRsp = new MemoryStream();
                        Serializer.Serialize <LoginRsp>(msRsp, rsp);
                        m_socket.Send(msRsp.ToArray());

                        Console.WriteLine("send a message to client, ret={0}", rsp.ret);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
        }
示例#15
0
 public void LoginRsp(LoginRsp rsp)
 {
     if (!rsp.OK)
     {
         if (currLoginObj_ != null)
         {
             NetSend.Instance.SendRegisterAsk(currLoginObj_.name_, currLoginObj_.passwd_);
         }
         else
         {
             Debug.Log("currLoginObj_ is null");
         }
     }
     else
     {
         userid_ = rsp.Userid;
         foreach (LoginObj obj in lsLoginObj_)
         {
             obj.Destroy();
         }
     }
 }
示例#16
0
        private static LoginRsp LoginResult(TcpClient tcpClient)
        {
            LoginRsp     result = null;
            BinaryReader br;

            try
            {
                byte[]        byteArray    = new byte[2048];
                NetworkStream clientStream = tcpClient.GetStream();
                br = new BinaryReader(clientStream);
                int    len  = br.Read(byteArray, 0, byteArray.Length);
                byte[] data = new byte[len];
                Array.Copy(byteArray, data, len);
                MemoryStream ms1 = new MemoryStream(data);
                result = Serializer.Deserialize <LoginRsp>(ms1);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
            }
            return(result);
        }
示例#17
0
    public void Recv(List <MessagePackObject> recvObject)
    {
        if (recvObject.Count < 1)
        {
            Debug.Log("Why the recv object lenght less than 1?");
            return;
        }
        int proto = recvObject[0].AsInt32();

        switch (proto)
        {
        case PROTO_ID.REGISTERRSP:
            RegisterRsp oRegisterRsp = new RegisterRsp();
            oRegisterRsp.OK = recvObject[1].AsBoolean();
            NetCallBack.Instance.RegisterRsp(oRegisterRsp);
            break;

        case PROTO_ID.LOGINRSP:
            LoginRsp oLoginRsp = new LoginRsp();
            oLoginRsp.Userid = recvObject[2].AsInt32();
            oLoginRsp.OK     = recvObject[1].AsBoolean();
            NetCallBack.Instance.LoginRsp(oLoginRsp);
            break;

        case PROTO_ID.FRIENDRSP:
            FriendRsp         oFriendRsp             = new FriendRsp();
            List <FriendInfo> lsoFriendRspFriendInfo = new List <FriendInfo>();
            foreach (MessagePackObject mix1 in recvObject[3].AsList())
            {
                IList <MessagePackObject> lsMix1 = mix1.AsList();
                FriendInfo oFriendRspFriendInfo  = new FriendInfo();
                oFriendRspFriendInfo.Userid = lsMix1[0].AsInt32();
                oFriendRspFriendInfo.Name   = lsMix1[1].AsString();
                lsoFriendRspFriendInfo.Add(oFriendRspFriendInfo);
            }
            oFriendRsp.FriendList = lsoFriendRspFriendInfo;
            oFriendRsp.Ok         = recvObject[1].AsBoolean();
            List <int> lsoFriendRspint = new List <int>();
            foreach (MessagePackObject mix1 in recvObject[2].AsList())
            {
                lsoFriendRspint.Add(mix1.AsInt32());
            }
            oFriendRsp.IdList = lsoFriendRspint;
            NetCallBack.Instance.FriendRsp(oFriendRsp);
            break;

        case PROTO_ID.RUOKRSP:
            RUOKRsp oRUOKRsp = new RUOKRsp();
            oRUOKRsp.OK = recvObject[1].AsBoolean();
            NetCallBack.Instance.RUOKRsp(oRUOKRsp);
            break;

        case PROTO_ID.USERINTOMAPRSP:
            UserIntoMapRsp oUserIntoMapRsp = new UserIntoMapRsp();
            oUserIntoMapRsp.Y = recvObject[3].AsInt32();
            oUserIntoMapRsp.X = recvObject[2].AsInt32();
            List <EntityInfo> lsoUserIntoMapRspEntityInfo = new List <EntityInfo>();
            foreach (MessagePackObject mix1 in recvObject[4].AsList())
            {
                IList <MessagePackObject> lsMix1     = mix1.AsList();
                EntityInfo oUserIntoMapRspEntityInfo = new EntityInfo();
                oUserIntoMapRspEntityInfo.Y          = lsMix1[3].AsInt32();
                oUserIntoMapRspEntityInfo.X          = lsMix1[2].AsInt32();
                oUserIntoMapRspEntityInfo.Entityid   = lsMix1[0].AsInt32();
                oUserIntoMapRspEntityInfo.EntityType = lsMix1[1].AsInt32();
                lsoUserIntoMapRspEntityInfo.Add(oUserIntoMapRspEntityInfo);
            }
            oUserIntoMapRsp.EntityList = lsoUserIntoMapRspEntityInfo;
            oUserIntoMapRsp.Mapid      = recvObject[1].AsInt32();
            NetCallBack.Instance.UserIntoMapRsp(oUserIntoMapRsp);
            break;

        case PROTO_ID.ENTITYINTOMAPRSP:
            EntityIntoMapRsp oEntityIntoMapRsp           = new EntityIntoMapRsp();
            EntityInfo       oEntityIntoMapRspEntityInfo = new EntityInfo();
            foreach (MessagePackObject mix1 in recvObject[1].AsList())
            {
                IList <MessagePackObject> lsMix1 = mix1.AsList();
                oEntityIntoMapRspEntityInfo.Y          = lsMix1[3].AsInt32();
                oEntityIntoMapRspEntityInfo.X          = lsMix1[2].AsInt32();
                oEntityIntoMapRspEntityInfo.Entityid   = lsMix1[0].AsInt32();
                oEntityIntoMapRspEntityInfo.EntityType = lsMix1[1].AsInt32();
            }
            oEntityIntoMapRsp.Entity = oEntityIntoMapRspEntityInfo;
            NetCallBack.Instance.EntityIntoMapRsp(oEntityIntoMapRsp);
            break;

        case PROTO_ID.ENTITYOUTMAPRSP:
            EntityOutMapRsp oEntityOutMapRsp = new EntityOutMapRsp();
            oEntityOutMapRsp.Entityid = recvObject[1].AsInt32();
            NetCallBack.Instance.EntityOutMapRsp(oEntityOutMapRsp);
            break;

        case PROTO_ID.ENTITYPOSRSP:
            EntityPosRsp      oEntityPosRsp             = new EntityPosRsp();
            List <EntityInfo> lsoEntityPosRspEntityInfo = new List <EntityInfo>();
            foreach (MessagePackObject mix1 in recvObject[1].AsList())
            {
                IList <MessagePackObject> lsMix1   = mix1.AsList();
                EntityInfo oEntityPosRspEntityInfo = new EntityInfo();
                oEntityPosRspEntityInfo.Y          = lsMix1[3].AsInt32();
                oEntityPosRspEntityInfo.X          = lsMix1[2].AsInt32();
                oEntityPosRspEntityInfo.Entityid   = lsMix1[0].AsInt32();
                oEntityPosRspEntityInfo.EntityType = lsMix1[1].AsInt32();
                lsoEntityPosRspEntityInfo.Add(oEntityPosRspEntityInfo);
            }
            oEntityPosRsp.EntityList = lsoEntityPosRspEntityInfo;
            NetCallBack.Instance.EntityPosRsp(oEntityPosRsp);
            break;

        case PROTO_ID.ENTITYHPRSP:
            EntityHpRsp oEntityHpRsp = new EntityHpRsp();
            oEntityHpRsp.Entityid = recvObject[1].AsInt32();
            oEntityHpRsp.Hp       = recvObject[2].AsInt32();
            NetCallBack.Instance.EntityHpRsp(oEntityHpRsp);
            break;

        case PROTO_ID.BOMBINRSP:
            BombInRsp oBombInRsp = new BombInRsp();
            oBombInRsp.Y      = recvObject[3].AsInt32();
            oBombInRsp.Bombid = recvObject[1].AsInt32();
            oBombInRsp.X      = recvObject[2].AsInt32();
            NetCallBack.Instance.BombInRsp(oBombInRsp);
            break;

        case PROTO_ID.BOMBBLASTRSP:
            BombBlastRsp oBombBlastRsp = new BombBlastRsp();
            oBombBlastRsp.Bombid = recvObject[1].AsInt32();
            NetCallBack.Instance.BombBlastRsp(oBombBlastRsp);
            break;

        default:
            Debug.Log("Unknow proto id: " + proto);
            break;
        }
    }
示例#18
0
        public void onMsg(byte[] buf)
        {
            Pro.He header = _mPro.de(buf);
            if (header == null)
            {
                return;
            }

            Log.d("[INFO] onMsg.header.cmd:{0}", header.cmd);
            switch (header.cmd)
            {
            case (int)CmdId.LoginRsp:
                LoginRsp loginRsp = (LoginRsp)header.deserialization;
                if (loginRsp.Status == ErrorCode.Ok)
                {
                    mState.setState(State.LOGIN);
                }
                else
                {
                    Log.w("[WARN] login fail:{0}", loginRsp.Status);
                    mState.clearState(State.LOGIN);
                    return;
                }

                MVS.RoomID = (loginRsp.RoomID != 0 ? loginRsp.RoomID:MVS.RoomID);
                MVS.TeamID = (loginRsp.TeamID != 0 ? loginRsp.TeamID:MVS.TeamID);
                if (mState.isHaveState(State.RECONNECT))
                {
                    reconnect();
                }

                callback("loginResponse", loginRsp);
                break;

            case (int)CmdId.LogoutRsp:
                callback("logoutResponse", header.deserialization);
                break;

            case (int)CmdId.CreateRoomRsp:
                connectHotel((CreateRoomRsp)header.deserialization);
                break;

            case (int)CmdId.JoinRoomRsp:
                var joinRoomRsp = (JoinRoomRsp)header.deserialization;
                if (joinRoomRsp.Status != ErrorCode.Ok)
                {
                    Log.w("[WARN] fail, join room:{0}", joinRoomRsp);
                    mState.clearState(State.ROOM);
                    this.onErr("", (int)joinRoomRsp.Status, "join room fail:" + joinRoomRsp);
                    return;
                }

                connectHotel((JoinRoomRsp)header.deserialization);
                break;

            case (int)CmdId.NoticeUserJoinReq:
                callback("joinRoomNotify", ((NoticeJoin)header.deserialization).User);
                break;

            case (int)CmdId.JoinOverRsp:
                callback("joinOverResponse", (JoinOverRsp)header.deserialization);
                break;

            case (int)CmdId.JoinOverNotify:
                callback("joinOverNotify", (JoinOverNotify)header.deserialization);
                break;

            case (int)CmdId.JoinOpenRsp:
                callback("joinOpenResponse", (JoinOpenRsp)header.deserialization);
                break;

            case (int)CmdId.JoinOpenNotify:
                callback("joinOpenNotify", (JoinOpenNotify)header.deserialization);
                break;

            case (int)CmdId.SetRoomPropertyRsp:
                callback("setRoomPropertyResponse", (SetRoomPropertyRsp)header.deserialization);
                break;

            case (int)CmdId.NoticeRoomProperty:
                callback("setRoomPropertyNotify", (NoticeRoomProperty)header.deserialization);
                break;

            case (int)CmdId.RoomListExRsp:
                callback("getRoomListExResponse", (GetRoomListExRsp)header.deserialization);
                break;

            case (int)CmdId.GetRoomDetailRsp:
                callback("getRoomDetailResponse", (GetRoomDetailRsp)header.deserialization);
                break;

            case (int)SDKHotelCmdID.CheckinAckCmdid:
                if (lastJoinRoomRsp == null)
                {
                    Log.w("[WARN] lastJoinRoomRsp is null when hotel ack");
                    break;
                }

                if (lastJoinRoomRsp is JoinRoomRsp)
                {
                    List <PlayerInfo> userList = new List <PlayerInfo>();
                    var d = (JoinRoomRsp)lastJoinRoomRsp;
                    if (d.Users != null && d.Users.Count > 0)
                    {
                        IEnumerator <PlayerInfo> iterator = d.Users.GetEnumerator();
                        while (true)
                        {
                            bool result = iterator.MoveNext();
                            if (!result)
                            {
                                break;
                            }

                            userList.Add(iterator.Current);
                        }
                    }

                    callback("joinRoomResponse", (int)d.Status, userList, d.RoomInfo);
                }
                else if (lastJoinRoomRsp is CreateRoomRsp)
                {
                    var d = (CreateRoomRsp)lastJoinRoomRsp;
                    callback("createRoomResponse", d);
                }
                else if (lastJoinRoomRsp is TeamMatchResultNotify)
                {
                    callback("teamMatchResultNotify", lastJoinRoomRsp);
                }
                else
                {
                    Log.w("[warn] unknown hotel checkin:{0}", lastJoinRoomRsp);
                }

                break;


            case (int)SDKHotelCmdID.BroadcastAckCmdid:
                callback("sendEventResponse", ((BroadcastAck)header.deserialization).Status);
                break;

            case (int)SDKHotelCmdID.NotifyCmdid:
                Notify r = ((Notify)header.deserialization);
                callback("sendEventNotify", r.SrcUid, r.CpProto.ToByteArray());
                break;

            case (int)CmdId.LeaveRoomRsp:
                _mHNw?.close();
                _mHNw      = null;
                MVS.RoomID = 0;
                mState.clearState(State.ROOM);
                callback("leaveRoomResponse", ((LeaveRoomRsp)header.deserialization));
                break;

            case (int)CmdId.NoticeUserLeaveReq:
                callback("leaveRoomNotify", ((NoticeLeave)header.deserialization));
                break;

            case (int)SDKHotelCmdID.FrameBroadcastAckCmdid:
                //
                callback("sendFrameEventResponse", ((FrameBroadcastAck)header.deserialization));
                break;

            case (int)SDKHotelCmdID.FrameDataNotifyCmdid:
                frameCache.Enqueue((FrameDataNotify)header.deserialization);
                break;

            case (int)SDKHotelCmdID.FrameSyncNotifyCmdid:
                var frameData = new FrameDataNotify[frameCache.Count];
                for (var i = 0; i < frameCache.Count; i++)
                {
                    frameData[i] = frameCache.Dequeue();
                }

                callback("frameUpdate",
                         new MsFrameData(((FrameSyncNotify)header.deserialization).LastIdx, frameData));
                break;

            case (int)SDKHotelCmdID.SetFrameSyncRateNotifyCmdid:
                callback("setFrameSyncNotify", ((SetFrameSyncRateNotify)header.deserialization));
                break;

            case (int)SDKHotelCmdID.SetFrameSyncRateAckCmdid:
                callback("setFrameSyncResponse", ((SetFrameSyncRateAck)header.deserialization));
                break;

            case (int)CmdId.NoticeTeamNetworkState:
                callback("teamNetworkStateNotify", header.deserialization);
                break;

            case (int)CmdId.NoticeRoomNetworkState:
                callback("networkStateNotify", header.deserialization);
                break;

            //watch
            case (int)CmdId.GetWatchRoomsRsp:
                callback("getWatchRoomsResponse", (GetWatchRoomsRsp)header.deserialization);
                break;

            case (int)CmdId.JoinWatchRoomRsp:
                var rsp = (JoinWatchRoomRsp)header.deserialization;
                if (rsp.Status == ErrorCode.Ok)
                {
                    connectWatch(rsp);
                }
                else
                {
                    callback("errorResponse", rsp.Status, "join watch room is fail");
                }

                break;

            case (int)CmdId.JoinWatchRoomNotify:
                callback("joinWatchRoomNotify", (JoinWatchRoomNotify)header.deserialization);
                break;

            case (int)SDKWatchCmdID.EnterLiveRoomAckCmdid:
                mState.SetWatch();
                var liveEA = (EnterLiveRoomAck)header.deserialization;
                callback("joinWatchRoomResponse", liveEA);
                break;

            case (int)SDKWatchCmdID.EnterLiveRoomNotifyCmdid:
                callback("enterLiveRoomNotify", (EnterLiveRoomNotify)header.deserialization);
                break;

            case (int)CmdId.LeaveWatchRoomRsp:
                _mWNw?.close();
                _mWNw           = null;
                MVS.WatchRoomID = 0;
                mState.clearState(State.WATCH);
                callback("leaveWatchRoomResponse", (LeaveWatchRoomRsp)header.deserialization);
                break;

            case (int)CmdId.LeaveWatchRoomNotify:
                callback("leaveWatchRoomNotify", (LeaveWatchRoomNotify)header.deserialization);
                break;

            case (int)SDKWatchCmdID.ExitLiveRoomNotifyCmdid:
                callback("exitLiveRoomNotify", (ExitLiveRoomNotify)header.deserialization);
                break;

            case (int)SDKWatchCmdID.LiveBroadcastAckCmdid:
                callback("sendLiveEventResponse", (LiveBroadcastAck)header.deserialization);
                break;

            case (int)SDKWatchCmdID.LiveBroadcastNotifyCmdid:
                callback("sendLiveEventNotify", (LiveBroadcastNotify)header.deserialization);
                break;

            case (int)SDKWatchCmdID.LiveFrameDataNotifyCmdid:
                frameWatchCache.Enqueue((LiveFrameDataNotify)header.deserialization);
                break;

            case (int)SDKWatchCmdID.LiveFrameSyncNotifyCmdid:
                var frameLiveData = new LiveFrameDataNotify[frameWatchCache.Count];
                for (var i = 0; i < frameLiveData.Length; i++)
                {
                    frameLiveData[i] = frameWatchCache.Dequeue();
                }

                callback("liveFrameUpdate", (LiveFrameSyncNotify)header.deserialization, frameLiveData);
                break;

            case (int)SDKWatchCmdID.SetLiveOffsetAckCmdid:
                callback("setLiveOffsetResponse", (SetLiveOffsetAck)header.deserialization);
                break;

            case (int)SDKWatchCmdID.LiveOverNotifyCmdid:
                callback("liveOverNotify", (LiveOverNotify)header.deserialization);
                break;


            //team
            case (int)CmdId.TeamMatchRsp:
                callback("teamMatchResponse", (TeamMatchRsp)header.deserialization);
                break;

            case (int)CmdId.TeamMatchStartNotify:
                callback("teamMatchStartNotify", (TeamMatchStartNotify)header.deserialization);
                break;

            case (int)CmdId.TeamMatchResultNotify:
                var teamMatchResult = (TeamMatchResultNotify)header.deserialization;
                if (teamMatchResult.Status == ErrorCode.Ok)
                {
                    connectHotel(teamMatchResult);
                    mState.setState(State.ROOM);
                }
                else
                {
                    callback("teamMatchResultNotify", (TeamMatchResultNotify)header.deserialization);
                }


                break;

            case (int)CmdId.CancelTeamMatchRsp:
                callback("cancelTeamMatchResponse", (CancelTeamMatchRsp)header.deserialization);
                break;

            case (int)CmdId.CancelTeamMatchNotify:
                callback("cancelTeamMatchNotify", (CancelTeamMatchNotify)header.deserialization);
                break;

            case (int)CmdId.KickTeamMemberRsp:
                callback("kickTeamMemberResponse", (KickTeamMemberRsp)header.deserialization);
                break;

            case (int)CmdId.KickTeamMemberNotify:
                callback("kickTeamMemberNotify", header.deserialization);
                break;

            case (int)CmdId.SendTeamEventRsp:
                callback("sendTeamEventResponse", (SendTeamEventRsp)header.deserialization);
                break;

            case (int)CmdId.SendTeamEventNotify:
                callback("sendTeamEventNotify", (SendTeamEventNotify)header.deserialization);
                break;

            case (int)CmdId.LeaveTeamNotify:
                callback("leaveTeamNotify", (LeaveTeamNotify)header.deserialization);
                break;

            case (int)CmdId.LeaveTeamRsp:
                callback("leaveTeamResponse", (LeaveTeamRsp)header.deserialization);
                break;

            case (int)CmdId.JoinTeamNotify:
                callback("joinTeamNotify", (JoinTeamNotify)header.deserialization);
                break;

            case (int)CmdId.JoinTeamRsp:
                var joinTeamRsp = (JoinTeamRsp)header.deserialization;
                callback("joinTeamResponse", joinTeamRsp);
                if (joinTeamRsp.Status == ErrorCode.Ok)
                {
                    MVS.TeamID = joinTeamRsp.TeamInfo.TeamID;
                }

                break;

            case (int)CmdId.SetTeamPropertyRsp:
                callback("setTeamPropertyResponse", (SetTeamPropertyRsp)header.deserialization);
                break;

            case (int)CmdId.NoticeTeamProperty:
                callback("setTeamPropertyNotify", (NoticeTeamProperty)header.deserialization);
                break;

            case (int)CmdId.SetTeamUserProfileRsp:
                callback("setTeamUserProfileResponse", (SetTeamUserProfileRsp)header.deserialization);
                break;

            case (int)CmdId.NoticeTeamUserProfile:
                callback("setTeamUserProfileNotify", (NoticeTeamUserProfile)header.deserialization);
                break;

            case (int)CmdId.SetReconnectTimeoutRsp:
                callback("setReconnectTimeoutResponse", (SetReconnectTimeoutRsp)header.deserialization);
                break;

            case (int)CmdId.SetTeamReconnectTimeoutRsp:
                callback("setTeamReconnectTimeoutResponse", (SetTeamReconnectTimeoutRsp)header.deserialization);
                break;

            case (int)CmdId.CreateTeamRsp:
                MVS.TeamID = ((CreateTeamRsp)header.deserialization).TeamID;
                callback("createTeamResponse", header.deserialization);
                break;

            case (int)CmdId.KickPlayerRsp:
                callback("kickPlayerResponse", header.deserialization);
                break;

            case (int)CmdId.KickPlayerNotify:
                var k = (KickPlayerNotify)header.deserialization;
                callback("kickPlayerNotify", header.deserialization);
                if (MVS.UserID == k.UserID)
                {
                    _mHNw?.close();
                }

                break;
            }
        }
示例#19
0
        private void ini()
        {
            //login
            mD[(int)CmdId.LoginRsp] = (He header) => {
                LoginRsp rsp = (LoginRsp)LoginRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LoginRsp.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.LogoutRsp] = (He header) => {
                var rsp = (LogoutRsp)LogoutRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LogoutRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mE[(int)CmdId.LoginReq] = (object[] arguments) => {
                u = (uint)arguments[1];
                LoginReq req = new LoginReq();
                req.Token    = MD5.MD5Encrypt((string)arguments[2]);
                req.GameID   = (uint)arguments[3];
                req.AppKey   = (string)arguments[4];
                req.DeviceID = (string)arguments[5];
                req.SdkVer   = "3";

                req.Sign = MD5.MD5Encrypt(string.Format("{0}&UserID={1}&GameID={2}&VersionSdk={3}&{4}", req.AppKey,
                                                        u, req.GameID, 3, req.Token));
                return(fHe(req.ToByteArray(), (int)arguments[0], true));
            };

            mE[(int)CmdId.LogoutReq] = (object[] arguments) => {
                return(fHe(StringUtil.toUtf8Array((string)arguments[1]), (int)arguments[0]));
            };


            //heartbeat

            mE[(int)CmdId.HeartBeatReq] = (object[] arguments) => {
                HeartbeatReq req = new HeartbeatReq();
                req.GameID = (uint)arguments[1];
                req.RoomID = (ulong)arguments[2];
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.HeartBeatReq] = (He header) => {
                return(header);
            };

            //hotel heartbeat
            mE[(int)SDKHotelCmdID.HeartbeatCmdid] = (object[] arguments) => {
                Heartbeat req = new Heartbeat();
                req.GameID = (uint)arguments[1];
                req.RoomID = (ulong)arguments[2];
                req.UserID = (uint)arguments[3];

                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)SDKHotelCmdID.HeartbeatAckCmdid] = (He header) => {
                HeartbeatAck rsp = (HeartbeatAck)HeartbeatAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("rsp.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };



            //createRoom
            mE[(int)CmdId.CreateRoomReq] = (object[] arguments) => {
                MsRoomInfo p = (MsRoomInfo)arguments[1];

                PlayerInfo pi = new PlayerInfo();
                pi.UserID      = p.userID;
                pi.UserProfile = tbs(p.userProfile);


                RoomInfo ri = new RoomInfo();
                ri.MaxPlayer    = p.maxPlayer;
                ri.CanWatch     = p.canWatch;
                ri.Mode         = p.mode;
                ri.Visibility   = p.visibility;
                ri.RoomName     = p.roomName;
                ri.RoomProperty = tbs(p.roomProperty);

                CreateRoom req = new CreateRoom();
                req.PlayerInfo   = pi;
                req.RoomInfo     = ri;
                req.GameID       = p.gameID;
                req.WatchSetting = p.watchSetting;


                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.CreateRoomRsp] = (He header) => {
                CreateRoomRsp rsp = (CreateRoomRsp)CreateRoomRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("CreateRoomRsp.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };


            //joinRoom
            mE[(int)CmdId.JoinRoomReq] = (object[] arguments) => {
                MsRoomInfo p = (MsRoomInfo)arguments[1];

                PlayerInfo pi = new PlayerInfo();
                pi.UserID      = p.userID;
                pi.UserProfile = tbs(p.userProfile);


                RoomInfo ri = new RoomInfo();
                ri.MaxPlayer  = p.maxPlayer;
                ri.CanWatch   = p.canWatch;
                ri.Mode       = p.mode;
                ri.Visibility = p.visibility;
                ri.RoomID     = p.roomID;

                JoinRoomReq req = new JoinRoomReq();
                req.PlayerInfo   = pi;
                req.RoomInfo     = ri;
                req.GameID       = p.gameID;
                req.JoinType     = p.joinType;
                req.CpProto      = tbs(p.userProfile);
                req.WatchSetting = p.watchSetting;
                var tags = p.tags;
                if (tags != null)
                {
                    foreach (var k in tags.Keys)
                    {
                        var tag = new keyValue();
                        tag.Key   = k;
                        tag.Value = tags[k];
                        req.Tags.Add(tag);
                    }
                }

                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.JoinRoomRsp] = (He header) => {
                JoinRoomRsp rsp = (JoinRoomRsp)JoinRoomRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinRoomRsp.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.NoticeUserJoinReq] = (He header) => {
                NoticeJoin rsp = (NoticeJoin)NoticeJoin.Descriptor.Parser.ParseFrom(header.data);
                Log.d("NoticeUserJoinReq.UserID:{0}->{1}", rsp.User.UserID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            mE[(int)CmdId.LeaveRoomReq] = (object[] arguments) => {
                LeaveRoomReq p = new LeaveRoomReq();
                p.GameID  = MVS.GameID;
                p.UserID  = MVS.UserID;
                p.RoomID  = MVS.RoomID;
                p.CpProto = ByteString.CopyFrom(StringUtil.toUtf8Array((string)arguments[1]));
                return(fHe(p.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.LeaveRoomRsp] = (He header) => {
                LeaveRoomRsp rsp = (LeaveRoomRsp)LeaveRoomRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LeaveRoomRsp.UserID:{0}->{1}", rsp.UserID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.NoticeUserLeaveReq] = (He header) => {
                NoticeLeave rsp = (NoticeLeave)NoticeLeave.Descriptor.Parser.ParseFrom(header.data);
                Log.d("NoticeUserLeave.UserID:{0}->{1}", rsp.UserID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //hotel
            mE[(int)SDKHotelCmdID.CheckinCmdid] = (object[] arguments) => {
                var pkg = new CheckIn();
                pkg.GameID = (uint)arguments[4];
                pkg.RoomID = ((RoomInfo)arguments[2]).RoomID;
                pkg.UserID = (uint)arguments[3];
                var bookInfo = (BookInfo)arguments[1];
                pkg.BookID = bookInfo.BookID;
                pkg.Key    = bookInfo.BookKey;

                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)SDKHotelCmdID.CheckinAckCmdid] = (He header) => {
                CheckInAck rsp = (CheckInAck)CheckInAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("CheckInAck.BookID:{0}->{1}", rsp.BookID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //sendEvent
            mE[(int)SDKHotelCmdID.BroadcastCmdid] = (object[] arguments) => {
                var pkg = new Broadcast();
                pkg.RoomID = (ulong)arguments[1];
                uint[] dstUids = (uint[])arguments[2];
                foreach (var i in dstUids)
                {
                    pkg.DstUids.Add(i);
                }

                // 低8位 由 0-3  | destType |msgType 组合 0000|00|00
                uint priority = 2;
                uint flag     = (uint)(((priority & 0x0F) << 4) + (((int)arguments[3] & 0x03) << 2) + ((int)arguments[4] & 0x03));
                pkg.Flag = flag;

                pkg.CpProto = ByteString.CopyFrom((byte[])arguments[5]);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)SDKHotelCmdID.BroadcastAckCmdid] = (He header) => {
                BroadcastAck rsp = (BroadcastAck)BroadcastAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("BroadcastAck.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKHotelCmdID.NotifyCmdid] = (He header) => {
                Notify rsp = (Notify)Notify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("Notify.SrcUid:{0}->data.len:{1}", rsp.SrcUid, rsp.CpProto.Length);
                header.deserialization = rsp;
                return(header);
            };

            //FrameSync
            mE[(int)SDKHotelCmdID.FrameBroadcastCmdid] = (object[] arguments) => {
                var pkg = new FrameBroadcast();
                pkg.RoomID    = (ulong)arguments[1];
                pkg.Priority  = (uint)arguments[2];
                pkg.CpProto   = ByteString.CopyFrom((byte[])arguments[3]);
                pkg.Operation = (int)arguments[4];
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };
            mE[(int)SDKHotelCmdID.SetFrameSyncRateCmdid] = (object[] arguments) => {
                var pkg = new SetFrameSyncRate();
                pkg.GameID       = (uint)arguments[1];
                pkg.RoomID       = (ulong)arguments[2];
                pkg.Priority     = (uint)arguments[3];
                pkg.FrameRate    = (uint)arguments[4];
                pkg.EnableGS     = (uint)arguments[5];
                pkg.CacheFrameMS = (int)arguments[6];
                pkg.FrameIdx     = 1;
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)SDKHotelCmdID.FrameBroadcastAckCmdid] = (He header) => {
                FrameBroadcastAck rsp = (FrameBroadcastAck)FrameBroadcastAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("FrameBroadcastAck.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKHotelCmdID.FrameDataNotifyCmdid] = (He header) => {
                FrameDataNotify rsp = (FrameDataNotify)FrameDataNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("FrameDataNotify.SrcUid:{0}->data.len:{1}", rsp.SrcUid, rsp.CpProto.Length);
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKHotelCmdID.FrameSyncNotifyCmdid] = (He header) => {
                FrameSyncNotify rsp = (FrameSyncNotify)FrameSyncNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("FrameSyncNotify.LastIdx:{0}->TimeStamp:{1}", rsp.LastIdx, rsp.TimeStamp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)SDKHotelCmdID.SetFrameSyncRateAckCmdid] = (He header) => {
                SetFrameSyncRateAck rsp =
                    (SetFrameSyncRateAck)SetFrameSyncRateAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetFrameSyncRateAck.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKHotelCmdID.SetFrameSyncRateNotifyCmdid] = (He header) => {
                SetFrameSyncRateNotify rsp =
                    (SetFrameSyncRateNotify)SetFrameSyncRateNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetFrameSyncRateNotify.FrameRate:{0}->{1}", rsp.FrameRate, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //turn on/off for join room
            mE[(int)CmdId.JoinOpenReq] = (object[] arguments) => {
                var pkg = new JoinOpenReq();
                pkg.GameID  = (uint)arguments[1];
                pkg.RoomID  = (ulong)arguments[2];
                pkg.UserID  = (uint)arguments[3];
                pkg.CpProto = ByteString.CopyFrom((byte[])arguments[4]);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };
            mE[(int)CmdId.JoinOverReq] = (object[] arguments) => {
                var pkg = new JoinOverReq();
                pkg.GameID  = (uint)arguments[1];
                pkg.RoomID  = (ulong)arguments[2];
                pkg.UserID  = (uint)arguments[3];
                pkg.CpProto = ByteString.CopyFrom((byte[])arguments[4]);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.JoinOverRsp] = (He header) => {
                JoinOverRsp rsp = (JoinOverRsp)JoinOverRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinOverRsp.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.JoinOpenRsp] = (He header) => {
                JoinOpenRsp rsp = (JoinOpenRsp)JoinOpenRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinOpenRsp.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.JoinOverNotify] = (He header) => {
                JoinOverNotify rsp = (JoinOverNotify)JoinOverNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinOverNotify.UserID:{0}->{1}", rsp.SrcUserID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.JoinOpenNotify] = (He header) => {
                JoinOpenNotify rsp = (JoinOpenNotify)JoinOpenNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinOpenNotify.UserID:{0}->{1}", rsp.UserID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //SetRoomProperty
            mE[(int)CmdId.SetRoomPropertyReq] = (object[] arguments) => {
                var pkg = new SetRoomPropertyReq();
                pkg.GameID       = (uint)arguments[1];
                pkg.RoomID       = (ulong)arguments[2];
                pkg.UserID       = (uint)arguments[3];
                pkg.RoomProperty = ByteString.CopyFrom((byte[])arguments[4]);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.SetRoomPropertyRsp] = (He header) => {
                SetRoomPropertyRsp rsp =
                    (SetRoomPropertyRsp)SetRoomPropertyRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetRoomPropertyRsp.UserID:{0}->{1}", rsp.UserID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.NoticeRoomProperty] = (He header) => {
                NoticeRoomProperty rsp =
                    (NoticeRoomProperty)NoticeRoomProperty.Descriptor.Parser.ParseFrom(header.data);
                Log.d("NoticeRoomProperty.UserID:{0}->{1}", rsp.UserID, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //getRoomDetail
            mE[(int)CmdId.GetRoomDetailReq] = (object[] arguments) => {
                var pkg = new GetRoomDetailReq();
                pkg.GameID = (uint)arguments[1];
                pkg.RoomID = (ulong)arguments[2];
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.GetRoomDetailRsp] = (He header) => {
                GetRoomDetailRsp rsp = (GetRoomDetailRsp)GetRoomDetailRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("GetRoomDetailRsp:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //getRoomList
            mE[(int)CmdId.RoomListExReq] = (object[] arguments) => {
                var pkg    = new GetRoomListExReq();
                var filter = (MsRoomFilter)arguments[2];

                var roomFilter = new RoomFilter();
                roomFilter.MaxPlayer     = (filter.maxPlayer);
                roomFilter.Mode          = filter.mode;
                roomFilter.Full          = filter.full;
                roomFilter.CanWatch      = (filter.canWatch);
                roomFilter.RoomProperty  = ByteString.CopyFrom(StringUtil.toUtf8Array(filter.roomProperty));
                roomFilter.State         = filter.state;
                roomFilter.GetSystemRoom = filter.getSystemRoom;

                pkg.GameID     = (uint)arguments[1];
                pkg.RoomFilter = roomFilter;
                pkg.Sort       = (filter.sort);
                pkg.Order      = (filter.order);
                pkg.PageNo     = (filter.pageNo);
                pkg.PageSize   = (filter.pageSize);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.RoomListExRsp] = (He header) => {
                GetRoomListExRsp rsp = (GetRoomListExRsp)GetRoomListExRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("GetRoomDetailRsp:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //NetWorkState
            mD[(int)CmdId.NoticeRoomNetworkState] = (He header) => {
                RoomNetworkStateNotify rsp =
                    (RoomNetworkStateNotify)RoomNetworkStateNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("RoomNetworkStateNotify:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.NoticeTeamNetworkState] = (He header) => {
                TeamNetworkStateNotify rsp =
                    (TeamNetworkStateNotify)TeamNetworkStateNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("TeamNetworkStateNotify:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };


            //watchRoomList
            mE[(int)CmdId.GetWatchRoomsReq] = (object[] arguments) => {
                var pkg    = new GetWatchRoomsReq();
                var filter = (MsRoomFilter)arguments[2];


                var roomFilter = new RoomFilter();
                roomFilter.MaxPlayer     = (filter.maxPlayer);
                roomFilter.Mode          = filter.mode;
                roomFilter.Full          = filter.full;
                roomFilter.CanWatch      = (filter.canWatch);
                roomFilter.RoomProperty  = ByteString.CopyFrom(StringUtil.toUtf8Array(filter.roomProperty));
                roomFilter.State         = filter.state;
                roomFilter.GetSystemRoom = filter.getSystemRoom;

                pkg.GameID     = (uint)arguments[1];
                pkg.RoomFilter = roomFilter;
                pkg.Sort       = (filter.sort);
                pkg.Order      = (filter.order);
                pkg.PageNo     = (filter.pageNo);
                pkg.PageSize   = (filter.pageSize);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.GetWatchRoomsRsp] = (He header) => {
                GetWatchRoomsRsp rsp = (GetWatchRoomsRsp)GetWatchRoomsRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("GetWatchRoomsRsp:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //joinWatch
            mE[(int)CmdId.JoinWatchRoomReq] = (object[] arguments) => {
                var p   = (MsRoomInfo)arguments[1];
                var req = new JoinWatchRoomReq();
                req.GameID      = p.gameID;
                req.RoomID      = p.roomID;
                req.UserID      = p.userID;
                req.UserProfile = tbs(p.userProfile);
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.JoinWatchRoomRsp] = (He header) => {
                var rsp = (JoinWatchRoomRsp)JoinWatchRoomRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinWatchRoomRsp.Status:{0}->{1}", rsp.Status, rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.JoinWatchRoomNotify] = (He header) => {
                var rsp = (JoinWatchRoomNotify)JoinWatchRoomNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinWatchRoomNotify:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //leaveWatch
            mE[(int)CmdId.LeaveWatchRoomReq] = (object[] arguments) => {
                var p = new LeaveWatchRoomReq();
                p.GameID  = MVS.GameID;
                p.UserID  = MVS.UserID;
                p.RoomID  = MVS.RoomID;
                p.CpProto = ByteString.CopyFrom(StringUtil.toUtf8Array((string)arguments[1]));
                return(fHe(p.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.LeaveWatchRoomRsp] = (He header) => {
                var rsp = (LeaveWatchRoomRsp)LeaveWatchRoomRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LeaveWatchRoomRsp:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.LeaveWatchRoomNotify] = (He header) => {
                var rsp = (LeaveWatchRoomNotify)LeaveWatchRoomNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LeaveWatchRoomNotify:{0}->", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };

            //WatchCheckIn
            mE[(int)SDKWatchCmdID.EnterLiveRoomCmdid] = (object[] arguments) => {
                var pkg = new EnterLiveRoom();
                pkg.GameID = (uint)arguments[4];
                pkg.RoomID = (ulong)arguments[2];
                pkg.UserID = (uint)arguments[3];
                var bookInfo = (BookInfo)arguments[1];
                pkg.BookID = bookInfo.BookID;
                pkg.Ticket = bookInfo.BookKey;
                pkg.SetID  = (uint)arguments[5];
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };
            mE[(int)SDKWatchCmdID.SetLiveOffsetCmdid] = (object[] arguments) => {
                var pkg = new SetLiveOffset();
                pkg.GameID   = (uint)arguments[1];
                pkg.RoomID   = (ulong)arguments[2];
                pkg.UserID   = (uint)arguments[3];
                pkg.OffsetMS = (int)arguments[4];
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)SDKWatchCmdID.EnterLiveRoomAckCmdid] = (He header) => {
                var rsp = (EnterLiveRoomAck)EnterLiveRoomAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("EnterLiveRoomAck:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKWatchCmdID.EnterLiveRoomNotifyCmdid] = (He header) => {
                var rsp = (EnterLiveRoomNotify)EnterLiveRoomNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("EnterLiveRoomNotify:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKWatchCmdID.ExitLiveRoomNotifyCmdid] = (He header) => {
                var rsp = (ExitLiveRoomNotify)ExitLiveRoomNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("ExitLiveRoomNotify:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };


            mD[(int)SDKWatchCmdID.SetLiveOffsetAckCmdid] = (He header) => {
                var rsp = (SetLiveOffsetAck)SetLiveOffsetAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetLiveOffsetAck:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };


            //LiveBroadcast
            mE[(int)SDKWatchCmdID.LiveBroadcastCmdid] = (object[] arguments) => {
                var pkg = new LiveBroadcast();
                pkg.RoomID = (ulong)arguments[1];
                uint[] dstUids = (uint[])arguments[2];
                foreach (var i in dstUids)
                {
                    pkg.DstUids.Add(i);
                }

                // 低8位 由 0-3  | destType |msgType 组合 0000|00|00
                uint priority = 2;
                uint flag     = ((priority & 0x0F) << 4) + (((uint)arguments[3] & 0x03) << 2) + ((uint)arguments[4] & 0x03);
                pkg.Flag    = flag;
                pkg.CpProto = ByteString.CopyFrom((byte[])arguments[5]);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)SDKWatchCmdID.LiveBroadcastAckCmdid] = (He header) => {
                var rsp = (LiveBroadcastAck)LiveBroadcastAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LiveBroadcast:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKWatchCmdID.LiveBroadcastNotifyCmdid] = (He header) => {
                var rsp = (LiveBroadcastNotify)LiveBroadcastNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LiveBroadcastNotify:{0}", rsp.ToString());
                header.deserialization = rsp;
                return(header);
            };


            mD[(int)SDKWatchCmdID.LiveFrameDataNotifyCmdid] = (He header) => {
                var rsp = (LiveFrameDataNotify)LiveFrameDataNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LiveFrameDataNotify.{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKWatchCmdID.LiveFrameSyncNotifyCmdid] = (He header) => {
                var rsp = (LiveFrameSyncNotify)LiveFrameSyncNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LiveFrameSyncNotify:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //watch heart beat
            mE[(int)SDKWatchCmdID.LiveHeartbeatCmdid] = (object[] arguments) => {
                LiveHeartbeat req = new LiveHeartbeat();
                req.GameID = (uint)arguments[1];
                req.RoomID = (ulong)arguments[2];
                req.UserID = (uint)arguments[3];
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)SDKWatchCmdID.LiveHeartbeatAckCmdid] = (He header) => {
                var rsp = (LiveHeartbeatAck)LiveHeartbeatAck.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LiveFrameSyncNotify:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)SDKWatchCmdID.LiveOverNotifyCmdid] = (He header) => {
                var rsp = (LiveOverNotify)LiveOverNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LiveOverNotify:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };


            //team - create
            mE[(int)CmdId.CreateTeamReq] = (arguments) => {
                PlayerInfo pi = new PlayerInfo();
                pi.UserID      = (uint)arguments[1];
                pi.UserProfile = tbs((string)arguments[2]);

                CreateTeamReq req = new CreateTeamReq();
                req.PlayerInfo = pi;
                req.GameID     = (uint)arguments[3];
                req.TeamInfo   = (TeamInfo)arguments[4];
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.CreateTeamRsp] = (header) => {
                var rsp = (CreateTeamRsp)CreateTeamRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("CreateTeamRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };
            //team - join
            mE[(int)CmdId.JoinTeamReq] = (arguments) => {
                PlayerInfo pi = new PlayerInfo();
                pi.UserID      = (uint)arguments[1];
                pi.UserProfile = tbs((string)arguments[2]);

                JoinTeamReq req = new JoinTeamReq();
                req.PlayerInfo = pi;
                req.GameID     = (uint)arguments[3];
                req.TeamID     = (ulong)arguments[4];
                req.Password   = (string)arguments[5];
                req.JoinType   = (JoinTeamType)arguments[6];
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.JoinTeamRsp] = (header) => {
                var rsp = (JoinTeamRsp)JoinTeamRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinTeamRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.JoinTeamNotify] = (He header) => {
                var rsp = (JoinTeamNotify)JoinTeamNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("JoinTeamNotify.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //team - leave
            mE[(int)CmdId.LeaveTeamReq] = (arguments) => {
                LeaveTeamReq req = new LeaveTeamReq();
                req.GameID = (uint)arguments[1];
                req.TeamID = (ulong)arguments[3];
                req.UserID = (uint)arguments[2];
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.LeaveTeamRsp] = (header) => {
                var rsp = (LeaveTeamRsp)LeaveTeamRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LeaveTeamRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.LeaveTeamNotify] = (He header) => {
                var rsp = (LeaveTeamNotify)LeaveTeamNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("LeaveTeamNotify.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //team - match
            mE[(int)CmdId.TeamMatchReq] = (arguments) => {
                TeamMatchReq req = new TeamMatchReq();
                req.GameID = (uint)arguments[1];
                req.UserID = (uint)arguments[2];
                req.TeamID = (ulong)arguments[3];
                req.Cond   = (TeamMatchCond)arguments[4];

                MsRoomInfo p  = (MsRoomInfo)arguments[5];
                RoomInfo   ri = new RoomInfo();
                ri.RoomID       = p.roomID;
                ri.RoomName     = p.roomName;
                ri.MaxPlayer    = p.maxPlayer;
                ri.Mode         = p.mode;
                ri.CanWatch     = p.canWatch;
                ri.Visibility   = p.visibility;
                ri.RoomProperty = tbs(p.roomProperty);

                req.RoomInfo = ri;
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.TeamMatchRsp] = (header) => {
                var rsp = (TeamMatchRsp)TeamMatchRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("TeamMatchRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.TeamMatchStartNotify] = (He header) => {
                var rsp = (TeamMatchStartNotify)TeamMatchStartNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("TeamMatchStartNotify.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };
            mD[(int)CmdId.TeamMatchResultNotify] = (He header) => {
                var rsp = (TeamMatchResultNotify)TeamMatchResultNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("TeamMatchResultNotify.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //team - cancel match
            mE[(int)CmdId.CancelTeamMatchReq] = (arguments) => {
                CancelTeamMatchReq req = new CancelTeamMatchReq();
                req.GameID  = (uint)arguments[1];
                req.UserID  = (uint)arguments[2];
                req.TeamID  = (ulong)arguments[3];
                req.CpProto = tbs((string)arguments[4]);
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.CancelTeamMatchRsp] = (header) => {
                var rsp = (CancelTeamMatchRsp)CancelTeamMatchRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("CancelTeamMatchRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.CancelTeamMatchNotify] = (header) => {
                var rsp = (CancelTeamMatchNotify)CancelTeamMatchNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("CancelTeamMatchNotify.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //team - kick match
            mE[(int)CmdId.KickTeamMemberReq] = (arguments) => {
                KickTeamMemberReq req = new KickTeamMemberReq();
                req.GameID    = (uint)arguments[1];
                req.UserID    = (uint)arguments[2];
                req.TeamID    = (ulong)arguments[3];
                req.CpProto   = tbs((string)arguments[4]);
                req.DstUserID = (uint)arguments[5];
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.KickTeamMemberRsp] = (header) => {
                var rsp = (KickTeamMemberRsp)KickTeamMemberRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("KickTeamMemberRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.KickTeamMemberNotify] = (header) => {
                var rsp = (KickTeamMemberNotify)KickTeamMemberNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("KickTeamMemberNotify:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //team sendEvent
            mE[(int)CmdId.SendTeamEventReq] = (arguments) => {
                var pkg = new SendTeamEventReq();
                pkg.TeamID = (ulong)arguments[1];
                uint[] dstUids = (uint[])arguments[2];
                foreach (var i in dstUids)
                {
                    pkg.DstUids.Add(i);
                }
                pkg.DstType = (TeamDstType)arguments[3];
                pkg.MsgType = (TeamMsgType)arguments[4];
                pkg.CpProto = ByteString.CopyFrom((byte[])arguments[5]);
                pkg.GameID  = (uint)arguments[6];
                pkg.UserID  = (uint)arguments[7];
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.SendTeamEventRsp] = (header) => {
                var rsp = (SendTeamEventRsp)SendTeamEventRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SendTeamEventRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.SendTeamEventNotify] = (header) => {
                var rsp = (SendTeamEventNotify)SendTeamEventNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SendTeamEventNotify.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //team profile
            mE[(int)CmdId.SetTeamPropertyReq] = (arguments) => {
                var pkg = new SetTeamPropertyReq();
                pkg.GameID       = (uint)arguments[1];
                pkg.TeamID       = (ulong)arguments[2];
                pkg.UserID       = (uint)arguments[3];;
                pkg.TeamProperty = tbs((string)arguments[4]);;
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.SetTeamPropertyRsp] = (header) => {
                var rsp = (SetTeamPropertyRsp)SetTeamPropertyRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetTeamPropertyRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.NoticeTeamProperty] = (header) => {
                var rsp = (NoticeTeamProperty)NoticeTeamProperty.Descriptor.Parser.ParseFrom(header.data);
                Log.d("NoticeTeamProperty.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            //team user profile
            mE[(int)CmdId.SetTeamUserProfileReq] = (arguments) => {
                var pkg = new SetTeamUserProfileReq();
                pkg.GameID      = (uint)arguments[1];
                pkg.TeamID      = (ulong)arguments[2];
                pkg.UserID      = (uint)arguments[3];
                pkg.UserProfile = tbs((string)arguments[4]);
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.SetTeamUserProfileRsp] = (header) => {
                var rsp = (SetTeamUserProfileRsp)SetTeamUserProfileRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetTeamUserProfileRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.NoticeTeamUserProfile] = (header) => {
                var rsp = (NoticeTeamUserProfile)NoticeTeamUserProfile.Descriptor.Parser.ParseFrom(header.data);
                Log.d("NoticeTeamUserProfile.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };


            //timeout
            //team user profile
            mE[(int)CmdId.SetReconnectTimeoutReq] = (arguments) => {
                var pkg = new SetReconnectTimeoutReq();
                pkg.UserID  = (uint)arguments[1];
                pkg.Timeout = (int)arguments[2];
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.SetReconnectTimeoutRsp] = (header) => {
                var rsp = (SetReconnectTimeoutRsp)SetReconnectTimeoutRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetReconnectTimeoutRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };
            mE[(int)CmdId.SetTeamReconnectTimeoutReq] = (arguments) => {
                var pkg = new SetTeamReconnectTimeoutReq();
                pkg.UserID  = (uint)arguments[1];
                pkg.Timeout = (int)arguments[2];
                return(fHe(pkg.ToByteArray(), (int)arguments[0]));
            };

            mD[(int)CmdId.SetTeamReconnectTimeoutRsp] = (header) => {
                var rsp = (SetTeamReconnectTimeoutRsp)SetTeamReconnectTimeoutRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("SetTeamReconnectTimeoutRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };


            //room - kick
            mE[(int)CmdId.KickPlayerReq] = (arguments) => {
                KickPlayer req = new KickPlayer();
                req.SrcUserID = (uint)arguments[2];
                req.RoomID    = (ulong)arguments[3];
                req.CpProto   = tbs((string)arguments[4]);
                req.UserID    = (uint)arguments[5];
                return(fHe(req.ToByteArray(), (int)arguments[0]));
            };
            mD[(int)CmdId.KickPlayerRsp] = (header) => {
                var rsp = (KickPlayerRsp)KickPlayerRsp.Descriptor.Parser.ParseFrom(header.data);
                Log.d("KickPlayerRsp.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };

            mD[(int)CmdId.KickPlayerNotify] = (header) => {
                var rsp = (KickPlayerNotify)KickPlayerNotify.Descriptor.Parser.ParseFrom(header.data);
                Log.d("KickPlayerNotify.Status:{0}", rsp);
                header.deserialization = rsp;
                return(header);
            };
        }
示例#20
0
        public void Init(string name, string password)
        {
            string serverIp = "119.23.12.116";

            try
            {
                IPAddress remoteIP            = IPAddress.Parse(serverIp);
                TcpClient mainServerTcpClient = new TcpClient();
                mainServerTcpClient.Connect(new IPEndPoint(remoteIP, 13333));
                SendToServer(mainServerTcpClient, name, password);
                LoginRsp result = LoginResult(mainServerTcpClient);
                if (LoginRsp.ResultCode.FAIL.Equals(result.resultCode))
                {
                    MessageBox.Show("用户名或密码错误,请重新输入");
                    mainServerTcpClient.Close();
                    return;
                }
                else if (LoginRsp.ResultCode.LOGGEDIN.Equals(result.resultCode))
                {
                    MessageBox.Show("该账号已登录");
                    mainServerTcpClient.Close();
                    return;
                }
                else if (LoginRsp.ResultCode.NOTMAINPHONE.Equals(result.resultCode))
                {
                    MessageBox.Show("该设备不是主设备");
                    Window loading = null;
                    Thread t       = new Thread(new ThreadStart(delegate
                    {
                        App.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            loading = new LoadingWindow();
                            loading.ShowDialog();
                        }));
                    }));
                    t.IsBackground = true;
                    t.Start();

                    Console.WriteLine("waite result");
                    AccreditRsp accreditResult = AccreditResult(mainServerTcpClient);
                    if (AccreditRsp.ResultCode.CANLOGIN.Equals(accreditResult.resultCode))
                    {
                        SendToServer(mainServerTcpClient, name, password);
                        MessageBox.Show("主设备同意登录");
                        App.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            if (loading != null)
                            {
                                loading.Close();
                            }
                        }));
                        MessageBox.Show("授权成功");
                        util.config.ConfigUtil.SetValue("longconnect", "true");
                        util.config.ConfigUtil.SetValue("username", name);
                        util.config.ConfigUtil.SetValue("password", password);
                        App.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            this.Close();
                        }));
                        MainWindow.main.Status = "长连接开启";
                    }
                    else if (AccreditRsp.ResultCode.FAIL.Equals(accreditResult.resultCode))
                    {
                        App.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            if (loading != null)
                            {
                                loading.Close();
                            }
                        }));
                        MessageBox.Show("授权被拒绝");
                        MainWindow.main.Status = "长连接失败";
                        mainServerTcpClient.Close();
                        return;
                    }
                }
                else if (LoginRsp.ResultCode.MAINPHONEOUTLINE.Equals(result.resultCode))
                {
                    MessageBox.Show("主设备不在线");
                    MainWindow.main.Status = "长连接失败";
                    mainServerTcpClient.Close();
                    return;
                }
                else if (LoginRsp.ResultCode.SUCCESS.Equals(result.resultCode))
                {
                    MessageBox.Show("登录成功");
                    util.config.ConfigUtil.SetValue("longconnect", "true");
                    util.config.ConfigUtil.SetValue("username", name);
                    util.config.ConfigUtil.SetValue("password", password);
                    App.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        this.Close();
                    }));
                    // can also be any object you'd like to use as a parameter
                    MainWindow.main.Status = "长连接已开启";
                    //启动长连接
                    ClientPCNew2.StartService(mainServerTcpClient);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
示例#21
0
 public void LoginRsp(LoginRsp rsp)
 {
     TestManager.Instance.LoginRsp(rsp);
 }