forked from powerfun/udpservice
61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using Newtonsoft.Json;
|
|
using OnlineUserPool.Model;
|
|
using Serilog;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace OnlineUserPool.Unility
|
|
{
|
|
public class GameRoomHelper
|
|
{
|
|
public static string GameRoomFilePath { get; set; }
|
|
static GameRoomHelper()
|
|
{
|
|
GameRoomFilePath = AppDomain.CurrentDomain.BaseDirectory + "\\GameRoom.txt";
|
|
if (!File.Exists(GameRoomFilePath))
|
|
{
|
|
File.Create(GameRoomFilePath);
|
|
}
|
|
}
|
|
|
|
public static List<RoomModel> Get()
|
|
{
|
|
var list = new List<RoomModel>();
|
|
try
|
|
{
|
|
if (!File.Exists(GameRoomFilePath))
|
|
{
|
|
return list;
|
|
}
|
|
var content = File.ReadAllText(GameRoomFilePath);
|
|
if (string.IsNullOrEmpty(content))
|
|
{
|
|
return list;
|
|
}
|
|
return JsonConvert.DeserializeObject<List<RoomModel>>(content);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"读取本地存储对战信息出错:{e}");
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public static void Set(List<RoomModel> list)
|
|
{
|
|
try
|
|
{
|
|
var str = JsonConvert.SerializeObject(list);
|
|
File.WriteAllText(GameRoomFilePath,str);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($"本地存储对战信息出错:{e}");
|
|
}
|
|
}
|
|
}
|
|
}
|