-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGhostNetModuleSettings.cs
More file actions
314 lines (274 loc) · 10.2 KB
/
GhostNetModuleSettings.cs
File metadata and controls
314 lines (274 loc) · 10.2 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
using Celeste.Mod.UI;
using FMOD.Studio;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Monocle;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;
namespace Celeste.Mod.Ghost.Net {
public class GhostNetModuleSettings : EverestModuleSettings {
#region Main Settings
[SettingInGame(false)]
public string Name {
get {
return GhostModule.Settings.Name;
}
set {
GhostModule.Settings.Name = value;
}
}
[YamlIgnore]
public bool Connection {
get {
return GhostNetModule.Instance.Client?.Connection != null;
}
set {
if (value) {
GhostNetModule.ResetGhostModuleSettings();
GhostNetModule.Instance.Start();
} else {
GhostNetModule.Instance.Stop();
}
if (ServerEntry != null)
ServerEntry.Disabled = value;
}
}
[YamlIgnore]
[SettingIgnore]
public TextMenu.OnOff EnabledEntry { get; protected set; }
[SettingIgnore]
[YamlMember(Alias = "Server")]
public string _Server { get; set; } = "celeste.0x0ade.ga";
[YamlIgnore]
public string Server {
get {
return _Server;
}
set {
_Server = value;
if (Connection)
GhostNetModule.Instance.Start();
}
}
[YamlIgnore]
[SettingIgnore]
public TextMenu.Button ServerEntry { get; protected set; }
#endregion
#region Client Settings
public bool Collision { get; set; } = true;
public bool Sounds { get; set; } = true;
[SettingIgnore]
// [SettingRange(0, 3)]
public int SendFrameSkip { get; set; } = 0;
[SettingIgnore]
[SettingRange(4, 16)]
public int ChatLogLength { get; set; } = 8;
[SettingIgnore]
public bool SendUFramesInMStream { get; set; } = false;
[SettingIgnore]
public string[] EmoteFavs { get; set; }
#endregion
#region Server Settings
[SettingIgnore]
public string ServerName { get; set; } = "";
[SettingIgnore]
[YamlIgnore]
public string ServerNameAuto =>
!string.IsNullOrEmpty(ServerName) ? ServerName :
$"{GhostModule.Settings.Name}'{(GhostModule.Settings.Name.ToLowerInvariant().EndsWith("s") ? "" : "s")} server";
[SettingIgnore]
public string ServerMessageGreeting { get; set; } = "Welcome ((player))#((id)), to ((server))!";
[SettingIgnore]
public string ServerMessageMOTD { get; set; } =
@"Don't cheat and have fun!
Press T to talk.
Send /help for a list of all commands.";
[SettingIgnore]
public string ServerMessageLeave { get; set; } = "Cya, ((player))#((id))!";
[SettingIgnore]
public int ServerMaxNameLength { get; set; } = 16;
[SettingIgnore]
public int ServerMaxEmoteValueLength { get; set; } = 2048;
[SettingIgnore]
public int ServerMaxChatTextLength { get; set; } = 256;
[SettingIgnore]
public string ServerCommandPrefix { get; set; } = "/";
[YamlMember(Alias = "ServerColorInfo")]
[SettingIgnore]
public string ServerColorDefaultHex {
get {
return ServerColorDefault.R.ToString("X2") + ServerColorDefault.G.ToString("X2") + ServerColorDefault.B.ToString("X2");
}
set {
if (string.IsNullOrEmpty(value))
return;
try {
ServerColorDefault = Calc.HexToColor(value);
} catch (Exception e) {
Logger.Log(LogLevel.Warn, "rainbowmod", "Invalid ServerColorDefault!");
e.LogDetailed();
}
}
}
[YamlIgnore]
[SettingIgnore]
public Color ServerColorDefault { get; set; } = Color.LightSlateGray;
[YamlMember(Alias = "ServerColorBroadcast")]
[SettingIgnore]
public string ServerColorBroadcastHex {
get {
return ServerColorBroadcast.R.ToString("X2") + ServerColorBroadcast.G.ToString("X2") + ServerColorBroadcast.B.ToString("X2");
}
set {
if (string.IsNullOrEmpty(value))
return;
try {
ServerColorBroadcast = Calc.HexToColor(value);
} catch (Exception e) {
Logger.Log(LogLevel.Warn, "rainbowmod", "Invalid ServerColorBroadcast!");
e.LogDetailed();
}
}
}
[YamlIgnore]
[SettingIgnore]
public Color ServerColorBroadcast { get; set; } = Color.Yellow;
[YamlMember(Alias = "ServerColorError")]
[SettingIgnore]
public string ServerColorErrorHex {
get {
return ServerColorError.R.ToString("X2") + ServerColorError.G.ToString("X2") + ServerColorError.B.ToString("X2");
}
set {
if (string.IsNullOrEmpty(value))
return;
try {
ServerColorError = Calc.HexToColor(value);
} catch (Exception e) {
Logger.Log(LogLevel.Warn, "rainbowmod", "Invalid ServerColorError!");
e.LogDetailed();
}
}
}
[YamlIgnore]
[SettingIgnore]
public Color ServerColorError { get; set; } = Color.MediumVioletRed;
[YamlMember(Alias = "ServerColorCommand")]
[SettingIgnore]
public string ServerColorCommandHex {
get {
return ServerColorCommand.R.ToString("X2") + ServerColorCommand.G.ToString("X2") + ServerColorCommand.B.ToString("X2");
}
set {
if (string.IsNullOrEmpty(value))
return;
try {
ServerColorCommand = Calc.HexToColor(value);
} catch (Exception e) {
Logger.Log(LogLevel.Warn, "rainbowmod", "Invalid ServerColorCommand!");
e.LogDetailed();
}
}
}
[YamlIgnore]
[SettingIgnore]
public Color ServerColorCommand { get; set; } = Color.DarkOliveGreen;
[YamlMember(Alias = "ServerColorEmote")]
[SettingIgnore]
public string ServerColorEmoteHex {
get {
return ServerColorEmote.R.ToString("X2") + ServerColorEmote.G.ToString("X2") + ServerColorEmote.B.ToString("X2");
}
set {
if (string.IsNullOrEmpty(value))
return;
try {
ServerColorEmote = Calc.HexToColor(value);
} catch (Exception e) {
Logger.Log(LogLevel.Warn, "rainbowmod", "Invalid ServerColorEmote!");
e.LogDetailed();
}
}
}
[YamlIgnore]
[SettingIgnore]
public Color ServerColorEmote { get; set; } = Color.LightSeaGreen;
public string[] ServerRemoteOpIPs { get; set; } = { "192.168.2.1" };
#endregion
#region Input Settings
public List<Buttons> ButtonPlayerList { get; set; } = new List<Buttons>();
public List<Buttons> ButtonEmoteSend { get; set; } = new List<Buttons>();
public List<Buttons> ButtonChat { get; set; } = new List<Buttons>();
#endregion
#region Helpers
[SettingIgnore]
[YamlIgnore]
public string Host {
get {
string server = Server.ToLowerInvariant();
int indexOfPort;
int port;
if (!string.IsNullOrEmpty(Server) &&
(indexOfPort = server.LastIndexOf(':')) != -1 &&
int.TryParse(server.Substring(indexOfPort + 1), out port)
) {
return server.Substring(0, indexOfPort);
}
return server;
}
}
[SettingIgnore]
[YamlIgnore]
public int Port {
get {
string server = Server;
int indexOfPort;
int port;
if (!string.IsNullOrEmpty(Server) &&
(indexOfPort = server.LastIndexOf(':')) != -1 &&
int.TryParse(server.Substring(indexOfPort + 1), out port)
) {
return port;
}
// Default port
return 2782;
}
}
[SettingIgnore]
[YamlIgnore]
public bool IsHost =>
Host == "localhost" ||
Host == "127.0.0.1"
;
#endregion
#region Custom Entry Creators
public void CreateConnectionEntry(TextMenu menu, bool inGame) {
if (Celeste.PlayMode == Celeste.PlayModes.Debug)
menu.Add(new TextMenu.SubHeader("modoptions_ghostnetmodule_debugwarn".DialogCleanOrNull() ?? "WARNING: DEBUG MODE DETECTED!"));
menu.Add(
(EnabledEntry = new TextMenu.OnOff("modoptions_ghostnetmodule_connected".DialogCleanOrNull() ?? "Connected", Connection))
.Change(v => Connection = v)
);
}
public void CreateServerEntry(TextMenu menu, bool inGame) {
menu.Add(
(ServerEntry = new TextMenu.Button(("modoptions_ghostnetmodule_server".DialogCleanOrNull() ?? "Server") + ": " + Server))
.Pressed(() => {
Audio.Play("event:/ui/main/savefile_rename_start");
menu.SceneAs<Overworld>().Goto<OuiModOptionString>().Init<OuiModOptions>(
Server,
v => Server = v,
maxValueLength: 30
);
})
);
ServerEntry.Disabled = inGame || Connection;
}
#endregion
}
}