KF2-Server-Extension/ServerExt/Classes/xVotingReplication.uc

238 lines
6.2 KiB
Ucode
Raw Permalink Normal View History

2017-10-20 02:00:49 +00:00
// Written by Marco.
// Mapvote manager client.
Class xVotingReplication extends ReplicationInfo;
struct FGameTypeEntry
{
var string GameName,GameShortName,Prefix;
};
struct FMapEntry
{
var string MapName,MapTitle;
var int UpVotes,DownVotes,Sequence,NumPlays,History;
};
struct FVotedMaps
{
var int GameIndex,MapIndex,NumVotes;
};
var array<FGameTypeEntry> GameModes;
var array<FMapEntry> Maps;
var array<FVotedMaps> ActiveVotes;
var PlayerController PlayerOwner;
var xVotingHandlerBase VoteHandler;
var byte DownloadStage;
var int DownloadIndex,ClientCurrentGame;
var int CurrentVote[2];
var transient float RebunchTimer,NextVoteTimer;
var bool bClientConnected,bAllReceived,bClientRanked;
var transient bool bListDirty;
2020-08-11 16:18:40 +00:00
var localized string MaplistRecvMsg;
var localized string ClientMapVoteMsg;
var localized string InitMapVoteMsg;
var localized string TwoMinRemainMsg;
var localized string OneMinRemainMsg;
var localized string XSecondsRemainMsg;
var localized string UnknownPlayerName;
var localized string VotedForKnownMapMsg;
var localized string VotedForUnkownMapMsg;
var localized string AdminForcedKnownMapswitchMsg;
var localized string AdminForcedUnknownMapswitchMsg;
var localized string KnownMapSwitchMsg;
var localized string UnknownMapSwitchMsg;
2017-10-20 02:00:49 +00:00
function PostBeginPlay()
{
PlayerOwner = PlayerController(Owner);
RebunchTimer = WorldInfo.TimeSeconds+5.f;
}
2020-08-11 16:18:40 +00:00
2020-11-28 20:04:55 +00:00
function Tick(float Delta)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (PlayerOwner==None || PlayerOwner.Player==None)
2017-10-20 02:00:49 +00:00
{
Destroy();
return;
}
2020-11-28 20:12:58 +00:00
if (!bClientConnected)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (RebunchTimer<WorldInfo.TimeSeconds)
2017-10-20 02:00:49 +00:00
{
RebunchTimer = WorldInfo.TimeSeconds+0.75;
ClientVerify();
}
}
2020-11-28 20:12:58 +00:00
else if (DownloadStage<255)
2017-10-20 02:00:49 +00:00
VoteHandler.ClientDownloadInfo(Self);
}
reliable server function ServerNotifyReady()
{
bClientConnected = true;
}
2020-11-28 21:54:57 +00:00
2017-10-20 02:00:49 +00:00
unreliable client simulated function ClientVerify()
{
SetOwner(GetPlayer());
ServerNotifyReady();
}
simulated final function PlayerController GetPlayer()
{
2020-11-28 20:12:58 +00:00
if (PlayerOwner==None)
2017-10-20 02:00:49 +00:00
PlayerOwner = GetALocalPlayerController();
return PlayerOwner;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientReceiveGame(int Index, string GameName, string GameSName, string Prefix)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (GameModes.Length<=Index)
2017-10-20 02:00:49 +00:00
GameModes.Length = Index+1;
GameModes[Index].GameName = GameName;
GameModes[Index].GameShortName = GameSName;
GameModes[Index].Prefix = Prefix;
bListDirty = true;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientReceiveMap(int Index, string MapName, int UpVote, int DownVote, int Sequence, int NumPlays, optional string MapTitle)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Maps.Length<=Index)
2017-10-20 02:00:49 +00:00
Maps.Length = Index+1;
Maps[Index].MapName = MapName;
Maps[Index].MapTitle = (MapTitle!="" ? MapTitle : MapName);
Maps[Index].UpVotes = UpVote;
Maps[Index].DownVotes = DownVote;
Maps[Index].Sequence = Sequence;
Maps[Index].NumPlays = NumPlays;
bListDirty = true;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientReceiveVote(int GameIndex, int MapIndex, int VoteCount)
2017-10-20 02:00:49 +00:00
{
local int i;
2023-05-14 02:49:12 +00:00
2020-11-28 20:12:58 +00:00
for (i=0; i<ActiveVotes.Length; ++i)
if (ActiveVotes[i].GameIndex==GameIndex && ActiveVotes[i].MapIndex==MapIndex)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (VoteCount==0)
2017-10-20 02:00:49 +00:00
ActiveVotes.Remove(i,1);
else ActiveVotes[i].NumVotes = VoteCount;
bListDirty = true;
return;
}
2020-11-28 20:12:58 +00:00
if (VoteCount==0)
2017-10-20 02:00:49 +00:00
return;
ActiveVotes.Length = i+1;
ActiveVotes[i].GameIndex = GameIndex;
ActiveVotes[i].MapIndex = MapIndex;
ActiveVotes[i].NumVotes = VoteCount;
bListDirty = true;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientReady(int CurGame)
2017-10-20 02:00:49 +00:00
{
ClientCurrentGame = CurGame;
bAllReceived = true;
2020-08-11 16:18:40 +00:00
MapVoteMsg(MaplistRecvMsg);
2017-10-20 02:00:49 +00:00
}
2020-11-28 20:04:55 +00:00
simulated final function MapVoteMsg(string S)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (S!="")
2020-08-11 16:18:40 +00:00
GetPlayer().ClientMessage(ClientMapVoteMsg$" "$S);
2017-10-20 02:00:49 +00:00
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientNotifyVote(PlayerReplicationInfo PRI, int GameIndex, int MapIndex)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllReceived)
2020-08-11 16:18:40 +00:00
MapVoteMsg((PRI!=None ? PRI.PlayerName : UnknownPlayerName)$" "$VotedForKnownMapMsg$" "$Maps[MapIndex].MapTitle$" ("$GameModes[GameIndex].GameShortName$").");
else MapVoteMsg((PRI!=None ? PRI.PlayerName : UnknownPlayerName)$" "$VotedForUnkownMapMsg);
2017-10-20 02:00:49 +00:00
}
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientNotifyVoteTime(int Time)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Time==0)
2020-08-11 16:18:40 +00:00
MapVoteMsg(InitMapVoteMsg);
2020-11-28 20:12:58 +00:00
if (Time<=10)
2017-10-20 02:00:49 +00:00
MapVoteMsg(string(Time)$"...");
2020-11-28 20:12:58 +00:00
else if (Time<60)
2020-08-11 16:18:40 +00:00
MapVoteMsg(string(Time)$" "$XSecondsRemainMsg);
2020-11-28 20:12:58 +00:00
else if (Time==60)
2020-08-11 16:18:40 +00:00
MapVoteMsg(OneMinRemainMsg);
2020-11-28 20:12:58 +00:00
else if (Time==120)
2020-08-11 16:18:40 +00:00
MapVoteMsg(TwoMinRemainMsg);
2017-10-20 02:00:49 +00:00
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientNotifyVoteWin(int GameIndex, int MapIndex, bool bAdminForce)
2017-10-20 02:00:49 +00:00
{
Class'KF2GUIController'.Static.GetGUIController(GetPlayer()).CloseMenu(None,true);
2020-11-28 20:12:58 +00:00
if (bAdminForce)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllReceived)
2020-08-11 16:18:40 +00:00
MapVoteMsg(AdminForcedKnownMapswitchMsg$" "$Maps[MapIndex].MapTitle$" ("$GameModes[GameIndex].GameShortName$").");
else MapVoteMsg(AdminForcedUnknownMapswitchMsg);
2017-10-20 02:00:49 +00:00
}
2020-11-28 20:12:58 +00:00
else if (bAllReceived)
2020-08-11 16:18:40 +00:00
MapVoteMsg(Maps[MapIndex].MapTitle$" ("$GameModes[GameIndex].GameShortName$") "$KnownMapSwitchMsg);
else MapVoteMsg(UnknownMapSwitchMsg);
2017-10-20 02:00:49 +00:00
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable client simulated function ClientOpenMapvote(optional bool bShowRank)
2017-10-20 02:00:49 +00:00
{
local xUI_MapRank R;
2020-11-28 20:12:58 +00:00
if (bAllReceived)
2017-10-20 02:00:49 +00:00
SetTimer(0.001,false,'DelayedOpenMapvote'); // To prevent no-mouse issue when local server host opens it from chat.
2020-11-28 20:12:58 +00:00
if (bShowRank)
2017-10-20 02:00:49 +00:00
{
R = xUI_MapRank(Class'KF2GUIController'.Static.GetGUIController(GetPlayer()).OpenMenu(class'xUI_MapRank'));
R.RepInfo = Self;
2023-05-14 02:49:12 +00:00
2020-11-28 20:12:58 +00:00
if (KFGFxHudWrapper(GetPlayer().myHUD)!=None)
2017-10-20 02:00:49 +00:00
KFGFxHudWrapper(GetPlayer().myHUD).HudMovie.DisplayPriorityMessage("MAP VOTE TIME","Cast your votes!",2);
2023-05-14 02:49:12 +00:00
2020-11-28 20:12:58 +00:00
if (KFGameReplicationInfo(WorldInfo.GRI)!=none)
2017-10-20 02:00:49 +00:00
KFGameReplicationInfo(WorldInfo.GRI).ProcessChanceDrop();
}
}
2020-11-28 21:54:57 +00:00
2017-10-20 02:00:49 +00:00
simulated function DelayedOpenMapvote()
{
local xUI_MapVote U;
U = xUI_MapVote(Class'KF2GUIController'.Static.GetGUIController(GetPlayer()).OpenMenu(class'xUI_MapVote'));
U.InitMapvote(Self);
}
2020-11-28 20:04:55 +00:00
reliable server simulated function ServerCastVote(int GameIndex, int MapIndex, bool bAdminForce)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (NextVoteTimer<WorldInfo.TimeSeconds)
2017-10-20 02:00:49 +00:00
{
NextVoteTimer = WorldInfo.TimeSeconds+1.f;
VoteHandler.ClientCastVote(Self,GameIndex,MapIndex,bAdminForce);
}
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
reliable server simulated function ServerRankMap(bool bUp)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (!bClientRanked)
2017-10-20 02:00:49 +00:00
{
bClientRanked = true;
VoteHandler.ClientRankMap(Self,bUp);
}
}
function Destroyed()
{
VoteHandler.ClientDisconnect(Self);
}
defaultproperties
{
bAlwaysRelevant=false
bOnlyRelevantToOwner=true
CurrentVote(0)=-1
CurrentVote(1)=-1
}