Skip to content

Commit

Permalink
Merge pull request #109 from startersclan/fix/asp-fix-serverinfo-modu…
Browse files Browse the repository at this point in the history
…le-parsing-of-gamespy-response-and-avoid-socket-timeouts-when-possible

Fix (ASP): Fix `Serverinfo` module parsing of gamespy response and avoid socket timeouts when possible
  • Loading branch information
leojonathanoh authored Jan 29, 2023
2 parents aa51287 + 526eb2a commit 11d0b8c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/ASP/system/modules/Serverinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ protected function loadGamespyData($ip, $port)
$end = true;
}

// Smaller servers will respond with only 2 packets.
// If we got all 2 packets, and Packet 2 starts with this header, we're done. Don't need to wait for socket timeout
if ($i == 2 && stripos($Packet[2], "\x00\x10\x20\x30@splitnum\x00\x81\x01") === 0) {
$end = true;
}

// Larger servers will respond with 3 packets.
// If we got all 3 packets, and Packet 3 starts with this header, we're done. Don't need to wait for socket timeout
if ($i == 3 && stripos($Packet[3], "\x00\x10\x20\x30@splitnum\x00\x82\x02") === 0) {
$end = true;
}

$i++;
}

Expand Down Expand Up @@ -219,7 +231,12 @@ protected function loadGamespyData($ip, $port)
$players = $p3 ? substr($players,0,$p3) : substr($players,0);
$players = str_replace("\\ 0@splitnum\�","",$players);
$players = str_replace("\\ 0@splitnum\\�","",$players);
$players = str_replace("\\\x10\x20\x30@splitnum\\\x81\x01","",$players);
$players = str_replace(" 0@splitnum\\","",$players);
$players = str_replace(" 0@splitnum\\�","",$players);
$players = str_replace("\x10\x20\x30@splitnum\\\x81\x01","",$players);
$players = str_replace("\x10\x20\x30@splitnum\\\x82\x02","",$players);
// Strip the cut-off prop. E.g. '\F. Liliegren\\score\\score_\\0\0' becomes '\F. Liliegren\\score_\\0'
$players = preg_replace('/\\\\{2}[^_\\\\]+(\\\\{2}[^_\\\\]+_\\\\)/',"$1",$players);

//Parse Rules
$rule_temp = substr($rules,1);
Expand Down

0 comments on commit 11d0b8c

Please sign in to comment.