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

Fixing XPEvo related bugfix #203

Closed
wants to merge 9 commits into from
5 changes: 5 additions & 0 deletions src/EvoSC.Common/Database/MigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EvoSC.Common.Logging;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Generators;
using FluentMigrator.Runner.Initialization;
using Microsoft.Extensions.DependencyInjection;

namespace EvoSC.Common.Database;
Expand All @@ -31,6 +32,10 @@ public void MigrateFromAssembly(Assembly asm)
.Configure<SelectingGeneratorAccessorOptions>(x =>
x.GeneratorId = GetDatabaseTypeIdentifier(_config.Database.Type))
.AddEvoScLogging(_config.Logging)
.Configure<RunnerOptions>(opt =>
{
opt.Tags = new[] { "Production", "XPEvo" };
})
.BuildServiceProvider(false);

provider.GetRequiredService<IMigrationRunner>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1665390396)]
public class AddPlayersTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1666859869)]
public class AddConfigOptionsTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1668338922)]
public class AddMapsTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1668492589)]
public class AddUserPermissionTables : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1675849925)]
public class AddAuditLogTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1687252035)]
public class AddPlayerSettingsTable : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1689575375)]
public class UpdateAuditLogTableDataTypes : Migration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1694073143)]
public class UpdateConfigOptionsTable : Migration
{
Expand Down
51 changes: 51 additions & 0 deletions src/EvoSC.Common/Database/Migrations/202309211312_XPEvoValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using EvoSC.Common.Database.Models.Permissions;
using EvoSC.Common.Database.Models.Player;
using EvoSC.Common.Interfaces.Models;
using FluentMigrator;

namespace EvoSC.Common.Database.Migrations;

[Tags("XPEvo", "Production")]
[Migration(1695294772)]
public class XPEvoValues : Migration
{
public override void Up()
{

Execute.Sql("INSERT INTO \"Groups\" (\"Id\", \"Title\", \"Description\", \"Icon\", \"Color\", \"Unrestricted\") VALUES (1, 'Admin', 'Admin', '', '', true)");

// Insert.IntoTable(""Players"").Row("Players");

Execute.Sql("""
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (2, NOW(), NOW(), NOW(), 'b792256a-912b-461c-9f8d-662a040a15ce', 'Karlukki', 'Karlukki', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (3, NOW(), NOW(), NOW(), '18c0c4e6-989a-4aef-b619-6313654f8f48', 'Roxiie', 'Roxiie', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (4, NOW(), NOW(), NOW(), '8e8ea58e-72b1-42eb-bd63-8183bf3add50', 'DoogiieMD', 'DoogiieMD', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (5, NOW(), NOW(), NOW(), '7599d4de-2ced-46d0-abf6-91612e1dca30', 'speq.x', 'speq.x', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (6, NOW(), NOW(), NOW(), '085e1d24-7d55-496d-ad7a-1eb1efec09eb', 'Keissla', 'Keissla', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (7, NOW(), NOW(), NOW(), '6a79abb8-0ffc-4d93-a6e7-2087cc2fd27a', 'Evo.Atomic', 'Evo.Atomic', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (8, NOW(), NOW(), NOW(), '06a503ae-f6da-430b-8d75-901e1302dfb5', 'XLRB.', 'XLRB.', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (9, NOW(), NOW(), NOW(), '39a38ee1-e0a0-49a0-93f5-8024cf1b7f9b', 'Evo.Braker', 'Evo.Braker', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (10, NOW(), NOW(), NOW(), '17868d60-b494-4b88-81df-f4ddfdae1cf1', 'Evo.Chris92', 'Evo.Chris92', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (11, NOW(), NOW(), NOW(), '2496fef1-fed2-44e4-9930-189f46496526', 'ItsPhenom', 'ItsPhenom', '');
INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone")
VALUES (12, NOW(), NOW(), NOW(), '07c8ae36-fdd3-4685-8050-ba44124dc7e7', 'Biscione156', 'Biscione156', '');
""");

Execute.Sql("INSERT INTO \"UserGroups\" (\"UserId\", \"GroupId\", \"Display\")\nVALUES (6, 1, true), (7, 1, true), (8, 1, true), (9, 1, true), (10, 1, true), (11, 1, true)");
}

public override void Down()
{

}
}
2 changes: 1 addition & 1 deletion src/EvoSC.Common/EvoSC.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="GBX.NET" Version="1.1.0" />
<PackageReference Include="GbxRemote.Net" Version="4.1.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="linq2db" Version="4.4.0" />
<PackageReference Include="linq2db" Version="4.4.1" />
<PackageReference Include="linq2db.MySql" Version="4.4.0" />
<PackageReference Include="linq2db.PostgreSQL" Version="4.4.0" />
<PackageReference Include="linq2db.SQLite" Version="4.4.0" />
Expand Down
10 changes: 10 additions & 0 deletions src/EvoSC.Common/Interfaces/Models/IPlayerSpectatorStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace EvoSC.Common.Interfaces.Models;

public interface IPlayerSpectatorStatus
{
public bool IsSpectator { get; }
public bool IsTemporarySpectator { get; }
public bool IsPureSpectator { get; }
public bool AutoTarget { get; }
public int CurrentTargetId { get; }
}
12 changes: 12 additions & 0 deletions src/EvoSC.Common/Models/Players/PlayerSpectatorStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using EvoSC.Common.Interfaces.Models;

namespace EvoSC.Common.Models.Players;

public class PlayerSpectatorStatus : IPlayerSpectatorStatus
{
public required bool IsSpectator { get; init; }
public required bool IsTemporarySpectator { get; init; }
public required bool IsPureSpectator { get; init; }
public required bool AutoTarget { get; init; }
public required int CurrentTargetId { get; init; }
}
8 changes: 6 additions & 2 deletions src/EvoSC.Testing/Database/TestDbMigrations.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Reflection;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Initialization;
using Microsoft.Extensions.DependencyInjection;

namespace EvoSC.Testing.Database;
Expand All @@ -19,8 +20,11 @@ public static void MigrateFromAssembly(string connectionString, Assembly asm)
.AddSQLite()
.WithGlobalConnectionString(connectionString)
.ScanIn(asm).For.Migrations()
)
.BuildServiceProvider();
).Configure<RunnerOptions>(opt =>
{
opt.Tags = new[] { "Production" };
})
.BuildServiceProvider(false);

