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

Added a Settings Command. #72

Merged
merged 13 commits into from
Aug 14, 2023
Merged

Added a Settings Command. #72

merged 13 commits into from
Aug 14, 2023

Conversation

iamalexrouse
Copy link
Contributor

Added a settings command which will print out the configuration information with colors.

Green - True
Red - False
Yellow - Other

@Jesus-QC
Copy link
Member

Jesus-QC commented Aug 13, 2023

First of all, you are using the same code for each setting to print in the desired color the value, make that a method.

Second of all, you could make a method inside the config class and return that value.

And third, there is no need to color anything, just return config::ToString()

Anyways that is my personal feedback, wait for Zabszk to see what he says.

@zabszk
Copy link
Member

zabszk commented Aug 13, 2023

Hi,

First of all conversion of the config to string already exists here:

LocalAdmin-V2/IO/Config.cs

Lines 234 to 280 in 593f190

public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine(RestartOnCrash ? "- Server will be automatically restarted after a crash." : "- Server will NOT be automatically restarted after a crash.");
sb.AppendLine(EnableHeartbeat ? "- LocalAdmin will attempt to detect silent server crashes (heartbeat enabled)." : "- LocalAdmin will NOT attempt to detect silent server crashes (heartbeat DISABLED).");
sb.AppendLine(LaLiveViewUseUtc ? "- LocalAdmin live view will use UTC timezone." : "- LocalAdmin live view will use local timezone.");
sb.AppendLine($"- LocalAdmin live will use the following timestamp format: {LaLiveViewTimeFormat}");
sb.AppendLine($"- UTC timezone will be displayed as \"{(LaLogsUseZForUtc ? "Z" : "+00:00")}\".");
sb.AppendLine(LaShowStdoutStderr ? "- Standard outputs (that contain a lot of debug information) will be displayed." : "- Standard outputs (that contain a lot of debug information) will NOT be displayed.");
sb.AppendLine(LaNoSetCursor ? "- Cursor position management is DISABLED." : "- Cursor position management is ENABLED.");
sb.AppendLine(EnableTrueColor ? "- True Color output is ENABLED." : "- True Color output is DISABLED.");
sb.AppendLine(EnableLaLogs ? "- LocalAdmin logs are ENABLED." : "- LocalAdmin logs are DISABLED.");
if (EnableLaLogs)
{
sb.AppendLine(LaLogsUseUtc ? "- LocalAdmin logs will use UTC timezone." : "- LocalAdmin logs will use local timezone.");
sb.AppendLine(LaLogAutoFlush ? "- LocalAdmin logs auto flushing is ENABLED." : "- LocalAdmin logs auto flushing is DISABLED.");
sb.AppendLine(LaLogStdoutStderr ? "- Standard outputs will be logged." : "- Standard outputs will NOT be logged.");
if (LaDeleteOldLogs)
{
sb.Append("- Delete LocalAdmin logs older than ");
sb.Append(LaLogsExpirationDays);
sb.AppendLine(" days");
}
else sb.AppendLine("- Do not delete old LocalAdmin logs.");
}
if (DeleteOldRoundLogs)
{
sb.Append("- Delete round logs older than ");
sb.Append(RoundLogsExpirationDays);
sb.AppendLine(" days");
}
else sb.AppendLine("- Do not delete old round logs.");
if (CompressOldRoundLogs)
{
sb.Append("- Compress round logs older than ");
sb.Append(RoundLogsCompressionThresholdDays);
sb.AppendLine(" days");
}
else sb.AppendLine("- Do not compress old round logs.");
return sb.ToString();
}

Secondly LocalAdmin is a multithreaded application. Printing output of this command line by line (using separate Write/WriteLine commands) will sooner or later cause an issue where two different Write/WriteLines run concurrently on different threads. That will result in output from this command being mixed with a different text (printed on a different thread). You additionally set foreground color, which will make the situation even worse.

And

/*
* Console colors:
* Gray - LocalAdmin log
* Red - critical error
* DarkGray - insignificant info
* Cyan - Header or important tip
* Yellow - warning
* DarkGreen - success
* Blue - normal SCPSL log
*/

@iamalexrouse
Copy link
Contributor Author

Honestly, I just wanted to get it done. And I had it in a method but is would make the code a bit longer than already. But yes, I'm working on the method part.

