Пример #1
0
        private ErrorCode UserAskReconnectGame(CSGSInfo csgsInfo, uint gcNetID, string name, string passwd)
        {
            UserNetInfo netinfo = new UserNetInfo(csgsInfo.m_n32GSID, gcNetID);

            if (this.ContainsUser(netinfo))
            {
                return(ErrorCode.InvalidNetState);
            }

            //需要从消息获取
            const int      sdkID           = 0;
            UserCombineKey sUserCombineKey = new UserCombineKey(name, sdkID);

            if (!this.allUserName2GuidMap.TryGetValue(sUserCombineKey, out ulong guid))
            {
                return(ErrorCode.NullUser);
            }

            CSUser pcUser = this.GetUser(guid);

            if (null == pcUser)
            {
                return(ErrorCode.NullUser);
            }

            GCToCS.Login login = new GCToCS.Login();
            pcUser.OnOnline(netinfo, login, false, false, true);
            return(ErrorCode.Success);
        }
Пример #2
0
        private ErrorCode OnRedisQueryUser(Task <RedisValue> task, object state)
        {
            CSToDB.QueryUserReq pQueryUser = (CSToDB.QueryUserReq)state;
            ErrorCode           res;

            do
            {
                //这里为什么还要检测一次?
                UserNetInfo netinfo = new UserNetInfo(pQueryUser.Gsid, ( uint )pQueryUser.Gcnetid);
                if (this.ContainsUser(netinfo))
                {
                    res = ErrorCode.InvalidNetState;
                    break;
                }

                GCToCS.Login sLoginMsg = new GCToCS.Login();
                sLoginMsg.MergeFrom(ByteString.CopyFromUtf8(pQueryUser.Logininfo));

                CSUser pcUser = this.GetUser(( ulong )pQueryUser.Objid);
                if (null != pcUser)
                {
                    pcUser.OnOnline(netinfo, sLoginMsg, false, false);
                    return(ErrorCode.Success);
                }

                if (task.Result.IsNullOrEmpty || !task.Result.HasValue)
                {
                    Logger.Error("Null Reply");
                    res = ErrorCode.RedisReplyNil;
                    break;
                }

                UserDBData userDbData;
                using (MemoryStream ms = new MemoryStream(task.Result))
                {
                    userDbData = Serializer.Deserialize <UserDBData>(ms);
                }
                userDbData.usrDBData.un64ObjIdx = ( ulong )pQueryUser.Objid;
                userDbData.szUserName           = sLoginMsg.Name;

                pcUser = new CSUser();
                pcUser.LoadDBData(userDbData);
                //todo
                //pcUser.GetUserBattleInfoEx().mDebugName = userDbData.szUserName;
                //pcUser.GetUserDBData().guideSteps.szCSContinueGuide = dbUserCache.guideStr;

                res = this.AddUser(pcUser);
                if (res != ErrorCode.Success)
                {
                    Logger.Error("add user fail!");
                    return(res);
                }

                pcUser.OnOnline(netinfo, sLoginMsg, false, true);
                this.RemoveUserFromRedisLRU(pcUser);
            } while (false);

            if (res != ErrorCode.Success)
            {
                Logger.Log("没命中cache,查询数据库");
                //todo
                //GetNowWorkActor().EncodeAndSendToDBThread( pQueryUser, CSToDB.MsgID.EQueryUserDbcallBack );
            }
            return(ErrorCode.Success);
        }
