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.
224 lines
8.6 KiB
224 lines
8.6 KiB
/*
|
|
Sog 游戏基础库
|
|
2016 by zouwei
|
|
*/
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
using Sog.IO;
|
|
|
|
|
|
namespace Account
|
|
{
|
|
public class GmCmdSvc : BaseReloadableService
|
|
{
|
|
public override int GetServiceType()
|
|
{
|
|
return AccountServiceType.GmCmdSvc;
|
|
}
|
|
|
|
//销毁的时候清空指令注册
|
|
public override void Dispose()
|
|
{
|
|
GmCommandMgr.Instance.ClearAll();
|
|
}
|
|
|
|
//构造的时候注册所有指令
|
|
public GmCmdSvc()
|
|
{
|
|
RegisterAllGmCmd();
|
|
}
|
|
|
|
public void Tick(long nowMs)
|
|
{
|
|
TickForAccountInfoTest(nowMs);
|
|
}
|
|
|
|
private void RegisterAllGmCmd()
|
|
{
|
|
//清空所有帐号
|
|
GmCommandMgr.Instance.Register("ClearAllHttpQueryTime", "ClearAllHttpQueryTime", ClearAllHttpQueryTime,GMBroadCastType.GMBroadCastType_MustBroad);
|
|
//改变一个帐号关联的uid
|
|
GmCommandMgr.Instance.Register("ChangeAccountUid", "ChangeAccountUid type accountid realm uid", ChangeAccountUid, GMBroadCastType.GMBroadCastType_CanNotBroad);
|
|
|
|
GmCommandMgr.Instance.Register("CreateFakeAccount", "CreateFakeAccount", CreateFakeAccount);
|
|
GmCommandMgr.Instance.Register("PrintAllAccount", "PrintAllAccount", PrintAllAccount);
|
|
// gm批量创建account任务, 可以预估一下处理上限,配置ticknum
|
|
GmCommandMgr.Instance.Register("AccountInfoTest", "param: type ticknum", this.AccountInfoTest);
|
|
|
|
//注册广播事件
|
|
GmCommandMgr.Instance.NotifyWorldBroadCastGMCmdToServer = NotifyWorldBroadCastGMCmdToServer;
|
|
}
|
|
|
|
//广播来的指令
|
|
public static void OnWorldNotifyDealGmCmd(StructPacket packet)
|
|
{
|
|
ref SSNotifyServerDealGMCmd gmCmd = ref packet.GetMessage<SSNotifyServerDealGMCmd>();
|
|
string[] splitStr = gmCmd.CmdParams.GetString().Split(' ');
|
|
GmCommandMgr.Instance.HandlerGmCommand(gmCmd.GmCmd.GetString(), gmCmd.UserId, splitStr, false);
|
|
}
|
|
|
|
private int ClearAllHttpQueryTime(long userid, string[] cmdParams)
|
|
{
|
|
TraceLog.Debug("GmCmdSvc.ClearAllHttpQueryTime begin");
|
|
|
|
AccountTable table = AccountServerUtils.GetAccountTable();
|
|
foreach (var accountInfo in table.m_accountTable.Values)
|
|
{
|
|
accountInfo.LastQueryHttpSnsFriendTime = 0;
|
|
accountInfo.LastQueryHttpUserInfoTime = 0;
|
|
}
|
|
|
|
TraceLog.Debug("GmCmdSvc.ClearAllHttpQueryTime success");
|
|
|
|
return 0;
|
|
}
|
|
|
|
private int ChangeAccountUid(long userid, string[] cmdParams)
|
|
{
|
|
if (cmdParams.Length != 4)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.ChangeAccountUid invalid param count {0}, need type, accountId, new uid", cmdParams.Length);
|
|
return -1;
|
|
}
|
|
|
|
int accountType = 0, realmId = 0, uid = 0;
|
|
if (! int.TryParse(cmdParams[0], out accountType)
|
|
|| ! int.TryParse(cmdParams[2], out realmId)
|
|
|| ! int.TryParse(cmdParams[3], out uid))
|
|
{
|
|
TraceLog.Error("GmCmdSvc.ChangeAccountUid invalid accountType {0} or realmId {1} uid {2}"
|
|
, cmdParams[0], cmdParams[2], cmdParams[3]);
|
|
return -1;
|
|
}
|
|
|
|
string accountId = cmdParams[1];
|
|
SSChangeFacebookUidDbReq req = new SSChangeFacebookUidDbReq();
|
|
req.AccountID.SetString(accountId);
|
|
req.AccountType = accountType;
|
|
req.RealmId = realmId; // realmId不要填错了
|
|
req.Uid = uid;
|
|
|
|
uint iDBServerID = DBServerSelect.GetDBServerID(req.AccountType, accountId);
|
|
AccountServerUtils.GetPacketSender().SendToServerByID(iDBServerID, (int)SSMsgID.ChangeFacebookUidDbReq, ref req, 0);
|
|
return 0;
|
|
}
|
|
|
|
//如果是需要广播的,通知下world进行广播
|
|
public void NotifyWorldBroadCastGMCmdToServer(long userId, string gmCmd, string cmdParams)
|
|
{
|
|
SSNotifyWorldBroadCastGMCmd notify = new SSNotifyWorldBroadCastGMCmd();
|
|
notify.UserId = userId;
|
|
notify.GmCmd.SetString(gmCmd);
|
|
notify.CmdParams.SetString(cmdParams);
|
|
notify.OnlyBroadCastSpec = userId > 0; //如果到了这里,userId又大于0 则是需要指定广播了
|
|
AccountServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.NotifyworldBroadcastgmcmd, ref notify, 0, 0);
|
|
}
|
|
|
|
private int CreateFakeAccount(long userid, string[] cmdParams)
|
|
{
|
|
if (cmdParams.Length < 1)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.CreateFakeAccount invalid param, need account num");
|
|
return -1;
|
|
}
|
|
|
|
int.TryParse(cmdParams[0], out int num);
|
|
long nowSec = AccountServerUtils.GetTimeSecond();
|
|
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
AccountServerUtils.GetAccountTableOp().CreateAccountInfo(1, "test_" + nowSec + "_" + i);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
private int PrintAllAccount(long userid, string[] cmdParams)
|
|
{
|
|
var table = AccountServerUtils.GetAccountTable().m_accountTable;
|
|
foreach (AccountInfoOnAccountServer info in table.Values)
|
|
{
|
|
TraceLog.Trace("GmCmdSvc.PrintAllAccount rid {0} accountId {1} dataSeq {2} saveSeq {3}"
|
|
, info.GetRuntimeId(), info.AccountID, info.DataSeq, info.SavedSuccessSeq);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
public int AccountInfoTest(long userid, string[] cmdParams)
|
|
{
|
|
if (cmdParams.Length < 3)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.AccountInfoTest no param");
|
|
return -1;
|
|
}
|
|
|
|
if (!int.TryParse(cmdParams[0], out var opType)
|
|
|| !int.TryParse(cmdParams[1], out var tickNum)
|
|
|| !int.TryParse(cmdParams[2], out var total))
|
|
{
|
|
return -2;
|
|
}
|
|
|
|
AccountInfoTest_OpType = opType;
|
|
AccountInfoTest_TickNum = tickNum;
|
|
AccountInfoTest_Total = total;
|
|
return 0;
|
|
}
|
|
|
|
private int AccountInfoTest_OpType = 0; // 发送类型 1 查询并插入
|
|
private int AccountInfoTest_TickNum = 0; // 每帧发送数量
|
|
private int AccountInfoTest_Total = 0; // 总量
|
|
private long AccountInfoTest_nextTickMs = 0;
|
|
private void TickForAccountInfoTest(long nowMs)
|
|
{
|
|
if (nowMs < AccountInfoTest_nextTickMs)
|
|
{
|
|
return;
|
|
}
|
|
AccountInfoTest_nextTickMs = nowMs + 100;
|
|
|
|
if (AccountInfoTest_OpType <= 0 || AccountInfoTest_TickNum <= 0 || AccountInfoTest_Total <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < AccountInfoTest_TickNum; i++)
|
|
{
|
|
RandomAccountQuery(AccountInfoTest_Total--);
|
|
if (AccountInfoTest_Total <= 0)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
private void RandomAccountQuery(int index)
|
|
{
|
|
var accountID = string.Format("{0}_accountId", index);
|
|
var accountType = index % 10;
|
|
|
|
SSQueryAccountInfoDB queryAccountInfodb = new SSQueryAccountInfoDB();
|
|
queryAccountInfodb.CSAccountAuthReq.Account.AccountType = accountType;
|
|
queryAccountInfodb.CSAccountAuthReq.Account.AccountID.SetString(accountID);
|
|
queryAccountInfodb.CSAccountAuthReq.Account.AccountToken.SetString(accountID);
|
|
queryAccountInfodb.CSAccountAuthReq.DeviceId.SetString("account test");
|
|
queryAccountInfodb.CSAccountAuthReq.Ip.SetString("127.0.0.1");
|
|
queryAccountInfodb.Nick.SetString("NickNickNickNickNickNick");
|
|
queryAccountInfodb.Gender = index % 2;
|
|
queryAccountInfodb.Icon.SetString("IconIconIconIconIconIcon");
|
|
queryAccountInfodb.Email.SetString("emailemailemailemailemailemail");
|
|
queryAccountInfodb.UserType = index % 2;
|
|
queryAccountInfodb.OpenId.SetString("OpenIdOpenIdOpenIdOpenIdOpenIdOpenId");
|
|
queryAccountInfodb.AccountIpAddr = NetUtils.IpAddrToNum("127.0.0.1");
|
|
queryAccountInfodb.ExData.Channel.SetString("ChannelChannelChannelChannelChannel");
|
|
queryAccountInfodb.ExData.ChannelId = index % 5;
|
|
queryAccountInfodb.CreateIfNotExist = true;
|
|
uint iDBServerID = DBServerSelect.GetDBServerID(accountType, accountID);
|
|
AccountServerUtils.GetPacketSender().SendToServerByID(iDBServerID, (int)SSMsgID.QueryAccountDb, ref queryAccountInfodb, 0);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|