Beispiel #1
0
        // 发送帧同步信息
        public string SendFrame(SendFrameReq para, Action <ResponseEvent> callback)
        {
            if (this.RoomInfo == null || string.IsNullOrEmpty(this.RoomInfo.Id))
            {
                var rspWrap1 = new ClientSendServerRspWrap1 {
                    ErrCode = ErrCode.EcSdkNoRoom,
                    ErrMsg  = "无房间信息"
                };
                var res = new DecodeRspResult(rspWrap1, null, null);
                this.SendFrameResponse(false, res, callback);
                return("");
            }
            this.AutoCheckLogin();

            var       response = new NetResponseCallback(this.SendFrameResponse);
            const int subcmd   = (int)ProtoCmd.ECmdRelaySendFrameReq;

            try {
                var seq = this.NetUtil2.Send(para, subcmd, response, callback);
                Debugger.Log("SendFrame_Para {0} {1}", para, seq);
                return(seq);
            } catch (System.Exception e) {
                Debugger.Log("Error: {0}", e.ToString());
                throw;
            }
        }
Beispiel #2
0
        // 确认登录
        public string CheckLogin(Action <ResponseEvent> callback, string tag)
        {
            if (this.RoomInfo == null || string.IsNullOrEmpty(this.RoomInfo.Id))
            {
                Debugger.Log("无房间信息");
                var rspWrap1 = new ClientSendServerRspWrap1 {
                    ErrCode = ErrCode.EcSdkNoRoom,
                    ErrMsg  = "无房间信息"
                };
                var res = new DecodeRspResult(rspWrap1, null, null);
                CheckLoginResponse(false, res, callback);
                return("");
            }
            CheckLoginStatus.SetStatus(CheckLoginStatus.StatusType.Checking);

            var       response = new NetResponseCallback(CheckLoginResponse);
            const int subcmd   = (int)ProtoCmd.ECmdCheckLoginReq;

            var para = new CheckLoginReq {
                Token   = RequestHeader.AuthKey,
                RouteId = this.RoomInfo.RouteId
            };

            var seq = this.NetUtil2.Send(para, subcmd, response, callback);

            CheckLoginStatus.SetRouteId(para.RouteId);
            Debugger.Log("CheckLogin_Para {0} {1}", para, seq);
            return(seq);
        }
Beispiel #3
0
        ////////////////////////////////////// 响应 ////////////////////////////////////
        private void LoginResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            if (send)
            {
                UserStatus.SetStatus(UserStatus.StatusType.Logout);
            }

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

            Debugger.Log("LoginResponse {0}", eve);

            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);
        }
Beispiel #4
0
        ///////////////////////////////// 响应 //////////////////////////////////

        // 多人复杂匹配
        private void MatchUsersComplexResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            callback?.Invoke(eve);
            Responses.MatchPlayersRsp(eve);
            return;
        }
Beispiel #5
0
        private void StopFrameSyncResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            callback?.Invoke(eve);
            Responses.StopFrameSyncRsp(eve);
            return;
        }
Beispiel #6
0
        private static void SendMessageExtResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            callback?.Invoke(eve);
            Responses.SendToGameSvrRsp(eve);
            return;
        }
Beispiel #7
0
        private void ChangeCustomGroupPlayerStatusResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            Debugger.Log("ChangeCustomGroupPlayerStatusResponse {0}", eve);
            callback?.Invoke(eve);
            return;
        }
Beispiel #8
0
        private void SendToGroupClientResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            Debugger.Log("SendToGroupClientResponse {0}", eve);
            callback?.Invoke(eve);
            return;
        }
Beispiel #9
0
        private static void StartFrameSyncResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            Debugger.Log("StartFrameSyncResponse {0}", eve);
            callback?.Invoke(eve);
            return;
        }
Beispiel #10
0
        // 查询房间详情
        private void GetRoomByRoomIdRsp(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            Debugger.Log("GetRoomByRoomIdRsp {0}", eve);
            callback?.Invoke(eve);
            return;
        }
Beispiel #11
0
        private void ChangeUserStateResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var wrap1 = res.RspWrap1;
            var rsp   = (ChangeCustomPlayerStatusRsp)res.Body;
            var eve   = new ResponseEvent(wrap1.ErrCode, wrap1.ErrMsg, wrap1.Seq, rsp);

            Debugger.Log("ChangeUserStateResponse {0}", eve);

            callback?.Invoke(eve);
        }
Beispiel #12
0
        private void ChangeUserStateResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var wrap1 = res.RspWrap1;
            var rsp   = new ChangeCustomPlayerStatusRsp();

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

            callback?.Invoke(eve);
            Responses.ChangeCustomPlayerStatusRsp(eve);
        }
Beispiel #13
0
        private static void CheckLoginResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            CheckLoginStatus.SetStatus(CheckLoginStatus.StatusType.Offline);
            var rspWrap1 = res.RspWrap1;
            var eve      = new ResponseEvent(rspWrap1.ErrCode, rspWrap1.ErrMsg, rspWrap1.Seq, res.Body);

            if (eve.Code == ErrCode.EcOk)
            {
                CheckLoginStatus.SetStatus(CheckLoginStatus.StatusType.Checked);
            }
            callback?.Invoke(eve);
            return;
        }
