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.
120 lines
3.8 KiB
120 lines
3.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
namespace Operation
|
|
{
|
|
class SaveFileRoleInfo
|
|
{
|
|
public List<IDValue32Class> uid_realmid = new List<IDValue32Class>();
|
|
}
|
|
|
|
public static class RoleInfoMap
|
|
{
|
|
private static SaveFileRoleInfo infoList;
|
|
private static Dictionary<long, int> infoMap = new Dictionary<long, int>();
|
|
public static bool needSave = false;
|
|
|
|
public static void OnSyncRoleinfoToOpsvr(uint serverID, StructPacket packet)
|
|
{
|
|
ref var sync = ref packet.GetMessage<SSSyncRoleInfoToOpSvr>();
|
|
if(!infoMap.ContainsKey(sync.PlayerUid))
|
|
{
|
|
infoMap.Add(sync.PlayerUid,sync.RealmId);
|
|
needSave = true;
|
|
}
|
|
}
|
|
|
|
private static string GetSaveFileName()
|
|
{
|
|
return "./OperationServerDb_RoleInfoMap_" + OperationServerUtils.GetApp().ServerID.ToString() + ".fdb";
|
|
}
|
|
|
|
//保存到数据库,存本地文件
|
|
public static void SaveDataToFile()
|
|
{
|
|
DateTime begin = DateTime.Now;
|
|
|
|
string filename = GetSaveFileName();
|
|
|
|
infoList.uid_realmid.Clear();
|
|
|
|
foreach (var item in infoMap)
|
|
{
|
|
IDValue32Class temp = new IDValue32Class();
|
|
temp.id = (int)item.Key;
|
|
temp.value = (int)item.Value;
|
|
infoList.uid_realmid.Add(temp);
|
|
}
|
|
|
|
int iRet = Sog.IO.FileDBSaveByBinSerialize.SaveToFile(infoList, filename);
|
|
if (iRet != 0)
|
|
{
|
|
TraceLog.Error("RoleInfoMap.SaveDataToFile save file {0} error ,ret {1}", filename, iRet);
|
|
return;
|
|
}
|
|
infoList.uid_realmid.Clear();//留着无用
|
|
needSave = false;
|
|
TraceLog.Trace("RoleInfoMap.SaveDataToFile save file {0} success, count {1} ,costTime {2}(ms)", filename,
|
|
infoList.uid_realmid.Count, DateTime.Now.Millisecond - begin.Millisecond);
|
|
}
|
|
|
|
public static void LoadDataFromFile()
|
|
{
|
|
string filename = GetSaveFileName();
|
|
|
|
infoList = Sog.IO.FileDBSaveByBinSerialize.ReadFromFile<SaveFileRoleInfo>(filename);
|
|
if (infoList == null)
|
|
{
|
|
infoList = new SaveFileRoleInfo();
|
|
|
|
TraceLog.Trace("RoleInfoMap.LoadDataFromFile no Data, new empty object");
|
|
|
|
//立即保存一下
|
|
SaveDataToFile();
|
|
}
|
|
|
|
infoMap.Clear();
|
|
foreach (var item in infoList.uid_realmid)
|
|
{
|
|
infoMap.Add(item.id, item.value);
|
|
}
|
|
infoList.uid_realmid.Clear();//留着无用
|
|
TraceLog.Trace("RoleInfoMap.LoadDataFromFile end");
|
|
}
|
|
|
|
//返回 <realmid,List<uid>>
|
|
public static Dictionary<int, List<long>> CheckMailUidList(string[] uids)
|
|
{
|
|
Dictionary<int, string> tmp = new Dictionary<int, string>();
|
|
Dictionary<int, List<long>> dict = new Dictionary<int, List<long>>();
|
|
string splitStr = string.Empty;
|
|
|
|
foreach (var item in uids)
|
|
{
|
|
if(long.TryParse(item,out long uid) && uid > 0)
|
|
{
|
|
int realmid = 0;
|
|
if(infoMap.ContainsKey(uid))
|
|
{
|
|
realmid = infoMap[uid];
|
|
}
|
|
if(dict.ContainsKey(realmid))
|
|
{
|
|
dict[realmid].Add(uid);
|
|
}
|
|
else
|
|
{
|
|
dict.Add(realmid,new List<long>() { uid});
|
|
}
|
|
}
|
|
}
|
|
|
|
return dict;
|
|
}
|
|
}
|
|
}
|
|
|