Repository navigation
Expand file tree
/
Copy pathServerConfig.cs
More file actions
executable file
·69 lines (54 loc) · 1.97 KB
/
Copy pathServerConfig.cs
File metadata and controls
executable file
·69 lines (54 loc) · 1.97 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
using AMP.Logging;
using Newtonsoft.Json;
using System;
using System.IO;
using static AMP.Data.SafeFile;
namespace AMP.DedicatedServer {
internal class ServerConfig {
[JsonIgnore]
public string filePath = "";
public ServerSettings serverSettings = new ServerSettings();
public HostingSettings hostingSettings = new HostingSettings();
public class ServerSettings {
public int port = 26950;
public string map = "Home";
public string mode = "Default";
public int max_players = 10;
public string password = "";
public string masterServerUrl = "bns.devforce.de";
public bool showInServerList = false;
public bool ignoreCertificateErrors = false;
public string servername = "Unnamed Server";
public string serverdescription = "No description";
public bool plugin_autorefresh = false;
}
#region Save and Load
public void Save() {
Save(filePath);
}
public void Save(string path) {
Save(this, path);
}
public static void Save(ServerConfig serverConfig, string path) {
string json = JsonConvert.SerializeObject(serverConfig, Formatting.Indented);
File.WriteAllText(path, json);
}
public static ServerConfig Load(string path) {
ServerConfig serverConfig = new ServerConfig();
bool safe = true;
if(File.Exists(path)) {
string json = File.ReadAllText(path);
try {
serverConfig = JsonConvert.DeserializeObject<ServerConfig>(json);
serverConfig.filePath = path;
} catch(Exception e) {
Log.Err(e);
safe = false;
}
}
if(safe) serverConfig.Save(path);
return serverConfig;
}
#endregion
}
}