对战细节调整

This commit is contained in:
lishuo committed 2022-05-18 10:39:35 +08:00
1 parent d77ed1bad1
commit aa9a4080fe
4 files changed
+182 -89

No files matched your search

+51 -7
View File
@@ -12,15 +12,59 @@ namespace OnlineUserPool.Unility
public class GameRoomHelper
{
public static string GameRoomFilePath { get; set; }
public static string GameRoomIdPath { get; set; }
public static object _lockobj = new object();
public static object _lockMaxId = new object();
static GameRoomHelper()
{
GameRoomFilePath = AppDomain.CurrentDomain.BaseDirectory + "\\GameRoom.txt";
GameRoomIdPath = AppDomain.CurrentDomain.BaseDirectory + "\\GameRoomId.txt";
if (!File.Exists(GameRoomFilePath))
{
File.Create(GameRoomFilePath);
}
if (!File.Exists(GameRoomIdPath))
{
File.Create(GameRoomIdPath);
}
}
public static int GetMaxId()
{
try
{
if (!File.Exists(GameRoomIdPath))
{
return 0;
}
var content = File.ReadAllText(GameRoomIdPath);
if (string.IsNullOrEmpty(content))
{
return 0;
}
return Convert.ToInt32(content);
}
catch (Exception e)
{
Log.Error($"本地读取对战信息房间号出错:{e}");
return 0;
}
}
public static void SetMaxId(int id)
{
try
{
lock (_lockMaxId)
{
File.WriteAllText(GameRoomIdPath, $"{id}");
}
}
catch (Exception e)
{
Log.Error($"本地存储对战信息房间号出错:{e}");
}
}
public static List<RoomModel> Get()
{
var list = new List<RoomModel>();
@@ -48,13 +92,13 @@ namespace OnlineUserPool.Unility
{
try
{
var str = JsonConvert.SerializeObject(list);
File.WriteAllText(GameRoomFilePath,str);
}
catch (Exception e)
{
Log.Error($"本地存储对战信息出错:{e}");
lock (_lockobj)
{
var str = JsonConvert.SerializeObject(list);
File.WriteAllText(GameRoomFilePath, str);
}
}
catch (Exception e) { Log.Error($"本地存储对战信息出错:{e}"); }
}
}
}