4 const string WIDGET_EDIT_IP =
"EditIP";
5 const string WIDGET_EDIT_PORT =
"EditPort";
6 const string WIDGET_CHECK_NETWORK =
"CheckboxNetwork";
8 const string DEFAULT_ADDRESS =
"127.0.0.1";
9 const string DEFAULT_PORT =
"2001";
10 const int DIRECT_JOIN_CODE_LENGTH = 10;
22 override void OnConfirm()
24 string address = GetAddress();
26 bool publicNetwork = !m_CheckNetwork.IsChecked();
28 m_OnConfirm.Invoke(address, format, publicNetwork);
40 if (!m_EditIP || !m_EditPort)
44 string sAddr = m_EditIP.GetValue();
45 if (sAddr.Length() == 0)
49 if (sAddr == DEFAULT_ADDRESS)
50 sAddr =
GetGame().GetBackendApi().GetClientLobby().GetMyIP();
53 string sPort =
string.Empty;
55 if (IsAddressValid(sAddr))
57 sPort = m_EditPort.GetValue();
58 if (sPort.Length() == 0)
62 BaseContainer gameplaySettings =
GetGame().GetGameUserSettings().GetModule(
"SCR_GameplaySettings");
65 if (IsAddressValid(sAddr))
69 gameplaySettings.Set(
"m_sLastIP", sAddr);
70 GetGame().UserSettingsChanged();
76 gameplaySettings.Set(
"m_sLastPort", sPort);
77 GetGame().UserSettingsChanged();
82 return sAddr +
":" + sPort;
93 super.OnMenuOpen(preset);
102 m_EditIP.m_OnChanged.Insert(CheckValidInput);
104 Widget focus = m_EditIP.GetRootWidget();
106 GetGame().GetWorkspace().SetFocusedWidget(focus);
114 m_EditPort.m_OnChanged.Insert(CheckValidInput);
125 BaseContainer gameplaySettings =
GetGame().GetGameUserSettings().GetModule(
"SCR_GameplaySettings");
126 if (gameplaySettings)
127 gameplaySettings.Get(
"m_sLastIP", text);
129 if (text !=
string.Empty && m_EditIP)
130 m_EditIP.SetValue(text);
134 if (gameplaySettings)
135 gameplaySettings.Get(
"m_sLastPort", port);
140 m_EditPort.SetValue(port);
142 m_EditPort.SetValue(DEFAULT_PORT);
146 CheckValidInput(m_EditIP,
string.Empty);
152 bool IsAddressValid(
string address)
155 if (address ==
string.Empty)
160 if (address.Contains(
":"))
162 int colonIndex = address.IndexOf(
":");
163 address = address.Substring(0, colonIndex);
166 array<string> values =
new array<string>();
167 address.Split(
".", values,
true);
168 int valuesCount = values.Count();
171 if (valuesCount != 4)
174 int zeroElements = 0;
176 for (
int i = 0; i < 4; i++)
182 int strLen = values[i].Length();
183 for (
int j = 0; j < strLen; j++)
186 string char = values[i].Get(j);
187 int asciiValue =
char.ToAscii();
188 if (asciiValue >= 48 && asciiValue <= 57)
194 int value = values[i].ToInt();
198 if (value >= 0 && value <= 255)
209 protected bool IsJoinCodeValid(
string text)
212 if (text.Length() != DIRECT_JOIN_CODE_LENGTH)
215 for (
int i = 0, len = text.Length(); i < len; i++)
218 if (text[i].ToInt() == 0 && text[i] !=
"0")
235 m_EditPort.SetEnabled(validAddress);
244 if (IsAddressValid(m_EditIP.GetValue()))
248 if (IsJoinCodeValid(m_EditIP.GetValue()))
255 void SetServerBrowserUI(
ServerBrowserMenuUI serverBrowserUI) { m_ServerBrowserUI = m_ServerBrowserUI; }