Skip to content

Commit

Permalink
Expand provision capability, fix chat command handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooshua committed Sep 29, 2023
1 parent 001dac0 commit d6cfca3
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 4 deletions.
4 changes: 3 additions & 1 deletion builtin/BitMod.Commands/Hosts/ChatCommandHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public Task<Directive> OnChatMessage(PlayerTypedMessageEventArgs ev, BitServer s
{
// This is a command (starts with ! or /)
// Send to command handler and prevent it from being shown in chat.
var withoutPrefix = ev.Message.Substring(1);

var source = new InGameSource(server, sender, _logger);
var input = CommandInput.FromString(source, ev.Message);
var input = CommandInput.FromString(source, withoutPrefix);

_logger.Information("Player {@Name} {@SteamId} used command: {@Command} {@Args} (From string {@Message})",
sender.Name, sender.SteamID, input.Command, input.Arguments, ev.Message);
Expand Down
2 changes: 1 addition & 1 deletion builtin/BitMod.Commands/Sources/Internal/InGameSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public void Reply(string message)
_player.SteamID,
message);

_player.Message(message);
_player.SayToChat(message);
}
}
19 changes: 17 additions & 2 deletions builtin/BitMod.Provision/Config/ProvisionServerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public class ProvisionServerAdapter
{
private const string MAPCYCLE = "mapcycle";
private const string GAMEMODES = "gamemodes";
private const string LOADING_TEXT = "loading_text";
private const string MIN_PLAYERS = "min_players";

private IConfigObject _configObject;

public ProvisionServerAdapter(IConfigObject configObject)
Expand All @@ -14,10 +17,16 @@ public ProvisionServerAdapter(IConfigObject configObject)
}

public bool HasMapcycle()
=> _configObject.Get(MAPCYCLE) != null;
=> _configObject.Get<IConfigObject>(MAPCYCLE) != null;

public bool HasGamemodes()
=> _configObject.Get(GAMEMODES) != null;
=> _configObject.Get<IConfigObject>(GAMEMODES) != null;

public bool HasLoadingText()
=> _configObject.Get<IConfigSymbol>(LOADING_TEXT) != null;

public bool HasMinPlayers()
=> _configObject.Get<IConfigSymbol>(MIN_PLAYERS) != null;

public string[]? GetMapcycle()
=> _configObject.Get<IConfigObject>(MAPCYCLE)?.AsList()
Expand All @@ -33,5 +42,11 @@ public bool HasGamemodes()
?.Select(symbol => symbol.Symbol)
?.ToArray();

public string? GetLoadingText()
=> _configObject.Get<IConfigSymbol>(LOADING_TEXT)?.Symbol;

public long? GetMinPlayers()
=> _configObject.Get<IConfigSymbol>(MIN_PLAYERS)?.AsInt;


}
36 changes: 36 additions & 0 deletions builtin/BitMod.Provision/Helpers/GamemodeValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Serilog;

namespace BitMod.Provision.Helpers;

public class GamemodeValidator
{
public static IEnumerable<string> Known = new[]
{
// infantry conquest
"INFCONQ",
// rush (bomb defusal)
"RUSH",
// conquest
"CONQ",
// team deathmatch
"TDM",
// domination
"DOMI",
"FRONTLINE",
"Elimination",
"CaptureTheFlag",
"CashRun",
"VoxelTrench",
"VoxelFortify",

};

public static void ValidateGamemodes(ILogger logger, IEnumerable<string> chosen)
{
var notInKnown = chosen
.Where(opt => !Known.Contains(opt));

foreach (string s in notInKnown)
logger.Warning("[BitMod Provision] Gamemode {@Gamemode} is not known to BitMod, it may be invalid! Check your spelling.", s);
}
}
49 changes: 49 additions & 0 deletions builtin/BitMod.Provision/Helpers/MapcycleValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Serilog;

namespace BitMod.Provision.Helpers;

public class MapcycleValidator
{
public static IEnumerable<string> Known = new[]
{

"Azagor",
"Basra",
"Construction",
"District",
"Dustydew",
"Eduardovo",
"Frugis",
"Isle",
"Lonovo",
"MultiIslands",
"Namak",
"OilDunes",
"River",
"Salhan",
"SandySunset",
"TensaTown",
"Valley",
"Wakistan",
"WineParadise",

// old versions of maps
"Old_District",
"Old_Eduardovo",
"Old_MultuIslands",
"Old_Namak",
"Old_OilDunes",

// not visible in polls
"EventMap"
};

public static void ValidateMaps(ILogger logger, IEnumerable<string> chosen)
{
var notInKnown = chosen
.Where(opt => !Known.Contains(opt));

foreach (string s in notInKnown)
logger.Warning("[BitMod Provision] Map {@Map} is not known to BitMod, it may be invalid! Check your spelling.", s);
}
}
15 changes: 15 additions & 0 deletions builtin/BitMod.Provision/Host/ProvisionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BitMod.Events.Meta;
using BitMod.Events.Server;
using BitMod.Provision.Config;
using BitMod.Provision.Helpers;
using BitMod.Public;

using Lilikoi.Standard;
Expand Down Expand Up @@ -50,13 +51,27 @@ private void Provision(BitServer server)
if (localAdapter.HasMapcycle())
{
_logger.Debug("Provisioning {@Server}'s mapcycle to {@Mapcycle}", server.ToString(), localAdapter.GetMapcycle());
MapcycleValidator.ValidateMaps(_logger, localAdapter.GetMapcycle());
server.MapRotation.SetRotation(localAdapter.GetMapcycle());
}

if (localAdapter.HasGamemodes())
{
_logger.Debug("Provisioning {@Server}'s gamemodes to {@Gamemodes}", server.ToString(), localAdapter.GetGamemodes());
GamemodeValidator.ValidateGamemodes(_logger, localAdapter.GetGamemodes());
server.GamemodeRotation.SetRotation(localAdapter.GetGamemodes());
}

if (localAdapter.HasLoadingText())
{
_logger.Debug("Provisioning {@Server}'s loading text to {@Text}", server.ToString(), localAdapter.GetLoadingText());
server.SetLoadingScreenText(localAdapter.GetLoadingText());
}

if (localAdapter.HasMinPlayers())
{
_logger.Debug("Provisioning {@Server}'s min players to {@MinPlayers}", server.ToString(), localAdapter.GetMinPlayers());
server.RoundSettings.PlayersToStart = (int) localAdapter.GetMinPlayers();
}
}
}
3 changes: 3 additions & 0 deletions standalone/BitMod.Launcher/BitMod.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<None Update="configs\core.cfg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="configs\provisions.cfg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions standalone/BitMod.Launcher/configs/provisions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"1" "CONQ"
}

// If you want a description to show on the loading screen, add it here.
// You can use unity rich text, as documented here:
// https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/StyledText.html
// "loading_text" "Welcome to this awesome server!"

// "mapcycle"
// {
// If you want to enforce a custom mapcycle, do it here.
Expand Down

0 comments on commit d6cfca3

Please sign in to comment.