Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
MultiplayerDialogUI.c
Go to the documentation of this file.
1
//------------------------------------------------------------------------------------------------
2
class
MultiplayerDialogUI
:
SCR_ConfigurableDialogUi
//DialogUI
3
{
4
const
string
WIDGET_EDIT_IP =
"EditIP"
;
5
const
string
WIDGET_EDIT_PORT =
"EditPort"
;
6
const
string
WIDGET_CHECK_NETWORK =
"CheckboxNetwork"
;
7
8
const
string
DEFAULT_ADDRESS =
"127.0.0.1"
;
9
const
string
DEFAULT_PORT =
"2001"
;
10
const
int
DIRECT_JOIN_CODE_LENGTH = 10;
11
12
protected
SCR_EditBoxComponent
m_EditIP
;
13
protected
SCR_EditBoxComponent
m_EditPort
;
14
protected
SCR_CheckboxComponent
m_CheckNetwork
;
15
16
protected
ServerBrowserMenuUI
m_ServerBrowserUI
;
17
18
/*ref ScriptInvoker m_OnJoinCodeEntered = new ScriptInvoker;
19
ref ScriptInvoker m_OnIpEntered = new ScriptInvoker;*/
20
21
//------------------------------------------------------------------------------------------------
22
override
void
OnConfirm
()
23
{
24
string
address =
GetAddress
();
25
EDirectJoinFormats
format =
IsInputValid
(
m_EditIP
);
26
bool
publicNetwork = !
m_CheckNetwork
.IsChecked();
27
28
m_OnConfirm
.Invoke(address, format, publicNetwork);
29
30
Close
();
31
}
32
33
//------------------------------------------------------------------------------------------------
34
string
GetAddress
()
35
{
36
// Theres no other way to recover the default values other than setting "UseDefaultValues".
37
// This prevents the user from setting the value directly. Instead it forces him to delete
38
// the default value glyph by glyph which is tedious.
39
40
if
(!
m_EditIP
|| !
m_EditPort
)
41
return
string
.Empty;
42
43
// Address
44
string
sAddr =
m_EditIP
.GetValue();
45
if
(sAddr.Length() == 0)
46
return
string
.Empty;
47
48
// Set client address as fallback - todo: this will be removed once lan detection is available
49
if
(sAddr == DEFAULT_ADDRESS)
50
sAddr =
GetGame
().GetBackendApi().GetClientLobby().GetMyIP();
51
52
// Port
53
string
sPort =
string
.Empty;
54
55
if
(
IsAddressValid
(sAddr))
56
{
57
sPort =
m_EditPort
.GetValue();
58
if
(sPort.Length() == 0)
59
return
string
.Empty;
60
}
61
62
BaseContainer
gameplaySettings
=
GetGame
().GetGameUserSettings().GetModule(
"SCR_GameplaySettings"
);
63
64
// Check whether address matches ipv4 format of x.x.x.x, or x.x.x.x:port where x = [0, 255]
65
//REFACTOR NOTE
66
//This is wrong, should check for either ip address OR invite code. Switche it to the corret function call.
67
if
(
IsInputValid
(
m_EditPort
))
68
{
69
if
(
gameplaySettings
)
70
{
71
gameplaySettings
.Set(
"m_sLastIP"
, sAddr);
72
GetGame
().UserSettingsChanged();
73
}
74
}
75
76
if
(
gameplaySettings
)
77
{
78
gameplaySettings
.Set(
"m_sLastPort"
, sPort);
79
GetGame
().UserSettingsChanged();
80
}
81
82
// Results
83
if
(!sPort.IsEmpty())
84
return
sAddr +
":"
+ sPort;
85
else
86
return
sAddr;
87
}
88
89
90
91
//------------------------------------------------------------------------------------------------
92
override
void
OnMenuOpen
(
SCR_ConfigurableDialogUiPreset
preset)
93
{
94
// Old OnMenuOpen()
95
super.OnMenuOpen(preset);
96
Widget
root =
GetRootWidget
();
97
98
99
// IP and join code edit
100
m_EditIP
=
SCR_EditBoxComponent
.
GetEditBoxComponent
(WIDGET_EDIT_IP, root);
101
102
if
(
m_EditIP
)
103
{
104
m_EditIP
.m_OnChanged.Insert(
CheckValidInput
);
105
106
Widget
focus =
m_EditIP
.GetRootWidget();
107
if
(focus)
108
GetGame
().GetWorkspace().SetFocusedWidget(focus);
109
}
110
111
// Port edit
112
m_EditPort
=
SCR_EditBoxComponent
.
GetEditBoxComponent
(WIDGET_EDIT_PORT, root);
113
114
if
(
m_EditPort
)
115
{
116
m_EditPort
.m_OnChanged.Insert(
CheckValidInput
);
117
}
118
119
// Checkbox network
120
m_CheckNetwork
=
SCR_CheckboxComponent
.GetCheckboxComponent(WIDGET_CHECK_NETWORK, root);
121
122
//SetDialogType(EDialogType.ACTION);
123
//---
124
125
// Try to load the last valid address
126
string
text;
127
BaseContainer
gameplaySettings
=
GetGame
().GetGameUserSettings().GetModule(
"SCR_GameplaySettings"
);
128
if
(
gameplaySettings
)
129
gameplaySettings
.Get(
"m_sLastIP"
, text);
130
131
if
(text !=
string
.Empty &&
m_EditIP
)
132
m_EditIP
.SetValue(text);
133
134
// Port
135
string
port;
136
if
(
gameplaySettings
)
137
gameplaySettings
.Get(
"m_sLastPort"
, port);
138
139
if
(
m_EditPort
)
140
{
141
if
(!port.IsEmpty())
142
m_EditPort
.SetValue(port);
143
else
144
m_EditPort
.SetValue(DEFAULT_PORT);
145
}
146
147
// Set the confirm button enabled or disabled
148
CheckValidInput
(
m_EditIP
,
string
.Empty);
149
}
150
151
//------------------------------------------------------------------------------------------------
152
// Checks whether specified ipv4 address matches the 'x.x.x.x' format, where x = [0, 255]
153
// if address is passed along with port, port is ignored
154
bool
IsAddressValid
(
string
address)
155
{
156
// ""
157
if
(address ==
string
.Empty)
158
return
false
;
159
160
161
// cut off port or whatever follows the :
162
if
(address.Contains(
":"
))
163
{
164
int
colonIndex = address.IndexOf(
":"
);
165
address = address.Substring(0, colonIndex);
166
}
167
168
array<string> values =
new
array<string>();
169
address.Split(
"."
, values,
true
);
170
int
valuesCount = values.Count();
171
172
// 0.1.2.3 = 4 values
173
if
(valuesCount != 4)
174
return
false
;
175
176
int
zeroElements = 0;
177
// check if values are ok
178
for
(
int
i = 0; i < 4; i++)
179
{
180
// Iterate through all tokens parsed between '.'
181
// if all of the characters are digit (ascii 48-57)
182
// it then checks if each value is within 0-255 range
183
// if anything fails, returns false
184
int
strLen = values[i].Length();
185
for
(
int
j = 0; j < strLen; j++)
186
{
187
// Check if it's a valid digit
188
string
char
= values[i].Get(j);
189
int
asciiValue =
char
.ToAscii();
190
if
(asciiValue >= 48 && asciiValue <= 57)
191
continue
;
192
else
193
return
false
;
194
}
195
196
int
value = values[i].ToInt();
197
if
(value == 0)
198
zeroElements++;
199
200
if
(value >= 0 && value <= 255)
201
continue
;
202
else
203
return
false
;
204
}
205
206
return
true
;
207
}
208
209
//------------------------------------------------------------------------------------------------
211
protected
bool
IsJoinCodeValid
(
string
text)
212
{
213
// Text size
214
if
(text.Length() != DIRECT_JOIN_CODE_LENGTH)
215
return
false
;
216
217
for
(
int
i = 0, len = text.Length(); i < len; i++)
218
{
219
// fail if is not a number
220
if
(text[i].ToInt() == 0 && text[i] !=
"0"
)
221
return
false
;
222
}
223
224
return
true
;
225
}
226
227
//------------------------------------------------------------------------------------------------
228
void
CheckValidInput
(
SCR_EditBoxComponent
comp,
string
text)
229
{
230
if
(!
m_EditIP
)
231
return
;
232
233
bool
validInput =
IsInputValid
(
m_EditIP
) !=
EDirectJoinFormats
.INVALID;
234
bool
validAddress =
IsInputValid
(
m_EditIP
) ==
EDirectJoinFormats
.IP_PORT;
235
236
// Enable input
237
m_EditPort
.SetEnabled(validAddress);
238
//m_Confirm.SetEnabled(validInput);
239
FindButton
(
"confirm"
).
SetEnabled
(validInput);
240
}
241
242
//------------------------------------------------------------------------------------------------
243
protected
EDirectJoinFormats
IsInputValid
(
SCR_EditBoxComponent
comp)
244
{
245
// IP:port
246
if
(
IsAddressValid
(
m_EditIP
.GetValue()))
247
return
EDirectJoinFormats
.IP_PORT;
248
249
// Join code
250
if
(
IsJoinCodeValid
(
m_EditIP
.GetValue()))
251
return
EDirectJoinFormats
.JOIN_CODE;
252
253
return
EDirectJoinFormats
.INVALID;
254
}
255
256
//------------------------------------------------------------------------------------------------
257
void
SetServerBrowserUI
(
ServerBrowserMenuUI
serverBrowserUI) {
m_ServerBrowserUI
=
m_ServerBrowserUI
; }
258
};
259
260
//------------------------------------------------------------------------------------------------
261
enum
EDirectJoinFormats
262
{
263
INVALID
,
264
IP_PORT
,
265
JOIN_CODE
,
266
ROOM_ID
,
267
};
268
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
EDirectJoinFormats
EDirectJoinFormats
Definition
MultiplayerDialogUI.c:262
ROOM_ID
@ ROOM_ID
Definition
MultiplayerDialogUI.c:266
IP_PORT
@ IP_PORT
Definition
MultiplayerDialogUI.c:264
JOIN_CODE
@ JOIN_CODE
Definition
MultiplayerDialogUI.c:265
gameplaySettings
SCR_HelicopterControllerComponentClass gameplaySettings
BaseContainer
Definition
BaseContainer.c:13
MultiplayerDialogUI
Definition
MultiplayerDialogUI.c:3
MultiplayerDialogUI::OnMenuOpen
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
Definition
MultiplayerDialogUI.c:92
MultiplayerDialogUI::m_CheckNetwork
SCR_CheckboxComponent m_CheckNetwork
Definition
MultiplayerDialogUI.c:14
MultiplayerDialogUI::SetServerBrowserUI
void SetServerBrowserUI(ServerBrowserMenuUI serverBrowserUI)
Definition
MultiplayerDialogUI.c:257
MultiplayerDialogUI::GetAddress
string GetAddress()
Definition
MultiplayerDialogUI.c:34
MultiplayerDialogUI::m_EditIP
SCR_EditBoxComponent m_EditIP
Definition
MultiplayerDialogUI.c:12
MultiplayerDialogUI::OnConfirm
override void OnConfirm()
Definition
MultiplayerDialogUI.c:22
MultiplayerDialogUI::m_ServerBrowserUI
ServerBrowserMenuUI m_ServerBrowserUI
Definition
MultiplayerDialogUI.c:16
MultiplayerDialogUI::IsAddressValid
bool IsAddressValid(string address)
Definition
MultiplayerDialogUI.c:154
MultiplayerDialogUI::m_EditPort
SCR_EditBoxComponent m_EditPort
Definition
MultiplayerDialogUI.c:13
MultiplayerDialogUI::IsJoinCodeValid
bool IsJoinCodeValid(string text)
Check it string is in join code format - 10 size, digits are check in editbox.
Definition
MultiplayerDialogUI.c:211
MultiplayerDialogUI::CheckValidInput
void CheckValidInput(SCR_EditBoxComponent comp, string text)
Definition
MultiplayerDialogUI.c:228
MultiplayerDialogUI::IsInputValid
EDirectJoinFormats IsInputValid(SCR_EditBoxComponent comp)
Definition
MultiplayerDialogUI.c:243
SCR_CheckboxComponent
This is refactored checkbox preserving its own class and API for compatability purposes.
Definition
SCR_CheckboxComponent.c:4
SCR_ConfigurableDialogUi
Definition
SCR_ConfigurableDialogUI.c:17
SCR_ConfigurableDialogUi::Close
void Close()
Definition
SCR_ConfigurableDialogUI.c:254
SCR_ConfigurableDialogUi::GetRootWidget
Widget GetRootWidget()
Definition
SCR_ConfigurableDialogUI.c:227
SCR_ConfigurableDialogUi::FindButton
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Definition
SCR_ConfigurableDialogUI.c:419
SCR_ConfigurableDialogUi::m_OnConfirm
ref ScriptInvoker m_OnConfirm
Definition
SCR_ConfigurableDialogUI.c:47
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition
SCR_ConfigurableDialogUI.c:764
SCR_EditBoxComponent
Definition
SCR_EditBoxComponent.c:9
SCR_EditBoxComponent::GetEditBoxComponent
static SCR_EditBoxComponent GetEditBoxComponent(string name, Widget parent, bool searchAllChildren=true)
Definition
SCR_EditBoxComponent.c:382
SCR_InputButtonComponent::SetEnabled
override void SetEnabled(bool enabled, bool animate=true)
Definition
SCR_InputButtonComponent.c:278
ServerBrowserMenuUI
Definition
ServerBrowserMenuUI.c:11
Widget
Definition
Widget.c:13
INVALID
@ INVALID
Missing components, or obstruction test was not possible.
Definition
WindingOrder.c:16
scripts
Game
UI
Menu
MultiplayerDialogUI.c
Generated by
1.17.0