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); }
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); }
/// <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); }
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); }
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); }