forked from powerfun/udpservice
对战
This commit is contained in:
1 parent
81409dca9e
commit
d77ed1bad1
13 files changed
+817
-47
No files matched your search
@@ -22,6 +22,8 @@ namespace OnlineUserPool.Unility
|
||||
|
||||
public static int TcpPort { get; private set; }
|
||||
|
||||
public static string GameRoomFilePath { get; private set; }
|
||||
|
||||
|
||||
static ConfigHelp()
|
||||
{
|
||||
@@ -32,7 +34,6 @@ namespace OnlineUserPool.Unility
|
||||
UdpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
|
||||
|
||||
TcpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["TcpPort"]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user