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.
 
 
 
 
 
 

208 lines
7.7 KiB

/*
Sog 游戏基础库
2016 by zouwei
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using Sog;
using ProtoCSStruct;
using Sog.IO;
namespace Realmlist
{
public class GmCmdSvc : BaseReloadableService
{
public override int GetServiceType()
{
return RealmlistServiceType.GmCmdSvc;
}
//销毁的时候清空指令注册
public override void Dispose()
{
GmCommandMgr.Instance.ClearAll();
}
//构造的时候注册所有指令
public GmCmdSvc()
{
RegisterAllGmCmd();
}
private void RegisterAllGmCmd()
{
GmCommandMgr.Instance.Register("SetAccountGateUrl", "SetAccountGateUrl accType accId realmId gateIndex", SetAccountGateUrl);
GmCommandMgr.Instance.Register("TestIp", "TestIp", TestIp);
GmCommandMgr.Instance.Register("PrintArea", "PrintArea", PrintArea);
GmCommandMgr.Instance.Register("SaveRealmCfg2DB", "SaveRealmCfg2DB", SaveRealmCfg2DB);
}
private int SetAccountGateUrl(long userid, string[] cmdParams)
{
TraceLog.Debug("GmCmdSvc.SetAccountGateUrl begin");
if (cmdParams.Length != 4)
{
TraceLog.Error("GmCmdSvc.SetAccountGateUrl invalid param,need accType accId realmId gateIndex");
return -1;
}
int accountType = 0;
int.TryParse(cmdParams[0], out accountType);
string accountId = cmdParams[1];
int realmId = 0;
int.TryParse(cmdParams[2], out realmId);
if (realmId <= 0)
{
TraceLog.Error("GmCmdSvc.SetAccountGateUrl invalid realmId");
return -1;
}
int gateIndex = 0;
int.TryParse(cmdParams[3], out gateIndex);
if (gateIndex < 0)
{
TraceLog.Error("GmCmdSvc.SetAccountGateUrl invalid gateIndex");
return -1;
}
PlayerRealmInfo player = RealmlistServerUtils.GetCreatePlayerInfo(accountType, accountId);
if(player.gateGameServerIDDict.ContainsKey(realmId))
{
player.gateGameServerIDDict[realmId] = gateIndex;
}
else
{
player.gateGameServerIDDict.Add(realmId, gateIndex);
}
TraceLog.Debug("GmCmdSvc.SetAccountGateUrl success new gateIndex {0} on realmId {1} of acc type {2} id {3}"
, gateIndex, realmId, accountType, accountId);
return 0;
}
private int TestIp(long userid, string[] cmdParams)
{
TraceLog.Debug("GmCmdSvc.TestIp begin");
RecommendRealmByIP.TestIp();
TraceLog.Debug("GmCmdSvc.TestIp end");
return 0;
}
private int PrintArea(long userid, string[] cmdParams)
{
foreach (AreaRealm area in RealmlistSvc.areaDict.Values)
{
var recommend = RealmlistSvc.GetRecommendRealm(area, null, null, true,null);
TraceLog.Error("GmCmdSvc.PrintArea area {0} timezone {1} recommend {2}"
, area.areaName, area.timezone, recommend != null ? recommend.realmId : 0);
foreach (WorldInfo world in area.areaWorldDict.Values)
{
foreach (GameGateInfo gate in world.gameGates)
{
TraceLog.Error("GmCmdSvc.PrintArea world {0} game {1} url {2} online {3} gatesvr {4}"
, world.worldId, gate.index, gate.url, gate.online
, ServerIDUtils.IDToString(gate.gatesvrId));
}
foreach (GameGateInfo gate in world.chatGates)
{
TraceLog.Error("GmCmdSvc.PrintArea world {0} chat {1} url {2} online {3} gatesvr {4}"
, world.worldId, gate.index, gate.url, gate.online
, ServerIDUtils.IDToString(gate.gatesvrId));
}
}
foreach (RealmGroup group in area.visibleRealmGroup.Values)
{
TraceLog.Error("GmCmdSvc.PrintArea visibleTime {0} : {1}", group.visibleTime
, AppTime.ConvertUnixTimeToDateTime(group.visibleTime * 1000));
foreach (RealmInfo realm in group.realmList)
{
TraceLog.Error("GmCmdSvc.PrintArea realm {0} runtimeState {1}", realm.realmId, realm.runtimeState);
}
}
foreach (RealmInfo realm in area.sortedRealms)
{
TraceLog.Error("GmCmdSvc.PrintArea showSeq {0} realm {1} realmIdx {2}", realm.config.showSeq
, realm.config.realmId, area.realmIndex[realm.config.realmId]);
}
}
return 0;
}
private int SaveRealmCfg2DB(long userid, string[] cmdParams)
{
var svrData = RealmlistServerUtils.GetRealmlistServerData();
foreach (AreaRealm area in RealmlistSvc.areaDict.Values)
{
foreach (WorldInfo world in area.areaWorldDict.Values)
{
foreach (var realmOne in world.worldRealms.Values)
{
bool found = false;
if (svrData.dbRealmConfigs.ContainsKey(realmOne.realmId))
{
found = true;
}
if (!found)
{
OneDBRealmConfig configOne = new OneDBRealmConfig()
{
//AreaName = area.areaName,
WorldId = realmOne.worldId,
RealmId = realmOne.realmId,
LogicWorldId = realmOne.logicWorldId,
//RealmName = realmOne.config.name,
ShowSeq = realmOne.config.showSeq,
Status = realmOne.config.status,
VisibleOnlyWhiteList = realmOne.config.visibleOnlyWhiteList,
//BdcName = realmOne.config.bdcName,
//OpenTime = realmOne.config.openTime,
//VisibleTime = realmOne.config.visibleTime,
BigRealmId = realmOne.config.bigRealmId,
};
configOne.AreaName.SetString(area.areaName);
configOne.RealmName.SetString(realmOne.config.name);
configOne.BdcName.SetString(realmOne.config.bdcName);
configOne.OpenTime.SetString(realmOne.config.openTime);
configOne.VisibleTime.SetString(realmOne.config.visibleTime);
SSRealmDBSaveReq reqSave = new SSRealmDBSaveReq();
reqSave.Cfg = configOne;
reqSave.Notreload = 1;
int instId = (int)ServerIDUtils.GetInstanceID(RealmlistServerUtils.GetApp().ServerID);
uint DBServerID = ServerIDUtils.GetLevel0ServerIDByType((int)ServerType.Db, instId);
RealmlistServerUtils.GetPacketSender().SendToServerByID(DBServerID, (int)SSMsgID.SsRealmDbsaveReq, ref reqSave, 0);
}
}
}
}
return 0;
}
}
}