Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
pluginadminlog.c
Go to the documentation of this file.
1 class PluginAdminLog extends PluginBase // Class for admin log messages handled by script
2 {
3  string m_PlayerName;
4  string m_Pid;
6  string m_PlayerPrefix;
7  string m_PlayerPrefix2;
8  string m_Message;
9  string m_DisplayName;
10  string m_HitMessage;
11  float m_Distance;
13  PlayerBase m_Source;
14  string m_ItemInHands;
15  string m_PosArray[3];
16  int m_DotIndex;
17  PlayerStat<float> m_StatWater;
18  PlayerStat<float> m_StatEnergy;
19  BleedingSourcesManagerServer m_BleedMgr;
20  // filters
21  protected int m_HitFilter;
22  protected int m_PlacementFilter;
23  protected int m_ActionsFilter;
24  protected int m_PlayerListFilter;
25 
26  ref Timer m_Timer;
27  autoptr array<Man> m_PlayerArray;
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 
42  void PluginAdminLog()
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 
58  void ~PluginAdminLog()
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  {
78  m_PosArray[i] = m_PosArray[i].Substring( 0, m_DotIndex + 2 );
79  }
80  }
81 
82  if ( identity ) // return partial message even if it fails to fetch identity
83  {
84  //return "Player \"" + "Unknown/Dead Entity" + "\" (id=" + "Unknown" + " pos=<" + m_PosArray[0] + ", " + m_PosArray[1] + ", " + m_PosArray[2] + ">)";
85  m_PlayerName = "\"" + identity.GetName() + "\"";
86  m_Pid = identity.GetId();
87  }
88  else
89  {
90  m_PlayerName = player.GetCachedName();
91  m_Pid = player.GetCachedID();
92  }
93 
94 
95  if ( !player.IsAlive() )
96  {
97  m_PlayerName = m_PlayerName + " (DEAD)";
98  }
99 
100  return "Player " + m_PlayerName + " (id=" + m_Pid + " pos=<" + m_PosArray[0] + ", " + m_PosArray[1] + ", " + m_PosArray[2] + ">)";
101  }
102 
103  string GetHitMessage( TotalDamageResult damageResult, int component, string zone, string ammo)
104  {
105  if ( damageResult )
106  {
107  float dmg = damageResult.GetHighestDamage("Health");
108  return " into " + zone + "(" + component.ToString() + ") for " + dmg.ToString() + " damage (" + ammo + ")";
109  }
110  else // block
111  {
112  return " into Block" + "(" + component.ToString() + ") for 0 damage ";
113  }
114  }
115 
116  void PlayerKilled( PlayerBase player, Object source ) // PlayerBase.c
117  {
118 
119  if (!player || !source)
120  {
121  LogPrint("DEBUG: PlayerKilled() player/source does not exist");
122  return;
123  }
124 
125  PlayerBase playerSource = PlayerBase.Cast( EntityAI.Cast( source ).GetHierarchyParent() );
126  if (!playerSource)
127  {
128  playerSource = PlayerBase.Cast( source );
129  }
130 
131  string playerPrefix, playerPrefix2;
132  if (playerSource)
133  {
134  playerPrefix2 = GetPlayerPrefix( playerSource , playerSource.GetIdentity() );
135  }
136 
137  playerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
138  if (player == source) // deaths not caused by another object (starvation, dehydration)
139  {
140  m_StatWater = player.GetStatWater();
141  m_StatEnergy = player.GetStatEnergy();
142  m_BleedMgr = player.GetBleedingManagerServer();
143 
144  if ( m_StatWater && m_StatEnergy && m_BleedMgr )
145  {
146  LogPrint( playerPrefix + " died. Stats> Water: " + m_StatWater.Get().ToString() + " Energy: " + m_StatEnergy.Get().ToString() + " Bleed sources: " + m_BleedMgr.GetBleedingSourcesCount().ToString() );
147  }
148  else if ( m_StatWater && m_StatEnergy && !m_BleedMgr )
149  {
150  LogPrint( playerPrefix + " died. Stats> Water: " + m_StatWater.Get().ToString() + " Energy: " + m_StatEnergy.Get().ToString() );
151  }
152  else
153  {
154  LogPrint( playerPrefix + " died. Stats> could not fetch");
155  }
156  }
157  else if (source.IsWeapon() || source.IsMeleeWeapon()) // player
158  {
159 
160  if (source.IsMeleeWeapon())
161  {
162  LogPrint( playerPrefix + " killed by " + playerPrefix2 + " with " + source.GetDisplayName() );
163  }
164  else
165  {
166  m_Distance = vector.Distance( player.GetPosition(), playerSource.GetPosition() );
167  LogPrint( playerPrefix + " killed by " + playerPrefix2 + " with " + source.GetDisplayName() + " from " + m_Distance + " meters " );
168  }
169  }
170  else
171  {
172  if (playerSource)
173  {
174  //fists
175  LogPrint( playerPrefix + " killed by " + playerPrefix2 + " with (MeleeFist)" );
176  }
177  else
178  {
179  //rest, Animals, Zombies
180  LogPrint( playerPrefix + " killed by " + source.GetType());
181  }
182 
183  }
184  }
185 
186  void PlayerHitBy( TotalDamageResult damageResult, int damageType, PlayerBase player, EntityAI source, int component, string dmgZone, string ammo ) // PlayerBase.c
187  {
188  if ( player && source )
189  {
190  string playerPrefix = GetPlayerPrefix( player , player.GetIdentity() ) + "[HP: " + player.GetHealth().ToString() + "]";
191  string playerPrefix2;
192  m_HitMessage = GetHitMessage( damageResult, component, dmgZone, ammo );
193  PlayerBase playerSource;
194 
195  if ( source.IsPlayer() )// Fists
196  playerSource = PlayerBase.Cast( source );
197  else
198  playerSource = PlayerBase.Cast( source.GetHierarchyParent() );
199 
200  if (playerSource)
201  playerPrefix2 = GetPlayerPrefix( playerSource , playerSource.GetIdentity() );
202 
203  switch ( damageType )
204  {
205  case DamageType.CLOSE_COMBAT: // Player melee, animals, infected
206 
207  if ( m_HitFilter != 1 && ( source.IsZombie() || source.IsAnimal() ) ) // Infected & Animals
208  {
209  m_DisplayName = source.GetDisplayName();
210 
211  LogPrint( playerPrefix + " hit by " + m_DisplayName + m_HitMessage );
212  }
213  else if (source.IsPlayer())// Fists
214  {
215  LogPrint( playerPrefix + " hit by " + playerPrefix2 + m_HitMessage );
216  }
217  else if ( playerSource && (source.IsMeleeWeapon() || source.IsWeapon())) // Melee weapons
218  {
219  m_ItemInHands = source.GetDisplayName();
220 
221  LogPrint( playerPrefix + " hit by " + playerPrefix2 + m_HitMessage + " with " + m_ItemInHands );
222  }
223  else
224  {
225  m_DisplayName = source.GetType();
226 
227  LogPrint( playerPrefix + " hit by " + m_DisplayName + m_HitMessage );
228  }
229  break;
230 
231  case DamageType.FIRE_ARM: // Player ranged
232 
233  if ( source.IsWeapon() && playerSource )
234  {
235  m_ItemInHands = source.GetDisplayName();
236  m_Distance = vector.Distance( player.GetPosition(), playerSource.GetPosition() );
237 
238  LogPrint( playerPrefix + " hit by " + playerPrefix2 + m_HitMessage + " with " + m_ItemInHands + " from " + m_Distance + " meters ");
239  }
240  else
241  {
242  m_DisplayName = source.GetType();
243 
244  LogPrint( playerPrefix + " hit by " + m_DisplayName + m_HitMessage );
245  }
246  break;
247 
248  case DamageType.EXPLOSION: // Explosion
249 
250  LogPrint( playerPrefix + " hit by explosion (" + ammo + ")" );
251  break;
252 
253  case DamageType.STUN: // unused atm
254 
255  LogPrint( playerPrefix + " stunned by " + ammo );
256  break;
257 
258  case DamageType.CUSTOM: // Others (Vehicle hit, fall, fireplace, barbed wire ...)
259  float globalHealthDamage = damageResult.GetDamage("", "Health");
260  if (ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_HEALTH || ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_SHOCK || ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS)
261  {
262  if (globalHealthDamage > 0.0)
263  LogPrint(playerPrefix + " hit by " + ammo);
264  }
265  else if ( source.GetType() == "AreaDamageManager" )
266  {
267  EntityAI parent = EntityAI.Cast( source );
268  if ( parent )
269  {
270  LogPrint( playerPrefix + " hit by " + parent.GetType() + " with " + ammo );
271  }
272  }
273  else
274  {
275  m_DisplayName = source.GetType();
276 
277  LogPrint( playerPrefix + " hit by " + m_DisplayName + " with " + ammo );
278  }
279  break;
280 
281  default:
282 
283  LogPrint("DEBUG: PlayerHitBy() unknown damageType: " + ammo );
284  break;
285  }
286  }
287  else
288  {
289  LogPrint("DEBUG: player/source does not exist");
290  }
291  }
292 
293  void UnconStart( PlayerBase player ) // PlayerBase.c
294  {
295  m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
296 
297  LogPrint( m_PlayerPrefix + " is unconscious" );
298  }
299 
300  void UnconStop( PlayerBase player ) // PlayerBase.c
301  {
302  if ( player.IsAlive() ) // Do not log uncon stop for dead players
303  {
304  m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
305 
306  LogPrint( m_PlayerPrefix + " regained consciousness" );
307  }
308  }
309 
310  void OnPlacementComplete( Man player, ItemBase item ) // ItemBase.c
311  {
312  if ( m_PlacementFilter == 1 )
313  {
314  m_Source = PlayerBase.Cast( player );
315  m_PlayerPrefix = GetPlayerPrefix( m_Source , m_Source.GetIdentity() );
316  m_DisplayName = item.GetDisplayName();
317 
318  if ( m_DisplayName == "" )
319  {
320  LogPrint( m_PlayerPrefix + " placed unknown object" );
321  }
322  else
323  {
324  LogPrint( m_PlayerPrefix + " placed " + m_DisplayName );
325  }
326  }
327  }
328 
329  void OnContinouousAction( ActionData action_data ) // ActionContinouousBase.c
330  {
331  if ( m_ActionsFilter == 1 )
332  {
333  m_Message = action_data.m_Action.GetAdminLogMessage(action_data);
334 
335  if(m_Message == "")
336  return;
337 
338  m_PlayerPrefix = GetPlayerPrefix( action_data.m_Player , action_data.m_Player.GetIdentity() );
339 
340  LogPrint( m_PlayerPrefix + m_Message );
341  }
342  }
343 
344  void Suicide( PlayerBase player ) // EmoteManager.c
345  {
346  m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
347 
348  LogPrint( m_PlayerPrefix + " committed suicide" );
349  }
350 
351  void BleedingOut( PlayerBase player ) // Bleeding.c
352  {
353  m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
354 
355  LogPrint( m_PlayerPrefix + " bled out" );
356  }
357 
358  //"top" == 'true' for flag all the way at the top, 'false' for all the way at the bottom
359  void TotemFlagChange(bool top, notnull PlayerBase player, notnull EntityAI totem)
360  {
361  if (m_ActionsFilter !=1)
362  return;
363 
364  string prefix = GetPlayerPrefix(player, player.GetIdentity());
365  string flagType = totem.FindAttachmentBySlotName("Material_FPole_Flag").ClassName();
366  string action;
367 
368  if (top)
369  action = "raised ";
370  else
371  action = "lowered ";
372 
373  LogPrint( prefix + " has " + action + flagType + " on " + totem.ClassName() + " at " + totem.GetPosition());
374  }
375 
376  void PlayerList()
377  {
378  GetGame().GetPlayers( m_PlayerArray );
379 
380  if ( m_PlayerArray.Count() != 0 )
381  {
382  LogPrint( "##### PlayerList log: " + m_PlayerArray.Count().ToString() + " players" );
383 
384  foreach ( Man player: m_PlayerArray )
385  {
386  m_Player = PlayerBase.Cast(player);
387  m_PlayerPrefix = GetPlayerPrefix( m_Player , m_Player.GetIdentity() );
388 
389  LogPrint( m_PlayerPrefix );
390  }
391 
392  LogPrint( "#####" );
393  }
394  }
395 
396  void DirectAdminLogPrint(string str)
397  {
398  LogPrint(str);
399  }
400 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
PlayerList
@ PlayerList
Definition: esyncevent.c:3
m_Position
protected vector m_Position
Cached world position.
Definition: effect.c:41
m_Timer
ref Timer m_Timer
Definition: dayzgame.c:690
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
PluginBase
Definition: pluginadminlog.c:1
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: explosivesbase.c:133
PlayerIdentity
The class that will be instanced (moddable)
Definition: gameplay.c:377
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
ActionData
Definition: actionbase.c:20
TotalDamageResult
Definition: damagesystem.c:1
DamageType
DamageType
exposed from C++ (do not change)
Definition: damagesystem.c:10
Object
Definition: objecttyped.c:1
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
DayZPlayerImplementFallDamage
void DayZPlayerImplementFallDamage(DayZPlayer pPlayer)
Definition: dayzplayerimplementfalldamage.c:73
array< Man >
m_ActionsFilter
EditBoxWidget m_ActionsFilter
Definition: plugindayzplayerdebug.c:231
Timer
Definition: dayzplayerimplement.c:62
EntityAI
Definition: building.c:5