34 lines
1.5 KiB
C#
34 lines
1.5 KiB
C#
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace XWorld.Server.Host
|
|
{
|
|
public sealed class GameManifest
|
|
{
|
|
public string GameId { get; set; }
|
|
public int Version { get; set; }
|
|
public string ServerAssembly { get; set; } // 例如 "RPS.Server.dll"
|
|
public string ServerEntryType { get; set; } // 例如 "RPS.Server.RpsServerRoom"
|
|
public int MinFrameworkVersion { get; set; }
|
|
public int PlayerCount { get; set; }
|
|
public int TickRateHz { get; set; }
|
|
|
|
public static GameManifest Parse(string json)
|
|
{
|
|
var opts = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
GameManifest m;
|
|
try { m = JsonSerializer.Deserialize<GameManifest>(json, opts); }
|
|
catch (JsonException ex) { throw new InvalidDataException("game.json: 无法解析", ex); }
|
|
|
|
if (m == null) throw new InvalidDataException("game.json: 内容为空");
|
|
if (string.IsNullOrEmpty(m.GameId)) throw new InvalidDataException("game.json: 缺少 gameId");
|
|
if (string.IsNullOrEmpty(m.ServerEntryType)) throw new InvalidDataException("game.json: 缺少 serverEntryType");
|
|
if (string.IsNullOrEmpty(m.ServerAssembly)) throw new InvalidDataException("game.json: 缺少 serverAssembly");
|
|
if (m.Version <= 0) throw new InvalidDataException("game.json: version 必须为正");
|
|
return m;
|
|
}
|
|
|
|
public static GameManifest Load(string path) => Parse(File.ReadAllText(path));
|
|
}
|
|
}
|