Beispiel #14
0
        ///////////////////////////////// 请求 //////////////////////////////////
        // 帧同步开始
        public string StartFrameSync(StartFrameSyncReq para, Action <ResponseEvent> callback)
        {
            if (this.RoomInfo == null || string.IsNullOrEmpty(this.RoomInfo.Id))
            {
                var rspWrap1 = new ClientSendServerRspWrap1 {
                    ErrCode = ErrCode.EcSdkNoRoom,
                    ErrMsg  = "无房间信息"
                };
                var res = new DecodeRspResult(rspWrap1, null, null);
                StartFrameSyncResponse(false, res, callback);
                return("");
            }
            this.AutoCheckLogin();

            var       response = new NetResponseCallback(StartFrameSyncResponse);
            const int subcmd   = (int)ProtoCmd.ECmdStartFrameSyncReq;
            var       seq      = this.NetUtil1.Send(para.ToByteString(), subcmd, response, callback);

            return(seq);
        }
Beispiel #15
0
        ///////////////////////////////// PONG //////////////////////////////////
        private void HandlePong(bool send, DecodeRspResult res, DateTime startTime)
        {
            PongTimer.Stop();

            Debugger.Log("Pong {0} {1} {2}", this.Id, res.RspWrap1.Seq, send);

            if (!send)
            {
                this.HandlePongTimeout(res.RspWrap1.Seq);
                return;
            }

            this.Retry = MaxPingRetry;
            // 清空发送队列
            this.client.ClearQueue();

            // 心跳的错误码单独处理
            var errCode = res.RspWrap1.ErrCode;

            // 上报心跳时延
            if (this.Id == 1 && errCode == ErrCode.EcOk)
            {
                EventUpload.PushPingEvent(new PingEventParam(Convert.ToInt64((DateTime.Now - startTime).TotalMilliseconds)));
            }

            if (IsTokenError(errCode))
            {
                UserStatus.SetStatus(UserStatus.StatusType.Logout);
                this.client.Socket.Emit("autoAuth", new SocketEvent());
                return;
            }

            if (IsRelayConnectError(errCode) && this.client.Socket.Id == (int)ConnectionType.Relay)
            {
                CheckLoginStatus.SetStatus(CheckLoginStatus.StatusType.Offline);
                this.client.Socket.Emit("autoAuth", new SocketEvent());
                return;
            }

            this.PingTimer.SetTimer(() => this.Ping(null), this.Timeout);
        }
Beispiel #16
0
        // 发送自定义服务消息
        public string SendMessageExt(SendToGameSvrReq para, Action <ResponseEvent> callback)
        {
            if (this.RoomInfo == null || string.IsNullOrEmpty(this.RoomInfo.Id))
            {
                var rspWrap1 = new ClientSendServerRspWrap1 {
                    ErrCode = ErrCode.EcSdkNoRoom,
                    ErrMsg  = "无房间信息"
                };
                var res = new DecodeRspResult(rspWrap1, null, null);
                SendMessageExtResponse(false, res, callback);
                return("");
            }
            this.AutoCheckLogin();

            var       response = new NetResponseCallback(SendMessageExtResponse);
            const int subcmd   = (int)ProtoCmd.ECmdRelayClientSendtoGamesvrReq;
            var       seq      = this.NetUtil2.Send(para, subcmd, response, callback);

            Debugger.Log("SendMessageExt_Para {0} {1}", para, seq);
            return(seq);
        }
Beispiel #17
0
        // 请求补帧
        public string RequestFrame(RequestFrameReq para, Action <ResponseEvent> callback)
        {
            if (this.RoomInfo == null || string.IsNullOrEmpty(this.RoomInfo.Id))
            {
                var rspWrap1 = new ClientSendServerRspWrap1 {
                    ErrCode = ErrCode.EcSdkNoRoom,
                    ErrMsg  = "无房间信息"
                };
                var res = new DecodeRspResult(rspWrap1, null, null);
                RequestFrameResponse(false, res, callback);
                return("");
            }
            this.AutoCheckLogin();

            var       response = new NetResponseCallback(RequestFrameResponse);
            const int subcmd   = (int)ProtoCmd.ECmdRelayRequestFrameReq;
            var       seq      = this.NetUtil2.Send(para.ToByteString(), subcmd, response, callback);

            // Debugger.Log ("REQUESTFRAME_Para {0} {1}", para, seq);
            return(seq);
        }
Beispiel #18
0
        private static void LogoutResponse(bool send, DecodeRspResult res, Action <ResponseEvent> callback)
        {
            var wrap1 = res.RspWrap1;
            var eve   = new ResponseEvent(wrap1.ErrCode, wrap1.ErrMsg, wrap1.Seq, null);

            Debugger.Log("LogoutResponse {0}", eve);

            void HandleSuccess()
            {
                RequestHeader.AuthKey  = null;
                RequestHeader.PlayerId = null;

                UserStatus.SetStatus(UserStatus.StatusType.Logout);

                var playerInfo = new PlayerInfo {
                    Id = null
                };

                GamePlayerInfo.SetInfo(playerInfo);
            }

            NetClient.HandleSuccess(eve.Code, HandleSuccess);
            callback?.Invoke(eve);
        }