-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
97 lines (83 loc) · 4.42 KB
/
Copy pathConfig.cs
File metadata and controls
97 lines (83 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace PhotonServer
{
// Host configuration, loaded from config.json next to the executable. A
// default file is written on first run so it's easy to discover and edit.
public sealed class ServerConfig
{
/// <summary>UDP ports to bind. The standard Photon UDP ports are
/// 27000 (name server), 27001 (master), 27002 (game); 5055 covers
/// clients configured with a custom master port.</summary>
public int[] Ports { get; set; } = { 5055, 27000, 27001, 27002 };
/// <summary>IP or hostname handed to clients for the create/join game-server
/// redirect (they reconnect here on the game-server port to enter a room).
/// Defaults to loopback for local testing — set this to your VPS's public
/// IP or DNS name when deploying so remote clients can reach it.</summary>
public string PublicHost { get; set; } = "127.0.0.1";
/// <summary>Hard cap on actors per room, applied to every room on top of
/// the room's own MaxPlayers. -1 means no server-imposed limit.</summary>
public int MaxPeersPerRoom { get; set; } = -1;
/// <summary>Maximum number of concurrent rooms. -1 means no limit.</summary>
public int MaxRooms { get; set; } = -1;
/// <summary>If set, clients must present this AppId to authenticate.
/// null accepts any AppId (useful while reverse engineering).</summary>
public string? RequireAppId { get; set; } = null;
/// <summary>If set, clients must present this AppVersion. null accepts any.</summary>
public string? RequireAppVersion { get; set; } = null;
/// <summary>Drop a peer (and remove it from its room) after this many
/// milliseconds without any inbound packet. Default 5 minutes so a briefly
/// stalled/backgrounded client is not kicked. -1 disables timeout sweeps.</summary>
public int PeerTimeoutMs { get; set; } = 300000;
/// <summary>Region code advertised to clients (shown in the game's UI).
/// Empty = auto-detect from the server's public IP geolocation.</summary>
public string Region { get; set; } = "";
/// <summary>Log every decoded operation/event. Disable for quieter,
/// higher-throughput hosting.</summary>
public bool VerboseLogging { get; set; } = true;
/// <summary>Load plugin DLLs from <see cref="PluginsDirectory"/> at startup.</summary>
public bool EnablePlugins { get; set; } = true;
/// <summary>Directory scanned for plugin *.dll files on boot. A relative
/// value is resolved next to the server executable (and created on first
/// run if absent); an absolute path is used as-is.</summary>
public string PluginsDirectory { get; set; } = "plugins";
// ── Load / create ────────────────────────────────────────────────────
public static ServerConfig Load(string path)
{
var opts = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
};
if (!File.Exists(path))
{
var def = new ServerConfig();
try
{
File.WriteAllText(path, JsonSerializer.Serialize(def, opts));
Console.WriteLine($"[Config] No config.json found — wrote defaults to {path}");
}
catch (Exception e)
{
Console.WriteLine($"[Config] Could not write default config: {e.Message}");
}
return def;
}
try
{
var cfg = JsonSerializer.Deserialize<ServerConfig>(File.ReadAllText(path), opts);
if (cfg == null) { Console.WriteLine("[Config] Empty config — using defaults"); return new ServerConfig(); }
Console.WriteLine($"[Config] Loaded {path}");
return cfg;
}
catch (Exception e)
{
Console.WriteLine($"[Config] Failed to parse {path}: {e.Message} — using defaults");
return new ServerConfig();
}
}
}
}