-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerRules.cs
65 lines (54 loc) · 1.76 KB
/
ServerRules.cs
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
using System.Globalization;
using MyApp;
public class ServerRules
{
public Dictionary<string, string> Rules { get; private set; } = new Dictionary<string, string>();
public ServerRules(byte[] data)
{
ReadInfo(data);
}
internal async void ReadInfo(byte[] data)
{
var reader = new Reader(data);
reader.Skip(4);
byte header = reader.ReadByte();
short numEntries = reader.ReadShort();
Rules.Clear();
for (int i = 0; i < numEntries; i++)
{
var name = reader.ReadUTF8String();
var value = reader.ReadUTF8String();
Rules.Add(name, value);
}
var modList = new List<string>();
// Get mod titles
foreach (var entry in Rules)
{
if (entry.Key.StartsWith("mods["))
{
var entries = entry.Value.Split(' ', StringSplitOptions.RemoveEmptyEntries);
foreach (var modid_hex in entries)
{
uint modid;
if (!uint.TryParse(modid_hex, NumberStyles.HexNumber, null, out modid))
{
modList.Add(modid_hex);
continue;
}
var result = await ModCache.Instance.GetModName(modid);
if (result != null)
{
var modName = result.Replace(';', ':');
modList.Add(modName);
}
else
{
modList.Add(modid_hex);
}
}
Rules.Remove(entry.Key);
}
}
Rules.Add("modlist", string.Join(';', modList));
}
}