Пример #3
0
        private ErrorCode SynHandleQueryUserCallback(GBuffer buffer)
        {
            DBToCS.QueryUser msg = new DBToCS.QueryUser();
            msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length);

            GCToCS.Login login = new GCToCS.Login();
            login.MergeFrom(ByteString.CopyFromUtf8(msg.Login));

            UserNetInfo netInfo = new UserNetInfo(msg.Gsid, ( uint )msg.Gcnetid);

            if (this.ContainsUser(netInfo))
            {
                Logger.Warn("invalid netInfo");
                return(ErrorCode.InvalidNetState);
            }

            UserDBData userDbData;

            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(msg.Db)))
            {
                userDbData = Serializer.Deserialize <UserDBData>(ms);
            }

            CSUser user = this.GetUser(userDbData.usrDBData.un64ObjIdx);

            if (null != user)
            {
                user.OnOnline(netInfo, login, false, false);
                return(ErrorCode.Success);
            }

            user = new CSUser();

            userDbData.szUserName             = login.Name;
            userDbData.szUserPwd              = login.Passwd;
            userDbData.szNickName             = msg.Nickname;
            userDbData.usrDBData.userPlatform = ( UserPlatform )login.Sdk;
            userDbData.szTaskData             = msg.TaskData;

            bool newUser = userDbData.usrDBData.tRegisteUTCMillisec < 1;

            user.LoadDBData(userDbData);
            user.userDbData.guideSteps.szCSContinueGuide = msg.Guidestr;

            for (int i = 0; i < msg.Rsinfo.Count; i++)
            {
                user.LoadUserSNSList(msg.Rsinfo[i]);
            }

            for (int i = 0; i < msg.ItemInfo.Count; i++)
            {
                user.AddUserItems(msg.ItemInfo[i]);
            }

            for (int i = 0; i < msg.MailInfo.Count; ++i)
            {
                CS.instance.mailMgr.UpdatePerMailList(msg.MailInfo[i].Mailid, userDbData.usrDBData.un64ObjIdx, ( MailCurtState )msg.MailInfo[i].State);
            }

            //todo
            //user.GetUserBattleInfoEx().mDebugName = pLogin.Name;

            if (!newUser)
            {
                long curTime = TimeUtils.utcTime;
                for (int i = 0; i < msg.Herocfg.Count; ++i)
                {
                    DBToCS.HeroCfg heroCfg = msg.Herocfg[i];
                    if (heroCfg.Expiredtime != Consts.PERSIST_TIME_ALWAYS && heroCfg.Expiredtime < curTime)
                    {
                        continue;
                    }

                    UserHeroDBData userHeroDbData = new UserHeroDBData(heroCfg.Commodityid, heroCfg.Expiredtime, heroCfg.Buytime);
                    user.AddHero(userHeroDbData);
                }
                for (int i = 0; i < msg.Runeinfo.Count; ++i)
                {
                    DBToCS.RuneInfo runeInfo = msg.Runeinfo[i];
                    user.InitRunes(runeInfo.BagStr, runeInfo.SlotStr);
                }
            }

            ErrorCode errorCode = this.AddUser(user);

            if (errorCode != ErrorCode.Success)
            {
                return(errorCode);
            }

            user.OnOnline(netInfo, login, newUser, true);
            return(ErrorCode.Success);
        }
Пример #4
0
        private ErrorCode UserAskLogin(CSGSInfo csgsInfo, uint gcNetID, GCToCS.Login login)
        {
            if (string.IsNullOrEmpty(login.Name) || login.Name.Length > Consts.DEFAULT_NAME_LEN)
            {
                return(ErrorCode.InvalidUserName);
            }

            UserNetInfo netinfo = new UserNetInfo(csgsInfo.m_n32GSID, gcNetID);

            if (this.ContainsUser(netinfo))
            {
                return(ErrorCode.InvalidNetState);
            }

            ErrorCode errorCode = ErrorCode.Success;

            UserCombineKey sUserCombineKey = new UserCombineKey(login.Name, login.Sdk);

            if (this.allUserName2GuidMap.TryGetValue(sUserCombineKey, out ulong guid))
            {
                //老玩家
                //如果还在内存里
                CSUser user = this.GetUser(guid);
                if (null != user)
                {
                    bool bFlag = this.CheckIfInGuideBattle(user);
                    if (bFlag)
                    {
                        Logger.Warn("新手引导玩家不允许顶号");
                        return(ErrorCode.GuideUserForbit);
                    }

                    user.OnOnline(netinfo, login, false, false);
                    return(ErrorCode.Success);
                }

                //异步查询玩家数据
                CSToDB.QueryUserReq queryUser = new CSToDB.QueryUserReq
                {
                    Logininfo = login.ToByteString().ToStringUtf8(),
                    Gsid      = csgsInfo.m_n32GSID,
                    Gcnetid   = ( int )gcNetID,
                    Csid      = ( int )CS.instance.csKernelCfg.unCSId,
                    Objid     = ( long )guid
                };
                errorCode = this.QueryUserAsync(queryUser).Result;
            }
            else
            {
                //新玩家,产生GUID
                guid = this.CombineGUID();

                CSUser     pcUser     = new CSUser();
                UserDBData userDbData = new UserDBData();
                userDbData.usrDBData.un64ObjIdx          = guid;
                userDbData.szUserName                    = login.Name;
                userDbData.szUserPwd                     = login.Passwd;
                userDbData.usrDBData.userPlatform        = ( UserPlatform )login.Sdk;
                userDbData.usrDBData.tRegisteUTCMillisec = TimeUtils.utcTime;

                //加入全局表
                this.allUserName2GuidMap.Add(sUserCombineKey, guid);

                pcUser.LoadDBData(userDbData);
                //todo
                //pcUser.userBattleInfoEx.mDebugName = login.Name;

                ErrorCode nRet = this.AddUser(pcUser);
                if (nRet != 0)
                {
                    return(nRet);
                }

                pcUser.OnOnline(netinfo, login, true, true);

                this.InsertNewUserToMysql(login, pcUser);
            }
            //todo
            //log
            //{
            //	string mystream = string.Empty;
            //	mystream << login.name() << LOG_SIGN;
            //	mystream << login.sdk() << LOG_SIGN;
            //	mystream << login.platform() << LOG_SIGN;
            //	mystream << login.equimentid() << LOG_SIGN;
            //	mystream << login.ipaddress();
            //	CSSGameLogMgr::GetInstance().AddGameLog( eLog_Login, guid, mystream.str() );
            //}
            return(errorCode);
        }