Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
ServerBrowserMenuCallbacks.c
Go to the documentation of this file.
1 /*
2 File for various server browser callbacks to keep ServerBrowserMenuUI clean.
3 */
4 
5 //------------------------------------------------------------------------------------------------
7 {
8  SUCCESS = 0,
9  ERROR = 1,
10  TIMEOUT = 2,
11 };
12 
13 //------------------------------------------------------------------------------------------------
16 {
17  // Cache
18  protected int m_iCode = -1;
19  protected int m_iRestCode = -1;
20  protected int m_iApiCode = -1;
21  protected EServerBrowserRequestResult m_Result = -1;
22 
23  // Invokers
24  ref ScriptInvoker m_OnSuccess = new ScriptInvoker;
25  ref ScriptInvoker m_OnFail = new ScriptInvoker;
26  ref ScriptInvoker m_OnTimeOut = new ScriptInvoker;
27 
28  ref ScriptInvoker<ServerBrowserCallback> event_OnResponse = new ScriptInvoker;
29 
30  //------------------------------------------------------------------------------------------------
31  // Override API
32  //------------------------------------------------------------------------------------------------
33 
34  //------------------------------------------------------------------------------------------------
35  override void OnSuccess(int code)
36  {
37  CacheLastResponse(EServerBrowserRequestResult.SUCCESS, code);
38  //CacheLastResponse(EServerBrowserRequestResult.ERROR, code);
39 
40  m_OnSuccess.Invoke(this);
41 
42  event_OnResponse.Invoke(this);
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  override void OnError(int code, int restCode, int apiCode)
47  {
48  CacheLastResponse(EServerBrowserRequestResult.ERROR, code, restCode, apiCode);
49  m_OnFail.Invoke(this, code, restCode, apiCode);
50 
51  event_OnResponse.Invoke(this);
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  override void OnTimeout()
56  {
57  CacheLastResponse(EServerBrowserRequestResult.TIMEOUT);
58  m_OnTimeOut.Invoke(this);
59 
60  event_OnResponse.Invoke(this);
61  }
62 
63 
64 
65  //------------------------------------------------------------------------------------------------
66  // Protected API
67  //------------------------------------------------------------------------------------------------
68 
69  //------------------------------------------------------------------------------------------------
71  protected void CacheLastResponse(EServerBrowserRequestResult result, int code = -1, int restCode = -1, int apiCode = -1)
72  {
73  m_Result = result;
74  m_iCode = code;
75  m_iRestCode = restCode;
76  m_iApiCode = m_iApiCode;
77  }
78 
79 
80 
81  //------------------------------------------------------------------------------------------------
82  // Getter API
83  //------------------------------------------------------------------------------------------------
84 
85  //------------------------------------------------------------------------------------------------
86  int GetCode()
87  {
88  return m_iCode;
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  int GetRestCode()
93  {
94  return m_iRestCode;
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  int GetApiCode()
99  {
100  return m_iApiCode;
101  }
102 
103  //------------------------------------------------------------------------------------------------
104  EServerBrowserRequestResult GetResultType()
105  {
106  return m_Result;
107  }
108 };
109 
110 //------------------------------------------------------------------------------------------------
112 class OnDirectJoinCallback extends ServerBrowserCallback
113 {
114  protected array<Room> m_Rooms;
115 
116  //------------------------------------------------------------------------------------------------
117  override void OnSuccess(int code)
118  {
119  array<Room> rooms = new array<Room>;
120  GetGame().GetBackendApi().GetClientLobby().Target(rooms);
121 
122  // No server
123  if (rooms.Count() == 0)
124  {
125  #ifdef SB_DEBUG
126  Print("[ServerBrowserMenuCallback] No room found with given parameters!", LogLevel.ERROR);
127  #endif
128 
129  m_OnFail.Invoke();
130  return;
131  }
132 
133  // Set room to join
134  m_Rooms = rooms;
135  super.OnSuccess(code);
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  void OnDirectJoinCallback()
140  {
141  //Print("OnDirectJoinCallback recreated");
142  return;
143  }
144 
145  //------------------------------------------------------------------------------------------------
146  array<Room> GetFoundRooms() { return m_Rooms; }
147 };
148 
149 //------------------------------------------------------------------------------------------------
152 {
153  protected Room m_Room;
154 
155  //------------------------------------------------------------------------------------------------
156  void SetRoom(Room room)
157  {
158  m_Room = room;
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  Room GetRoom()
163  {
164  return m_Room;
165  }
166 }
167 
168 //------------------------------------------------------------------------------------------------
170 class OnJoinRoomSB extends ServerBrowserCallback
171 {
172  //------------------------------------------------------------------------------------------------
173  override void OnSuccess(int code)
174  {
175  super.OnSuccess(code);
176 
177  #ifdef SB_DEBUG
178  Print("[ServerBrowserMenuCallback] OnJoinRoomSB Success");
179  #endif
180  }
181 
182  //------------------------------------------------------------------------------------------------
183  override void OnError(int code, int restCode, int apiCode)
184  {
185  super.OnError(code, restCode, apiCode);
186 
187  #ifdef SB_DEBUG
188  Print("[ServerBrowserMenuCallback] OnJoinRoomSB Error");
189  #endif
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  override void OnTimeout()
194  {
195  super.OnTimeout();
196 
197  #ifdef SB_DEBUG
198  Print("[ServerBrowserMenuCallback] OnJoinRoomSB Timeout");
199  #endif
200  }
201 };
202 
203 //------------------------------------------------------------------------------------------------
205 class RoomJoinData extends JsonApiStruct
206 {
207  string m_Password = "";
208 
209  // Ban related data
210  string scope = "";
211  string type = "";
212  string reason = "";
213  string issuer = "";
214  int expiresAt = 0;
215  int createdAt = 0;
216 
217  //------------------------------------------------------------------------------------------------
218  override void OnPack()
219  {
220  UnregV("scope");
221  UnregV("type");
222  UnregV("reason");
223  UnregV("issuer");
224  UnregV("expiresAt");
225  UnregV("createdAt");
226 
227  if (!m_Password.IsEmpty())
228  StoreString("password", m_Password);
229  }
230 
231  override void OnExpand()
232  {
233  RegV("scope");
234  RegV("type");
235  RegV("reason");
236  RegV("issuer");
237  RegV("expiresAt");
238  RegV("createdAt");
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  void SetPassword(string password) { m_Password = password; }
243 };
ERROR
@ ERROR
Definition: ServerBrowserMenuCallbacks.c:9
OnExpand
override void OnExpand()
Definition: SCR_DSConfig.c:191
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
JsonApiStruct
Parameters for joining server.
Definition: FeedbackDialogUI.c:2
OnError
override void OnError(int code, int restCode, int apiCode)
Definition: ServerBrowserMenuCallbacks.c:183
ServerBrowserCallback
Callback for searching servers dirrecly.
Definition: ServerBrowserMenuCallbacks.c:112
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
OnTimeout
override void OnTimeout()
Definition: ServerBrowserMenuCallbacks.c:193
OnPack
override void OnPack()
Definition: SCR_ContentBrowser_AddonsSubMenu.c:1564
TIMEOUT
@ TIMEOUT
Definition: ServerBrowserMenuCallbacks.c:10
BackendCallback
Base server browser callback.
Definition: SCR_ServerListComponent.c:4
SCR_RoomCallback
Scripted room callback specific for single room.
Definition: ServerBrowserMenuCallbacks.c:151
SUCCESS
@ SUCCESS
Definition: ServerBrowserMenuCallbacks.c:8
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
m_Room
protected Room m_Room
Definition: ServerBrowserMenuCallbacks.c:2
OnSuccess
class RoomJoinData extends JsonApiStruct OnSuccess
EServerBrowserRequestResult
EServerBrowserRequestResult
Definition: ServerBrowserMenuCallbacks.c:6