private void InsertNewUserToMysql(GCToCS.Login login, CSUser user)
        {
            if (user == null)
            {
                return;
            }

            CSToDB.ExeSQL_Call sqlCall = new CSToDB.ExeSQL_Call
            {
                Sql = $"insert account_user(id,cs_id,sdk_id,cdkey) values({user.guid},{CS.instance.csKernelCfg.unCSId},{login.Sdk},\'{login.Name}\');"
            };
            this._cdkeyWrapper.EncodeAndSendToDBThread(sqlCall, ( int )CSToDB.MsgID.EExeSqlCall);

            string op =
                $"insert gameuser(obj_id,sdk_id,obj_cdkey, obj_register_time) values({user.guid},{login.Sdk},\'{login.Name}\',{user.userDbData.usrDBData.tRegisteUTCMillisec});" +
                $"insert gameuser_runne(user_id) values({user.guid});" +
                $"insert gameuser_guide(obj_id) values({user.guid});";

            CSToDB.UpdateUser updateUser = new CSToDB.UpdateUser
            {
                Sqlstr = op,
                Guid   = ( long )user.guid
            };
            this._userCacheDBActiveWrapper.EncodeAndSendToDBThread(updateUser, ( int )CSToDB.MsgID.EUpdateUserDbcallBack);
        }
Exemple #2
0
        private ErrorCode DBAsynQueryUserCallBack(GBuffer buffer, DBActiveWrapper db)
        {
            CSToDB.QueryUserReq msg = new CSToDB.QueryUserReq();
            msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length);

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

            UserDBData userDbData = new UserDBData();

            userDbData.usrDBData.un64ObjIdx   = ( ulong )msg.Objid;
            userDbData.usrDBData.userPlatform = ( UserPlatform )login.Sdk;

            DBToCS.QueryUser queryUser = new DBToCS.QueryUser();
            this.DBAsynQueryUser(userDbData, queryUser, db);

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, userDbData.usrDBData);
                queryUser.Db       = Encoding.UTF8.GetString(ms.GetBuffer(), 0, ( int )ms.Length);
                queryUser.Login    = msg.Logininfo;
                queryUser.Gcnetid  = msg.Gcnetid;
                queryUser.Gsid     = msg.Gsid;
                queryUser.Nickname = userDbData.szNickName;
            }
            CS.instance.userMgr.EncodeAndSendToLogicThread(queryUser, ( int )DBToCS.MsgID.EQueryUserDbcallBack);
            return(ErrorCode.Success);
        }
Exemple #3
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);
        }
Exemple #4
0
 public void AskLoginToGateServer()
 {
     GCToCS.Login msg = new GCToCS.Login
     {
         sdk        = (Int32)SdkManager.Instance.PlatformType,
         platform   = 0,
         equimentid = "",  // todo
         name       = GameServerData.Instance.GateServerUin,
         passwd     = GameServerData.Instance.ServerToken,
     };
     NetworkManager.Instance.SendMsg(msg, (int)msg.msgnum);
 }
Exemple #5
0
 public void AskLogin()
 {
     //请求登录  返回用户信息
     GCToCS.Login pMsg = new GCToCS.Login
     {
         sdk        = 10,//ToReview 平台写死为10?
         platform   = 0,
         equimentid = MacAddressIosAgent.GetMacAddressByDNet(),
         name       = "1", /* SelectServerData.Instance.gateServerUin*/
         passwd     = "1", /* SelectServerData.Instance.GateServerToken*/
     };
     NetworkManager.Instance.SendMsg(pMsg, (int)pMsg.msgnum);
 }
        private ErrorCode OnMsgToGstoCsfromGcAskLogin(CSGSInfo csgsInfo, uint gcNetID, byte[] data, int offset, int size)
        {
            GCToCS.Login login = new GCToCS.Login();
            login.MergeFrom(data, offset, size);
            Logger.Log($"--new login({login.Name})--");
            ErrorCode errorCode = this.UserAskLogin(csgsInfo, gcNetID, login);

            if (ErrorCode.Success != errorCode)
            {
                this.PostMsgToGCAskReturn(csgsInfo, gcNetID, ( int )GCToCS.MsgNum.EMsgToGstoCsfromGcAskLogin, errorCode);
            }
            return(ErrorCode.Success);
        }
