Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/t chat does not work #292

Merged
merged 4 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions EvoSC.sln
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameModeUiModule.Tests", "t
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveRankingModule.Tests", "tests\Modules\LiveRankingModule.Tests\LiveRankingModule.Tests.csproj", "{4AA1890A-1423-4831-95B2-E29B9A7A58D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamChatModule", "src/Modules/TeamChatModule/TeamChatModule.csproj", "{DDB0A249-BD1C-4556-BFE1-362B17EDA874}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamChatModule.Tests", "tests\Modules\TeamChatModule.Tests\TeamChatModule.Tests.csproj", "{7BD60D6E-7B7E-4771-87C0-7F98FC82F990}"
EndProject




Expand Down Expand Up @@ -417,6 +422,14 @@ Global
{4AA1890A-1423-4831-95B2-E29B9A7A58D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AA1890A-1423-4831-95B2-E29B9A7A58D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AA1890A-1423-4831-95B2-E29B9A7A58D1}.Release|Any CPU.Build.0 = Release|Any CPU
{DDB0A249-BD1C-4556-BFE1-362B17EDA874}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDB0A249-BD1C-4556-BFE1-362B17EDA874}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDB0A249-BD1C-4556-BFE1-362B17EDA874}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDB0A249-BD1C-4556-BFE1-362B17EDA874}.Release|Any CPU.Build.0 = Release|Any CPU
{7BD60D6E-7B7E-4771-87C0-7F98FC82F990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BD60D6E-7B7E-4771-87C0-7F98FC82F990}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BD60D6E-7B7E-4771-87C0-7F98FC82F990}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BD60D6E-7B7E-4771-87C0-7F98FC82F990}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -482,5 +495,7 @@ Global
{5BA1FF1B-8CB0-4FF5-B6C0-4E2E323D446E} = {DC47658A-F421-4BA4-B617-090A7DFB3900}
{5B515690-0F0B-44D1-B644-3524A83A17CE} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
{4AA1890A-1423-4831-95B2-E29B9A7A58D1} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
{DDB0A249-BD1C-4556-BFE1-362B17EDA874} = {DC47658A-F421-4BA4-B617-090A7DFB3900}
{7BD60D6E-7B7E-4771-87C0-7F98FC82F990} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions src/EvoSC.CLI/CliStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public static void SetupBasePipeline(this IStartupPipeline pipeline, IEvoScBaseC
.RegisterSingleton<IServiceContainerManager, ServiceContainerManager>()
, "Logging")

.Services(AppFeature.Chat, s => s
.Register<IChatService, ChatService>(Lifestyle.Transient)
, "GbxRemoteClient", "Themes")

