Skip to content

Commit

Permalink
Better Configuration (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tides authored May 26, 2024
1 parent 59596d7 commit f2704ef
Show file tree
Hide file tree
Showing 29 changed files with 775 additions and 513 deletions.
279 changes: 279 additions & 0 deletions .schema/server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "IServerConfiguration",
"type": "object",
"x-abstract": true,
"additionalProperties": false,
"properties": {
"Logging": {
"$ref": "#/definitions/logging"
},
"baah": {
"type": [
"boolean",
"null"
]
},
"allowLan": {
"type": "boolean"
},
"motd": {
"type": "string"
},
"port": {
"type": "integer",
"format": "int32"
},
"address": {
"type": [
"null",
"string"
]
},
"onlineMode": {
"type": "boolean"
},
"maxPlayers": {
"type": "integer",
"format": "int32"
},
"pregenerateChunkRange": {
"type": "integer",
"format": "int32"
},
"serverListQuery": {
"$ref": "#/definitions/ServerListQuery"
},
"timeTickSpeedMultiplier": {
"type": "integer",
"format": "int32"
},
"allowOperatorRequests": {
"type": "boolean"
},
"enableRcon": {
"type": "boolean"
},
"whitelist": {
"type": "boolean"
},
"network": {
"$ref": "#/definitions/NetworkConfiguration"
},
"messages": {
"$ref": "#/definitions/MessagesConfiguration"
},
"rcon": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/RconConfiguration"
}
]
},
"viewDistance": {
"type": "integer",
"format": "byte"
}
},
"definitions": {
"logLevelThreshold": {
"description": "Log level threshold.",
"type": "string",
"enum": [
"Trace",
"Debug",
"Information",
"Warning",
"Error",
"Critical",
"None"
]
},
"logLevel": {
"title": "logging level options",
"description": "Log level configurations used when creating logs. Only logs that exceeds its matching log level will be enabled. Each log level configuration has a category specified by its JSON property name. For more information about configuring log levels, see https://docs.microsoft.com/aspnet/core/fundamentals/logging/#configure-logging.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/logLevelThreshold"
}
},
"logging": {
"title": "logging options",
"type": "object",
"description": "Configuration for Microsoft.Extensions.Logging.",
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
},
"Console": {
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
},
"FormatterName": {
"description": "Name of the log message formatter to use. Defaults to 'simple'.",
"type": "string",
"default": "simple"
},
"FormatterOptions": {
"title": "formatter options",
"description": "Log message formatter options. Additional properties are available on the options depending on the configured formatter. The formatter is specified by FormatterName.",
"type": "object",
"properties": {
"IncludeScopes": {
"description": "Include scopes when true. Defaults to false.",
"type": "boolean",
"default": false
},
"TimestampFormat": {
"description": "Format string used to format timestamp in logging messages. Defaults to null.",
"type": "string"
},
"UseUtcTimestamp": {
"description": "Indication whether or not UTC timezone should be used to for timestamps in logging messages. Defaults to false.",
"type": "boolean",
"default": false
}
}
},
"LogToStandardErrorThreshold": {
"$ref": "#/definitions/logLevelThreshold",
"description": "The minimum level of messages are written to Console.Error."
}
}
},
"EventSource": {
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
}
}
},
"Debug": {
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
}
}
},
"EventLog": {
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
}
}
},
"ElmahIo": {
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
}
}
},
"ElmahIoBreadcrumbs": {
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
}
}
}
},
"additionalProperties": {
"title": "provider logging settings",
"type": "object",
"description": "Logging configuration for a provider. The provider name must match the configuration's JSON property property name.",
"properties": {
"LogLevel": {
"$ref": "#/definitions/logLevel"
}
}
}
},
"ServerListQuery": {
"type": "string",
"description": "",
"x-enumNames": [
"Full",
"Anonymized",
"Disabled"
],
"enum": [
"Full",
"Anonymized",
"Disabled"
]
},
"NetworkConfiguration": {
"type": "object",
"additionalProperties": false,
"properties": {
"shouldThrottle": {
"type": "boolean"
},
"keepAliveInterval": {
"type": "integer",
"format": "int64"
},
"keepAliveTimeoutInterval": {
"type": "integer",
"format": "int64"
},
"connectionThrottle": {
"type": "integer",
"format": "int64"
},
"mulitplayerDebugMode": {
"type": "boolean"
}
}
},
"MessagesConfiguration": {
"type": "object",
"additionalProperties": false,
"properties": {
"join": {
"type": "string"
},
"leave": {
"type": "string"
},
"notWhitelisted": {
"type": "string"
},
"serverFull": {
"type": "string"
},
"outdatedClient": {
"type": "string"
},
"outdatedServer": {
"type": "string"
}
}
},
"RconConfiguration": {
"type": "object",
"additionalProperties": false,
"properties": {
"password": {
"type": [
"null",
"string"
]
},
"port": {
"type": "integer"
},
"broadcastToOps": {
"type": "boolean"
},
"requireEncryption": {
"type": "boolean"
}
}
}
}
}
35 changes: 35 additions & 0 deletions .schema/whitelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "WhitelistConfiguration",
"type": "object",
"additionalProperties": false,
"properties": {
"whitelistedPlayers": {
"type": "array",
"items": {
"$ref": "#/definitions/WhitelistedPlayer"
}
},
"whitelistedIps": {
"type": "array",
"items": {
"type": "string"
}
}
},
"definitions": {
"WhitelistedPlayer": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"id": {
"type": "string",
"format": "guid"
}
}
}
}
}
15 changes: 15 additions & 0 deletions Obsidian.API/Configuration/MessagesConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Obsidian.API.Configuration;
public sealed record class MessagesConfiguration
{
public string Join { get; set; } = "&e{0} joined the game";

public string Leave { get; set; } = "&e{0} left the game";

public string NotWhitelisted { get; set; } = "You are not whitelisted on this server!";

public string ServerFull { get; set; } = "The server is full!";

public string OutdatedClient { get; set; } = "Outdated client! Please use {0}";
public string OutdatedServer { get; set; } = "Outdated server! I'm still on {0}";
}

22 changes: 22 additions & 0 deletions Obsidian.API/Configuration/NetworkConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Obsidian.API.Configuration;
public sealed record class NetworkConfiguration
{
/// <summary>
/// Returns true if <see cref="ConnectionThrottle"/> has a value greater than 0.
/// </summary>
public bool ShouldThrottle => this.ConnectionThrottle > 0;

public long KeepAliveInterval { get; set; } = 10_000;

public long KeepAliveTimeoutInterval { get; set; } = 30_000;

/// <summary>
/// The time in milliseconds to wait before an ip is allowed to try and connect again.
/// </summary>
public long ConnectionThrottle { get; set; } = 15_000;

/// <summary>
/// If true, each login/client gets a random username where multiple connections from the same host will be allowed.
/// </summary>
public bool MulitplayerDebugMode { get; set; } = false;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Obsidian.API.Config;
namespace Obsidian.API.Configuration;

public sealed class RconConfig
public sealed record class RconConfiguration
{
/// <summary>
/// Password to access the RCON.
/// </summary>
public string Password { get; set; }
public string? Password { get; set; }

/// <summary>
/// Port on which RCON server listens.
Expand Down
Loading

0 comments on commit f2704ef

Please sign in to comment.