Skip to content

Commit

Permalink
Fixes (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
snixtho authored Jul 27, 2024
1 parent f030022 commit 4604096
Show file tree
Hide file tree
Showing 44 changed files with 212 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/EvoSC.Common/Interfaces/Services/IAuditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IAuditService
/// <param name="comment">A comment or description of the event.</param>
/// <param name="properties">Any properties or values associated with the event.</param>
/// <returns></returns>
internal Task LogAsync(string eventName, AuditEventStatus status, IPlayer actor, string comment,
internal Task LogAsync(string eventName, AuditEventStatus status, IPlayer? actor, string comment,
dynamic? properties);

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions src/EvoSC.Common/Interfaces/Services/IMatchSettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using EvoSC.Common.Interfaces.Models;
using EvoSC.Common.Interfaces.Util;
using EvoSC.Common.Util.MatchSettings;
using EvoSC.Common.Util.MatchSettings.Builders;
using GbxRemoteNet.Exceptions;

Expand Down Expand Up @@ -90,4 +91,16 @@ public interface IMatchSettingsService
/// <exception cref="FileNotFoundException">Thrown if the match settings file was not found.</exception>
/// <returns></returns>
public Task DeleteMatchSettingsAsync(string name);

/// <summary>
/// Get the name of the current mode script.
/// </summary>
/// <returns></returns>
public Task<string> GetCurrentScriptNameAsync();

/// <summary>
/// Get the mode of the current match settings.
/// </summary>
/// <returns></returns>
public Task<DefaultModeScriptName> GetCurrentModeAsync();
}
7 changes: 4 additions & 3 deletions src/EvoSC.Common/Services/AuditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using EvoSC.Common.Interfaces.Services;
using EvoSC.Common.Interfaces.Util.Auditing;
using EvoSC.Common.Models.Audit;
using EvoSC.Common.Util;
using EvoSC.Common.Util.Auditing;
using EvoSC.Common.Util.EnumIdentifier;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -37,17 +38,17 @@ private void LogLogger(DbAuditRecord auditRecord)
);
}

