/// <summary> /// 查询玩家数据的回调函数 /// 把数据库的所有玩家数据取回内存 /// </summary> private void SynHandleAllAccountCallback(GBuffer buffer) { DBToCS.QueryAllAccount msg = new DBToCS.QueryAllAccount(); msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); for (int i = 0; i < msg.Account.Count; ++i) { DBToCS.QueryAllAccount.Types.Account pAccount = msg.Account[i]; //取回所有昵称 if (!string.IsNullOrEmpty(pAccount.Nickname)) { this.allNickNameSet.Add(pAccount.Nickname); } UserCombineKey userCombineKey; userCombineKey.sdkid = pAccount.Sdkid; userCombineKey.username = pAccount.UserName; ulong guid = ( ulong )pAccount.Guid; //取回所有guid this.allUserName2GuidMap.Add(userCombineKey, guid); if (this._maxGuid < guid) { this._maxGuid = guid; } } this._maxGuid /= GUID_Devide; Logger.Log($"load maxguid {this._maxGuid}"); }
private ErrorCode DBAsyAlterItemCallBack(GBuffer buffer, DBActiveWrapper db) { CSToDB.AlterItem msg = new CSToDB.AlterItem(); msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); return(this.DBAsynAlterUserItem(db, msg.SqlStr)); }
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 DBAsynAlterSNSList(GBuffer buffer, DBActiveWrapper db) { CSToDB.AlterSNSList msg = new CSToDB.AlterSNSList(); msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); return(this.AlterUserSNSList(db, msg.UserId, msg.RelatedId, ( RelationShip )msg.Related, ( DBOperation )msg.Opration)); }
private ErrorCode DBAsynInsertNoticeCall(GBuffer buffer, DBActiveWrapper db) { CSToDB.InsertNotice msg = new CSToDB.InsertNotice(); msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); return(db.SqlExecNonQuery(msg.SqlStr)); }
private ErrorCode DBAsynUpdateGameMail(GBuffer buffer, DBActiveWrapper db) { CSToDB.UpdateGameMail pMsg = new CSToDB.UpdateGameMail(); pMsg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); int total = pMsg.Maillist.Count; if (total <= 0) { return(ErrorCode.Success); } string[] sqlStrs = new string[3]; sqlStrs[0] = "begin; set autocommit=0;"; for (int i = 0; i < total; i++) { CSToDB.GameMailInfo mail = pMsg.Maillist[i]; if (mail.Curtstate == CSToDB.EMailCurtState.EMailStateDel) { sqlStrs[1] = $"update game_mail set mail_del_state ={mail.Curtstate} where mail_id={mail.MailId};"; } else if (mail.Curtstate == CSToDB.EMailCurtState.EMailStateNew) { sqlStrs[1] = $"insert into game_mail(mail_id,mail_sdk,mail_type,mail_user_id,mail_title,mail_content,mail_gift,mail_send,mail_create_time,mail_over_time,mail_del_state) values({mail.MailId},{mail.Sdkidx},{mail.Type},{mail.Userid},\'{mail.Title}\',\'{mail.Content}\',\'{mail.Giftstr}\',\'{mail.Sender}\',\'{mail.Createtime}\',\'{mail.Overtime}\',{mail.Curtstate});"; } } sqlStrs[2] = "commit;"; return(db.SqlExecNonQuery(sqlStrs)); }
private ErrorCode DBAsynChangeNickNameCallBack(GBuffer buffer, DBActiveWrapper db) { CSToDB.ChangeNickName sChangeNickName = new CSToDB.ChangeNickName(); sChangeNickName.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); string mystream = $"update account_user set user_name=\'{sChangeNickName.Nickname}\' where id={sChangeNickName.Guid};"; ErrorCode errorCode = db.SqlExecNonQuery(mystream); return(errorCode); }
private ErrorCode DBAsynUpdateUserCallback(GBuffer buffer, DBActiveWrapper db) { CSToDB.UpdateUser msg = new CSToDB.UpdateUser(); msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); ErrorCode errorCode = db.SqlExecNonQuery(new[] { "begin;set autocommit=0;", msg.Sqlstr, "commit;" }); if (errorCode != ErrorCode.Success) { return(errorCode); } Logger.Log($"udate user {msg.Guid} to db"); return(ErrorCode.Success); }
private void DBCallBackQueryNotice(GBuffer buffer) { DBToCS.QueryNotice msg = new DBToCS.QueryNotice(); msg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); for (int i = 0; i < msg.NoticeInfo.Count; i++) { Notice notice = new Notice(); DBToCS.QueryNotice.Types.Notice noticeInfo = msg.NoticeInfo[i]; notice.id = noticeInfo.Id; notice.platform = ( UserPlatform )noticeInfo.Platform; notice.title = noticeInfo.Title; notice.flag = ( NoticeFlag )noticeInfo.Eflag; notice.state = ( NoticeState )noticeInfo.Estate; notice.priority = ( uint )noticeInfo.Priority; notice.msg = noticeInfo.Notice_; notice.star_time = ( long )noticeInfo.StarTime; notice.end_time = ( long )noticeInfo.EndTime; this.AddNotice(notice); } }
private void SynHandleMailCallback(GBuffer buffer) { DBToCS.MailCallBack pMsg = new DBToCS.MailCallBack(); pMsg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); MailDBData mailDb = new MailDBData(); mailDb.mailId = pMsg.Mailid; mailDb.mailType = ( MailType )pMsg.Mailtype; mailDb.channelId = pMsg.Channel; mailDb.mailContent = pMsg.Content; mailDb.mailTitle = pMsg.Title; mailDb.mailGift = pMsg.Gift; mailDb.szSender = pMsg.Sender; mailDb.mCreateTime = pMsg.Createtime; //todo //mailDb.n64CreateTime = CFunction::FormatTime2TimeT( mailDb.mCreateTime ); //mailDb.n64EndTime = CFunction::FormatTime2TimeT( mailDb.mEndTime ); mailDb.objIdx = pMsg.Objid; CS.instance.mailMgr.AddGameMail(mailDb); }
private ErrorCode DBAsynUpdateUserGameMail(GBuffer buffer, DBActiveWrapper db) { CSToDB.UpdateUserMail pMsg = new CSToDB.UpdateUserMail(); pMsg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); string sqlStr = $"select id from gameuser_mail where mail_id={pMsg.Mailid} and user_id={pMsg.Objid};"; int ntotal = 0; ErrorCode errorCode = db.SqlExecQuery(sqlStr, dataReader => { ntotal = dataReader.GetInt32("id"); return(ErrorCode.Success); }); if (errorCode != ErrorCode.Success) { return(errorCode); } sqlStr = ntotal > 0 ? $"update gameuser_mail set mail_state={pMsg.Cstate} where mail_id={pMsg.Mailid} and user_id={pMsg.Objid};" : $"insert into gameuser_mail (mail_id,user_id, mail_state) values({pMsg.Mailid},{pMsg.Objid},{pMsg.Cstate});"; errorCode = db.SqlExecNonQuery(sqlStr); return(errorCode); }
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); }
private ErrorCode InsertCDKey(GBuffer buffer, DBActiveWrapper db) { CSToDB.InsertCDKeyInfo sMsg = new CSToDB.InsertCDKeyInfo(); sMsg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); return(db.SqlExecNonQuery(sMsg.SqlStr)); }
private ErrorCode DBAsynExeSQL(GBuffer buffer, DBActiveWrapper db) { CSToDB.ExeSQL_Call sMsg = new CSToDB.ExeSQL_Call(); sMsg.MergeFrom(buffer.GetBuffer(), 0, ( int )buffer.length); return(db.SqlExecNonQuery(sMsg.Sql)); }