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

Fix envis for module settings #261

Merged
merged 2 commits into from
Aug 3, 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
132 changes: 78 additions & 54 deletions docker/evosc.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,66 @@
#

# The type of database to use. Available types: PostgreSql, MySql, SQLite
#EVOSC_DATABASE_TYPE=PostgreSql
EVOSC_DATABASE_TYPE=PostgreSql

# Address to the database
#EVOSC_DATABASE_HOST=127.0.0.1
EVOSC_DATABASE_HOST=127.0.0.1

# Port of the database
#EVOSC_DATABASE_PORT=5432
EVOSC_DATABASE_PORT=5432

# The name of the database
#EVOSC_DATABASE_NAME=postgres
EVOSC_DATABASE_NAME=evosc

# Name of the user to access the database
#EVOSC_DATABASE_USERNAME=evosc
EVOSC_DATABASE_USERNAME=evosc

# Password of the user to access the database
#EVOSC_DATABASE_PASSWORD=evosc
EVOSC_DATABASE_PASSWORD=evosc

# A string prefix to add to all table names
#EVOSC_DATABASE_TABLEPREFIX=
EVOSC_DATABASE_TABLEPREFIX=

# Possible values lowest to highest verbosity: none, critical, error, warning, information, debug, trace
#EVOSC_LOGGING_LOGLEVEL=debug
EVOSC_LOGGING_LOGLEVEL=debug

# Whether to output logs to the console in JSON.
#EVOSC_LOGGING_USEJSON=False
EVOSC_LOGGING_USEJSON=False

# Address to the Trackmania server
#EVOSC_SERVER_HOST=127.0.0.1
EVOSC_SERVER_HOST=127.0.0.1

# Port that the XMLRPC is listening to
#EVOSC_SERVER_PORT=5000
EVOSC_SERVER_PORT=5000

# Username of the super admin account
#EVOSC_SERVER_USERNAME=SuperAdmin
EVOSC_SERVER_USERNAME=SuperAdmin

# Password of the super admin account
#EVOSC_SERVER_PASSWORD=SuperAdmin
EVOSC_SERVER_PASSWORD=SuperAdmin

# If enabled, the client will try to reconnect with the server every 1 second until a connection is established
#EVOSC_SERVER_RETRYCONNECTION=True
EVOSC_SERVER_RETRYCONNECTION=True

# Path to the maps folder
#EVOSC_PATH_MAPS=
EVOSC_PATH_MAPS=

# Default match settings file
#EVOSC_PATH_DEFAULTMATCHSETTINGS=example.txt
EVOSC_PATH_DEFAULTMATCHSETTINGS=example.txt

# Signature verification of module's files. If enabled and verification fails, the module will not load.
#EVOSC_MODULES_REQUIRESIGNATUREVERIFICATION=True
EVOSC_MODULES_REQUIRESIGNATUREVERIFICATION=True

# Directories to scan for external modules.
#EVOSC_MODULES_MODULEDIRECTORIES=System.String[]
EVOSC_MODULES_MODULEDIRECTORIES=System.String[]

# Modules that will not load on startup. Note that if a module depend on a disabled module, it will load anyways.
#EVOSC_MODULES_DISABLEDMODULES=
EVOSC_MODULES_DISABLEDMODULES=

# The default display language of the controller. Must be a "language tag" as found here: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c
#EVOSC_LOCALE_DEFAULTLANGUAGE=en
EVOSC_LOCALE_DEFAULTLANGUAGE=en

#EVOSC_THEME=
EVOSC_THEME=



Expand All @@ -71,97 +71,121 @@
#


## Module "ExampleModule" v1.0.0 ##
## Module "RecordsModule" with Settings "PlayerRecordSettings" v1.0.0 ##

#EVOSC_EXAMPLEMODULE_MYOPTION=default value
# How to send a message about a new PB.
EVOSC_PLAYERRECORDSETTINGS_RECORDSMODULE_ECHOPB=None



