Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ReconnectComponent.c
Go to the documentation of this file.
3 {
4  int m_iPlayerId;
5  IEntity m_ReservedEntity;
6 
7  //------------------------------------------------------------------------------------------------
8  // constructor
11  void SCR_ReconnectData(int playerId, IEntity entity)
12  {
13  m_iPlayerId = playerId;
14  m_ReservedEntity = entity;
15  }
16 }
17 
19 enum SCR_EReconnectState
20 {
23  ENTITY_DISCARDED
24 }
25 
26 [EntityEditorProps(category: "GameScripted/GameMode", description: "")]
27 class SCR_ReconnectComponentClass : SCR_BaseGameModeComponentClass
28 {
29  //------------------------------------------------------------------------------------------------
30  static override bool DependsOn(string className)
31  {
32  if (className == "RplComponentClass")
33  return true;
34 
35  return false;
36  }
37 }
38 
42 {
43  [Attribute(defvalue: "1", uiwidget: UIWidgets.CheckBox, desc: "Enable reconnect functionality for this gamemode")]
44  bool m_bEnableReconnect;
45 
46  static SCR_ReconnectComponent s_Instance;
47 
48  protected bool m_bIsInit; // whether check for connection to backend happenned
49  protected bool m_bIsReconEnabled;
50  protected ref array<ref SCR_ReconnectData> m_ReconnectPlayerList = {};
51 
52  protected ref ScriptInvoker m_OnAddedToReconnectList;
53  protected ref ScriptInvoker m_OnPlayerReconnect;
54 
55  //------------------------------------------------------------------------------------------------
57  static SCR_ReconnectComponent GetInstance()
58  {
59  return s_Instance;
60  }
61 
62  //------------------------------------------------------------------------------------------------
64  ScriptInvoker GetOnAddedToList()
65  {
66  if (!m_OnAddedToReconnectList)
67  m_OnAddedToReconnectList = new ScriptInvoker();
68 
69  return m_OnAddedToReconnectList;
70  }
71 
72  //------------------------------------------------------------------------------------------------
74  ScriptInvoker GetOnReconnect()
75  {
77  m_OnPlayerReconnect = new ScriptInvoker();
78 
79  return m_OnPlayerReconnect;
80  }
81 
82  //------------------------------------------------------------------------------------------------
84  bool IsReconnectListEmpty()
85  {
86  return m_ReconnectPlayerList.IsEmpty();
87  }
88 
89  //------------------------------------------------------------------------------------------------
91  bool IsReconnectEnabled()
92  {
93  return m_bIsReconEnabled;
94  }
95 
96  //------------------------------------------------------------------------------------------------
100  SCR_EReconnectState IsInReconnectList(int playerId)
101  {
102  if (!m_bIsInit)
103  {
104  if (!Init())
105  return SCR_EReconnectState.NOT_RECONNECT;
106  }
107 
108  if (m_ReconnectPlayerList.IsEmpty())
109  return SCR_EReconnectState.NOT_RECONNECT;
110 
111  int count = m_ReconnectPlayerList.Count();
112  for (int i; i < count; i++)
113  {
114  if (m_ReconnectPlayerList[i].m_iPlayerId == playerId)
115  {
116  ChimeraCharacter char = ChimeraCharacter.Cast(m_ReconnectPlayerList[i].m_ReservedEntity);
117  if (!char || char.GetCharacterController().IsDead()) // entity could have died meanwhile
118  {
119  m_ReconnectPlayerList.Remove(i);
120  return SCR_EReconnectState.ENTITY_DISCARDED;
121  }
122 
123  return SCR_EReconnectState.ENTITY_AVAILABLE;
124  }
125  }
126 
127  return SCR_EReconnectState.NOT_RECONNECT;
128  }
129 
130  //------------------------------------------------------------------------------------------------
134  SCR_EReconnectState IsEntityReconnectList(IEntity entity)
135  {
136  if (!m_bIsInit)
137  {
138  if (!Init())
139  return SCR_EReconnectState.NOT_RECONNECT;
140  }
141 
142  if (m_ReconnectPlayerList.IsEmpty())
143  return SCR_EReconnectState.NOT_RECONNECT;
144 
145  int count = m_ReconnectPlayerList.Count();
146  for (int i; i < count; i++)
147  {
148  if (m_ReconnectPlayerList[i].m_ReservedEntity == entity)
149  {
150  ChimeraCharacter char = ChimeraCharacter.Cast(m_ReconnectPlayerList[i].m_ReservedEntity);
151  if (!char || char.GetCharacterController().IsDead()) // entity could have died meanwhile
152  {
153  m_ReconnectPlayerList.Remove(i);
154  return SCR_EReconnectState.ENTITY_DISCARDED;
155  }
156 
157  return SCR_EReconnectState.ENTITY_AVAILABLE;
158  }
159  }
160 
161  return SCR_EReconnectState.NOT_RECONNECT;
162  }
163 
164  //------------------------------------------------------------------------------------------------
168  IEntity ReturnControlledEntity(int playerId)
169  {
170  int count = m_ReconnectPlayerList.Count();
171  for (int i; i < count; i++)
172  {
173  if (m_ReconnectPlayerList[i].m_iPlayerId == playerId)
174  {
175  IEntity ent = m_ReconnectPlayerList[i].m_ReservedEntity;
176  PlayerManager playerManager = GetGame().GetPlayerManager();
177  SCR_PlayerController playerController = SCR_PlayerController.Cast(playerManager.GetPlayerController(playerId));
178  playerController.SetInitialMainEntity(ent);
179 
181  m_OnPlayerReconnect.Invoke(m_ReconnectPlayerList[i]);
182 
183  m_ReconnectPlayerList.Remove(i);
184  return ent;
185  }
186  }
187 
188  return null;
189  }
190 
191  //------------------------------------------------------------------------------------------------
194  bool OnPlayerDC(int playerId, KickCauseCode cause)
195  {
196  KickCauseGroup2 groupInt = KickCauseCodeAPI.GetGroup(cause);
197  int reasonInt = KickCauseCodeAPI.GetReason(cause);
198 
199  if (groupInt != RplKickCauseGroup.REPLICATION)
200  return false;
201  else if (reasonInt == RplError.SHUTDOWN)
202  return false;
203 
204  bool addEntry = true;
205 
206  if (!m_ReconnectPlayerList.IsEmpty())
207  {
208  int count = m_ReconnectPlayerList.Count();
209  for (int i; i < count; i++)
210  {
211  if (m_ReconnectPlayerList[i].m_iPlayerId == playerId)
212  {
213  addEntry = false;
214  break;
215  }
216  }
217  }
218 
219  if (addEntry)
220  {
221  IEntity ent = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerId);
222  if (!ent)
223  return false;
224 
225  SCR_ReconnectData newEntry = new SCR_ReconnectData(playerId, ent);
226  m_ReconnectPlayerList.Insert(newEntry);
227  if (m_OnAddedToReconnectList)
228  m_OnAddedToReconnectList.Invoke(newEntry);
229  }
230 
231  return true;
232  }
233 
234  //------------------------------------------------------------------------------------------------
236  bool Init()
237  {
238  m_bIsInit = true;
239 
240  BackendApi backendApi = GetGame().GetBackendApi();
241  if (!backendApi || !backendApi.IsActive() || (!backendApi.IsInitializing() && !backendApi.IsRunning()))
242  {
243  m_bIsReconEnabled = false; // not connected to backend
244  Deactivate(GetOwner());
245  return false;
246  }
247 
248  return true;
249  }
250 
251  //------------------------------------------------------------------------------------------------
253  override protected void OnPlayerAuditTimeouted(int playerId)
254  {
255  if (m_ReconnectPlayerList.IsEmpty())
256  return;
257 
258  int count = m_ReconnectPlayerList.Count();
259  for (int i; i < count; i++)
260  {
261  if (m_ReconnectPlayerList[i].m_iPlayerId == playerId)
262  {
263  RplComponent.DeleteRplEntity(m_ReconnectPlayerList[i].m_ReservedEntity, false);
264  m_ReconnectPlayerList.Remove(i);
265  return;
266  }
267  }
268  }
269 
270  //------------------------------------------------------------------------------------------------
271  override void OnPostInit(IEntity owner)
272  {
273  RplComponent rplComp = RplComponent.Cast(owner.FindComponent(RplComponent));
274  if (!rplComp.IsProxy() && m_bEnableReconnect) // ends here if not authority
275  SetEventMask(owner, EntityEvent.INIT);
276  else
277  m_bIsReconEnabled = false;
278  }
279 
280  //------------------------------------------------------------------------------------------------
281  override void EOnInit(IEntity owner)
282  {
283  s_Instance = this;
284  m_bIsReconEnabled = true;
285 
286  ArmaReforgerScripted game = GetGame();
287  if (game && !game.InPlayMode())
288  return;
289 
290  SCR_BaseGameMode.Cast(game.GetGameMode()).GetOnPlayerAuditTimeouted().Insert(OnPlayerAuditTimeouted);
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  // destructor
295  void ~SCR_ReconnectComponent()
296  {
297  if (SCR_BaseGameMode.Cast(GetGame().GetGameMode()))
298  SCR_BaseGameMode.Cast(GetGame().GetGameMode()).GetOnPlayerAuditTimeouted().Remove(OnPlayerAuditTimeouted);
299 
300  s_Instance = null;
301  }
302 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
GetCharacterController
protected SCR_CharacterControllerComponent GetCharacterController(IEntity from)
Definition: SCR_ItemPlacementComponent.c:50
SCR_PlayerController
Definition: SCR_PlayerController.c:31
KickCauseGroup2
KickCauseGroup2
Extends KickCauseGroup by adding game-specific groups.
Definition: KickCauseGroup2.c:13
NOT_RECONNECT
class SCR_ReconnectData NOT_RECONNECT
State of a reconnecting player.
m_ReservedEntity
IEntity m_ReservedEntity
entity of the returning player
Definition: SCR_ReconnectComponent.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
KickCauseCodeAPI
Definition: KickCauseCodeAPI.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
ENTITY_AVAILABLE
class SCR_ReconnectData ENTITY_AVAILABLE
KickCauseCode
KickCauseCode
Definition: KickCauseCode.c:19
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
s_Instance
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ReconnectData
Data class for reconnecting players.
Definition: SCR_ReconnectComponent.c:2
Deactivate
protected void Deactivate()
Definition: SCR_BaseHintCondition.c:27
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_iPlayerId
protected int m_iPlayerId
Definition: SCR_CallsignCharacterComponent.c:14
EntityEditorProps
class SCR_ReconnectData EntityEditorProps(category:"GameScripted/GameMode", description:"")
Definition: SCR_ReconnectComponent.c:26
IsDead
proto external bool IsDead()
m_OnPlayerReconnect
protected ref ScriptInvokerInt m_OnPlayerReconnect
Definition: SCR_ReconnectSynchronizationComponent.c:12
PlayerManager
Definition: PlayerManager.c:12
SCR_ReconnectComponent
Definition: SCR_ReconnectComponent.c:41
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
m_iPlayerId
int m_iPlayerId
Definition: SCR_ReconnectComponent.c:2
SCR_ReconnectData
void SCR_ReconnectData(int playerId, IEntity entity)
Definition: SCR_ReconnectComponent.c:9
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199