using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; namespace DB { public static class DBServerUtils { public static string GetAccountTableName(int accountType, string accountID) { int accountTableIndex = TableIndexCalc.CalcAccountTableIndex(accountType, accountID); return "tbaccount_" + accountTableIndex.ToString(); } public static string GetAccountRealmUidLinkTableName(int accountType, string accountID) { int accountTableIndex = TableIndexCalc.CalcAccountTableIndex(accountType, accountID); return "tbacc_realmuid_link_" + accountTableIndex.ToString(); } public static string GetAccountRealmUidLinkTableNameByUid(int uid) { // 目前 根据uid 和根据account计算结果都相同,这里新增一个根据uid获取 表名的方法 // 直接就在这处理了 int index = (int)(uid % 100); if (index == 0) { index = 100; } return "tbacc_realmuid_link_" + index; } public static string GetPayTableName(long uid) { int index = TableIndexCalc.CalcPayTableIndex(uid); return "tbpay_" + index; } public static DBServerData GetDBServerData() { return ServerDataObjMgr.GetDataObj(DBDataObjType.DBServerData); } public static ProtoCSStructPacker GetProtoPacker() { return ProtoPackerFactory.Instance.GetProtoCSStructPacker(); } public static StructPacketSender GetPacketSender() { return GetDBServerData().m_packetSender; } public static long GetTimeSecond() { return GetDBServerData().m_app.Time.GetTimeSecond(); } public static uint GetAppID() { return GetDBServerData().m_app.ServerID; } /// /// 获取服务器配置方法 /// public static DBServerConfig GetServerConfig() { return (DBServerConfig)ServerConfigMgr.Instance.m_serverConfig; } public static void ParseDBConfig(ServerApp app, out int dbtype, out string dbname, out string dbip) { DBServerConfig serverConfig = GetServerConfig(); // 优先使用参数里传入的db配置, 方便每个人独立修改 string dbtypestr = app.GetCluster().GetAppParamByKey("dbtype"); if (string.IsNullOrEmpty(dbtypestr) || !int.TryParse(dbtypestr, out dbtype)) { dbtype = serverConfig.dbtype; } dbip = app.GetCluster().GetAppParamByKey("dbip"); if (string.IsNullOrEmpty(dbip)) { dbip = serverConfig.dbip; } if (dbtype == 1) // mongo db 不再使用 { TraceLog.Error("GameDBServerUtils.ParseDBConfig invalid dbtype 1"); } else if (dbtype == 2) { string rs = app.GetCluster().GetAppParamByKey("redisDBReplicaSet"); if (string.IsNullOrEmpty(rs)) { rs = serverConfig.redisDBReplicaSet; } // 配置格式: 127.0.0.1:27027;127.0.0.1:27028;127.0.0.1:27029, 需要把;替换成, if (! string.IsNullOrEmpty(rs)) { dbip = rs.Replace(';', ',').TrimEnd(','); } } // dbname不让单独修改, 大家统一简单些 dbname = serverConfig.dbname; } } }