예제 #1
0
        /// <summary>
        /// GS请求CS,验证GC登陆的合法性
        /// </summary>
        public ErrorCode OnGs2CsGcaskLogin(NetSessionBase session, IMessage message)
        {
            Protos.GS2CS_GCAskLogin request  = (Protos.GS2CS_GCAskLogin)message;
            Protos.CS2GS_GCLoginRet response = ProtoCreator.R_GS2CS_GCAskLogin(request.Opts.Pid);

            //创建玩家并上线
            CSUser user = CS.instance.userMgr.Online(request.SessionID, session.id, session.logicID);

            if (user == null)
            {
                //非法登陆
                response.Result = Protos.CS2GS_GCLoginRet.Types.EResult.IllegalLogin;
            }
            else
            {
                response.UserInfo = new Protos.G_UserInfo
                {
                    Ukey     = user.ukey,
                    GcNID    = user.gcNID,
                    OpenID   = user.openID,
                    Nickname = user.nickname,
                    Avatar   = user.avatar,
                    Gender   = user.gender,
                    Rank     = user.rank,
                    Money    = user.money,
                    Diamoned = user.diamoned,
                    Exp      = user.exp,
                };
                response.UserInfo.Champions.AddRange(user.champions);

                //检查玩家是否在战场
                if (user.isInBattle)
                {
                    //检查是否存在BS信息(可能当玩家上线时,BS已丢失)
                    //这里理应不会成功断言,因为BS丢失时会把玩家从战场暂存器里移除
                    INetSession bsSession = CS.instance.netSessionMgr.GetSession(user.bsSID);
                    System.Diagnostics.Debug.Assert(bsSession != null, $"can not find BS:{user.bsSID}");

                    CS.instance.lIDToBSInfos.TryGetValue((( BattleSession )bsSession).logicID, out BSInfo bsInfo);
                    System.Diagnostics.Debug.Assert(bsInfo != null, $"can not find BS:{( ( BattleSession )bsSession ).logicID}");
                    response.GcState = Protos.CS2GS_GCLoginRet.Types.EGCCState.Battle;
                    response.GcNID   = user.ukey | ( ulong )bsInfo.lid << 32;
                    response.BsIP    = bsInfo.ip;
                    response.BsPort  = bsInfo.port;
                }
                response.Result = Protos.CS2GS_GCLoginRet.Types.EResult.Success;
            }
            session.Send(response);
            return(ErrorCode.Success);
        }
예제 #2
0
파일: GCBiz.cs 프로젝트: niuniuzhu/KOW
        private static void OnCS2GSAskLoginRet(NetSessionBase session, Google.Protobuf.IMessage message, object[] args)
        {
            uint sid = ( uint )args[0];

            Protos.GC2GS_AskLogin login = (Protos.GC2GS_AskLogin)args[1];

            Protos.CS2GS_GCLoginRet csLoginRet = (Protos.CS2GS_GCLoginRet)message;
            Protos.GS2GC_LoginRet   gsLoginRet = ProtoCreator.R_GC2GS_AskLogin(login.Opts.Pid);
            switch (csLoginRet.Result)
            {
            case Protos.CS2GS_GCLoginRet.Types.EResult.Success:
                //检测客户端是否断线了
                ClientSession gcSession = GS.instance.netSessionMgr.GetSession(sid) as ClientSession;
                if (gcSession == null)
                {
                    //通知CS客户端断开了
                    Protos.GS2CS_GCLost gcLost = ProtoCreator.Q_GS2CS_GCLost();
                    gcLost.SessionID = login.SessionID;
                    GS.instance.netSessionMgr.Send(SessionType.ServerG2CS, gcLost);
                    return;
                }

                //添加到管理器
                GS.instance.userMgr.AddClient(login.SessionID, sid);

                //设置该Session为受信任的连接
                gcSession.accredited = true;

                gsLoginRet.Result   = Protos.GS2GC_LoginRet.Types.EResult.Success;
                gsLoginRet.GcNID    = csLoginRet.GcNID;
                gsLoginRet.GcState  = (Protos.GS2GC_LoginRet.Types.EGCCState)csLoginRet.GcState;
                gsLoginRet.UserInfo = csLoginRet.UserInfo;
                gsLoginRet.BsIP     = csLoginRet.BsIP;
                gsLoginRet.BsPort   = csLoginRet.BsPort;
                gsLoginRet.Defs     = Defs.binary;
                GS.instance.netSessionMgr.Send(sid, gsLoginRet);
                break;

            case Protos.CS2GS_GCLoginRet.Types.EResult.IllegalLogin:
                gsLoginRet.Result = Protos.GS2GC_LoginRet.Types.EResult.SessionExpire;
                GS.instance.netSessionMgr.Send(sid, gsLoginRet);
                GS.instance.netSessionMgr.CloseSession(sid, "client login failed");
                break;
            }
        }