Dayz Explorer 1.28.160049
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{
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
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 {
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 if (!player || !source)
119 {
120 LogPrint("DEBUG: PlayerKilled() player/source does not exist");
121 return;
122 }
123
124 PlayerBase playerSource = PlayerBase.Cast( EntityAI.Cast( source ).GetHierarchyParent() );
125 if (!playerSource)
126 {
127 playerSource = PlayerBase.Cast( source );
128 }
129
130 string playerPrefix, playerPrefix2;
131 if (playerSource)
132 {
133 playerPrefix2 = GetPlayerPrefix( playerSource , playerSource.GetIdentity() );
134 }
135
136 playerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
137 if (player == source) // deaths not caused by another object (starvation, dehydration)
138 {
139 m_StatWater = player.GetStatWater();
140 m_StatEnergy = player.GetStatEnergy();
141 m_BleedMgr = player.GetBleedingManagerServer();
142
143 string reason = " died.";
144 if (player.GetDrowningWaterLevelCheck())
145 reason = " drowned.";
146
147 string additionalStats;
148 if (m_StatWater && m_StatEnergy)
149 additionalStats = " Stats> Water: " + m_StatWater.Get().ToString() + " Energy: " + m_StatEnergy.Get().ToString();
150
151 if (m_BleedMgr)
152 additionalStats = additionalStats + " Bleed sources: " + m_BleedMgr.GetBleedingSourcesCount().ToString();
153
154 LogPrint(playerPrefix + reason + additionalStats);
155
156 }
157 else if (source.IsWeapon() || source.IsMeleeWeapon()) // player
158 {
159 if (ExplosivesBase.Cast(source))
160 {
161 LogPrint( playerPrefix + " killed by " + source.GetDisplayName() );
162 }
163 else if (source.IsMeleeWeapon())
164 {
165 LogPrint( playerPrefix + " killed by " + playerPrefix2 + " with " + source.GetDisplayName() );
166 }
167 else
168 {
169 m_Distance = vector.Distance( player.GetPosition(), playerSource.GetPosition() );
170 LogPrint( playerPrefix + " killed by " + playerPrefix2 + " with " + source.GetDisplayName() + " from " + m_Distance + " meters " );
171 }
172 }
173 else
174 {
175 if (playerSource)
176 {
177 //fists
178 LogPrint( playerPrefix + " killed by " + playerPrefix2 + " with (MeleeFist)" );
179 }
180 else
181 {
182 //rest, Animals, Zombies
183 LogPrint( playerPrefix + " killed by " + source.GetType());
184 }
185
186 }
187 }
188
190 {
191 string playerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
192 LogPrint( playerPrefix + " has drowned while unconscious" );
193 }
194
196 {
197 string playerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
198 LogPrint( playerPrefix + " is choosing to respawn" );
199 }
200
202 {
203 string playerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
204 if (player.IsUnconscious())
205 LogPrint( playerPrefix + " is disconnecting while being unconscious" );
206 else if (player.IsRestrained())
207 LogPrint( playerPrefix + " is disconnecting while being restrained" );
208 }
209
210 void PlayerHitBy( TotalDamageResult damageResult, int damageType, PlayerBase player, EntityAI source, int component, string dmgZone, string ammo ) // PlayerBase.c
211 {
212 if ( player && source )
213 {
214 string playerPrefix = GetPlayerPrefix( player , player.GetIdentity() ) + "[HP: " + player.GetHealth().ToString() + "]";
215 string playerPrefix2;
216 m_HitMessage = GetHitMessage( damageResult, component, dmgZone, ammo );
217 PlayerBase playerSource;
218
219 if ( source.IsPlayer() )// Fists
220 playerSource = PlayerBase.Cast( source );
221 else
222 playerSource = PlayerBase.Cast( source.GetHierarchyParent() );
223
224 if (playerSource)
225 playerPrefix2 = GetPlayerPrefix( playerSource , playerSource.GetIdentity() );
226
227 switch ( damageType )
228 {
229 case DamageType.CLOSE_COMBAT: // Player melee, animals, infected
230
231 if (source.IsZombie() || source.IsAnimal()) // Infected & Animals
232 {
233 if (m_HitFilter == 1)
234 break;
235
236 m_DisplayName = source.GetDisplayName();
237
238 LogPrint( playerPrefix + " hit by " + m_DisplayName + m_HitMessage );
239 }
240 else if (source.IsPlayer())// Fists
241 {
242 LogPrint( playerPrefix + " hit by " + playerPrefix2 + m_HitMessage );
243 }
244 else if ( playerSource && (source.IsMeleeWeapon() || source.IsWeapon())) // Melee weapons
245 {
246 m_ItemInHands = source.GetDisplayName();
247
248 LogPrint( playerPrefix + " hit by " + playerPrefix2 + m_HitMessage + " with " + m_ItemInHands );
249 }
250 else
251 {
252 m_DisplayName = source.GetType();
253
254 LogPrint( playerPrefix + " hit by " + m_DisplayName + m_HitMessage );
255 }
256 break;
257
258 case DamageType.FIRE_ARM: // Player ranged
259
260 if ( source.IsWeapon() && playerSource )
261 {
262 m_ItemInHands = source.GetDisplayName();
263 m_Distance = vector.Distance( player.GetPosition(), playerSource.GetPosition() );
264
265 LogPrint( playerPrefix + " hit by " + playerPrefix2 + m_HitMessage + " with " + m_ItemInHands + " from " + m_Distance + " meters ");
266 }
267 else
268 {
269 m_DisplayName = source.GetType();
270
271 LogPrint( playerPrefix + " hit by " + m_DisplayName + m_HitMessage );
272 }
273 break;
274
275 case DamageType.EXPLOSION: // Explosion
276
277 LogPrint( playerPrefix + " hit by explosion (" + ammo + ")" );
278 break;
279
280 case DamageType.STUN: // unused atm
281
282 LogPrint( playerPrefix + " stunned by " + ammo );
283 break;
284
285 case DamageType.CUSTOM: // Others (Vehicle hit, fall, fireplace, barbed wire ...)
286 float globalHealthDamage = damageResult.GetDamage("", "Health");
287 if (ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_HEALTH || ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_SHOCK || ammo == DayZPlayerImplementFallDamage.FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS)
288 {
289 if (globalHealthDamage > 0.0)
290 LogPrint(playerPrefix + " hit by " + ammo);
291 }
292 else if ( source.GetType() == "AreaDamageManager" )
293 {
294 EntityAI parent = EntityAI.Cast( source );
295 if ( parent )
296 {
297 LogPrint( playerPrefix + " hit by " + parent.GetType() + " with " + ammo );
298 }
299 }
300 else
301 {
302 m_DisplayName = source.GetType();
303
304 LogPrint( playerPrefix + " hit by " + m_DisplayName + " with " + ammo );
305 }
306 break;
307
308 default:
309
310 LogPrint("DEBUG: PlayerHitBy() unknown damageType: " + ammo );
311 break;
312 }
313 }
314 else
315 {
316 LogPrint("DEBUG: player/source does not exist");
317 }
318 }
319
320 void UnconStart( PlayerBase player ) // PlayerBase.c
321 {
322 m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
323
324 LogPrint( m_PlayerPrefix + " is unconscious" );
325 }
326
327 void UnconStop( PlayerBase player ) // PlayerBase.c
328 {
329 if ( player.IsAlive() ) // Do not log uncon stop for dead players
330 {
331 m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
332
333 LogPrint( m_PlayerPrefix + " regained consciousness" );
334 }
335 }
336
337 void OnPlacementComplete( Man player, ItemBase item ) // ItemBase.c
338 {
339 if ( m_PlacementFilter == 1 )
340 {
341 m_Source = PlayerBase.Cast( player );
342 m_PlayerPrefix = GetPlayerPrefix( m_Source , m_Source.GetIdentity() );
343 m_DisplayName = item.GetDisplayName();
344
345 if ( m_DisplayName == "" )
346 {
347 LogPrint( m_PlayerPrefix + " placed Nameless Object" + "<" + item.GetType() + ">" );
348 }
349 else
350 {
351 LogPrint( m_PlayerPrefix + " placed " + m_DisplayName + "<" + item.GetType() + ">");
352 }
353 }
354 }
355
356 void OnContinouousAction( ActionData action_data ) // ActionContinouousBase.c
357 {
358 if ( m_ActionsFilter == 1 )
359 {
360 m_Message = action_data.m_Action.GetAdminLogMessage(action_data);
361
362 if(m_Message == "")
363 return;
364
365 m_PlayerPrefix = GetPlayerPrefix( action_data.m_Player , action_data.m_Player.GetIdentity() );
366
367 LogPrint( m_PlayerPrefix + m_Message );
368 }
369 }
370
371 void OnEmote(PlayerBase player, EmoteBase emote)
372 {
373 m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
374
375 ItemBase item = player.GetItemInHands();
376 if (item)
377 LogPrint(m_PlayerPrefix + " performed " + emote.GetInputActionName() + " with " + item.GetType());
378 else
379 LogPrint(m_PlayerPrefix + " performed " + emote.GetInputActionName());
380 }
381
382 void Suicide( PlayerBase player ) // EmoteManager.c
383 {
384 m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
385
386 LogPrint( m_PlayerPrefix + " committed suicide" );
387 }
388
389 void BleedingOut( PlayerBase player ) // Bleeding.c
390 {
391 m_PlayerPrefix = GetPlayerPrefix( player , player.GetIdentity() );
392
393 LogPrint( m_PlayerPrefix + " bled out" );
394 }
395
396 //"top" == 'true' for flag all the way at the top, 'false' for all the way at the bottom
397 void TotemFlagChange(bool top, notnull PlayerBase player, notnull EntityAI totem)
398 {
399 if (m_ActionsFilter !=1)
400 return;
401
402 string prefix = GetPlayerPrefix(player, player.GetIdentity());
403 string flagType = totem.FindAttachmentBySlotName("Material_FPole_Flag").ClassName();
404 string action;
405
406 if (top)
407 action = "raised ";
408 else
409 action = "lowered ";
410
411 LogPrint( prefix + " has " + action + flagType + " on " + totem.ClassName() + " at " + totem.GetPosition());
412 }
413
415 {
416 GetGame().GetPlayers( m_PlayerArray );
417
418 if ( m_PlayerArray.Count() != 0 )
419 {
420 LogPrint( "##### PlayerList log: " + m_PlayerArray.Count().ToString() + " players" );
421
422 foreach ( Man player: m_PlayerArray )
423 {
424 m_Player = PlayerBase.Cast(player);
425 m_PlayerPrefix = GetPlayerPrefix( m_Player , m_Player.GetIdentity() );
426
427 LogPrint( m_PlayerPrefix );
428 }
429
430 LogPrint( "#####" );
431 }
432 }
433
434 void PlayerTeleportedLog(notnull PlayerBase player, vector startPos, vector targetPos, string reason)
435 {
436 m_PlayerPrefix = GetPlayerPrefix(player, player.GetIdentity());
437
438 LogPrint(m_PlayerPrefix + " was teleported from: " + startPos.ToString() + " to: " + targetPos.ToString() + ". Reason: " + reason);
439 }
440
441 void DirectAdminLogPrint(string str)
442 {
443 LogPrint(str);
444 }
445}
proto native int ServerConfigGetInt(string name)
Server config parsing. Returns 0 if not found.
string GetInputActionName()
Definition emotebase.c:70
The class that will be instanced (moddable)
Definition gameplay.c:389
Plugin interface for controlling of agent pool system.
Definition pluginbase.c:2
void PlayerKilled(PlayerBase player, Object source)
void OnContinouousAction(ActionData action_data)
void Suicide(PlayerBase player)
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)
void BleedingOut(PlayerBase player)
void OnPlacementComplete(Man player, ItemBase item)
void DirectAdminLogPrint(string str)
void PlayerKilledByDrowningUncon(PlayerBase player)
void PlayerList()
ref Timer m_Timer
void PlayerKilledByDisconnect(PlayerBase player)
void UnconStop(PlayerBase player)
void PlayerKilledByRespawn(PlayerBase player)
void TotemFlagChange(bool top, notnull PlayerBase player, notnull EntityAI totem)
string GetPlayerPrefix(PlayerBase player, PlayerIdentity identity)
void PlayerTeleportedLog(notnull PlayerBase player, vector startPos, vector targetPos, string reason)
void PluginAdminLog()
string GetHitMessage(TotalDamageResult damageResult, int component, string zone, string ammo)
void OnEmote(PlayerBase player, EmoteBase emote)
static int GetPlayerListTimer()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DamageType
exposed from C++ (do not change)
ref Timer m_Timer
Definition dayzgame.c:705
vector m_Position
Cached world position.
Definition effect.c:43
proto native CGame GetGame()
DayZPlayer m_Player
Definition hand_events.c:42
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
void PlayerStat(T min, T max, T init, string label, int flags)
EditBoxWidget m_ActionsFilter