forked from LittleBigRefresh/Refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameServerConfig.cs
More file actions
185 lines (162 loc) · 9.43 KB
/
Copy pathGameServerConfig.cs
File metadata and controls
185 lines (162 loc) · 9.43 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
using System.Diagnostics.CodeAnalysis;
using Bunkum.Core.Configuration;
using Microsoft.CSharp.RuntimeBinder;
namespace Refresh.Core.Configuration;
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")]
[SuppressMessage("ReSharper", "RedundantDefaultMemberInitializer")]
public class GameServerConfig : Config
{
public override int CurrentConfigVersion => 28;
public override int Version { get; set; } = 0;
protected override void Migrate(int oldVer, dynamic oldConfig)
{
// In version 27, various (mostly already role-specific) perms, like blocked assets and read-only mode, were moved to dedicated child objects,
// to more cleanly split the perms between certain roles, and to make their enforcement easier.
if (oldVer < 27)
{
this.NormalUserPermissions = new();
this.TrustedUserPermissions = new();
// filesize quota limit was added during version 11, but the version wasn't bumped, so catch error to be safe
if (oldVer >= 11)
{
try
{
this.NormalUserPermissions.UserFilesizeQuota = (int)oldConfig.UserFilesizeQuota;
this.TrustedUserPermissions.UserFilesizeQuota = (int)oldConfig.UserFilesizeQuota;
}
catch (RuntimeBinderException)
{
// do nothing
}
}
if (oldVer >= 18)
{
this.NormalUserPermissions.BlockedAssetFlags.Dangerous = (bool)oldConfig.BlockedAssetFlags.Dangerous;
this.NormalUserPermissions.BlockedAssetFlags.Media = (bool)oldConfig.BlockedAssetFlags.Media;
this.NormalUserPermissions.BlockedAssetFlags.Modded = (bool)oldConfig.BlockedAssetFlags.Modded;
this.TrustedUserPermissions.BlockedAssetFlags.Dangerous = (bool)oldConfig.BlockedAssetFlagsForTrustedUsers.Dangerous;
this.TrustedUserPermissions.BlockedAssetFlags.Media = (bool)oldConfig.BlockedAssetFlagsForTrustedUsers.Media;
this.TrustedUserPermissions.BlockedAssetFlags.Modded = (bool)oldConfig.BlockedAssetFlagsForTrustedUsers.Modded;
}
else
{
// Asset safety level was added in config version 2, so dont try to migrate if we are coming from an older version than that
if (oldVer >= 2)
{
int oldSafetyLevel = (int)oldConfig.MaximumAssetSafetyLevel;
this.NormalUserPermissions.BlockedAssetFlags = new ConfigAssetFlags
{
Dangerous = oldSafetyLevel < 3,
Modded = oldSafetyLevel < 2,
Media = oldSafetyLevel < 1,
};
}
// Asset safety level for trusted users was added in config version 12, so dont try to migrate if we are coming from a version older than that
if (oldVer >= 12)
{
// There was no version bump for trusted users being added, so we just have to catch this error :/
try
{
int oldTrustedSafetyLevel = (int)oldConfig.MaximumAssetSafetyLevelForTrustedUsers;
this.TrustedUserPermissions.BlockedAssetFlags = new ConfigAssetFlags
{
Dangerous = oldTrustedSafetyLevel < 3,
Modded = oldTrustedSafetyLevel < 2,
Media = oldTrustedSafetyLevel < 1,
};
}
catch (RuntimeBinderException)
{
this.TrustedUserPermissions.BlockedAssetFlags = this.NormalUserPermissions.BlockedAssetFlags;
}
}
}
// Timed level upload limits were added in version 19.
if (oldVer >= 19)
{
this.NormalUserPermissions.LevelUploadRateLimit.Enabled = (bool)oldConfig.TimedLevelUploadLimits.Enabled;
this.NormalUserPermissions.LevelUploadRateLimit.TimeSpanHours = (int)oldConfig.TimedLevelUploadLimits.TimeSpanHours;
this.NormalUserPermissions.LevelUploadRateLimit.UploadQuota = (int)oldConfig.TimedLevelUploadLimits.LevelQuota;
this.TrustedUserPermissions.LevelUploadRateLimit.Enabled = (bool)oldConfig.TimedLevelUploadLimits.Enabled;
this.TrustedUserPermissions.LevelUploadRateLimit.TimeSpanHours = (int)oldConfig.TimedLevelUploadLimits.TimeSpanHours;
this.TrustedUserPermissions.LevelUploadRateLimit.UploadQuota = (int)oldConfig.TimedLevelUploadLimits.LevelQuota;
}
// Read-only mode was added for both normal and trusted users in version 20.
if (oldVer >= 20)
{
this.NormalUserPermissions.ReadOnlyMode = (bool)oldConfig.ReadOnlyMode;
this.TrustedUserPermissions.ReadOnlyMode = (bool)oldConfig.ReadonlyModeForTrustedUsers;
}
}
// In version 28, PhotoUploadRateLimit and PlaylistUploadRateLimit were added to RolePermissions, and various renamings related to level upload rate-limiting
// were done to prepare for this: the class TimedLevelUploadLimitProperties was renamed to EntityUploadRateLimitProperties, its attribute LevelQuota was renamed to UploadQuota,
// and RolePermissions' attribute TimedLevelUploadLimits was renamed to LevelUploadRateLimit
else if (oldVer == 27)
{
this.NormalUserPermissions.LevelUploadRateLimit.Enabled = (bool)oldConfig.NormalUserPermissions.TimedLevelUploadLimits.Enabled;
this.NormalUserPermissions.LevelUploadRateLimit.TimeSpanHours = (int)oldConfig.NormalUserPermissions.TimedLevelUploadLimits.TimeSpanHours;
this.NormalUserPermissions.LevelUploadRateLimit.UploadQuota = (int)oldConfig.NormalUserPermissions.TimedLevelUploadLimits.LevelQuota;
this.TrustedUserPermissions.LevelUploadRateLimit.Enabled = (bool)oldConfig.TrustedUserPermissions.TimedLevelUploadLimits.Enabled;
this.TrustedUserPermissions.LevelUploadRateLimit.TimeSpanHours = (int)oldConfig.TrustedUserPermissions.TimedLevelUploadLimits.TimeSpanHours;
this.TrustedUserPermissions.LevelUploadRateLimit.UploadQuota = (int)oldConfig.TrustedUserPermissions.TimedLevelUploadLimits.LevelQuota;
}
}
public string LicenseText { get; set; } = "Welcome to Refresh!";
/// <summary>
/// Role-specific permissions for normal users and below
/// </summary>
public RolePermissions NormalUserPermissions = new();
/// <summary>
/// Role-specific permissions for trusted users and above
/// </summary>
public RolePermissions TrustedUserPermissions = new();
public bool AllowUsersToUseIpAuthentication { get; set; } = false;
public bool PermitPsnLogin { get; set; } = true;
public bool PermitRpcnLogin { get; set; } = true;
public bool PermitWebLogin { get; set; } = true;
/// <summary>
/// Secondary safety switch incase the PSN and RPCN toggles somehow fail.
/// </summary>
public bool PermitAllLogins { get; set; } = true;
/// <summary>
/// Should all game logins be required to use Patchwork?
/// </summary>
public bool EnforcePatchwork { get; set; } = true;
/// <summary>
/// The minimum required major version of Patchwork on the client to be able to connect.
/// </summary>
public int RequiredPatchworkMajorVersion { get; set; } = 1;
/// <summary>
/// The minimum required minor version of Patchwork on the client to be able to connect.
/// </summary>
public int RequiredPatchworkMinorVersion { get; set; } = 0;
public bool UseTicketVerification { get; set; } = true;
public bool RegistrationEnabled { get; set; } = true;
public string InstanceName { get; set; } = "Refresh";
public string InstanceDescription { get; set; } = "A server running Refresh!";
public bool MaintenanceMode { get; set; } = false;
public bool RequireGameLoginToRegister { get; set; } = false;
/// <summary>
/// Whether to use deflate compression for responses.
/// If this is disabled, large enough responses will cause LBP to overflow its read buffer and eventually corrupt its own memory to the point of crashing.
/// </summary>
public bool UseDeflateCompression { get; set; } = true;
public string WebExternalUrl { get; set; } = "https://refresh.example.com";
/// <summary>
/// The base URL that LBP3 uses to grab config files like `network_settings.nws`.
/// </summary>
public string GameConfigStorageUrl { get; set; } = "https://refresh.example.com/lbp";
public bool AllowInvalidTextureGuids { get; set; } = false;
/// <summary>
/// Whether to print the room state whenever a `FindBestRoom` match returns no results
/// </summary>
public bool PrintRoomStateWhenNoFoundRooms { get; set; } = true;
/// <summary>
/// Whether to unconditionally print data like token, token owner, remote IP, request URI etc during authentication outside of exceptions
/// </summary>
public bool PrintAuthenticationData { get; set; } = false;
public string[] Sha1DigestKeys = ["CustomServerDigest"];
public string[] HmacDigestKeys = ["CustomServerDigest"];
public bool PermitShowingOnlineUsers { get; set; } = true;
public bool EnableDiveIn { get; set; } = true;
}