-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add server management module with set password and slots commands (#264)
- Loading branch information
Showing
25 changed files
with
426 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Modules/ServerManagementModule/Controllers/ServerCommandsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using EvoSC.Commands.Attributes; | ||
using EvoSC.Commands.Interfaces; | ||
using EvoSC.Common.Controllers; | ||
using EvoSC.Common.Controllers.Attributes; | ||
using EvoSC.Modules.Official.ServerManagementModule.Events; | ||
using EvoSC.Modules.Official.ServerManagementModule.Interfaces; | ||
using EvoSC.Modules.Official.ServerManagementModule.Permissions; | ||
|
||
namespace EvoSC.Modules.Official.ServerManagementModule.Controllers; | ||
|
||
[Controller] | ||
public class ServerCommandsController(IServerManagementService serverManagementService) : EvoScController<ICommandInteractionContext> | ||
{ | ||
[ChatCommand("setpassword", "Set the player and spectator password for joining the server.", | ||
ServerManagementPermissions.SetPassword)] | ||
[CommandAlias("/setpw", true)] | ||
public async Task SetServerPasswordAsync(string password) | ||
{ | ||
await serverManagementService.SetPasswordAsync(password); | ||
|
||
Context.AuditEvent | ||
.WithEventName(ServerManagementAuditEvents.PasswordSet) | ||
.HavingProperties(new { password }) | ||
.Success(); | ||
|
||
await Context.Server.SuccessMessageAsync(Context.Player, "The password was changed."); | ||
} | ||
|
||
[ChatCommand("clearpassword", "Clear the server password.", | ||
ServerManagementPermissions.SetPassword)] | ||
[CommandAlias("/clearpw", true)] | ||
public async Task ClearServerPasswordAsync() | ||
{ | ||
await serverManagementService.SetPasswordAsync(""); | ||
|
||
Context.AuditEvent | ||
.WithEventName(ServerManagementAuditEvents.PasswordSet) | ||
.HavingProperties(new { password = "", cleared = true }) | ||
.Success(); | ||
|
||
await Context.Server.SuccessMessageAsync(Context.Player, "The password was cleared and removed."); | ||
} | ||
|
||
[ChatCommand("setmaxplayers", "Set maximum number of players that can join the server.", | ||
ServerManagementPermissions.SetMaxSlots)] | ||
[CommandAlias("/maxplayers", true)] | ||
public async Task SetMaxPlayersAsync(int maxPlayers) | ||
{ | ||
await serverManagementService.SetMaxPlayersAsync(maxPlayers); | ||
|
||
Context.AuditEvent | ||
.WithEventName(ServerManagementAuditEvents.MaxPlayersSet) | ||
.HavingProperties(new { maxPlayers }) | ||
.Success(); | ||
|
||
await Context.Server.SuccessMessageAsync(Context.Player, $"Max players set to {maxPlayers}"); | ||
} | ||
|
||
[ChatCommand("setmaxspectators", "Set the maximum number of spectators that can join the server.", | ||
ServerManagementPermissions.SetMaxSlots)] | ||
[CommandAlias("/maxspectators", true)] | ||
public async Task SetMaxSpectatorsAsync(int maxSpectators) | ||
{ | ||
await serverManagementService.SetMaxSpectatorsAsync(maxSpectators); | ||
|
||
Context.AuditEvent | ||
.WithEventName(ServerManagementAuditEvents.MaxSpectatorsSet) | ||
.HavingProperties(new { maxSpectators }) | ||
.Success(); | ||
|
||
await Context.Server.SuccessMessageAsync(Context.Player, $"Max spectators set to {maxSpectators}"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Modules/ServerManagementModule/Events/Args/PasswordChangedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using EvoSC.Common.Events.Arguments; | ||
|
||
namespace EvoSC.Modules.Official.ServerManagementModule.Events.Args; | ||
|
||
public class PasswordChangedEventArgs : EvoScEventArgs | ||
{ | ||
public string NewPassword { get; init; } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Modules/ServerManagementModule/Events/Args/PlayerSlotsChangedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using EvoSC.Common.Events.Arguments; | ||
|
||
namespace EvoSC.Modules.Official.ServerManagementModule.Events.Args; | ||
|
||
public class PlayerSlotsChangedEventArgs : EvoScEventArgs | ||
{ | ||
public int NewSlots { get; init; } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Modules/ServerManagementModule/Events/ServerManagementAuditEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace EvoSC.Modules.Official.ServerManagementModule.Events; | ||
|
||
public enum ServerManagementAuditEvents | ||
{ | ||
PasswordSet, | ||
MaxPlayersSet, | ||
MaxSpectatorsSet | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Modules/ServerManagementModule/Events/ServerManagementEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace EvoSC.Modules.Official.ServerManagementModule.Events; | ||
|
||
public enum ServerManagementEvents | ||
{ | ||
PasswordChanged, | ||
MaxPlayersChanged, | ||
MaxSpectatorsChanged | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Modules/ServerManagementModule/Interfaces/IServerManagementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace EvoSC.Modules.Official.ServerManagementModule.Interfaces; | ||
|
||
public interface IServerManagementService | ||
{ | ||
public Task SetPasswordAsync(string password); | ||
public Task SetMaxPlayersAsync(int maxPlayers); | ||
public Task SetMaxSpectatorsAsync(int maxSpectators); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>1.3</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
</root> |
10 changes: 10 additions & 0 deletions
10
src/Modules/ServerManagementModule/Permissions/ServerManagementPermissions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using EvoSC.Common.Permissions.Attributes; | ||
|
||
namespace EvoSC.Modules.Official.ServerManagementModule.Permissions; | ||
|
||
[PermissionGroup] | ||
public enum ServerManagementPermissions | ||
{ | ||
SetPassword, | ||
SetMaxSlots | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using EvoSC.Modules.Attributes; | ||
|
||
namespace EvoSC.Modules.Official.ServerManagementModule; | ||
|
||
[Module(IsInternal = true)] | ||
public class ServerManagementModule : EvoScModule; |
25 changes: 25 additions & 0 deletions
25
src/Modules/ServerManagementModule/ServerManagementModule.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>EvoSC.Modules.Official.ServerManagementModule</RootNamespace> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<AssemblyName>ServerManagementModule</AssemblyName> | ||
<Title>Server Management</Title> | ||
<Description>Commands and functions to manage server configuration such as password, player slots etc.</Description> | ||
<Version>1.0.0</Version> | ||
<Authors>Evo</Authors> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Templates\**\*" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Update="Localization.resx" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="../../EvoSC.Modules.SourceGeneration/EvoSC.Modules.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="../../EvoSC.Modules/EvoSC.Modules.csproj" Private="true" /> | ||
</ItemGroup> | ||
|
||
</Project> |
34 changes: 34 additions & 0 deletions
34
src/Modules/ServerManagementModule/Services/ServerManagementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using EvoSC.Common.Interfaces; | ||
using EvoSC.Common.Services.Attributes; | ||
using EvoSC.Modules.Official.ServerManagementModule.Events; | ||
using EvoSC.Modules.Official.ServerManagementModule.Events.Args; | ||
using EvoSC.Modules.Official.ServerManagementModule.Interfaces; | ||
|
||
namespace EvoSC.Modules.Official.ServerManagementModule.Services; | ||
|
||
[Service] | ||
public class ServerManagementService(IServerClient serverClient, IEventManager events) : IServerManagementService | ||
{ | ||
public async Task SetPasswordAsync(string password) | ||
{ | ||
await serverClient.Remote.SetServerPasswordAsync(password); | ||
await serverClient.Remote.SetServerPasswordForSpectatorAsync(password); | ||
|
||
await events.RaiseAsync(ServerManagementEvents.PasswordChanged, | ||
new PasswordChangedEventArgs { NewPassword = password }); | ||
} | ||
|
||
public async Task SetMaxPlayersAsync(int maxPlayers) | ||
{ | ||
await serverClient.Remote.SetMaxPlayersAsync(maxPlayers); | ||
await events.RaiseAsync(ServerManagementEvents.MaxPlayersChanged, | ||
new PlayerSlotsChangedEventArgs() { NewSlots = maxPlayers }); | ||
} | ||
|
||
public async Task SetMaxSpectatorsAsync(int maxSpectators) | ||
{ | ||
await serverClient.Remote.SetMaxSpectatorsAsync(maxSpectators); | ||
await events.RaiseAsync(ServerManagementEvents.MaxSpectatorsChanged, | ||
new PlayerSlotsChangedEventArgs() { NewSlots = maxSpectators }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[info] | ||
# A unique name for this module, this is used as a identifier | ||
name = "ServerManagementModule" | ||
# The title of the module | ||
title = "Server Management" | ||
# A short description of what the module is and does | ||
summary = "Commands and functions to manage server configuration such as password, player slots etc." | ||
# The current version of this module, using SEMVER | ||
version = "1.0.0" | ||
# The name of the author that created this module | ||
author = "Evo" |
Oops, something went wrong.