Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow server owners to specify contact information #382

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Refresh.GameServer/Configuration/ContactInfoConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Bunkum.Core.Configuration;

namespace Refresh.GameServer.Configuration;

/// <summary>
/// A configuration holding basic contact information for those operating this instance.
/// </summary>
public class ContactInfoConfig : Config
{
public override int CurrentConfigVersion => 1;
public override int Version { get; set; }

protected override void Migrate(int oldVer, dynamic oldConfig)
{}

/// <summary>
/// The owner's screen name.
/// </summary>
public string AdminName { get; set; } = "Administrator";
/// <summary>
/// The owner's email address.
/// </summary>
public string EmailAddress { get; set; } = "[email protected]";
/// <summary>
/// A link to a Discord server.
/// </summary>
public string? DiscordServerInvite { get; set; }
/// <summary>
/// The owner's personal Discord account.
/// </summary>
public string? AdminDiscordUsername { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Refresh.GameServer.Endpoints.ApiV3.DataTypes.Response;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class ApiContactInfoResponse : IApiResponse
{
/// <summary>
/// The owner's screen name.
/// </summary>
public required string AdminName { get; set; }
/// <summary>
/// The owner's email address.
/// </summary>
public required string EmailAddress { get; set; }
/// <summary>
/// A link to a Discord server.
/// </summary>
public required string? DiscordServerInvite { get; set; }
/// <summary>
/// The owner's personal Discord account.
/// </summary>
public required string? AdminDiscordUsername { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@

public required bool MaintenanceModeEnabled { get; set; }
public required string? GrafanaDashboardUrl { get; set; }

public ApiContactInfoResponse ContactInfo { get; set; }

Check warning on line 50 in Refresh.GameServer/Endpoints/ApiV3/DataTypes/Response/ApiInstanceResponse.cs

View workflow job for this annotation

GitHub Actions / Build, Test, and Upload Builds

Non-nullable property 'ContactInfo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 50 in Refresh.GameServer/Endpoints/ApiV3/DataTypes/Response/ApiInstanceResponse.cs

View workflow job for this annotation

GitHub Actions / Build, Test, and Upload Builds

Non-nullable property 'ContactInfo' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
10 changes: 9 additions & 1 deletion Refresh.GameServer/Endpoints/ApiV3/InstanceApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public ApiResponse<ApiInstanceResponse> GetInstanceInformation(RequestContext co
GameServerConfig gameConfig,
RichPresenceConfig richConfig,
IntegrationConfig integrationConfig,
ContactInfoConfig contactInfoConfig,
GameDatabaseContext database)
=> new ApiInstanceResponse
{
Expand All @@ -71,7 +72,14 @@ public ApiResponse<ApiInstanceResponse> GetInstanceInformation(RequestContext co
MaintenanceModeEnabled = gameConfig.MaintenanceMode,
RichPresenceConfiguration = ApiRichPresenceConfigurationResponse.FromOld(RichPresenceConfiguration.Create(gameConfig, richConfig))!,
GrafanaDashboardUrl = integrationConfig.GrafanaDashboardUrl,


ContactInfo = new ApiContactInfoResponse
{
AdminName = contactInfoConfig.AdminName,
EmailAddress = contactInfoConfig.EmailAddress,
DiscordServerInvite = contactInfoConfig.DiscordServerInvite,
AdminDiscordUsername = contactInfoConfig.AdminDiscordUsername,
},
#if DEBUG
SoftwareType = "Debug",
#else
Expand Down
1 change: 1 addition & 0 deletions Refresh.GameServer/RefreshGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ protected override void SetupConfiguration()
this.Server.AddConfig(config);
this.Server.AddConfig(integrationConfig);
this.Server.AddConfigFromJsonFile<RichPresenceConfig>("rpc.json");
this.Server.AddConfigFromJsonFile<ContactInfoConfig>("contactInfo.json");
}

protected override void SetupServices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected override void SetupConfiguration()
this.Server.AddConfig(this._config = new GameServerConfig());
this.Server.AddConfig(new RichPresenceConfig());
this.Server.AddConfig(new IntegrationConfig());
this.Server.AddConfig(new ContactInfoConfig());
}

public GameServerConfig GameServerConfig => this._config!;
Expand Down
Loading