Exemple #7
0
        /// <summary>
        /// 客户端请求登录网关服务器
        /// </summary>
        private ErrorCode OnMsgToGstoCsfromGcAskLogin(byte[] data, int offset, int size, int msgID)
        {
            if (!this._logicInited)
            {
                this.SetInited(true, true);
            }

            bool logMsgFlag = false;

            GCToCS.Login loginMsg = new GCToCS.Login();

            GCToCS.Login login = new GCToCS.Login();
            login.MergeFrom(data, offset, size);

            //验证token
            //正常登录流程是连接到登录服务器,再通过负载均衡服务器把消息转发给合适的网关服务器
            //如果客户端绕过上述过程直接连接网关服务器并请求登录,则是非法操作
            if (!GS.instance.gsStorage.IsUserCanLogin(login.Name, login.Passwd, this.id))
            {
                Logger.Error($"user {login.Name} can't login with token {login.Passwd}");
                GSToGC.NetClash msg = new GSToGC.NetClash();
                //断开连接
                GS.instance.PostToGameClient(this.id, msg, ( int )GSToGC.MsgID.EMsgToGcfromGsNotifyNetClash);
                GS.instance.PostGameClientDisconnect(this.id);
                return(ErrorCode.Success);
            }
            //获取IP
            INetSession pClient = GS.instance.GetSession(this.id);

            if (null != pClient)
            {
                EndPoint endPoint = pClient.connection.remoteEndPoint;
                if (endPoint == null)
                {
                    Logger.Error($"user {login.Name} can't login with IP is null");
                    GS.instance.PostGameClientDisconnect(this.id);
                    return(ErrorCode.Success);
                }
                logMsgFlag          = true;
                loginMsg.Platform   = login.Platform;
                loginMsg.Sdk        = login.Sdk;
                loginMsg.Name       = login.Name;
                loginMsg.Passwd     = login.Passwd;
                loginMsg.Equimentid = login.Equimentid;
                loginMsg.Ipaddress  = endPoint.ToString();
                Logger.Log($"client({this.id}) ask login({loginMsg.Name})({loginMsg.Passwd})");
            }
            //把登录信息转发到中心服务器
            this.TransToCS(this.id, data, offset, size, msgID, logMsgFlag, loginMsg);
            return(ErrorCode.Success);
        }
Exemple #8
0
        public void OnOnline(UserNetInfo netInfo, GCToCS.Login login, bool isFirstInDB, bool isFirstInMem, bool isReLogin = false)
        {
            this.KickOutOldUser();
            this.ResetPingTimer();
            this.LoginRewardInit();
            if (!isReLogin)
            {
                this.userDbData.ChangeUserDbData(UserDBDataType.Channel, login.Platform);
            }
            CS.instance.userMgr.OnUserOnline(this, netInfo);
            this.NotifyUserPlayState();
            this.SynUserIsOnSS();
            this.SynUser_UserBaseInfo();
            this.SynCommidityCfgInfo();
            this.SynUserCLDays();
            this.SynUserAllHeroList();
            //todo
            //SynUser_AllRunesList();
            //CalculateItemAddition();
            //SynOtherItemInfo( 0 );
            //GetCSUserMgrInstance().PostUserCurtMailList( this );
            this.SynUserSNSList(0, RelationShip.Friends);
            this.SynUserSNSList(0, RelationShip.Detestation);
            //PosUserCSCurtGuideSteps();
            //GetTaskMgr().NotifyAllTask();
            if (!isFirstInDB)
            {
                this.PostCSNotice();
            }

            //if ( isReLogin )
            //	CSSGameLogMgr::GetInstance().AddGameLog( eLog_UserRecon, this.GetUserDBData().usrDBData.un64ObjIdx, 0 );

            //if ( GetUserBattleInfoEx().GetBattleState() < eBattleState_Async )
            //{//由cs进行管理//
            //	if ( GetUserBattleInfoEx().GetBattleState() != eBattleState_Free )
            //	{
            //		Logger.Error( &"战斗类型(%u)战斗状态(%u)战斗ID(%u)房间(%u)队伍(%u)",
            //			  GetUserBattleInfoEx().GetBattleType(),
            //			  GetUserBattleInfoEx().GetBattleState(),
            //			  GetUserBattleInfoEx().GetBattleID(),
            //			  GetRoomPlayer().m_RoomID, GetMatchPlayer().m_MatchTeamId );
            //		Assert( false );
            //	}
            //}
            //else
            //{//由ss进行管理,只通知ss一下//
            //GetBattleMgrInstance().NotifyBattleSSUserIsOnline( this, true );
            //}
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
0
        private ErrorCode TransToCS(uint nsID, byte[] data, int offset, int size, int msgID, bool logMsgFlag, GCToCS.Login loginMsg)
        {
            //确保已经连接到中心服务器
            if (GS.instance.gsStorage.csNetSessionId > 0)
            {
                if (logMsgFlag)
                {
                    byte[] data2 = loginMsg.ToByteArray();
                    GS.instance.TranMsgToSession(SessionType.ClientG2C, data2, 0, data2.Length, msgID, ( int )GSToCS.MsgID.EMsgToCsfromGsReportGcmsg, nsID);
                }
                else
                {
                    GS.instance.TranMsgToSession(SessionType.ClientG2C, data, offset, size, msgID, ( int )GSToCS.MsgID.EMsgToCsfromGsReportGcmsg, nsID);
                }

                return(ErrorCode.Success);
            }
            Logger.Warn($"invalid CSNetSessionId:{GS.instance.gsStorage.csNetSessionId}");
            return(ErrorCode.InvalidNSID);
        }