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.
 
 
 
 
 
 

342 lines
9.7 KiB

/*
Sog 游戏基础库
2016 by zouwei
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using ProtoCSStruct;
namespace Game
{
public static class GameServerUtils
{
public static GameServerData GetGameServerData()
{
return ServerDataObjMgr.GetDataObj<GameServerData>(GameDataObjType.GameServerData);
}
public static PlayerTable GetPlayerTable()
{
return ServerDataObjMgr.GetDataObj<PlayerTable>(GameDataObjType.PlayerTable);
}
public static DiamondHolderData GetDiamondHolderData()
{
return ServerDataObjMgr.GetDataObj<DiamondHolderData>(GameDataObjType.DiamondHolderData); ;
}
public static BattleServerVersionData GetBattleServerVersionData()
{
return ServerDataObjMgr.GetDataObj<BattleServerVersionData>(GameDataObjType.battleServerVersionData);
}
public static RealmBriefInfo GetRealmBriefInfo(int realmID)
{
GetGameServerData().m_allRealm.TryGetValue(realmID, out var realmBriefInfo);
return realmBriefInfo;
}
/// <summary>
/// 获取开服天数
/// </summary>
/// <param name="realmID"></param>
/// <returns></returns>
public static int GetOpenDay(int realmID, long nowTime = 0)
{
var realmInfo = GetRealmBriefInfo(realmID);
if(realmInfo == null)
{
return 1;
}
if (nowTime <= 0)
{
nowTime = GetTimeSecond();
}
int openDay = AppTime.GetDayElapse(nowTime, realmInfo.openTime) + 1;
return openDay;
}
/// <summary>
/// 获取开服当天的时间戳(秒)
/// </summary>
/// <returns></returns>
public static int GetServerOpenTimeSpan(int realmID)
{
var realmInfo = GetRealmBriefInfo(realmID);
if (realmInfo == null)
{
return 1;
}
return realmInfo.openTime;
}
public static ProtoCSStructPacker GetProtoPacker()
{
return ProtoPackerFactory.Instance.GetProtoCSStructPacker();
}
public static StructPacketSender GetPacketSender()
{
return GetGameServerData().m_packetSender;
}
public static uint GetWorldServerID()
{
return GetGameServerData().m_packetSender.GetWorldServerID();
}
public static DirtyString GetDirtyStringData()
{
return GetGameServerData().m_dirtyStringData;
}
public static LoginHandler GetLoginHandler()
{
return ServiceMgr.GetService<LoginHandler>(GameServiceType.LoginHandler);
}
public static PlayerTableOp GetPlayerTableOp()
{
return ServiceMgr.GetService<PlayerTableOp>(GameServiceType.PlayerTableOp);
}
public static Dictionary<int, RealmServerInfo> GetServerInfoMap()
{
return GetGameServerData().m_realmIdServerInfoMap;
}
public static ServerApp GetApp()
{
return GetGameServerData().m_app;
}
public static uint GetAppID()
{
return GetGameServerData().m_app.ServerID;
}
public static string GetAppIDStr()
{
return GetGameServerData().m_app.StrServerID;
}
public static long GetTimeSecond()
{
return GetGameServerData().m_app.Time.GetTimeSecond();
}
public static long GetTimeMs()
{
return GetGameServerData().m_app.Time.GetTime();
}
public static DateTime GetDateTime()
{
return GetGameServerData().m_app.Time.GetDateTime();
}
public static RealmServerInfo GetRealmServerInfo(int realmId)
{
var map = GetGameServerData().m_realmIdServerInfoMap;
if (map.ContainsKey(realmId) == false)
{
TraceLog.Error("GameServerUtils.GetRealmServerInfo no info {0}", realmId);
return null;
}
return map[realmId];
}
public static GameRankInfo GetGameRankInfo(int realmId)
{
var serverInfo = GetRealmServerInfo(realmId);
if(serverInfo == null)
{
return null;
}
return serverInfo.rankInfo;
}
public static GameReportSvc GetGameReportSvc()
{
return ServiceMgr.GetService<GameReportSvc>(GameServiceType.GameReportSvc);
}
public static PlayerDataSvc GetPlayerDataSvc()
{
return ServiceMgr.GetService<PlayerDataSvc>(GameServiceType.PlayerDataSvc);
}
public static PayHandler GetPayHandler()
{
return ServiceMgr.GetService<PayHandler>(GameServiceType.PayHandler);
}
public static SysHandler GetSysHandler()
{
return ServiceMgr.GetService<SysHandler>(GameServiceType.SysHandler);
}
public static FriendHandler GetFriendHandler()
{
return ServiceMgr.GetService<FriendHandler>(GameServiceType.FriendHandler);
}
public static FriendOpHandler GetFriendOpHandler()
{
return ServiceMgr.GetService<FriendOpHandler>(GameServiceType.FriendOpHandler);
}
public static MailHandler GetMailHandler()
{
return ServiceMgr.GetService<MailHandler>(GameServiceType.MailHandler);
}
public static MonitorHandler GetMonitorHandler()
{
return ServiceMgr.GetService<MonitorHandler>(GameServiceType.MonitorHandler);
}
public static EventHandlerMgr GetEventHandlerMgr()
{
return ServiceMgr.GetService<EventHandlerMgr>(GameServiceType.EventHandlerMgr);
}
public static BagHandler GetBagHandler()
{
return ServiceMgr.GetService<BagHandler>(GameServiceType.BagHandler);
}
public static DynamicMsgHandler GetDynamicMsgHandler()
{
return ServiceMgr.GetService<DynamicMsgHandler>(GameServiceType.DynamicMsgHandler);
}
public static RankHandler GetRankHandler()
{
return ServiceMgr.GetService<RankHandler>(GameServiceType.RankHandler);
}
public static EquipmentHandler GetEquipmentHandler()
{
return ServiceMgr.GetService<EquipmentHandler>(GameServiceType.EquipmentHandler);
}
public static LevelHandler GetLevelHandler()
{
return ServiceMgr.GetService<LevelHandler>(GameServiceType.LevelHandler);
}
public static MarketShopHandler GetMarketShopHandler()
{
return ServiceMgr.GetService<MarketShopHandler>(GameServiceType.MarketShopHandler);
}
public static NameHandler GetNameHandle()
{
return ServiceMgr.GetService<NameHandler>(GameServiceType.NameHandler);
}
public static TaskEXHandler GetTaskEXHandler()
{
return ServiceMgr.GetService<TaskEXHandler>(GameServiceType.TaskEXHandler);
}
public static HomeAdHandler GetHomeAdHandler()
{
return ServiceMgr.GetService<HomeAdHandler>(GameServiceType.HomeAdHandler);
}
public static BeginnerGuideHandler GetBeginnerGuideHandler()
{
return ServiceMgr.GetService<BeginnerGuideHandler>(GameServiceType.BeginnerGuideHandler);
}
public static ChatHandler GetChatHandler()
{
return ServiceMgr.GetService<ChatHandler>(GameServiceType.ChatHandler);
}
public static ActivityHandler GetActivityHandler()
{
return ServiceMgr.GetService<ActivityHandler>(GameServiceType.ActivityHandler);
}
/// <summary>
/// 获取服务器配置方法
/// </summary>
public static GameServerConfig GetServerConfig()
{
return (GameServerConfig)ServerConfigMgr.Instance.m_serverConfig;
}
public static void ReadAllCsvConfig()
{
TraceLog.Error("ReadAllCsvConfig begin");
TraceLog.Error("ReadAllCsvConfig end");
}
public static int GetLogicWorldId(int realmId)
{
var realmInfo = GetRealmServerInfo(realmId);
if (realmInfo != null)
{
return realmInfo.logicWorldId;
}
return 0;
}
public static int GetStarArenaBigRealm(int realmId)
{
var realmInfo = GetRealmServerInfo(realmId);
if (realmInfo != null)
{
return realmInfo.bigRealmId;
}
return 0;
}
public static void GetSequenceCheckIndex(int ID,out int rIndex, out int index, out int byteIndex)
{
CoreHelper.GetSequenceCheckIndex(ID,out rIndex,out index,out byteIndex);
}
public static bool CheckInSequence(int byteIndex, int sequence)
{
return CoreHelper.CheckInSequence(byteIndex,sequence);
}
public static void SetSequence(int byteIndex, ref int sequence)
{
CoreHelper.SetSequence(byteIndex,ref sequence);
}
public static void ClearSequence(int byteIndex, ref int sequence)
{
CoreHelper.ClearSequence(byteIndex,ref sequence);
}
public static List<int> GetConfigLogicWorldIds()
{
var data = GetGameServerData();
return data.m_configLogicWorldIds;
}
}
}