## Module "RecordsModule" v1.0.0 ##
## Module "CurrentMapModule" with Settings "CurrentMapSettings" v1.0.1 ##

# How to send a message about a new PB.
#EVOSC_RECORDSMODULE_ECHOPB=None
# Specifies the Y position of the widget.
EVOSC_CURRENTMAPSETTINGS_CURRENTMAPMODULE_Y=80

# Specifies the width of the widget.
EVOSC_CURRENTMAPSETTINGS_CURRENTMAPMODULE_WIDTH=36

# Specifies on which side the widget is displayed.
EVOSC_CURRENTMAPSETTINGS_CURRENTMAPMODULE_POSITION=right



## Module "MotdModule" v1.0.0 ##
## Module "MotdModule" with Settings "MotdSettings" v1.0.0 ##

# The URL from which the controller fetches the motd.
#EVOSC_MOTDMODULE_MOTDURL=
EVOSC_MOTDSETTINGS_MOTDMODULE_MOTDURL=

# The interval in which the motd gets fetched from the server.
#EVOSC_MOTDMODULE_MOTDFETCHINTERVAL=600000
EVOSC_MOTDSETTINGS_MOTDMODULE_MOTDFETCHINTERVAL=600000

# The locally stored Motd text if it should not be fetched from a server.
#EVOSC_MOTDMODULE_MOTDLOCALTEXT=This is the Motd!
EVOSC_MOTDSETTINGS_MOTDMODULE_MOTDLOCALTEXT=This is the Motd!

# Indicator if the locally stored motd should be used.
#EVOSC_MOTDMODULE_USELOCALMOTD=True
EVOSC_MOTDSETTINGS_MOTDMODULE_USELOCALMOTD=True



## Module "OpenPlanetModule" v1.0.0 ##
## Module "OpenPlanetModule" with Settings "OpenPlanetControlSettings" v1.1.0 ##

# Allowed signature types: Regular, DevMode, Official, Competition
#EVOSC_OPENPLANETMODULE_ALLOWEDSIGNATUREMODES=Regular, Official, TMGL
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_ALLOWEDSIGNATUREMODES=Regular, Official, TMGL

# Time to wait before kicking the player.
#EVOSC_OPENPLANETMODULE_KICKTIMEOUT=30
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_KICKTIMEOUT=30

# Enable continous check of the signature mode of the player while they are on the server.
#EVOSC_OPENPLANETMODULE_CONTINUOUSCHECKSENABLED=False
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_CONTINUOUSCHECKSENABLED=False

# Number of milliseconds to wait between the continous checks.
#EVOSC_OPENPLANETMODULE_CHECKINTERVAL=5000
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_CHECKINTERVAL=5000

# Enable checking of the signature mode of a player when they join.
#EVOSC_OPENPLANETMODULE_SIGNATUREMODECHECKENABLED=True
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_SIGNATUREMODECHECKENABLED=True

# Allow the use of openplanet. If false, no signature mode is allowed.
#EVOSC_OPENPLANETMODULE_ALLOWOPENPLANET=True
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_ALLOWOPENPLANET=True

# The minimum required OpenPlanet version to play on this server.
#EVOSC_OPENPLANETMODULE_MINIMUMREQUIREDVERSION=1.25.45
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_MINIMUMREQUIREDVERSION=1.26.25

# Enable auditing of all checks.
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_AUDITALLCHECKS=True

# Enable auditing of players that got jailed.
EVOSC_OPENPLANETCONTROLSETTINGS_OPENPLANETMODULE_AUDITJAILS=True

## Module "MatchTrackerModule" v1.0.0 ##


## Module "MatchTrackerModule" with Settings "TrackerSettings" v1.0.0 ##

# Whether to start tracking matches automatically.
#EVOSC_MATCHTRACKERMODULE_AUTOMATICTRACKING=False
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_AUTOMATICTRACKING=False

