Пример #1
0
        public virtual void connect_rpc_Handle(SessionDisconnectNotify disconnect)
        {
            //log.Log("Disconnect");
            last_heartbeat         = DateTime.Now;
            disconnect.sessionName = SelfAddress.ServiceName;
            if (enter_game != null)
            {
                disconnect.roleID = enter_game.c2s_roleUUID;
            }

            //             var area = remote_area_service;
            //             if (area != null)
            //             {
            //                 area.Invoke(disconnect);
            //             }
            //排除老Session踢下线导致的Disconnect//
            if (this.session == null || disconnect.socketID == this.session.socket.ID)
            {
                this.session = null;
                var logic = this.remote_logic_service;
                if (logic != null)
                {
                    mDisconnected = true;
                    logic.Invoke(disconnect);
                }
            }
        }
Пример #2
0
        public virtual async Task <LocalBindSessionResponse> connect_rpc_Handle(LocalBindSessionRequest bind)
        {
            if (!string.IsNullOrEmpty(bind.enter.c2s_session_token) && !string.IsNullOrEmpty(this.sessionToken) &&
                bind.enter.c2s_session_token != this.sessionToken)
            {
                this.sessionToken = null;
                return(new LocalBindSessionResponse()
                {
                    s2c_code = Response.CODE_ERROR
                });
            }

            var savedLoginToken = await accountSave.LoadFieldAsync <string>(nameof(AccountData.lastLoginToken));

            var savedServerGroup = await accountSave.LoadFieldAsync <string>(nameof(AccountData.lastLoginServerGroupID));

            if (savedLoginToken != bind.enter.c2s_login_token)
            {
                this.sessionToken = null;
                return(new LocalBindSessionResponse()
                {
                    s2c_code = Response.CODE_ERROR
                });
            }

            var old_session = this.session;

            if (old_session != null)
            {
                var disconnect = new SessionDisconnectNotify()
                {
                    socketID    = old_session.socket.ID,
                    sessionName = SelfAddress.ServiceName,
                };
                if (enter_game != null)
                {
                    disconnect.roleID = enter_game.c2s_roleUUID;
                }

                //老Session暂停发包//
                var logic = this.remote_logic_service;
                if (logic != null)
                {
                    logic.Invoke(disconnect);
                }

                //log.Log("Reconnect");
                //老Session踢下线//
                old_session.socket.Disconnect("New Session Reconnect");
            }
            else
            {
                //log.Log("Connect");
            }

            this.session = bind.session;
            this.enter   = bind.enter;
            //登录成功后,产生新的Token用于断线重连//
            this.sessionToken   = Guid.NewGuid().ToString();
            this.last_heartbeat = DateTime.Now;

            return(new LocalBindSessionResponse()
            {
                session = this,
                sessionToken = sessionToken,
                serverGroupID = savedServerGroup,
            });
        }