Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_KickDialogs.c
Go to the documentation of this file.
2 {
3  protected const ResourceName KICK_DIALOGS_CONFIG = "{D3BFEE28E7D5B6A1}Configs/ServerBrowser/KickDialogs.conf";
4  protected const ResourceName HOSTING_ERROR_DIALOG_CONFIG = "{F96212757F65C4A3}Configs/ServerBrowser/ServerHosting/Dialogs/ServerHostingErrors.conf";
5 
6  protected const string TAG_KICK_DEFAULT = "DEFAULT_ERROR";
7  protected const int MAX_AUTO_REJOINS = 3;
8 
9  protected static SCR_ConfigurableDialogUi s_CurrentKickDialog;
10 
11  protected static string s_sErrorMessage;
12  protected static string s_sErrorMessageGroup;
13  protected static string s_sErrorMessageDetail;
14 
15  protected static bool m_bReconnectEnabled;
16 
17  protected static ref ScriptInvokerVoid s_OnErrorMessageSet;
18  protected static ref ScriptInvokerVoid s_OnCancel;
19  protected static ref ScriptInvokerVoid s_OnReconnect;
20 
21  protected static ref SCR_BackendCallback m_ProcessLastHostCallback = new SCR_BackendCallback();
22 
23  //------------------------------------------------------------------------------------------------
25  static void CreateKickErrorDialog(string msg, string group, string details = "")
26  {
27  s_sErrorMessage = msg;
28  s_sErrorMessageGroup = group;
29  s_sErrorMessageDetail = details;
30 
31  if (s_OnErrorMessageSet)
32  s_OnErrorMessageSet.Invoke();
33 
34  DisplayKickErrorDialog();
35  }
36 
37  //------------------------------------------------------------------------------------------------
39  static void DisplayKickErrorDialog()
40  {
41  if (s_sErrorMessage.IsEmpty())
42  return;
43 
44  // --- Setup Kick dialog ---
45  SCR_ConfigurableDialogUi dialogUi = SCR_ConfigurableDialogUi.CreateFromPreset(KICK_DIALOGS_CONFIG, s_sErrorMessage);
46 
47  // Use group as fallback if no dialog found
48  if (!dialogUi)
49  dialogUi = SCR_ConfigurableDialogUi.CreateFromPreset(KICK_DIALOGS_CONFIG, s_sErrorMessageGroup);
50 
51  // Show default error if tag is not found
52  if (!dialogUi)
53  dialogUi = SCR_ConfigurableDialogUi.CreateFromPreset(KICK_DIALOGS_CONFIG, TAG_KICK_DEFAULT);
54 
55  if (!dialogUi)
56  {
57  Clear();
58  return;
59  }
60 
61  s_CurrentKickDialog = dialogUi;
62  dialogUi.m_OnClose.Insert(OnDialogClose);
63 
64  // Set error details
65  SCR_RejoinDialog errorDialogComp = SCR_RejoinDialog.FindRejoinComponent(dialogUi.GetRootWidget());
66  if (errorDialogComp)
67  errorDialogComp.SetErrorDetail(s_sErrorMessageDetail);
68 
69  // Check reconnect
70  SCR_KickDialogUiPreset kickPreset = SCR_KickDialogUiPreset.Cast(dialogUi.GetDialogPreset());
71  bool reconnect = m_bReconnectEnabled && kickPreset && kickPreset.m_bCanBeReconnected;
72 
73  SCR_InputButtonComponent confirmButton = dialogUi.FindButton(SCR_ConfigurableDialogUi.BUTTON_CONFIRM);
74  if (confirmButton)
75  confirmButton.SetVisible(reconnect);
76 
77  // --- Setup reconnect ---
78  if (!reconnect)
79  {
80  Clear();
81  return;
82  }
83 
84  string errorStr = kickPreset.m_sMessage;
85  errorDialogComp.SetErrorMessage(errorStr);
86 
87  // Check rejoin attempt
88  string strAttempt = GameSessionStorage.s_Data["m_iRejoinAttempt"];
89  int attempt = strAttempt.ToInt();
90 
91  if (attempt <= MAX_AUTO_REJOINS)
92  {
93  errorStr += "\n" + "#AR-ServerBrowser_JoinMessageDefault";
94  errorDialogComp.SetErrorMessage(errorStr);
95 
96  dialogUi.SetMessage(errorStr + " " + errorDialogComp.GetTimer());
97 
98  // Setup timer
99  errorDialogComp.GetEventOnTimerChanged().Insert(OnDialogTimerChange);
100 
101  errorDialogComp.ShowLoading(true);
102  errorDialogComp.SetTimer(kickPreset.m_iAutomaticReconnectTime);
103  errorDialogComp.RunTimer(true);
104  }
105  else
106  {
107  dialogUi.SetMessage(errorStr);
108 
109  // Block rejoin
110  errorDialogComp.ShowLoading(false);
111  if (confirmButton)
112  confirmButton.SetEnabled(false);
113  }
114 
115  // Reconnect button
116  dialogUi.m_OnConfirm.Insert(OnReconnect);
117  dialogUi.m_OnCancel.Insert(OnCancel);
118 
119  Clear();
120  }
121 
122  //------------------------------------------------------------------------------------------------
124  static void CheckLastServerHost()
125  {
126  // Check for hosting errors
127  m_ProcessLastHostCallback.GetEventOnResponse().Insert(OnProcessLastHostResponse);
128  GetGame().GetBackendApi().GetClientLobby().ProcessLastHostError(m_ProcessLastHostCallback);
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  protected static void OnProcessLastHostResponse(SCR_BackendCallback callback)
133  {
134  int code = callback.GetCode();
135  int rest = callback.GetRestCode();
136  int api = callback.GetApiCode();
137 
138  if (callback.GetResponseType() != EBackendCallbackResponse.SUCCESS)
139  {
140  string apiStr = typename.EnumToString(EApiCode, api);
141 
142  switch (api)
143  {
144  case EApiCode.EACODE_ERROR_ASSET_NOT_FOUND:
145  {
146  SCR_ConfigurableDialogUi dialogUi = SCR_ConfigurableDialogUi.CreateFromPreset(HOSTING_ERROR_DIALOG_CONFIG, apiStr);
147  return;
148  }
149  default:
150  {
151  SCR_ConfigurableDialogUi dialogUi = SCR_ConfigurableDialogUi.CreateFromPreset(HOSTING_ERROR_DIALOG_CONFIG, "unknown");
152  return;
153  }
154  }
155  }
156 
157  callback.GetEventOnResponse().Remove(OnProcessLastHostResponse);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  static void SetReconnectEnabled(bool enabled)
162  {
163  m_bReconnectEnabled = enabled;
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  static void Clear()
168  {
169  s_sErrorMessage = string.Empty;
170  s_sErrorMessageGroup = string.Empty;
171  s_sErrorMessageDetail = string.Empty;
172  }
173 
174  // Getters
175  //------------------------------------------------------------------------------------------------
176  static SCR_ConfigurableDialogUi GetCurrentKickDialog()
177  {
178  return s_CurrentKickDialog;
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  static ScriptInvokerVoid GetOnCancel()
183  {
184  if (!s_OnCancel)
185  s_OnCancel = new ScriptInvokerVoid();
186 
187  return s_OnCancel;
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  static ScriptInvokerVoid GetOnReconnect()
192  {
193  if (!s_OnReconnect)
194  s_OnReconnect = new ScriptInvokerVoid();
195 
196  return s_OnReconnect;
197  }
198 
199  // Internal
200  //------------------------------------------------------------------------------------------------
201  protected static void OnDialogTimerChange(SCR_RejoinDialog dialog, int time)
202  {
203  if (!s_CurrentKickDialog)
204  return;
205 
206  s_CurrentKickDialog.SetMessage(dialog.GetErrorMessage() + " " + time);
207 
208  if (time == 0)
209  {
210  OnReconnect();
211  s_CurrentKickDialog.Close();
212  }
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  protected static void OnDialogClose()
217  {
218  s_CurrentKickDialog = null;
219  Clear();
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  protected static void OnReconnect()
224  {
225  if (s_OnReconnect)
226  s_OnReconnect.Invoke();
227  }
228 
229  //------------------------------------------------------------------------------------------------
230  protected static void OnCancel()
231  {
232  if (s_OnCancel)
233  s_OnCancel.Invoke();
234  }
235 }
SCR_KickDialogs
Definition: SCR_KickDialogs.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
SCR_RejoinDialog
Definition: SCR_RejoinDialog.c:2
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
SCR_KickDialogUiPreset
Server kick message specific dialog.
Definition: SCR_KickDialogUiPreset.c:5
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
EBackendCallbackResponse
EBackendCallbackResponse
Basic callback responses.
Definition: SCR_BackendCallback.c:12
callback
DownloadConfigCallback callback
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1