forked from LittleBigRefresh/Refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstanceApiEndpoints.cs
More file actions
91 lines (84 loc) · 4.16 KB
/
Copy pathInstanceApiEndpoints.cs
File metadata and controls
91 lines (84 loc) · 4.16 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
using AttribDoc.Attributes;
using Bunkum.Core;
using Bunkum.Core.Endpoints;
using Bunkum.Core.RateLimit;
using Refresh.Core;
using Refresh.Core.Authentication.Permission;
using Refresh.Core.Configuration;
using Refresh.Core.Services;
using Refresh.Core.Types.Data;
using Refresh.Core.Types.Matching;
using Refresh.Core.Types.RichPresence;
using Refresh.Database;
using Refresh.Interfaces.APIv3.Endpoints.ApiTypes;
using Refresh.Interfaces.APIv3.Endpoints.DataTypes.Response;
namespace Refresh.Interfaces.APIv3.Endpoints;
public class InstanceApiEndpoints : EndpointGroup
{
[ApiV3Endpoint("statistics"), Authentication(false)]
[DocSummary("Retrieves various statistics about the Refresh instance.")]
[RateLimitSettings(300, 12, 240, "instance-stats-api")]
public ApiResponse<ApiStatisticsResponse> GetStatistics(RequestContext context, GameDatabaseContext database,
MatchService match, GameServerConfig config, DataContext dataContext)
{
ApiRequestStatisticsResponse requestStatistics = ApiRequestStatisticsResponse.FromOld(database.GetRequestStatistics(), dataContext)!;
RoomStatistics statistics = match.RoomAccessor.GetStatistics();
return new ApiStatisticsResponse
{
TotalLevels = database.GetTotalLevelCount(),
ModdedLevels = database.GetModdedLevelCount(),
TotalUsers = database.GetTotalUserCount(),
ActiveUsers = database.GetActiveUserCount(),
TotalPhotos = database.GetTotalPhotoCount(),
TotalEvents = database.GetTotalEventCount(),
CurrentRoomCount = statistics.RoomCount,
CurrentIngamePlayersCount = statistics.PlayerCount,
RequestStatistics = requestStatistics,
};
}
[ApiV3Endpoint("instance"), Authentication(false), AllowDuringMaintenance]
[ClientCacheResponse(3600)] // One hour
[DocSummary("Retrieves various information and metadata about the Refresh instance.")]
[RateLimitSettings(300, 12, 240, "instance-info-api")]
public ApiResponse<ApiInstanceResponse> GetInstanceInformation(RequestContext context,
GameServerConfig gameConfig,
RichPresenceConfig richConfig,
IntegrationConfig integrationConfig,
ContactInfoConfig contactInfoConfig,
GameDatabaseContext database,
DataContext dataContext)
=> new ApiInstanceResponse
{
InstanceName = gameConfig.InstanceName,
InstanceDescription = gameConfig.InstanceDescription,
RegistrationEnabled = gameConfig.RegistrationEnabled,
SoftwareName = "Refresh",
SoftwareVersion = VersionInformation.Version,
SoftwareSourceUrl = "https://github.com/LittleBigRefresh/Refresh",
SoftwareLicenseName = "AGPL-3.0",
SoftwareLicenseUrl = "https://www.gnu.org/licenses/agpl-3.0.txt",
BlockedAssetFlags = gameConfig.NormalUserPermissions.BlockedAssetFlags,
BlockedAssetFlagsForTrustedUsers = gameConfig.TrustedUserPermissions.BlockedAssetFlags,
Announcements = ApiGameAnnouncementResponse.FromOldList(database.GetAnnouncements(), dataContext),
MaintenanceModeEnabled = gameConfig.MaintenanceMode,
RichPresenceConfiguration = ApiRichPresenceConfigurationResponse.FromOld(RichPresenceConfiguration.Create(
gameConfig,
richConfig), dataContext)!,
GrafanaDashboardUrl = integrationConfig.GrafanaDashboardUrl,
WebsiteLogoUrl = integrationConfig.WebsiteLogoUrl,
WebsiteDefaultTheme = integrationConfig.WebsiteDefaultTheme,
ContactInfo = new ApiContactInfoResponse
{
AdminName = contactInfoConfig.AdminName,
EmailAddress = contactInfoConfig.EmailAddress,
DiscordServerInvite = contactInfoConfig.DiscordServerInvite,
AdminDiscordUsername = contactInfoConfig.AdminDiscordUsername,
},
ActiveContest = ApiContestResponse.FromOld(database.GetNewestActiveContest(), dataContext),
#if DEBUG
SoftwareType = "Debug",
#else
SoftwareType = "Release",
#endif
};
}