5 IEntity m_ReservedEntity;
19 enum SCR_EReconnectState
30 static override bool DependsOn(
string className)
32 if (className ==
"RplComponentClass")
43 [
Attribute(defvalue:
"1", uiwidget: UIWidgets.CheckBox,
desc:
"Enable reconnect functionality for this gamemode")]
44 bool m_bEnableReconnect;
48 protected bool m_bIsInit;
49 protected bool m_bIsReconEnabled;
50 protected ref array<ref SCR_ReconnectData> m_ReconnectPlayerList = {};
52 protected ref ScriptInvoker m_OnAddedToReconnectList;
53 protected ref ScriptInvoker m_OnPlayerReconnect;
64 ScriptInvoker GetOnAddedToList()
66 if (!m_OnAddedToReconnectList)
67 m_OnAddedToReconnectList =
new ScriptInvoker();
69 return m_OnAddedToReconnectList;
74 ScriptInvoker GetOnReconnect()
84 bool IsReconnectListEmpty()
86 return m_ReconnectPlayerList.IsEmpty();
91 bool IsReconnectEnabled()
93 return m_bIsReconEnabled;
100 SCR_EReconnectState IsInReconnectList(
int playerId)
105 return SCR_EReconnectState.NOT_RECONNECT;
108 if (m_ReconnectPlayerList.IsEmpty())
109 return SCR_EReconnectState.NOT_RECONNECT;
111 int count = m_ReconnectPlayerList.Count();
112 for (
int i; i < count; i++)
114 if (m_ReconnectPlayerList[i].
m_iPlayerId == playerId)
116 ChimeraCharacter
char = ChimeraCharacter.Cast(m_ReconnectPlayerList[i].
m_ReservedEntity);
119 m_ReconnectPlayerList.Remove(i);
120 return SCR_EReconnectState.ENTITY_DISCARDED;
123 return SCR_EReconnectState.ENTITY_AVAILABLE;
127 return SCR_EReconnectState.NOT_RECONNECT;
134 SCR_EReconnectState IsEntityReconnectList(IEntity entity)
139 return SCR_EReconnectState.NOT_RECONNECT;
142 if (m_ReconnectPlayerList.IsEmpty())
143 return SCR_EReconnectState.NOT_RECONNECT;
145 int count = m_ReconnectPlayerList.Count();
146 for (
int i; i < count; i++)
150 ChimeraCharacter
char = ChimeraCharacter.Cast(m_ReconnectPlayerList[i].
m_ReservedEntity);
153 m_ReconnectPlayerList.Remove(i);
154 return SCR_EReconnectState.ENTITY_DISCARDED;
157 return SCR_EReconnectState.ENTITY_AVAILABLE;
161 return SCR_EReconnectState.NOT_RECONNECT;
168 IEntity ReturnControlledEntity(
int playerId)
170 int count = m_ReconnectPlayerList.Count();
171 for (
int i; i < count; i++)
173 if (m_ReconnectPlayerList[i].
m_iPlayerId == playerId)
175 IEntity ent = m_ReconnectPlayerList[i].m_ReservedEntity;
178 playerController.SetInitialMainEntity(ent);
183 m_ReconnectPlayerList.Remove(i);
199 if (groupInt != RplKickCauseGroup.REPLICATION)
201 else if (reasonInt == RplError.SHUTDOWN)
204 bool addEntry =
true;
206 if (!m_ReconnectPlayerList.IsEmpty())
208 int count = m_ReconnectPlayerList.Count();
209 for (
int i; i < count; i++)
211 if (m_ReconnectPlayerList[i].
m_iPlayerId == playerId)
221 IEntity ent =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerId);
226 m_ReconnectPlayerList.Insert(newEntry);
227 if (m_OnAddedToReconnectList)
228 m_OnAddedToReconnectList.Invoke(newEntry);
240 BackendApi backendApi =
GetGame().GetBackendApi();
241 if (!backendApi || !backendApi.IsActive() || (!backendApi.IsInitializing() && !backendApi.IsRunning()))
243 m_bIsReconEnabled =
false;
253 override protected void OnPlayerAuditTimeouted(
int playerId)
255 if (m_ReconnectPlayerList.IsEmpty())
258 int count = m_ReconnectPlayerList.Count();
259 for (
int i; i < count; i++)
261 if (m_ReconnectPlayerList[i].
m_iPlayerId == playerId)
263 RplComponent.DeleteRplEntity(m_ReconnectPlayerList[i].
m_ReservedEntity,
false);
264 m_ReconnectPlayerList.Remove(i);
271 override void OnPostInit(IEntity owner)
273 RplComponent rplComp = RplComponent.Cast(owner.FindComponent(RplComponent));
274 if (!rplComp.IsProxy() && m_bEnableReconnect)
275 SetEventMask(owner, EntityEvent.INIT);
277 m_bIsReconEnabled =
false;
281 override void EOnInit(IEntity owner)
284 m_bIsReconEnabled =
true;
286 ArmaReforgerScripted game =
GetGame();
287 if (game && !game.InPlayMode())
290 SCR_BaseGameMode.Cast(game.GetGameMode()).GetOnPlayerAuditTimeouted().Insert(OnPlayerAuditTimeouted);