using System; using System.Linq; using System.Collections.Generic; using ProtoCSStruct; using Sog; namespace PlayerOp { public static class PlayerOpServerUtils { public static PlayerOpServerData GetPlayerOpServerData() { return ServerDataObjMgr.GetDataObj(PlayerOpDataObjType.ExchangeCodeServerData); } public static string GetExchangeRecordTableName(int codeIndex) { int accountTableIndex = TableIndexCalc.CalcExchangeRecordIndex(codeIndex); return "tbexchange_record_" + accountTableIndex.ToString(); } public static string CalcCommonExchangeRecordIndex(int codeIndex) { int accountTableIndex = TableIndexCalc.CalcCommonExchangeRecordIndex(codeIndex); return "tbexchange_record_common_" + accountTableIndex.ToString(); } public static ServerApp GetApp() { return GetPlayerOpServerData().m_app; } public static ProtoCSStructPacker GetProtoPacker() { return ProtoPackerFactory.Instance.GetProtoCSStructPacker(); } public static uint GetAppID() { return GetPlayerOpServerData().m_app.ServerID; } public static StructPacketSender GetPacketSender() { return GetPlayerOpServerData().m_packetSender; } public static PlayerOpMsgHandler GetMsgHandler() { return ServiceMgr.GetService(PlayerOpServiceType.PlayerOpMsgHandler); } public static ExchangeSvc GetExchangeSvc() { return ServiceMgr.GetService(PlayerOpServiceType.ExchangeSvc); } public static ExchangeOp GetExchangeOp() { return ServiceMgr.GetService(PlayerOpServiceType.ExchangeOp); } public static long GetTimeSecond() { return GetPlayerOpServerData().m_app.Time.GetTimeSecond(); } //获取服务器配置方法 public static PlayerOpServerConfig GetServerConfig() { return (PlayerOpServerConfig)ServerConfigMgr.Instance.m_serverConfig; } public static PlayerOpServerConfig ParseDBConfig(ServerApp app, out int dbtype, out string dbname, out string dbip) { PlayerOpServerConfig serverConfig = GetServerConfig(); // 优先使用参数里传入的db配置, 方便每个人独立修改 string dbtypestr = app.GetCluster().GetAppParamByKey("playeropdbtype"); if (string.IsNullOrEmpty(dbtypestr) || !int.TryParse(dbtypestr, out dbtype)) { dbtype = serverConfig.dbtype; } dbip = app.GetCluster().GetAppParamByKey("playeropdbip"); if (string.IsNullOrEmpty(dbip)) { dbip = serverConfig.dbip; } if (dbtype == 1) // mongo db 不再使用 { TraceLog.Error("PlayerOpServerUtils.ParseDBConfig invalid dbtype 1"); } // dbname不让单独修改, 大家统一简单些 dbname = serverConfig.dbname; return serverConfig; } } }