From ddfbfd745b46bc2aa7117417180e452bdd56aa31 Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:08:16 +0200 Subject: [PATCH 01/12] fix matchtracker module tests being in the wrong directory --- EvoSC.sln | 14 +++++++------- .../MatchTrackerEventControllerTests.cs | 0 .../MatchTrackerModule.Tests.csproj | 8 ++++++-- .../Repository/MatchRecordRepositoryTests.cs | 0 .../Stores/DatabaseMatchTrackerStoreTests.cs | 0 .../Modules/MatchTrackerModule.Tests}/UnitTest1.cs | 0 .../Modules/MatchTrackerModule.Tests}/Usings.cs | 0 .../Util/MatchStateUtilsTests.cs | 0 8 files changed, 13 insertions(+), 9 deletions(-) rename {MatchTrackerModule.Tests => tests/Modules/MatchTrackerModule.Tests}/Controllers/MatchTrackerEventControllerTests.cs (100%) rename {MatchTrackerModule.Tests => tests/Modules/MatchTrackerModule.Tests}/MatchTrackerModule.Tests.csproj (72%) rename {MatchTrackerModule.Tests => tests/Modules/MatchTrackerModule.Tests}/Repository/MatchRecordRepositoryTests.cs (100%) rename {MatchTrackerModule.Tests => tests/Modules/MatchTrackerModule.Tests}/Stores/DatabaseMatchTrackerStoreTests.cs (100%) rename {MatchTrackerModule.Tests => tests/Modules/MatchTrackerModule.Tests}/UnitTest1.cs (100%) rename {MatchTrackerModule.Tests => tests/Modules/MatchTrackerModule.Tests}/Usings.cs (100%) rename {MatchTrackerModule.Tests => tests/Modules/MatchTrackerModule.Tests}/Util/MatchStateUtilsTests.cs (100%) diff --git a/EvoSC.sln b/EvoSC.sln index 22416ce54..e03f2ca6e 100644 --- a/EvoSC.sln +++ b/EvoSC.sln @@ -84,8 +84,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchTrackerModule", "src\M EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchReadyModule", "src\Modules\MatchReadyModule\MatchReadyModule.csproj", "{0538B9AB-B556-45BF-8230-53087BA9D353}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchTrackerModule.Tests", "MatchTrackerModule.Tests\MatchTrackerModule.Tests.csproj", "{1EBEC855-5BF7-43D3-BABF-A09343B8693A}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeardownModule", "src\Modules\GeardownModule\GeardownModule.csproj", "{D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XPEvoAdminControl", "src\Modules\XPEvoAdminControl\XPEvoAdminControl.csproj", "{D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9}" @@ -110,6 +108,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModuleManagerModule", "src\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SponsorsModule", "src\Modules\SponsorsModule\SponsorsModule.csproj", "{1F628FDD-289C-48C3-B736-B5A13D7EC9F2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchTrackerModule.Tests", "tests\Modules\MatchTrackerModule.Tests\MatchTrackerModule.Tests.csproj", "{9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -286,10 +286,6 @@ Global {0538B9AB-B556-45BF-8230-53087BA9D353}.Debug|Any CPU.Build.0 = Debug|Any CPU {0538B9AB-B556-45BF-8230-53087BA9D353}.Release|Any CPU.ActiveCfg = Release|Any CPU {0538B9AB-B556-45BF-8230-53087BA9D353}.Release|Any CPU.Build.0 = Release|Any CPU - {1EBEC855-5BF7-43D3-BABF-A09343B8693A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1EBEC855-5BF7-43D3-BABF-A09343B8693A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1EBEC855-5BF7-43D3-BABF-A09343B8693A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1EBEC855-5BF7-43D3-BABF-A09343B8693A}.Release|Any CPU.Build.0 = Release|Any CPU {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -318,6 +314,10 @@ Global {1F628FDD-289C-48C3-B736-B5A13D7EC9F2}.Debug|Any CPU.Build.0 = Debug|Any CPU {1F628FDD-289C-48C3-B736-B5A13D7EC9F2}.Release|Any CPU.ActiveCfg = Release|Any CPU {1F628FDD-289C-48C3-B736-B5A13D7EC9F2}.Release|Any CPU.Build.0 = Release|Any CPU + {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -361,7 +361,6 @@ Global {A533CF48-1BE5-4F0E-A636-941ED63DF9ED} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} {CBE9F195-758F-470D-B3BF-6B012C8216CC} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {0538B9AB-B556-45BF-8230-53087BA9D353} = {DC47658A-F421-4BA4-B617-090A7DFB3900} - {1EBEC855-5BF7-43D3-BABF-A09343B8693A} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {570CEDDA-7EBC-486D-BD5D-0A1C39DD69F8} = {DC47658A-F421-4BA4-B617-090A7DFB3900} @@ -369,5 +368,6 @@ Global {42BCE01C-EBEF-4DB6-A61C-35B63C915AD3} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} {65F795D5-058D-4F8D-B8E0-BE3F64E14CDF} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {1F628FDD-289C-48C3-B736-B5A13D7EC9F2} = {DC47658A-F421-4BA4-B617-090A7DFB3900} + {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} EndGlobalSection EndGlobal diff --git a/MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs b/tests/Modules/MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs similarity index 100% rename from MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs rename to tests/Modules/MatchTrackerModule.Tests/Controllers/MatchTrackerEventControllerTests.cs diff --git a/MatchTrackerModule.Tests/MatchTrackerModule.Tests.csproj b/tests/Modules/MatchTrackerModule.Tests/MatchTrackerModule.Tests.csproj similarity index 72% rename from MatchTrackerModule.Tests/MatchTrackerModule.Tests.csproj rename to tests/Modules/MatchTrackerModule.Tests/MatchTrackerModule.Tests.csproj index 2635639dc..53a65a8d3 100644 --- a/MatchTrackerModule.Tests/MatchTrackerModule.Tests.csproj +++ b/tests/Modules/MatchTrackerModule.Tests/MatchTrackerModule.Tests.csproj @@ -23,10 +23,14 @@ + + + + - - + + diff --git a/MatchTrackerModule.Tests/Repository/MatchRecordRepositoryTests.cs b/tests/Modules/MatchTrackerModule.Tests/Repository/MatchRecordRepositoryTests.cs similarity index 100% rename from MatchTrackerModule.Tests/Repository/MatchRecordRepositoryTests.cs rename to tests/Modules/MatchTrackerModule.Tests/Repository/MatchRecordRepositoryTests.cs diff --git a/MatchTrackerModule.Tests/Stores/DatabaseMatchTrackerStoreTests.cs b/tests/Modules/MatchTrackerModule.Tests/Stores/DatabaseMatchTrackerStoreTests.cs similarity index 100% rename from MatchTrackerModule.Tests/Stores/DatabaseMatchTrackerStoreTests.cs rename to tests/Modules/MatchTrackerModule.Tests/Stores/DatabaseMatchTrackerStoreTests.cs diff --git a/MatchTrackerModule.Tests/UnitTest1.cs b/tests/Modules/MatchTrackerModule.Tests/UnitTest1.cs similarity index 100% rename from MatchTrackerModule.Tests/UnitTest1.cs rename to tests/Modules/MatchTrackerModule.Tests/UnitTest1.cs diff --git a/MatchTrackerModule.Tests/Usings.cs b/tests/Modules/MatchTrackerModule.Tests/Usings.cs similarity index 100% rename from MatchTrackerModule.Tests/Usings.cs rename to tests/Modules/MatchTrackerModule.Tests/Usings.cs diff --git a/MatchTrackerModule.Tests/Util/MatchStateUtilsTests.cs b/tests/Modules/MatchTrackerModule.Tests/Util/MatchStateUtilsTests.cs similarity index 100% rename from MatchTrackerModule.Tests/Util/MatchStateUtilsTests.cs rename to tests/Modules/MatchTrackerModule.Tests/Util/MatchStateUtilsTests.cs From 0f020708c07a836a64d3894ff8883b39c8829da9 Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:12:17 +0200 Subject: [PATCH 02/12] remove xpevo specific modules --- EvoSC.sln | 14 - src/EvoSC/EvoSC.csproj | 2 - .../Controllers/EventsController.cs | 86 ----- .../Controllers/GeardownCommandsController.cs | 79 ---- src/Modules/GeardownModule/GeardownModule.cs | 13 - .../GeardownModule/GeardownModule.csproj | 45 --- .../Interfaces/IGeardownMatchState.cs | 16 - .../Interfaces/IGeardownService.cs | 39 -- .../Interfaces/IGeardownSetupService.cs | 19 - .../Interfaces/IMatchManagementService.cs | 33 -- .../Repositories/IGeardownEventApi.cs | 12 - .../Repositories/IGeardownGroupApi.cs | 13 - .../Repositories/IGeardownMatchApi.cs | 49 --- .../ITourneyTimelineRepository.cs | 12 - .../Services/IGeardownApiService.cs | 11 - .../Services/IGeardownSetupStateService.cs | 40 -- src/Modules/GeardownModule/Localization.resx | 24 -- ...2309160959_AddGeardownMatchRecordsTable.cs | 20 - .../GeardownModule/Models/API/GdFormat.cs | 12 - .../GeardownModule/Models/API/GdGameServer.cs | 13 - .../GeardownModule/Models/API/GdGroup.cs | 17 - .../Models/API/GdMapPoolOrder.cs | 10 - .../GeardownModule/Models/API/GdMatch.cs | 20 - .../Models/API/GdMatchResult.cs | 12 - .../Models/API/GdMatchSetting.cs | 9 - .../GeardownModule/Models/API/GdMatchToken.cs | 12 - .../Models/API/GdOnEndMapRequest.cs | 6 - .../Models/API/GdOnEndRoundRequest.cs | 9 - .../Models/API/GdOnStartMatchRequest.cs | 7 - .../GeardownModule/Models/API/GdPage.cs | 5 - .../Models/API/GdParticipant.cs | 13 - .../GeardownModule/Models/API/GdResult.cs | 7 - .../GeardownModule/Models/API/GdResults.cs | 7 - .../GeardownModule/Models/API/GdUser.cs | 12 - .../Models/Database/DbGeardownMatchRecord.cs | 15 - .../GeardownModule/Models/EventStatus.cs | 8 - .../GeardownModule/Models/FormatType.cs | 12 - .../Models/GeardownMatchState.cs | 10 - .../GeardownModule/Models/MatchStatus.cs | 8 - .../Permissions/GeardownPermissions.cs | 23 -- .../Repositories/GeardownApiBase.cs | 24 -- .../Repositories/GeardownEventApi.cs | 27 -- .../Repositories/GeardownGroupApi.cs | 35 -- .../Repositories/GeardownMatchApi.cs | 94 ----- .../Repositories/TourneyTimelineRepository.cs | 20 - .../Services/GeardownApiService.cs | 20 - .../Services/GeardownService.cs | 142 ------- .../Services/GeardownSetupService.cs | 354 ------------------ .../Services/GeardownSetupStateService.cs | 106 ------ .../Services/MatchManagementService.cs | 40 -- .../Settings/IGeardownSettings.cs | 28 -- .../Util/MatchSettingsTypeUtils.cs | 39 -- src/Modules/GeardownModule/info.toml | 11 - .../Controllers/AdminCpComController.cs | 107 ------ .../XPEvoAdminControl/Events/AdminCpEvents.cs | 6 - .../Events/EventArgs/CpComActionEventArgs.cs | 8 - .../Interfaces/CpCom/ICpAction.cs | 10 - .../Interfaces/ICpComService.cs | 11 - .../Interfaces/IProblemService.cs | 10 - .../XPEvoAdminControl/Localization.resx | 24 -- .../Models/CpCom/CpAction.cs | 10 - .../Models/Dto/CpActionAssignServerDto.cs | 6 - .../Models/MatchServerStatus.cs | 12 - .../Services/CpComBackgroundService.cs | 97 ----- .../Services/CpComService.cs | 89 ----- .../Services/ProblemService.cs | 36 -- .../Settings/IXPEvoAdminSettings.cs | 12 - .../XPEvoAdminControl/XPEvoAdminControl.cs | 8 - .../XPEvoAdminControl.csproj | 34 -- src/Modules/XPEvoAdminControl/info.toml | 9 - 70 files changed, 2203 deletions(-) delete mode 100644 src/Modules/GeardownModule/Controllers/EventsController.cs delete mode 100644 src/Modules/GeardownModule/Controllers/GeardownCommandsController.cs delete mode 100644 src/Modules/GeardownModule/GeardownModule.cs delete mode 100644 src/Modules/GeardownModule/GeardownModule.csproj delete mode 100644 src/Modules/GeardownModule/Interfaces/IGeardownMatchState.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/IGeardownService.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/IGeardownSetupService.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/IMatchManagementService.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/Repositories/IGeardownEventApi.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/Repositories/IGeardownGroupApi.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/Repositories/IGeardownMatchApi.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/Repositories/ITourneyTimelineRepository.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/Services/IGeardownApiService.cs delete mode 100644 src/Modules/GeardownModule/Interfaces/Services/IGeardownSetupStateService.cs delete mode 100644 src/Modules/GeardownModule/Localization.resx delete mode 100644 src/Modules/GeardownModule/Migrations/202309160959_AddGeardownMatchRecordsTable.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdFormat.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdGameServer.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdGroup.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdMapPoolOrder.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdMatch.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdMatchResult.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdMatchSetting.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdMatchToken.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdOnEndMapRequest.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdOnEndRoundRequest.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdOnStartMatchRequest.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdPage.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdParticipant.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdResult.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdResults.cs delete mode 100644 src/Modules/GeardownModule/Models/API/GdUser.cs delete mode 100644 src/Modules/GeardownModule/Models/Database/DbGeardownMatchRecord.cs delete mode 100644 src/Modules/GeardownModule/Models/EventStatus.cs delete mode 100644 src/Modules/GeardownModule/Models/FormatType.cs delete mode 100644 src/Modules/GeardownModule/Models/GeardownMatchState.cs delete mode 100644 src/Modules/GeardownModule/Models/MatchStatus.cs delete mode 100644 src/Modules/GeardownModule/Permissions/GeardownPermissions.cs delete mode 100644 src/Modules/GeardownModule/Repositories/GeardownApiBase.cs delete mode 100644 src/Modules/GeardownModule/Repositories/GeardownEventApi.cs delete mode 100644 src/Modules/GeardownModule/Repositories/GeardownGroupApi.cs delete mode 100644 src/Modules/GeardownModule/Repositories/GeardownMatchApi.cs delete mode 100644 src/Modules/GeardownModule/Repositories/TourneyTimelineRepository.cs delete mode 100644 src/Modules/GeardownModule/Services/GeardownApiService.cs delete mode 100644 src/Modules/GeardownModule/Services/GeardownService.cs delete mode 100644 src/Modules/GeardownModule/Services/GeardownSetupService.cs delete mode 100644 src/Modules/GeardownModule/Services/GeardownSetupStateService.cs delete mode 100644 src/Modules/GeardownModule/Services/MatchManagementService.cs delete mode 100644 src/Modules/GeardownModule/Settings/IGeardownSettings.cs delete mode 100644 src/Modules/GeardownModule/Util/MatchSettingsTypeUtils.cs delete mode 100644 src/Modules/GeardownModule/info.toml delete mode 100644 src/Modules/XPEvoAdminControl/Controllers/AdminCpComController.cs delete mode 100644 src/Modules/XPEvoAdminControl/Events/AdminCpEvents.cs delete mode 100644 src/Modules/XPEvoAdminControl/Events/EventArgs/CpComActionEventArgs.cs delete mode 100644 src/Modules/XPEvoAdminControl/Interfaces/CpCom/ICpAction.cs delete mode 100644 src/Modules/XPEvoAdminControl/Interfaces/ICpComService.cs delete mode 100644 src/Modules/XPEvoAdminControl/Interfaces/IProblemService.cs delete mode 100644 src/Modules/XPEvoAdminControl/Localization.resx delete mode 100644 src/Modules/XPEvoAdminControl/Models/CpCom/CpAction.cs delete mode 100644 src/Modules/XPEvoAdminControl/Models/Dto/CpActionAssignServerDto.cs delete mode 100644 src/Modules/XPEvoAdminControl/Models/MatchServerStatus.cs delete mode 100644 src/Modules/XPEvoAdminControl/Services/CpComBackgroundService.cs delete mode 100644 src/Modules/XPEvoAdminControl/Services/CpComService.cs delete mode 100644 src/Modules/XPEvoAdminControl/Services/ProblemService.cs delete mode 100644 src/Modules/XPEvoAdminControl/Settings/IXPEvoAdminSettings.cs delete mode 100644 src/Modules/XPEvoAdminControl/XPEvoAdminControl.cs delete mode 100644 src/Modules/XPEvoAdminControl/XPEvoAdminControl.csproj delete mode 100644 src/Modules/XPEvoAdminControl/info.toml diff --git a/EvoSC.sln b/EvoSC.sln index e03f2ca6e..2487aa426 100644 --- a/EvoSC.sln +++ b/EvoSC.sln @@ -84,10 +84,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchTrackerModule", "src\M EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchReadyModule", "src\Modules\MatchReadyModule\MatchReadyModule.csproj", "{0538B9AB-B556-45BF-8230-53087BA9D353}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeardownModule", "src\Modules\GeardownModule\GeardownModule.csproj", "{D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XPEvoAdminControl", "src\Modules\XPEvoAdminControl\XPEvoAdminControl.csproj", "{D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scoreboard", "src\Modules\Scoreboard\Scoreboard.csproj", "{CD032D37-3BC8-4DE8-8C5B-45A0DE36932E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NextMapModule", "src\Modules\NextMapModule\NextMapModule.csproj", "{64688FA7-136C-4BB9-B716-4E96DD0AA82F}" @@ -286,14 +282,6 @@ Global {0538B9AB-B556-45BF-8230-53087BA9D353}.Debug|Any CPU.Build.0 = Debug|Any CPU {0538B9AB-B556-45BF-8230-53087BA9D353}.Release|Any CPU.ActiveCfg = Release|Any CPU {0538B9AB-B556-45BF-8230-53087BA9D353}.Release|Any CPU.Build.0 = Release|Any CPU - {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0}.Release|Any CPU.Build.0 = Release|Any CPU - {D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9}.Release|Any CPU.Build.0 = Release|Any CPU {570CEDDA-7EBC-486D-BD5D-0A1C39DD69F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {570CEDDA-7EBC-486D-BD5D-0A1C39DD69F8}.Debug|Any CPU.Build.0 = Debug|Any CPU {570CEDDA-7EBC-486D-BD5D-0A1C39DD69F8}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -361,8 +349,6 @@ Global {A533CF48-1BE5-4F0E-A636-941ED63DF9ED} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} {CBE9F195-758F-470D-B3BF-6B012C8216CC} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {0538B9AB-B556-45BF-8230-53087BA9D353} = {DC47658A-F421-4BA4-B617-090A7DFB3900} - {D7916D8A-57D2-4CDC-ABA6-03C7FA5BB3D0} = {DC47658A-F421-4BA4-B617-090A7DFB3900} - {D0E37AF5-BBF2-4D8B-AEDB-43265DB37AD9} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {570CEDDA-7EBC-486D-BD5D-0A1C39DD69F8} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {1D3B25FA-F807-4428-A520-878A582DCF28} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {42BCE01C-EBEF-4DB6-A61C-35B63C915AD3} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} diff --git a/src/EvoSC/EvoSC.csproj b/src/EvoSC/EvoSC.csproj index 2f272ffa4..2498ab0a4 100644 --- a/src/EvoSC/EvoSC.csproj +++ b/src/EvoSC/EvoSC.csproj @@ -25,7 +25,6 @@ - @@ -57,7 +56,6 @@ - diff --git a/src/Modules/GeardownModule/Controllers/EventsController.cs b/src/Modules/GeardownModule/Controllers/EventsController.cs deleted file mode 100644 index 5a2eefc74..000000000 --- a/src/Modules/GeardownModule/Controllers/EventsController.cs +++ /dev/null @@ -1,86 +0,0 @@ -using EvoSC.Common.Controllers; -using EvoSC.Common.Controllers.Attributes; -using EvoSC.Common.Events.Attributes; -using EvoSC.Common.Interfaces; -using EvoSC.Common.Interfaces.Controllers; -using EvoSC.Common.Remote; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Settings; -using EvoSC.Modules.Official.MatchReadyModule.Events; -using EvoSC.Modules.Official.MatchReadyModule.Events.Args; -using EvoSC.Modules.Official.MatchTrackerModule.Events; -using EvoSC.Modules.Official.MatchTrackerModule.Events.EventArgObjects; -using EvoSC.Modules.Official.MatchTrackerModule.Interfaces; -using EvoSC.Modules.Official.MatchTrackerModule.Models; -using Microsoft.Extensions.Logging; - -namespace EvoSC.Modules.Evo.GeardownModule.Controllers; - -[Controller] -public class EventsController : EvoScController -{ - private readonly IGeardownService _geardownService; - private readonly IGeardownSettings _settings; - private readonly IServerClient _server; - private readonly ILogger _logger; - - public EventsController(IGeardownService geardownService, IGeardownSettings settings, IServerClient server, ILogger logger) - { - _geardownService = geardownService; - _settings = settings; - _server = server; - _logger = logger; - } - - [Subscribe(MatchReadyEvents.AllPlayersReady)] - public async Task OnAllPlayersReadyAsync(object sender, AllPlayersReadyEventArgs args) - { - if (!_settings.AutomaticMatchStart) - { - return; - } - - try - { - await _geardownService.StartMatchAsync(); - } - catch (Exception ex) - { - await _server.ErrorMessageAsync( - "An error occured while trying to start the match. Contact match admin immediately."); - _logger.LogError(ex, "Failed to start match on all players ready."); - } - } - - [Subscribe(MatchTrackerEvent.StateTracked)] - public async Task OnMatchStateTracked(object sender, MatchStateTrackedEventArgs args) - { - if (args.State.Status == MatchStatus.Ended) - { - try - { - await _geardownService.EndMatchAsync(args.Timeline); - } - catch (Exception ex) - { - await _server.ErrorMessageAsync( - "Failed to send match results. Take screenshots and contact a match admin."); - _logger.LogError(ex, "Failed to send match results."); - } - } - } - - [Subscribe(ModeScriptEvent.WarmUpStart)] - public async Task OnWarmupStart(object sender, EventArgs args) - { - try - { - await _geardownService.FinishServerSetupAsync(); - } - catch (Exception) - { - await _server.ErrorMessageAsync("Failed to finish match setup. Contact a match admin immediately."); - throw; - } - } -} diff --git a/src/Modules/GeardownModule/Controllers/GeardownCommandsController.cs b/src/Modules/GeardownModule/Controllers/GeardownCommandsController.cs deleted file mode 100644 index 4f241ee59..000000000 --- a/src/Modules/GeardownModule/Controllers/GeardownCommandsController.cs +++ /dev/null @@ -1,79 +0,0 @@ -using EvoSC.Commands.Attributes; -using EvoSC.Commands.Interfaces; -using EvoSC.Common.Controllers; -using EvoSC.Common.Controllers.Attributes; -using EvoSC.Common.Interfaces; -using EvoSC.Common.Interfaces.Models; -using EvoSC.Common.Util; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Permissions; - -namespace EvoSC.Modules.Evo.GeardownModule.Controllers; - -[Controller] -public class GeardownCommandsController : EvoScController -{ - private readonly IGeardownService _geardown; - private readonly IServerClient _server; - private readonly IMatchManagementService _matchManagement; - - public GeardownCommandsController(IGeardownService geardown, IServerClient server, IMatchManagementService matchManagement) - { - _geardown = geardown; - _server = server; - _matchManagement = matchManagement; - } - - [ChatCommand("geardown_setup", "Setup the server for a match from geardown.", GeardownPermissions.SetupMatch)] - public async Task GeardownSetupAsync(int matchId) - { - try - { - await _server.InfoMessageAsync($"Setting up the match for ID {matchId}, please wait ...", Context.Player); - await _geardown.SetupServerAsync(matchId); - await _server.SuccessMessageAsync("Match successfully set up! Reloading match settings ...", - Context.Player); - } - catch (InvalidOperationException ex) - { - await _server.ErrorMessageAsync($"(Geardown) {ex.Message}", Context.Player); - } - catch (Exception) - { - await _server.ErrorMessageAsync($"(Geardown) An unknown error occured, check console."); - throw; - } - } - - [ChatCommand("geardown_startmatch", "Start a geardown controller match.", GeardownPermissions.StartMatch)] - public async Task GeardownStartMatchAsync() - { - try - { - await _geardown.StartMatchAsync(); - } - catch (Exception ex) - { - await _server.ErrorMessageAsync($"Failed to start match: {ex.Message}"); - throw; - } - } - - [ChatCommand("setpoints", "Set points for a player.", GeardownPermissions.SetPoints)] - public Task SetPlayerPointsAsync(IOnlinePlayer player, int points) => - _matchManagement.SetPlayerPointsAsync(player, points); - - [ChatCommand("pausematch", "Pause the current match.", GeardownPermissions.PauseMatch)] - [CommandAlias("/pause")] - public Task PauseMatchAsync() => _matchManagement.PauseMatchAsync(); - - [ChatCommand("unpausematch", "Pause the current match.", GeardownPermissions.PauseMatch)] - [CommandAlias("/unpause")] - public Task UnpauseMatchAsync() => _matchManagement.UnpauseMatchAsync(); - - [ChatCommand("servername", "Set the current server name.", GeardownPermissions.ServerName)] - public Task SetServerNameAsync(string name) => _matchManagement.SetServerNameAsync(name); - - [ChatCommand("setmaxplayers", "Sets max players of the server.", GeardownPermissions.ServerName)] - public Task SetMaxPlayersAsync(int count) => _server.Remote.SetMaxPlayersAsync(count); -} diff --git a/src/Modules/GeardownModule/GeardownModule.cs b/src/Modules/GeardownModule/GeardownModule.cs deleted file mode 100644 index af824ba1a..000000000 --- a/src/Modules/GeardownModule/GeardownModule.cs +++ /dev/null @@ -1,13 +0,0 @@ -using EvoSC.Modules.Attributes; -using EvoSC.Modules.Evo.GeardownModule.Settings; - -namespace EvoSC.Modules.Evo.GeardownModule; - -[Module(IsInternal = true)] -public class GeardownModule : EvoScModule -{ - public GeardownModule(IGeardownSettings settings) - { - Console.WriteLine($"settings: {settings.ApiAccessToken}"); - } -} diff --git a/src/Modules/GeardownModule/GeardownModule.csproj b/src/Modules/GeardownModule/GeardownModule.csproj deleted file mode 100644 index 390dc0272..000000000 --- a/src/Modules/GeardownModule/GeardownModule.csproj +++ /dev/null @@ -1,45 +0,0 @@ - - - - net7.0 - enable - enable - EvoSC.Modules.Evo.GeardownModule - false - GeardownModule - MyModule - This is my awesome module. - 1.0.0 - Me - - - - - - - - - - - - - - - - - - - - - - - - ..\..\..\..\..\..\.nuget\packages\hawf\1.0.3\lib\net6.0\Hawf.dll - - - - - - - - diff --git a/src/Modules/GeardownModule/Interfaces/IGeardownMatchState.cs b/src/Modules/GeardownModule/Interfaces/IGeardownMatchState.cs deleted file mode 100644 index 94f1460bd..000000000 --- a/src/Modules/GeardownModule/Interfaces/IGeardownMatchState.cs +++ /dev/null @@ -1,16 +0,0 @@ -using EvoSC.Modules.Evo.GeardownModule.Models.API; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces; - -public interface IGeardownMatchState -{ - /// - /// Details about the match. - /// - public GdMatch Match { get; } - - /// - /// The match token for this match. - /// - public string MatchToken { get; } -} diff --git a/src/Modules/GeardownModule/Interfaces/IGeardownService.cs b/src/Modules/GeardownModule/Interfaces/IGeardownService.cs deleted file mode 100644 index 94ab4a75c..000000000 --- a/src/Modules/GeardownModule/Interfaces/IGeardownService.cs +++ /dev/null @@ -1,39 +0,0 @@ -using EvoSC.Modules.Official.MatchTrackerModule.Interfaces.Models; -using EvoSC.Modules.Official.MatchTrackerModule.Models; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces; - -public interface IGeardownService -{ - /// - /// Begin automatic setup of the server. This is the initial setup phase. - /// - /// ID of the match to set the server up for. - /// - public Task SetupServerAsync(int matchId); - - /// - /// Finish setting up the server. SetupServerAsync must be called first. - /// - /// - public Task FinishServerSetupAsync(); - - /// - /// Start the match now. - /// - /// - public Task StartMatchAsync(); - - /// - /// End the match and send the provided timeline as match results. - /// - /// Timeline representing the match's results. - /// - public Task EndMatchAsync(IMatchTimeline timeline); - - /// - /// Get the current status of the match. - /// - /// - public MatchStatus GetMatchStatus(); -} diff --git a/src/Modules/GeardownModule/Interfaces/IGeardownSetupService.cs b/src/Modules/GeardownModule/Interfaces/IGeardownSetupService.cs deleted file mode 100644 index 47bc80fdf..000000000 --- a/src/Modules/GeardownModule/Interfaces/IGeardownSetupService.cs +++ /dev/null @@ -1,19 +0,0 @@ -using EvoSC.Modules.Evo.GeardownModule.Models.API; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces; - -public interface IGeardownSetupService -{ - /// - /// Initialize the server with a match. - /// - /// The match to set the server up for. - /// - public Task<(GdMatch match, string token)> InitialSetupAsync(int matchId); - - /// - /// Finalize the server setup. - /// - /// - public Task FinalizeSetupAsync(); -} diff --git a/src/Modules/GeardownModule/Interfaces/IMatchManagementService.cs b/src/Modules/GeardownModule/Interfaces/IMatchManagementService.cs deleted file mode 100644 index dd3f314b9..000000000 --- a/src/Modules/GeardownModule/Interfaces/IMatchManagementService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using EvoSC.Common.Interfaces.Models; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces; - -public interface IMatchManagementService -{ - /// - /// Set custom score for a player. - /// - /// The player to set the score for. - /// Number of points to set the score to. - /// - public Task SetPlayerPointsAsync(IPlayer player, int points); - - /// - /// Pause the current match. - /// - /// - public Task PauseMatchAsync(); - - /// - /// Resume the current match from a paused state. - /// - /// - public Task UnpauseMatchAsync(); - - /// - /// Set the name of the server. - /// - /// Texts to set the server name to. - /// - Task SetServerNameAsync(string name); -} diff --git a/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownEventApi.cs b/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownEventApi.cs deleted file mode 100644 index 575635a4a..000000000 --- a/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownEventApi.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using EvoSC.Modules.Evo.GeardownModule.Models; -using EvoSC.Modules.Evo.GeardownModule.Models.API; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; - -public interface IGeardownEventApi -{ - public Task UpdateStatus(int eventId, EventStatus statusId); - public Task?> GetParticipants(int eventId); -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownGroupApi.cs b/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownGroupApi.cs deleted file mode 100644 index a9d1ec4c0..000000000 --- a/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownGroupApi.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Threading.Tasks; -using EvoSC.Modules.Evo.GeardownModule.Models.API; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces; - -public interface IGeardownGroupApi -{ - public Task?> GetParticipantsAsync(int groupId); - public Task CreateGroupAsync(string name, int eventId, bool isTypeTree); - public Task UpdateGroupParticipantsAsync(int groupId, IEnumerable participants); -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownMatchApi.cs b/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownMatchApi.cs deleted file mode 100644 index 30c8d6918..000000000 --- a/src/Modules/GeardownModule/Interfaces/Repositories/IGeardownMatchApi.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using EvoSC.Common.Remote.EventArgsModels; -using EvoSC.Modules.Evo.GeardownModule.Models; -using EvoSC.Modules.Evo.GeardownModule.Models.API; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; - -public interface IGeardownMatchApi -{ - /// - /// Assign a server to a match. - /// - /// ID of the match. - /// Name of the server. - /// Unique ID of the server. (typically account uid) - /// The password required to join the server. - /// - public Task AssignServerAsync(int matchId, string name, string serverId, string? serverPassword); - - /// - /// Get details about a match from a match token. - /// - /// Token corresponding to the match. - /// - public Task GetMatchDataByTokenAsync(string matchToken); - - /// - /// Notify the end of match. - /// - /// Token of the match. - /// - public Task OnEndMatchAsync(string matchToken); - - /// - /// Notify start of match. - /// - /// Token of the match. - /// - public Task OnStartMatchAsync(string matchToken); - - /// - /// Add results to a match. - /// - /// ID of the match. - /// Results containing an array of account ID and score pairs. - /// - public Task AddResultsAsync(int matchId, IEnumerable results); -} diff --git a/src/Modules/GeardownModule/Interfaces/Repositories/ITourneyTimelineRepository.cs b/src/Modules/GeardownModule/Interfaces/Repositories/ITourneyTimelineRepository.cs deleted file mode 100644 index 9285959d5..000000000 --- a/src/Modules/GeardownModule/Interfaces/Repositories/ITourneyTimelineRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; - -public interface ITourneyTimelineRepository -{ - /// - /// Add a match ID to a timeline. - /// - /// ID of the match. - /// Tracking ID of the timeline. - /// - public Task AddTimelineAsync(int matchId, Guid timelineId); -} diff --git a/src/Modules/GeardownModule/Interfaces/Services/IGeardownApiService.cs b/src/Modules/GeardownModule/Interfaces/Services/IGeardownApiService.cs deleted file mode 100644 index 5165e0b55..000000000 --- a/src/Modules/GeardownModule/Interfaces/Services/IGeardownApiService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; - -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces.Services; - -public interface IGeardownApiService -{ - /// - /// Manage Tourney matches. - /// - public IGeardownMatchApi Matches { get; } -} diff --git a/src/Modules/GeardownModule/Interfaces/Services/IGeardownSetupStateService.cs b/src/Modules/GeardownModule/Interfaces/Services/IGeardownSetupStateService.cs deleted file mode 100644 index 68bc24375..000000000 --- a/src/Modules/GeardownModule/Interfaces/Services/IGeardownSetupStateService.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Interfaces.Services; - -public interface IGeardownSetupStateService -{ - /// - /// True when the server is initially set up. - /// - public bool IsInitialSetup { get; } - - /// - /// The name of the MatchSettings for the match that is currently set up. - /// - public string MatchSettingsName { get; } - - /// - /// True when the server has finished the match setup. - /// - public bool SetupFinished { get; } - - /// - /// True if the server is waiting for the match to start. - /// - public bool WaitingForMatchStart { get; } - - /// - /// Set the initial setup state. - /// - /// Name of the match settings to use. - public void SetInitialSetup(string matchSettingsName); - - /// - /// Set the finish setup state. - /// - public void SetSetupFinished(); - - /// - /// Set that the match has started. - /// - public void SetMatchStarted(); -} diff --git a/src/Modules/GeardownModule/Localization.resx b/src/Modules/GeardownModule/Localization.resx deleted file mode 100644 index f2bbd290f..000000000 --- a/src/Modules/GeardownModule/Localization.resx +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Hello {0} - - \ No newline at end of file diff --git a/src/Modules/GeardownModule/Migrations/202309160959_AddGeardownMatchRecordsTable.cs b/src/Modules/GeardownModule/Migrations/202309160959_AddGeardownMatchRecordsTable.cs deleted file mode 100644 index 58e49d56f..000000000 --- a/src/Modules/GeardownModule/Migrations/202309160959_AddGeardownMatchRecordsTable.cs +++ /dev/null @@ -1,20 +0,0 @@ -using EvoSC.Modules.Evo.GeardownModule.Models.Database; -using FluentMigrator; - -namespace EvoSC.Modules.Evo.GeardownModule.Migrations; - -[Migration(1694847552)] -public class AddGeardownMatchRecordsTable : Migration -{ - public override void Up() - { - Create.Table(DbTourneyTimeline.TableName) - .WithColumn(nameof(DbTourneyTimeline.MatchId)).AsInt64().Indexed() - .WithColumn(nameof(DbTourneyTimeline.TimelineId)).AsGuid().Indexed(); - } - - public override void Down() - { - Delete.Table(DbTourneyTimeline.TableName); - } -} diff --git a/src/Modules/GeardownModule/Models/API/GdFormat.cs b/src/Modules/GeardownModule/Models/API/GdFormat.cs deleted file mode 100644 index 8669ea7df..000000000 --- a/src/Modules/GeardownModule/Models/API/GdFormat.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; - -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdFormat -{ - public int? id { get; set; } - public string? name { get; set; } - public FormatType? type_id { get; set; } - public string? description { get; set; } - public List? match_settings { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdGameServer.cs b/src/Modules/GeardownModule/Models/API/GdGameServer.cs deleted file mode 100644 index be31ffcc3..000000000 --- a/src/Modules/GeardownModule/Models/API/GdGameServer.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdGameServer -{ - public int? id { get; set; } - public string? created_at { get; set; } - public string? updated_at { get; set; } - public string? name { get; set; } - public string? url { get; set; } // can be used as join instructions as well - public int? game_id { get; set; } - public int? event_id { get; set; } - public int? pending { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdGroup.cs b/src/Modules/GeardownModule/Models/API/GdGroup.cs deleted file mode 100644 index 21c42e72c..000000000 --- a/src/Modules/GeardownModule/Models/API/GdGroup.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; - -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdGroup -{ - public int? id { get; set; } - public string? type { get; set; } - public string? name { get; set; } - public int? min_size { get; set; } //not used - public int? max_size { get; set; } //not used - public int? event_id { get; set; } - public int? is_type_tree { get; set; } //not used - public string? created_at { get; set; } - public string? updated_at { get; set; } - public List? praticipants { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdMapPoolOrder.cs b/src/Modules/GeardownModule/Models/API/GdMapPoolOrder.cs deleted file mode 100644 index b27da6c23..000000000 --- a/src/Modules/GeardownModule/Models/API/GdMapPoolOrder.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdMapPoolOrder -{ - public int? id { get; set; } - public int? map_pool_id { get; set; } - public int? mx_map_id { get; set; } - public int? order { get; set; } - public int? match_id { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdMatch.cs b/src/Modules/GeardownModule/Models/API/GdMatch.cs deleted file mode 100644 index 2958f94ad..000000000 --- a/src/Modules/GeardownModule/Models/API/GdMatch.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; - -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdMatch -{ - public int? id { get; set; } - public string? name { get; set; } - public int? status_id { get; set; } - public string? status { get; set; } - public int? group_id { get; set; } //not used - public int? map_pool_id { get; set; } //not used - public string? date { get; set; } - public string? created_at { get; set; } - public string? updated_at { get; set; } - public List? participants { get; set; } - public List? formats { get; set; } - public GdGameServer? selectedGameServer { get; set; } - public List? map_pool_orders { get; set; } -} diff --git a/src/Modules/GeardownModule/Models/API/GdMatchResult.cs b/src/Modules/GeardownModule/Models/API/GdMatchResult.cs deleted file mode 100644 index 2fb02b550..000000000 --- a/src/Modules/GeardownModule/Models/API/GdMatchResult.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdMatchResult -{ - public int? id { get; set; } - public string? result { get; set; } - public bool? is_total_result { get; set; } - public int? match_id { get; set; } - public bool? pending { get; set; } - public string? created_at { get; set; } - public string? updated_at { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdMatchSetting.cs b/src/Modules/GeardownModule/Models/API/GdMatchSetting.cs deleted file mode 100644 index af41e3b4e..000000000 --- a/src/Modules/GeardownModule/Models/API/GdMatchSetting.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdMatchSetting -{ - public int? id { get; set; } - public string? key { get; set; } //S_WhateverOption - public string? value { get; set; } - public int? format_id { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdMatchToken.cs b/src/Modules/GeardownModule/Models/API/GdMatchToken.cs deleted file mode 100644 index ef54f90b2..000000000 --- a/src/Modules/GeardownModule/Models/API/GdMatchToken.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; - -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdMatchToken -{ - [JsonPropertyName("matchId")] - public int MatchId { get; set; } - - [JsonPropertyName("evoscToken")] - public string EvoScToken { get; set; } -} diff --git a/src/Modules/GeardownModule/Models/API/GdOnEndMapRequest.cs b/src/Modules/GeardownModule/Models/API/GdOnEndMapRequest.cs deleted file mode 100644 index 2b31c2105..000000000 --- a/src/Modules/GeardownModule/Models/API/GdOnEndMapRequest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdOnEndMapRequest -{ - public string matchToken { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdOnEndRoundRequest.cs b/src/Modules/GeardownModule/Models/API/GdOnEndRoundRequest.cs deleted file mode 100644 index ea70d7732..000000000 --- a/src/Modules/GeardownModule/Models/API/GdOnEndRoundRequest.cs +++ /dev/null @@ -1,9 +0,0 @@ -using EvoSC.Common.Remote.EventArgsModels; - -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdOnEndRoundRequest -{ - public string matchToken { get; set; } - public ScoresEventArgs eventData { get; set; } -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdOnStartMatchRequest.cs b/src/Modules/GeardownModule/Models/API/GdOnStartMatchRequest.cs deleted file mode 100644 index 045f3518a..000000000 --- a/src/Modules/GeardownModule/Models/API/GdOnStartMatchRequest.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdOnStartMatchRequest -{ - public string matchToken { get; set; } - public string join { get; set; } // Join Instructions. e.g. Club Name | Server #1 -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdPage.cs b/src/Modules/GeardownModule/Models/API/GdPage.cs deleted file mode 100644 index 02ebc8e0f..000000000 --- a/src/Modules/GeardownModule/Models/API/GdPage.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdPage -{ -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/API/GdParticipant.cs b/src/Modules/GeardownModule/Models/API/GdParticipant.cs deleted file mode 100644 index 36b851be5..000000000 --- a/src/Modules/GeardownModule/Models/API/GdParticipant.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdParticipant -{ - public int? id { get; set; } - public string? type { get; set; } //user|page - public int? user_id { get; set; } - public int? page_id { get; set; } - public int event_id { get; set; } - public string? created_at { get; set; } - public string? updated_at { get; set; } - public GdUser? user { get; set; } //null in team formats -} diff --git a/src/Modules/GeardownModule/Models/API/GdResult.cs b/src/Modules/GeardownModule/Models/API/GdResult.cs deleted file mode 100644 index b771d8e4b..000000000 --- a/src/Modules/GeardownModule/Models/API/GdResult.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdResult -{ - public string account_id { get; set; } - public int score { get; set; } -} diff --git a/src/Modules/GeardownModule/Models/API/GdResults.cs b/src/Modules/GeardownModule/Models/API/GdResults.cs deleted file mode 100644 index d5a05c8ed..000000000 --- a/src/Modules/GeardownModule/Models/API/GdResults.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdResults -{ - public int matchId { get; set; } - public IEnumerable results { get; set; } -} diff --git a/src/Modules/GeardownModule/Models/API/GdUser.cs b/src/Modules/GeardownModule/Models/API/GdUser.cs deleted file mode 100644 index 931dd2e28..000000000 --- a/src/Modules/GeardownModule/Models/API/GdUser.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models.API; - -public class GdUser -{ - public int? id { get; set; } - public string? nickname { get; set; } - public string? tm_nickname { get; set; } - public string? tm_account_id { get; set; } - public string? nat { get; set; } //nationality - public string? created_at { get; set; } - public string? updated_at { get; set; } -} diff --git a/src/Modules/GeardownModule/Models/Database/DbGeardownMatchRecord.cs b/src/Modules/GeardownModule/Models/Database/DbGeardownMatchRecord.cs deleted file mode 100644 index 766fbc99e..000000000 --- a/src/Modules/GeardownModule/Models/Database/DbGeardownMatchRecord.cs +++ /dev/null @@ -1,15 +0,0 @@ -using LinqToDB.Mapping; - -namespace EvoSC.Modules.Evo.GeardownModule.Models.Database; - -[Table(DbTourneyTimeline.TableName)] -public class DbTourneyTimeline -{ - public const string TableName = "TourneyTimelines"; - - [Column] - public long MatchId { get; set; } - - [Column] - public Guid TimelineId { get; set; } -} diff --git a/src/Modules/GeardownModule/Models/EventStatus.cs b/src/Modules/GeardownModule/Models/EventStatus.cs deleted file mode 100644 index d59916d4e..000000000 --- a/src/Modules/GeardownModule/Models/EventStatus.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models; - -public enum EventStatus -{ - Upcoming = 1, - Live = 2, - Ended = 3 -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/FormatType.cs b/src/Modules/GeardownModule/Models/FormatType.cs deleted file mode 100644 index ed15f087b..000000000 --- a/src/Modules/GeardownModule/Models/FormatType.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models; - -public enum FormatType -{ - Other = 0, - TimeAttack = 1, - Rounds = 2, - Cup = 3, - Laps = 4, - Team = 5, - Knockout = 6 -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Models/GeardownMatchState.cs b/src/Modules/GeardownModule/Models/GeardownMatchState.cs deleted file mode 100644 index 844026d6e..000000000 --- a/src/Modules/GeardownModule/Models/GeardownMatchState.cs +++ /dev/null @@ -1,10 +0,0 @@ -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Models.API; - -namespace EvoSC.Modules.Evo.GeardownModule.Models; - -public class GeardownMatchState : IGeardownMatchState -{ - public required GdMatch Match { get; init; } - public required string MatchToken { get; init; } -} diff --git a/src/Modules/GeardownModule/Models/MatchStatus.cs b/src/Modules/GeardownModule/Models/MatchStatus.cs deleted file mode 100644 index 47dce8b7d..000000000 --- a/src/Modules/GeardownModule/Models/MatchStatus.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace EvoSC.Modules.Evo.GeardownModule.Models; - -public enum MatchStatus -{ - Upcoming = 1, - Live = 2, - Ended = 3 -} \ No newline at end of file diff --git a/src/Modules/GeardownModule/Permissions/GeardownPermissions.cs b/src/Modules/GeardownModule/Permissions/GeardownPermissions.cs deleted file mode 100644 index 7834fd28e..000000000 --- a/src/Modules/GeardownModule/Permissions/GeardownPermissions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.ComponentModel; -using EvoSC.Common.Permissions.Attributes; - -namespace EvoSC.Modules.Evo.GeardownModule.Permissions; - -[PermissionGroup] -public enum GeardownPermissions -{ - [Description("Can start a match through geardown.")] - StartMatch, - - [Description("Can set up the server for a match.")] - SetupMatch, - - [Description("Can set custom points for a player.")] - SetPoints, - - [Description("Can pause/unpause a match.")] - PauseMatch, - - [Description("Allows to manage the server name.")] - ServerName -} diff --git a/src/Modules/GeardownModule/Repositories/GeardownApiBase.cs b/src/Modules/GeardownModule/Repositories/GeardownApiBase.cs deleted file mode 100644 index 31bdf1af5..000000000 --- a/src/Modules/GeardownModule/Repositories/GeardownApiBase.cs +++ /dev/null @@ -1,24 +0,0 @@ -using EvoSC.Modules.Evo.GeardownModule.Settings; -using Hawf.Client; - -namespace EvoSC.Modules.Evo.GeardownModule.Repositories; - -public class GeardownApiBase : ApiBase where T : ApiBase -{ - private readonly IGeardownSettings _settings; - - public GeardownApiBase(IGeardownSettings settings) - { - _settings = settings; - - Configure(c => - { - c.BaseUrl = settings.ApiBaseUrl; - c.CacheResponse = false; - c.UseRateLimit = false; - }); - } - - protected T WithAccessToken() => - WithQueryParam("token", _settings.ApiAccessToken); -} diff --git a/src/Modules/GeardownModule/Repositories/GeardownEventApi.cs b/src/Modules/GeardownModule/Repositories/GeardownEventApi.cs deleted file mode 100644 index 7e6db7b90..000000000 --- a/src/Modules/GeardownModule/Repositories/GeardownEventApi.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; -using EvoSC.Modules.Evo.GeardownModule.Models; -using EvoSC.Modules.Evo.GeardownModule.Models.API; -using EvoSC.Modules.Evo.GeardownModule.Settings; -using Hawf.Attributes; - -namespace EvoSC.Modules.Evo.GeardownModule.Repositories; - -[ApiClient] -public class GeardownEventApi : GeardownApiBase, IGeardownEventApi -{ - public GeardownEventApi(IGeardownSettings settings) : base(settings) - { - } - - public Task UpdateStatus(int eventId, EventStatus statusId) => - WithAccessToken() - .WithJsonBody(new { eventId, statusId }) - .PutStringAsync("/api/v1/events/status"); - - public Task?> GetParticipants(int eventId) => - WithAccessToken() - .WithJsonBody(new { eventId }) - .GetJsonAsync>("/api/v1/events/participants"); -} diff --git a/src/Modules/GeardownModule/Repositories/GeardownGroupApi.cs b/src/Modules/GeardownModule/Repositories/GeardownGroupApi.cs deleted file mode 100644 index ccf2c7d1b..000000000 --- a/src/Modules/GeardownModule/Repositories/GeardownGroupApi.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Models.API; -using EvoSC.Modules.Evo.GeardownModule.Settings; -using Hawf.Attributes; -using Hawf.Client; - -namespace EvoSC.Modules.Evo.GeardownModule.Repositories; - -[ApiClient] -public class GeardownGroupApi : GeardownApiBase, IGeardownGroupApi -{ - private readonly IGeardownSettings _settings; - - public GeardownGroupApi(IGeardownSettings settings) : base(settings) - { - } - - public Task?> GetParticipantsAsync(int groupId) => - WithAccessToken() - .WithJsonBody(new { groupId }) - .GetJsonAsync>("/v1/groups/participants"); - - - public Task CreateGroupAsync(string name, int eventId, bool isTypeTree) => - WithAccessToken() - .WithJsonBody(new { name, eventId, isTypeTree }) - .PostJsonAsync("/v1/groups/create"); - - public Task UpdateGroupParticipantsAsync(int groupId, IEnumerable participants) => - WithAccessToken() - .WithJsonBody(new { groupId, participants }) - .PutJsonAsync("/v1/groups/participants"); -} diff --git a/src/Modules/GeardownModule/Repositories/GeardownMatchApi.cs b/src/Modules/GeardownModule/Repositories/GeardownMatchApi.cs deleted file mode 100644 index 1b83337d4..000000000 --- a/src/Modules/GeardownModule/Repositories/GeardownMatchApi.cs +++ /dev/null @@ -1,94 +0,0 @@ -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; -using EvoSC.Modules.Evo.GeardownModule.Models.API; -using EvoSC.Modules.Evo.GeardownModule.Settings; -using Flurl; -using Flurl.Http; -using Flurl.Util; - -namespace EvoSC.Modules.Evo.GeardownModule.Repositories; - -public class GeardownMatchApi : IGeardownMatchApi -{ - private readonly IGeardownSettings _settings; - - public GeardownMatchApi(IGeardownSettings settings) - { - _settings = settings; - } - - /* public Task AssignServerAsync(int matchId, string name, string serverId, string? serverPassword) => - WithAccessToken() - .WithJsonBody(new { serverId, password = serverPassword, name }) - .PostJsonAsync("/api/matches/game_server/{matchId}", matchId); - - public Task GetMatchDataByTokenAsync(string matchToken) => - WithAccessToken() - .GetJsonAsync("/api/matches/evo_token/{matchToken}", matchToken); - - public Task OnEndMatchAsync(string matchToken) => - WithAccessToken() - .WithJsonBody(new { matchToken }) - .PostStringAsync("/v1/matches/on_end_match"); - - public Task OnStartMatchAsync(string matchToken) => - WithAccessToken() - .WithJsonBody(new { matchToken }) - .PostStringAsync("/v1/matches/on_start_match"); - - public Task AddResultsAsync(int matchId, IEnumerable results) => - WithAccessToken() - .WithJsonBody(new { matchId = matchId, results = results }) - .PostStringAsync("/api/console/dedicated_controllers/results"); */ - public Task AssignServerAsync(int matchId, string name, string serverId, string? serverPassword) - { - return $"https://tourneyapi.evoesports.gg/api/matches/game_server/{matchId}" - .SetQueryParam("token", _settings.ApiAccessToken) - .PostJsonAsync(new { serverId, password = serverPassword, name }) - .ReceiveJson(); - } - - public Task GetMatchDataByTokenAsync(string matchToken) - { - return $"https://tourneyapi.evoesports.gg/api/matches/evo_token/{matchToken}" - .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json") - .WithHeader("User-Agent", "EvoSC") - .WithHeader("Connection", "keep-alive") - .WithHeader("Accept-Encoding", "gzip, deflate, br") - .SetQueryParam("token", _settings.ApiAccessToken) - .GetAsync() - .ReceiveJson(); - } - - public Task OnEndMatchAsync(string matchToken) - { - return $"https://tourneyapi.evoesports.gg/v1/matches/on_end_match" - .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json") - .WithHeader("User-Agent", "EvoSC") - .WithHeader("Connection", "keep-alive") - .WithHeader("Accept-Encoding", "gzip, deflate, br") - .SetQueryParam("token", _settings.ApiAccessToken) - .PostAsync(); - } - - public Task OnStartMatchAsync(string matchToken) - { - return $"https://tourneyapi.evoesports.gg/v1/matches/on_start_match" - .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json") - .WithHeader("User-Agent", "EvoSC") - .WithHeader("Connection", "keep-alive") - .WithHeader("Accept-Encoding", "gzip, deflate, br") - .SetQueryParam("token", _settings.ApiAccessToken) - .PostAsync(); - } - - public Task AddResultsAsync(int matchId, IEnumerable results) - { - return $"https://tourneyapi.evoesports.gg/api/matches/game_server/{matchId}" - .WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json") - .WithHeader("User-Agent", "EvoSC") - .WithHeader("Connection", "keep-alive") - .WithHeader("Accept-Encoding", "gzip, deflate, br") - .SetQueryParam("token", _settings.ApiAccessToken) - .PostJsonAsync(new { matchId = matchId, results = results }); - } -} diff --git a/src/Modules/GeardownModule/Repositories/TourneyTimelineRepository.cs b/src/Modules/GeardownModule/Repositories/TourneyTimelineRepository.cs deleted file mode 100644 index ba9d0d6c1..000000000 --- a/src/Modules/GeardownModule/Repositories/TourneyTimelineRepository.cs +++ /dev/null @@ -1,20 +0,0 @@ -using EvoSC.Common.Database.Repository; -using EvoSC.Common.Interfaces.Database; -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; -using EvoSC.Modules.Evo.GeardownModule.Models.Database; -using LinqToDB; - -namespace EvoSC.Modules.Evo.GeardownModule.Repositories; - -[Service(LifeStyle = ServiceLifeStyle.Transient)] -public class TourneyTimelineRepository : DbRepository, ITourneyTimelineRepository -{ - public TourneyTimelineRepository(IDbConnectionFactory dbConnFactory) : base(dbConnFactory) - { - } - - public Task AddTimelineAsync(int matchId, Guid timelineId) => - Database.InsertAsync(new DbTourneyTimeline { MatchId = matchId, TimelineId = timelineId }); -} diff --git a/src/Modules/GeardownModule/Services/GeardownApiService.cs b/src/Modules/GeardownModule/Services/GeardownApiService.cs deleted file mode 100644 index eb0722d26..000000000 --- a/src/Modules/GeardownModule/Services/GeardownApiService.cs +++ /dev/null @@ -1,20 +0,0 @@ -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Services; -using EvoSC.Modules.Evo.GeardownModule.Repositories; -using EvoSC.Modules.Evo.GeardownModule.Settings; - -namespace EvoSC.Modules.Evo.GeardownModule.Services; - -[Service(LifeStyle = ServiceLifeStyle.Transient)] -public class GeardownApiService : IGeardownApiService -{ - public IGeardownMatchApi Matches { get; } - - public GeardownApiService(IGeardownSettings settings) - { - Matches = new GeardownMatchApi(settings); - } -} diff --git a/src/Modules/GeardownModule/Services/GeardownService.cs b/src/Modules/GeardownModule/Services/GeardownService.cs deleted file mode 100644 index 41936e5b5..000000000 --- a/src/Modules/GeardownModule/Services/GeardownService.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System.Text.Json; -using EvoSC.Common.Interfaces; -using EvoSC.Common.Interfaces.Services; -using EvoSC.Common.Models; -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Services; -using EvoSC.Modules.Evo.GeardownModule.Models; -using EvoSC.Modules.Evo.GeardownModule.Models.API; -using EvoSC.Modules.Evo.GeardownModule.Settings; -using EvoSC.Modules.Official.MatchReadyModule.Interfaces; -using EvoSC.Modules.Official.MatchTrackerModule.Interfaces; -using EvoSC.Modules.Official.MatchTrackerModule.Interfaces.Models; -using MatchStatus = EvoSC.Modules.Official.MatchTrackerModule.Models.MatchStatus; - -namespace EvoSC.Modules.Evo.GeardownModule.Services; - -[Service(LifeStyle = ServiceLifeStyle.Transient)] -public class GeardownService : IGeardownService -{ - private readonly IMatchTracker _matchTracker; - private readonly IGeardownSetupService _setupService; - private readonly IGeardownApiService _geardownApi; - private readonly IAuditService _audits; - private readonly IServerClient _server; - private readonly IPlayerReadyService _playerReadyService; - private readonly IGeardownSettings _settings; - private readonly IGeardownSetupStateService _setupState; - private readonly ITourneyTimelineRepository _tourneyTimelineRepository; - - public GeardownService(IMatchTracker matchTracker, IGeardownSetupService setupService, - IGeardownApiService geardownApi, IAuditService auditService, IServerClient server, - IPlayerReadyService playerReadyService, IGeardownSettings settings, IGeardownSetupStateService setupState, ITourneyTimelineRepository tourneyTimelineRepository) - { - _matchTracker = matchTracker; - _setupService = setupService; - _geardownApi = geardownApi; - _audits = auditService; - _server = server; - _playerReadyService = playerReadyService; - _settings = settings; - _setupService = setupService; - _setupState = setupState; - _tourneyTimelineRepository = tourneyTimelineRepository; - } - - public async Task SetupServerAsync(int matchId) - { - var (match, token) = await _setupService.InitialSetupAsync(matchId); - - _audits.NewInfoEvent("Geardown.ServerSetup") - .HavingProperties(new { Match = match, MatchToken = token }) - .Comment("Server was setup through geardown."); - } - - public Task FinishServerSetupAsync() => _setupService.FinalizeSetupAsync(); - - public async Task StartMatchAsync() - { - // create a new timeline and get the tracking ID - var matchTrackerId = await _matchTracker.BeginMatchAsync(); - await _server.Remote.RestartMapAsync(); - - // disable the ready widget - await _playerReadyService.SetWidgetEnabled(false); - - await _server.InfoMessageAsync("Match is about to begin ..."); - - // obtain the current match details - var matchState = JsonSerializer.Deserialize(_settings.MatchState); - - if (matchState == null) - { - throw new InvalidOperationException("Failed to obtain current match state from settings."); - } - - _setupState.SetMatchStarted(); - - // create a relation for the match and the timeline - if (matchState.Match.id != null) - { - await _tourneyTimelineRepository.AddTimelineAsync((int)matchState.Match.id, matchTrackerId); - } - - // notify geardown that the match has started - await _geardownApi.Matches.OnStartMatchAsync(matchState.MatchToken); - - _audits.NewInfoEvent("Geardown.StartMatch") - .HavingProperties(new { MatchTrackingId = matchTrackerId }) - .Comment("Match was started."); - } - - public async Task EndMatchAsync(IMatchTimeline timeline) - { - await _playerReadyService.SetWidgetEnabled(false); - await SendResultsAsync(timeline); - - await _server.SuccessMessageAsync("Match finished, thanks for playing!"); - } - - public MatchStatus GetMatchStatus() - { - return _matchTracker.Status; - } - - private async Task SendResultsAsync(IMatchTimeline timeline) - { - // get the current match details - var matchState = JsonSerializer.Deserialize(_settings.MatchState); - - if (matchState?.Match?.participants?.FirstOrDefault()?.user?.tm_account_id == null) - { - throw new InvalidOperationException("The match state is invalid, failed to send results."); - } - - // obtain match results - var results = timeline.States.LastOrDefault(s => s.Status == MatchStatus.Running) as IScoresMatchState; - - if (results == null || results.Section != ModeScriptSection.EndMatch) - { - throw new InvalidOperationException("Did not get a match end result to send to geardown."); - } - - if (matchState.Match.id == null) - { - throw new InvalidOperationException("Match Id is null, cannot send results to geardown."); - } - - // send match results to geardown - await _geardownApi.Matches.AddResultsAsync((int)matchState.Match.id, - results.Players.Select(r => new GdResult - { - account_id = r.Player.AccountId, - score = r.MatchPoints - })); - - // notify geardown that the match has ended - await _geardownApi.Matches.OnEndMatchAsync(matchState.MatchToken); - } -} diff --git a/src/Modules/GeardownModule/Services/GeardownSetupService.cs b/src/Modules/GeardownModule/Services/GeardownSetupService.cs deleted file mode 100644 index 535293f8b..000000000 --- a/src/Modules/GeardownModule/Services/GeardownSetupService.cs +++ /dev/null @@ -1,354 +0,0 @@ -using System.Globalization; -using System.Text.Json; -using EvoSC.Common.Interfaces; -using EvoSC.Common.Interfaces.Database.Repository; -using EvoSC.Common.Interfaces.Models; -using EvoSC.Common.Interfaces.Services; -using EvoSC.Common.Models.Maps; -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Common.Util; -using EvoSC.Common.Util.MatchSettings; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Services; -using EvoSC.Modules.Evo.GeardownModule.Models; -using EvoSC.Modules.Evo.GeardownModule.Models.API; -using EvoSC.Modules.Evo.GeardownModule.Settings; -using EvoSC.Modules.Evo.GeardownModule.Util; -using EvoSC.Modules.Official.MatchReadyModule.Interfaces; -using GbxRemoteNet; -using ManiaExchange.ApiClient; - -namespace EvoSC.Modules.Evo.GeardownModule.Services; - -[Service(LifeStyle = ServiceLifeStyle.Transient)] -public class GeardownSetupService : IGeardownSetupService -{ - private readonly IMapService _maps; - private readonly IMatchSettingsService _matchSettings; - private readonly IGeardownApiService _geardownApi; - private readonly IServerClient _server; - private readonly IGeardownSettings _settings; - private readonly IPlayerReadyService _playerReadyService; - private readonly IPlayerReadyTrackerService _playerReadyTracker; - private readonly IPlayerManagerService _players; - private readonly IGeardownSetupStateService _setupState; - private readonly IPlayerRepository _playerRepo; - - public GeardownSetupService(IGeardownApiService geardownApi, IMapService maps, IMatchSettingsService matchSettings, - IServerClient server, IGeardownSettings settings, IPlayerReadyService playerReadyService, - IPlayerReadyTrackerService playerReadyTracker, IPlayerManagerService players, IGeardownSetupStateService setupState, - IPlayerRepository playerRepo) - { - _geardownApi = geardownApi; - _maps = maps; - _matchSettings = matchSettings; - _server = server; - _settings = settings; - _playerReadyService = playerReadyService; - _playerReadyTracker = playerReadyTracker; - _players = players; - _setupState = setupState; - _playerRepo = playerRepo; - } - - public async Task<(GdMatch match, string token)> InitialSetupAsync(int matchId) - { - // generate a match token and assign this server to the provided match - var token = await AssignServerToMatchAsync(matchId); - - if (token == null) - { - throw new InvalidOperationException($"Failed to assign server to match {matchId}. Token returned is null."); - } - - // get match information such as format, maps, participants etc. - var match = await GetMatchInfoAsync(token.EvoScToken); - var maps = await GetMatchMapsAsync(match); - var matchSettingsName = await CreateMatchSettingsAsync(match, maps); - - _settings.MatchState = JsonSerializer.Serialize(new GeardownMatchState - { - Match = match, - MatchToken = token.EvoScToken - }); - - var players = (await GetParticipantPlayersAsync(match)).ToArray(); - - if (!players.Any()) - { - throw new InvalidOperationException($"No participants found for match {match.id} ({match.name})."); - } - - // whitelist players and spectators - await SetupPlayersAndSpectatorsAsync(players); - - // load the match settings and skip to the first map - await _matchSettings.LoadMatchSettingsAsync(matchSettingsName); - - await _server.Remote.SetServerNameAsync(match.name); - - if (players.Length <= 4) - { - await SetupReadyWidgetAsync(players); - } - - _setupState.SetInitialSetup(matchSettingsName); - - return (match, token.EvoScToken); - } - - public async Task FinalizeSetupAsync() - { - if (!_setupState.IsInitialSetup) - { - return; - } - - _setupState.SetSetupFinished(); - - // load match settings again to make sure its properly loaded - await _matchSettings.LoadMatchSettingsAsync(_setupState.MatchSettingsName, false); - await _server.Remote.RestartMapAsync(); - } - - private async Task SetupReadyWidgetAsync(IPlayer[] players) - { - await _playerReadyService.ResetReadyWidgetAsync(true); - await _playerReadyTracker.AddRequiredPlayersAsync(players); - await _playerReadyService.SetWidgetEnabled(true); - - var onlinePlayers = (await _players.GetOnlinePlayersAsync()).ToArray(); - - foreach (var player in onlinePlayers) - { - await _playerReadyService.SendWidgetAsync(player); - } - } - - private async Task SetupPlayersAndSpectatorsAsync(IEnumerable players) - { - await _server.Remote.CleanGuestListAsync(); - await WhitelistPlayers(players); - await WhitelistSpectators(); - await _server.Remote.SetMaxPlayersAsync(0); - } - - private async Task WhitelistPlayers(IEnumerable players) - { - var multiCall = new MultiCall(); - - foreach (var player in players) - { - multiCall.Add("AddGuest", player.GetLogin()); - } - - await _server.Remote.MultiCallAsync(multiCall); - } - - private async Task WhitelistSpectators() - { - var multiCall = new MultiCall(); - foreach (var accountId in _settings.Whitelist.Split(',')) - { - var login = PlayerUtils.ConvertAccountIdToLogin(accountId); - // await _server.Remote.AddGuestAsync(login); - multiCall.Add("AddGuest", login); - } - - await _server.Remote.MultiCallAsync(multiCall); - } - - private async Task GetMatchMapsAsync(GdMatch? match) - { - var maps = (await GetMapsAsync(match)).ToArray(); - - if (!maps.Any()) - { - throw new InvalidOperationException("Did not find any maps for this match."); - } - - return maps; - } - - private async Task DownloadAndAddMap(GdMapPoolOrder mapPoolMap) - { - var tmxApi = new MxTmApi("EvoSC# Geardown Integration"); - var tmxId = (long?)mapPoolMap.mx_map_id ?? 0; - - var mapInfo = await tmxApi.GetMapInfoAsync(tmxId); - - if (mapInfo == null) - { - throw new InvalidOperationException( - $"Failed to get map info for the map with pool ID {mapPoolMap.map_pool_id} and TMX ID {tmxId}."); - } - - var mapFile = await tmxApi.DownloadMapAsync(tmxId, ""); - - if (mapFile == null) - { - throw new InvalidOperationException( - $"Failed to download the map with pool ID {mapPoolMap.map_pool_id} and TMX ID {tmxId}."); - } - - var mapMetaInfo = new MapMetadata - { - MapUid = mapInfo.TrackUID, - MapName = mapInfo.GbxMapName, - AuthorId = mapInfo.AuthorLogin, - AuthorName = mapInfo.Username, - ExternalId = mapInfo.TrackID.ToString(), - ExternalVersion = Convert.ToDateTime(mapInfo.UpdatedAt, NumberFormatInfo.InvariantInfo).ToUniversalTime(), - ExternalMapProvider = MapProviders.ManiaExchange - }; - - var mapStream = new MapStream(mapMetaInfo, mapFile); - return await _maps.AddMapAsync(mapStream); - } - - private async Task> GetMapsAsync(GdMatch match) - { - if (match.map_pool_orders == null || match.map_pool_orders.Count == 0) - { - throw new InvalidOperationException("No maps found for this match. Did you add them on geardown or forgot to give them an order?"); - } - - var maps = new List(); - - foreach (var mapPoolMap in match.map_pool_orders) - { - if (mapPoolMap.mx_map_id == null) - { - throw new InvalidOperationException($"The map with pool ID {mapPoolMap.map_pool_id} does not have a TMX id."); - } - - var map = await _maps.GetMapByExternalIdAsync(mapPoolMap.mx_map_id.ToString() ?? "") ?? - await DownloadAndAddMap(mapPoolMap); - - maps.Add(map); - } - - return maps; - } - - private async Task CreateMatchSettingsAsync(GdMatch match, IEnumerable maps) - { - if (match.formats == null || match.formats.Count == 0) - { - throw new InvalidOperationException("No formats has been assigned to this match, did you assign one to the match at geardown?"); - } - - var format = match.formats.First(); - var name = $"geardown_{format.id}"; - - var mapsToAdd = new List(); - - foreach (var map in maps) - { - try - { - var serverMap = await _server.Remote.GetMapInfoAsync(map.FilePath); - - if (serverMap != null) - { - mapsToAdd.Add(map); - } - } - catch (Exception) - { - // do nothing - } - } - - await _matchSettings.CreateMatchSettingsAsync(name, builder => - { - var mode = format.type_id switch - { - FormatType.Rounds => DefaultModeScriptName.Rounds, - FormatType.Cup => DefaultModeScriptName.Cup, - FormatType.TimeAttack => DefaultModeScriptName.TimeAttack, - FormatType.Knockout => DefaultModeScriptName.Knockout, - FormatType.Laps => DefaultModeScriptName.Laps, - FormatType.Team => DefaultModeScriptName.Teams, - _ => DefaultModeScriptName.TimeAttack - }; - - builder.WithMode(mode); - builder.WithModeSettings(s => - { - if (format.match_settings == null) - { - return; - } - - foreach (var setting in format.match_settings) - { - s[setting.key] = MatchSettingsTypeUtils.ConvertToCorrectType(setting.key, setting.value).GetAwaiter().GetResult(); - } - }); - - builder.WithMaps(mapsToAdd); - builder.WithFilter(f => f.AsRandomMapOrder(true)); - }); - - return name; - } - - private async Task AssignServerToMatchAsync(int matchId) - { - var password = await _server.Remote.GetServerPasswordAsync(); - var name = await _server.Remote.GetServerNameAsync() ?? "Server"; - var mainServerPlayer = await _server.Remote.GetMainServerPlayerInfoAsync(0); - - if (string.IsNullOrEmpty(password)) - { - password = null; - } - - return await _geardownApi.Matches.AssignServerAsync(matchId, name, mainServerPlayer.Login, password); - } - - private async Task> GetParticipantPlayersAsync(GdMatch match) - { - if (match.participants == null) - { - throw new InvalidOperationException("No participants found for this match."); - } - - var players = new List(); - - foreach (var participant in match.participants) - { - if (participant.user == null) - { - throw new InvalidOperationException( - $"Participant with ID {participant.id} has no user account attached. Are they a real geardown user?"); - } - - if (string.IsNullOrEmpty(participant.user.tm_account_id)) - { - throw new InvalidOperationException( - $"Participant with ID {participant.id} (name: {participant.user.nickname}) has no TM account ID."); - } - - var player = await _players.GetOrCreatePlayerAsync(participant.user.tm_account_id); - await _playerRepo.UpdateNicknameAsync(player, participant.user.nickname ?? participant.user.tm_account_id); - players.Add(player); - } - - return players; - } - - private async Task GetMatchInfoAsync(string matchToken) - { - var match = await _geardownApi.Matches.GetMatchDataByTokenAsync(matchToken); - - if (match == null) - { - throw new InvalidOperationException("Failed to fetch match from geardown API."); - } - - return match; - } -} diff --git a/src/Modules/GeardownModule/Services/GeardownSetupStateService.cs b/src/Modules/GeardownModule/Services/GeardownSetupStateService.cs deleted file mode 100644 index c86c5189e..000000000 --- a/src/Modules/GeardownModule/Services/GeardownSetupStateService.cs +++ /dev/null @@ -1,106 +0,0 @@ -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Services; - -namespace EvoSC.Modules.Evo.GeardownModule.Services; - -[Service(LifeStyle = ServiceLifeStyle.Singleton)] -public class GeardownSetupStateService : IGeardownSetupStateService -{ - private bool _initialSetup; - private string _matchSettingsName = ""; - private readonly object _initialSetupLock = new(); - private bool _setupFinished; - private readonly object _setupFinishedLock = new(); - private bool _waitingForMatchStart; - private readonly object _waitingForMatchStartLock = new(); - - public bool IsInitialSetup - { - get - { - lock (_initialSetupLock) - { - return _initialSetup; - } - } - } - - public string MatchSettingsName - { - get - { - lock (_initialSetupLock) - { - return _matchSettingsName; - } - } - } - - public bool SetupFinished - { - get - { - lock (_setupFinishedLock) - { - return _setupFinished; - } - } - } - - public bool WaitingForMatchStart - { - get - { - lock (_waitingForMatchStartLock) - { - return _waitingForMatchStart; - } - } - } - - public void SetInitialSetup(string matchSettingsName) - { - lock (_initialSetupLock) - { - _initialSetup = true; - _matchSettingsName = matchSettingsName; - } - - lock (_setupFinishedLock) - { - _setupFinished = false; - } - - lock (_waitingForMatchStartLock) - { - _waitingForMatchStart = false; - } - } - - public void SetSetupFinished() - { - lock (_initialSetupLock) - { - _initialSetup = false; - } - - lock (_setupFinishedLock) - { - _setupFinished = true; - } - - lock (_waitingForMatchStartLock) - { - _waitingForMatchStart = true; - } - } - - public void SetMatchStarted() - { - lock (_waitingForMatchStartLock) - { - _waitingForMatchStart = false; - } - } -} diff --git a/src/Modules/GeardownModule/Services/MatchManagementService.cs b/src/Modules/GeardownModule/Services/MatchManagementService.cs deleted file mode 100644 index 2b7c682f6..000000000 --- a/src/Modules/GeardownModule/Services/MatchManagementService.cs +++ /dev/null @@ -1,40 +0,0 @@ -using EvoSC.Common.Interfaces; -using EvoSC.Common.Interfaces.Models; -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Common.Util; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; - -namespace EvoSC.Modules.Evo.GeardownModule.Services; - -[Service(LifeStyle = ServiceLifeStyle.Transient)] -public class MatchManagementService : IMatchManagementService -{ - private readonly IServerClient _server; - - public MatchManagementService(IServerClient server) - { - _server = server; - } - - public Task SetPlayerPointsAsync(IPlayer player, int points) - { - return _server.Remote.TriggerModeScriptEventArrayAsync("Trackmania.SetPlayerPoints", player.GetLogin(), "", "", - points.ToString()); - } - - public Task PauseMatchAsync() - { - return _server.Remote.TriggerModeScriptEventArrayAsync("Maniaplanet.Pause.SetActive", "true"); - } - - public Task UnpauseMatchAsync() - { - return _server.Remote.TriggerModeScriptEventArrayAsync("Maniaplanet.Pause.SetActive", "false"); - } - - public Task SetServerNameAsync(string name) - { - return _server.Remote.SetServerNameAsync(name); - } -} diff --git a/src/Modules/GeardownModule/Settings/IGeardownSettings.cs b/src/Modules/GeardownModule/Settings/IGeardownSettings.cs deleted file mode 100644 index 5d71c97ea..000000000 --- a/src/Modules/GeardownModule/Settings/IGeardownSettings.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.ComponentModel; -using Config.Net; -using EvoSC.Modules.Attributes; -using LinqToDB.Common; - -namespace EvoSC.Modules.Evo.GeardownModule.Settings; - -[Settings] -public interface IGeardownSettings -{ - [Option(DefaultValue = false)] - public bool MatchBegin { get; set; } - - [Option, Description("The base URL for the geardown API.")] - public string ApiBaseUrl { get; set; } - - [Option, Description("The access token for the geardown API.")] - public string ApiAccessToken { get; set; } - - [Option, Description("List of player's account IDs which are always whitelisted for matches.")] - public string Whitelist { get; } - - [Option(DefaultValue = false), Description("Whether to start the match automatically when all players are ready.")] - public bool AutomaticMatchStart { get; set; } - - [Option, Description("The current match state object.")] - public string MatchState { get; set; } -} diff --git a/src/Modules/GeardownModule/Util/MatchSettingsTypeUtils.cs b/src/Modules/GeardownModule/Util/MatchSettingsTypeUtils.cs deleted file mode 100644 index 4744bd643..000000000 --- a/src/Modules/GeardownModule/Util/MatchSettingsTypeUtils.cs +++ /dev/null @@ -1,39 +0,0 @@ -using EvoSC.Common.Util.MatchSettings; - -namespace EvoSC.Modules.Evo.GeardownModule.Util; - -public static class MatchSettingsTypeUtils -{ - private static Dictionary s_settingsTypeMap = new() - { - {"S_ChatTime", typeof(int)}, - {"S_UseClublinks", typeof(bool)}, - {"S_UseClublinksSponsors", typeof(bool)}, - {"S_NeutralEmblemUrl", typeof(string)}, - {"S_IsChannelServer", typeof(bool)}, - {"S_AllowRespawn", typeof(bool)}, - {"S_RespawnBehaviour", typeof(int)}, - {"S_HideOpponents", typeof(bool)}, - {"S_PointsLimit", typeof(int)}, - {"S_FinishTimeout", typeof(int)}, - {"S_UseAlternateRules", typeof(bool)}, - {"S_ForceLapsNb", typeof(int)}, - {"S_DisplayTimeDiff", typeof(bool)}, - {"S_PointsRepartition", typeof(string)}, - {"S_RoundsPerMap", typeof(int)}, - {"S_NbOfWinners", typeof(int)}, - {"S_WarmUpNb", typeof(int)}, - {"S_WarmUpDuration", typeof(int)}, - {"S_TimeLimit", typeof(int)}, - {"S_DisableGiveUp", typeof(bool)}, - {"S_MapsPerMatch", typeof(int)}, - {"S_UseTieBreak", typeof(bool)}, - {"S_MaxPointsPerRound", typeof(int)}, - {"S_PointsGap", typeof(int)}, - {"S_UseCustomPointsRepartition", typeof(bool)}, - {"S_CumulatePoints", typeof(bool)} - }; - - public static Task ConvertToCorrectType(string name, string? value) => - MatchSettingsMapper.ToValueTypeAsync(s_settingsTypeMap[name], value); -} diff --git a/src/Modules/GeardownModule/info.toml b/src/Modules/GeardownModule/info.toml deleted file mode 100644 index 026cd3d32..000000000 --- a/src/Modules/GeardownModule/info.toml +++ /dev/null @@ -1,11 +0,0 @@ -[info] -name = "GeardownModule" -title = "Geardown" -summary = "Geardown integration." -version = "1.0.0" -author = "Evo" - -[dependencies] -MapsModule = "1.0.0" -MatchReadyModule = "1.0.0" -MatchTrackerModule = "1.0.0" diff --git a/src/Modules/XPEvoAdminControl/Controllers/AdminCpComController.cs b/src/Modules/XPEvoAdminControl/Controllers/AdminCpComController.cs deleted file mode 100644 index 4810fef62..000000000 --- a/src/Modules/XPEvoAdminControl/Controllers/AdminCpComController.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System.Text.Json; -using EvoSC.Common.Controllers; -using EvoSC.Common.Controllers.Attributes; -using EvoSC.Common.Events.Attributes; -using EvoSC.Common.Interfaces; -using EvoSC.Common.Interfaces.Controllers; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Official.XPEvoAdminControl.Events; -using EvoSC.Modules.Official.XPEvoAdminControl.Events.EventArgs; -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces; -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces.CpCom; -using EvoSC.Modules.Official.XPEvoAdminControl.Models.Dto; -using Microsoft.Extensions.Logging; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Controllers; - -[Controller] -public class AdminCpComController : EvoScController -{ - private readonly IServerClient _server; - private readonly ILogger _logger; - private readonly IGeardownService _geardown; - private readonly ICpComService _cpCom; - - public AdminCpComController(IServerClient server, ILogger logger, IGeardownService geardown, - ICpComService cpCom) - { - _server = server; - _logger = logger; - _geardown = geardown; - _cpCom = cpCom; - } - - [Subscribe(AdminCpEvents.Action)] - public Task OnAction(object sender, CpComActionEventArgs args) - { - switch (args.Action.Action) - { - case "AssignServer": - return AssignServerActionAsync(args.Action); - case "RestartMatch": - return RestartMatchAsync(args.Action); - case "StartMatch": - return StartMatchAsync(args.Action); - default: - return Task.CompletedTask; - } - } - - private async Task StartMatchAsync(ICpAction action) - { - try - { - await _geardown.StartMatchAsync(); - await _cpCom.RespondSuccessAsync(action.ActionId); - } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to start match."); - await _cpCom.RespondErrorAsync(ex.Message, action.ActionId); - } - } - - private async Task RestartMatchAsync(ICpAction action) - { - try - { - await _server.Remote.RestartMapAsync(); - await _cpCom.RespondSuccessAsync(action.ActionId); - } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to restart match."); - await _cpCom.RespondErrorAsync(ex.Message, action.ActionId); - } - } - - private async Task AssignServerActionAsync(ICpAction action) - { - var data = ((JsonElement)action.Data).Deserialize(); - - if (data == null) - { - await _cpCom.RespondErrorAsync("Invalid action data.", action.ActionId); - _logger.LogError("Invalid action data for assign server."); - return; - } - - if (data.MatchId <= 0) - { - await _cpCom.RespondErrorAsync($"Invalid match ID: ${data.MatchId}", action.ActionId); - _logger.LogError("Invalid match id for assign server: {MatchId}", data.MatchId); - return; - } - - try - { - await _geardown.SetupServerAsync(data.MatchId); - await _cpCom.RespondSuccessAsync(action.ActionId); - } - catch (Exception ex) - { - await _cpCom.RespondErrorAsync($"Failed to setup match (ID: {data.MatchId}): " + ex.Message, action.ActionId); - _logger.LogError(ex, "Failed to setup server for match ID: {MatchId}", data.MatchId); - } - } -} diff --git a/src/Modules/XPEvoAdminControl/Events/AdminCpEvents.cs b/src/Modules/XPEvoAdminControl/Events/AdminCpEvents.cs deleted file mode 100644 index d33c7b3e2..000000000 --- a/src/Modules/XPEvoAdminControl/Events/AdminCpEvents.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace EvoSC.Modules.Official.XPEvoAdminControl.Events; - -public enum AdminCpEvents -{ - Action -} diff --git a/src/Modules/XPEvoAdminControl/Events/EventArgs/CpComActionEventArgs.cs b/src/Modules/XPEvoAdminControl/Events/EventArgs/CpComActionEventArgs.cs deleted file mode 100644 index f14e6a426..000000000 --- a/src/Modules/XPEvoAdminControl/Events/EventArgs/CpComActionEventArgs.cs +++ /dev/null @@ -1,8 +0,0 @@ -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces.CpCom; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Events.EventArgs; - -public class CpComActionEventArgs : System.EventArgs -{ - public ICpAction Action { get; init; } -} diff --git a/src/Modules/XPEvoAdminControl/Interfaces/CpCom/ICpAction.cs b/src/Modules/XPEvoAdminControl/Interfaces/CpCom/ICpAction.cs deleted file mode 100644 index 5bc89adde..000000000 --- a/src/Modules/XPEvoAdminControl/Interfaces/CpCom/ICpAction.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace EvoSC.Modules.Official.XPEvoAdminControl.Interfaces.CpCom; - -public interface ICpAction -{ - public string AccessToken { get; set; } - public string Action { get; set; } - public object Data { get; set; } - - public Guid ActionId { get; set; } -} diff --git a/src/Modules/XPEvoAdminControl/Interfaces/ICpComService.cs b/src/Modules/XPEvoAdminControl/Interfaces/ICpComService.cs deleted file mode 100644 index 8c4f515aa..000000000 --- a/src/Modules/XPEvoAdminControl/Interfaces/ICpComService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces.CpCom; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Interfaces; - -public interface ICpComService -{ - public Task RespondAsync(ICpAction action, Guid actionId); - public Task UpdateAsync(ICpAction action); - public Task RespondErrorAsync(string message, Guid actionId); - public Task RespondSuccessAsync(Guid actionId); -} diff --git a/src/Modules/XPEvoAdminControl/Interfaces/IProblemService.cs b/src/Modules/XPEvoAdminControl/Interfaces/IProblemService.cs deleted file mode 100644 index a7f36c1c6..000000000 --- a/src/Modules/XPEvoAdminControl/Interfaces/IProblemService.cs +++ /dev/null @@ -1,10 +0,0 @@ -using EvoSC.Common.Interfaces.Models; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Interfaces; - -public interface IProblemService -{ - public void SetProblem(IPlayer player, bool isProblem); - - public IEnumerable GetPlayersWithAProblem(); -} diff --git a/src/Modules/XPEvoAdminControl/Localization.resx b/src/Modules/XPEvoAdminControl/Localization.resx deleted file mode 100644 index f2bbd290f..000000000 --- a/src/Modules/XPEvoAdminControl/Localization.resx +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Hello {0} - - \ No newline at end of file diff --git a/src/Modules/XPEvoAdminControl/Models/CpCom/CpAction.cs b/src/Modules/XPEvoAdminControl/Models/CpCom/CpAction.cs deleted file mode 100644 index e09edac12..000000000 --- a/src/Modules/XPEvoAdminControl/Models/CpCom/CpAction.cs +++ /dev/null @@ -1,10 +0,0 @@ -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces.CpCom; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Models.CpCom; - -public class CpAction : ICpAction { - public string AccessToken { get; set; } - public string Action { get; set; } - public object Data { get; set; } - public Guid ActionId { get; set; } -} diff --git a/src/Modules/XPEvoAdminControl/Models/Dto/CpActionAssignServerDto.cs b/src/Modules/XPEvoAdminControl/Models/Dto/CpActionAssignServerDto.cs deleted file mode 100644 index 3b8fb3dcc..000000000 --- a/src/Modules/XPEvoAdminControl/Models/Dto/CpActionAssignServerDto.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace EvoSC.Modules.Official.XPEvoAdminControl.Models.Dto; - -public class CpActionAssignServerDto -{ - public int MatchId { get; set; } -} diff --git a/src/Modules/XPEvoAdminControl/Models/MatchServerStatus.cs b/src/Modules/XPEvoAdminControl/Models/MatchServerStatus.cs deleted file mode 100644 index 518ae07fb..000000000 --- a/src/Modules/XPEvoAdminControl/Models/MatchServerStatus.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace EvoSC.Modules.Official.XPEvoAdminControl.Models; - -public enum MatchServerStatus -{ - Unknown = 0, - Waiting = 1, - Ready = 2, - Running = 3, - Paused = 4, - Finished = 5, - Problem = 6 -} diff --git a/src/Modules/XPEvoAdminControl/Services/CpComBackgroundService.cs b/src/Modules/XPEvoAdminControl/Services/CpComBackgroundService.cs deleted file mode 100644 index 5759641c5..000000000 --- a/src/Modules/XPEvoAdminControl/Services/CpComBackgroundService.cs +++ /dev/null @@ -1,97 +0,0 @@ -using EvoSC.Common.Interfaces.Services; -using EvoSC.Common.Services.Attributes; -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces; -using EvoSC.Common.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Interfaces; -using EvoSC.Modules.Evo.GeardownModule.Interfaces.Services; -using EvoSC.Modules.Official.MatchTrackerModule.Models; -using EvoSC.Modules.Official.XPEvoAdminControl.Models; -using EvoSC.Modules.Official.XPEvoAdminControl.Models.CpCom; -using Microsoft.Extensions.Logging; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Services; - -[Service] -public class CpComBackgroundService : IBackgroundService -{ - private readonly ICpComService _cpComService; - private readonly IGeardownService _geardown; - private readonly IGeardownSetupStateService _geardownState; - private readonly IProblemService _problems; - private readonly IServerClient _server; - private readonly ILogger _logger; - - private Task _updateTask; - private readonly CancellationTokenSource _cancelSource = new(); - - public CpComBackgroundService(ICpComService cpComService, IGeardownService geardown, - IGeardownSetupStateService geardownState, IProblemService problems, IServerClient server, - ILogger logger) - { - _cpComService = cpComService; - _geardown = geardown; - _geardownState = geardownState; - _problems = problems; - _server = server; - _logger = logger; - } - - public Task StartAsync() - { - _updateTask = Task.Run(UpdateStatus); - - return Task.CompletedTask; - } - - private async Task UpdateStatus() - { - while (!_cancelSource.IsCancellationRequested) - { - try - { - var matchStatus = _geardown.GetMatchStatus(); - - var status = matchStatus switch - { - MatchStatus.Running => MatchServerStatus.Running, - MatchStatus.Ended => MatchServerStatus.Finished, - MatchStatus.Started => MatchServerStatus.Running, - MatchStatus.UnPaused => MatchServerStatus.Running, - _ => MatchServerStatus.Unknown - }; - - var pauseStatus = await _server.Remote.GetModeScriptResponseAsync("Maniaplanet.Pause.GetStatus"); - - if (_geardownState.WaitingForMatchStart) - { - status = MatchServerStatus.Ready; - } - - if (!_geardownState.SetupFinished) - { - status = MatchServerStatus.Waiting; - } - - if (_problems.GetPlayersWithAProblem().Any()) - { - status = MatchServerStatus.Problem; - } - - await _cpComService.UpdateAsync(new CpAction { Action = "Status", Data = status }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Failed to update status."); - } - - await Task.Delay(TimeSpan.FromSeconds(3)); - } - } - - public async Task StopAsync() - { - _cancelSource.Cancel(); - await _updateTask; - } -} - diff --git a/src/Modules/XPEvoAdminControl/Services/CpComService.cs b/src/Modules/XPEvoAdminControl/Services/CpComService.cs deleted file mode 100644 index 34428608b..000000000 --- a/src/Modules/XPEvoAdminControl/Services/CpComService.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System.Text.Json; -using EvoSC.Common.Interfaces; -using EvoSC.Common.Remote; -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Modules.Official.XPEvoAdminControl.Events; -using EvoSC.Modules.Official.XPEvoAdminControl.Events.EventArgs; -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces; -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces.CpCom; -using EvoSC.Modules.Official.XPEvoAdminControl.Models.CpCom; -using GbxRemoteNet.Events; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Services; - -[Service(LifeStyle = ServiceLifeStyle.Singleton)] -public class CpComService : ICpComService -{ - public const string ActionPrefix = "XPEvoAdminAction"; - - private readonly IServerClient _server; - private readonly IEventManager _events; - - public CpComService(IServerClient server, IEventManager events) - { - _server = server; - _events = events; - - _events.Subscribe(s => s - .WithEvent(GbxRemoteEvent.Echo) - .WithInstance(this) - .WithInstanceClass() - .WithHandlerMethod(OnEcho) - .AsAsync() - ); - } - - public Task RespondAsync(ICpAction action, Guid actionId) - { - action.ActionId = actionId; - var packet = JsonSerializer.Serialize((object)action); - return _server.Remote.EchoAsync($"XPEvoAdminAction.Response", packet); - } - - public Task UpdateAsync(ICpAction action) - { - var packet = JsonSerializer.Serialize((object)action); - return _server.Remote.EchoAsync($"XPEvoAdminAction.Update", packet); - } - - public Task RespondErrorAsync(string message, Guid actionId) => - RespondAsync(new CpAction - { - AccessToken = null, - Action = $"{ActionPrefix}.Response", - Data = new - { - Success = false, - ErrorMessage = message - } - }, actionId); - - public Task RespondSuccessAsync(Guid actionId) => - RespondAsync(new CpAction - { - AccessToken = null, - Action = $"{ActionPrefix}.Response", - Data = new { Success = true } - }, actionId); - - - private async Task OnEcho(object sender, EchoGbxEventArgs args) - { - if (!args.PublicParam.StartsWith(ActionPrefix) || args.PublicParam.Length <= ActionPrefix.Length) - { - return; - } - - var action = args.PublicParam.Substring(ActionPrefix.Length + 1); - - if (action == "Response" || action == "Update") - { - return; - } - - var actionInfo = JsonSerializer.Deserialize(args.InternalParam); - - await _events.RaiseAsync(AdminCpEvents.Action, new CpComActionEventArgs { Action = actionInfo }, this); - } -} diff --git a/src/Modules/XPEvoAdminControl/Services/ProblemService.cs b/src/Modules/XPEvoAdminControl/Services/ProblemService.cs deleted file mode 100644 index 6e7c1fe3c..000000000 --- a/src/Modules/XPEvoAdminControl/Services/ProblemService.cs +++ /dev/null @@ -1,36 +0,0 @@ -using EvoSC.Common.Interfaces.Models; -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Modules.Official.XPEvoAdminControl.Interfaces; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Services; - -[Service(LifeStyle = ServiceLifeStyle.Singleton)] -public class ProblemService : IProblemService -{ - private readonly HashSet _playersWithProblems = new(); - private readonly object _playersWithProblemsLock = new(); - - public void SetProblem(IPlayer player, bool isProblem) - { - lock (_playersWithProblemsLock) - { - if (isProblem) - { - _playersWithProblems.Add(player); - } - else if (_playersWithProblems.Contains(player)) - { - _playersWithProblems.Remove(player); - } - } - } - - public IEnumerable GetPlayersWithAProblem() - { - lock (_playersWithProblemsLock) - { - return _playersWithProblems.ToList(); - } - } -} diff --git a/src/Modules/XPEvoAdminControl/Settings/IXPEvoAdminSettings.cs b/src/Modules/XPEvoAdminControl/Settings/IXPEvoAdminSettings.cs deleted file mode 100644 index 643a056d6..000000000 --- a/src/Modules/XPEvoAdminControl/Settings/IXPEvoAdminSettings.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.ComponentModel; -using Config.Net; -using EvoSC.Modules.Attributes; - -namespace EvoSC.Modules.Official.XPEvoAdminControl.Settings; - -[Settings] -public interface IXPEvoAdminSettings -{ - [Option(DefaultValue = "test"), Description("The access token required to access this server.")] - public string AccessToken { get; set; } -} diff --git a/src/Modules/XPEvoAdminControl/XPEvoAdminControl.cs b/src/Modules/XPEvoAdminControl/XPEvoAdminControl.cs deleted file mode 100644 index af8728b56..000000000 --- a/src/Modules/XPEvoAdminControl/XPEvoAdminControl.cs +++ /dev/null @@ -1,8 +0,0 @@ -using EvoSC.Modules.Attributes; - -namespace EvoSC.Modules.Official.XPEvoAdminControl; - -[Module(IsInternal = true)] -public class XPEvoAdminControl : EvoScModule -{ -} diff --git a/src/Modules/XPEvoAdminControl/XPEvoAdminControl.csproj b/src/Modules/XPEvoAdminControl/XPEvoAdminControl.csproj deleted file mode 100644 index 6baecb875..000000000 --- a/src/Modules/XPEvoAdminControl/XPEvoAdminControl.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - net7.0 - enable - enable - EvoSC.Modules.Official.XPEvoAdminControl - false - XPEvoAdminControl - MyModule - This is my awesome module. - 1.0.0 - Me - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Modules/XPEvoAdminControl/info.toml b/src/Modules/XPEvoAdminControl/info.toml deleted file mode 100644 index 155323b28..000000000 --- a/src/Modules/XPEvoAdminControl/info.toml +++ /dev/null @@ -1,9 +0,0 @@ -[info] -name = "XPEvoAdminControl" -title = "MyModule" -summary = "This is my awesome module." -version = "1.0.0" -author = "Me" - -[dependencies] -GeardownModule = "1.0.0" From 7157fb3be44596b2e21afe5176115e56454e66bb Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:13:35 +0200 Subject: [PATCH 03/12] remove references from xpevo admin and geardown module --- src/EvoSC/InternalModules.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/EvoSC/InternalModules.cs b/src/EvoSC/InternalModules.cs index 96d864f16..916497b71 100644 --- a/src/EvoSC/InternalModules.cs +++ b/src/EvoSC/InternalModules.cs @@ -1,5 +1,4 @@ using EvoSC.Common.Interfaces; -using EvoSC.Modules.Evo.GeardownModule; using EvoSC.Modules.Interfaces; using EvoSC.Modules.Official.OpenPlanetModule; using EvoSC.Modules.Official.CurrentMapModule; @@ -20,7 +19,6 @@ using EvoSC.Modules.Official.SetName; using EvoSC.Modules.Official.SponsorsModule; using EvoSC.Modules.Official.WorldRecordModule; -using EvoSC.Modules.Official.XPEvoAdminControl; using FluentMigrator.Runner.Exceptions; using SpectatorTargetInfo; @@ -44,8 +42,6 @@ public static class InternalModules typeof(OpenPlanetModule), typeof(MatchTrackerModule), typeof(MatchReadyModule), - typeof(GeardownModule), - typeof(XPEvoAdminControl), typeof(NextMapModule), typeof(LiveRankingModule), typeof(MatchRankingModule), From b48205ecffce09e3526bababc9f0ae87e680cae3 Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:28:08 +0200 Subject: [PATCH 04/12] Initial cleanup of the World Record module --- src/EvoSC.Common/Util/RaceTime.cs | 3 +- .../Services/CurrentMapService.cs | 2 +- .../Controllers/WorldRecordEventController.cs | 12 +--- .../{ => Events}/WorldRecordEvents.cs | 2 +- ...oaded.cs => WorldRecordLoadedEventArgs.cs} | 5 +- .../Interfaces/IWorldRecord.cs | 11 ++++ .../Interfaces/IWorldRecordService.cs | 15 ++--- .../WorldRecordModule/Models/WorldRecord.cs | 16 ++--- .../Models/WorldRecordSource.cs | 8 +++ .../Services/WorldRecordService.cs | 66 ++++++++++++------- .../WorldRecordModule/WorldRecordModule.cs | 4 +- 11 files changed, 83 insertions(+), 61 deletions(-) rename src/Modules/WorldRecordModule/{ => Events}/WorldRecordEvents.cs (79%) rename src/Modules/WorldRecordModule/Events/{WorldRecordLoaded.cs => WorldRecordLoadedEventArgs.cs} (57%) create mode 100644 src/Modules/WorldRecordModule/Interfaces/IWorldRecord.cs create mode 100644 src/Modules/WorldRecordModule/Models/WorldRecordSource.cs diff --git a/src/EvoSC.Common/Util/RaceTime.cs b/src/EvoSC.Common/Util/RaceTime.cs index 68ca73341..73d1e3277 100644 --- a/src/EvoSC.Common/Util/RaceTime.cs +++ b/src/EvoSC.Common/Util/RaceTime.cs @@ -1,5 +1,4 @@ -using System.Runtime.Serialization; -using EvoSC.Common.Interfaces.Util; +using EvoSC.Common.Interfaces.Util; namespace EvoSC.Common.Util; diff --git a/src/Modules/CurrentMapModule/Services/CurrentMapService.cs b/src/Modules/CurrentMapModule/Services/CurrentMapService.cs index 631748481..e3c2306cd 100644 --- a/src/Modules/CurrentMapModule/Services/CurrentMapService.cs +++ b/src/Modules/CurrentMapModule/Services/CurrentMapService.cs @@ -57,7 +57,7 @@ private async Task ShowManialinkAsync(string mapUId) { var dbMap = await _mapRepository.GetMapByUidAsync(mapUId); var author = ""; - var worldRecord = await _worldRecordService.GetRecord(); + var worldRecord = await _worldRecordService.GetRecordAsync(); if (dbMap.Author.NickName == dbMap.Author.AccountId) { var serverMap = await _client.Remote.GetCurrentMapInfoAsync(); diff --git a/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs b/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs index b7502aed3..c2bb294be 100644 --- a/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs +++ b/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs @@ -13,20 +13,14 @@ public class WorldRecordEventController : EvoScController _worldRecordService = worldRecordService; - } - - //[Subscribe(ModeScriptEvent.Scores)] - //public Task OnScores(object sender, ScoresEventArgs scoresEventArgs) - // => _worldRecordService.DetectNewWorldRecordThroughScores(scoresEventArgs); [Subscribe(ModeScriptEvent.EndMapEnd)] public Task OnMapEnd(object sender, MapEventArgs mapEventArgs) - => _worldRecordService.ClearRecord(); + => _worldRecordService.ClearRecordAsync(); [Subscribe(ModeScriptEvent.StartMapStart)] public Task OnMapStart(object sender, MapEventArgs mapEventArgs) - => _worldRecordService.FetchRecord(mapEventArgs.Map.Uid); + => _worldRecordService.FetchRecordAsync(mapEventArgs.Map.Uid); } diff --git a/src/Modules/WorldRecordModule/WorldRecordEvents.cs b/src/Modules/WorldRecordModule/Events/WorldRecordEvents.cs similarity index 79% rename from src/Modules/WorldRecordModule/WorldRecordEvents.cs rename to src/Modules/WorldRecordModule/Events/WorldRecordEvents.cs index 4880ebb40..8de580fff 100644 --- a/src/Modules/WorldRecordModule/WorldRecordEvents.cs +++ b/src/Modules/WorldRecordModule/Events/WorldRecordEvents.cs @@ -1,6 +1,6 @@ using EvoSC.Common.Util.EnumIdentifier; -namespace EvoSC.Modules.Official.WorldRecordModule; +namespace EvoSC.Modules.Official.WorldRecordModule.Events; public enum WorldRecordEvents { diff --git a/src/Modules/WorldRecordModule/Events/WorldRecordLoaded.cs b/src/Modules/WorldRecordModule/Events/WorldRecordLoadedEventArgs.cs similarity index 57% rename from src/Modules/WorldRecordModule/Events/WorldRecordLoaded.cs rename to src/Modules/WorldRecordModule/Events/WorldRecordLoadedEventArgs.cs index 141c0e641..70ebfe098 100644 --- a/src/Modules/WorldRecordModule/Events/WorldRecordLoaded.cs +++ b/src/Modules/WorldRecordModule/Events/WorldRecordLoadedEventArgs.cs @@ -2,7 +2,10 @@ namespace EvoSC.Modules.Official.WorldRecordModule.Events; -public class WorldRecordLoaded: EventArgs +public class WorldRecordLoadedEventArgs: EventArgs { + /// + /// The world record that was loaded. + /// public required WorldRecord Record { get; init; } } diff --git a/src/Modules/WorldRecordModule/Interfaces/IWorldRecord.cs b/src/Modules/WorldRecordModule/Interfaces/IWorldRecord.cs new file mode 100644 index 000000000..8369812dc --- /dev/null +++ b/src/Modules/WorldRecordModule/Interfaces/IWorldRecord.cs @@ -0,0 +1,11 @@ +using EvoSC.Common.Interfaces.Util; +using EvoSC.Modules.Official.WorldRecordModule.Models; + +namespace EvoSC.Modules.Official.WorldRecordModule.Interfaces; + +public interface IWorldRecord +{ + public string PlayerName { get; init; } + public IRaceTime Time { get; init; } + public WorldRecordSource Source { get; init; } +} diff --git a/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs b/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs index 71ce6add4..dca17f43f 100644 --- a/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs +++ b/src/Modules/WorldRecordModule/Interfaces/IWorldRecordService.cs @@ -10,26 +10,19 @@ public interface IWorldRecordService /// /// The UID of the map to load records from. /// - public Task FetchRecord(string mapUid); - - /// - /// Overwrite the current record with the given one. - /// - /// The record to set. - /// - public Task OverwriteRecord(WorldRecord newRecord); + public Task FetchRecordAsync(string mapUid); /// /// Clears the currently loaded world record. /// /// - public Task ClearRecord(); + public Task ClearRecordAsync(); /// /// Gets the currently loaded world record or null. /// /// WR or null. - public Task GetRecord(); + public Task GetRecordAsync(); /// /// Goes through scores and checks whether the world record has been beaten. @@ -37,5 +30,5 @@ public interface IWorldRecordService /// /// The event args of the round scores. /// - Task DetectNewWorldRecordThroughScores(ScoresEventArgs scoresEventArgs); + Task DetectNewWorldRecordThroughScoresAsync(ScoresEventArgs scoresEventArgs); } diff --git a/src/Modules/WorldRecordModule/Models/WorldRecord.cs b/src/Modules/WorldRecordModule/Models/WorldRecord.cs index 61cecd33a..009e6cc8c 100644 --- a/src/Modules/WorldRecordModule/Models/WorldRecord.cs +++ b/src/Modules/WorldRecordModule/Models/WorldRecord.cs @@ -1,15 +1,11 @@ -using EvoSC.Common.Util; +using EvoSC.Common.Interfaces.Util; +using EvoSC.Modules.Official.WorldRecordModule.Interfaces; namespace EvoSC.Modules.Official.WorldRecordModule.Models; -public class WorldRecord +public class WorldRecord : IWorldRecord { - public required string Name { get; init; } - public required int Time { get; init; } - public required string Source { get; init; } - - public string FormattedTime() - { - return FormattingUtils.FormatTime(Time); - } + public required string PlayerName { get; init; } + public required IRaceTime Time { get; init; } + public required WorldRecordSource Source { get; init; } } diff --git a/src/Modules/WorldRecordModule/Models/WorldRecordSource.cs b/src/Modules/WorldRecordModule/Models/WorldRecordSource.cs new file mode 100644 index 000000000..6bfacd643 --- /dev/null +++ b/src/Modules/WorldRecordModule/Models/WorldRecordSource.cs @@ -0,0 +1,8 @@ +namespace EvoSC.Modules.Official.WorldRecordModule.Models; + +public enum WorldRecordSource +{ + Local, + AuthorTime, + TrackmaniaIo +} diff --git a/src/Modules/WorldRecordModule/Services/WorldRecordService.cs b/src/Modules/WorldRecordModule/Services/WorldRecordService.cs index 229fa25d1..d2ec2b06b 100644 --- a/src/Modules/WorldRecordModule/Services/WorldRecordService.cs +++ b/src/Modules/WorldRecordModule/Services/WorldRecordService.cs @@ -2,6 +2,7 @@ using EvoSC.Common.Remote.EventArgsModels; using EvoSC.Common.Services.Attributes; using EvoSC.Common.Services.Models; +using EvoSC.Common.Util; using EvoSC.Modules.Official.LiveRankingModule.Models; using EvoSC.Modules.Official.WorldRecordModule.Events; using EvoSC.Modules.Official.WorldRecordModule.Interfaces; @@ -29,7 +30,7 @@ public WorldRecordService(ILogger logger, IEventManager even _client = client; } - public async Task FetchRecord(string mapUid) + public async Task FetchRecordAsync(string mapUid) { TMioLeaderboardResponse? res = null; try @@ -46,7 +47,9 @@ public async Task FetchRecord(string mapUid) catch (FlurlHttpException ex) { _logger.LogError(ex, "Invalid response from Openplanet. Maybe API issues?"); + throw; } + _logger.LogDebug("Loaded records for map."); @@ -55,12 +58,17 @@ public async Task FetchRecord(string mapUid) var bestRecord = res.tops.First(); var newWorldRecord = new WorldRecord { - Name = bestRecord.player.name, Time = bestRecord.time, Source = "tm.io" + PlayerName = bestRecord.player.name, + Time = RaceTime.FromMilliseconds(bestRecord.time), + Source = WorldRecordSource.TrackmaniaIo }; - _logger.LogTrace("New world record loaded from tm.io: {name} -> {time}", newWorldRecord.Name, - newWorldRecord.FormattedTime()); - await OverwriteRecord(newWorldRecord); + _logger.LogTrace("New world record loaded from tm.io: {name} -> {time}", + newWorldRecord.PlayerName, + newWorldRecord.Time.ToString() + ); + + await OverwriteRecordAsync(newWorldRecord); } else { @@ -68,29 +76,19 @@ public async Task FetchRecord(string mapUid) var author = mapInfo.AuthorNickname.Length > 0 ? mapInfo.AuthorNickname : mapInfo.Author; var newWorldRecord = new WorldRecord { - Name = author, Time = mapInfo.AuthorTime, Source = "AT" + PlayerName = author, + Time = RaceTime.FromMilliseconds(mapInfo.AuthorTime), + Source = WorldRecordSource.AuthorTime }; _logger.LogDebug("Couldn't load World Record, using Author Time instead."); - await OverwriteRecord(newWorldRecord); + + await OverwriteRecordAsync(newWorldRecord); } } - public async Task OverwriteRecord(WorldRecord newRecord) - { - lock (_currentWorldRecordLock) - { - _currentWorldRecord = newRecord; - } - - await _events.RaiseAsync(WorldRecordEvents.NewRecord, new WorldRecordLoaded - { - Record = newRecord - }); - } - - public Task ClearRecord() + public Task ClearRecordAsync() { lock (_currentWorldRecordLock) { @@ -100,12 +98,12 @@ public Task ClearRecord() return Task.CompletedTask; } - public Task GetRecord() + public Task GetRecordAsync() { return Task.FromResult(_currentWorldRecord); } - public async Task DetectNewWorldRecordThroughScores(ScoresEventArgs scoresEventArgs) + public async Task DetectNewWorldRecordThroughScoresAsync(ScoresEventArgs scoresEventArgs) { if (_currentWorldRecord == null) { @@ -114,10 +112,28 @@ public async Task DetectNewWorldRecordThroughScores(ScoresEventArgs scoresEventA foreach (var score in scoresEventArgs.Players) { - if (score is { BestRaceTime: < 0 } && score.BestRaceTime < _currentWorldRecord.Time) + if (score is { BestRaceTime: < 0 } && score.BestRaceTime < _currentWorldRecord.Time.TotalMilliseconds) { - await OverwriteRecord(new WorldRecord { Name = score.Name, Time = score.BestRaceTime, Source = "local" }); + await OverwriteRecordAsync(new WorldRecord + { + PlayerName = score.Name, + Time = RaceTime.FromMilliseconds(score.BestRaceTime), + Source = WorldRecordSource.Local + }); } } } + + private async Task OverwriteRecordAsync(WorldRecord newRecord) + { + lock (_currentWorldRecordLock) + { + _currentWorldRecord = newRecord; + } + + await _events.RaiseAsync(WorldRecordEvents.NewRecord, new WorldRecordLoadedEventArgs + { + Record = newRecord + }); + } } diff --git a/src/Modules/WorldRecordModule/WorldRecordModule.cs b/src/Modules/WorldRecordModule/WorldRecordModule.cs index 924021382..f021b38d1 100644 --- a/src/Modules/WorldRecordModule/WorldRecordModule.cs +++ b/src/Modules/WorldRecordModule/WorldRecordModule.cs @@ -19,10 +19,12 @@ public WorldRecordModule(IWorldRecordService worldRecordService, IMapService map public async Task EnableAsync() { + // initially fetch the world record to be displayed var currentMap = await _mapService.GetCurrentMapAsync(); + if (currentMap != null) { - await _worldRecordService.FetchRecord(currentMap.Uid); + await _worldRecordService.FetchRecordAsync(currentMap.Uid); } } From d07c9aaf88c36d3ff463d4399cb68ed772305c5e Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:32:42 +0200 Subject: [PATCH 05/12] remove sponsors module --- EvoSC.sln | 7 - .../Controllers/SponsorsController.cs | 46 ------ .../Interfaces/ISponsorsService.cs | 12 -- .../Services/SponsorsService.cs | 92 ------------ src/Modules/SponsorsModule/SponsorsModule.cs | 26 ---- .../SponsorsModule/SponsorsModule.csproj | 19 --- .../SponsorsModule/Templates/Sponsors.mt | 136 ------------------ src/Modules/SponsorsModule/info.toml | 6 - 8 files changed, 344 deletions(-) delete mode 100644 src/Modules/SponsorsModule/Controllers/SponsorsController.cs delete mode 100644 src/Modules/SponsorsModule/Interfaces/ISponsorsService.cs delete mode 100644 src/Modules/SponsorsModule/Services/SponsorsService.cs delete mode 100644 src/Modules/SponsorsModule/SponsorsModule.cs delete mode 100644 src/Modules/SponsorsModule/SponsorsModule.csproj delete mode 100644 src/Modules/SponsorsModule/Templates/Sponsors.mt delete mode 100644 src/Modules/SponsorsModule/info.toml diff --git a/EvoSC.sln b/EvoSC.sln index 2487aa426..7fa4feec5 100644 --- a/EvoSC.sln +++ b/EvoSC.sln @@ -102,8 +102,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchReadyModule.Tests", "t EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModuleManagerModule", "src\Modules\ModuleManagerModule\ModuleManagerModule.csproj", "{65F795D5-058D-4F8D-B8E0-BE3F64E14CDF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SponsorsModule", "src\Modules\SponsorsModule\SponsorsModule.csproj", "{1F628FDD-289C-48C3-B736-B5A13D7EC9F2}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchTrackerModule.Tests", "tests\Modules\MatchTrackerModule.Tests\MatchTrackerModule.Tests.csproj", "{9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}" EndProject Global @@ -298,10 +296,6 @@ Global {65F795D5-058D-4F8D-B8E0-BE3F64E14CDF}.Debug|Any CPU.Build.0 = Debug|Any CPU {65F795D5-058D-4F8D-B8E0-BE3F64E14CDF}.Release|Any CPU.ActiveCfg = Release|Any CPU {65F795D5-058D-4F8D-B8E0-BE3F64E14CDF}.Release|Any CPU.Build.0 = Release|Any CPU - {1F628FDD-289C-48C3-B736-B5A13D7EC9F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1F628FDD-289C-48C3-B736-B5A13D7EC9F2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1F628FDD-289C-48C3-B736-B5A13D7EC9F2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1F628FDD-289C-48C3-B736-B5A13D7EC9F2}.Release|Any CPU.Build.0 = Release|Any CPU {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}.Debug|Any CPU.Build.0 = Debug|Any CPU {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -353,7 +347,6 @@ Global {1D3B25FA-F807-4428-A520-878A582DCF28} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {42BCE01C-EBEF-4DB6-A61C-35B63C915AD3} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} {65F795D5-058D-4F8D-B8E0-BE3F64E14CDF} = {DC47658A-F421-4BA4-B617-090A7DFB3900} - {1F628FDD-289C-48C3-B736-B5A13D7EC9F2} = {DC47658A-F421-4BA4-B617-090A7DFB3900} {9EF4D340-0C49-4A15-9BCF-6CD9508AA7DE} = {6D75D6A2-6ECD-4DE4-96C5-CAD7D134407A} EndGlobalSection EndGlobal diff --git a/src/Modules/SponsorsModule/Controllers/SponsorsController.cs b/src/Modules/SponsorsModule/Controllers/SponsorsController.cs deleted file mode 100644 index 77c362f59..000000000 --- a/src/Modules/SponsorsModule/Controllers/SponsorsController.cs +++ /dev/null @@ -1,46 +0,0 @@ -using EvoSC.Common.Controllers; -using EvoSC.Common.Controllers.Attributes; -using EvoSC.Common.Events.Attributes; -using EvoSC.Common.Interfaces.Controllers; -using EvoSC.Common.Interfaces.Models.Enums; -using EvoSC.Common.Interfaces.Services; -using EvoSC.Common.Remote; -using EvoSC.Common.Util; -using EvoSC.Modules.Official.SponsorsModule.Interfaces; -using GbxRemoteNet.Events; - -namespace EvoSC.Modules.Official.SponsorsModule.Controllers; - -[Controller] -public class SponsorsController : EvoScController -{ - private readonly ISponsorsService _sponsorsService; - private readonly IPlayerManagerService _playerManager; - - public SponsorsController(ISponsorsService sponsorsService, IPlayerManagerService playerManagerService) - { - _sponsorsService = sponsorsService; - _playerManager = playerManagerService; - } - - [Subscribe(GbxRemoteEvent.PlayerConnect)] - public async Task OnPlayerJoin(object sender, PlayerConnectGbxEventArgs playerConnectArgs) - { - var player = await _playerManager.GetOnlinePlayerAsync(PlayerUtils.ConvertLoginToAccountId(playerConnectArgs.Login)); - - if (player.State == PlayerState.Spectating) - { - await _sponsorsService.ShowWidget(playerConnectArgs.Login); - } - } - - [Subscribe(GbxRemoteEvent.BeginMap)] - public async Task OnBeginMap(object sender, MapGbxEventArgs mapGbxEventArgs) - { - await _sponsorsService.ShowWidgetToAllSpectators(); - } - - [Subscribe(GbxRemoteEvent.PlayerInfoChanged)] - public Task OnPlayerInfoChange(object sender, PlayerInfoChangedGbxEventArgs playerInfoChangedArgs) => - _sponsorsService.ShowOrHide(playerInfoChangedArgs); -} diff --git a/src/Modules/SponsorsModule/Interfaces/ISponsorsService.cs b/src/Modules/SponsorsModule/Interfaces/ISponsorsService.cs deleted file mode 100644 index 487293cce..000000000 --- a/src/Modules/SponsorsModule/Interfaces/ISponsorsService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using EvoSC.Common.Interfaces.Models; -using GbxRemoteNet.Events; - -namespace EvoSC.Modules.Official.SponsorsModule.Interfaces; - -public interface ISponsorsService -{ - public Task ShowWidgetToAllSpectators(); - public Task HideWidgetFromEveryone(); - public Task ShowWidget(string playerLogin); - public Task ShowOrHide(PlayerInfoChangedGbxEventArgs playerInfoChangedArgs); -} diff --git a/src/Modules/SponsorsModule/Services/SponsorsService.cs b/src/Modules/SponsorsModule/Services/SponsorsService.cs deleted file mode 100644 index 82fb861e1..000000000 --- a/src/Modules/SponsorsModule/Services/SponsorsService.cs +++ /dev/null @@ -1,92 +0,0 @@ -using EvoSC.Common.Config.Models; -using EvoSC.Common.Interfaces.Models.Enums; -using EvoSC.Common.Interfaces.Services; -using EvoSC.Common.Services.Attributes; -using EvoSC.Common.Services.Models; -using EvoSC.Common.Util; -using EvoSC.Manialinks.Interfaces; -using EvoSC.Modules.Official.SponsorsModule.Interfaces; -using GbxRemoteNet.Events; -using Microsoft.Extensions.Logging; - -namespace EvoSC.Modules.Official.SponsorsModule.Services; - -[Service(LifeStyle = ServiceLifeStyle.Singleton)] -public class SponsorsService : ISponsorsService -{ - private const string Template = "SponsorsModule.Sponsors"; - - private readonly IPlayerManagerService _playerManager; - private readonly IManialinkManager _manialinkManager; - private readonly ILogger _logger; - private readonly IPlayerCacheService _playerCacheService; - private readonly IEvoScBaseConfig _config; - - public SponsorsService(IPlayerManagerService playerManager, IManialinkManager manialinkManager, - ILogger logger, IPlayerCacheService playerCacheService, IEvoScBaseConfig config) - { - _playerManager = playerManager; - _manialinkManager = manialinkManager; - _logger = logger; - _playerCacheService = playerCacheService; - _config = config; - } - - public async Task ShowWidgetToAllSpectators() - { - _logger.LogInformation("Showing widget to everyone."); - await _manialinkManager.SendManialinkAsync(Template, GetData()); - - /* - foreach (var player in players) - { - //if (player.State == PlayerState.Spectating) - //{ - _logger.LogInformation("Showing widget to {user}.", player.NickName); - await ShowWidget(player.GetLogin()); - //} - } - */ - } - - private dynamic GetData() - { - return new - { - sponsorImageUrls = new List - { - "https://cdn.evotm.com/tm2020/xpevo/Xperion.png", - "https://cdn.evotm.com/tm2020/xpevo/Evo.png", - "https://cdn.evotm.com/tm2020/xpevo/Lenovo.png", - }, - headerColor = _config.Theme.UI.HeaderBackgroundColor, - primaryColor = _config.Theme.UI.PrimaryColor, - logoUrl = _config.Theme.UI.LogoWhiteUrl, - playerRowBackgroundColor = _config.Theme.UI.PlayerRowBackgroundColor - }; - } - - public Task HideWidgetFromEveryone() - { - return _manialinkManager.HideManialinkAsync(Template); - } - - public Task ShowWidget(string playerLogin) - { - return _manialinkManager.SendManialinkAsync(playerLogin, Template, new { }); - } - - public async Task ShowOrHide(PlayerInfoChangedGbxEventArgs playerInfoChangedArgs) - { - var player = await _playerManager.GetOnlinePlayerAsync(PlayerUtils.ConvertLoginToAccountId(playerInfoChangedArgs.PlayerInfo.Login)); - - if (player.State == PlayerState.Spectating) - { - await ShowWidget(playerInfoChangedArgs.PlayerInfo.Login); - } - else - { - await _manialinkManager.HideManialinkAsync(player, Template); - } - } -} diff --git a/src/Modules/SponsorsModule/SponsorsModule.cs b/src/Modules/SponsorsModule/SponsorsModule.cs deleted file mode 100644 index d10ecd3e1..000000000 --- a/src/Modules/SponsorsModule/SponsorsModule.cs +++ /dev/null @@ -1,26 +0,0 @@ -using EvoSC.Modules.Attributes; -using EvoSC.Modules.Interfaces; -using EvoSC.Modules.Official.SponsorsModule.Interfaces; - -namespace EvoSC.Modules.Official.SponsorsModule; - -[Module(IsInternal = true)] -public class SponsorsModule : EvoScModule, IToggleable -{ - private readonly ISponsorsService _sponsorsService; - - public SponsorsModule(ISponsorsService sponsorsService) - { - _sponsorsService = sponsorsService; - } - - public Task EnableAsync() - { - return _sponsorsService.ShowWidgetToAllSpectators(); - } - - public Task DisableAsync() - { - return _sponsorsService.HideWidgetFromEveryone(); - } -} diff --git a/src/Modules/SponsorsModule/SponsorsModule.csproj b/src/Modules/SponsorsModule/SponsorsModule.csproj deleted file mode 100644 index 7c6021c1f..000000000 --- a/src/Modules/SponsorsModule/SponsorsModule.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net7.0 - enable - enable - EvoSC.Modules.Official.SponsorsModule - - - - - - - - - - - - diff --git a/src/Modules/SponsorsModule/Templates/Sponsors.mt b/src/Modules/SponsorsModule/Templates/Sponsors.mt deleted file mode 100644 index 5e46d6e7a..000000000 --- a/src/Modules/SponsorsModule/Templates/Sponsors.mt +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Modules/SponsorsModule/info.toml b/src/Modules/SponsorsModule/info.toml deleted file mode 100644 index 4023e44c4..000000000 --- a/src/Modules/SponsorsModule/info.toml +++ /dev/null @@ -1,6 +0,0 @@ -[info] -name = "SponsorsModule" -title = "Sponsors" -summary = "Shows slides of sponsor images." -version = "1.0.0" -author = "Evo" From 5d0a536eebf48468f779b430cb6018e4ed0345b7 Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:32:56 +0200 Subject: [PATCH 06/12] from internal modules as well --- src/EvoSC/InternalModules.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/EvoSC/InternalModules.cs b/src/EvoSC/InternalModules.cs index 916497b71..0b90768aa 100644 --- a/src/EvoSC/InternalModules.cs +++ b/src/EvoSC/InternalModules.cs @@ -17,7 +17,6 @@ using EvoSC.Modules.Official.PlayerRecords; using EvoSC.Modules.Official.Scoreboard; using EvoSC.Modules.Official.SetName; -using EvoSC.Modules.Official.SponsorsModule; using EvoSC.Modules.Official.WorldRecordModule; using FluentMigrator.Runner.Exceptions; using SpectatorTargetInfo; @@ -46,8 +45,7 @@ public static class InternalModules typeof(LiveRankingModule), typeof(MatchRankingModule), typeof(ASayModule), - typeof(SpectatorTargetInfoModule), - typeof(SponsorsModule) + typeof(SpectatorTargetInfoModule) }; /// From 78f19a72531d08d83211ae29df5ee786c61549d8 Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:39:50 +0200 Subject: [PATCH 07/12] initial cleanup of spectator target info module --- EvoSC.sln | 2 +- src/EvoSC/EvoSC.csproj | 3 +- src/EvoSC/InternalModules.cs | 2 +- .../SpectatorTargetInfoEventController.cs | 14 +++-- .../Interfaces/ISpectatorTargetInfoService.cs | 23 +++++--- .../Services/SpectatorTargetInfoService.cs | 52 +++++++++---------- .../SpectatorTargetInfoModule.cs | 21 +++----- .../SpectatorTargetInfoModule.csproj} | 1 + .../Templates/NewCpTime.mt | 0 .../Templates/ResetCpTimes.mt | 0 .../Templates/SpectatorTargetInfo.mt | 0 .../info.toml | 2 +- 12 files changed, 58 insertions(+), 62 deletions(-) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/Controllers/SpectatorTargetInfoEventController.cs (76%) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/Interfaces/ISpectatorTargetInfoService.cs (62%) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/Services/SpectatorTargetInfoService.cs (75%) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/SpectatorTargetInfoModule.cs (50%) rename src/Modules/{SpectatorTargetInfo/SpectatorTargetInfo.csproj => SpectatorTargetInfoModule/SpectatorTargetInfoModule.csproj} (87%) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/Templates/NewCpTime.mt (100%) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/Templates/ResetCpTimes.mt (100%) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/Templates/SpectatorTargetInfo.mt (100%) rename src/Modules/{SpectatorTargetInfo => SpectatorTargetInfoModule}/info.toml (77%) diff --git a/EvoSC.sln b/EvoSC.sln index 7fa4feec5..63b041ee4 100644 --- a/EvoSC.sln +++ b/EvoSC.sln @@ -92,7 +92,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NextMapModule.Tests", "test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatchRankingModule", "src\Modules\MatchRankingModule\MatchRankingModule.csproj", "{A3D8F2EB-59E4-44AB-B036-4BC0DB7D2774}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpectatorTargetInfo", "src\Modules\SpectatorTargetInfo\SpectatorTargetInfo.csproj", "{FCC3C10E-9CA8-4DF1-A508-339678846032}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpectatorTargetInfoModule", "src\Modules\SpectatorTargetInfoModule\SpectatorTargetInfoModule.csproj", "{FCC3C10E-9CA8-4DF1-A508-339678846032}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASayModule", "src\Modules\ASayModule\ASayModule.csproj", "{570CEDDA-7EBC-486D-BD5D-0A1C39DD69F8}" EndProject diff --git a/src/EvoSC/EvoSC.csproj b/src/EvoSC/EvoSC.csproj index 2498ab0a4..b4db4600a 100644 --- a/src/EvoSC/EvoSC.csproj +++ b/src/EvoSC/EvoSC.csproj @@ -45,7 +45,7 @@ - + @@ -65,7 +65,6 @@ - diff --git a/src/EvoSC/InternalModules.cs b/src/EvoSC/InternalModules.cs index 0b90768aa..0efa17655 100644 --- a/src/EvoSC/InternalModules.cs +++ b/src/EvoSC/InternalModules.cs @@ -17,9 +17,9 @@ using EvoSC.Modules.Official.PlayerRecords; using EvoSC.Modules.Official.Scoreboard; using EvoSC.Modules.Official.SetName; +using EvoSC.Modules.Official.SpectatorTargetInfoModule; using EvoSC.Modules.Official.WorldRecordModule; using FluentMigrator.Runner.Exceptions; -using SpectatorTargetInfo; namespace EvoSC; diff --git a/src/Modules/SpectatorTargetInfo/Controllers/SpectatorTargetInfoEventController.cs b/src/Modules/SpectatorTargetInfoModule/Controllers/SpectatorTargetInfoEventController.cs similarity index 76% rename from src/Modules/SpectatorTargetInfo/Controllers/SpectatorTargetInfoEventController.cs rename to src/Modules/SpectatorTargetInfoModule/Controllers/SpectatorTargetInfoEventController.cs index 99c3a5782..82c2f0499 100644 --- a/src/Modules/SpectatorTargetInfo/Controllers/SpectatorTargetInfoEventController.cs +++ b/src/Modules/SpectatorTargetInfoModule/Controllers/SpectatorTargetInfoEventController.cs @@ -7,31 +7,29 @@ using GbxRemoteNet.Events; using SpectatorTargetInfo.Interfaces; -namespace SpectatorTargetInfo.Controllers; +namespace EvoSC.Modules.Official.SpectatorTargetInfoModule.Controllers; [Controller] public class SpectatorTargetInfoEventController : EvoScController { private readonly ISpectatorTargetInfoService _spectatorTargetInfoService; - public SpectatorTargetInfoEventController(ISpectatorTargetInfoService spectatorTargetInfoService) - { + public SpectatorTargetInfoEventController(ISpectatorTargetInfoService spectatorTargetInfoService) => _spectatorTargetInfoService = spectatorTargetInfoService; - } [Subscribe(GbxRemoteEvent.PlayerConnect)] public Task OnPlayerConnect(object x, PlayerConnectGbxEventArgs args) => - _spectatorTargetInfoService.SendManiaLink(args.Login); + _spectatorTargetInfoService.SendManiaLinkAsync(args.Login); [Subscribe(ModeScriptEvent.WayPoint)] public Task OnWayPoint(object sender, WayPointEventArgs wayPointEventArgs) => - _spectatorTargetInfoService.ForwardCheckpointTimeToClients(wayPointEventArgs); + _spectatorTargetInfoService.ForwardCheckpointTimeToClientsAsync(wayPointEventArgs); [Subscribe(ModeScriptEvent.StartRoundStart)] public Task OnNewRound(object sender, RoundEventArgs roundEventArgs) => - _spectatorTargetInfoService.ResetCheckpointTimes(); + _spectatorTargetInfoService.ResetCheckpointTimesAsync(); [Subscribe(ModeScriptEvent.GiveUp)] public Task OnPlayerGiveUp(object sender, PlayerUpdateEventArgs playerUpdateEventArgs) => - _spectatorTargetInfoService.ForwardDnf(playerUpdateEventArgs); + _spectatorTargetInfoService.ForwardDnfToClientsAsync(playerUpdateEventArgs); } diff --git a/src/Modules/SpectatorTargetInfo/Interfaces/ISpectatorTargetInfoService.cs b/src/Modules/SpectatorTargetInfoModule/Interfaces/ISpectatorTargetInfoService.cs similarity index 62% rename from src/Modules/SpectatorTargetInfo/Interfaces/ISpectatorTargetInfoService.cs rename to src/Modules/SpectatorTargetInfoModule/Interfaces/ISpectatorTargetInfoService.cs index 8b2e9f4dc..32d2d9148 100644 --- a/src/Modules/SpectatorTargetInfo/Interfaces/ISpectatorTargetInfoService.cs +++ b/src/Modules/SpectatorTargetInfoModule/Interfaces/ISpectatorTargetInfoService.cs @@ -7,33 +7,40 @@ public interface ISpectatorTargetInfoService /// /// Sends the manialink to all players. /// - public Task SendManiaLink(); + public Task SendManiaLinkAsync(); + /// /// Sends the manialink to a specific player. /// - public Task SendManiaLink(string playerLogin); + public Task SendManiaLinkAsync(string playerLogin); + /// /// Hides the manialink for all players. /// - public Task HideManiaLink(); + public Task HideManiaLinkAsync(); + /// /// Hides the default spectator info. /// - public Task HideNadeoSpectatorInfo(); + public Task HideNadeoSpectatorInfoAsync(); + /// /// Shows the default spectator info. /// - public Task ShowNadeoSpectatorInfo(); + public Task ShowNadeoSpectatorInfoAsync(); + /// /// Maps wayPointEventArgs and sends data to clients. /// - public Task ForwardCheckpointTimeToClients(WayPointEventArgs wayPointEventArgs); + public Task ForwardCheckpointTimeToClientsAsync(WayPointEventArgs wayPointEventArgs); + /// /// Clears the checkpoint times for the clients. /// - public Task ResetCheckpointTimes(); + public Task ResetCheckpointTimesAsync(); + /// /// Sends players DNF to clients. /// - public Task ForwardDnf(PlayerUpdateEventArgs playerUpdateEventArgs); + public Task ForwardDnfToClientsAsync(PlayerUpdateEventArgs playerUpdateEventArgs); } diff --git a/src/Modules/SpectatorTargetInfo/Services/SpectatorTargetInfoService.cs b/src/Modules/SpectatorTargetInfoModule/Services/SpectatorTargetInfoService.cs similarity index 75% rename from src/Modules/SpectatorTargetInfo/Services/SpectatorTargetInfoService.cs rename to src/Modules/SpectatorTargetInfoModule/Services/SpectatorTargetInfoService.cs index 65e86f7c1..6c5a9b2cf 100644 --- a/src/Modules/SpectatorTargetInfo/Services/SpectatorTargetInfoService.cs +++ b/src/Modules/SpectatorTargetInfoModule/Services/SpectatorTargetInfoService.cs @@ -6,12 +6,12 @@ using EvoSC.Manialinks.Interfaces; using SpectatorTargetInfo.Interfaces; -namespace SpectatorTargetInfo.Services; +namespace EvoSC.Modules.Official.SpectatorTargetInfoModule.Services; [Service(LifeStyle = ServiceLifeStyle.Singleton)] public class SpectatorTargetInfoService : ISpectatorTargetInfoService { - private const string WidgetTemplate = "SpectatorTargetInfo.SpectatorTargetInfo"; + private const string WidgetTemplate = "SpectatorTargetInfoModule.SpectatorTargetInfoModule"; private readonly IManialinkManager _manialinks; private readonly IServerClient _server; @@ -24,27 +24,17 @@ public SpectatorTargetInfoService(IManialinkManager manialinks, IServerClient se _config = config; } - public async Task SendManiaLink() => - await _manialinks.SendManialinkAsync(WidgetTemplate, await GetWidgetData()); + public async Task SendManiaLinkAsync() => + await _manialinks.SendManialinkAsync(WidgetTemplate, GetWidgetData()); - public async Task SendManiaLink(string playerLogin) => - await _manialinks.SendManialinkAsync(playerLogin, WidgetTemplate, await GetWidgetData()); + public async Task SendManiaLinkAsync(string playerLogin) => + await _manialinks.SendManialinkAsync(playerLogin, WidgetTemplate, GetWidgetData()); - public async Task HideManiaLink() => + public async Task HideManiaLinkAsync() => await _manialinks.HideManialinkAsync(WidgetTemplate); - private async Task GetWidgetData() - { - return new - { - primaryColor = _config.Theme.UI.PrimaryColor, - backgroundColor = _config.Theme.UI.BackgroundColor, - headerColor = _config.Theme.UI.HeaderBackgroundColor - }; - } - - public Task HideNadeoSpectatorInfo() + public Task HideNadeoSpectatorInfoAsync() { var hudSettings = new List() { @@ -65,7 +55,7 @@ public Task HideNadeoSpectatorInfo() return _server.Remote.TriggerModeScriptEventArrayAsync("Common.UIModules.SetProperties", hudSettings.ToArray()); } - public Task ShowNadeoSpectatorInfo() + public Task ShowNadeoSpectatorInfoAsync() { var hudSettings = new List() { @@ -86,9 +76,9 @@ public Task ShowNadeoSpectatorInfo() return _server.Remote.TriggerModeScriptEventArrayAsync("Common.UIModules.SetProperties", hudSettings.ToArray()); } - public Task ForwardCheckpointTimeToClients(WayPointEventArgs wayPointEventArgs) + public Task ForwardCheckpointTimeToClientsAsync(WayPointEventArgs wayPointEventArgs) { - return _manialinks.SendManialinkAsync("SpectatorTargetInfo.NewCpTime", + return _manialinks.SendManialinkAsync("SpectatorTargetInfoModule.NewCpTime", new { accountId = wayPointEventArgs.AccountId, @@ -97,19 +87,29 @@ public Task ForwardCheckpointTimeToClients(WayPointEventArgs wayPointEventArgs) }); } - public Task ResetCheckpointTimes() + public Task ResetCheckpointTimesAsync() { - _manialinks.HideManialinkAsync("SpectatorTargetInfo.NewCpTime"); - return _manialinks.SendManialinkAsync("SpectatorTargetInfo.ResetCpTimes"); + _manialinks.HideManialinkAsync("SpectatorTargetInfoModule.NewCpTime"); + return _manialinks.SendManialinkAsync("SpectatorTargetInfoModule.ResetCpTimes"); } - public Task ForwardDnf(PlayerUpdateEventArgs playerUpdateEventArgs) + public Task ForwardDnfToClientsAsync(PlayerUpdateEventArgs playerUpdateEventArgs) { - return _manialinks.SendManialinkAsync("SpectatorTargetInfo.NewCpTime", new + return _manialinks.SendManialinkAsync("SpectatorTargetInfoModule.NewCpTime", new { accountId = playerUpdateEventArgs.AccountId, time = 0, cpIndex = -1 }); } + + private dynamic GetWidgetData() + { + return new + { + primaryColor = _config.Theme.UI.PrimaryColor, + backgroundColor = _config.Theme.UI.BackgroundColor, + headerColor = _config.Theme.UI.HeaderBackgroundColor + }; + } } diff --git a/src/Modules/SpectatorTargetInfo/SpectatorTargetInfoModule.cs b/src/Modules/SpectatorTargetInfoModule/SpectatorTargetInfoModule.cs similarity index 50% rename from src/Modules/SpectatorTargetInfo/SpectatorTargetInfoModule.cs rename to src/Modules/SpectatorTargetInfoModule/SpectatorTargetInfoModule.cs index 069cb0077..96483c205 100644 --- a/src/Modules/SpectatorTargetInfo/SpectatorTargetInfoModule.cs +++ b/src/Modules/SpectatorTargetInfoModule/SpectatorTargetInfoModule.cs @@ -1,31 +1,22 @@ -using EvoSC.Modules; -using EvoSC.Modules.Attributes; +using EvoSC.Modules.Attributes; using EvoSC.Modules.Interfaces; using SpectatorTargetInfo.Interfaces; -namespace SpectatorTargetInfo; +namespace EvoSC.Modules.Official.SpectatorTargetInfoModule; [Module(IsInternal = true)] public class SpectatorTargetInfoModule : EvoScModule, IToggleable { private readonly ISpectatorTargetInfoService _spectatorTargetInfoService; - public SpectatorTargetInfoModule(ISpectatorTargetInfoService spectatorTargetInfoService) - { + public SpectatorTargetInfoModule(ISpectatorTargetInfoService spectatorTargetInfoService) => _spectatorTargetInfoService = spectatorTargetInfoService; - } public Task EnableAsync() { - _spectatorTargetInfoService.HideNadeoSpectatorInfo(); - - return _spectatorTargetInfoService.SendManiaLink(); + _spectatorTargetInfoService.HideNadeoSpectatorInfoAsync(); + return _spectatorTargetInfoService.SendManiaLinkAsync(); } - public Task DisableAsync() - { - _spectatorTargetInfoService.HideManiaLink(); - - return _spectatorTargetInfoService.ShowNadeoSpectatorInfo(); - } + public Task DisableAsync() => _spectatorTargetInfoService.ShowNadeoSpectatorInfoAsync(); } diff --git a/src/Modules/SpectatorTargetInfo/SpectatorTargetInfo.csproj b/src/Modules/SpectatorTargetInfoModule/SpectatorTargetInfoModule.csproj similarity index 87% rename from src/Modules/SpectatorTargetInfo/SpectatorTargetInfo.csproj rename to src/Modules/SpectatorTargetInfoModule/SpectatorTargetInfoModule.csproj index 3cb92596b..1c9f4d490 100644 --- a/src/Modules/SpectatorTargetInfo/SpectatorTargetInfo.csproj +++ b/src/Modules/SpectatorTargetInfoModule/SpectatorTargetInfoModule.csproj @@ -4,6 +4,7 @@ net7.0 enable enable + EvoSC.Modules.Official.SpectatorTargetInfoModule diff --git a/src/Modules/SpectatorTargetInfo/Templates/NewCpTime.mt b/src/Modules/SpectatorTargetInfoModule/Templates/NewCpTime.mt similarity index 100% rename from src/Modules/SpectatorTargetInfo/Templates/NewCpTime.mt rename to src/Modules/SpectatorTargetInfoModule/Templates/NewCpTime.mt diff --git a/src/Modules/SpectatorTargetInfo/Templates/ResetCpTimes.mt b/src/Modules/SpectatorTargetInfoModule/Templates/ResetCpTimes.mt similarity index 100% rename from src/Modules/SpectatorTargetInfo/Templates/ResetCpTimes.mt rename to src/Modules/SpectatorTargetInfoModule/Templates/ResetCpTimes.mt diff --git a/src/Modules/SpectatorTargetInfo/Templates/SpectatorTargetInfo.mt b/src/Modules/SpectatorTargetInfoModule/Templates/SpectatorTargetInfo.mt similarity index 100% rename from src/Modules/SpectatorTargetInfo/Templates/SpectatorTargetInfo.mt rename to src/Modules/SpectatorTargetInfoModule/Templates/SpectatorTargetInfo.mt diff --git a/src/Modules/SpectatorTargetInfo/info.toml b/src/Modules/SpectatorTargetInfoModule/info.toml similarity index 77% rename from src/Modules/SpectatorTargetInfo/info.toml rename to src/Modules/SpectatorTargetInfoModule/info.toml index c44da9587..b3b1fdd7b 100644 --- a/src/Modules/SpectatorTargetInfo/info.toml +++ b/src/Modules/SpectatorTargetInfoModule/info.toml @@ -1,5 +1,5 @@ [info] -name = "SpectatorTargetInfo" +name = "SpectatorTargetInfoModule" title = "Spectator Target Info" summary = "Shows player info in spectator mode." version = "1.0.0" From bb5c4d68ebe5d1a86dc24f5685f28c00654dc04b Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 09:54:00 +0200 Subject: [PATCH 08/12] initial scoreboard service cleanup --- .../ScoreboardCommandsController.cs | 25 +---- .../Controllers/ScoreboardEventController.cs | 14 ++- .../ScoreboardManialinkController.cs | 12 +-- .../Interfaces/IScoreboardService.cs | 22 +++-- .../Interfaces/IScoreboardTrackerService.cs | 12 +++ src/Modules/Scoreboard/ScoreboardModule.cs | 8 +- .../Scoreboard/Services/ScoreboardService.cs | 41 ++++---- .../Services/ScoreboardTrackerService.cs | 97 +++++++++++++++++++ 8 files changed, 160 insertions(+), 71 deletions(-) create mode 100644 src/Modules/Scoreboard/Interfaces/IScoreboardTrackerService.cs create mode 100644 src/Modules/Scoreboard/Services/ScoreboardTrackerService.cs diff --git a/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs b/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs index 95a90b134..b6e6e4528 100644 --- a/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs +++ b/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs @@ -2,9 +2,6 @@ using EvoSC.Commands.Interfaces; using EvoSC.Common.Controllers; using EvoSC.Common.Controllers.Attributes; -using EvoSC.Common.Interfaces; -using EvoSC.Common.Util; -using EvoSC.Modules.Official.MatchManagerModule.Permissions; using EvoSC.Modules.Official.Scoreboard.Interfaces; namespace EvoSC.Modules.Official.Scoreboard.Controllers; @@ -12,30 +9,14 @@ namespace EvoSC.Modules.Official.Scoreboard.Controllers; [Controller] public class ScoreboardCommandsController : EvoScController { - private readonly IServerClient _server; private readonly IScoreboardService _scoreboardService; - public ScoreboardCommandsController(IServerClient server, IScoreboardService scoreboardService) - { - _server = server; + public ScoreboardCommandsController(IScoreboardService scoreboardService) => _scoreboardService = scoreboardService; - } - [ChatCommand("sb", "[Command.ShowScoreboard]")] + [ChatCommand("scoreboard", "[Command.ShowScoreboard]")] public async Task ShowScoreboard() { - await _scoreboardService.ShowScoreboard(Context.Player.GetLogin()); - } - - [ChatCommand("fake", "[Command.FakePlayer]", MatchManagerPermissions.LoadMatchSettings)] - public async Task FakePlayer() - { - await _server.Remote.ConnectFakePlayerAsync(); - await _server.Remote.ConnectFakePlayerAsync(); - await _server.Remote.ConnectFakePlayerAsync(); - await _server.Remote.ConnectFakePlayerAsync(); - await _server.Remote.ConnectFakePlayerAsync(); - await _server.Remote.ConnectFakePlayerAsync(); - await _server.Remote.ConnectFakePlayerAsync(); + await _scoreboardService.ShowScoreboardAsync(Context.Player); } } diff --git a/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs b/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs index aab597e1f..545199285 100644 --- a/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs +++ b/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs @@ -16,29 +16,27 @@ public class ScoreboardEventController : EvoScController _scoreboardService = scoreboardService; - } [Subscribe(GbxRemoteEvent.BeginMap)] public async Task OnBeginMap(object sender, MapGbxEventArgs args) { - await _scoreboardService.LoadAndSendRequiredAdditionalInfos(); - await _scoreboardService.ShowScoreboard(); + await _scoreboardService.LoadAndSendRequiredAdditionalInfoAsync(); + await _scoreboardService.ShowScoreboardToAllAsync(); } [Subscribe(MatchSettingsEvent.MatchSettingsLoaded)] public async Task OnMatchSettingsLoaded(object sender, MatchSettingsLoadedEventArgs args) { - await _scoreboardService.LoadAndSendRequiredAdditionalInfos(); - await _scoreboardService.ShowScoreboard(); + await _scoreboardService.LoadAndSendRequiredAdditionalInfoAsync(); + await _scoreboardService.ShowScoreboardToAllAsync(); } [Subscribe(ModeScriptEvent.StartRoundStart)] public async Task OnRoundStart(object sender, RoundEventArgs args) { _scoreboardService.SetCurrentRound(args.Count); - await _scoreboardService.SendRequiredAdditionalInfos(); + await _scoreboardService.SendRequiredAdditionalInfoAsync(); } } diff --git a/src/Modules/Scoreboard/Controllers/ScoreboardManialinkController.cs b/src/Modules/Scoreboard/Controllers/ScoreboardManialinkController.cs index 3872f50e0..31bd7d179 100644 --- a/src/Modules/Scoreboard/Controllers/ScoreboardManialinkController.cs +++ b/src/Modules/Scoreboard/Controllers/ScoreboardManialinkController.cs @@ -1,5 +1,4 @@ using EvoSC.Common.Controllers.Attributes; -using EvoSC.Common.Util; using EvoSC.Manialinks; using EvoSC.Modules.Official.Scoreboard.Interfaces; @@ -10,13 +9,8 @@ public class ScoreboardManialinkController : ManialinkController { private readonly IScoreboardService _scoreboardService; - public ScoreboardManialinkController(IScoreboardService scoreboardService) - { + public ScoreboardManialinkController(IScoreboardService scoreboardService) => _scoreboardService = scoreboardService; - } - - public Task ResendScoreboardAsync() - { - return _scoreboardService.ShowScoreboard(Context.Player.GetLogin()); - } + + public Task ResendScoreboardAsync() => _scoreboardService.ShowScoreboardAsync(Context.Player); } diff --git a/src/Modules/Scoreboard/Interfaces/IScoreboardService.cs b/src/Modules/Scoreboard/Interfaces/IScoreboardService.cs index 4c42a25f0..2e6a4d11f 100644 --- a/src/Modules/Scoreboard/Interfaces/IScoreboardService.cs +++ b/src/Modules/Scoreboard/Interfaces/IScoreboardService.cs @@ -1,31 +1,39 @@ -namespace EvoSC.Modules.Official.Scoreboard.Interfaces; +using EvoSC.Common.Interfaces.Models; + +namespace EvoSC.Modules.Official.Scoreboard.Interfaces; public interface IScoreboardService { /// /// Sends the scoreboard manialink to all players. /// - public Task ShowScoreboard(); + public Task ShowScoreboardToAllAsync(); + /// /// Sends the scoreboard manialink to a specific players. /// - public Task ShowScoreboard(string playerLogin); + public Task ShowScoreboardAsync(IPlayer playerLogin); + /// /// Hide the default game scoreboard. /// - public Task HideNadeoScoreboard(); + public Task HideNadeoScoreboardAsync(); + /// /// Shows the default game scoreboard. /// - public Task ShowNadeoScoreboard(); + public Task ShowNadeoScoreboardAsync(); + /// /// Sends the manialink with additional values used by the scoreboard. /// - public Task SendRequiredAdditionalInfos(); + public Task SendRequiredAdditionalInfoAsync(); + /// /// Refreshes the additionally required data and sends the manialink. /// - public Task LoadAndSendRequiredAdditionalInfos(); + public Task LoadAndSendRequiredAdditionalInfoAsync(); + /// /// Sets the current round. /// diff --git a/src/Modules/Scoreboard/Interfaces/IScoreboardTrackerService.cs b/src/Modules/Scoreboard/Interfaces/IScoreboardTrackerService.cs new file mode 100644 index 000000000..c00c7d63a --- /dev/null +++ b/src/Modules/Scoreboard/Interfaces/IScoreboardTrackerService.cs @@ -0,0 +1,12 @@ +namespace EvoSC.Modules.Official.Scoreboard.Interfaces; + +public interface IScoreboardTrackerService +{ + public int RoundsPerMap { get; set; } + + public int PointsLimit { get; set; } + + public int CurrentRound { get; set; } + + public int MaxPlayers { get; set; } +} diff --git a/src/Modules/Scoreboard/ScoreboardModule.cs b/src/Modules/Scoreboard/ScoreboardModule.cs index 33cca0855..89782c5d4 100644 --- a/src/Modules/Scoreboard/ScoreboardModule.cs +++ b/src/Modules/Scoreboard/ScoreboardModule.cs @@ -16,14 +16,14 @@ public ScoreboardModule(IScoreboardService scoreboardService) public Task EnableAsync() { - _scoreboardService.LoadAndSendRequiredAdditionalInfos(); - _scoreboardService.HideNadeoScoreboard(); + _scoreboardService.LoadAndSendRequiredAdditionalInfoAsync(); + _scoreboardService.HideNadeoScoreboardAsync(); - return _scoreboardService.ShowScoreboard(); + return _scoreboardService.ShowScoreboardToAllAsync(); } public Task DisableAsync() { - return _scoreboardService.ShowNadeoScoreboard(); + return _scoreboardService.ShowNadeoScoreboardAsync(); } } diff --git a/src/Modules/Scoreboard/Services/ScoreboardService.cs b/src/Modules/Scoreboard/Services/ScoreboardService.cs index d3c10dbd0..e529bb533 100644 --- a/src/Modules/Scoreboard/Services/ScoreboardService.cs +++ b/src/Modules/Scoreboard/Services/ScoreboardService.cs @@ -1,5 +1,6 @@ using EvoSC.Common.Config.Models; using EvoSC.Common.Interfaces; +using EvoSC.Common.Interfaces.Models; using EvoSC.Common.Interfaces.Services; using EvoSC.Common.Services.Attributes; using EvoSC.Common.Services.Models; @@ -8,33 +9,31 @@ namespace EvoSC.Modules.Official.Scoreboard.Services; -[Service(LifeStyle = ServiceLifeStyle.Singleton)] +[Service(LifeStyle = ServiceLifeStyle.Transient)] public class ScoreboardService : IScoreboardService { private readonly IManialinkManager _manialinks; private readonly IServerClient _server; private readonly IEvoScBaseConfig _config; private readonly IMatchSettingsService _matchSettingsService; + private readonly IScoreboardTrackerService _scoreboardTracker; - private int _roundsPerMap = -1; - private int _pointsLimit = -1; - private int _currentRound = -1; - private int _maxPlayers = -1; - - public ScoreboardService(IManialinkManager manialinks, IServerClient server, IEvoScBaseConfig config, IMatchSettingsService matchSettingsService) + public ScoreboardService(IManialinkManager manialinks, IServerClient server, IEvoScBaseConfig config, + IMatchSettingsService matchSettingsService, IScoreboardTrackerService scoreboardTracker) { _manialinks = manialinks; _server = server; _config = config; _matchSettingsService = matchSettingsService; + _scoreboardTracker = scoreboardTracker; } - public async Task ShowScoreboard() + public async Task ShowScoreboardToAllAsync() { await _manialinks.SendPersistentManialinkAsync("Scoreboard.Scoreboard", await GetData()); } - public async Task ShowScoreboard(string playerLogin) + public async Task ShowScoreboardAsync(IPlayer playerLogin) { await _manialinks.SendManialinkAsync(playerLogin, "Scoreboard.Scoreboard", await GetData()); } @@ -43,8 +42,8 @@ private Task GetData() { return Task.FromResult(new { - MaxPlayers = _maxPlayers, - RoundsPerMap = _roundsPerMap, + _scoreboardTracker.MaxPlayers, + _scoreboardTracker.RoundsPerMap, PositionColors = new Dictionary { { 1, "d1b104" }, { 2, "9e9e9e" }, { 3, "915d29" } }, headerColor = _config.Theme.UI.HeaderBackgroundColor, primaryColor = _config.Theme.UI.PrimaryColor, @@ -56,7 +55,7 @@ private Task GetData() }); } - public async Task HideNadeoScoreboard() + public async Task HideNadeoScoreboardAsync() { var hudSettings = new List() { @@ -76,7 +75,7 @@ public async Task HideNadeoScoreboard() await _server.Remote.TriggerModeScriptEventArrayAsync("Common.UIModules.SetProperties", hudSettings.ToArray()); } - public async Task ShowNadeoScoreboard() + public async Task ShowNadeoScoreboardAsync() { var hudSettings = new List() { @@ -96,13 +95,13 @@ public async Task ShowNadeoScoreboard() await _server.Remote.TriggerModeScriptEventArrayAsync("Common.UIModules.SetProperties", hudSettings.ToArray()); } - public async Task SendRequiredAdditionalInfos() + public async Task SendRequiredAdditionalInfoAsync() { await _manialinks.SendPersistentManialinkAsync("Scoreboard.RoundsInfo", - new { RoundsPerMap = _roundsPerMap, CurrentRound = _currentRound, PointsLimit = _pointsLimit }); + new { _scoreboardTracker.RoundsPerMap, _scoreboardTracker.CurrentRound, _scoreboardTracker.PointsLimit }); } - public async Task LoadAndSendRequiredAdditionalInfos() + public async Task LoadAndSendRequiredAdditionalInfoAsync() { var settings = await _matchSettingsService.GetCurrentScriptSettingsAsync(); @@ -123,15 +122,15 @@ public async Task LoadAndSendRequiredAdditionalInfos() pointsLimit = (int)pointsLimitValue; } - _maxPlayers = (await _server.Remote.GetMaxPlayersAsync()).CurrentValue; - _roundsPerMap = roundsPerMap; - _pointsLimit = pointsLimit; + _scoreboardTracker.MaxPlayers = (await _server.Remote.GetMaxPlayersAsync()).CurrentValue; + _scoreboardTracker.RoundsPerMap = roundsPerMap; + _scoreboardTracker.PointsLimit = pointsLimit; - await SendRequiredAdditionalInfos(); + await SendRequiredAdditionalInfoAsync(); } public void SetCurrentRound(int round) { - _currentRound = round; + _scoreboardTracker.CurrentRound = round; } } diff --git a/src/Modules/Scoreboard/Services/ScoreboardTrackerService.cs b/src/Modules/Scoreboard/Services/ScoreboardTrackerService.cs new file mode 100644 index 000000000..bbf52a0e6 --- /dev/null +++ b/src/Modules/Scoreboard/Services/ScoreboardTrackerService.cs @@ -0,0 +1,97 @@ +using EvoSC.Common.Services.Attributes; +using EvoSC.Common.Services.Models; +using EvoSC.Modules.Official.Scoreboard.Interfaces; + +namespace EvoSC.Modules.Official.Scoreboard.Services; + +[Service(LifeStyle = ServiceLifeStyle.Singleton)] +public class ScoreboardTrackerService : IScoreboardTrackerService +{ + private int _roundsPerMap = -1; + private readonly object _roundsPerMapLock = new(); + + private int _pointsLimit = -1; + private readonly object _pointsLimitLock = new(); + + private int _currentRound = -1; + private readonly object _currentRoundLock = new(); + + private int _maxPlayers = -1; + private readonly object _maxPlayersLock = new(); + + public int RoundsPerMap + { + get + { + lock (_roundsPerMapLock) + { + return _roundsPerMap; + } + } + + set + { + lock (_roundsPerMapLock) + { + _roundsPerMap = value; + } + } + } + + public int PointsLimit + { + get + { + lock (_pointsLimitLock) + { + return _pointsLimit; + } + } + + set + { + lock (_pointsLimitLock) + { + _pointsLimit = value; + } + } + } + + public int CurrentRound + { + get + { + lock (_currentRoundLock) + { + return _currentRound; + } + } + + set + { + lock (_currentRoundLock) + { + _currentRound = value; + } + } + } + + public int MaxPlayers + { + get + { + lock (_maxPlayersLock) + { + return _maxPlayers; + } + } + + set + { + lock (_maxPlayersLock) + { + _maxPlayers = value; + } + } + } +} From 87ab214d223804aefbd536240f6e7075d976e7cf Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 10:05:10 +0200 Subject: [PATCH 09/12] at least some cleanup of liveranking --- .../Controllers/LiveRankingEventController.cs | 51 ++++--------------- .../Interfaces/ILiveRankingService.cs | 6 +-- .../Models/ExpandedLiveRankingPosition.cs | 5 ++ .../Models/LiveRankingPosition.cs | 8 +++ .../Models/LiveRankingStore.cs | 1 + .../Services/LiveRankingService.cs | 10 ++-- 6 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/Modules/LiveRankingModule/Controllers/LiveRankingEventController.cs b/src/Modules/LiveRankingModule/Controllers/LiveRankingEventController.cs index 756837af7..a12735f80 100644 --- a/src/Modules/LiveRankingModule/Controllers/LiveRankingEventController.cs +++ b/src/Modules/LiveRankingModule/Controllers/LiveRankingEventController.cs @@ -14,63 +14,32 @@ public class LiveRankingEventController : EvoScController _service = service; [Subscribe(ModeScriptEvent.WayPoint)] - public async Task OnPlayerWaypointAsync(object sender, WayPointEventArgs args) - { - await _service.OnPlayerWaypointAsync(args); - } + public Task OnPlayerWaypointAsync(object sender, WayPointEventArgs args) => _service.OnPlayerWaypointAsync(args); [Subscribe(ModeScriptEvent.GiveUp)] - public async Task OnPlayerGiveUpAsync(object sender, PlayerUpdateEventArgs args) - { - await _service.OnPlayerGiveupAsync(args); - } + public Task OnPlayerGiveUpAsync(object sender, PlayerUpdateEventArgs args) => _service.OnPlayerGiveupAsync(args); [Subscribe(ModeScriptEvent.StartRoundStart)] - public async Task OnStartRoundAsync(object sender, RoundEventArgs args) - { - await _service.OnStartRoundAsync(args); - } + public Task OnStartRoundAsync(object sender, RoundEventArgs args) => _service.OnStartRoundAsync(args); [Subscribe(ModeScriptEvent.EndMapStart)] - public async Task OnEndMapAsync(object sender, MapEventArgs args) - { - await _service.OnEndMapAsync(args); - } + public Task OnEndMapAsync(object sender, MapEventArgs args) => _service.OnEndMapAsync(args); [Subscribe(ModeScriptEvent.PodiumStart)] - public async Task OnPodiumStart(object sender, PodiumEventArgs args) - { - await _service.OnPodiumStartAsync(args); - } + public Task OnPodiumStartAsync(object sender, PodiumEventArgs args) => _service.OnPodiumStartAsync(args); [Subscribe(ModeScriptEvent.EndRoundStart)] - public async Task OnEndRound(object sender, RoundEventArgs args) - { - await _service.OnEndRoundAsync(args); - } + public Task OnEndRoundAsync(object sender, RoundEventArgs args) => _service.OnEndRoundAsync(args); [Subscribe(GbxRemoteEvent.BeginMatch)] - public async Task OnBeginMatch(object sender, EventArgs args) - { - await _service.OnBeginMatchAsync(); - } + public Task OnBeginMatchAsync(object sender, EventArgs args) => _service.OnBeginMatchAsync(); [Subscribe(GbxRemoteEvent.EndMatch)] - public async Task OnEndMatch(object sender, EndMatchGbxEventArgs args) - { - await _service.OnEndMatchAsync(args); - } + public Task OnEndMatchAsync(object sender, EndMatchGbxEventArgs args) => _service.OnEndMatchAsync(args); [Subscribe(GbxRemoteEvent.PlayerConnect)] - public async Task OnPlayerConnect(object sender, PlayerConnectGbxEventArgs args) - { - await _service.SendManialink(); - } + public Task OnPlayerConnectAsync(object sender, PlayerConnectGbxEventArgs args) => _service.SendManialinkAsync(); } diff --git a/src/Modules/LiveRankingModule/Interfaces/ILiveRankingService.cs b/src/Modules/LiveRankingModule/Interfaces/ILiveRankingService.cs index fd8869fc2..ab61ad8e1 100644 --- a/src/Modules/LiveRankingModule/Interfaces/ILiveRankingService.cs +++ b/src/Modules/LiveRankingModule/Interfaces/ILiveRankingService.cs @@ -64,7 +64,7 @@ public interface ILiveRankingService /// Sends a manialink. /// /// - Task SendManialink(); + Task SendManialinkAsync(); /// /// Called when a new match starts. @@ -82,11 +82,11 @@ public interface ILiveRankingService /// Calculates and sets the diffs of given live ranking positions. /// /// - Task CalculateDiffs(List rankings); + Task CalculateDiffsAsync(List rankings); /// /// Resets the live ranking data. /// /// - Task ResetLiveRanking(); + Task ResetLiveRankingAsync(); } diff --git a/src/Modules/LiveRankingModule/Models/ExpandedLiveRankingPosition.cs b/src/Modules/LiveRankingModule/Models/ExpandedLiveRankingPosition.cs index edb1c4815..cd2b166c9 100644 --- a/src/Modules/LiveRankingModule/Models/ExpandedLiveRankingPosition.cs +++ b/src/Modules/LiveRankingModule/Models/ExpandedLiveRankingPosition.cs @@ -8,22 +8,27 @@ public record ExpandedLiveRankingPosition /// The player. /// public required IOnlinePlayer Player { get; init; } + /// /// The time at the checkpoint. /// public required int CheckpointTime { get; init; } + /// /// The index of the checkpoint. /// public required int CheckpointIndex { get; init; } + /// /// Whether the player retreated from the round. /// public required bool IsDnf { get; init; } + /// /// Whether the player crossed the finish line. /// public required bool IsFinish { get; init; } + /// /// The difference in milliseconds of the players time to the leading players time. /// diff --git a/src/Modules/LiveRankingModule/Models/LiveRankingPosition.cs b/src/Modules/LiveRankingModule/Models/LiveRankingPosition.cs index cf7f89ea6..79581d9bf 100644 --- a/src/Modules/LiveRankingModule/Models/LiveRankingPosition.cs +++ b/src/Modules/LiveRankingModule/Models/LiveRankingPosition.cs @@ -1,3 +1,11 @@ namespace EvoSC.Modules.Official.LiveRankingModule.Models; +/// +/// The live ranking position of a player. +/// +/// Account Id of the player. +/// The checkpoint time of the player. +/// The checkpoint index that was driven through. +/// Whether the player has given up or not. +/// Whether the player has finished. public record LiveRankingPosition(string accountId, int cpTime, int cpIndex, bool isDNF, bool isFinish); diff --git a/src/Modules/LiveRankingModule/Models/LiveRankingStore.cs b/src/Modules/LiveRankingModule/Models/LiveRankingStore.cs index de334dba9..9e4fbe55c 100644 --- a/src/Modules/LiveRankingModule/Models/LiveRankingStore.cs +++ b/src/Modules/LiveRankingModule/Models/LiveRankingStore.cs @@ -10,6 +10,7 @@ internal class LiveRankingStore private ConcurrentDictionary _prevLiveRanking { get; set; } = new(); private readonly ILogger _logger; private readonly IPlayerManagerService _playerManager; + private MatchInfo _matchInfo = new(); internal LiveRankingStore(ILogger logger, IPlayerManagerService playerManager) diff --git a/src/Modules/LiveRankingModule/Services/LiveRankingService.cs b/src/Modules/LiveRankingModule/Services/LiveRankingService.cs index 23484ae3d..7ca6c5a4b 100644 --- a/src/Modules/LiveRankingModule/Services/LiveRankingService.cs +++ b/src/Modules/LiveRankingModule/Services/LiveRankingService.cs @@ -82,7 +82,7 @@ await _manialinkManager.SendPersistentManialinkAsync("LiveRankingModule.LiveRank private async Task GetWidgetData() { var currentRanking = (await _liveRankingStore.GetFullLiveRankingAsync()).Take(ShowRows).ToList(); - await CalculateDiffs(currentRanking); + await CalculateDiffsAsync(currentRanking); var widgetCurrentRanking = GetLiveRankingForWidget(currentRanking); return new @@ -116,7 +116,7 @@ private async Task GetWidgetData() */ } - public Task CalculateDiffs(List rankings) + public Task CalculateDiffsAsync(List rankings) { if (rankings.Count > 0) { @@ -175,7 +175,7 @@ public async Task OnEndMapAsync(MapEventArgs args) } } - public async Task ResetLiveRanking() + public async Task ResetLiveRankingAsync() { await _liveRankingStore.ResetLiveRankingsAsync(); } @@ -187,7 +187,7 @@ public async Task OnStartRoundAsync(RoundEventArgs args) await _manialinkManager.SendPersistentManialinkAsync("LiveRankingModule.LiveRanking", await GetWidgetData()); } - public async Task SendManialink() + public async Task SendManialinkAsync() { await _manialinkManager.SendPersistentManialinkAsync("LiveRankingModule.LiveRanking", await GetWidgetData()); } @@ -207,7 +207,7 @@ public async Task OnEndRoundAsync(RoundEventArgs args) public async Task OnBeginMatchAsync() { - await SendManialink(); + await SendManialinkAsync(); } public async Task OnEndMatchAsync(EndMatchGbxEventArgs args) From 4a7a03b44c2332d5d933c97d02ca52394a42a803 Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 10:08:03 +0200 Subject: [PATCH 10/12] remove xpevo seeding --- .../Migrations/202309211312_XPEvoValues.cs | 51 ------------------- .../Database/Migrations/202309221512_Snix.cs | 23 --------- 2 files changed, 74 deletions(-) delete mode 100644 src/EvoSC.Common/Database/Migrations/202309211312_XPEvoValues.cs delete mode 100644 src/EvoSC.Common/Database/Migrations/202309221512_Snix.cs diff --git a/src/EvoSC.Common/Database/Migrations/202309211312_XPEvoValues.cs b/src/EvoSC.Common/Database/Migrations/202309211312_XPEvoValues.cs deleted file mode 100644 index 57757272f..000000000 --- a/src/EvoSC.Common/Database/Migrations/202309211312_XPEvoValues.cs +++ /dev/null @@ -1,51 +0,0 @@ -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() - { - - } -} diff --git a/src/EvoSC.Common/Database/Migrations/202309221512_Snix.cs b/src/EvoSC.Common/Database/Migrations/202309221512_Snix.cs deleted file mode 100644 index 8ffa56c87..000000000 --- a/src/EvoSC.Common/Database/Migrations/202309221512_Snix.cs +++ /dev/null @@ -1,23 +0,0 @@ -using FluentMigrator; - -namespace EvoSC.Common.Database.Migrations; - -[Tags("XPEvo", "Production")] -[Migration(1695388994)] -public class AddSnix : Migration { - public override void Up() - { - Execute.Sql(""" - INSERT INTO "Players" ("Id", "LastVisit", "CreatedAt", "UpdatedAt", "AccountId", "NickName", "UbisoftName", "Zone") - VALUES (69, NOW(), NOW(), NOW(), 'a467a996-eba5-44bf-9e2b-8543b50f39ae', 'snixtho', 'snixtho', ''); - """); - - Execute.Sql("INSERT INTO \"UserGroups\" (\"UserId\", \"GroupId\", \"Display\")\nVALUES (69, 1, true)"); - } - - public override void Down() - { - } -} - - From a1ed3d4caae11969ca99ec716632f2bf1b2ae665 Mon Sep 17 00:00:00 2001 From: snixtho Date: Mon, 2 Oct 2023 10:13:47 +0200 Subject: [PATCH 11/12] fix add map tests as the method works differently now --- src/EvoSC.Common/Services/MapService.cs | 3 --- tests/EvoSC.Common.Tests/Services/MapServiceTests.cs | 6 ------ 2 files changed, 9 deletions(-) diff --git a/src/EvoSC.Common/Services/MapService.cs b/src/EvoSC.Common/Services/MapService.cs index 349599bd7..34dc5c5a9 100644 --- a/src/EvoSC.Common/Services/MapService.cs +++ b/src/EvoSC.Common/Services/MapService.cs @@ -75,9 +75,6 @@ public async Task AddMapAsync(MapStream mapStream) await _matchSettings.EditMatchSettingsAsync(Path.GetFileNameWithoutExtension(_config.Path.DefaultMatchSettings), builder => builder.AddMap($"EvoSC/{fileName}")); - /*await _serverClient.Remote.InsertMapAsync($"EvoSC/{fileName}"); - await _serverClient.Remote.SaveMatchSettingsAsync($"MatchSettings/{_config.Path.DefaultMatchSettings}"); */ - return map; } diff --git a/tests/EvoSC.Common.Tests/Services/MapServiceTests.cs b/tests/EvoSC.Common.Tests/Services/MapServiceTests.cs index 6e48ca9c3..06ba598b3 100644 --- a/tests/EvoSC.Common.Tests/Services/MapServiceTests.cs +++ b/tests/EvoSC.Common.Tests/Services/MapServiceTests.cs @@ -151,8 +151,6 @@ public async Task Add_Map_Returns_Map() var createdMap = await _mapService.AddMapAsync(mapStream); - _server.Remote.Verify(m => m.InsertMapAsync("EvoSC/" + mapMetadata.MapUid + ".Map.Gbx")); - Assert.Equal(MapProviders.ManiaExchange, createdMap.ExternalMapProvider); Assert.Equal(map.ExternalId, createdMap.ExternalId); Assert.Equal(map.Uid, createdMap.Uid); @@ -209,8 +207,6 @@ public async Task Add_Map_New_Map_Version_Returns_Map() var updatedMap = await _mapService.AddMapAsync(mapStream); - _server.Remote.Verify(m => m.InsertMapAsync("EvoSC/" + mapMetadata.MapUid + ".Map.Gbx")); - Assert.NotEqual(mapMetadata.ExternalVersion, updatedMap.ExternalVersion); Assert.Equal(MapProviders.ManiaExchange, updatedMap.ExternalMapProvider); Assert.Equal(map.ExternalId, updatedMap.ExternalId); @@ -323,8 +319,6 @@ public async Task Add_Maps_Return_Maps() var createdMaps = await _mapService.AddMapsAsync(new List { mapStream, mapStream2 }); - _server.Remote.Verify(m => m.InsertMapAsync(It.IsAny()), Times.Exactly(2)); - Assert.Equal(2, createdMaps.Count()); } From 6cfc63801b1ebd61e3436fcba13d238162d632ae Mon Sep 17 00:00:00 2001 From: snixtho Date: Tue, 3 Oct 2023 10:31:40 +0200 Subject: [PATCH 12/12] fix sonarcloud, ignoring live ranking module as it will be re-written --- src/EvoSC.Common/Util/RaceTime.cs | 9 +++++---- .../Controllers/ScoreboardCommandsController.cs | 2 +- .../Controllers/ScoreboardEventController.cs | 6 +++--- src/Modules/Scoreboard/Services/ScoreboardService.cs | 10 +++++----- .../Controllers/SpectatorTargetInfoEventController.cs | 8 ++++---- .../Services/SpectatorTargetInfoService.cs | 4 ++-- .../Controllers/WorldRecordEventController.cs | 4 ++-- tests/Modules/MatchTrackerModule.Tests/UnitTest1.cs | 9 --------- 8 files changed, 22 insertions(+), 30 deletions(-) delete mode 100644 tests/Modules/MatchTrackerModule.Tests/UnitTest1.cs diff --git a/src/EvoSC.Common/Util/RaceTime.cs b/src/EvoSC.Common/Util/RaceTime.cs index 73d1e3277..2f8ddf2da 100644 --- a/src/EvoSC.Common/Util/RaceTime.cs +++ b/src/EvoSC.Common/Util/RaceTime.cs @@ -1,4 +1,5 @@ -using EvoSC.Common.Interfaces.Util; +using System.Globalization; +using EvoSC.Common.Interfaces.Util; namespace EvoSC.Common.Util; @@ -30,15 +31,15 @@ public static IRaceTime FromMilliseconds(int totalMilliseconds) public override string ToString() { - var milli = Milliseconds.ToString().PadLeft(3, '0'); - var seconds = Seconds.ToString().PadLeft(2, '0'); + var milli = Milliseconds.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'); + var seconds = Seconds.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'); if (Minutes == 0 && Hours == 0) { return $"{seconds}.{milli}"; } - var minutes = Minutes.ToString().PadLeft(2, '0'); + var minutes = Minutes.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'); return Hours == 0 ? $"{minutes}:{seconds}.{milli}" : $"{Hours}:{minutes}:{seconds}.{milli}"; } diff --git a/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs b/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs index b6e6e4528..d90971c23 100644 --- a/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs +++ b/src/Modules/Scoreboard/Controllers/ScoreboardCommandsController.cs @@ -15,7 +15,7 @@ public ScoreboardCommandsController(IScoreboardService scoreboardService) => _scoreboardService = scoreboardService; [ChatCommand("scoreboard", "[Command.ShowScoreboard]")] - public async Task ShowScoreboard() + public async Task ShowScoreboardAsync() { await _scoreboardService.ShowScoreboardAsync(Context.Player); } diff --git a/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs b/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs index 545199285..bfeb638bf 100644 --- a/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs +++ b/src/Modules/Scoreboard/Controllers/ScoreboardEventController.cs @@ -20,21 +20,21 @@ public ScoreboardEventController(IScoreboardService scoreboardService) => _scoreboardService = scoreboardService; [Subscribe(GbxRemoteEvent.BeginMap)] - public async Task OnBeginMap(object sender, MapGbxEventArgs args) + public async Task OnBeginMapAsync(object sender, MapGbxEventArgs args) { await _scoreboardService.LoadAndSendRequiredAdditionalInfoAsync(); await _scoreboardService.ShowScoreboardToAllAsync(); } [Subscribe(MatchSettingsEvent.MatchSettingsLoaded)] - public async Task OnMatchSettingsLoaded(object sender, MatchSettingsLoadedEventArgs args) + public async Task OnMatchSettingsLoadedAsync(object sender, MatchSettingsLoadedEventArgs args) { await _scoreboardService.LoadAndSendRequiredAdditionalInfoAsync(); await _scoreboardService.ShowScoreboardToAllAsync(); } [Subscribe(ModeScriptEvent.StartRoundStart)] - public async Task OnRoundStart(object sender, RoundEventArgs args) + public async Task OnRoundStartAsync(object sender, RoundEventArgs args) { _scoreboardService.SetCurrentRound(args.Count); await _scoreboardService.SendRequiredAdditionalInfoAsync(); diff --git a/src/Modules/Scoreboard/Services/ScoreboardService.cs b/src/Modules/Scoreboard/Services/ScoreboardService.cs index e529bb533..6dfa156ba 100644 --- a/src/Modules/Scoreboard/Services/ScoreboardService.cs +++ b/src/Modules/Scoreboard/Services/ScoreboardService.cs @@ -30,15 +30,15 @@ public ScoreboardService(IManialinkManager manialinks, IServerClient server, IEv public async Task ShowScoreboardToAllAsync() { - await _manialinks.SendPersistentManialinkAsync("Scoreboard.Scoreboard", await GetData()); + await _manialinks.SendPersistentManialinkAsync("Scoreboard.Scoreboard", await GetDataAsync()); } public async Task ShowScoreboardAsync(IPlayer playerLogin) { - await _manialinks.SendManialinkAsync(playerLogin, "Scoreboard.Scoreboard", await GetData()); + await _manialinks.SendManialinkAsync(playerLogin, "Scoreboard.Scoreboard", await GetDataAsync()); } - private Task GetData() + private Task GetDataAsync() { return Task.FromResult(new { @@ -57,7 +57,7 @@ private Task GetData() public async Task HideNadeoScoreboardAsync() { - var hudSettings = new List() + var hudSettings = new List { @"{ ""uimodules"": [ @@ -77,7 +77,7 @@ public async Task HideNadeoScoreboardAsync() public async Task ShowNadeoScoreboardAsync() { - var hudSettings = new List() + var hudSettings = new List { @"{ ""uimodules"": [ diff --git a/src/Modules/SpectatorTargetInfoModule/Controllers/SpectatorTargetInfoEventController.cs b/src/Modules/SpectatorTargetInfoModule/Controllers/SpectatorTargetInfoEventController.cs index 82c2f0499..b9b2777cc 100644 --- a/src/Modules/SpectatorTargetInfoModule/Controllers/SpectatorTargetInfoEventController.cs +++ b/src/Modules/SpectatorTargetInfoModule/Controllers/SpectatorTargetInfoEventController.cs @@ -18,18 +18,18 @@ public SpectatorTargetInfoEventController(ISpectatorTargetInfoService spectatorT _spectatorTargetInfoService = spectatorTargetInfoService; [Subscribe(GbxRemoteEvent.PlayerConnect)] - public Task OnPlayerConnect(object x, PlayerConnectGbxEventArgs args) => + public Task OnPlayerConnectAsync(object x, PlayerConnectGbxEventArgs args) => _spectatorTargetInfoService.SendManiaLinkAsync(args.Login); [Subscribe(ModeScriptEvent.WayPoint)] - public Task OnWayPoint(object sender, WayPointEventArgs wayPointEventArgs) => + public Task OnWayPointAsync(object sender, WayPointEventArgs wayPointEventArgs) => _spectatorTargetInfoService.ForwardCheckpointTimeToClientsAsync(wayPointEventArgs); [Subscribe(ModeScriptEvent.StartRoundStart)] - public Task OnNewRound(object sender, RoundEventArgs roundEventArgs) => + public Task OnNewRoundAsync(object sender, RoundEventArgs roundEventArgs) => _spectatorTargetInfoService.ResetCheckpointTimesAsync(); [Subscribe(ModeScriptEvent.GiveUp)] - public Task OnPlayerGiveUp(object sender, PlayerUpdateEventArgs playerUpdateEventArgs) => + public Task OnPlayerGiveUpAsync(object sender, PlayerUpdateEventArgs playerUpdateEventArgs) => _spectatorTargetInfoService.ForwardDnfToClientsAsync(playerUpdateEventArgs); } diff --git a/src/Modules/SpectatorTargetInfoModule/Services/SpectatorTargetInfoService.cs b/src/Modules/SpectatorTargetInfoModule/Services/SpectatorTargetInfoService.cs index 6c5a9b2cf..6d0db7f0b 100644 --- a/src/Modules/SpectatorTargetInfoModule/Services/SpectatorTargetInfoService.cs +++ b/src/Modules/SpectatorTargetInfoModule/Services/SpectatorTargetInfoService.cs @@ -36,7 +36,7 @@ public async Task HideManiaLinkAsync() => public Task HideNadeoSpectatorInfoAsync() { - var hudSettings = new List() + var hudSettings = new List { @"{""uimodules"": [ { @@ -57,7 +57,7 @@ public Task HideNadeoSpectatorInfoAsync() public Task ShowNadeoSpectatorInfoAsync() { - var hudSettings = new List() + var hudSettings = new List { @"{""uimodules"": [ { diff --git a/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs b/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs index c2bb294be..c0c3de979 100644 --- a/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs +++ b/src/Modules/WorldRecordModule/Controllers/WorldRecordEventController.cs @@ -17,10 +17,10 @@ public WorldRecordEventController(IWorldRecordService worldRecordService) => _worldRecordService = worldRecordService; [Subscribe(ModeScriptEvent.EndMapEnd)] - public Task OnMapEnd(object sender, MapEventArgs mapEventArgs) + public Task OnMapEndAsync(object sender, MapEventArgs mapEventArgs) => _worldRecordService.ClearRecordAsync(); [Subscribe(ModeScriptEvent.StartMapStart)] - public Task OnMapStart(object sender, MapEventArgs mapEventArgs) + public Task OnMapStartAsync(object sender, MapEventArgs mapEventArgs) => _worldRecordService.FetchRecordAsync(mapEventArgs.Map.Uid); } diff --git a/tests/Modules/MatchTrackerModule.Tests/UnitTest1.cs b/tests/Modules/MatchTrackerModule.Tests/UnitTest1.cs deleted file mode 100644 index dc11279db..000000000 --- a/tests/Modules/MatchTrackerModule.Tests/UnitTest1.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace MatchTrackerModule.Tests; - -public class UnitTest1 -{ - [Fact] - public void Test1() - { - } -}