Skip to content

Commit f707b9e

Browse files
Merge pull request #20 from downloadpizza/feature/configurableCommandPrefix
Add CommandPrefix config entry
2 parents 4054f3a + bbd552f commit f707b9e

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

Nuclei/Features/ChatService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ private static bool CanSend(string message, bool ignoreEmpty = false, bool ignor
4242
/// <returns> The sanitized message. </returns>
4343
private static string SanitizeMessage(this string message)
4444
{
45-
return message.TrimStart('/');
45+
return message.TrimStart(NucleiConfig.CommandPrefixChar);
4646
}
4747

4848
/// <summary>
49-
/// Pre-processes a chat message by replacing dynamic placeholders & sanitizing it.
49+
/// Pre-processes a chat message by replacing dynamic placeholders &amp; sanitizing it.
5050
/// </summary>
5151
/// <param name="message"> The message to pre-process. </param>
5252
/// <param name="player"> Player to use for chat message variables </param>

Nuclei/Features/NucleiConfig.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public static class NucleiConfig
7878

7979
internal static ConfigEntry<bool>? UseAllMissions;
8080
internal const bool DefaultUseAllMissions = false;
81+
82+
internal static ConfigEntry<string>? CommandPrefix;
83+
internal const string DefaultCommandPrefix = "/";
8184

8285
internal static List<string> ModeratorsList => Moderators!.Value.Split(';').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
8386

@@ -86,6 +89,8 @@ public static class NucleiConfig
8689
internal static List<string> BannedPlayersList => BannedPlayers!.Value.Split(';').Where(b => !string.IsNullOrWhiteSpace(b)).ToList();
8790

8891
internal static List<string> MissionsList => Missions!.Value.Split(';').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
92+
93+
internal static char CommandPrefixChar => CommandPrefix!.Value[0];
8994

9095
internal static void InitSettings(ConfigFile config)
9196
{
@@ -153,6 +158,9 @@ internal static void InitSettings(ConfigFile config)
153158

154159
UseAllMissions = config.Bind(GeneralSection, "UseAllMissions", DefaultUseAllMissions, "Whether to use all missions available to the client (including tutorials, workshop items, custom missions, etc...) for mission selection. If false, only the missions in the config will be used.");
155160
Nuclei.Logger?.LogDebug($"UseAllMissions: {UseAllMissions.Value}");
161+
162+
CommandPrefix = config.Bind(GeneralSection, "CommandPrefix", DefaultCommandPrefix, "What to use as the command prefix (the character at the start of a command).");
163+
Nuclei.Logger?.LogDebug($"CommandPrefix: {CommandPrefix.Value}");
156164

157165
Nuclei.Logger?.LogDebug("Loaded settings!");
158166
}
@@ -196,6 +204,12 @@ internal static void ValidateSettings()
196204
Nuclei.Logger?.LogWarning("TargetFrameRate cannot be less than -1! Setting to -1 (unlimited).");
197205
TargetFrameRate.Value = -1;
198206
}
207+
208+
if (CommandPrefix!.Value.Length != 1)
209+
{
210+
Nuclei.Logger?.LogWarning("CommandPrefix must be a single character! Resetting to default value.");
211+
CommandPrefix.Value = DefaultCommandPrefix;
212+
}
199213

200214
ValidateForUserErrors();
201215

Nuclei/Nuclei.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PackageId>MaxWasUnavailable.Nuclei</PackageId>
88
<Title>Nuclei</Title>
99
<Description>A flexible and powerful dedicated server solution for Nuclear Option.</Description>
10-
<Version>1.3.2</Version>
10+
<Version>1.3.3</Version>
1111
<Authors>MaxWasUnavailable</Authors>
1212
<PackageTags>nuclear;option;bepinex</PackageTags>
1313

Nuclei/Patches/ChatManagerPatches.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using HarmonyLib;
22
using Mirage;
3+
using Nuclei.Features;
34
using Nuclei.Features.Commands;
45
using Nuclei.Helpers;
56

@@ -17,7 +18,7 @@ private static bool UserCode_CmdSendChatMessage_1323305531Prefix(string message,
1718
if (!sender.TryGetPlayer(out var player))
1819
Nuclei.Logger?.LogWarning("Player component is null");
1920

20-
if (message.StartsWith("/") && message.Length > 1)
21+
if (message.StartsWith(NucleiConfig.CommandPrefix!.Value) && message.Length > 1)
2122
if (CommandService.TryExecuteCommand(player!, message.Remove(0, 1)))
2223
return false;
2324

0 commit comments

Comments
 (0)