Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VotingKick.c
Go to the documentation of this file.
3{
4 [Attribute(desc: "When true, only players on the same faction as target of the vote can vote.")]
5 protected bool m_bFactionSpecific;
6
8
9 //~ Used in voting to make sure there is a min kick duration (in seconds)
10 protected static const int PLAYER_VOTE_KICK_DURATION = 300;
11
12 //------------------------------------------------------------------------------------------------
13 override void InitFromTemplate(SCR_VotingBase template, int startingPlayerID, int value, float remainingDuration)
14 {
15 super.InitFromTemplate(template, startingPlayerID, value, remainingDuration);
16
17 SCR_VotingKick votingKickTemplate = SCR_VotingKick.Cast(template);
18 m_bFactionSpecific = votingKickTemplate.isFactionSpecific();
19
20 PlayerManager playerMgr = GetGame().GetPlayerManager();
21 string cliVal;
22 if (playerMgr && System.GetCLIParam("logVoting", cliVal))
23 Print("VOTING SYSTEM - Player '" + playerMgr.GetPlayerName(startingPlayerID) + "' (with player id = " + startingPlayerID + ") started a vote to kick player '" + playerMgr.GetPlayerName(value) + "' (with player id = " + value + ")", LogLevel.NORMAL);
24
26 {
27 SCR_FactionManager factionMgr = SCR_FactionManager.Cast(GetGame().GetFactionManager());
28 if (!factionMgr)
29 return;
30
31 m_SubjectFaction = factionMgr.GetPlayerFaction(value);
32 }
33 }
34
35 //------------------------------------------------------------------------------------------------
38 // TODO: fix casing
40 {
41 return m_bFactionSpecific;
42 }
43
44 //------------------------------------------------------------------------------------------------
45 override bool IsAvailable(int value, bool isOngoing)
46 {
47 //--- Cannot kick yourself
49 return false;
50
51 //--- Cannot kick admin
52 if (SCR_Global.IsAdmin(value))
53 return false;
54
55 //~ Player is currently not admin but is on the admin list and should not be able to be voted out
57 if (adminManager && adminManager.IsPlayerOnAdminList(value))
58 return false;
59
60 //--- When faction specific, allow voting only for players on the same faction as target of the vote
62 {
63 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
64 if (!factionManager)
65 return false;
66
67 Faction targetFaction;
68 PlayerManager playerMgr = GetGame().GetPlayerManager();
69 if (isOngoing && !m_bCancelWhenSubjectLeavesTheServer && playerMgr && !playerMgr.IsPlayerConnected(value))
70 targetFaction = m_SubjectFaction;
71 else
72 targetFaction = factionManager.GetPlayerFaction(value); //--- value is ID of the player who is target of the vote
73
74 Faction playerFaction = factionManager.GetPlayerFaction(SCR_PlayerController.GetLocalPlayerId());
75 if (targetFaction != playerFaction || !targetFaction)
76 return false;
77 }
78
79 //--- Cannot vote to kick out session host
80 SCR_VotingManagerComponent votingManager = SCR_VotingManagerComponent.GetInstance();
81 if (!votingManager)
82 return false;
83
84 //~ Cannot kick if auto kick vote already active
85 if (m_Type == EVotingType.KICK && votingManager.IsVoting(EVotingType.AUTO_KICK, value))
86 return false;
87
88 return votingManager && votingManager.GetHostPlayerID() != value;
89 }
90
91 //------------------------------------------------------------------------------------------------
92 override int GetPlayerCount()
93 {
94 int playerCount;
95 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
96
97 Faction targetFaction;
98
99 if (factionManager)
100 targetFaction = factionManager.GetPlayerFaction(m_iValue);
101
102 if (m_bFactionSpecific && targetFaction)
103 {
104 //--- When faction specific, count only players on the same faction as target of the vote
105 //--- e.g., with 50% vote limit, only half of BLUFOR players will have to vote, not half of all players
106
107 Faction playerFaction;
108 array<int> players = {};
109
110 for (int i = 0, count = GetGame().GetPlayerManager().GetPlayers(players); i < count; i++)
111 {
112 //~ Ignore player that is the target of vote
113 if (players[i] != m_iValue)
114 {
115 //~ Check if player faction is the same as target faction
116 playerFaction = factionManager.GetPlayerFaction(players[i]);
117 if (targetFaction == playerFaction)
118 playerCount++;
119 }
120 }
121 }
122 else
123 {
124 //--- Ignore target player by subtracting 1
125 playerCount = super.GetPlayerCount() - 1;
126 }
127 //--- Limit to prevent instant completion in a session with less than limited participants
128 return Math.Max(playerCount, m_iMinVotes);
129 }
130
131 //------------------------------------------------------------------------------------------------
132 override int GetWinner()
133 {
134 if (super.GetWinner() != DEFAULT_VALUE)
135 {
136 PlayerManager playerMgr = GetGame().GetPlayerManager();
137 if (!m_bCancelWhenSubjectLeavesTheServer && playerMgr && !playerMgr.IsPlayerConnected(m_iValue))
138 return ALTERNATIVE_VALUE;
139 else
140 return m_iValue;
141 }
142
143 return DEFAULT_VALUE;
144 }
145
146 //------------------------------------------------------------------------------------------------
147 override bool Evaluate(out EVotingOutcome outcome)
148 {
149 bool output = super.Evaluate(outcome);
150
151 //Ensure that outcome is set to 'evaluate' in order to force the manager to use value provided by GetWinner()
152 outcome = EVotingOutcome.EVALUATE;
153
154 return output;
155 }
156
157 //------------------------------------------------------------------------------------------------
158 override void OnVotingEnd(int value = DEFAULT_VALUE, int winner = DEFAULT_VALUE)
159 {
160 PlayerManager playerMgr = GetGame().GetPlayerManager();
161 string cliVal;
162 if (playerMgr && System.GetCLIParam("logVoting", cliVal))
163 {
164 if (winner == DEFAULT_VALUE)
165 Print("VOTING SYSTEM - Vote to kick player '" + playerMgr.GetPlayerName(m_iValue) + "' (with player id = " + m_iValue + ") failed", LogLevel.NORMAL);
166 else
167 Print("VOTING SYSTEM - Vote to kick player '" + playerMgr.GetPlayerName(m_iValue) + "' (with player id = " + m_iValue + ") succeeded", LogLevel.NORMAL);
168 }
169
170 //~ Vote failed
171 if (winner == DEFAULT_VALUE)
172 return;
173
175 //~ Kick using crime module
176 if (crimesModule)
177 {
178 switch(m_Type)
179 {
180 case EVotingType.KICK:
182 return;
183 case EVotingType.AUTO_KICK:
184 crimesModule.KickOrBanPlayer(value, PlayerManagerKickReason.KICK, 0);
185 return;
186 case EVotingType.AUTO_LIGHTBAN:
188 return;
189 case EVotingType.AUTO_HEAVYBAN:
191 return;
192 }
193 }
194 //~ For some reason the crime module does not exist so default kick/ban is called. Note that it can never heavy ban/backend ban only temp ban
195 else
196 {
197 if (m_Type == EVotingType.KICK)
198 GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.KICK_VOTED, PLAYER_VOTE_KICK_DURATION);
199 else if (m_Type == EVotingType.AUTO_KICK)
200 GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.KICK, 0);
201 else
202 {
203 //~ Ban for which ever time is longer
205 GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.TEMP_BAN, SCR_DataCollectorCrimesModule.MIN_AUTO_BAN_DURATION);
206 else
207 GetGame().GetPlayerManager().KickPlayer(winner, PlayerManagerKickReason.TEMP_BAN, PLAYER_VOTE_KICK_DURATION);
208 }
209 }
210 }
211}
EVotingOutcome
EVotingType
Definition EVotingType.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DataCollectorComponent GetDataCollector()
Definition game.c:110
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_AnalyticsDataCollectionModule FindModule(typename type)
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
int GetPlayers(out notnull array< int > outPlayers)
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_PlayerListedAdminManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition Math.c:13
void KickOrBanPlayer(int playerId, SCR_PlayerManagerKickReason reason, int minimmumDuration)
static bool IsAdmin(int playerID)
Definition Functions.c:1927
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
EVotingType m_Type
static const int DEFAULT_VALUE
bool m_bCancelWhenSubjectLeavesTheServer
static const int ALTERNATIVE_VALUE
Value of the vote, that is used when vote ends in an alternative solution.
Faction m_SubjectFaction
override void OnVotingEnd(int value=DEFAULT_VALUE, int winner=DEFAULT_VALUE)
override int GetWinner()
override void InitFromTemplate(SCR_VotingBase template, int startingPlayerID, int value, float remainingDuration)
static const int PLAYER_VOTE_KICK_DURATION
override bool IsAvailable(int value, bool isOngoing)
override int GetPlayerCount()
override bool Evaluate(out EVotingOutcome outcome)
bool isFactionSpecific()
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
PlayerManagerKickReason