forked from powerfun/udpservice
对战细节调整
This commit is contained in:
1 parent
d77ed1bad1
commit
aa9a4080fe
4 files changed
+182
-89
No files matched your search
@@ -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}"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user