Exemplo n.º 1
0
        public override int ProcessReLoginRequest(ReLogin rpc)
        {
            Session session = Session.Get(rpc);

            BAccount account = _taccount.Get(session.Account);

            if (null == account)
            {
                return(ReturnCode(ResultCodeAccountNotExist));
            }

            if (account.LastLoginRoleId != rpc.Argument.RoleId)
            {
                return(ReturnCode(ResultCodeNotLastLoginRoleId));
            }

            BRoleData role = _trole.Get(rpc.Argument.RoleId);

            if (null == role)
            {
                return(ReturnCode(ResultCodeRoleNotExist));
            }

            BOnline online = _tonline.Get(rpc.Argument.RoleId);

            if (null == online)
            {
                return(ReturnCode(ResultCodeOnlineDataNotFound));
            }

            online.LinkName = session.LinkName;
            online.LinkSid  = session.SessionId;
            online.State    = BOnline.StateOnline;

            // 先发结果,再发送同步数据(ReliableNotifySync)。
            // 都使用 WhileCommit,如果成功,按提交的顺序发送,失败全部不会发送。
            session.SendResponseWhileCommit(rpc);
            Transaction.Current.RunWhileCommit(() =>
            {
                var setUserState = new gnet.Provider.SetUserState();
                setUserState.Argument.LinkSid = session.SessionId;
                setUserState.Argument.States.Add(rpc.Argument.RoleId);
                rpc.Sender.Send(setUserState); // 直接使用link连接。
            });

            var syncResultCode = ReliableNotifySync(
                session, rpc.Argument.ReliableNotifyConfirmCount,
                online);

            if (syncResultCode != ResultCodeSuccess)
            {
                return(ReturnCode((ushort)syncResultCode));
            }

            App.Load.LoginCount.IncrementAndGet();
            return(Procedure.Success);
        }
Exemplo n.º 2
0
        public override int ProcessLoginRequest(Login rpc)
        {
            Session session = Session.Get(rpc);

            BAccount account = _taccount.Get(session.Account);

            if (null == account)
            {
                return(ReturnCode(ResultCodeAccountNotExist));
            }

            account.LastLoginRoleId = rpc.Argument.RoleId;
            BRoleData role = _trole.Get(rpc.Argument.RoleId);

            if (null == role)
            {
                return(ReturnCode(ResultCodeRoleNotExist));
            }

            BOnline online = _tonline.GetOrAdd(rpc.Argument.RoleId);

            online.LinkName = session.LinkName;
            online.LinkSid  = session.SessionId;
            online.State    = BOnline.StateOnline;

            online.ReliableNotifyConfirmCount = 0;
            online.ReliableNotifyTotalCount   = 0;
            online.ReliableNotifyMark.Clear();
            online.ReliableNotifyQueue.Clear();

            var linkSession = session.Link.UserState as Game.Server.LinkSession;

            online.ProviderId        = App.Zeze.Config.AutoKeyLocalId;
            online.ProviderSessionId = linkSession.ProviderSessionId;

            // 先提交结果再设置状态。
            // see linkd::gnet.Provider.ModuleProvider。ProcessBroadcast
            session.SendResponseWhileCommit(rpc);
            Transaction.Current.RunWhileCommit(() =>
            {
                var setUserState = new gnet.Provider.SetUserState();
                setUserState.Argument.LinkSid = session.SessionId;
                setUserState.Argument.States.Add(rpc.Argument.RoleId);
                rpc.Sender.Send(setUserState); // 直接使用link连接。
            });
            App.Load.LoginCount.IncrementAndGet();
            return(Procedure.Success);
        }
Exemplo n.º 3
0
        public override int ProcessLogoutRequest(Logout rpc)
        {
            Session session = Session.Get(rpc);

            if (session.RoleId == null)
            {
                return(ReturnCode(ResultCodeNotLogin));
            }

            _tonline.Remove(session.RoleId.Value);

            // 先设置状态,再发送Logout结果。
            Transaction.Current.RunWhileCommit(() =>
            {
                var setUserState = new gnet.Provider.SetUserState();
                setUserState.Argument.LinkSid = session.SessionId;
                rpc.Sender.Send(setUserState); // 直接使用link连接。
            });
            session.SendResponseWhileCommit(rpc);
            // 在 OnLinkBroken 时处理。可以同时处理网络异常的情况。
            // App.Load.LogoutCount.IncrementAndGet();
            return(Procedure.Success);
        }