Browse Source

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.
pull/2/head
Anton Tarasenko 2 years ago
parent
commit
e6ef9428f0
  1. 79
      sources/MapList/MapTool.uc
  2. 2
      sources/VotingHandlerAdapter.uc

79
sources/MapList/MapTool.uc

@ -22,19 +22,27 @@ class MapTool extends AcediaObject;
var private NativeActorRef votingHandlerReference; var private NativeActorRef votingHandlerReference;
// Maps map pseudonims we've used in voting handler to real map names // Maps map pseudonims we've used in voting handler to real map names
var private HashTable pseudonimToMap; var private HashTable pseudonimToMap;
var private array<VotingHandler.MapVoteMapList> outputMapList; var private array<VotingHandler.MapVoteMapList> pseudonimMapList;
var private array<VotingHandler.MapVoteMapList> realMapList;
var private int gameModesSeen; 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() { protected function Constructor() {
pseudonimToMap = _.collections.EmptyHashTable(); pseudonimToMap = _.collections.EmptyHashTable();
} }
protected function Finalizer() { protected function Finalizer() {
_server.unreal.broadcasts.OnHandleText(self).Disconnect();
_.memory.Free(votingHandlerReference); _.memory.Free(votingHandlerReference);
_.memory.Free(pseudonimToMap); _.memory.Free(pseudonimToMap);
votingHandlerReference = none; votingHandlerReference = none;
pseudonimToMap = none; pseudonimToMap = none;
outputMapList.length = 0; pseudonimMapList.length = 0;
realMapList.length = 0;
gameModesSeen = 0; gameModesSeen = 0;
} }
@ -54,7 +62,7 @@ public function string LoadGameModeMaps(GameMode gameMode) {
local Text mapNameReal, mapNamePseudonim; local Text mapNameReal, mapNamePseudonim;
local VotingHandler.MapHistoryInfo nextMapInfo; local VotingHandler.MapHistoryInfo nextMapInfo;
local VotingHandler.MapVoteMapList nextRecord; local VotingHandler.MapVoteMapList nextRecord;
local array<VotingHandler.MapVoteMapList> newMaps; local array<VotingHandler.MapVoteMapList> newMapsPseudonim, newMapReal;
local string gameModePrefix; local string gameModePrefix;
votingHandler = GetVotingHandler(); votingHandler = GetVotingHandler();
@ -70,7 +78,6 @@ public function string LoadGameModeMaps(GameMode gameMode) {
mapNamePseudonim = MakeMapPseudonim(mapNameReal, gameModePrefix); mapNamePseudonim = MakeMapPseudonim(mapNameReal, gameModePrefix);
pseudonimToMap.SetItem(mapNamePseudonim, mapNameReal); pseudonimToMap.SetItem(mapNamePseudonim, mapNameReal);
// Setup `VotingHandler.MapVoteMapList` struct for next map // Setup `VotingHandler.MapVoteMapList` struct for next map
nextRecord.mapName = mapNamePseudonim.ToString();
if (votingHandler.history != none) { if (votingHandler.history != none) {
nextMapInfo = votingHandler.history.GetMapHistory(mapNameReal.ToString()); nextMapInfo = votingHandler.history.GetMapHistory(mapNameReal.ToString());
nextRecord.playCount = nextMapInfo.p; nextRecord.playCount = nextMapInfo.p;
@ -79,9 +86,12 @@ public function string LoadGameModeMaps(GameMode gameMode) {
nextRecord.playCount = 0; nextRecord.playCount = 0;
nextRecord.sequence = 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; gameModesSeen += 1;
return gameModePrefix; return gameModePrefix;
} }
@ -148,7 +158,9 @@ private function ArrayList GetAllGameModeMaps(GameMode gameMode) {
return result; return result;
} }
private function AppendMapsIntoHandler(array<VotingHandler.MapVoteMapList> newMaps) { private function AppendMaps(
array<VotingHandler.MapVoteMapList> newMapsPseudonim,
array<VotingHandler.MapVoteMapList> newMapsReal) {
local int i; local int i;
local XVotingHandler votingHandler; local XVotingHandler votingHandler;
@ -157,12 +169,11 @@ private function AppendMapsIntoHandler(array<VotingHandler.MapVoteMapList> newMa
warn("votingHandler is none!"); warn("votingHandler is none!");
return; return;
} }
if (newMaps.length == 0) { for (i = 0; i < newMapsPseudonim.length; i += 1) {
warn("newMaps.length is 0!"); pseudonimMapList[pseudonimMapList.length] = newMapsPseudonim[i];
return;
} }
for (i = 0; i < newMaps.length; i += 1) { for (i = 0; i < newMapsReal.length; i += 1) {
outputMapList[outputMapList.length] = newMaps[i]; realMapList[realMapList.length] = newMapsReal[i];
} }
} }
@ -171,9 +182,47 @@ public final function InjectMaps() {
votingHandler = GetVotingHandler(); votingHandler = GetVotingHandler();
if (votingHandler != none) { if (votingHandler != none) {
votingHandler.mapList = outputMapList; votingHandler.mapList = pseudonimMapList;
votingHandler.mapCount = outputMapList.length; 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() { private function XVotingHandler GetVotingHandler() {
@ -184,4 +233,6 @@ private function XVotingHandler GetVotingHandler() {
} }
defaultproperties { defaultproperties {
ACEDIA_MAP_FORCED_COMMAND = "ACEDIA_LAUNCHER:MAP_FORCED:DEADBEEF"
ACEDIA_MAP_WON_COMMAND = "ACEDIA_LAUNCHER:MAP_WON:DEADBEEF"
} }

2
sources/VotingHandlerAdapter.uc

@ -145,7 +145,7 @@ public final function InjectIntoVotingHandler()
backupVotingHandlerConfig = votingHandler.gameConfig; backupVotingHandlerConfig = votingHandler.gameConfig;
votingHandler.gameConfig = newVotingHandlerConfig; votingHandler.gameConfig = newVotingHandlerConfig;
mapTool.InjectMaps(); mapTool.InjectMaps();
_.memory.Free(mapTool); //_.memory.Free(mapTool);
} }
private function VotingHandler.MapVoteGameConfig BuildVotingHandlerConfig( private function VotingHandler.MapVoteGameConfig BuildVotingHandlerConfig(

Loading…
Cancel
Save