# Whether to automatically end a match when the EndMatch section is detected.
#EVOSC_MATCHTRACKERMODULE_AUTOMATICMATCHEND=True
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_AUTOMATICMATCHEND=True

# Whether to store match state changes immediately instead of waiting until the match ends.
#EVOSC_MATCHTRACKERMODULE_IMMEDIATESTORING=True
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_IMMEDIATESTORING=True

# Record end of map states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDMAP=True
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_RECORDENDMAP=True

# Record end of match states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDMATCH=True
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_RECORDENDMATCH=True

# Record end of round states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDROUND=True
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_RECORDENDROUND=True

# Record pre end of match states.
#EVOSC_MATCHTRACKERMODULE_RECORDENDMATCHEARLY=False
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_RECORDENDMATCHEARLY=False

# Keep pre end of round states.
#EVOSC_MATCHTRACKERMODULE_RECORDPREENDROUND=False
EVOSC_TRACKERSETTINGS_MATCHTRACKERMODULE_RECORDPREENDROUND=False



## Module "NextMapModule" with Settings "NextMapSettings" v1.0.0 ##

## Module "LocalRecordsModule" v1.0.0 ##
# Specifies the Y position of the widget.
EVOSC_NEXTMAPSETTINGS_NEXTMAPMODULE_Y=80

# Specifies the width of the widget.
EVOSC_NEXTMAPSETTINGS_NEXTMAPMODULE_WIDTH=36

# Specifies on which side the widget is displayed.
EVOSC_NEXTMAPSETTINGS_NEXTMAPMODULE_POSITION=right



## Module "LocalRecordsModule" with Settings "LocalRecordsSettings" v1.0.0 ##

# Max of rows to show in the local records widget.
#EVOSC_LOCALRECORDSMODULE_MAXWIDGETROWS=10
EVOSC_LOCALRECORDSSETTINGS_LOCALRECORDSMODULE_MAXWIDGETROWS=10

# Always show top N players in the widget.
#EVOSC_LOCALRECORDSMODULE_WIDGETSHOWTOP=3
EVOSC_LOCALRECORDSSETTINGS_LOCALRECORDSMODULE_WIDGETSHOWTOP=3

# Maximum number of local records to keep track of per map.
#EVOSC_LOCALRECORDSMODULE_MAXRECORDSPERMAP=100


EVOSC_LOCALRECORDSSETTINGS_LOCALRECORDSMODULE_MAXRECORDSPERMAP=100
17 changes: 16 additions & 1 deletion src/EvoSC.Common/Config/Stores/DatabaseStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Globalization;
using System.Reflection;
using Config.Net;
using EvoSC.Common.Database.Models.Config;
using EvoSC.Common.Interfaces.Database.Repository;
Expand Down Expand Up @@ -65,6 +66,14 @@ public void Dispose()

public string? Read(string key)
{
var enviName = GetEnviName(key);
var enviValue = Environment.GetEnvironmentVariable(enviName);

if (enviValue != null)
{
return enviValue;
}

var dbKey = $"{_prefix}.{key}";
var option = configStoreRepository.GetConfigOptionsByKeyAsync(dbKey).GetAwaiter().GetResult();

Expand Down Expand Up @@ -100,4 +109,10 @@ public void Write(string key, string? value)

public bool CanRead => true;
public bool CanWrite => true;

private string GetEnviName(string key)
{
var fullKey = $"EvoSC.{_prefix}.{key}";
return fullKey.Replace(".", "_", StringComparison.Ordinal).ToUpper(CultureInfo.InvariantCulture);
}
}
3 changes: 2 additions & 1 deletion src/EvoSC.Manialinks/Templates/Scripts/UIScripts.ms
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#Include "MathLib" as Math
#Include "ColorLib" as ColorLib

declare Boolean ScriptRunning;

Void __DoNothing() {}