Secondly, I understand the mixing issue and I'm trying to figure out the best way to implement it without that issue. And I am trying to find a better solution for it.

@iamalexrouse
Copy link
Contributor Author

First of all, you are using the same code for each setting to print in the desired color the value, make that a method.

Second of all, you could make a method inside the config class and return that value.

And third, there is no need to color anything, just return config::ToString()

Anyways that is my personal feedback, wait for Zabszk to see what he says.

That might be the better solution. I'll try to change it to that now.

@Jesus-QC
Copy link
Member

Jesus-QC commented Aug 13, 2023

It should be an easy command smt like this:

internal override void Execute(string[] arguments) => ConsoleUtil.WriteLine(Configuration.ToString());

Again, personal feedback.

Also about the command name I would maybe change it to smt more LA related so it doesnt break any type of plugins that may be using that.

But zabszk may have their opinion about that.

@zabszk
Copy link
Member

zabszk commented Aug 13, 2023

It should be an easy command smt like this:

internal override void Execute(string[] arguments) => ConsoleUtil.WriteLine(Configuration.ToString());

Yes. Something like this should be enough.

Again, personal feedback.

Also about the command name I would maybe change it to smt more LA related so it doesnt break any type of plugins that may be using that.

But zabszk may have their opinion about that.

While plugins don't interact with LA, having a LA command named settings means that you can't execute such command as server console. The command already existing for showing config path is named "lacfg" to clearly indicate it's an LA config.

Copy link
Member

@zabszk zabszk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally keep in mind that "help" command isn't automatically generated. You need to add the command there as well.

Commands/LASettingsCommand.cs Outdated Show resolved Hide resolved
Commands/LASettingsCommand.cs Outdated Show resolved Hide resolved
Core/Program.cs Outdated Show resolved Hide resolved
@zabszk zabszk self-assigned this Aug 13, 2023
@Jesus-QC
Copy link
Member

Jesus-QC commented Aug 13, 2023

It should be an easy command smt like this:

internal override void Execute(string[] arguments) => ConsoleUtil.WriteLine(Configuration.ToString());

Yes. Something like this should be enough.

Again, personal feedback.

Also about the command name I would maybe change it to smt more LA related so it doesnt break any type of plugins that may be using that.

But zabszk may have their opinion about that.

While plugins don't interact with LA, having a LA command named settings means that you can't execute such command as server console. The command already existing for showing config path is named "lacfg" to clearly indicate it's an LA config.

Yeah, that was what I was afraid of, server console commands.

With breaking I meant being overrided.

@iamalexrouse
Copy link
Contributor Author

It should be an easy command smt like this:

internal override void Execute(string[] arguments) => ConsoleUtil.WriteLine(Configuration.ToString());

Yes. Something like this should be enough.

Again, personal feedback.
Also about the command name I would maybe change it to smt more LA related so it doesnt break any type of plugins that may be using that.
But zabszk may have their opinion about that.

While plugins don't interact with LA, having a LA command named settings means that you can't execute such command as server console. The command already existing for showing config path is named "lacfg" to clearly indicate it's an LA config.

Yeah, that was what I was afraid of, server console commands.

With breaking I meant being overrided.

It still gives the same idea. But I get where your trying to point.

Commands/LaCfgCommand.cs Outdated Show resolved Hide resolved
Core/Program.cs Outdated Show resolved Hide resolved
iamalexrouse and others added 2 commits August 13, 2023 22:53
Co-authored-by: Łukasz Jurczyk <zabszk@protonmail.ch>
Commands/LaCfgCommand.cs Outdated Show resolved Hide resolved
Based on suggestion by zabszk.

Co-authored-by: Łukasz Jurczyk <zabszk@protonmail.ch>
@zabszk
Copy link
Member

zabszk commented Aug 14, 2023

The code looks good. Can you update the command description in the "help" command?

@zabszk zabszk removed the request for review from MichalPetryka August 14, 2023 09:43
@iamalexrouse
Copy link
Contributor Author

The code looks good. Can you update the command description in the "help" command?

Yes, I can do that rn.

@iamalexrouse
Copy link
Contributor Author

iamalexrouse commented Aug 14, 2023

Feel free to make suggested changes.

@zabszk zabszk merged commit 2a7b902 into northwood-studios:master Aug 14, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants