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.
189 lines
5.4 KiB
189 lines
5.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
|
|
namespace GameDB
|
|
{
|
|
public static class GameDBServerUtils
|
|
{
|
|
|
|
public static string GetUserTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcRoleTableIndex(uid);
|
|
|
|
return "tbuser_" + index.ToString();
|
|
}
|
|
|
|
public static string GetMailTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcRoleTableIndex(uid);
|
|
|
|
return "tbmail_" + index.ToString();
|
|
}
|
|
|
|
public static string GetArenaDefenceTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcRoleTableIndex(uid);
|
|
|
|
return "tbarena_defence_" + index.ToString();
|
|
}
|
|
|
|
public static string GetArenaBattleRecordTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcRoleTableIndex(uid);
|
|
|
|
return "tbarena_battle_record_" + index.ToString();
|
|
}
|
|
|
|
public static string GetRacehorseTableName()
|
|
{
|
|
return "tbrace_user";
|
|
}
|
|
|
|
public static string GetRacehorseSignUpTableName()
|
|
{
|
|
return "tbrace_user_signup";
|
|
}
|
|
|
|
public static string GetTradeTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcTradeTableIndex(uid);
|
|
|
|
return "tbtrade_user_" + index.ToString();
|
|
}
|
|
public static string GetPetPvpPlayerTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcPetPvpPlayerTableIndex(uid);
|
|
|
|
return "tbpetpvp_player_" + index.ToString();
|
|
}
|
|
public static string GetNewPeakArenaTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcNewPeakArenaPlayerTableIndex(uid);
|
|
|
|
return "tbpeakarena_player_" + index.ToString();
|
|
}
|
|
public static GameDBServerData GetDBServerData()
|
|
{
|
|
return ServerDataObjMgr.GetDataObj<GameDBServerData>(GameDBDataObjType.GameDBServerData);
|
|
}
|
|
|
|
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 ServerApp GetApp()
|
|
{
|
|
return GetDBServerData().m_app;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取服务器配置方法
|
|
/// </summary>
|
|
public static GameDBServerConfig GetServerConfig()
|
|
{
|
|
return (GameDBServerConfig)ServerConfigMgr.Instance.m_serverConfig;
|
|
}
|
|
|
|
public static string GetFriendTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcRoleTableIndex(uid);
|
|
|
|
return "tbfriend_" + index.ToString();
|
|
}
|
|
|
|
public static string GetUnionTableName(int realmId)
|
|
{
|
|
int index = TableIndexCalc.CalcUnionTableIndex(realmId);
|
|
|
|
return "tbunion_" + index.ToString();
|
|
}
|
|
|
|
public static string GetUnionRoleTableName(int realmId)
|
|
{
|
|
int index = TableIndexCalc.CalcUnionRoleTableIndex(realmId);
|
|
|
|
return "tbunionrole_" + index.ToString();
|
|
}
|
|
|
|
public static string GetBattleReplayTableName(long battleId)
|
|
{
|
|
int index = TableIndexCalc.CalcBattleReplayTableIndex(battleId);
|
|
return "tbbattle_replay_" + index.ToString();
|
|
}
|
|
|
|
public static string GetMainlandRecordTableName()
|
|
{
|
|
return "tb_mainland_recording";
|
|
}
|
|
|
|
public static string GetWorldHomeTableName(long uid)
|
|
{
|
|
int index = TableIndexCalc.CalcWorldHomeTableIndex(uid);
|
|
|
|
return "tbworld_home_" + index.ToString();
|
|
}
|
|
|
|
public static string GetWorldRobotHomeTableName()
|
|
{
|
|
return "tbworld_robot_home";
|
|
}
|
|
|
|
public static long GetactRemRankId(int remId, int actId)
|
|
{
|
|
return (long)remId * 10000000 + actId;
|
|
}
|
|
|
|
public static void GetactRemAndRankId(long actRemRankId, out int remId, out int actId)
|
|
{
|
|
remId = (int)(actRemRankId / 10000000);
|
|
actId = (int)(actRemRankId % 10000000);
|
|
}
|
|
|
|
public static void ParseDBConfig(ServerApp app, out int dbtype, out string dbname, out string dbip)
|
|
{
|
|
GameDBServerConfig serverConfig = GetServerConfig();
|
|
|
|
// 优先使用参数里传入的db配置, 方便每个人独立修改
|
|
string dbtypestr = app.GetCluster().GetAppParamByKey("gamedbtype");
|
|
if (string.IsNullOrEmpty(dbtypestr) || !int.TryParse(dbtypestr, out dbtype))
|
|
{
|
|
dbtype = serverConfig.dbtype;
|
|
}
|
|
|
|
dbip = app.GetCluster().GetAppParamByKey("gamedbip");
|
|
if (string.IsNullOrEmpty(dbip))
|
|
{
|
|
dbip = serverConfig.dbip;
|
|
}
|
|
|
|
if (dbtype == 1) // mongo db 不再使用
|
|
{
|
|
TraceLog.Error("GameDBServerUtils.ParseDBConfig invalid dbtype 1");
|
|
}
|
|
|
|
// dbname不让单独修改, 大家统一简单些
|
|
dbname = serverConfig.dbname;
|
|
}
|
|
}
|
|
}
|
|
|