main() {
Expand All @@ -11,7 +13,6 @@ main() {
declare Vec2 MouseDragStart = <0., 0.>;

// set to true before initialization if scripts wants to terminate immediately
declare Boolean ScriptRunning for This = False;
ScriptRunning = True;

+++ OnInitialization +++
Expand Down
24 changes: 16 additions & 8 deletions src/EvoSC/CliCommands/ConfigGeneratorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task ExecuteAsync(
[Alias(Name = "-t"), Description("The output format, supported types: ENV")]
string formatType,
[Alias(Name = "-f"), Description("The file to write to.")]
string fileName
string? fileName
)
{
if (formatType.ToUpper(CultureInfo.InvariantCulture) != "ENV")
Expand All @@ -47,12 +47,12 @@ string fileName
output.AppendLine();
GenerateModuleConfig(ConfigGenFormatType.ENV, output);

File.WriteAllText(fileName, output.ToString());
File.WriteAllText(fileName ?? ".env", output.ToString());
}

private void GenerateBaseConfig(ConfigGenFormatType formatType, StringBuilder sb)
{
GeneratePropertiesRecursiveEnv(sb, typeof(IEvoScBaseConfig), null);
GeneratePropertiesRecursiveEnv(sb, typeof(IEvoScBaseConfig), null, null);
}

private void GenerateModuleConfig(ConfigGenFormatType formatType, StringBuilder sb)
Expand Down Expand Up @@ -88,22 +88,23 @@ private void GenerateModuleConfig(ConfigGenFormatType formatType, StringBuilder
{
foreach (var type in assembly.AssemblyTypesWithAttribute<SettingsAttribute>())
{
var prefix = type.Name[0] == 'I' ? type.Name.Substring(1) : type.Name;
if (lastModuleName != name)
{
sb.AppendLine();
sb.AppendLine($"## Module \"{name}\" v{version} ##");
sb.AppendLine($"## Module \"{name}\" v{version} with Settings \"{prefix}\" ##");
sb.AppendLine();
lastModuleName = name;
}

GeneratePropertiesRecursiveEnv(sb, type, name);
GeneratePropertiesRecursiveEnv(sb, type, name, prefix);

sb.AppendLine();
}
}
}

private void GeneratePropertiesRecursiveEnv(StringBuilder sb, Type type, string? name)
private void GeneratePropertiesRecursiveEnv(StringBuilder sb, Type type, string? name, string? prefix)
{
foreach (var property in type.GetProperties())
{
Expand All @@ -114,7 +115,7 @@ private void GeneratePropertiesRecursiveEnv(StringBuilder sb, Type type, string?

if (property.PropertyType.IsInterface)
{
GeneratePropertiesRecursiveEnv(sb, property.PropertyType, keyName);
GeneratePropertiesRecursiveEnv(sb, property.PropertyType, keyName, prefix);
}
else
{
Expand All @@ -123,7 +124,14 @@ private void GeneratePropertiesRecursiveEnv(StringBuilder sb, Type type, string?
sb.AppendLine($"# {descAttr.Description}");
}

sb.Append($"EVOSC_{keyName.ToUpper(CultureInfo.InvariantCulture)}");
sb.Append($"EVOSC_");

if (!string.IsNullOrEmpty(prefix))
{
sb.Append($"{prefix.ToUpper()}_");
}

sb.Append(keyName.ToUpper(CultureInfo.InvariantCulture));
sb.Append("=");
sb.AppendLine(optionAttr?.DefaultValue?.ToString() ?? "");
sb.AppendLine();
Expand Down
7 changes: 2 additions & 5 deletions src/Modules/OpenPlanetModule/OpenPlanetModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ public class OpenPlanetModule(IManialinkManager manialinks, IOpenPlanetControlSe
public Task EnableAsync()
{
manialinkInteractions.ValueReader.AddReader(new OpenPlanetInfoValueReader());

manialinks.SendPersistentManialinkAsync("OpenPlanetModule.DetectOP", new
{
config = settings
});

manialinks.SendPersistentManialinkAsync("OpenPlanetModule.DetectOP", new { config = settings });

return Task.CompletedTask;
}
Expand Down
Loading