Skip to content

Commit

Permalink
Run commands in a task. Ignore message case when matching commands. B…
Browse files Browse the repository at this point in the history
…ump version.
  • Loading branch information
oliver4888 committed Nov 15, 2020
1 parent 7c7c4e5 commit 95bfc84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions LobbyCommands/GameEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ public class GameEventListener : IEventListener
public GameEventListener(ILogger<LobbyCommandsPlugin> logger) => _logger = logger;

[EventListener]
public async ValueTask OnPlayerChat(IPlayerChatEvent e)
public void OnPlayerChat(IPlayerChatEvent e)
{
if (e.Game.GameState != GameStates.NotStarted || !e.Message.StartsWith("/") || !e.ClientPlayer.IsHost)
return;

_logger.LogInformation($"Attempting to evaluate command from {e.PlayerControl.PlayerInfo.PlayerName} on {e.Game.Code.Code}. Message was: {e.Message}");
Task.Run(async () => await DoCommands(e));
}

private async Task DoCommands(IPlayerChatEvent e)
{
_logger.LogDebug($"Attempting to evaluate command from {e.PlayerControl.PlayerInfo.PlayerName} on {e.Game.Code.Code}. Message was: {e.Message}");

string[] parts = e.Message[1..].Split(" ");
string[] parts = e.Message.ToLowerInvariant()[1..].Split(" ");

switch (parts[0])
{
Expand Down Expand Up @@ -55,12 +60,12 @@ public async ValueTask OnPlayerChat(IPlayerChatEvent e)
return;
}

if (!_mapNames.Any(name => name.ToUpperInvariant() == parts[1].ToUpperInvariant()))
if (!_mapNames.Any(name => name.ToLowerInvariant() == parts[1]))
{
await e.PlayerControl.SendChatAsync($"Unknown map. Accepted values: {string.Join(", ", _mapNames)}");
return;
}

MapTypes map = Enum.Parse<MapTypes>(parts[1], true);

await e.PlayerControl.SendChatAsync($"Setting map to {map}");
Expand Down
2 changes: 1 addition & 1 deletion LobbyCommands/LobbyCommandsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace LobbyCommands
package: "uk.ol48.lobbycommands",
name: "Lobby Commands",
author: "oliver4888",
version: "1.0.0")]
version: "1.0.1")]
public class LobbyCommandsPlugin : PluginBase
{
readonly ILogger<LobbyCommandsPlugin> _logger;
Expand Down

0 comments on commit 95bfc84

Please sign in to comment.