DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ GenerateValidIP()

string ScriptedWidgetEventHandler::GenerateValidIP ( string potential_ip)
inlineprotected

Attempts to generate a valid IP address & port from the given string in format like this: "192.168.0.2:2503". If the process fails, then an empty string is returned.

См. определение в файле ServerBrowserFilterContainer.c строка 289

290 {
291 string correct_ip_format;
292
293 TStringArray array_ip_and_port = new TStringArray;
294 potential_ip.Split(":", array_ip_and_port);
295
296 string ip_entries;
297 int port;
298
299 if(array_ip_and_port.Count() > 0)
300 {
301 ip_entries = array_ip_and_port.Get(0);
302 TStringArray array_ip = new TStringArray;
303 ip_entries.Split(".", array_ip);
304
305 string ip_string;
306 int ip_entries_count = array_ip.Count();
307
308 if (ip_entries_count <= 3 || ip_entries_count > 4)
309 return "";
310
311 for (int i = 0; i < 4; i++)
312 {
313 int ip_entry = array_ip.Get(i).ToInt();
314
315 // Check if the entry is a valid number
316 if (ip_entry > 255 || ip_entry < 0)
317 ip_entry = 0;
318
319 ip_string = ip_string + ip_entry.ToString();
320
321 if (i < ip_entries_count - 1)
322 ip_string = ip_string + ".";
323 ;
324 }
325
326 correct_ip_format = ip_string;
327 }
328 else
329 {
330 ip_entries = "";
331 correct_ip_format = ip_entries;
332 }
333
334 if (correct_ip_format == "")
335 return ""; // Input string was not recognized as a valid IP address. Thus return an empty string.
336
337 // The input string was recognized as a valid IP address. Thus continue with port number.
338
339 if(array_ip_and_port.Count() > 1)
340 {
341 port = array_ip_and_port.Get(1).ToInt();
342
343 if (port > 65535 | port < 0) // max port value is 65535
344 port = 2302;
345
346
347 if (port >= 0)
348 correct_ip_format = correct_ip_format + ":" + port.ToString();
349
350 }
351 else
352 {
353 port = 2302;
354 correct_ip_format = correct_ip_format + ":" + port.ToString();
355 }
356
357 return correct_ip_format;
358 }
class array< Class T > TStringArray
proto string Get(int index)
Gets n-th character from string.
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.
void Split(string sample, out array< string > output)
Splits string into array of strings separated by 'sample'.
Определения EnString.c:396

Перекрестные ссылки string::Get(), string::Split(), string::ToString() и TStringArray.