DayZ 1.24
Loading...
Searching...
No Matches
PluginAdminLog.c
Go to the documentation of this file.
1class PluginAdminLog extends PluginBase // Class for admin log messages handled by script
2{
4 string m_Pid;
8 string m_Message;
15 string m_PosArray[3];
20 // filters
21 protected int m_HitFilter;
22 protected int m_PlacementFilter;
23 protected int m_ActionsFilter;
24 protected int m_PlayerListFilter;
25
28 const int TIMER_PLAYERLIST = GetPlayerListTimer();
29
30 static int GetPlayerListTimer()
31 {
32 return 300; // seconds
33 }
34
35 /*
36 EXE side ADM log messages (not removable):
37 Connect / Disconnect
38 Chat
39 Player->Admin report (ingame chat: #toadmin <text>)
40 */
41
43 {
44 m_HitFilter = GetGame().ServerConfigGetInt("adminLogPlayerHitsOnly"); // 1 - log player hits only / 0 - log all hits ( animals/infected )
45 m_PlacementFilter = GetGame().ServerConfigGetInt("adminLogPlacement"); // 1 - log placement ( traps, tents )
46 m_ActionsFilter = GetGame().ServerConfigGetInt("adminLogBuildActions"); // 1 - log basebuilding actions ( build, dismantle, destroy )
47 m_PlayerListFilter = GetGame().ServerConfigGetInt("adminLogPlayerList"); // 1 - log periodic player list with position every 5 minutes
48
49 m_PlayerArray = new array<Man>;
50
51 if (m_PlayerListFilter == 1)
52 {
53 m_Timer = new Timer();
54 m_Timer.Run(TIMER_PLAYERLIST, this, "PlayerList", NULL, true);
55 }
56 }
57
59 {
60 }
61
62 void LogPrint(string message)
63 {
64 GetGame().AdminLog(message);
65 }
66
67 string GetPlayerPrefix(PlayerBase player, PlayerIdentity identity) // player name + id + position prefix for log prints
68 {
69
70 m_Position = player.GetPosition();
71 m_PosArray[3] = { m_Position[0].ToString(), m_Position[2].ToString(), m_Position[1].ToString() };
72
73 for (int i = 0; i < 3; i++) // trim position precision
74 {
75 m_DotIndex = m_PosArray[i].IndexOf(".");
76 if (m_DotIndex != -1)
77 m_PosArray[i] = m_PosArray[i].Substring(0, m_DotIndex + 2);
78 }
79
80 if (identity) // return partial message even if it fails to fetch identity
81 {
82 //return "Player \"" + "Unknown/Dead Entity" + "\" (id=" + "Unknown" + " pos=<" + m_PosArray[0] + ", " + m_PosArray[1] + ", " + m_PosArray[2] + ">)";
83 m_PlayerName = "\"" + identity.GetName() + "\"";
84 m_Pid = identity.GetId();
85 }
86 else
87 {
88 m_PlayerName = player.GetCachedName();
89 m_Pid = player.GetCachedID();
90 }
91
92
93 if (!player.IsAlive())
94 m_PlayerName = m_PlayerName + " (DEAD)";
95
96 return "Player " + m_PlayerName + " (id=" + m_Pid + " pos=<" + m_PosArray[0] + ", " + m_PosArray[1] + ", " + m_PosArray[2] + ">)";
97 }
98
100 {
101 if (damageResult)
102 {
103 float dmg = damageResult.GetHighestDamage("Health");
104 return " into " + zone + "(" + component.ToString() + ") for " + dmg.ToString() + " damage (" + ammo + ")";
105 }
106 else // block
107 return " into Block" + "(" + component.ToString() + ") for 0 damage ";
108 }
109
111 {
112
113 if (!player || !source)
114 {
115 LogPrint("DEBUG: PlayerKilled() player/source does not exist");
116 return;
117 }
118
119 PlayerBase playerSource = PlayerBase.Cast(EntityAI.Cast(source).GetHierarchyParent());
120 if (!playerSource)
122
124 if (playerSource)
126
127 playerPrefix = GetPlayerPrefix(player, player.GetIdentity());
128 if (player == source) // deaths not caused by another object (starvation, dehydration)
129 {
130 m_StatWater = player.GetStatWater();
131 m_StatEnergy = player.GetStatEnergy();
132 m_BleedMgr = player.GetBleedingManagerServer();
133
134 if (m_StatWater && m_StatEnergy && m_BleedMgr)
135 LogPrint(playerPrefix + " died. Stats> Water: " + m_StatWater.Get().ToString() + " Energy: " + m_StatEnergy.Get().ToString() + " Bleed sources: " + m_BleedMgr.GetBleedingSourcesCount().ToString());
136 else if (m_StatWater && m_StatEnergy && !m_BleedMgr)
137 LogPrint(playerPrefix + " died. Stats> Water: " + m_StatWater.Get().ToString() + " Energy: " + m_StatEnergy.Get().ToString());
138 else
139 LogPrint(playerPrefix + " died. Stats> could not fetch");
140 }
141 else if (source.IsWeapon() || source.IsMeleeWeapon()) // player
142 {
143
144 if (source.IsMeleeWeapon())
145 LogPrint(playerPrefix + " killed by " + playerPrefix2 + " with " + source.GetDisplayName());
146 else
147 {
148 m_Distance = vector.Distance(player.GetPosition(), playerSource.GetPosition());
149 LogPrint(playerPrefix + " killed by " + playerPrefix2 + " with " + source.GetDisplayName() + " from " + m_Distance + " meters ");
150 }
151 }
152 else
153 {
154 if (playerSource)
155 {
156 //fists
157 LogPrint(playerPrefix + " killed by " + playerPrefix2 + " with (MeleeFist)");
158 }
159 else
160 {
161 //rest, Animals, Zombies
162 LogPrint(playerPrefix + " killed by " + source.GetType());
163 }
164
165 }
166 }
167
169 {
170 if (player && source)
171 {
172 string playerPrefix = GetPlayerPrefix(player, player.GetIdentity()) + "[HP: " + player.GetHealth().ToString() + "]";
173 string playerPrefix2;
176
177 if (source.IsPlayer()) // Fists
179 else
180 playerSource = PlayerBase.Cast(source.GetHierarchyParent());
181
182 if (playerSource)
184
185 switch (damageType)
186 {
187 case DamageType.CLOSE_COMBAT: // Player melee, animals, infected
188
189 if (m_HitFilter != 1 && (source.IsZombie() || source.IsAnimal())) // Infected & Animals
190 {
191 m_DisplayName = source.GetDisplayName();
192
193 LogPrint(playerPrefix + " hit by " + m_DisplayName + m_HitMessage);
194 }
195 else if (source.IsPlayer())// Fists
196 LogPrint(playerPrefix + " hit by " + playerPrefix2 + m_HitMessage);
197 else if (playerSource && (source.IsMeleeWeapon() || source.IsWeapon())) // Melee weapons
198 {
199 m_ItemInHands = source.GetDisplayName();
200
201 LogPrint(playerPrefix + " hit by " + playerPrefix2 + m_HitMessage + " with " + m_ItemInHands);
202 }
203 else
204 {
205 m_DisplayName = source.GetType();
206
207 LogPrint(playerPrefix + " hit by " + m_DisplayName + m_HitMessage);
208 }
209 break;
210
211 case DamageType.FIRE_ARM: // Player ranged
212
213 if (source.IsWeapon() && playerSource)
214 {
215 m_ItemInHands = source.GetDisplayName();
216 m_Distance = vector.Distance(player.GetPosition(), playerSource.GetPosition());
217
218 LogPrint(playerPrefix + " hit by " + playerPrefix2 + m_HitMessage + " with " + m_ItemInHands + " from " + m_Distance + " meters ");
219 }
220 else
221 {
222 m_DisplayName = source.GetType();
223
224 LogPrint(playerPrefix + " hit by " + m_DisplayName + m_HitMessage);
225 }
226 break;
227
228 case DamageType.EXPLOSION: // Explosion
229
230 LogPrint(playerPrefix + " hit by explosion (" + ammo + ")");
231 break;
232
233 case DamageType.STUN: // unused atm
234
235 LogPrint(playerPrefix + " stunned by " + ammo);
236 break;
237
238 case DamageType.CUSTOM: // Others (Vehicle hit, fall, fireplace, barbed wire ...)
239 float globalHealthDamage = damageResult.GetDamage("", "Health");
240 if (ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_HEALTH || ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_SHOCK || ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS)
241 {
242 if (globalHealthDamage > 0.0)
243 LogPrint(playerPrefix + " hit by " + ammo);
244 }
245 else if (source.GetType() == "AreaDamageManager")
246 {
247 EntityAI parent = EntityAI.Cast(source);
248 if (parent)
249 LogPrint(playerPrefix + " hit by " + parent.GetType() + " with " + ammo);
250 }
251 else
252 {
253 m_DisplayName = source.GetType();
254
255 LogPrint(playerPrefix + " hit by " + m_DisplayName + " with " + ammo);
256 }
257 break;
258
259 default:
260
261 LogPrint("DEBUG: PlayerHitBy() unknown damageType: " + ammo);
262 break;
263 }
264 }
265 else
266 LogPrint("DEBUG: player/source does not exist");
267 }
268
269 void UnconStart(PlayerBase player) // PlayerBase.c
270 {
271 m_PlayerPrefix = GetPlayerPrefix(player, player.GetIdentity());
272
273 LogPrint(m_PlayerPrefix + " is unconscious");
274 }
275
276 void UnconStop(PlayerBase player) // PlayerBase.c
277 {
278 if (player.IsAlive()) // Do not log uncon stop for dead players
279 {
280 m_PlayerPrefix = GetPlayerPrefix(player, player.GetIdentity());
281
282 LogPrint(m_PlayerPrefix + " regained consciousness");
283 }
284 }
285
286 void OnPlacementComplete(Man player, ItemBase item) // ItemBase.c
287 {
288 if (m_PlacementFilter == 1)
289 {
290 m_Source = PlayerBase.Cast(player);
291 m_PlayerPrefix = GetPlayerPrefix(m_Source, m_Source.GetIdentity());
292 m_DisplayName = item.GetDisplayName();
293
294 if (m_DisplayName == "")
295 LogPrint(m_PlayerPrefix + " placed unknown object");
296 else
297 LogPrint(m_PlayerPrefix + " placed " + m_DisplayName);
298 }
299 }
300
301 void OnContinouousAction(ActionData action_data) // ActionContinouousBase.c
302 {
303 if (m_ActionsFilter == 1)
304 {
305 m_Message = action_data.m_Action.GetAdminLogMessage(action_data);
306
307 if (m_Message == "")
308 return;
309
310 m_PlayerPrefix = GetPlayerPrefix(action_data.m_Player, action_data.m_Player.GetIdentity());
311
312 LogPrint(m_PlayerPrefix + m_Message);
313 }
314 }
315
316 void Suicide(PlayerBase player) // EmoteManager.c
317 {
318 m_PlayerPrefix = GetPlayerPrefix(player, player.GetIdentity());
319
320 LogPrint(m_PlayerPrefix + " committed suicide");
321 }
322
323 void BleedingOut(PlayerBase player) // Bleeding.c
324 {
325 m_PlayerPrefix = GetPlayerPrefix(player, player.GetIdentity());
326
327 LogPrint(m_PlayerPrefix + " bled out");
328 }
329
330 //"top" == 'true' for flag all the way at the top, 'false' for all the way at the bottom
332 {
333 if (m_ActionsFilter != 1)
334 return;
335
336 string prefix = GetPlayerPrefix(player, player.GetIdentity());
337 string flagType = totem.FindAttachmentBySlotName("Material_FPole_Flag").ClassName();
338 string action;
339
340 if (top)
341 action = "raised ";
342 else
343 action = "lowered ";
344
345 LogPrint(prefix + " has " + action + flagType + " on " + totem.ClassName() + " at " + totem.GetPosition());
346 }
347
349 {
350 GetGame().GetPlayers(m_PlayerArray);
351
352 if (m_PlayerArray.Count() != 0)
353 {
354 LogPrint("##### PlayerList log: " + m_PlayerArray.Count().ToString() + " players");
355
356 foreach (Man player: m_PlayerArray)
357 {
358 m_Player = PlayerBase.Cast(player);
359 m_PlayerPrefix = GetPlayerPrefix(m_Player, m_Player.GetIdentity());
360
361 LogPrint(m_PlayerPrefix);
362 }
363
364 LogPrint("#####");
365 }
366 }
367
369 {
370 LogPrint(str);
371 }
372}
DamageType
exposed from C++ (do not change)
ref Timer m_Timer
Definition DayZGame.c:675
void DayZPlayerImplementFallDamage(DayZPlayer pPlayer)
vector m_Position
Cached world position.
Definition Effect.c:41
DayZPlayer m_Player
Definition Hand_Events.c:42
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
EditBoxWidget m_ActionsFilter
The class that will be instanced (moddable)
Definition gameplay.c:376
string m_PlayerPrefix2
void PlayerKilled(PlayerBase player, Object source)
void OnContinouousAction(ActionData action_data)
void Suicide(PlayerBase player)
BleedingSourcesManagerServer m_BleedMgr
string m_Message
vector m_Position
int m_PlayerListFilter
void LogPrint(string message)
autoptr array< Man > m_PlayerArray
void ~PluginAdminLog()
int m_PlacementFilter
void UnconStart(PlayerBase player)
void PlayerHitBy(TotalDamageResult damageResult, int damageType, PlayerBase player, EntityAI source, int component, string dmgZone, string ammo)
string m_DisplayName
void BleedingOut(PlayerBase player)
void OnPlacementComplete(Man player, ItemBase item)
string m_PlayerName
void DirectAdminLogPrint(string str)
void PlayerList()
ref Timer m_Timer
PlayerBase m_Source
PlayerStat< float > m_StatWater
void UnconStop(PlayerBase player)
void TotemFlagChange(bool top, notnull PlayerBase player, notnull EntityAI totem)
string GetPlayerPrefix(PlayerBase player, PlayerIdentity identity)
PlayerBase m_Player
string m_HitMessage
PlayerStat< float > m_StatEnergy
string m_ItemInHands
void PluginAdminLog()
string GetHitMessage(TotalDamageResult damageResult, int component, string zone, string ammo)
string m_PlayerPrefix
static int GetPlayerListTimer()
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto string ToString(bool beautify=true)
Vector to string.
proto native CGame GetGame()
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
proto native int IndexOf(string sample)
Finds 'sample' in 'str'. Returns -1 when not found.