var runner = sp.GetRequiredService<IMigrationRunner>();
runner.MigrateUp();
Expand Down
1 change: 1 addition & 0 deletions src/EvoSC/EvoSC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="linq2db" Version="4.4.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.5.0.73987">
Expand Down
19 changes: 19 additions & 0 deletions src/Modules/LiveRankingModule/Services/LiveRankingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public async Task OnEnableAsync()
{
_logger.LogTrace("LiveRankingModule enabled");
await CheckIsRoundsModeAsync();
await HideNadeoScoreboard();
if (_isRoundsMode)
{
await _liveRankingStore.ResetLiveRankingsAsync();
Expand Down Expand Up @@ -222,6 +223,24 @@ public async Task OnPodiumStartAsync(PodiumEventArgs args)
await CheckIsRoundsModeAsync();
await HideManialink();
}

public async Task HideNadeoScoreboard()
{
var hudSettings = new List<string>()
{
@"{
""uimodules"": [
{
""id"": ""Rounds_SmallScoresTable"",
""visible"": false,
""visible_update"": true
}
]
}"
};

await _client.Remote.TriggerModeScriptEventArrayAsync("Common.UIModules.SetProperties", hudSettings.ToArray());
}

private async Task HideManialink()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using EvoSC.Common.Models;
using EvoSC.Common.Remote;
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Common.Util;
using EvoSC.Modules.Official.MatchRankingModule.Interfaces;
using GbxRemoteNet.Events;

namespace EvoSC.Modules.Official.MatchRankingModule.Controllers;

Expand Down Expand Up @@ -35,19 +37,31 @@ public async Task OnScores(object data, ScoresEventArgs eventArgs)
[Subscribe(ModeScriptEvent.StartRoundStart)]
public async Task OnBeginMapAsync(object sender, RoundEventArgs args)
{
await _matchRankingService.SendManialink();
await _matchRankingService.SendManialinkToPlayers();
}

[Subscribe(ModeScriptEvent.StartMatchStart)]
public async Task OnStartMatch(object sender, MatchEventArgs eventArgs)
public async Task OnStartMatch(object sender, MatchEventArgs args)
{
await _matchRankingService.ResetMatchData();
await _matchRankingService.SendManialink();
await _matchRankingService.SendManialinkToPlayers();
}

[Subscribe(ModeScriptEvent.PodiumStart)]
public async Task OnPodiumStart(object sender, PodiumEventArgs args)
{
await _matchRankingService.HideManialink();
}

[Subscribe(GbxRemoteEvent.PlayerInfoChanged)]
public async Task OnPlayerInfoChanged(object sender, PlayerInfoChangedGbxEventArgs args)
{
await _matchRankingService.HandlePlayerStateChange(PlayerUtils.ConvertLoginToAccountId(args.PlayerInfo.Login));
}

[Subscribe(GbxRemoteEvent.PlayerConnect)]
public async Task OnPlayerConnect(object sender, PlayerConnectGbxEventArgs args)
{
await _matchRankingService.SendManialinkToPlayer(PlayerUtils.ConvertLoginToAccountId(args.Login));
}
}
15 changes: 13 additions & 2 deletions src/Modules/MatchRankingModule/Interfaces/IMatchRankingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ public interface IMatchRankingService
/// <returns></returns>
Task UpdateAndShowScores(ScoresEventArgs scores);
/// <summary>
/// Send the manialink to all players.
/// Send the manialink to spectating players.
/// </summary>
/// <returns></returns>
Task SendManialink();
Task SendManialinkToPlayers();
/// <summary>
/// Send the manialink to spectating player.
/// </summary>
/// <returns></returns>
Task SendManialinkToPlayer(string accountId);
/// <summary>
/// Hide the manialink for all players.
/// </summary>
Expand All @@ -24,4 +29,10 @@ public interface IMatchRankingService
/// </summary>
/// <returns></returns>
Task ResetMatchData();

/// <sumamry>
/// Handles a player state change, e.g. the player switches from spectator to playing or vice versa.
/// </summary>
/// <returns></returns>
Task HandlePlayerStateChange(string accountId);
}
2 changes: 1 addition & 1 deletion src/Modules/MatchRankingModule/MatchRankingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public MatchRankingModule(IMatchRankingService matchRankingService)
_matchRankingService = matchRankingService;
}

public Task EnableAsync() => _matchRankingService.SendManialink();
public Task EnableAsync() => _matchRankingService.SendManialinkToPlayers();

public Task DisableAsync() => _matchRankingService.HideManialink();
}
Loading