From e6ef9428f07379e02aa60d06017e4ff363083c28 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Wed, 8 Mar 2023 14:04:03 +0700 Subject: [PATCH] Fix map switching Previously map switching didn't work because of the map name replacement. This patch fixes that fatal flaw for the voting handler. --- sources/MapList/MapTool.uc | 79 +++++++++++++++++++++++++++------ sources/VotingHandlerAdapter.uc | 2 +- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/sources/MapList/MapTool.uc b/sources/MapList/MapTool.uc index a1d8dc8..ba5ec86 100644 --- a/sources/MapList/MapTool.uc +++ b/sources/MapList/MapTool.uc @@ -22,19 +22,27 @@ class MapTool extends AcediaObject; var private NativeActorRef votingHandlerReference; // Maps map pseudonims we've used in voting handler to real map names var private HashTable pseudonimToMap; -var private array outputMapList; +var private array pseudonimMapList; +var private array realMapList; var private int gameModesSeen; +var private string backupMessageMapWon; +var private string backupMessageAdminMapChange; +var private const string ACEDIA_MAP_FORCED_COMMAND; +var private const string ACEDIA_MAP_WON_COMMAND; + protected function Constructor() { pseudonimToMap = _.collections.EmptyHashTable(); } protected function Finalizer() { + _server.unreal.broadcasts.OnHandleText(self).Disconnect(); _.memory.Free(votingHandlerReference); _.memory.Free(pseudonimToMap); votingHandlerReference = none; pseudonimToMap = none; - outputMapList.length = 0; + pseudonimMapList.length = 0; + realMapList.length = 0; gameModesSeen = 0; } @@ -54,7 +62,7 @@ public function string LoadGameModeMaps(GameMode gameMode) { local Text mapNameReal, mapNamePseudonim; local VotingHandler.MapHistoryInfo nextMapInfo; local VotingHandler.MapVoteMapList nextRecord; - local array newMaps; + local array newMapsPseudonim, newMapReal; local string gameModePrefix; votingHandler = GetVotingHandler(); @@ -70,7 +78,6 @@ public function string LoadGameModeMaps(GameMode gameMode) { mapNamePseudonim = MakeMapPseudonim(mapNameReal, gameModePrefix); pseudonimToMap.SetItem(mapNamePseudonim, mapNameReal); // Setup `VotingHandler.MapVoteMapList` struct for next map - nextRecord.mapName = mapNamePseudonim.ToString(); if (votingHandler.history != none) { nextMapInfo = votingHandler.history.GetMapHistory(mapNameReal.ToString()); nextRecord.playCount = nextMapInfo.p; @@ -79,9 +86,12 @@ public function string LoadGameModeMaps(GameMode gameMode) { nextRecord.playCount = 0; nextRecord.sequence = 0; } - newMaps[newMaps.length] = nextRecord; + nextRecord.mapName = mapNamePseudonim.ToString(); + newMapsPseudonim[newMapsPseudonim.length] = nextRecord; + nextRecord.mapName = mapNameReal.ToString(); + newMapReal[newMapReal.length] = nextRecord; } - AppendMapsIntoHandler(newMaps); + AppendMaps(newMapsPseudonim, newMapReal); gameModesSeen += 1; return gameModePrefix; } @@ -148,7 +158,9 @@ private function ArrayList GetAllGameModeMaps(GameMode gameMode) { return result; } -private function AppendMapsIntoHandler(array newMaps) { +private function AppendMaps( + array newMapsPseudonim, + array newMapsReal) { local int i; local XVotingHandler votingHandler; @@ -157,12 +169,11 @@ private function AppendMapsIntoHandler(array newMa warn("votingHandler is none!"); return; } - if (newMaps.length == 0) { - warn("newMaps.length is 0!"); - return; + for (i = 0; i < newMapsPseudonim.length; i += 1) { + pseudonimMapList[pseudonimMapList.length] = newMapsPseudonim[i]; } - for (i = 0; i < newMaps.length; i += 1) { - outputMapList[outputMapList.length] = newMaps[i]; + for (i = 0; i < newMapsReal.length; i += 1) { + realMapList[realMapList.length] = newMapsReal[i]; } } @@ -171,9 +182,47 @@ public final function InjectMaps() { votingHandler = GetVotingHandler(); if (votingHandler != none) { - votingHandler.mapList = outputMapList; - votingHandler.mapCount = outputMapList.length; + votingHandler.mapList = pseudonimMapList; + votingHandler.mapCount = pseudonimMapList.length; + backupMessageMapWon = votingHandler.lmsgMapWon; + backupMessageAdminMapChange = votingHandler.lmsgAdminMapChange; + votingHandler.lmsgMapWon = ACEDIA_MAP_WON_COMMAND $ "::%mapname%"; + votingHandler.lmsgAdminMapChange = ACEDIA_MAP_FORCED_COMMAND $ "::%mapname%"; + _server.unreal.broadcasts.OnHandleText(self).connect = HandleMapChange; + } +} + +private function bool HandleMapChange( + Actor sender, + out string message, + name type, + bool teamMessage +) { + local Parser parser; + local XVotingHandler votingHandler; + + votingHandler = GetVotingHandler(); + if (sender == none) return true; + if (votingHandler != sender) return true; + + parser = _.text.ParseString(message); + parser.Match(P(ACEDIA_MAP_WON_COMMAND)); + parser.Match(P("::")); + if (parser.Ok()) { + message = Repl(backupMessageMapWon, "%mapname%", parser.GetRemainderS()); + } else { + parser.Match(P(ACEDIA_MAP_FORCED_COMMAND)); + parser.Match(P("::")); + if (parser.Ok()) { + message = Repl(backupMessageAdminMapChange, "%mapname%", parser.GetRemainderS()); + } } + if (parser.Ok()) { + votingHandler.mapList = realMapList; + votingHandler.mapCount = realMapList.length; + } + _.memory.Free(parser); + return true; } private function XVotingHandler GetVotingHandler() { @@ -184,4 +233,6 @@ private function XVotingHandler GetVotingHandler() { } defaultproperties { + ACEDIA_MAP_FORCED_COMMAND = "ACEDIA_LAUNCHER:MAP_FORCED:DEADBEEF" + ACEDIA_MAP_WON_COMMAND = "ACEDIA_LAUNCHER:MAP_WON:DEADBEEF" } \ No newline at end of file diff --git a/sources/VotingHandlerAdapter.uc b/sources/VotingHandlerAdapter.uc index e338685..d6e6216 100644 --- a/sources/VotingHandlerAdapter.uc +++ b/sources/VotingHandlerAdapter.uc @@ -145,7 +145,7 @@ public final function InjectIntoVotingHandler() backupVotingHandlerConfig = votingHandler.gameConfig; votingHandler.gameConfig = newVotingHandlerConfig; mapTool.InjectMaps(); - _.memory.Free(mapTool); + //_.memory.Free(mapTool); } private function VotingHandler.MapVoteGameConfig BuildVotingHandlerConfig(