.Services(AppFeature.ChatCommands, s => s
.AddEvoScChatCommands()
, "Logging", "PlayerManager")
Expand Down
10 changes: 5 additions & 5 deletions src/EvoSC.Commands/Middleware/CommandsMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CommandsMiddleware(ActionDelegate next, ILogger<CommandsMiddleware>
{
private readonly ChatCommandParser _parser = new(cmdManager);

async Task HandleUserErrorsAsync(IParserResult result, string playerLogin)
async Task HandleUserErrorsAsync(IParserResult result, IPlayer player)
{
if (result.Exception is CommandParserException cmdParserException)
{
Expand All @@ -31,12 +31,12 @@ async Task HandleUserErrorsAsync(IParserResult result, string playerLogin)
}

var message = $"Error: {cmdParserException.Message}";
await serverClient.SendChatMessageAsync(playerLogin, $"Error: {message}");
await serverClient.Chat.ErrorMessageAsync($"Error: {message}", player);
}

if (result.Exception is PlayerNotFoundException playerNotFoundException)
{
await serverClient.SendChatMessageAsync(playerLogin, $"Error: {playerNotFoundException.Message}");
await serverClient.Chat.ErrorMessageAsync($"Error: {playerNotFoundException.Message}", player);
}
else
{
Expand All @@ -55,7 +55,7 @@ private async Task ExecuteCommandAsync(IChatCommand cmd, object[] args, ChatRout

var contextServerClient = context.ServiceScope.Container.GetRequiredService<IServerClient>();

var playerInteractionContext = new CommandInteractionContext((IOnlinePlayer)routerContext.Player, contextServerClient, context)
var playerInteractionContext = new CommandInteractionContext((IOnlinePlayer)routerContext.Author, contextServerClient, context)
{
CommandExecuted = cmd
};
Expand Down Expand Up @@ -122,7 +122,7 @@ public async Task ExecuteAsync(ChatRouterPipelineContext context)
}
else if (parserResult.Exception != null)
{
await HandleUserErrorsAsync(parserResult, context.Player.GetLogin());
await HandleUserErrorsAsync(parserResult, context.Author);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ await permissions.HasPermissionAsync(cmdContext.Player, cmdContext.CommandExecut
return;
}

await server.SendChatMessageAsync(cmdContext.Player, "Insufficient permissions to run this command.");
await server.Chat.SendChatMessageAsync("Insufficient permissions to run this command.", cmdContext.Player);
}
}
6 changes: 6 additions & 0 deletions src/EvoSC.Common/Application/AppFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ public enum AppFeature
/// </summary>
[Identifier(NoPrefix = true)]
Themes,

/// <summary>
/// Optimized way to send chat messages to a set of players of any size.
/// </summary>
[Identifier(NoPrefix = true)]
Chat,
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using EvoSC.Common.Interfaces.Models;
using EvoSC.Common.Interfaces.Services;

namespace EvoSC.Common.Interfaces.Controllers;

public interface IPlayerInteractionContext : IGenericControllerContext
{
public IOnlinePlayer Player { get; }
public IServerClient Server { get; }
public IChatService Chat => Server.Chat;
}
7 changes: 6 additions & 1 deletion src/EvoSC.Common/Interfaces/IRemoteChatRouter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
namespace EvoSC.Common.Interfaces;
using EvoSC.Common.Interfaces.Models;
using EvoSC.Common.Remote.ChatRouter;

namespace EvoSC.Common.Interfaces;

public interface IRemoteChatRouter
{
public Task SendMessageAsync(string message, IOnlinePlayer actor);
public Task SendMessageAsync(ChatRouterPipelineContext pipelineContext);
}
64 changes: 5 additions & 59 deletions src/EvoSC.Common/Interfaces/IServerClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using EvoSC.Common.Interfaces.Models;
using EvoSC.Common.Interfaces.Services;
using EvoSC.Common.Util.TextFormatting;
using GbxRemoteNet.Interfaces;

namespace EvoSC.Common.Interfaces;
Expand All @@ -13,6 +15,8 @@ public interface IServerClient
/// Whether the client is connected to the remote XMLRPC server or not.
/// </summary>
public bool Connected { get; }

public IChatService Chat { get; }

/// <summary>
/// Start the client and set up a connection.
Expand All @@ -29,66 +33,8 @@ public interface IServerClient
public Task StopAsync(CancellationToken token);

/// <summary>
/// Send an info message to the chat.
/// </summary>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task InfoMessageAsync(string text);

/// <summary>
/// Send an info message to a specific player.
/// </summary>
/// <param name="player">Player to send the message to.</param>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task InfoMessageAsync(IPlayer player, string text);

/// <summary>
/// Send a success message to the chat.
/// </summary>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task SuccessMessageAsync(string text);

/// <summary>
/// Send a success message to a specific player.
/// Get the server's maps directory.
/// </summary>
/// <param name="player">Player to send the message to.</param>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task SuccessMessageAsync(IPlayer player, string text);

/// <summary>
/// Send a warning message to the chat.
/// </summary>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task WarningMessageAsync(string text);

/// <summary>
/// Send a warning message to a specific player.
/// </summary>
/// <param name="player">Player to send the message to.</param>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task WarningMessageAsync(IPlayer player, string text);

/// <summary>
/// Send a error message to the chat.
/// </summary>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task ErrorMessageAsync(string text);

/// <summary>
/// Send a error message to a specific player.
/// </summary>
/// <param name="player">Player to send the message to.</param>
/// <param name="text">Text to send.</param>
/// <returns></returns>
public Task ErrorMessageAsync(IPlayer player, string text);

public Task<string> GetMapsDirectoryAsync();

public Task<bool> FileExistsAsync(string file);
}
Loading
Loading