2013-08-06 16:11:46 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2022-10-28 11:13:20 +08:00
|
|
|
|
using System.Globalization;
|
2022-10-02 18:31:08 +08:00
|
|
|
|
using System.IO;
|
2013-08-06 16:11:46 +02:00
|
|
|
|
using System.Linq;
|
2022-10-02 18:31:08 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2013-08-06 16:11:46 +02:00
|
|
|
|
using System.Text;
|
2015-10-22 22:17:15 +02:00
|
|
|
|
using System.Text.RegularExpressions;
|
2022-10-28 11:13:20 +08:00
|
|
|
|
using System.Threading;
|
2022-10-02 18:31:08 +08:00
|
|
|
|
using MinecraftClient.Protocol;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
using MinecraftClient.Proxy;
|
|
|
|
|
|
using Tomlet;
|
|
|
|
|
|
using Tomlet.Attributes;
|
|
|
|
|
|
using Tomlet.Models;
|
|
|
|
|
|
using static MinecraftClient.Settings.AppVarConfigHelper;
|
|
|
|
|
|
using static MinecraftClient.Settings.ChatBotConfigHealper;
|
|
|
|
|
|
using static MinecraftClient.Settings.ChatFormatConfigHelper;
|
2022-12-11 13:00:19 +08:00
|
|
|
|
using static MinecraftClient.Settings.ConsoleConfigHealper;
|
2022-10-06 14:53:05 +08:00
|
|
|
|
using static MinecraftClient.Settings.HeadCommentHealper;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
using static MinecraftClient.Settings.LoggingConfigHealper;
|
|
|
|
|
|
using static MinecraftClient.Settings.MainConfigHealper;
|
2022-11-06 16:20:38 +08:00
|
|
|
|
using static MinecraftClient.Settings.MainConfigHealper.MainConfig;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
using static MinecraftClient.Settings.MainConfigHealper.MainConfig.AdvancedConfig;
|
|
|
|
|
|
using static MinecraftClient.Settings.MCSettingsConfigHealper;
|
|
|
|
|
|
using static MinecraftClient.Settings.SignatureConfigHelper;
|
2013-08-06 16:11:46 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class Settings
|
|
|
|
|
|
{
|
2022-10-05 19:39:21 +08:00
|
|
|
|
private const int CommentsAlignPosition = 45;
|
2022-10-06 14:53:05 +08:00
|
|
|
|
private readonly static Regex CommentRegex = new(@"^(.*)\s?#\s\$([\w\.]+)\$\s*$$", RegexOptions.Compiled);
|
2016-08-26 12:19:25 +02:00
|
|
|
|
|
2022-12-11 13:00:19 +08:00
|
|
|
|
// Other Settings
|
|
|
|
|
|
public const string TranslationsFile_Version = "1.19.3";
|
|
|
|
|
|
public const string TranslationsFile_Website_Index = "https://piston-meta.mojang.com/v1/packages/c492375ded5da34b646b8c5c0842a0028bc69cec/2.json";
|
2023-01-19 18:20:45 +08:00
|
|
|
|
public const string TranslationsFile_Website_Download = "https://resources.download.minecraft.net";
|
Add Mailer bot (#1108)
* Update for the mail script.
As requested, I added the synchronization between the config debugmessage bool and the one in the script. Furthermore, I added a way to send anonymous mails by writing "tellonym". The messages are saved as normal mails, which lets them count to the mail cap, due to the fact that the host knows the sender.
I added the script to the chat bots because of the problems, that the scripts have with serialization. Instead of rewriting the whole serialization part, my idea was to add the script to the other chat bots, to avoid the compiling issues. Then the serialization would work perfectly fine. Then you could remove the option class at some point and move all the settings to the config file with the addition to activate the whole script.
* Correction of debug message loading.
The object was missing and the change would be overridden a few lines later.
* Update McClient.cs
* Add Mail to config file
* Correcting the safe file.
* Small correction of Settings.c
* Update Mailscript
Added a failsafe version of the path changing commands. If a path could not be found, an error will be created and the path will be reseted to standart, to avoid endless chains of errors.
* Fix for the mail script
Removed a wrong option call. Removed the debug_msg condition around the path functions. => Users are aware of what happened (if they see the error) although they turned off debug_msg.
* Added some features.
Added a try statement to all number changing commands. Added a command to list all moderators to the console.
* Serialization Fix
There was a chance, that if two bots work on one file, and two users send messages in a short time period, that one bot deserializes the message and then the other bot deserialize the same file, before the other one could save its changes. This would lead to one message disappearing, because one bot never deserialized this message. For this I changed the whole serialization process.
All changes are now committed after the interval and not after an incoming mail command directly. All mails are safed temporarily in cache and get serialized after the interval. Due to this changes, you can determit when the individual bot changes the file (there are no more direct interactions with the file after a command, which lead to a certain randomness). Furthermore you can now set an interval of e.g. 2 mins and reset the interval of one bot with "resettimer" after one minute so that the bots won't disturb eachother and no files get lost.
* My idea of a manual.
This is my idea of a manual for the bot. Improvements of my language / further ideas are welcome! :D
* addIgnored [NAME] and removeIgnored[NAME]
Added an ignored list. Moderators can add players to the list. The bot won't react to them and just log to the console that they are ignored, everytime they are sending a message, to ensure that they are not accidently ignored. (Just if debug_msg is active.)
Especially useful if there are other chat bots on the server, which spam many messages that aren't useful for the mail system. Or block spammers etc.
* Add the three commands to the manual.
Added addignored, removeignored and getignored to the manual.
* Remove moderators. Implement Console Control.
Due to security concerns, I converted all moderator commands to console internal commands. Thereby only the host can change crucial settings. Special thanks to ORelio for the hint!
* Added empty statement check
Added if to all commands, where the syntax is not already protected by a try, so that an incorrect syntax (Empty args[] due to missing statement) won't crash the script.
* Changed the serialization fail
If the programm can't safe the file, because of some strange character for instance, it first tries to change the path back to normal and if this not helps, it creates a new, file.
* toggle mail sending/receiving
Add an option to turn mailsending and the listening to commands in chat on/off.
* Updated manual.
- Removed moderator commands.
- Removed moderator part in the network manual
+ added the two new commands
+ added a waring for nick plugins and minecraft renames
+ added a small syntax example
* Updated the Settings.cs file.
* Smaller fixes and additions
+ improved command reading of 'mail' & 'tellonym'
+ sorted internal commands alphabetically
+ host can set a maximum message length
+ host can accept commands from public chat
+ host can decide if 'self mailing' (mailing yourself) is accepted
+ new order makes 'getsettings' easier to read
+ new internal commands to toggle 'publiccommands' and 'selfmailing' as well as the maximum mail size
- removed the old command interpreter
* Small improvements and additions
Added a few commands and settings
* Completing getsettings
+ added 'publiccomands'
* Completed getsettings
+ Added 'publiccommand' to 'getsettings'
* Removed single bolean, added Dictionary
- removed all boleans in the option class
- removed all functions relating them
+ added Dictionary for the booleans
+ added a single function to set/toggle all booleans
* Removed Commands, added interpreter
- Removed all Register commands
- removed all integer methods
+ added a single mail command
+ added integer dictionary
+ added integer handling similar like bool handling
* Small fix
+ Changed the numbers in several methods to adjust them to the new syntax.
- removed parameters in several methods, because they got unneccesary
* Even smaller fix
+ Sorted 'getsettings' alphabetically
+ corrected a typo
* New Serialization method.
Now serializing through the .INI format! Thanks to ORelio, who helped me a lot! :)
* Added different time
Added the option to switch between utc and the time of the local machine for timestamps.
* Made timeinutc serializable
Added the bool to the serialization method.
* Adding the INIFile.cs
For Dictionary serialization.
* Reworked ignore feature
Ignored players are now serialized in a file and reloaded, after the bot enters a server.
* Mailer bot refactoring
Rename Mail to Mailer
Move options to MinecraftClient.ini
Make the bot much simpler by removing some settings
Create specific MailDatabase and IgnoreList classes
However the core functionality for users is the same
Settings removed:
- allow_sendmail: Cannot use Mailer if it's disabled
- allow_receivemail: Cannot use Mailer if it's disabled
- path_setting: Settings moved to MinecraftClient.ini
- debug_msg: MCC already has a setting for that with LogDebugToConsole()
- auto_respawn: MCC already has a built-in auto-respawn feature
- allow_selfmail: Is it really necessary to block self mails? ;)
- maxcharsinmsg: Automatically calculated based on max chat message length
- timeinutc: DateTime is not show to the recipient so I think it's not absolutely necessary
- interval_sendmail: Set to 10 seconds for now
Internal Commands removed:
- changemailpath: Now a static setting in config
- changesettingspath: Now a static setting in config
- updatemails: Already updated every 10 seconds
- getsettings: Shown on startup with debugmessages=true
- resettimer: Seems only useful for debugging
- setbool: Settings are static in config file
- setinteger: Settings are static in config file
All user commands are retained:
- mail
- tellonym
* Reload database for mailer network feature
* Merge Mail documentation to Readme.md
Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
2020-08-03 21:44:39 +02:00
|
|
|
|
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public const string TranslationProjectUrl = "https://crwd.in/minecraft-console-client";
|
2022-10-06 14:53:05 +08:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static GlobalConfig Config = new();
|
|
|
|
|
|
|
|
|
|
|
|
public static class InternalConfig
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static string ServerIP = String.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
public static ushort ServerPort = 25565;
|
|
|
|
|
|
|
2022-11-06 16:20:38 +08:00
|
|
|
|
public static AccountInfoConfig Account = new();
|
2022-10-16 20:37:07 +08:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static string Username = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
public static string MinecraftVersion = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
public static bool InteractiveMode = true;
|
|
|
|
|
|
|
|
|
|
|
|
public static bool GravityEnabled = true;
|
2022-11-05 20:27:10 +08:00
|
|
|
|
|
|
|
|
|
|
public static bool KeepAccountSettings = false;
|
|
|
|
|
|
|
|
|
|
|
|
public static bool KeepServerSettings = false;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2013-08-06 16:11:46 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public class GlobalConfig
|
2013-08-06 16:11:46 +02:00
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$Head$")]
|
2022-10-06 14:53:05 +08:00
|
|
|
|
public HeadComment Head
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return HeadCommentHealper.Config; }
|
|
|
|
|
|
set { HeadCommentHealper.Config = value; HeadCommentHealper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
public MainConfig Main
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return MainConfigHealper.Config; }
|
|
|
|
|
|
set { MainConfigHealper.Config = value; MainConfigHealper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$Signature$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public SignatureConfig Signature
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return SignatureConfigHelper.Config; }
|
|
|
|
|
|
set { SignatureConfigHelper.Config = value; SignatureConfigHelper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$Logging$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public LoggingConfig Logging
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return LoggingConfigHealper.Config; }
|
|
|
|
|
|
set { LoggingConfigHealper.Config = value; LoggingConfigHealper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-11 13:00:19 +08:00
|
|
|
|
public ConsoleConfig Console
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ConsoleConfigHealper.Config; }
|
|
|
|
|
|
set { ConsoleConfigHealper.Config = value; ConsoleConfigHealper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public AppVarConfig AppVar
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return AppVarConfigHelper.Config; }
|
|
|
|
|
|
set { AppVarConfigHelper.Config = value; AppVarConfigHelper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$Proxy$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ProxyHandler.Configs Proxy
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ProxyHandler.Config; }
|
|
|
|
|
|
set { ProxyHandler.Config = value; ProxyHandler.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$MCSettings$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public MCSettingsConfig MCSettings
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return MCSettingsConfigHealper.Config; }
|
|
|
|
|
|
set { MCSettingsConfigHealper.Config = value; MCSettingsConfigHealper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatFormat$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatFormatConfig ChatFormat
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatFormatConfigHelper.Config; }
|
|
|
|
|
|
set { ChatFormatConfigHelper.Config = value; ChatFormatConfigHelper.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBotConfig ChatBot
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBotConfigHealper.Config; }
|
|
|
|
|
|
set { ChatBotConfigHealper.Config = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-05 20:27:10 +08:00
|
|
|
|
public static Tuple<bool, bool> LoadFromFile(string filepath, bool keepAccountAndServerSettings = false)
|
2022-10-05 15:02:30 +08:00
|
|
|
|
{
|
2022-11-05 20:27:10 +08:00
|
|
|
|
bool keepAccountSettings = InternalConfig.KeepAccountSettings;
|
|
|
|
|
|
bool keepServerSettings = InternalConfig.KeepServerSettings;
|
|
|
|
|
|
if (keepAccountAndServerSettings)
|
|
|
|
|
|
InternalConfig.KeepAccountSettings = InternalConfig.KeepServerSettings = true;
|
|
|
|
|
|
|
2022-10-28 11:13:20 +08:00
|
|
|
|
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
TomlDocument document;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
document = TomlParser.ParseFile(filepath);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
Thread.CurrentThread.CurrentCulture = Program.ActualCulture;
|
|
|
|
|
|
|
2022-10-05 19:16:33 +08:00
|
|
|
|
Config = TomletMain.To<GlobalConfig>(document);
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
2013-08-06 16:11:46 +02:00
|
|
|
|
{
|
2022-10-28 11:13:20 +08:00
|
|
|
|
Thread.CurrentThread.CurrentCulture = Program.ActualCulture;
|
2013-08-06 16:11:46 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
// The old configuration file has been backed up as A.
|
|
|
|
|
|
string configString = File.ReadAllText(filepath);
|
|
|
|
|
|
if (configString.Contains("Some settings missing here after an upgrade?"))
|
2013-08-06 16:11:46 +02:00
|
|
|
|
{
|
2022-11-07 11:15:19 +08:00
|
|
|
|
string newFilePath = Path.ChangeExtension(filepath, ".old.ini");
|
2022-10-05 15:02:30 +08:00
|
|
|
|
File.Copy(filepath, newFilePath, true);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c" + Translations.mcc_use_new_config);
|
|
|
|
|
|
ConsoleIO.WriteLineFormatted("§c" + string.Format(Translations.mcc_backup_old_config, newFilePath));
|
2022-10-08 10:06:11 +08:00
|
|
|
|
return new(false, true);
|
2013-08-06 16:11:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
catch { }
|
2022-11-30 16:22:48 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c" + Translations.config_load_fail);
|
2022-10-08 10:06:11 +08:00
|
|
|
|
ConsoleIO.WriteLine(ex.GetFullMessage());
|
|
|
|
|
|
return new(false, false);
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
2022-11-05 20:27:10 +08:00
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!keepAccountSettings)
|
|
|
|
|
|
InternalConfig.KeepAccountSettings = false;
|
|
|
|
|
|
if (!keepServerSettings)
|
|
|
|
|
|
InternalConfig.KeepServerSettings = false;
|
|
|
|
|
|
}
|
2022-10-08 10:06:11 +08:00
|
|
|
|
return new(true, false);
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void WriteToFile(string filepath, bool backupOldFile)
|
|
|
|
|
|
{
|
2022-10-28 11:13:20 +08:00
|
|
|
|
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
string tomlString = TomletMain.TomlStringFrom(Config);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
Thread.CurrentThread.CurrentCulture = Program.ActualCulture;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
string[] tomlList = tomlString.Split('\n');
|
|
|
|
|
|
StringBuilder newConfig = new();
|
|
|
|
|
|
foreach (string line in tomlList)
|
|
|
|
|
|
{
|
2022-10-06 14:53:05 +08:00
|
|
|
|
Match matchComment = CommentRegex.Match(line);
|
|
|
|
|
|
if (matchComment.Success && matchComment.Groups.Count == 3)
|
2022-10-05 15:02:30 +08:00
|
|
|
|
{
|
2022-10-06 14:53:05 +08:00
|
|
|
|
string config = matchComment.Groups[1].Value, comment = matchComment.Groups[2].Value;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (config.Length > 0)
|
2022-10-05 19:39:21 +08:00
|
|
|
|
newConfig.Append(config).Append(' ', Math.Max(1, CommentsAlignPosition - config.Length) - 1);
|
2022-11-30 16:22:48 +08:00
|
|
|
|
string? comment_trans = ConfigComments.ResourceManager.GetString(comment);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
if (string.IsNullOrEmpty(comment_trans))
|
|
|
|
|
|
newConfig.Append("# ").AppendLine(comment.ReplaceLineEndings());
|
|
|
|
|
|
else
|
|
|
|
|
|
newConfig.Append("# ").AppendLine(comment_trans.Replace("\n", "\n# ").ReplaceLineEndings());
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
newConfig.AppendLine(line);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool needUpdate = true;
|
2022-10-06 18:12:32 +08:00
|
|
|
|
byte[] newConfigByte = Encoding.UTF8.GetBytes(newConfig.ToString());
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (File.Exists(filepath))
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-10-06 18:12:32 +08:00
|
|
|
|
if (new FileInfo(filepath).Length == newConfigByte.Length)
|
|
|
|
|
|
if (File.ReadAllBytes(filepath).SequenceEqual(newConfigByte))
|
|
|
|
|
|
needUpdate = false;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch { }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (needUpdate)
|
|
|
|
|
|
{
|
2022-10-06 14:53:05 +08:00
|
|
|
|
bool backupSuccessed = true;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (backupOldFile && File.Exists(filepath))
|
2022-10-06 14:53:05 +08:00
|
|
|
|
{
|
|
|
|
|
|
string backupFilePath = Path.ChangeExtension(filepath, ".backup.ini");
|
|
|
|
|
|
try { File.Copy(filepath, backupFilePath, true); }
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
backupSuccessed = false;
|
2022-11-30 16:22:48 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c" + string.Format(Translations.config_backup_fail, backupFilePath));
|
2022-10-06 14:53:05 +08:00
|
|
|
|
ConsoleIO.WriteLine(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (backupSuccessed)
|
|
|
|
|
|
{
|
2022-10-06 18:12:32 +08:00
|
|
|
|
try { File.WriteAllBytes(filepath, newConfigByte); }
|
2022-10-06 14:53:05 +08:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c" + string.Format(Translations.config_write_fail, filepath));
|
2022-10-06 14:53:05 +08:00
|
|
|
|
ConsoleIO.WriteLine(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-08-06 16:11:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-20 21:40:57 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Load settings from the command line
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="args">Command-line arguments</param>
|
|
|
|
|
|
/// <exception cref="System.ArgumentException">Thrown on invalid arguments</exception>
|
|
|
|
|
|
public static void LoadArguments(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
int positionalIndex = 0;
|
2022-11-06 16:20:38 +08:00
|
|
|
|
bool skipPassword = false;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
|
|
|
|
|
foreach (string argument in args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (argument.StartsWith("--"))
|
|
|
|
|
|
{
|
|
|
|
|
|
//Load settings as --setting=value and --section.setting=value
|
2022-10-02 18:31:08 +08:00
|
|
|
|
if (!argument.Contains('='))
|
2022-10-28 11:13:20 +08:00
|
|
|
|
throw new ArgumentException(string.Format(Translations.error_setting_argument_syntax, argument));
|
2022-10-05 15:02:30 +08:00
|
|
|
|
throw new NotImplementedException();
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
else if (argument.StartsWith("-") && argument.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Keep single dash arguments as unsupported for now (future use)
|
2022-10-28 11:13:20 +08:00
|
|
|
|
throw new ArgumentException(string.Format(Translations.error_setting_argument_syntax, argument));
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (positionalIndex)
|
|
|
|
|
|
{
|
2022-10-11 22:47:06 +02:00
|
|
|
|
case 0:
|
2022-11-06 16:20:38 +08:00
|
|
|
|
if (Config.Main.Advanced.AccountList.TryGetValue(argument, out AccountInfoConfig accountInfo))
|
|
|
|
|
|
{
|
|
|
|
|
|
InternalConfig.Account = accountInfo;
|
|
|
|
|
|
skipPassword = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
InternalConfig.Account.Login = argument;
|
|
|
|
|
|
}
|
2022-11-05 20:27:10 +08:00
|
|
|
|
InternalConfig.KeepAccountSettings = true;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
break;
|
2022-10-11 22:47:06 +02:00
|
|
|
|
case 1:
|
2022-11-06 16:20:38 +08:00
|
|
|
|
if (!skipPassword)
|
|
|
|
|
|
InternalConfig.Account.Password = argument;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
break;
|
2022-10-11 22:47:06 +02:00
|
|
|
|
case 2:
|
|
|
|
|
|
Config.Main.SetServerIP(new MainConfig.ServerInfoConfig(argument), true);
|
2022-11-05 20:27:10 +08:00
|
|
|
|
InternalConfig.KeepServerSettings = true;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
break;
|
2022-10-11 22:47:06 +02:00
|
|
|
|
case 3:
|
2022-10-05 15:02:30 +08:00
|
|
|
|
// SingleCommand = argument;
|
|
|
|
|
|
break;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
positionalIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-06 14:53:05 +08:00
|
|
|
|
public static class HeadCommentHealper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static HeadComment Config = new();
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class HeadComment
|
|
|
|
|
|
{
|
|
|
|
|
|
[TomlProperty("Current Version")]
|
2022-10-06 18:12:32 +08:00
|
|
|
|
public string CurrentVersion { get; set; } = Program.BuildInfo ?? "Development Build";
|
2022-10-11 22:47:06 +02:00
|
|
|
|
|
2022-10-06 14:53:05 +08:00
|
|
|
|
[TomlProperty("Latest Version")]
|
|
|
|
|
|
public string LatestVersion { get; set; } = "Unknown";
|
|
|
|
|
|
|
|
|
|
|
|
public void OnSettingUpdate()
|
|
|
|
|
|
{
|
2022-10-06 18:12:32 +08:00
|
|
|
|
CurrentVersion = Program.BuildInfo ?? "Development Build";
|
2022-10-06 14:53:05 +08:00
|
|
|
|
LatestVersion ??= "Unknown";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class MainConfigHealper
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static MainConfig Config = new();
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class MainConfig
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public GeneralConfig General = new();
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$Main.Advanced$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public AdvancedConfig Advanced = new();
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
[NonSerialized]
|
|
|
|
|
|
public static readonly string[] AvailableLang =
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
"af_za", "ar_sa", "ast_es", "az_az", "ba_ru", "bar", "be_by", "bg_bg",
|
|
|
|
|
|
"br_fr", "brb", "bs_ba", "ca_es", "cs_cz", "cy_gb", "da_dk", "de_at",
|
|
|
|
|
|
"de_ch", "de_de", "el_gr", "en_au", "en_ca", "en_gb", "en_nz", "en_pt",
|
|
|
|
|
|
"en_ud", "en_us", "enp", "enws", "eo_uy", "es_ar", "es_cl", "es_ec",
|
|
|
|
|
|
"es_es", "es_mx", "es_uy", "es_ve", "esan", "et_ee", "eu_es", "fa_ir",
|
|
|
|
|
|
"fi_fi", "fil_ph", "fo_fo", "fr_ca", "fr_fr", "fra_de", "fur_it", "fy_nl",
|
|
|
|
|
|
"ga_ie", "gd_gb", "gl_es", "haw_us", "he_il", "hi_in", "hr_hr", "hu_hu",
|
|
|
|
|
|
"hy_am", "id_id", "ig_ng", "io_en", "is_is", "isv", "it_it", "ja_jp",
|
|
|
|
|
|
"jbo_en", "ka_ge", "kk_kz", "kn_in", "ko_kr", "ksh", "kw_gb", "la_la",
|
|
|
|
|
|
"lb_lu", "li_li", "lmo", "lol_us", "lt_lt", "lv_lv", "lzh", "mk_mk",
|
2022-12-11 13:00:19 +08:00
|
|
|
|
"mn_mn", "ms_my", "mt_mt", "nah", "nds_de", "nl_be", "nl_nl", "nn_no",
|
|
|
|
|
|
"no_no", "oc_fr", "ovd", "pl_pl", "pt_br", "pt_pt", "qya_aa", "ro_ro",
|
|
|
|
|
|
"rpr", "ru_ru", "ry_ua", "se_no", "sk_sk", "sl_si", "so_so", "sq_al",
|
|
|
|
|
|
"sr_sp", "sv_se", "sxu", "szl", "ta_in", "th_th", "tl_ph", "tlh_aa",
|
|
|
|
|
|
"tok", "tr_tr", "tt_ru", "uk_ua", "val_es", "vec_it", "vi_vn", "yi_de",
|
|
|
|
|
|
"yo_ng", "zh_cn", "zh_hk", "zh_tw", "zlm_arab"
|
2022-10-05 15:02:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Load server information in ServerIP and ServerPort variables from a "serverip:port" couple or server alias
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>True if the server IP was valid and loaded, false otherwise</returns>
|
|
|
|
|
|
public bool SetServerIP(ServerInfoConfig serverInfo, bool checkAlias)
|
|
|
|
|
|
{
|
2022-11-05 21:15:16 +08:00
|
|
|
|
string[] sip = serverInfo.Host.Split(new[] { ":", ":" }, StringSplitOptions.None);
|
|
|
|
|
|
string host = ToLowerIfNeed(sip[0]);
|
2022-10-05 15:02:30 +08:00
|
|
|
|
ushort port = 25565;
|
2022-08-15 23:55:44 +08:00
|
|
|
|
|
2022-11-05 21:15:16 +08:00
|
|
|
|
if (serverInfo.Port.HasValue)
|
2022-10-05 15:02:30 +08:00
|
|
|
|
{
|
2022-11-05 21:15:16 +08:00
|
|
|
|
port = serverInfo.Port.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (sip.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
try { port = Convert.ToUInt16(sip[1]); }
|
|
|
|
|
|
catch (FormatException) { return false; }
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (host == "localhost" || host.Contains('.'))
|
|
|
|
|
|
{
|
|
|
|
|
|
//Server IP (IP or domain names contains at least a dot)
|
2022-11-05 21:15:16 +08:00
|
|
|
|
if (sip.Length == 1 && !serverInfo.Port.HasValue && host.Contains('.') && host.Any(c => char.IsLetter(c)) &&
|
|
|
|
|
|
Settings.Config.Main.Advanced.ResolveSrvRecords != ResolveSrvRecordType.no)
|
2022-10-05 15:02:30 +08:00
|
|
|
|
//Domain name without port may need Minecraft SRV Record lookup
|
|
|
|
|
|
ProtocolHandler.MinecraftServiceLookup(ref host, ref port);
|
|
|
|
|
|
InternalConfig.ServerIP = host;
|
|
|
|
|
|
InternalConfig.ServerPort = port;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-11-05 21:15:16 +08:00
|
|
|
|
else if (checkAlias && Advanced.ServerList.TryGetValue(sip[0], out ServerInfoConfig serverStr2))
|
2022-10-05 15:02:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
return SetServerIP(serverStr2, false);
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public void OnSettingUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.EnableTimestamps = Advanced.Timestamps;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
InternalConfig.InteractiveMode = !Advanced.ExitOnFailure;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
General.Account.Login ??= string.Empty;
|
|
|
|
|
|
General.Account.Password ??= string.Empty;
|
2022-11-05 20:27:10 +08:00
|
|
|
|
if (!InternalConfig.KeepAccountSettings)
|
2022-11-06 16:20:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (Advanced.AccountList.TryGetValue(General.Account.Login, out AccountInfoConfig account))
|
|
|
|
|
|
InternalConfig.Account = account;
|
|
|
|
|
|
else
|
|
|
|
|
|
InternalConfig.Account = General.Account;
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
General.Server.Host ??= string.Empty;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (Advanced.MessageCooldown < 0)
|
|
|
|
|
|
Advanced.MessageCooldown = 0;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (Advanced.TcpTimeout < 1)
|
|
|
|
|
|
Advanced.TcpTimeout = 1;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (Advanced.MovementSpeed < 1)
|
|
|
|
|
|
Advanced.MovementSpeed = 1;
|
2022-08-15 23:55:44 +08:00
|
|
|
|
|
2022-10-28 11:13:20 +08:00
|
|
|
|
if (!Advanced.LoadMccTranslation)
|
|
|
|
|
|
{
|
2022-12-11 13:00:19 +08:00
|
|
|
|
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
|
2022-10-28 11:13:20 +08:00
|
|
|
|
CultureInfo.DefaultThreadCurrentCulture = culture;
|
|
|
|
|
|
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
|
|
|
|
|
Program.ActualCulture = culture;
|
|
|
|
|
|
Thread.CurrentThread.CurrentCulture = culture;
|
|
|
|
|
|
Thread.CurrentThread.CurrentUICulture = culture;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
Advanced.Language = Regex.Replace(Advanced.Language, @"[^-^_^\w^*\d]", string.Empty).Replace('-', '_');
|
2022-10-06 18:12:32 +08:00
|
|
|
|
Advanced.Language = ToLowerIfNeed(Advanced.Language);
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (!AvailableLang.Contains(Advanced.Language))
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-28 11:13:20 +08:00
|
|
|
|
Advanced.Language = GetDefaultGameLanguage();
|
|
|
|
|
|
ConsoleIO.WriteLogLine("[Settings] " + Translations.config_Main_Advanced_language_invaild);
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-05 20:27:10 +08:00
|
|
|
|
if (!InternalConfig.KeepServerSettings)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-11-05 20:27:10 +08:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(General.Server.Host))
|
2022-10-05 15:02:30 +08:00
|
|
|
|
{
|
2022-11-05 20:27:10 +08:00
|
|
|
|
string[] sip = General.Server.Host.Split(new[] { ":", ":" }, StringSplitOptions.None);
|
2022-11-05 21:30:15 +08:00
|
|
|
|
General.Server.Host = sip[0];
|
2022-11-05 20:27:10 +08:00
|
|
|
|
InternalConfig.ServerIP = General.Server.Host;
|
|
|
|
|
|
|
|
|
|
|
|
if (sip.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
try { General.Server.Port = Convert.ToUInt16(sip[1]); }
|
|
|
|
|
|
catch (FormatException) { }
|
|
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-11-05 20:27:10 +08:00
|
|
|
|
if (General.Server.Port.HasValue)
|
|
|
|
|
|
InternalConfig.ServerPort = General.Server.Port.Value;
|
|
|
|
|
|
else
|
|
|
|
|
|
SetServerIP(General.Server, true);
|
|
|
|
|
|
}
|
2022-10-09 07:57:28 +08:00
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Advanced.BotOwners.Count; ++i)
|
|
|
|
|
|
Advanced.BotOwners[i] = ToLowerIfNeed(Advanced.BotOwners[i]);
|
2022-10-13 19:34:49 +08:00
|
|
|
|
|
|
|
|
|
|
if (Advanced.MinTerminalWidth < 1)
|
|
|
|
|
|
Advanced.MinTerminalWidth = 1;
|
|
|
|
|
|
if (Advanced.MinTerminalHeight < 1)
|
|
|
|
|
|
Advanced.MinTerminalHeight = 1;
|
2023-01-13 16:12:10 +08:00
|
|
|
|
|
|
|
|
|
|
if (Advanced.TemporaryFixBadpacket && !Advanced.TerrainAndMovements)
|
|
|
|
|
|
{
|
|
|
|
|
|
Advanced.TerrainAndMovements = true;
|
|
|
|
|
|
ConsoleIO.WriteLineFormatted("§c[Settings]You need to enable TerrainAndMovements before enabling TemporaryFixBadpacket.");
|
|
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class GeneralConfig
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.General.account$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public AccountInfoConfig Account = new(string.Empty, string.Empty);
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.General.login$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ServerInfoConfig Server = new(string.Empty);
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.General.server_info$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public LoginType AccountType = LoginType.microsoft;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.General.method$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public LoginMethod Method = LoginMethod.mcc;
|
2023-11-12 21:04:20 +08:00
|
|
|
|
[TomlInlineComment("$Main.General.AuthlibServer$")]
|
|
|
|
|
|
public AuthlibServer AuthServer = new(string.Empty);
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2023-11-12 21:04:20 +08:00
|
|
|
|
public enum LoginType { mojang, microsoft,Yggdrasil };
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
public enum LoginMethod { mcc, browser };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class AdvancedConfig
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.language$")]
|
2022-12-11 13:00:19 +08:00
|
|
|
|
public string Language = "en_us";
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.LoadMccTrans$")]
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public bool LoadMccTranslation = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
// [TomlInlineComment("$Main.Advanced.console_title$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string ConsoleTitle = "%username%@%serverip% - Minecraft Console Client";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.internal_cmd_char$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public InternalCmdCharType InternalCmdChar = InternalCmdCharType.slash;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.message_cooldown$")]
|
2022-10-06 18:12:32 +08:00
|
|
|
|
public double MessageCooldown = 1.0;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.bot_owners$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public List<string> BotOwners = new() { "Player1", "Player2" };
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.mc_version$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string MinecraftVersion = "auto";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.mc_forge$")]
|
2023-01-16 14:47:17 +08:00
|
|
|
|
public ForgeConfigType EnableForge = ForgeConfigType.no;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.brand_info$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public BrandInfoType BrandInfo = BrandInfoType.mcc;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.chatbot_log_file$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string ChatbotLogFile = "";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.private_msgs_cmd_name$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string PrivateMsgsCmdName = "tell";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.show_system_messages$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ShowSystemMessages = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.show_xpbar_messages$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ShowXPBarMessages = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.show_chat_links$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ShowChatLinks = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.show_inventory_layout$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ShowInventoryLayout = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.terrain_and_movements$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool TerrainAndMovements = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.move_head_while_walking$")]
|
2022-10-13 19:34:49 +08:00
|
|
|
|
public bool MoveHeadWhileWalking = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.movement_speed$")]
|
2022-10-13 19:34:49 +08:00
|
|
|
|
public int MovementSpeed = 2;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.temporary_fix_badpacket$")]
|
2022-11-01 16:37:50 +08:00
|
|
|
|
public bool TemporaryFixBadpacket = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.inventory_handling$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool InventoryHandling = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.entity_handling$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool EntityHandling = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.session_cache$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public CacheType SessionCache = CacheType.disk;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.profilekey_cache$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public CacheType ProfileKeyCache = CacheType.disk;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.resolve_srv_records$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ResolveSrvRecordType ResolveSrvRecords = ResolveSrvRecordType.fast;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$Main.Advanced.account_list$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public Dictionary<string, AccountInfoConfig> AccountList = new() {
|
2022-10-05 20:41:37 +08:00
|
|
|
|
{ "AccountNikename1", new AccountInfoConfig("playerone@email.com", "thepassword") },
|
|
|
|
|
|
{ "AccountNikename2", new AccountInfoConfig("TestBot", "-") },
|
2022-10-05 15:02:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$Main.Advanced.server_list$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public Dictionary<string, ServerInfoConfig> ServerList = new() {
|
2022-10-05 20:41:37 +08:00
|
|
|
|
{ "ServerAlias1", new ServerInfoConfig("mc.awesomeserver.com") },
|
|
|
|
|
|
{ "ServerAlias2", new ServerInfoConfig("192.168.1.27", 12345) },
|
2022-10-05 15:02:30 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.player_head_icon$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool PlayerHeadAsIcon = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.exit_on_failure$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ExitOnFailure = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.script_cache$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool CacheScript = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.timestamps$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool Timestamps = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.auto_respawn$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool AutoRespawn = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.minecraft_realms$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool MinecraftRealms = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.timeout$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public int TcpTimeout = 30;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.enable_emoji$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool EnableEmoji = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.MinTerminalWidth$")]
|
2022-10-13 19:34:49 +08:00
|
|
|
|
public int MinTerminalWidth = 16;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.MinTerminalHeight$")]
|
2022-10-13 19:34:49 +08:00
|
|
|
|
public int MinTerminalHeight = 10;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2023-08-02 14:00:11 +08:00
|
|
|
|
[TomlInlineComment("$Main.Advanced.ignore_invalid_playername$")]
|
|
|
|
|
|
public bool IgnoreInvalidPlayerName = true;
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Load login/password using an account alias
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>True if the account was found and loaded</returns>
|
|
|
|
|
|
public bool SetAccount(string accountAlias)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (AccountList.TryGetValue(accountAlias, out AccountInfoConfig accountInfo))
|
|
|
|
|
|
{
|
2022-11-06 16:20:38 +08:00
|
|
|
|
InternalConfig.Account = accountInfo;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
return true;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public enum InternalCmdCharType { none, slash, backslash };
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public enum BrandInfoType { mcc, vanilla, empty };
|
|
|
|
|
|
|
|
|
|
|
|
public enum CacheType { none, memory, disk };
|
|
|
|
|
|
|
|
|
|
|
|
public enum ResolveSrvRecordType { no, fast, yes };
|
|
|
|
|
|
|
|
|
|
|
|
public enum ForgeConfigType { no, auto, force };
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public struct AccountInfoConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Login = string.Empty, Password = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
public AccountInfoConfig(string Login)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
this.Login = Login;
|
|
|
|
|
|
this.Password = "-";
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public AccountInfoConfig(string Login, string Password)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
this.Login = Login;
|
|
|
|
|
|
this.Password = Password;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct ServerInfoConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Host = string.Empty;
|
|
|
|
|
|
public ushort? Port = null;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ServerInfoConfig(string Host)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
string[] sip = Host.Split(new[] { ":", ":" }, StringSplitOptions.None);
|
|
|
|
|
|
this.Host = sip[0];
|
|
|
|
|
|
|
|
|
|
|
|
if (sip.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
try { this.Port = Convert.ToUInt16(sip[1]); }
|
|
|
|
|
|
catch (FormatException) { }
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ServerInfoConfig(string Host, ushort Port)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
this.Host = Host.Split(new[] { ":", ":" }, StringSplitOptions.None)[0];
|
|
|
|
|
|
this.Port = Port;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
2023-11-12 21:04:20 +08:00
|
|
|
|
public struct AuthlibServer
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Host = string.Empty;
|
|
|
|
|
|
public int Port = 443;
|
|
|
|
|
|
|
|
|
|
|
|
public AuthlibServer(string Host)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] sip = Host.Split(new[] { ":", ":" }, StringSplitOptions.None);
|
|
|
|
|
|
this.Host = sip[0];
|
|
|
|
|
|
|
|
|
|
|
|
if (sip.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
try { this.Port = Convert.ToUInt16(sip[1]); }
|
|
|
|
|
|
catch (FormatException) { }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AuthlibServer(string Host, ushort Port)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Host = Host.Split(new[] { ":", ":" }, StringSplitOptions.None)[0];
|
|
|
|
|
|
this.Port = Port;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class SignatureConfigHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static SignatureConfig Config = new();
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class SignatureConfig
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.LoginWithSecureProfile$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool LoginWithSecureProfile = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.SignChat$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool SignChat = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.SignMessageInCommand$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool SignMessageInCommand = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.MarkLegallySignedMsg$")]
|
2023-01-29 22:39:11 +08:00
|
|
|
|
public bool MarkLegallySignedMsg = true;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.MarkModifiedMsg$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool MarkModifiedMsg = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.MarkIllegallySignedMsg$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool MarkIllegallySignedMsg = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.MarkSystemMessage$")]
|
2023-01-29 22:39:11 +08:00
|
|
|
|
public bool MarkSystemMessage = true;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.ShowModifiedChat$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ShowModifiedChat = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Signature.ShowIllegalSignedChat$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ShowIllegalSignedChat = true;
|
|
|
|
|
|
|
|
|
|
|
|
public void OnSettingUpdate() { }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class LoggingConfigHealper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static LoggingConfig Config = new();
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class LoggingConfig
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.DebugMessages$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool DebugMessages = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.ChatMessages$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ChatMessages = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.InfoMessages$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool InfoMessages = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.WarningMessages$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool WarningMessages = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.ErrorMessages$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ErrorMessages = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.ChatFilter$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string ChatFilterRegex = @".*";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.DebugFilter$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string DebugFilterRegex = @".*";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.FilterMode$")]
|
2022-10-06 18:12:32 +08:00
|
|
|
|
public FilterModeEnum FilterMode = FilterModeEnum.disable;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.LogToFile$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool LogToFile = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.LogFile$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string LogFile = @"console-log.txt";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.PrependTimestamp$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool PrependTimestamp = false;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$Logging.SaveColorCodes$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool SaveColorCodes = false;
|
|
|
|
|
|
|
|
|
|
|
|
public void OnSettingUpdate() { }
|
|
|
|
|
|
|
2022-10-06 18:12:32 +08:00
|
|
|
|
public enum FilterModeEnum { disable, blacklist, whitelist }
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-11 13:00:19 +08:00
|
|
|
|
public static class ConsoleConfigHealper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static ConsoleConfig Config = new();
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class ConsoleConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public MainConfig General = new();
|
|
|
|
|
|
|
|
|
|
|
|
[TomlPrecedingComment("$Console.CommandSuggestion$")]
|
|
|
|
|
|
public CommandSuggestionConfig CommandSuggestion = new();
|
|
|
|
|
|
|
|
|
|
|
|
public void OnSettingUpdate()
|
|
|
|
|
|
{
|
2022-12-14 14:45:51 +08:00
|
|
|
|
// Reader
|
|
|
|
|
|
ConsoleInteractive.ConsoleReader.DisplayUesrInput = General.Display_Input;
|
|
|
|
|
|
|
|
|
|
|
|
// Writer
|
|
|
|
|
|
ConsoleInteractive.ConsoleWriter.EnableColor = General.ConsoleColorMode != ConsoleColorModeType.disable;
|
|
|
|
|
|
|
|
|
|
|
|
ConsoleInteractive.ConsoleWriter.UseVT100ColorCode = General.ConsoleColorMode != ConsoleColorModeType.legacy_4bit;
|
|
|
|
|
|
|
|
|
|
|
|
// Buffer
|
2023-01-14 21:07:09 +08:00
|
|
|
|
General.History_Input_Records =
|
2022-12-14 14:45:51 +08:00
|
|
|
|
ConsoleInteractive.ConsoleBuffer.SetBackreadBufferLimit(General.History_Input_Records);
|
2022-12-11 13:00:19 +08:00
|
|
|
|
|
2022-12-14 14:45:51 +08:00
|
|
|
|
// Suggestion
|
|
|
|
|
|
if (General.ConsoleColorMode == ConsoleColorModeType.disable)
|
|
|
|
|
|
CommandSuggestion.Enable_Color = false;
|
2022-12-11 13:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
ConsoleInteractive.ConsoleSuggestion.EnableColor = CommandSuggestion.Enable_Color;
|
|
|
|
|
|
|
2022-12-14 14:45:51 +08:00
|
|
|
|
ConsoleInteractive.ConsoleSuggestion.Enable24bitColor = General.ConsoleColorMode == ConsoleColorModeType.vt100_24bit;
|
|
|
|
|
|
|
2022-12-11 16:30:45 +08:00
|
|
|
|
ConsoleInteractive.ConsoleSuggestion.UseBasicArrow = CommandSuggestion.Use_Basic_Arrow;
|
|
|
|
|
|
|
2022-12-11 13:00:19 +08:00
|
|
|
|
CommandSuggestion.Max_Suggestion_Width =
|
|
|
|
|
|
ConsoleInteractive.ConsoleSuggestion.SetMaxSuggestionLength(CommandSuggestion.Max_Suggestion_Width);
|
|
|
|
|
|
|
|
|
|
|
|
CommandSuggestion.Max_Displayed_Suggestions =
|
|
|
|
|
|
ConsoleInteractive.ConsoleSuggestion.SetMaxSuggestionCount(CommandSuggestion.Max_Displayed_Suggestions);
|
|
|
|
|
|
|
2022-12-14 14:45:51 +08:00
|
|
|
|
// Suggestion color settings
|
2022-12-11 13:00:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (!CheckColorCode(CommandSuggestion.Text_Color))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.WriteLine(string.Format(Translations.config_commandsuggestion_illegal_color, "CommandSuggestion.TextColor", CommandSuggestion.Text_Color));
|
|
|
|
|
|
CommandSuggestion.Text_Color = "#f8fafc";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!CheckColorCode(CommandSuggestion.Text_Background_Color))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.WriteLine(string.Format(Translations.config_commandsuggestion_illegal_color, "CommandSuggestion.TextBackgroundColor", CommandSuggestion.Text_Background_Color));
|
|
|
|
|
|
CommandSuggestion.Text_Background_Color = "#64748b";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!CheckColorCode(CommandSuggestion.Highlight_Text_Color))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.WriteLine(string.Format(Translations.config_commandsuggestion_illegal_color, "CommandSuggestion.HighlightTextColor", CommandSuggestion.Highlight_Text_Color));
|
|
|
|
|
|
CommandSuggestion.Highlight_Text_Color = "#334155";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!CheckColorCode(CommandSuggestion.Highlight_Text_Background_Color))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.WriteLine(string.Format(Translations.config_commandsuggestion_illegal_color, "CommandSuggestion.HighlightTextBackgroundColor", CommandSuggestion.Highlight_Text_Background_Color));
|
|
|
|
|
|
CommandSuggestion.Highlight_Text_Background_Color = "#fde047";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!CheckColorCode(CommandSuggestion.Tooltip_Color))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.WriteLine(string.Format(Translations.config_commandsuggestion_illegal_color, "CommandSuggestion.TooltipColor", CommandSuggestion.Tooltip_Color));
|
|
|
|
|
|
CommandSuggestion.Tooltip_Color = "#7dd3fc";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!CheckColorCode(CommandSuggestion.Highlight_Tooltip_Color))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.WriteLine(string.Format(Translations.config_commandsuggestion_illegal_color, "CommandSuggestion.HighlightTooltipColor", CommandSuggestion.Highlight_Tooltip_Color));
|
|
|
|
|
|
CommandSuggestion.Highlight_Tooltip_Color = "#3b82f6";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!CheckColorCode(CommandSuggestion.Arrow_Symbol_Color))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleIO.WriteLine(string.Format(Translations.config_commandsuggestion_illegal_color, "CommandSuggestion.ArrowSymbolColor", CommandSuggestion.Arrow_Symbol_Color));
|
|
|
|
|
|
CommandSuggestion.Arrow_Symbol_Color = "#d1d5db";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConsoleInteractive.ConsoleSuggestion.SetColors(
|
|
|
|
|
|
CommandSuggestion.Text_Color, CommandSuggestion.Text_Background_Color,
|
|
|
|
|
|
CommandSuggestion.Highlight_Text_Color, CommandSuggestion.Highlight_Text_Background_Color,
|
|
|
|
|
|
CommandSuggestion.Tooltip_Color, CommandSuggestion.Highlight_Tooltip_Color,
|
|
|
|
|
|
CommandSuggestion.Arrow_Symbol_Color);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static bool CheckColorCode(string? input)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(input))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (input.Length < 6 || input.Length > 7)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (input.Length == 6 && input[0] == '#')
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (input.Length == 7 && input[0] != '#')
|
|
|
|
|
|
return false;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Convert.ToInt32(input.Length == 7 ? input[1..] : input, 16);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class MainConfig
|
|
|
|
|
|
{
|
2022-12-14 14:45:51 +08:00
|
|
|
|
[TomlInlineComment("$Console.General.ConsoleColorMode$")]
|
|
|
|
|
|
public ConsoleColorModeType ConsoleColorMode = ConsoleColorModeType.vt100_24bit;
|
2022-12-11 13:00:19 +08:00
|
|
|
|
|
2022-12-14 14:45:51 +08:00
|
|
|
|
[TomlInlineComment("$Console.General.Display_Input$")]
|
|
|
|
|
|
public bool Display_Input = true;
|
|
|
|
|
|
|
|
|
|
|
|
[TomlInlineComment("$Console.General.History_Input_Records$")]
|
|
|
|
|
|
public int History_Input_Records = 32;
|
2022-12-11 13:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class CommandSuggestionConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
[TomlInlineComment("$Console.CommandSuggestion.Enable$")]
|
|
|
|
|
|
public bool Enable = true;
|
|
|
|
|
|
|
|
|
|
|
|
public bool Enable_Color = true;
|
|
|
|
|
|
|
2022-12-11 16:30:45 +08:00
|
|
|
|
[TomlInlineComment("$Console.CommandSuggestion.Use_Basic_Arrow$")]
|
|
|
|
|
|
public bool Use_Basic_Arrow = false;
|
|
|
|
|
|
|
2022-12-11 13:00:19 +08:00
|
|
|
|
public int Max_Suggestion_Width = 30;
|
|
|
|
|
|
|
|
|
|
|
|
public int Max_Displayed_Suggestions = 6;
|
|
|
|
|
|
|
|
|
|
|
|
public string Text_Color = "#f8fafc";
|
|
|
|
|
|
|
|
|
|
|
|
public string Text_Background_Color = "#64748b";
|
|
|
|
|
|
|
|
|
|
|
|
public string Highlight_Text_Color = "#334155";
|
|
|
|
|
|
|
|
|
|
|
|
public string Highlight_Text_Background_Color = "#fde047";
|
|
|
|
|
|
|
|
|
|
|
|
public string Tooltip_Color = "#7dd3fc";
|
|
|
|
|
|
|
|
|
|
|
|
public string Highlight_Tooltip_Color = "#3b82f6";
|
|
|
|
|
|
|
|
|
|
|
|
public string Arrow_Symbol_Color = "#d1d5db";
|
|
|
|
|
|
}
|
2022-12-14 14:45:51 +08:00
|
|
|
|
|
|
|
|
|
|
public enum ConsoleColorModeType { disable, legacy_4bit, vt100_4bit, vt100_8bit, vt100_24bit };
|
2022-12-11 13:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class AppVarConfigHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static AppVarConfig Config = new();
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class AppVarConfig
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$AppVars.Variables$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
private readonly Dictionary<string, string> VarStirng = new() {
|
|
|
|
|
|
{ "your_var", "your_value" },
|
|
|
|
|
|
{ "your var 2", "your value 2" },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public void OnSettingUpdate() { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NonSerialized]
|
|
|
|
|
|
private readonly Dictionary<string, object> VarObject = new();
|
|
|
|
|
|
|
|
|
|
|
|
[NonSerialized]
|
|
|
|
|
|
readonly object varLock = new();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set a custom %variable% which will be available through expandVars()
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="varName">Name of the variable</param>
|
|
|
|
|
|
/// <param name="varData">Value of the variable</param>
|
|
|
|
|
|
/// <returns>True if the parameters were valid</returns>
|
|
|
|
|
|
public bool SetVar(string varName, object varData)
|
|
|
|
|
|
{
|
|
|
|
|
|
varName = Settings.ToLowerIfNeed(new string(varName.TakeWhile(char.IsLetterOrDigit).ToArray()));
|
|
|
|
|
|
if (varName.Length > 0)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
bool isString = varData.GetType() == typeof(string);
|
|
|
|
|
|
lock (varLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isString)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (VarObject.ContainsKey(varName))
|
|
|
|
|
|
VarObject.Remove(varName);
|
|
|
|
|
|
VarStirng[varName] = (string)varData;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (VarStirng.ContainsKey(varName))
|
|
|
|
|
|
VarStirng.Remove(varName);
|
|
|
|
|
|
VarObject[varName] = varData;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
else
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-11 22:47:06 +02:00
|
|
|
|
return false;
|
2022-09-13 19:25:00 +08:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a custom %variable% or null if the variable does not exist
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="varName">Variable name</param>
|
|
|
|
|
|
/// <returns>The value or null if the variable does not exists</returns>
|
|
|
|
|
|
public object? GetVar(string varName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (VarStirng.TryGetValue(varName, out string? valueString))
|
|
|
|
|
|
return valueString;
|
|
|
|
|
|
else if (VarObject.TryGetValue(varName, out object? valueObject))
|
|
|
|
|
|
return valueObject;
|
|
|
|
|
|
else
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a custom %variable% or null if the variable does not exist
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="varName">Variable name</param>
|
|
|
|
|
|
/// <returns>The value or null if the variable does not exists</returns>
|
|
|
|
|
|
public bool TryGetVar(string varName, [NotNullWhen(true)] out object? varData)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (VarStirng.TryGetValue(varName, out string? valueString))
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
varData = valueString;
|
|
|
|
|
|
return true;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
else if (VarObject.TryGetValue(varName, out object? valueObject))
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
varData = valueObject;
|
|
|
|
|
|
return true;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
else
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
varData = null;
|
|
|
|
|
|
return false;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a dictionary containing variables (names and value)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>A IDictionary<string, object> containing a name and a vlaue key pairs of variables</returns>
|
|
|
|
|
|
public Dictionary<string, object> GetVariables()
|
|
|
|
|
|
{
|
2022-10-11 22:47:06 +02:00
|
|
|
|
Dictionary<string, object> res = new(VarObject);
|
2022-10-05 15:02:30 +08:00
|
|
|
|
foreach ((string varName, string varData) in VarStirng)
|
|
|
|
|
|
res.Add(varName, varData);
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Replace %variables% with their value from global AppVars
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="str">String to parse</param>
|
|
|
|
|
|
/// <param name="localContext">Optional local variables overriding global variables</param>
|
|
|
|
|
|
/// <returns>Modifier string</returns>
|
|
|
|
|
|
public string ExpandVars(string str, Dictionary<string, object>? localVars = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder result = new();
|
|
|
|
|
|
for (int i = 0; i < str.Length; i++)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (str[i] == '%')
|
|
|
|
|
|
{
|
|
|
|
|
|
bool varname_ok = false;
|
|
|
|
|
|
StringBuilder var_name = new();
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = i + 1; j < str.Length; j++)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (!char.IsLetterOrDigit(str[j]) && str[j] != '_')
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
if (str[j] == '%')
|
|
|
|
|
|
varname_ok = var_name.Length > 0;
|
|
|
|
|
|
break;
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
else var_name.Append(str[j]);
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
if (varname_ok)
|
2021-05-20 21:40:57 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
string varname = var_name.ToString();
|
|
|
|
|
|
string varname_lower = Settings.ToLowerIfNeed(varname);
|
|
|
|
|
|
i = i + varname.Length + 1;
|
|
|
|
|
|
|
|
|
|
|
|
switch (varname_lower)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "username": result.Append(InternalConfig.Username); break;
|
2022-11-06 16:20:38 +08:00
|
|
|
|
case "login": result.Append(InternalConfig.Account.Login); break;
|
2022-10-05 15:02:30 +08:00
|
|
|
|
case "serverip": result.Append(InternalConfig.ServerIP); break;
|
|
|
|
|
|
case "serverport": result.Append(InternalConfig.ServerPort); break;
|
|
|
|
|
|
case "datetime":
|
|
|
|
|
|
DateTime time = DateTime.Now;
|
|
|
|
|
|
result.Append(String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
|
|
|
|
|
time.Year.ToString("0000"),
|
|
|
|
|
|
time.Month.ToString("00"),
|
|
|
|
|
|
time.Day.ToString("00"),
|
|
|
|
|
|
time.Hour.ToString("00"),
|
|
|
|
|
|
time.Minute.ToString("00"),
|
|
|
|
|
|
time.Second.ToString("00")));
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
if (localVars != null && localVars.ContainsKey(varname_lower))
|
|
|
|
|
|
result.Append(localVars[varname_lower].ToString());
|
|
|
|
|
|
else if (TryGetVar(varname_lower, out object? var_value))
|
|
|
|
|
|
result.Append(var_value.ToString());
|
|
|
|
|
|
else
|
|
|
|
|
|
result.Append("%" + varname + '%');
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
else result.Append(str[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
else result.Append(str[i]);
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
return result.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class MCSettingsConfigHealper
|
|
|
|
|
|
{
|
|
|
|
|
|
public static MCSettingsConfig Config = new();
|
2021-05-20 21:40:57 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class MCSettingsConfig
|
|
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$MCSettings.Enabled$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool Enabled = true;
|
2022-09-09 15:39:41 +02:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$MCSettings.Locale$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string Locale = "en_US";
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$MCSettings.RenderDistance$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public byte RenderDistance = 8;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$MCSettings.Difficulty$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public DifficultyType Difficulty = DifficultyType.peaceful;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$MCSettings.ChatMode$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatModeType ChatMode = ChatModeType.enabled;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$MCSettings.ChatColors$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool ChatColors = true;
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$MCSettings.MainHand$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public MainHandType MainHand = MainHandType.left;
|
|
|
|
|
|
|
|
|
|
|
|
public SkinInfo Skin = new();
|
|
|
|
|
|
|
|
|
|
|
|
public void OnSettingUpdate() { }
|
|
|
|
|
|
|
|
|
|
|
|
public enum DifficultyType { peaceful, easy, normal, difficult };
|
|
|
|
|
|
|
|
|
|
|
|
public enum ChatModeType { enabled, commands, disabled };
|
|
|
|
|
|
|
|
|
|
|
|
public enum MainHandType { left, right };
|
|
|
|
|
|
|
|
|
|
|
|
public struct SkinInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Cape = true, Hat = true, Jacket = false;
|
|
|
|
|
|
public bool Sleeve_Left = false, Sleeve_Right = false;
|
|
|
|
|
|
public bool Pants_Left = false, Pants_Right = false;
|
|
|
|
|
|
|
|
|
|
|
|
public SkinInfo() { }
|
|
|
|
|
|
|
|
|
|
|
|
public SkinInfo(bool Cape, bool Hat, bool Jacket, bool Sleeve_Left, bool Sleeve_Right, bool Pants_Left, bool Pants_Right)
|
2022-09-25 22:06:26 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
this.Cape = Cape;
|
|
|
|
|
|
this.Hat = Hat;
|
|
|
|
|
|
this.Jacket = Jacket;
|
|
|
|
|
|
this.Sleeve_Left = Sleeve_Left;
|
|
|
|
|
|
this.Sleeve_Right = Sleeve_Right;
|
|
|
|
|
|
this.Pants_Left = Pants_Left;
|
|
|
|
|
|
this.Pants_Right = Pants_Right;
|
2022-09-25 22:06:26 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
|
|
|
|
|
public byte GetByte()
|
2022-09-28 00:14:43 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
return (byte)(
|
|
|
|
|
|
((Cape ? 1 : 0) << 0)
|
|
|
|
|
|
| ((Jacket ? 1 : 0) << 1)
|
|
|
|
|
|
| ((Sleeve_Left ? 1 : 0) << 2)
|
|
|
|
|
|
| ((Sleeve_Right ? 1 : 0) << 3)
|
|
|
|
|
|
| ((Pants_Left ? 1 : 0) << 4)
|
|
|
|
|
|
| ((Pants_Right ? 1 : 0) << 5)
|
|
|
|
|
|
| ((Hat ? 1 : 0) << 6)
|
|
|
|
|
|
);
|
2022-09-28 00:14:43 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
2021-05-20 21:40:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class ChatFormatConfigHelper
|
2013-08-06 16:11:46 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static ChatFormatConfig Config = new();
|
2013-08-06 16:11:46 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class ChatFormatConfig
|
2022-08-29 19:12:44 +02:00
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$ChatFormat.Builtins$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public bool Builtins = true;
|
2015-10-22 22:17:15 +02:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlInlineComment("$ChatFormat.UserDefined$")]
|
2022-10-06 18:12:32 +08:00
|
|
|
|
public bool UserDefined = false;
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string Public = @"^<([a-zA-Z0-9_]+)> (.+)$";
|
2022-09-12 02:10:18 +08:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public string Private = @"^([a-zA-Z0-9_]+) whispers to you: (.+)$";
|
|
|
|
|
|
|
|
|
|
|
|
public string TeleportRequest = @"^([a-zA-Z0-9_]+) has requested (?:to|that you) teleport to (?:you|them)\.$";
|
|
|
|
|
|
|
2022-10-17 10:03:01 +08:00
|
|
|
|
public void OnSettingUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (UserDefined)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool checkResult = true;
|
|
|
|
|
|
|
|
|
|
|
|
try { _ = new Regex(Public); }
|
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
|
{
|
|
|
|
|
|
checkResult = false;
|
2023-01-13 16:12:10 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c[Settings]Illegal regular expression: ChatFormat.Public = " + Public);
|
2022-10-17 10:03:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try { _ = new Regex(Private); }
|
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
|
{
|
|
|
|
|
|
checkResult = false;
|
2023-01-13 16:12:10 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c[Settings]Illegal regular expression: ChatFormat.Private = " + Private);
|
2022-10-17 10:03:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try { _ = new Regex(TeleportRequest); }
|
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
|
{
|
|
|
|
|
|
checkResult = false;
|
2023-01-13 16:12:10 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c[Settings]Illegal regular expression: ChatFormat.TeleportRequest = " + TeleportRequest);
|
2022-10-17 10:03:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!checkResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
UserDefined = false;
|
2023-01-13 16:12:10 +08:00
|
|
|
|
ConsoleIO.WriteLineFormatted("§c[Settings]ChatFormat: User-defined regular expressions are disabled.");
|
2022-10-17 10:03:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-28 19:26:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class ChatBotConfigHealper
|
2015-10-22 22:17:15 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static ChatBotConfig Config = new();
|
2013-08-06 16:11:46 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class ChatBotConfig
|
2022-09-12 16:27:37 +08:00
|
|
|
|
{
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.Alerts$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.Alerts.Configs Alerts
|
2022-09-12 16:27:37 +08:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
get { return ChatBots.Alerts.Config; }
|
|
|
|
|
|
set { ChatBots.Alerts.Config = value; ChatBots.Alerts.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
2022-09-12 16:27:37 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AntiAfk$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AntiAFK.Configs AntiAFK
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AntiAFK.Config; }
|
|
|
|
|
|
set { ChatBots.AntiAFK.Config = value; ChatBots.AntiAFK.Config.OnSettingUpdate(); }
|
2022-09-12 16:27:37 +08:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoAttack$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AutoAttack.Configs AutoAttack
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AutoAttack.Config; }
|
|
|
|
|
|
set { ChatBots.AutoAttack.Config = value; ChatBots.AutoAttack.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoCraft$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AutoCraft.Configs AutoCraft
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AutoCraft.Config; }
|
|
|
|
|
|
set { ChatBots.AutoCraft.Config = value; ChatBots.AutoCraft.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoDig$")]
|
2022-10-08 17:56:32 +08:00
|
|
|
|
public ChatBots.AutoDig.Configs AutoDig
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AutoDig.Config; }
|
|
|
|
|
|
set { ChatBots.AutoDig.Config = value; ChatBots.AutoDig.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoDrop$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AutoDrop.Configs AutoDrop
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AutoDrop.Config; }
|
|
|
|
|
|
set { ChatBots.AutoDrop.Config = value; ChatBots.AutoDrop.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoEat$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AutoEat.Configs AutoEat
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AutoEat.Config; }
|
|
|
|
|
|
set { ChatBots.AutoEat.Config = value; ChatBots.AutoEat.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoFishing$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AutoFishing.Configs AutoFishing
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AutoFishing.Config; }
|
|
|
|
|
|
set { ChatBots.AutoFishing.Config = value; ChatBots.AutoFishing.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoRelog$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AutoRelog.Configs AutoRelog
|
2022-09-12 16:27:37 +08:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
get { return ChatBots.AutoRelog.Config; }
|
|
|
|
|
|
set { ChatBots.AutoRelog.Config = value; ChatBots.AutoRelog.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.AutoRespond$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.AutoRespond.Configs AutoRespond
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.AutoRespond.Config; }
|
|
|
|
|
|
set { ChatBots.AutoRespond.Config = value; ChatBots.AutoRespond.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.ChatLog$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.ChatLog.Configs ChatLog
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.ChatLog.Config; }
|
|
|
|
|
|
set { ChatBots.ChatLog.Config = value; ChatBots.ChatLog.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.DiscordBridge$")]
|
2022-10-21 02:29:47 +02:00
|
|
|
|
public ChatBots.DiscordBridge.Configs DiscordBridge
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.DiscordBridge.Config; }
|
2022-10-21 19:05:49 +08:00
|
|
|
|
set { ChatBots.DiscordBridge.Config = value; ChatBots.DiscordBridge.Config.OnSettingUpdate(); }
|
2022-10-21 02:29:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.Farmer$")]
|
2022-10-11 22:47:06 +02:00
|
|
|
|
public ChatBots.Farmer.Configs Farmer
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.Farmer.Config; }
|
|
|
|
|
|
set { ChatBots.Farmer.Config = value; ChatBots.Farmer.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.FollowPlayer$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.FollowPlayer.Configs FollowPlayer
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.FollowPlayer.Config; }
|
|
|
|
|
|
set { ChatBots.FollowPlayer.Config = value; ChatBots.FollowPlayer.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.HangmanGame$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.HangmanGame.Configs HangmanGame
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.HangmanGame.Config; }
|
|
|
|
|
|
set { ChatBots.HangmanGame.Config = value; ChatBots.HangmanGame.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.Mailer$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.Mailer.Configs Mailer
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.Mailer.Config; }
|
|
|
|
|
|
set { ChatBots.Mailer.Config = value; ChatBots.Mailer.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.Map$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.Map.Configs Map
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.Map.Config; }
|
|
|
|
|
|
set { ChatBots.Map.Config = value; ChatBots.Map.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.PlayerListLogger$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.PlayerListLogger.Configs PlayerListLogger
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.PlayerListLogger.Config; }
|
|
|
|
|
|
set { ChatBots.PlayerListLogger.Config = value; ChatBots.PlayerListLogger.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.RemoteControl$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.RemoteControl.Configs RemoteControl
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.RemoteControl.Config; }
|
|
|
|
|
|
set { ChatBots.RemoteControl.Config = value; ChatBots.RemoteControl.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.ReplayCapture$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.ReplayCapture.Configs ReplayCapture
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.ReplayCapture.Config; }
|
|
|
|
|
|
set { ChatBots.ReplayCapture.Config = value; ChatBots.ReplayCapture.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.ScriptScheduler$")]
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public ChatBots.ScriptScheduler.Configs ScriptScheduler
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.ScriptScheduler.Config; }
|
|
|
|
|
|
set { ChatBots.ScriptScheduler.Config = value; ChatBots.ScriptScheduler.Config.OnSettingUpdate(); }
|
2022-09-12 16:27:37 +08:00
|
|
|
|
}
|
2022-10-20 19:29:35 +02:00
|
|
|
|
|
2022-11-30 16:22:48 +08:00
|
|
|
|
[TomlPrecedingComment("$ChatBot.TelegramBridge$")]
|
2022-10-24 15:35:24 +02:00
|
|
|
|
public ChatBots.TelegramBridge.Configs TelegramBridge
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.TelegramBridge.Config; }
|
|
|
|
|
|
set { ChatBots.TelegramBridge.Config = value; ChatBots.TelegramBridge.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
2023-05-20 21:44:18 +02:00
|
|
|
|
|
|
|
|
|
|
[TomlPrecedingComment("$ChatBot.ItemsCollector$")]
|
|
|
|
|
|
public ChatBots.ItemsCollector.Configs ItemsCollector
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.ItemsCollector.Config; }
|
|
|
|
|
|
set { ChatBots.ItemsCollector.Config = value; ChatBots.ItemsCollector.Config.OnSettingUpdate(); }
|
|
|
|
|
|
}
|
2023-05-27 19:46:28 +02:00
|
|
|
|
|
|
|
|
|
|
[TomlPrecedingComment("$ChatBot.WebSocketBot$")]
|
|
|
|
|
|
public ChatBots.WebSocketBot.Configs WebSocketBot
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ChatBots.WebSocketBot.Config!; }
|
|
|
|
|
|
set { ChatBots.WebSocketBot.Config = value; }
|
|
|
|
|
|
}
|
2022-09-12 16:27:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public static string GetDefaultGameLanguage()
|
|
|
|
|
|
{
|
2022-12-11 13:00:19 +08:00
|
|
|
|
string gameLanguage = "en_us";
|
2022-10-28 11:13:20 +08:00
|
|
|
|
string systemLanguage = string.IsNullOrWhiteSpace(Program.ActualCulture.Name)
|
|
|
|
|
|
? Program.ActualCulture.Parent.Name
|
|
|
|
|
|
: Program.ActualCulture.Name;
|
|
|
|
|
|
switch (systemLanguage)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "af":
|
|
|
|
|
|
case "af-ZA":
|
|
|
|
|
|
gameLanguage = "af_za";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ar":
|
|
|
|
|
|
case "ar-AE":
|
|
|
|
|
|
case "ar-BH":
|
|
|
|
|
|
case "ar-DZ":
|
|
|
|
|
|
case "ar-EG":
|
|
|
|
|
|
case "ar-IQ":
|
|
|
|
|
|
case "ar-JO":
|
|
|
|
|
|
case "ar-KW":
|
|
|
|
|
|
case "ar-LB":
|
|
|
|
|
|
case "ar-LY":
|
|
|
|
|
|
case "ar-MA":
|
|
|
|
|
|
case "ar-OM":
|
|
|
|
|
|
case "ar-QA":
|
|
|
|
|
|
case "ar-SA":
|
|
|
|
|
|
case "ar-SY":
|
|
|
|
|
|
case "ar-TN":
|
|
|
|
|
|
case "ar-YE":
|
|
|
|
|
|
gameLanguage = "ar_sa";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "az":
|
|
|
|
|
|
case "az-Cyrl-AZ":
|
|
|
|
|
|
case "az-Latn-AZ":
|
|
|
|
|
|
gameLanguage = "az_az";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "be":
|
|
|
|
|
|
case "be-BY":
|
|
|
|
|
|
gameLanguage = "be_by";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "bg":
|
|
|
|
|
|
case "bg-BG":
|
|
|
|
|
|
gameLanguage = "bg_bg";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "bs-Latn-BA":
|
|
|
|
|
|
gameLanguage = "bs_ba";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ca":
|
|
|
|
|
|
case "ca-ES":
|
|
|
|
|
|
gameLanguage = "ca_es";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "cs":
|
|
|
|
|
|
case "cs-CZ":
|
|
|
|
|
|
gameLanguage = "cs_cz";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "cy-GB":
|
|
|
|
|
|
gameLanguage = "cy_gb";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "da":
|
|
|
|
|
|
case "da-DK":
|
|
|
|
|
|
gameLanguage = "da_dk";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "de":
|
|
|
|
|
|
case "de-DE":
|
|
|
|
|
|
case "de-LI":
|
|
|
|
|
|
case "de-LU":
|
|
|
|
|
|
gameLanguage = "de_de";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "de-AT":
|
|
|
|
|
|
gameLanguage = "de_at";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "de-CH":
|
|
|
|
|
|
gameLanguage = "de_ch";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "dv":
|
|
|
|
|
|
case "dv-MV":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "el":
|
|
|
|
|
|
case "el-GR":
|
|
|
|
|
|
gameLanguage = "el_gr";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "en":
|
|
|
|
|
|
case "en-029":
|
|
|
|
|
|
case "en-BZ":
|
|
|
|
|
|
case "en-IE":
|
|
|
|
|
|
case "en-JM":
|
|
|
|
|
|
case "en-PH":
|
|
|
|
|
|
case "en-TT":
|
|
|
|
|
|
case "en-ZA":
|
|
|
|
|
|
case "en-ZW":
|
2022-12-11 13:00:19 +08:00
|
|
|
|
case "en-US":
|
|
|
|
|
|
gameLanguage = "en_us";
|
|
|
|
|
|
break;
|
2022-10-28 11:13:20 +08:00
|
|
|
|
case "en-GB":
|
|
|
|
|
|
gameLanguage = "en_gb";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "en-AU":
|
|
|
|
|
|
gameLanguage = "en_au";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "en-CA":
|
|
|
|
|
|
gameLanguage = "en_ca";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "en-NZ":
|
|
|
|
|
|
gameLanguage = "en_nz";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "es":
|
|
|
|
|
|
case "es-BO":
|
|
|
|
|
|
case "es-CO":
|
|
|
|
|
|
case "es-CR":
|
|
|
|
|
|
case "es-DO":
|
|
|
|
|
|
case "es-ES":
|
|
|
|
|
|
case "es-GT":
|
|
|
|
|
|
case "es-HN":
|
|
|
|
|
|
case "es-NI":
|
|
|
|
|
|
case "es-PA":
|
|
|
|
|
|
case "es-PE":
|
|
|
|
|
|
case "es-PR":
|
|
|
|
|
|
case "es-PY":
|
|
|
|
|
|
case "es-SV":
|
|
|
|
|
|
gameLanguage = "es_es";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "es-AR":
|
|
|
|
|
|
gameLanguage = "es_ar";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "es-CL":
|
|
|
|
|
|
gameLanguage = "es_cl";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "es-EC":
|
|
|
|
|
|
gameLanguage = "es_ec";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "es-MX":
|
|
|
|
|
|
gameLanguage = "es_mx";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "es-UY":
|
|
|
|
|
|
gameLanguage = "es_uy";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "es-VE":
|
|
|
|
|
|
gameLanguage = "es_ve";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "et":
|
|
|
|
|
|
case "et-EE":
|
|
|
|
|
|
gameLanguage = "et_ee";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "eu":
|
|
|
|
|
|
case "eu-ES":
|
|
|
|
|
|
gameLanguage = "eu_es";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "fa":
|
|
|
|
|
|
case "fa-IR":
|
|
|
|
|
|
gameLanguage = "fa_ir";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "fi":
|
|
|
|
|
|
case "fi-FI":
|
|
|
|
|
|
gameLanguage = "fi_fi";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "fo":
|
|
|
|
|
|
case "fo-FO":
|
|
|
|
|
|
gameLanguage = "fo_fo";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "fr":
|
|
|
|
|
|
case "fr-BE":
|
|
|
|
|
|
case "fr-FR":
|
|
|
|
|
|
case "fr-CH":
|
|
|
|
|
|
case "fr-LU":
|
|
|
|
|
|
case "fr-MC":
|
|
|
|
|
|
gameLanguage = "fr_fr";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "fr-CA":
|
|
|
|
|
|
gameLanguage = "fr_ca";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "gl":
|
|
|
|
|
|
case "gl-ES":
|
|
|
|
|
|
gameLanguage = "gl_es";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "gu":
|
|
|
|
|
|
case "gu-IN":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "he":
|
|
|
|
|
|
case "he-IL":
|
|
|
|
|
|
gameLanguage = "he_il";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "hi":
|
|
|
|
|
|
case "hi-IN":
|
|
|
|
|
|
gameLanguage = "hi_in";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "hr":
|
|
|
|
|
|
case "hr-BA":
|
|
|
|
|
|
case "hr-HR":
|
|
|
|
|
|
gameLanguage = "hr_hr";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "hu":
|
|
|
|
|
|
case "hu-HU":
|
|
|
|
|
|
gameLanguage = "hu_hu";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "hy":
|
|
|
|
|
|
case "hy-AM":
|
|
|
|
|
|
gameLanguage = "hy_am";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "id":
|
|
|
|
|
|
case "id-ID":
|
|
|
|
|
|
gameLanguage = "id_id";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "is":
|
|
|
|
|
|
case "is-IS":
|
|
|
|
|
|
gameLanguage = "is_is";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "it":
|
|
|
|
|
|
case "it-CH":
|
|
|
|
|
|
case "it-IT":
|
|
|
|
|
|
gameLanguage = "it_it";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ja":
|
|
|
|
|
|
case "ja-JP":
|
|
|
|
|
|
gameLanguage = "ja_jp";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ka":
|
|
|
|
|
|
case "ka-GE":
|
|
|
|
|
|
gameLanguage = "ka_ge";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "kk":
|
|
|
|
|
|
case "kk-KZ":
|
|
|
|
|
|
gameLanguage = "kk_kz";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "kn":
|
|
|
|
|
|
case "kn-IN":
|
|
|
|
|
|
gameLanguage = "kn_in";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "kok":
|
|
|
|
|
|
case "kok-IN":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ko":
|
|
|
|
|
|
case "ko-KR":
|
|
|
|
|
|
gameLanguage = "ko_kr";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ky":
|
|
|
|
|
|
case "ky-KG":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "lt":
|
|
|
|
|
|
case "lt-LT":
|
|
|
|
|
|
gameLanguage = "lt_lt";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "lv":
|
|
|
|
|
|
case "lv-LV":
|
|
|
|
|
|
gameLanguage = "lv_lv";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "mi-NZ":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "mk":
|
|
|
|
|
|
case "mk-MK":
|
|
|
|
|
|
gameLanguage = "mk_mk";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "mn":
|
|
|
|
|
|
case "mn-MN":
|
|
|
|
|
|
gameLanguage = "mn_mn";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "mr":
|
|
|
|
|
|
case "mr-IN":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ms":
|
|
|
|
|
|
case "ms-BN":
|
|
|
|
|
|
case "ms-MY":
|
|
|
|
|
|
gameLanguage = "ms_my";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "mt-MT":
|
|
|
|
|
|
gameLanguage = "mt_mt";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "nb-NO":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "nl":
|
|
|
|
|
|
case "nl-NL":
|
|
|
|
|
|
gameLanguage = "nl_nl";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "nl-BE":
|
|
|
|
|
|
gameLanguage = "nl_be";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "nn-NO":
|
|
|
|
|
|
gameLanguage = "nn_no";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "no":
|
|
|
|
|
|
gameLanguage = "no_no";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ns-ZA":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "pa":
|
|
|
|
|
|
case "pa-IN":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "pl":
|
|
|
|
|
|
case "pl-PL":
|
|
|
|
|
|
gameLanguage = "pl_pl";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "pt":
|
|
|
|
|
|
case "pt-PT":
|
|
|
|
|
|
gameLanguage = "pt_pt";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "pt-BR":
|
|
|
|
|
|
gameLanguage = "pt_br";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "quz-BO":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "quz-EC":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "quz-PE":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ro":
|
|
|
|
|
|
case "ro-RO":
|
|
|
|
|
|
gameLanguage = "ro_ro";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ru":
|
|
|
|
|
|
case "ru-RU":
|
|
|
|
|
|
gameLanguage = "ru_ru";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sa":
|
|
|
|
|
|
case "sa-IN":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "se-FI":
|
|
|
|
|
|
case "se-NO":
|
|
|
|
|
|
case "se-SE":
|
|
|
|
|
|
gameLanguage = "se_no";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sk":
|
|
|
|
|
|
case "sk-SK":
|
|
|
|
|
|
gameLanguage = "sk_sk";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sl":
|
|
|
|
|
|
case "sl-SI":
|
|
|
|
|
|
gameLanguage = "sl_si";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sma-NO":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sma-SE":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "smj-NO":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "smj-SE":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "smn-FI":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sms-FI":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sq":
|
|
|
|
|
|
case "sq-AL":
|
|
|
|
|
|
gameLanguage = "sq_al";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sr":
|
|
|
|
|
|
case "sr-Cyrl-BA":
|
|
|
|
|
|
case "sr-Cyrl-CS":
|
|
|
|
|
|
case "sr-Latn-BA":
|
|
|
|
|
|
case "sr-Latn-CS":
|
|
|
|
|
|
gameLanguage = "sr_sp";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sv":
|
|
|
|
|
|
case "sv-FI":
|
|
|
|
|
|
case "sv-SE":
|
|
|
|
|
|
gameLanguage = "sv_se";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "sw":
|
|
|
|
|
|
case "sw-KE":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "syr":
|
|
|
|
|
|
case "syr-SY":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ta":
|
|
|
|
|
|
case "ta-IN":
|
|
|
|
|
|
gameLanguage = "ta_in";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "te":
|
|
|
|
|
|
case "te-IN":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "th":
|
|
|
|
|
|
case "th-TH":
|
|
|
|
|
|
gameLanguage = "th_th";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "tn-ZA":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "tr":
|
|
|
|
|
|
case "tr-TR":
|
|
|
|
|
|
gameLanguage = "tr_tr";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "tt":
|
|
|
|
|
|
case "tt-RU":
|
|
|
|
|
|
gameLanguage = "tt_ru";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "uk":
|
|
|
|
|
|
case "uk-UA":
|
|
|
|
|
|
gameLanguage = "uk_ua";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "ur":
|
|
|
|
|
|
case "ur-PK":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "uz":
|
|
|
|
|
|
case "uz-Cyrl-UZ":
|
|
|
|
|
|
case "uz-Latn-UZ":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "vi":
|
|
|
|
|
|
case "vi-VN":
|
|
|
|
|
|
gameLanguage = "vi_vn";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "xh-ZA":
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "zh-Hans": /* CurrentCulture.Parent.Name */
|
|
|
|
|
|
case "zh":
|
|
|
|
|
|
case "zh-CN":
|
|
|
|
|
|
case "zh-CHS":
|
|
|
|
|
|
case "zh-SG":
|
|
|
|
|
|
gameLanguage = "zh_cn";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "zh-Hant": /* CurrentCulture.Parent.Name */
|
|
|
|
|
|
case "zh-HK":
|
|
|
|
|
|
case "zh-CHT":
|
|
|
|
|
|
case "zh-MO":
|
|
|
|
|
|
gameLanguage = "zh_hk";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "zh-TW":
|
|
|
|
|
|
gameLanguage = "zh_tw";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "zu-ZA":
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
return gameLanguage;
|
|
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
|
2022-09-06 16:08:51 +02:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
|
|
|
|
|
public static string ToLowerIfNeed(string str)
|
|
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
const string lookupStringL = "---------------------------------!-#$%&-()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[-]^_`abcdefghijklmnopqrstuvwxyz{|}~-";
|
2022-09-06 16:08:51 +02:00
|
|
|
|
|
|
|
|
|
|
bool needLower = false;
|
|
|
|
|
|
foreach (Char c in str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Char.IsUpper(c))
|
|
|
|
|
|
{
|
|
|
|
|
|
needLower = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (needLower)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder sb = new(str);
|
|
|
|
|
|
for (int i = 0; i < str.Length; ++i)
|
|
|
|
|
|
if (char.IsUpper(sb[i]))
|
|
|
|
|
|
sb[i] = lookupStringL[sb[i]];
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-06 14:53:05 +08:00
|
|
|
|
|
2022-10-08 17:56:32 +08:00
|
|
|
|
public static int DoubleToTick(double time)
|
|
|
|
|
|
{
|
|
|
|
|
|
time = Math.Min(int.MaxValue / 10, time);
|
|
|
|
|
|
return (int)Math.Round(time * 10);
|
|
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
2022-09-06 16:08:51 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class InternalCmdCharTypeExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static char ToChar(this InternalCmdCharType type)
|
2014-06-13 16:50:55 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
return type switch
|
2014-06-13 16:50:55 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
InternalCmdCharType.none => ' ',
|
|
|
|
|
|
InternalCmdCharType.slash => '/',
|
|
|
|
|
|
InternalCmdCharType.backslash => '\\',
|
|
|
|
|
|
_ => '/',
|
|
|
|
|
|
};
|
2014-06-19 19:24:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static string ToLogString(this InternalCmdCharType type)
|
2014-06-19 19:24:03 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
return type switch
|
2014-06-29 14:49:54 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
InternalCmdCharType.none => string.Empty,
|
|
|
|
|
|
InternalCmdCharType.slash => @"/",
|
|
|
|
|
|
InternalCmdCharType.backslash => @"\",
|
|
|
|
|
|
_ => @"/",
|
|
|
|
|
|
};
|
2022-09-11 22:35:26 +02:00
|
|
|
|
}
|
2022-10-05 15:02:30 +08:00
|
|
|
|
}
|
2022-10-11 22:47:06 +02:00
|
|
|
|
|
2022-10-05 15:02:30 +08:00
|
|
|
|
public static class BrandInfoTypeExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static string? ToBrandString(this BrandInfoType info)
|
2014-06-11 20:40:25 +02:00
|
|
|
|
{
|
2022-10-05 15:02:30 +08:00
|
|
|
|
return info switch
|
2014-06-11 20:40:25 +02:00
|
|
|
|
{
|
2022-10-05 19:39:21 +08:00
|
|
|
|
BrandInfoType.mcc => "Minecraft-Console-Client/" + Program.Version,
|
2022-10-05 15:02:30 +08:00
|
|
|
|
BrandInfoType.vanilla => "vanilla",
|
|
|
|
|
|
BrandInfoType.empty => null,
|
|
|
|
|
|
_ => null,
|
|
|
|
|
|
};
|
2014-06-11 20:40:25 +02:00
|
|
|
|
}
|
2013-08-06 16:11:46 +02:00
|
|
|
|
}
|
2022-10-08 10:06:11 +08:00
|
|
|
|
|
|
|
|
|
|
public static class ExceptionExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static string GetFullMessage(this Exception ex)
|
|
|
|
|
|
{
|
2022-10-13 19:34:49 +08:00
|
|
|
|
string msg = ex.Message.Replace("+", "->");
|
2022-10-08 10:06:11 +08:00
|
|
|
|
return ex.InnerException == null
|
2022-10-13 19:34:49 +08:00
|
|
|
|
? msg
|
|
|
|
|
|
: msg + "\n --> " + ex.InnerException.GetFullMessage();
|
2022-10-08 10:06:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-08-06 16:11:46 +02:00
|
|
|
|
}
|