rott/kf_sources/KFPatcher/Classes/stub_VotingHandler.uc
2026-07-14 20:27:09 +07:00

142 lines
5.4 KiB
Ucode

class stub_VotingHandler extends xVotingHandler;
// only REAL players are counted. FUCKING IGNORES SPECS AND FAKES. FINALLY!!!!!!
function TallyVotes(bool bForceMapSwitch)
{
local int oldNumPlayers;
local Controller c;
// save the current player count
oldNumPlayers = Level.Game.NumPlayers;
// reset the player count
Level.Game.NumPlayers = 0;
// count real players to prevent fakes from or specs from preventing map switching
for (c=level.ControllerList; c!=none; c=c.nextController)
{
if (c.bIsPlayer && c.PlayerReplicationInfo != none && !c.PlayerReplicationInfo.bOnlySpectator)
Level.Game.NumPlayers++;
}
super(xVotingHandler).TallyVotes(bForceMapSwitch);
// restore the original number of players
Level.Game.NumPlayers = oldNumPlayers;
}
// this is just here to tell spectators that they can't vote
function SubmitMapVote(int MapIndex, int GameIndex, Actor Voter)
{
local int Index, VoteCount, PrevMapVote, PrevGameVote;
local MapHistoryInfo MapInfo;
local bool bAdminForce;
if (bLevelSwitchPending)
return;
Index = GetMVRIIndex(PlayerController(Voter));
if (GameIndex < 0)
{
bAdminForce = true;
GameIndex = (-GameIndex) - 1;
}
if (GameIndex >= GameConfig.Length || MapIndex < 0 || MapIndex >= MapList.Length)
return; // Something is wrong...
// check for invalid vote from unpatch players
if (!IsValidVote(MapIndex, GameIndex))
return;
// Administrator Vote
if (bAdminForce && (PlayerController(Voter).PlayerReplicationInfo.bAdmin || PlayerController(Voter).PlayerReplicationInfo.bSilentAdmin))
{
TextMessage = lmsgAdminMapChange;
TextMessage = Repl(TextMessage, "%mapname%", MapList[MapIndex].MapName $ "(" $ GameConfig[GameIndex].Acronym $ ")");
Level.Game.Broadcast(self,TextMessage);
log("Admin has forced map switch to " $ MapList[MapIndex].MapName $ "(" $ GameConfig[GameIndex].Acronym $ ")",'MapVote');
CloseAllVoteWindows();
bLevelSwitchPending = true;
MapInfo = History.PlayMap(MapList[MapIndex].MapName);
ServerTravelString = SetupGameMap(MapList[MapIndex], GameIndex, MapInfo);
log("ServerTravelString = " $ ServerTravelString ,'MapVoteDebug');
// change the map
Level.ServerTravel(ServerTravelString, false);
settimer(1,true);
return;
}
if (PlayerController(Voter).PlayerReplicationInfo.bOnlySpectator)
{
// Spectators cant vote
PlayerController(Voter).ClientMessage(lmsgSpectatorsCantVote);
return;
}
// check for invalid map, invalid gametype, player isnt revoting same as previous vote, and map choosen isnt disabled
if (MapIndex < 0 || MapIndex >= MapCount || GameIndex >= GameConfig.Length || (MVRI[Index].GameVote == GameIndex && MVRI[Index].MapVote == MapIndex) ||
!MapList[MapIndex].bEnabled)
return;
log("___" $ Index $ " - " $ PlayerController(Voter).PlayerReplicationInfo.PlayerName $ " voted for " $ MapList[MapIndex].MapName $ "(" $ GameConfig[GameIndex].Acronym $ ")",'MapVote');
PrevMapVote = MVRI[Index].MapVote;
PrevGameVote = MVRI[Index].GameVote;
MVRI[Index].MapVote = MapIndex;
MVRI[Index].GameVote = GameIndex;
if (bAccumulationMode)
{
if (bScoreMode)
{
VoteCount = GetAccVote(PlayerController(Voter)) + int(GetPlayerScore(PlayerController(Voter)));
TextMessage = lmsgMapVotedForWithCount;
TextMessage = repl(TextMessage, "%playername%", PlayerController(Voter).PlayerReplicationInfo.PlayerName );
TextMessage = repl(TextMessage, "%votecount%", string(VoteCount) );
TextMessage = repl(TextMessage, "%mapname%", MapList[MapIndex].MapName $ "(" $ GameConfig[GameIndex].Acronym $ ")" );
Level.Game.Broadcast(self,TextMessage);
}
else
{
VoteCount = GetAccVote(PlayerController(Voter)) + 1;
TextMessage = lmsgMapVotedForWithCount;
TextMessage = repl(TextMessage, "%playername%", PlayerController(Voter).PlayerReplicationInfo.PlayerName );
TextMessage = repl(TextMessage, "%votecount%", string(VoteCount) );
TextMessage = repl(TextMessage, "%mapname%", MapList[MapIndex].MapName $ "(" $ GameConfig[GameIndex].Acronym $ ")" );
Level.Game.Broadcast(self,TextMessage);
}
}
else
{
if (bScoreMode)
{
VoteCount = int(GetPlayerScore(PlayerController(Voter)));
TextMessage = lmsgMapVotedForWithCount;
TextMessage = repl(TextMessage, "%playername%", PlayerController(Voter).PlayerReplicationInfo.PlayerName );
TextMessage = repl(TextMessage, "%votecount%", string(VoteCount) );
TextMessage = repl(TextMessage, "%mapname%", MapList[MapIndex].MapName $ "(" $ GameConfig[GameIndex].Acronym $ ")" );
Level.Game.Broadcast(self,TextMessage);
}
else
{
VoteCount = 1;
TextMessage = lmsgMapVotedFor;
TextMessage = repl(TextMessage, "%playername%", PlayerController(Voter).PlayerReplicationInfo.PlayerName );
TextMessage = repl(TextMessage, "%mapname%", MapList[MapIndex].MapName $ "(" $ GameConfig[GameIndex].Acronym $ ")" );
Level.Game.Broadcast(self,TextMessage);
}
}
UpdateVoteCount(MapIndex, GameIndex, VoteCount);
if (PrevMapVote > -1 && PrevGameVote > -1)
UpdateVoteCount(PrevMapVote, PrevGameVote, -MVRI[Index].VoteCount); // undo previous vote
MVRI[Index].VoteCount = VoteCount;
TallyVotes(false);
}