Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
syncevents.c
Go to the documentation of this file.
1 class SyncEvents
2 {
3  static void RegisterEvents()
4  {
5  DayZGame dz_game = DayZGame.Cast( GetGame() );
6 
7  dz_game.Event_OnRPC.Insert( Event_OnRPC );
8  Print("SyncEvents -> RegisterEvents");
9  }
10 
11  static void Event_OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx)
12  {
13  if ( rpc_type == ERPCs.RPC_SYNC_EVENT && GetGame() && GetGame().IsMultiplayer() && GetGame().IsClient() )
14  {
16 
17  if ( ctx.Read( event_data ) )
18  {
19  OnSyncEvent( event_data.param1, event_data.param2, target );
20  }
21  }
22  }
23 
24  static void OnSyncEvent( ESyncEvent event_type, SyncData data, Object target )
25  {
26  switch ( event_type )
27  {
28  case ESyncEvent.PlayerList:
29  {
30  ClientData.SyncEvent_PreprocessPlayerList(data.m_ServerPlayerList);
31  ClientData.SyncEvent_OnRecievedPlayerList(data.m_ServerPlayerList);
32  break;
33  }
34  case ESyncEvent.EntityKill:
35  {
36  ClientData.SyncEvent_OnEntityKilled( data.m_EntityKill );
37  break;
38  }
39  case ESyncEvent.PlayerIgnateFireplayce:
40  {
41  ClientData.SyncEvent_OnPlayerIgnitedFireplace( data.m_SyncInt );
42  break;
43  }
44  }
45  }
46 
47  static void SendPlayerList()
48  {
49  SyncData data = new SyncData;
50  data.m_ServerPlayerList = new SyncPlayerList;
51  data.m_ServerPlayerList.CreatePlayerList();
52 
53  SendSyncEvent( ERPCs.RPC_SYNC_EVENT, ESyncEvent.PlayerList, data, true );
54  }
55 
56  static void SendEntityKilled( EntityAI victim, EntityAI killer, EntityAI source, bool is_headshot )
57  {
58  if ( (victim && victim.IsPlayer()) || (killer && killer.IsPlayer()) )
59  {
60  SyncData data = new SyncData;
61  data.m_EntityKill = new SyncEntityKillInfo;
62 
63  data.m_EntityKill.m_EntityVictim = victim;
64  data.m_EntityKill.m_EntityKiller = killer;
65  data.m_EntityKill.m_EntitySource = source;
66  data.m_EntityKill.m_IsHeadShot = is_headshot;
67 
68  Man recipient;
69 
70  if ( killer && killer.IsPlayer() && victim.GetID() != killer.GetID() )
71  {
72  recipient = Man.Cast(killer);
73  }
74  else if ( victim && victim.IsPlayer() )
75  {
76  recipient = Man.Cast(victim);
77  }
78 
79  SendSyncEventEx( ERPCs.RPC_SYNC_EVENT, ESyncEvent.EntityKill, data, true, recipient );
80  }
81  }
82 
83  static void SendPlayerIgnatedFireplace( Man player, EFireIgniteType ignite_type )
84  {
85  SyncData data = new SyncData;
86  data.m_SyncInt = ignite_type;
87 
88  SendSyncEvent( ERPCs.RPC_SYNC_EVENT, ESyncEvent.PlayerIgnateFireplayce, data, true, player.GetIdentity() );
89  }
90 
91  private static void SendSyncEvent( ERPCs rpc_event_id, ESyncEvent sync_event_type, SyncData data = null, bool guaranteed = true, PlayerIdentity player_target = null )
92  {
93  Param2<ESyncEvent, ref SyncData> event_data = new Param2<ESyncEvent, ref SyncData>( sync_event_type, data );
94  if ( !player_target )
95  {
96  GetGame().RPCSingleParam( null, rpc_event_id, event_data, guaranteed );
97  }
98  else
99  {
100  GetGame().RPCSingleParam( null, rpc_event_id, event_data, guaranteed, player_target );
101  }
102  }
103 
104  private static void SendSyncEventEx( ERPCs rpc_event_id, ESyncEvent sync_event_type, SyncData data = null, bool guaranteed = true, Man recipient = null )
105  {
106  SendSyncEvent(rpc_event_id, sync_event_type, data, guaranteed, recipient.GetIdentity());
107  }
108 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
SyncData
Definition: syncdata.c:1
Print
proto void Print(void var)
Prints content of variable to console/log.
ClientData
Definition: clientdata.c:1
ESyncEvent
ESyncEvent
Definition: esyncevent.c:1
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PlayerIdentity
The class that will be instanced (moddable)
Definition: gameplay.c:377
SyncEntityKillInfo
Definition: syncentitykill.c:1
Object
Definition: objecttyped.c:1
EFireIgniteType
EFireIgniteType
Definition: efireignitetype.c:1
SyncPlayerList
Definition: syncplayerlist.c:1
SyncEvents
Definition: syncevents.c:1
ERPCs
ERPCs
Definition: erpcs.c:1
EntityAI
Definition: building.c:5