From d8778206b12872558f52747a719e3e510cfc54b5 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Wed, 23 Jun 2021 00:58:28 +0300 Subject: [PATCH] abc --- MskGs/Classes/MskGsMut.uc | 48 ++++++---- MskGs/Classes/MskGsVoteCollector.uc | 141 +++++++++++++++++++--------- 2 files changed, 131 insertions(+), 58 deletions(-) diff --git a/MskGs/Classes/MskGsMut.uc b/MskGs/Classes/MskGsMut.uc index 7e4b140..1022060 100644 --- a/MskGs/Classes/MskGsMut.uc +++ b/MskGs/Classes/MskGsMut.uc @@ -1,10 +1,7 @@ Class MskGsMut extends KFMutator config(MskGs); -var const int SteamIDLen; -var const int UniqueIDLen; - -var const int CurrentVersion; +const CurrentVersion = 2; var config int ConfigVersion; var config bool bEnableMapStats; @@ -13,7 +10,7 @@ var config bool bOfficialNextMapOnly; var config bool bRandomizeNextMap; var config int WeapDespawnTime; -var config array ImportantPersonList; +var config array KickProtectedList; var config array PerPlayerMaxMonsters; function InitMutator(string Options, out string ErrorMessage) @@ -62,7 +59,7 @@ function InitConfig() `log("[MskGsMut] Config is up-to-date"); break; default: - `log("[MskGsMut] Warn: The config version is higher than the current version (are you using an old mutator?)"); + `log("[MskGsMut] Warn: The config version is higher than the current version"); `log("[MskGsMut] Warn: Config version is"@ConfigVersion@"but current version is"@CurrentVersion); `log("[MskGsMut] Warn: The config version will be changed to "@CurrentVersion); break; @@ -125,17 +122,17 @@ function Initialize() steamworks = class'GameEngine'.static.GetOnlineSubsystem(); - foreach ImportantPersonList(Person) + foreach KickProtectedList(Person) { - if (Len(Person) == UniqueIDLen && steamworks.StringToUniqueNetId(Person, PersonUID)) + if (IsUID(Person) && steamworks.StringToUniqueNetId(Person, PersonUID)) { - if (VoteCollector.ImportantPersonList.Find('Uid', PersonUID.Uid) == -1) - VoteCollector.ImportantPersonList.AddItem(PersonUID); + if (VoteCollector.KickProtectedList.Find('Uid', PersonUID.Uid) == -1) + VoteCollector.KickProtectedList.AddItem(PersonUID); } - else if (Len(Person) == SteamIDLen && steamworks.Int64ToUniqueNetId(Person, PersonUID)) + else if (steamworks.Int64ToUniqueNetId(Person, PersonUID)) { - if (VoteCollector.ImportantPersonList.Find('Uid', PersonUID.Uid) == -1) - VoteCollector.ImportantPersonList.AddItem(PersonUID); + if (VoteCollector.KickProtectedList.Find('Uid', PersonUID.Uid) == -1) + VoteCollector.KickProtectedList.AddItem(PersonUID); } else `Log("[MskGsMut] WARN: Can't add person:"@Person); } @@ -170,6 +167,11 @@ function AddMutator(Mutator Mut) Super.AddMutator(Mut); } +private function bool IsUID(String ID) +{ + return (Left(ID, 2) ~= "0x"); +} + function bool CheckRelevance(Actor Other) { local bool SuperRelevant; @@ -210,9 +212,23 @@ function bool PreventDeath(Pawn Killed, Controller Killer, class dam return Super.PreventDeath(Killed, Killer, damageType, HitLocation); } +function NotifyLogin(Controller NewPlayer) +{ + super.NotifyLogin(NewPlayer); +} + +function NotifyLogout(Controller Exiting) +{ + local MskGsVoteCollector VoteCollector; + + VoteCollector = MskGsVoteCollector(MyKFGI.MyKFGRI.VoteCollector); + + VoteCollector.NotifyLogout(Exiting); + + super.NotifyLogout(Exiting); +} + defaultproperties { - SteamIDLen=17 - UniqueIDLen=18 - CurrentVersion=2 // Config + } diff --git a/MskGs/Classes/MskGsVoteCollector.uc b/MskGs/Classes/MskGsVoteCollector.uc index 7c27cef..bb50c78 100644 --- a/MskGs/Classes/MskGsVoteCollector.uc +++ b/MskGs/Classes/MskGsVoteCollector.uc @@ -8,57 +8,114 @@ var bool bRandomizeNextMap; var private array ActiveMapCycle; -var public array ImportantPersonList; -var private array PunishList; +var public array KickProtectedList; -function ServerStartPunishment() +var private array KickWarningList; +var private array KickPunishList; + +function NotifyLogout(Controller Exiting) +{ + KickWarningList.RemoveItem(KFPlayerController(Exiting)); + KickPunishList.RemoveItem(KFPlayerController(Exiting)); +} + +function PunishmentTick() { local KFGameReplicationInfo KFGRI; local KFGameInfo KFGI; local KFPlayerController KFPC; - local int i; + local KFInventoryManager KFIM; + local array LocalKickPunishList; - if (PunishList.Length == 0) + if (KickPunishList.Length == 0) + { + ClearTimer(nameof(PunishmentTick)); return; + } KFGRI = KFGameReplicationInfo(WorldInfo.GRI); KFGI = KFGameInfo(WorldInfo.Game); - for (i=0; i < PunishList.Length; i++) + LocalKickPunishList = KickPunishList; + foreach LocalKickPunishList(KFPC) { - KFPC = PunishList[i]; if (KFGRI.bMatchHasBegun) { - KFPC.Suicide(); + if (KFPC.Pawn.Health <= 1) + { + KFPC.Suicide(); + KickPunishList.RemoveItem(KFPC); + KickWarningList.RemoveItem(KFPC); + } + else + { + KFPC.Pawn.Health--; + + if (KFPawn_Human(KFPC.Pawn).Armor > 0) + KFPawn_Human(KFPC.Pawn).Armor--; + + if (KFPC.Pawn.InvManager != None) + { + KFIM = KFInventoryManager(KFPC.Pawn.InvManager); + if (KFIM != None) + { + KFIM.ThrowMoney(); + } + } + } } else if (KFGI.AccessControl != none) { + KickPunishList.RemoveItem(KFPC); + KickWarningList.RemoveItem(KFPC); KFAccessControl(KFGI.AccessControl).ForceKickPlayer(KFPC, KFGI.AccessControl.KickedMsg); KFGI.BroadcastLocalized(KFGI, class'KFLocalMessage', LMT_KickVoteSucceeded, CurrentKickVote.PlayerPRI); } } - PunishList.Length = 0; } -function bool ImportantKickee(PlayerReplicationInfo PRI_Kickee, PlayerReplicationInfo PRI_Kicker) +function bool IsPlayerKickProtected(PlayerReplicationInfo PRI_Kickee) +{ + return (KickProtectedList.Find('Uid', PRI_Kickee.UniqueId.Uid) != -1); +} + +function bool IsKickerWarned(KFPlayerController KFPC) +{ + return (KickWarningList.Find(KFPC) != -1); +} + +function bool IsKickerPunishListed(KFPlayerController KFPC) +{ + return (KickPunishList.Find(KFPC) != -1); +} + +function WarnKicker(PlayerReplicationInfo PRI_Kickee, PlayerReplicationInfo PRI_Kicker) +{ + local KFPlayerController KFPC_Kicker; + + KFPC_Kicker = KFPlayerController(PRI_Kicker.Owner); + if (!IsKickerWarned(KFPC_Kicker)) + { + KickWarningList.AddItem(KFPC_Kicker); + WorldInfo.Game.Broadcast(KFPC_Kicker, PRI_Kicker.PlayerName@"tried to kick"@PRI_Kickee.PlayerName); + WorldInfo.Game.Broadcast(KFPC_Kicker, "If he tries to do it again, the hand of God will punish him"); + } +} + +function PunishKicker(PlayerReplicationInfo PRI_Kicker) { - local string PunishMessage; local KFPlayerController KFPC_Kicker; - if (ImportantPersonList.Find('Uid', PRI_Kickee.UniqueId.Uid) != -1) + KFPC_Kicker = KFPlayerController(PRI_Kicker.Owner); + if (!IsKickerPunishListed(KFPC_Kicker)) { - KFPC_Kicker = KFPlayerController(PRI_Kicker.Owner); - if (PunishList.Find(KFPC_Kicker) == -1) + KickPunishList.AddItem(KFPC_Kicker); + WorldInfo.Game.Broadcast(KFPC_Kicker, PRI_Kicker.PlayerName@"seems to be feeling bad..."); + if (!IsTimerActive(nameof(PunishmentTick))) { - PunishMessage = PRI_Kicker.PlayerName@"tried to kick"@PRI_Kickee.PlayerName@", but sat down on the bottle instead."; - WorldInfo.Game.Broadcast(KFPC_Kicker, PunishMessage); - - PunishList.AddItem(KFPC_Kicker); - SetTimer(2.0f, false, 'ServerStartPunishment', self); + SetTimer(0.5f, true, nameof(PunishmentTick), self); } - return true; } - return false; } function ServerStartVoteKick(PlayerReplicationInfo PRI_Kickee, PlayerReplicationInfo PRI_Kicker) @@ -71,66 +128,66 @@ function ServerStartVoteKick(PlayerReplicationInfo PRI_Kickee, PlayerReplication KFGI = KFGameInfo(WorldInfo.Game); KFPC = KFPlayerController(PRI_Kicker.Owner); KickeePC = KFPlayerController(PRI_Kickee.Owner); - - // Kick voting is disabled - if(KFGI.bDisableKickVote) + + if (KFGI.bDisableKickVote) // Kick voting is disabled { KFPC.ReceiveLocalizedMessage(class'KFLocalMessage', LMT_KickVoteDisabled); return; } - // Spectators aren't allowed to vote - if(PRI_Kicker.bOnlySpectator) + if (PRI_Kicker.bOnlySpectator) // Spectators aren't allowed to vote { KFPC.ReceiveLocalizedMessage(class'KFLocalMessage', LMT_KickVoteNoSpectators); return; } - // Not enough players to start a vote - if( KFGI.NumPlayers <= 2 ) + if (KFGI.NumPlayers <= 2) // Not enough players to start a vote { KFPC.ReceiveLocalizedMessage(class'KFLocalMessage', LMT_KickVoteNotEnoughPlayers); return; } - // Maximum number of players kicked per match has been reached - if( KickedPlayers >= 2 ) + if (KickedPlayers >= 2) // Maximum number of players kicked per match has been reached { KFPC.ReceiveLocalizedMessage(class'KFLocalMessage', LMT_KickVoteMaxKicksReached); return; } - // Bottling - if (ImportantKickee(PRI_Kickee, PRI_Kicker)) + if (IsPlayerKickProtected(PRI_Kickee)) // Bottling { + if (IsKickerWarned(KFPC)) + { + PunishKicker(PRI_Kicker); + } + else + { + WarnKicker(PRI_Kickee, PRI_Kicker); + } return; } - // Can't kick admins - if(KFGI.AccessControl != none) + if (KFGI.AccessControl != none) // Can't kick admins { - if(KFGI.AccessControl.IsAdmin(KickeePC)) + if (KFGI.AccessControl.IsAdmin(KickeePC)) { KFPC.ReceiveLocalizedMessage(class'KFLocalMessage', LMT_KickVoteAdmin); return; } } - // Last vote failed, must wait until failed vote cooldown before starting a new vote - if( bIsFailedVoteTimerActive ) + if (bIsFailedVoteTimerActive) // Last vote failed, must wait until failed vote cooldown before starting a new vote { KFPC.ReceiveLocalizedMessage(class'KFLocalMessage', LMT_KickVoteRejected); return; } - // A kick vote is not allowed while another vote is active - if(bIsSkipTraderVoteInProgress) + if (bIsSkipTraderVoteInProgress) // A kick vote is not allowed while another vote is active { KFPC.ReceiveLocalizedMessage(class'KFLocalMessage', LMT_OtherVoteInProgress); return; } - if( !bIsKickVoteInProgress ) + if (!bIsKickVoteInProgress) { // Clear voter array PlayersThatHaveVoted.Length = 0; @@ -149,11 +206,11 @@ function ServerStartVoteKick(PlayerReplicationInfo PRI_Kickee, PlayerReplication } KFGI.BroadcastLocalized(KFGI, class'KFLocalMessage', LMT_KickVoteStarted, CurrentKickVote.PlayerPRI); WorldInfo.Game.Broadcast(KFPC, PRI_Kicker.PlayerName@"starts voting for kick"@PRI_Kickee.PlayerName); - SetTimer( VoteTime, false, nameof(ConcludeVoteKick), self ); + SetTimer(VoteTime, false, nameof(ConcludeVoteKick), self ); // Cast initial vote RecieveVoteKick(PRI_Kicker, true); } - else if(PRI_Kickee == CurrentKickVote.PlayerPRI) + else if (PRI_Kickee == CurrentKickVote.PlayerPRI) { RecieveVoteKick(PRI_Kicker, false); }