async Task IAuditService.LogAsync(string eventName, AuditEventStatus status, IPlayer actor, string comment,
async Task IAuditService.LogAsync(string eventName, AuditEventStatus status, IPlayer? actor, string comment,
dynamic? properties)
{
var serializedData = properties != null ? JsonSerializer.Serialize(properties) : null;

var auditRecord = new DbAuditRecord
{
Status = status,
Actor = new DbPlayer(actor),
Actor = actor == null ? null : new DbPlayer(actor),
CreatedAt = DateTime.UtcNow,
ActorId = actor.Id,
ActorId = actor?.Id ?? 0,
EventName = eventName,
Comment = comment,
Properties = serializedData
Expand Down
15 changes: 14 additions & 1 deletion src/EvoSC.Common/Services/MatchSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using EvoSC.Common.Interfaces.Util;
using EvoSC.Common.Models.Maps;
using EvoSC.Common.Util;
using EvoSC.Common.Util.EnumIdentifier;
using EvoSC.Common.Util.MatchSettings;
using EvoSC.Common.Util.MatchSettings.Builders;
using GbxRemoteNet.Exceptions;
Expand Down Expand Up @@ -108,7 +109,19 @@ public async Task DeleteMatchSettingsAsync(string name)
var filePath = await GetFilePathAsync(name);
File.Delete(filePath);
}


public async Task<string> GetCurrentScriptNameAsync()
{
var scriptInfo = await server.Remote.GetModeScriptInfoAsync();
return scriptInfo.Name;
}

public async Task<DefaultModeScriptName> GetCurrentModeAsync()
{
var scriptName = await GetCurrentScriptNameAsync();
return scriptName.ToEnumValue<DefaultModeScriptName>() ?? DefaultModeScriptName.Unknown;
}

private async Task<string> GetFilePathAsync(string name)
{
var mapsDir = await server.GetMapsDirectoryAsync();
Expand Down
2 changes: 2 additions & 0 deletions src/EvoSC.Common/Util/MatchSettings/DefaultModeScriptName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public enum DefaultModeScriptName
Laps,

[Identifier(Name = "Trackmania/TM_Knockout_Online.Script.txt", NoPrefix = true)]
[Alias(Name = "ko")]
Knockout,

[Identifier(Name = "Trackmania/TM_TMWTTeams_Online.Script.txt", NoPrefix = true)]
[Alias(Name = "tmwt")]
TmwtTeams,

/// <summary>
Expand Down
64 changes: 1 addition & 63 deletions src/EvoSC.Manialinks/Templates/Containers/Window.mt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ The window is designed to only be used once per Manialink.
y="-1.6"
data="{{ id }}"
size="small"
if="canClose"
/>

<!-- Body Contents -->
Expand All @@ -121,69 +122,6 @@ The window is designed to only be used once per Manialink.
>
<slot />
</Container>

<!-- Window Header -->
<!-- <quad
class="window-bg"
size="{{ width }} {{ height }}"
scriptevents="1"
/>

<quad
class="window-header evosc-window-header evosc-window"
size="{{ width }} {{ 5 }}"
if="hasTitlebar"
/>

<label
class="window-title evosc-window"
valign="center"
text="{{ icon }}"
size="{{ width-1.5 }} 5"
pos="1.5 -2.2"
if='hasTitlebar &amp;&amp; icon != ""'
/>

<label
class="window-title-{{ style }} evosc-window"
valign="center"
text="{{ title.ToUpper() }}"
size='{{ width-1.5 }} 5'
pos='{{ icon != "" ? 5.5 : 1.5 }} -2.2'
if="hasTitlebar"
/>

<label
class="window-closebtn-{{ style }} evosc-window-closebtn evosc-window-ctrlbtn"
data-id="{{ id }}"
valign="center"
text="❌"
size="5 5"
pos="{{ width-4.5 }} -2.2"
scriptevents="1"
if="hasTitlebar &amp;&amp; canClose"
/>

<label
class="window-minimizebtn-{{ style }} evosc-window-minimizebtn evosc-window-ctrlbtn"
data-id="{{ id }}"
valign="center"
text="—"
size="5 5"
pos="{{ width - 4.5 - (canClose ? 4 : 0) }} -2.2"
scriptevents="1"
if="hasTitlebar &amp;&amp; canMinimize"
/>

<Container
x="{{ padding }}"
y="-{{ hasTitlebar ? 5+padding : padding }}"
width="{{ width-padding*2 }}"
height="{{ height-(hasTitlebar ? 5+padding*2 : padding*2) }}"
scrollable="false"
>
<slot />
</Container> -->
</frame>
</template>

Expand Down
4 changes: 4 additions & 0 deletions src/EvoSC.Testing/EvoSC.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.15.0.81779">
<PrivateAssets>all</PrivateAssets>
Expand Down
6 changes: 3 additions & 3 deletions src/EvoSC/InternalModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ namespace EvoSC;
public static class InternalModules
{
public static readonly Type[] Modules =
{
[
//typeof(ExampleModule),
typeof(PlayerModule),
typeof(ExampleModule),
typeof(MapsModule),
typeof(WorldRecordModule),
typeof(PlayerRecordsModule),
Expand All @@ -56,7 +56,7 @@ public static class InternalModules
typeof(LocalRecordsModule),
typeof(ForceTeamModule),
typeof(TeamSettingsModule)
};
];

/// <summary>
/// Run any migrations from all the modules.
Expand Down
10 changes: 3 additions & 7 deletions src/Modules/ExampleModule/ExampleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ public async Task RateMap(int rating)
[ChatCommand("test", "Some testing.")]
public async Task TestCommand()
{
var mapList = await _server.Remote.GetMapListAsync(-1, 0);

var maps = new List<IMap>();
foreach (var map in mapList)
{
maps.Add(await _mapService.GetMapByUidAsync(map.UId));
}
var mode = await _matchSettings.GetCurrentModeAsync();

Console.WriteLine(mode);
}

[ChatCommand("rejoin", "Simulates the player joining the server.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@ public async Task OnPlayerConnectAsync(object sender, PlayerConnectGbxEventArgs
public Task OnBeginMapAsync(object sender, MapGbxEventArgs args) => localRecords.ShowWidgetToAllAsync();

[Subscribe(PlayerRecordsEvent.PbRecord)]
public Task OnPbAsync(object sender, PbRecordUpdateEventArgs args) => localRecords.UpdatePbAsync(args.Record);
public Task OnPbAsync(object sender, PbRecordUpdateEventArgs args)
{
if (args.Status == RecordUpdateStatus.NotUpdated)
{
return Task.CompletedTask;
}

return localRecords.UpdatePbAsync(args.Record);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ await NewLoadAll()

public async Task<DbLocalRecord?> GetRecordOfPlayerInMapAsync(IPlayer player, IMap map) =>
await NewLoadAll()
.FirstOrDefaultAsync(r => r.DbRecord.DbPlayer.Id == player.Id);
.FirstOrDefaultAsync(r => r.DbRecord.DbPlayer.Id == player.Id && r.DbMap.Id == map.Id);

public async Task DeleteRecordAsync(IPlayer player, IMap map)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ await server.InfoMessageAsync(new TextFormatter()
.ToString());
await ShowWidgetToAllAsync();
}
else if (record.Score == oldRecord.Record.Score)
else if (record.Score == localRecord.Record.Score)
{
await server.InfoMessageAsync(new TextFormatter()
.AddText(record.Player.NickName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Config.Net;
using EvoSC.Modules.Attributes;
using EvoSC.Modules.Official.OpenPlanetModule.Models;
using LinqToDB.Common;

namespace EvoSC.Modules.Official.OpenPlanetModule.Config;

Expand Down Expand Up @@ -29,6 +30,12 @@ public interface IOpenPlanetControlSettings
[Option(DefaultValue = true), Description("Allow the use of openplanet. If false, no signature mode is allowed.")]
public bool AllowOpenplanet { get; set; }

[Option(DefaultValue = "1.25.45"), Description("The minimum required OpenPlanet version to play on this server.")]
[Option(DefaultValue = "1.26.25"), Description("The minimum required OpenPlanet version to play on this server.")]
public Version MinimumRequiredVersion { get; set; }

[Option(DefaultValue = true), Description("Enable auditing of all checks.")]
public bool AuditAllChecks { get; set; }

[Option(DefaultValue = true), Description("Enable auditing of players that got jailed.")]
public bool AuditJails { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using EvoSC.Common.Util;
using EvoSC.Manialinks;
using EvoSC.Manialinks.Attributes;
using EvoSC.Modules.Official.OpenPlanetModule.Config;
using EvoSC.Modules.Official.OpenPlanetModule.Events;
using EvoSC.Modules.Official.OpenPlanetModule.Interfaces;
using EvoSC.Modules.Official.OpenPlanetModule.Interfaces.Models;

Expand All @@ -11,7 +13,7 @@ namespace EvoSC.Modules.Official.OpenPlanetModule.Controllers;
[Controller]
[ManialinkRoute(Route = "OpenPlanetActions")]
public class OpenPlanetControlManialinkController(IOpenPlanetControlService opControl, IServerClient server,
IOpenPlanetTrackerService trackerService)
IOpenPlanetTrackerService trackerService, IOpenPlanetScheduler scheduler)
: ManialinkController
{
public async Task CheckAsync(IOpenPlanetInfo openPlanetInfo)
Expand All @@ -20,5 +22,13 @@ public async Task CheckAsync(IOpenPlanetInfo openPlanetInfo)
trackerService.AddOrUpdatePlayer(Context.Player, openPlanetInfo);
}

public Task DisconnectAsync() => server.Remote.KickAsync(Context.Player.GetLogin());
public async Task DisconnectAsync()
{
await server.Remote.KickAsync(Context.Player.GetLogin());

if (scheduler.PlayerIsScheduledForKick(Context.Player))
{
scheduler.UnScheduleKickPlayer(Context.Player);
}
}
}
12 changes: 12 additions & 0 deletions src/Modules/OpenPlanetModule/Events/OpAuditEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using EvoSC.Common.Util.EnumIdentifier;

namespace EvoSC.Modules.Official.OpenPlanetModule.Events;

public enum OpAuditEvents
{
[Identifier(Name = "OpenPlanet:SignatureModeCheck")]
SignatureModeCheck,

[Identifier(Name = "OpenPlanet:PlayerJailed")]
PlayerJailed
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EvoSC.Common.Util;
using EvoSC.Manialinks.Interfaces;
using EvoSC.Modules.Official.OpenPlanetModule.Config;
using EvoSC.Modules.Official.OpenPlanetModule.Events;
using EvoSC.Modules.Official.OpenPlanetModule.Interfaces;
using EvoSC.Modules.Official.OpenPlanetModule.Interfaces.Models;
using EvoSC.Modules.Official.OpenPlanetModule.Models;
Expand All @@ -18,7 +19,7 @@ namespace EvoSC.Modules.Official.OpenPlanetModule.Services;
public class OpenPlanetControlService(ILogger<OpenPlanetControlService> logger, IPermissionManager permissions,
IOpenPlanetControlSettings opcSettings, IManialinkManager manialinks, IServerClient server,
IOpenPlanetScheduler scheduler,
Locale locale)
Locale locale, IAuditService auditService)
: IOpenPlanetControlService
{
private readonly dynamic _locale = locale;
Expand All @@ -27,6 +28,15 @@ public async Task VerifySignatureModeAsync(IPlayer player, IOpenPlanetInfo playe
{
logger.LogDebug("Verifying OpenPlanet for Player {Player}", player.AccountId);

if (opcSettings.AuditAllChecks)
{
await auditService.NewEvent(OpAuditEvents.SignatureModeCheck)
.HavingProperties(new { Player = player, OpenPlanetData = playerOpInfo })
.Comment("OpenPlanet state checked for player.")
.Info()
.LogAsync();
}

if (!playerOpInfo.IsOpenPlanet)
{
await ReleasePlayerAsync(player);
Expand Down Expand Up @@ -74,6 +84,14 @@ public async Task VerifySignatureModeAsync(IPlayer player, IOpenPlanetInfo playe

private async Task JailPlayerAsync(IPlayer player, OpJailReason reason)
{
if (opcSettings.AuditJails)
{
await auditService.NewEvent(OpAuditEvents.PlayerJailed)
.HavingProperties(new { Player = player, Reason = reason })
.Success()
.LogAsync("Player jailed.");
}

if (scheduler.PlayerIsScheduledForKick(player))
{
return;
Expand Down
7 changes: 5 additions & 2 deletions src/Modules/OpenPlanetModule/Templates/DetectOP.mt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@

*** OnLoop ***
***
if (lastTime + {{ config.CheckInterval }} <= Now && lastToolInfo != System.ExtraTool_Info) {
CheckOpenPlanet();
if (lastTime + {{ config.CheckInterval }} <= Now) {
if (lastToolInfo != System.ExtraTool_Info) {
CheckOpenPlanet();
}

lastTime = Now;
lastToolInfo = System.ExtraTool_Info;
}
Expand Down
Loading

0 comments on commit 4604096

Please sign in to comment.