You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

877 lines
37 KiB

using System.Collections.Generic;
using System.Diagnostics;
using Sog;
using Sog.Service;
using ProtoCSStruct;
namespace DB
{
//每个Task需要一个Handler,一个Handler一个DBOperator
public partial class MessageTaskHandler
{
private DBOperator m_dbOperator;
private DBOperator m_oldDBOperator;
private long m_lastKeepMysqlConnTimeSecond;
//自管理
private static MessageTaskHandler[] m_allTaskHandler;
public static void InitAllTaskHandler(ServerApp app)
{
//分配消息任务,线程数量=表的数量,免得冲突
uint iTaskCount = (uint)AccountUtils.DBServerWorkThreadCount;
TraceLog.Debug("MessageTaskHandler.InitAllTaskHandler messageTaskCount is {0}", iTaskCount);
MessageTaskDistributor.Instance.InitTask(iTaskCount, app);
DBServerConfig serverConfig = DBServerUtils.GetServerConfig();
DBServerUtils.ParseDBConfig(app, out int dbtype, out string dbname, out string dbip);
TraceLog.Trace("MessageTaskHandler.InitAllTaskHandler ip {0} db {1}", dbip, dbname);
m_allTaskHandler = new MessageTaskHandler[iTaskCount];
for (int i = 0; i < m_allTaskHandler.Length; i++)
{
m_allTaskHandler[i] = new MessageTaskHandler();
MessageTaskObj taskObj = MessageTaskDistributor.Instance.GetTaskByIndex(i);
switch (dbtype)
{
case 0:
m_allTaskHandler[i].m_dbOperator = new MySqlDBOperator(dbname, dbip
, serverConfig.dbuser, serverConfig.dbpassword);
break;
case 2:
m_allTaskHandler[i].m_dbOperator = new RedisDBOperator(dbname, dbip
, serverConfig.dbuser, serverConfig.dbpassword);
break;
default:
TraceLog.Error("MessageTaskHandler.InitAllTaskHandler invalid dbtype {0}", dbtype);
break;
}
taskObj.Handler = m_allTaskHandler[i].HandlerPacket;
taskObj.IdleTick = m_allTaskHandler[i].OnIdleTick;
}
MessageTaskDistributor.Instance.StartAllTask();
}
public static void DisposeAllHandler()
{
//关闭所有消息处理任务
MessageTaskDistributor.Instance.CloseAllTask();
if (m_allTaskHandler == null)
{
return;
}
//销毁数据库连接,销毁对象
for (int i = 0; i < m_allTaskHandler.Length; i++)
{
m_allTaskHandler[i].m_dbOperator.Dispose();
m_allTaskHandler[i].m_dbOperator = null;
}
m_allTaskHandler = null;
}
public static void AfterReloadServerConfigChangeDB(ServerApp app)
{
DBServerConfig serverConfig = DBServerUtils.GetServerConfig();
DBServerUtils.ParseDBConfig(app, out int dbtype, out string dbname, out string dbip);
for (int i = 0; i < m_allTaskHandler.Length; i++)
{
m_allTaskHandler[i].m_oldDBOperator = m_allTaskHandler[i].m_dbOperator;
m_allTaskHandler[i].m_lastKeepMysqlConnTimeSecond = AppTime.GetNowSysSecond();
switch (dbtype)
{
case 0:
m_allTaskHandler[i].m_dbOperator = new MySqlDBOperator(dbname, dbip
, serverConfig.dbuser, serverConfig.dbpassword);
break;
case 2:
m_allTaskHandler[i].m_dbOperator = new RedisDBOperator(dbname, dbip
, serverConfig.dbuser, serverConfig.dbpassword);
break;
default:
TraceLog.Error("MessageTaskHandler.AfterReloadServerConfigChangeDB invalid dbtype {0}", dbtype);
break;
}
}
}
public void OnIdleTick(long idleSecond)
{
//5分钟保持连接一次
if (AppTime.GetNowSysSecond() - m_lastKeepMysqlConnTimeSecond < 300)
{
return;
}
if (m_oldDBOperator != null)
{
m_oldDBOperator.Dispose();
m_oldDBOperator = null;
}
m_lastKeepMysqlConnTimeSecond = AppTime.GetNowSysSecond();
m_dbOperator.KeepAlive();
}
public void HandlerPacket(uint remoteAppID, StructPacket packet)
{
//去掉这里的时间重置逻辑,如果下面实际处理逻辑里没有进行sql查询就返回会造成KeepAlive不执行
//m_lastKeepMysqlConnTimeSecond = AppTime.GetNowSysSecond();
switch (packet.MsgID)
{
case (int)SSMsgID.QueryAccountDb:
OnQueryAccountDBReq(remoteAppID, packet);
break;
case (int)SSMsgID.QueryDbSnsFriendAccountReq:
OnQueryDbSnsFriendAccountReq(remoteAppID, packet);
break;
case (int)SSMsgID.BindGuestFacebookDbReq:
OnBindGuestFacebookDbReq(remoteAppID, packet);
break;
case (int)SSMsgID.UnbindGuestFacebookDbReq:
OnUnbindGuestFacebookDbReq(remoteAppID, packet);
break;
case (int)SSMsgID.QueryUidByFbuseridReq:
OnQueryUidByFbuseridReq(remoteAppID, packet);
break;
case (int)SSMsgID.QueryUidByWxidReq:
OnQueryUidByWxidReq(remoteAppID, packet);
break;
case (int)SSMsgID.ChangeFacebookUidDbReq:
OnChangeFacebookUidDbReq(remoteAppID, packet);
break;
case (int)SSMsgID.UpdateAccountLastloginrealm:
OnUpdateAccountLastLoginRealm(remoteAppID, packet);
break;
case (int)SSMsgID.LoginCheckValidReq:
OnLoginCheckValidReq(remoteAppID, packet);
break;
case (int)SSMsgID.RealmRoleBriefReq:
OnRealmRoleBriefReq(remoteAppID, packet);
break;
case (int)SSMsgID.UpdateRealmRoleBrief:
UpdateRealmRoleBrief(remoteAppID, packet);
break;
case (int)SSMsgID.UpdateAccountGradeDbReq:
OnUpdateAccountGradeDbReq(remoteAppID, packet);
break;
case (int)SSMsgID.QueryRealmUidDataReq:
OnQueryRealmUidDataReq(remoteAppID, packet);
break;
case (int)SSMsgID.SaveRealmUidDataReq:
OnSaveRealmUidDataReq(remoteAppID, packet);
break;
case (int)SSMsgID.SsRealmDbqueryReq:
OnQueryRealmDBReq(remoteAppID, packet);
break;
case (int)SSMsgID.SsRealmDbsaveReq:
OnSaveRealmDBReq(remoteAppID, packet);
break;
case (int)SSMsgID.SsRealmSavePlayernum:
OnSsRealmSavePlayernum(remoteAppID, packet);
break;
//pay
case (int)SSGameMsgID.GmQueryUserPayRecordReq:
PayOp.OnGmQueryUserPayRecordReq(remoteAppID, packet, m_dbOperator);
break;
//AccountInfo
case (int)SSGameMsgID.GmQueryUserAccountinfoReq:
AccountOP.OnSelectAccountInfo(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.PayGoogleReq:
PayOp.OnPayGoogleReq(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.PayGoogleSuccessReq:
PayOp.OnPayGoogleSuccessReq(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.PayDbAddDiamondStatusReq:
PayOp.OnPayDBAddDiamondStatusReq(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.QueryPayGoogleSuccOrder:
PayOp.OnQueryPayGoogleSuccOrder(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.PaySendDbRefundReq:
PayOp.OnPaySendDBRefundReq(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.PayHeroSaveHttpContentReq:
PayOp.OnSaveHttpContentReq(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.PayHeroSelectHttpContentReq:
PayOp.OnSelectHttpContentReq(remoteAppID, packet, m_dbOperator);
break;
case (int)SSGameMsgID.PayHeroDeleteHttpContentNotify:
PayOp.OnDeleteHttpContentNotify(remoteAppID, packet, m_dbOperator);
break;
case (int)SSMsgID.SendGifts:
AccountOP.SSSendGift(remoteAppID, packet,m_dbOperator );
break;
default:
TraceLog.Error("MessageTaskHandler unknow MsgID {0}", packet.MsgID);
break;
}
}
//进入游戏时,account没有缓存该玩家,则从db请求
private void OnQueryAccountDBReq(uint remoteAppID, StructPacket packet)
{
ref SSQueryAccountInfoDB queryAccountDbReq = ref packet.GetMessage<SSQueryAccountInfoDB>();
int accountType = queryAccountDbReq.CSAccountAuthReq.Account.AccountType;
string accountID = queryAccountDbReq.CSAccountAuthReq.Account.AccountID.GetString();
string accountToken = queryAccountDbReq.CSAccountAuthReq.Account.AccountToken.GetString();
TraceLog.Debug("OnQueryAccountDBReq type {0} id {1}", accountType, accountID);
//GM代码,查看外网数据用
if (DBServerUtils.GetServerConfig().gmReplaceAccountType > 0
&& AccountType.AccountType_Guest == (AccountType)queryAccountDbReq.CSAccountAuthReq.Account.AccountType)
{
accountType = DBServerUtils.GetServerConfig().gmReplaceAccountType;
accountID = accountID.Replace("@Guest", "");
}
tbAccount accountRecord = m_dbOperator.QueryAccount(accountType, accountID);
if (accountRecord != null)
{
TraceLog.Debug("OnQueryAccountDBReq accountID {0} query success", accountID);
if (AccountType.AccountType_Guest == (AccountType)queryAccountDbReq.CSAccountAuthReq.Account.AccountType)
{
queryAccountDbReq.Nick.SetString(accountRecord.Nick);
queryAccountDbReq.Gender = accountRecord.Gender;
queryAccountDbReq.Icon.SetString(accountRecord.Icon);
queryAccountDbReq.TokenInDB.SetString(accountToken);
}
else
{
queryAccountDbReq.TokenInDB.SetString(accountRecord.AccountToken);
}
queryAccountDbReq.LastLoginRealm = accountRecord.LastLoginRealm;
queryAccountDbReq.AccountCreateTime = accountRecord.CreateTime;
queryAccountDbReq.AccountIpAddr = (uint)accountRecord.CreateIpAddr;
queryAccountDbReq.Grade = accountRecord.Grade;
string reqChannel = queryAccountDbReq.ExData.Channel.GetString();
int reqChannelId = queryAccountDbReq.ExData.ChannelId;
// 查询时没有附带玩家的channel信息, 使用DB保存的记录
if (string.IsNullOrEmpty(reqChannel))
{
StructMessageParseUtils.ParseFrom(ref queryAccountDbReq.ExData, accountRecord.exData);
}
else
{
// channel和channelId是新增字段, 尝试在查询account时更新老玩家的channel信息
UpdateAccountChannelInfo(accountRecord, reqChannel, reqChannelId);
}
}
else if (queryAccountDbReq.CreateIfNotExist)//自动创建角色
{
//没有记录,则创建,大部分手游只有一个玩家角色信息(棋牌,卡牌,竞技游戏等等),直接创建user
TraceLog.Debug("OnQueryAccountDBReq accountID {0} no record, create it", accountID);
long accountCreateTime = DBServerUtils.GetTimeSecond();
bool bSuccess = m_dbOperator.InsertAccount(
accountType
, accountID
, accountToken
, accountCreateTime
, queryAccountDbReq.CSAccountAuthReq.DeviceId.GetString()
, NetUtils.IpAddrToNum(queryAccountDbReq.CSAccountAuthReq.Ip.GetString())
, queryAccountDbReq.Nick.GetString()
, queryAccountDbReq.Gender
, queryAccountDbReq.Icon.GetString()
, 0
, ref queryAccountDbReq.ExData);
if (!bSuccess)
{
TraceLog.Error("OnQueryAccountDBReq accountType {0} accountID {1} insert failed"
, accountType, accountID);
}
else
{
queryAccountDbReq.TokenInDB = queryAccountDbReq.CSAccountAuthReq.Account.AccountToken;
queryAccountDbReq.AccountCreateTime = accountCreateTime;
queryAccountDbReq.IsNewCreate = 1;
}
}
else
{
TraceLog.Debug("OnQueryAccountDBReq type {0} id {1} not exist, config.CreateIfNotExist is false! "
, accountType, accountID);
}
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.QueryAccountDb, ref queryAccountDbReq, packet.ObjectID);
}
private void UpdateAccountChannelInfo(tbAccount accountRecord, string channel, int channelId)
{
TraceLog.Trace("UpdateAccountChannelInfo accountType {0} accountID {1} update channel {2} channelId {3}"
, accountRecord.AccountType, accountRecord.AccountID, channel, channelId);
DBAccountExData dbExData = new DBAccountExData();
StructMessageParseUtils.ParseFrom(ref dbExData, accountRecord.exData);
bool update = false;
string dbChannel = dbExData.Channel.GetString();
if (!string.IsNullOrEmpty(channel) && !channel.Equals(dbChannel))
{
dbExData.Channel.SetString(channel);
update = true;
}
if (channelId > 0 && dbExData.ChannelId != channelId)
{
dbExData.ChannelId = channelId;
update = true;
}
// 无需更新
if (!update)
{
return;
}
if (!m_dbOperator.UpdateAccountExData(accountRecord.AccountType,
accountRecord.AccountID, accountRecord, ref dbExData))
{
TraceLog.Error("UpdateAccountChannelInfo accountType {0} accountID {1} update fail"
, accountRecord.AccountType, accountRecord.AccountID);
}
}
private void OnQueryDbSnsFriendAccountReq(uint remoteAppID, StructPacket packet)
{
ref SSQueryDBSnsFriendAccountReq req = ref packet.GetMessage<SSQueryDBSnsFriendAccountReq>();
TraceLog.Debug("OnQueryDbSnsFriendAccountReq type {0} id {1}"
, req.AccountType, req.AccountID);
tbAccount accountRecord = m_dbOperator.QueryAccount(req.AccountType, req.AccountID.GetString());
SSQueryDBSnsFriendAccountRes res = new SSQueryDBSnsFriendAccountRes();
res.AccountID = req.AccountID;
res.AccountType = req.AccountType;
if (accountRecord != null)
{
//uid先不查询,可能存在多个
//TraceLog.Debug("query success, uid is {0}", accountRecord.GameID);
//res.Uid = accountRecord.GameID;
res.Gender = accountRecord.Gender;
res.Icon.SetString(accountRecord.Icon);
res.Nick.SetString(accountRecord.Nick);
}
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.QueryDbSnsFriendAccountRes, ref res, packet.ObjectID);
}
private void OnBindGuestFacebookDbReq(uint remoteAppID, StructPacket packet)
{
ref SSBindGuestFacebookDbReq req = ref packet.GetMessage<SSBindGuestFacebookDbReq>();
TraceLog.Debug("OnBindGuestFacebookDbReq type {0} id {1}"
, req.AccountInfo.AccountType, req.AccountInfo.AccountID);
SSBindGuestFacebookDbRes res = new SSBindGuestFacebookDbRes();
res.GuestAccountID = req.GuestAccountID;
res.AccountInfo = req.AccountInfo;
res.Gender = req.Gender;
res.Icon = req.Icon;
res.Nick = req.Nick;
res.Uid = req.Uid;
res.Email = req.Email;
tbAccount accountRecord = m_dbOperator.QueryAccount(req.AccountInfo.AccountType,
req.AccountInfo.AccountID.GetString());
if (accountRecord != null)
{
//已经存在,返回成功
res.Ret = 0;
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.BindGuestFacebookDbRes, ref res, packet.ObjectID);
return;
}
long accountCreateTime = DBServerUtils.GetTimeSecond();
DBAccountExData exData = new DBAccountExData();
bool bSuccess = m_dbOperator.InsertAccount(
req.AccountInfo.AccountType
, req.AccountInfo.AccountID.GetString()
, req.AccountInfo.AccountToken.GetString()
, accountCreateTime
, ""
, NetUtils.IpAddrToNum(req.Ip.GetString())
, req.Nick.GetString()
, req.Gender
, req.Icon.GetString()
, 0
, ref exData);
if (!bSuccess)
{
res.Ret = -1;
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.BindGuestFacebookDbRes, ref res, packet.ObjectID);
return;
}
res.Ret = 0;
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.BindGuestFacebookDbRes, ref res, packet.ObjectID);
return;
}
private void OnUnbindGuestFacebookDbReq(uint remoteAppID, StructPacket packet)
{
ref SSUnbindGuestFacebookDbReq req = ref packet.GetMessage<SSUnbindGuestFacebookDbReq>();
TraceLog.Debug("OnUnbindGuestFacebookDbReq type {0} id {1}"
, req.AccountInfo.AccountType, req.AccountInfo.AccountID);
SSUnbindGuestFacebookDbRes res = new SSUnbindGuestFacebookDbRes();
res.GuestAccountID = req.GuestAccountID;
res.AccountInfo = req.AccountInfo;
res.Uid = req.Uid;
tbAccount accountRecord = m_dbOperator.QueryAccount(req.AccountInfo.AccountType,
req.AccountInfo.AccountID.GetString());
if (accountRecord != null)
{
}
//返回成功
res.Ret = 0;
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.UnbindGuestFacebookDbRes, ref res, packet.ObjectID);
return;
}
//目前看没什么用
private void OnQueryUidByFbuseridReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSQueryUidByFbuseridReq>();
var res = new SSQueryUidByFbuseridRes();
res.Fbuserid = req.Fbuserid;
res.GameServerID = req.GameServerID;
res.WorldServerID = req.WorldServerID;
tbAccount accountRecord = m_dbOperator.QueryAccount((int)AccountType.AccountType_Facebook,
req.Fbuserid.GetString());
if (accountRecord != null)
{
//res.Uid = accountRecord.GameID;
}
TraceLog.Debug("OnQueryUidByFbuseridReq type fbuserid {0} uid {1} for request Uid {2}"
, req.Fbuserid, res.Uid, packet.ObjectID);
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.QueryUidByFbuseridRes,
ref res,
packet.ObjectID);
}
private void OnQueryUidByWxidReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSQueryUidByWXIDReq>();
var res = new SSQueryUidByWXIDRes();
res.Wxid = req.Wxid;
res.GameServerID = req.GameServerID;
res.WorldServerID = req.WorldServerID;
var realmuid_linklist = m_dbOperator.QueryAccountUid((int)AccountType.AccountType_WX, req.Wxid.ToString(), 0);
//取最后一个
var l = realmuid_linklist[realmuid_linklist.Count - 1];
res.Uid = l.uid;
res.RealmId = l.realmId;
TraceLog.Debug("OnQueryUidByWxidReq type wxid {0} uid {1} for request Uid {2}"
, req.Wxid, res.Uid, packet.ObjectID);
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.QueryUidByWxidRes,
ref res,
packet.ObjectID);
}
// 这个接口只能GM调用, 因为realmlink缓存了uid的简要信息, 只更新uid是不对的
// 如果需要更新其他信息, 则需要知道new uid的数据, 至少要知道new uid属于哪张表, 即new uid的accountType, accountId, realm
private void OnChangeFacebookUidDbReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSChangeFacebookUidDbReq>();
string accountId = req.AccountID.GetString();
var res = new SSChangeFacebookUidDbRes();
res.AccountType = req.AccountType;
res.AccountID = req.AccountID;
res.RealmId = req.RealmId;
res.Uid = req.Uid;
tbAccount accountRecord = m_dbOperator.QueryAccount(req.AccountType, accountId);
if (accountRecord == null)
{
TraceLog.Error("OnChangeFacebookUidDbReq type {0} accountId {1} no tbaccount", req.AccountType, accountId);
res.Ret = -1;
}
else
{
TraceLog.Debug("OnChangeFacebookUidDbReq type {0} accountId {1}", req.AccountType, accountId);
var list = m_dbOperator.QueryAccountUid(req.AccountType, accountId, req.RealmId);
// 没有数据
if (list == null || list.Count == 0)
{
if (!m_dbOperator.InsertAccRealmUidLink(req.AccountType, accountId, req.RealmId, req.Uid))
{
TraceLog.Error("OnChangeFacebookUidDbReq type {0} accountId {1} realm {2} insert uid {3} fail"
, req.AccountType, accountId, req.RealmId, req.Uid);
res.Ret = -1;
}
}
else
{
if (!m_dbOperator.UpdateAccRealmLinkUid(req.AccountType, accountId, req.RealmId, req.Uid))
{
res.Ret = -1;
}
TraceLog.Error("OnChangeFacebookUidDbReq type {0} accountId {1} realm {2} old uid {3} new uid {4} update result {5}"
, req.AccountType, accountId, req.RealmId, list[0].uid, req.Uid, res.Ret);
}
}
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.ChangeFacebookUidDbRes, ref res, packet.ObjectID);
}
private void OnUpdateAccountLastLoginRealm(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSUpdateAccountLastLoginRealm>();
//GM代码,查看外网数据用
int accountType = req.AccountType;
string accountID = req.AccountID.GetString();
if (DBServerUtils.GetServerConfig().gmReplaceAccountType > 0 && AccountType.AccountType_Guest == (AccountType)req.AccountType)
{
accountType = DBServerUtils.GetServerConfig().gmReplaceAccountType;
accountID = accountID.Replace("@Guest", "");
}
tbAccount accountRecord = m_dbOperator.QueryAccount(accountType, accountID);
if (accountRecord == null)
{
TraceLog.Error("OnUpdateAccountLastLoginRealm accountid {0} update lastLoginRealm {1} no account record"
, accountID, req.LastLoginRealm);
}
else
{
TraceLog.Debug("OnUpdateAccountLastLoginRealm accountid {0} update lastLoginRealm {1} old {2}"
, accountID, req.LastLoginRealm, accountRecord.LastLoginRealm);
if (accountRecord.LastLoginRealm == req.LastLoginRealm)
{
return;
}
bool bSuccess = m_dbOperator.UpdateAccountLastLoginRealm(accountType, accountID, accountRecord, req.LastLoginRealm);
if (bSuccess == false)
{
TraceLog.Error("OnUpdateAccountLastLoginRealm accountid {0} update lastLoginRealm {1} update failed!"
, accountID, req.LastLoginRealm);
}
else
{
TraceLog.Debug("OnUpdateAccountLastLoginRealm accountid {0} update lastLoginRealm {1} success"
, accountID, req.LastLoginRealm);
}
}
}
private void OnLoginCheckValidReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSLoginCheckValidReq>();
long uid = 0;
//GM代码,查看外网数据用
int accountType = req.AccountInfo.AccountType;
string accountID = req.AccountInfo.AccountID.GetString();
if (DBServerUtils.GetServerConfig().gmReplaceAccountType > 0 && AccountType.AccountType_Guest == (AccountType)req.AccountInfo.AccountType)
{
accountType = DBServerUtils.GetServerConfig().gmReplaceAccountType;
accountID = accountID.Replace("@Guest", "");
}
List<tbacc_realmuid_link> accountRecord = m_dbOperator.QueryAccountUid(accountType, accountID, 0);
int roleCount = 0;
if (accountRecord != null && accountRecord.Count > 0)
{
roleCount = accountRecord.Count;
foreach (var it in accountRecord)
{
if (req.RealmId == it.realmId) //已经有号
{
uid = it.uid;
}
}
}
if (0 == uid)//没有号就新建
{
int accountTableIndex = TableIndexCalc.CalcAccountTableIndex(accountType, accountID);
long gameId = m_dbOperator.GenNewGameID(accountTableIndex);
if (gameId > 0 && m_dbOperator.InsertAccRealmUidLink(accountType, accountID, req.RealmId, gameId))
{
TraceLog.Debug("record exit but no gameId, create new gameId {0} ", gameId);
uid = gameId;
roleCount++;
}
else
{
TraceLog.Error("record exit but no gameId, create new gameId {0} failed", gameId);
}
}
SSLoginCheckValidRes res = new SSLoginCheckValidRes();
res.Uid = uid;
res.RealmId = req.RealmId;
res.AccountInfo = req.AccountInfo;
res.Lang = req.Lang;
res.GameServerID = req.GameServerID;
res.LoginReqInfo = req.LoginReqInfo;
res.WorldServerID = req.WorldserverId;
res.PlayerSessionID = packet.ObjectID;
res.RoleCount = roleCount;
if (uid == 0)
{
TraceLog.Error("OnLoginCheckValidReq accountid {0} invalid uid 0", req.AccountInfo.AccountID);
res.Ret = -1;
}
else
{
res.Ret = 0;
}
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.LoginCheckValidRes, ref res, packet.ObjectID);
}
private void OnRealmRoleBriefReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSRealmRoleBriefReq>();
TraceLog.Trace("OnRealmRoleBriefReq accType {0} accId {1} req uid {2}"
, req.AccountType, req.AccountID, packet.ObjectID);
var res = new SSRealmRoleBriefRes { AccountType = req.AccountType };
res.AccountID = req.AccountID;
res.FromClient = req.FromClient;
res.AreaName.SetString(req.AreaName.GetString());
res.ClientReq = req.ClientReq;
//GM代码,查看外网数据用
int accountType = req.AccountType;
string accountID = req.AccountID.GetString();
if (DBServerUtils.GetServerConfig().gmReplaceAccountType > 0 && AccountType.AccountType_Guest == (AccountType)req.AccountType)
{
accountType = DBServerUtils.GetServerConfig().gmReplaceAccountType;
accountID = accountID.Replace("@Guest", "");
}
List<tbacc_realmuid_link> accountRecord = m_dbOperator.QueryAccountUid(accountType, accountID, 0);
if (accountRecord != null)
{
for (int i = 0; i < accountRecord.Count; i++)
{
var role = new CSRoleBrief
{
Uid = accountRecord[i].uid,
Level = accountRecord[i].level,
RealmId = (int)accountRecord[i].realmId,
IconFrameId = accountRecord[i].iconFrameId,
LastLoginTime = accountRecord[i].lastLoginTime
};
role.Nick.SetString(accountRecord[i].nick);
role.Icon.SetString(accountRecord[i].icon);
if (res.RoleList.Count < res.RoleList.GetMaxCount())
{
res.RoleList.Add(role);
}
else
{
TraceLog.Error("MessageTaskHandler.OnRealmRoleBriefReq error, RealmRoleBriefRes no space");
}
}
}
else
{
//新账号没有是正常的
TraceLog.Trace("OnRealmRoleBriefReq accType {0} accId {1} no record", req.AccountType, accountID);
}
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.RealmRoleBriefRes, ref res, packet.ObjectID, packet.ServerID);
}
private void UpdateRealmRoleBrief(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSUpdateRealmRoleBrief>();
//GM代码,查看外网数据用
int accountType = req.AccountType;
string accountID = req.AccountID.GetString();
if (DBServerUtils.GetServerConfig().gmReplaceAccountType > 0 && AccountType.AccountType_Guest == (AccountType)req.AccountType)
{
accountType = DBServerUtils.GetServerConfig().gmReplaceAccountType;
accountID = accountID.Replace("@Guest", "");
}
if (!m_dbOperator.UpdateAccRealmUidLink(accountType, accountID, ref req.RoleBrief))
{
TraceLog.Error("UpdateRealmRoleBrief accType {0} accountId {1} failed"
, req.AccountType, req.AccountID.GetString());
}
}
private void OnUpdateAccountGradeDbReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSUpdateAccountGradeDbReq>();
var res = new SSUpdateAccountGradeDbRes();
res.AccountInfo.AccountID.SetString(req.AccountInfo.AccountID.GetPtr());
res.AccountInfo.AccountToken.SetString(req.AccountInfo.AccountToken.GetPtr());
res.AccountInfo.AccountType = req.AccountInfo.AccountType;
res.IsExData = req.IsExData;
//GM代码,查看外网数据用
int accountType = req.AccountInfo.AccountType;
string accountID = req.AccountInfo.AccountID.GetString();
if (DBServerUtils.GetServerConfig().gmReplaceAccountType > 0 && AccountType.AccountType_Guest == (AccountType)req.AccountInfo.AccountType)
{
accountType = DBServerUtils.GetServerConfig().gmReplaceAccountType;
accountID = accountID.Replace("@Guest", "");
}
tbAccount accountRecord = m_dbOperator.QueryAccount(accountType, accountID);
if (accountRecord == null)
{
TraceLog.Error("OnUpdateAccountGradeDbReq accountid {0} update Grade {1} or exdata no account record"
, accountID, req.Grade);
res.Ret = -1;
}
else
{
bool bSuccess = false;
if (req.IsExData)
{
TraceLog.Debug("OnUpdateAccountGradeDbReq accountid {0} update exdata old", accountID);
bSuccess = m_dbOperator.UpdateAccountExData(accountType, accountID, accountRecord, ref req.ExData);
}
else
{
TraceLog.Debug("OnUpdateAccountGradeDbReq accountid {0} update Grade {1} old {2}"
, accountID, req.Grade, accountRecord.Grade);
if (accountRecord.Grade == req.Grade)
{
res.Ret = 0;
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.UpdateAccountGradeDbRes, ref res, packet.ObjectID);
return;
}
bSuccess = m_dbOperator.UpdateAccountGrade(accountType, accountID, accountRecord, req.Grade);
}
if (bSuccess == false)
{
TraceLog.Error("OnUpdateAccountGradeDbReq accountid {0} update Grade {1} or exdata update failed!"
, accountID, req.Grade);
res.Ret = -1;
}
else
{
TraceLog.Debug("OnUpdateAccountGradeDbReq accountid {0} update Grade {1} or exdata success"
, accountID, req.Grade);
res.Ret = 0;
}
}
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
(int)SSMsgID.UpdateAccountGradeDbRes, ref res, packet.ObjectID);
}
private void OnQueryRealmUidDataReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSQueryRealmUidDataReq>();
var res = new SSQueryRealmUidDataRes();
m_dbOperator.QueryRealmUidData(req.RealmId, ref res);
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.QueryRealmUidDataRes, ref res, 0);
}
private void OnSaveRealmUidDataReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSSaveRealmUidDataReq>();
var res = new SSSaveRealmUidDataRes { RealmId = req.RealmId, SaveSeq = req.SaveSeq };
res.Ret = m_dbOperator.SaveRealmUidData(ref req);
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.SaveRealmUidDataRes, ref res, 0);
}
private void OnQueryRealmDBReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSRealmDBQueryReq>();
var res = new SSRealmDBQueryRes();
res.RemoteAppID = remoteAppID;
m_dbOperator.QueryRealmDBData(ref res);
res.IsEnd = 1;
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.SsRealmDbqueryRes, ref res, 0);
}
private void OnSaveRealmDBReq(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSRealmDBSaveReq>();
var res = new SSRealmDBSaveRes();
m_dbOperator.UpdateRealmDBData(ref req,ref res);
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.SsRealmDbsaveRes, ref res, 0);
}
private void OnSsRealmSavePlayernum(uint remoteAppID, StructPacket packet)
{
ref var req = ref packet.GetMessage<SSRealmSavePlayerNum>();
m_dbOperator.UpdateRealmPlayerNum(req.RealmId, req.RegNum);
}
}
}