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.
99 lines
3.1 KiB
99 lines
3.1 KiB
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace Game
|
|
{
|
|
public static class ServerDataFileDbSvc
|
|
{
|
|
private static long m_lastTickTime;
|
|
|
|
private static string GetSaveFileName()
|
|
{
|
|
return "./GameServerDb_" + GameServerUtils.GetApp().ServerID.ToString() + ".fdb";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存到数据库,存本地文件
|
|
/// </summary>
|
|
public static void SaveDataToFile()
|
|
{
|
|
ref GameServerGlobalData data = ref GameServerUtils.GetGameServerData().m_GameServerGlobalData;
|
|
|
|
string filename = GetSaveFileName();
|
|
int iRet = Sog.IO.FileDBSave.SaveToFile(ref data, filename);
|
|
if (iRet != 0)
|
|
{
|
|
TraceLog.Error("ServerDataFileDbSvc.SaveDataToFile save file {0} error ,ret {1}", filename, iRet);
|
|
return;
|
|
}
|
|
|
|
TraceLog.Trace("ServerDataFileDbSvc.SaveDataToFile save file {0} success", filename);
|
|
}
|
|
|
|
public static void LoadDataFromFile()
|
|
{
|
|
string filename = GetSaveFileName();
|
|
TraceLog.Trace("ServerDataFileDbSvc.LoadDataFromFile load now file {0}", filename);
|
|
|
|
ref GameServerGlobalData data = ref GameServerUtils.GetGameServerData().m_GameServerGlobalData;
|
|
bool success = Sog.IO.FileDBSave.ReadFromFile(ref data, filename);
|
|
if (success)
|
|
{
|
|
TraceLog.Trace("ServerDataFileDbSvc.LoadDataFromFile load file {0} success, count {1}"
|
|
, filename, data.ShareFBGetPhoneCardNum);
|
|
}
|
|
else
|
|
{
|
|
GameServerUtils.GetGameServerData().m_GameServerGlobalData = new GameServerGlobalData();
|
|
|
|
TraceLog.Trace("ServerDataFileDbSvc.LoadDataFromFile no Data, new empty object");
|
|
|
|
//立即保存一下
|
|
SaveDataToFile();
|
|
}
|
|
}
|
|
|
|
public static void OnTick(long nowMs)
|
|
{
|
|
//5秒一次
|
|
if(nowMs - m_lastTickTime < 5000)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_lastTickTime = nowMs;
|
|
|
|
long secondTime = nowMs / 1000;
|
|
|
|
ref GameServerGlobalData data = ref GameServerUtils.GetGameServerData().m_GameServerGlobalData;
|
|
if(AppTime.IsSameDay(secondTime, data.DailyTime))
|
|
{
|
|
return;
|
|
}
|
|
|
|
TraceLog.Trace("ServerDataFileDbSvc.Tick diff day start , reset data");
|
|
|
|
data.DailyTime = secondTime;
|
|
|
|
data.ShareFBGetPhoneCardNum = 0;
|
|
}
|
|
|
|
//是否达到全服每日最大值,不能再发电话卡了
|
|
public static bool IsShareFBGetPhoneCardLimit(int limitNum)
|
|
{
|
|
ref GameServerGlobalData data = ref GameServerUtils.GetGameServerData().m_GameServerGlobalData;
|
|
|
|
return data.ShareFBGetPhoneCardNum >= limitNum;
|
|
}
|
|
|
|
public static void AddShareFBGetPhoneCardNum()
|
|
{
|
|
ref GameServerGlobalData data = ref GameServerUtils.GetGameServerData().m_GameServerGlobalData;
|
|
|
|
data.ShareFBGetPhoneCardNum++;
|
|
|
|
SaveDataToFile();
|
|
}
|
|
|
|
}
|
|
}
|
|
|