/// <summary>
        /// BS请求验证登陆的客户端是否合法
        /// </summary>
        private ErrorCode MsgHandleOneClientLoginCheck(byte[] data, int offset, int size, int msgID)
        {
            GCToBS.OneClinetLogin oneClientLogin = new GCToBS.OneClinetLogin();
            oneClientLogin.MergeFrom(data, offset, size);

            string sessionID = string.Empty;

            if (oneClientLogin.Plat == ( uint )UserPlatform.PC)
            {
                sessionID += oneClientLogin.Plat;
                sessionID += oneClientLogin.Uin;
            }
            else
            {
                sessionID = oneClientLogin.Sessionid;
            }

            LoginUserInfo loginUserInfo = LS.instance.sdkConnector.GetLoginUserInfo(sessionID);

            if (loginUserInfo != null)
            {
                oneClientLogin.LoginSuccess = 1;
                oneClientLogin.Uin          = loginUserInfo.uin;
                LS.instance.sdkConnector.RemoveLoginUserInfo(sessionID);
                Logger.Log($"vaild uid:{oneClientLogin.Uin}");
            }
            else
            {
                Logger.Warn($"fail! user with uin({oneClientLogin.Uin}) not found.");
                oneClientLogin.LoginSuccess = 0;
            }
            //回应BS该登陆的客户端是否合法
            this.owner.SendMsgToSession(this.id, oneClientLogin, ( int )LSToBS.MsgID.EMsgToBsfromLsOneClinetLoginCheckRet);
            return(ErrorCode.Success);
        }
Example #2
0
        /// <summary>
        /// LS回应BS的检查登陆合法性
        /// </summary>
        private ErrorCode MsgUserLogin(byte[] data, int offset, int size, int msgID)
        {
            GCToBS.OneClinetLogin userLoginInfo = new GCToBS.OneClinetLogin();
            userLoginInfo.MergeFrom(data, offset, size);

            //发送第3消息:验证登陆是否成功,如果成功,请求分配GS给客户端
            BSToGC.ClinetLoginCheckRet msg = new BSToGC.ClinetLoginCheckRet();
            msg.LoginSuccess = userLoginInfo.LoginSuccess;
            this.owner.SendMsgToSession(userLoginInfo.Nsid, msg, ( int )BSToGC.MsgID.EMsgToGcfromBsOneClinetLoginCheckRet);

            Logger.Log($"user({userLoginInfo.Uin})({userLoginInfo.Sessionid})({userLoginInfo.Nsid}) ask login ret");

            if (userLoginInfo.LoginSuccess == 0)
            {
                this.owner.DisconnectOne(userLoginInfo.Nsid);
            }
            else
            {
                //找到最空闲的网关服务器
                OneGsInfo littleOne = null;
                foreach (KeyValuePair <int, OneGsInfo> kv in BS.instance.bsConfig.allGsInfo)
                {
                    OneGsInfo theGsInfo = kv.Value;
                    if (theGsInfo.gs_isLost)
                    {
                        continue;
                    }
                    if (littleOne == null || theGsInfo.gs_gc_count < littleOne.gs_gc_count)
                    {
                        littleOne = theGsInfo;
                    }
                }

                if (littleOne == null)
                {
                    return(ErrorCode.GSNotFound);
                }

                ++littleOne.gs_gc_count;                //仅仅作为缓存,GS会定时汇报服务器的状态

                //这条消息的路由:BS-GS-BS-GC
                BSToGS.OneUserLoginToken oneUserLoginToken = new BSToGS.OneUserLoginToken
                {
                    Gateclient = ( int )userLoginInfo.Nsid,
                    Token      = GuidHash.GetString(),
                    UserName   = userLoginInfo.Uin,
                    //这里ip和port最终会到达GC
                    Ip   = littleOne.gs_IpExport,
                    Port = littleOne.gs_Port
                };
                //通知网关服务器有客户端登陆
                this.owner.SendMsgToSession(littleOne.gs_nets, oneUserLoginToken, ( int )BSToGS.MsgID.EMsgToGsfromBsOneUserLoginToken);
            }
            return(ErrorCode.Success);
        }
        private ErrorCode MSGOneClientLogin(byte[] data, int offset, int size, int msgID)
        {
            //收到第2消息:客户端连接BS,向LS请求客户端是否合法登陆
            GCToBS.OneClinetLogin oneClientLogin = new GCToBS.OneClinetLogin();
            oneClientLogin.MergeFrom(data, offset, size);

            Logger.Log($"user({oneClientLogin.Uin})({oneClientLogin.Sessionid})({this.id}) ask login bs");
            oneClientLogin.Nsid = this.id;

            this.owner.SendMsgToSession(SessionType.ClientB2L, oneClientLogin, ( int )BSToLS.MsgID.EMsgToLsfromBcOneClinetLoginCheck);

            return(ErrorCode.Success);
        }