Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /******************************************************************\
- |* Copyright (c) by Starlex.de
- |*
- |* Visit:
- |* http://teeworlds.com
- |* http://teeworlds.de
- |* http://teeworlds-community.de
- |*
- |* Special Thanks:
- |* east - annoyingeast.info
- |* m!nus - mnus.de and teeworlds.com
- |*
- |* License:
- |* http://creativecommons.org/licenses/by-nc-sa/3.0/deed.de
- |*
- \******************************************************************/
- $masters = Array(
- "master1.teeworlds.com:8300",
- "master2.teeworlds.com:8300",
- "master3.teeworlds.com:8300",
- "master4.teeworlds.com:8300");
- foreach ($masters as $ms) {
- if($servers = get_tw_master_new($ms))
- {
- foreach ($servers as $server)
- {
- echo $server."<br>";
- }
- }
- }
- function get_tw_master_new($server) {
- $socket = stream_socket_client('udp://'.$server , $errno, $errstr, 1);
- stream_set_timeout($socket, 1);
- fwrite($socket, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xffreq2");
- $servers = Array();
- $response = fread($socket, 2048);
- if ($response)
- {
- while (strlen($response) >= 1)
- {
- $response = substr($response, 14);
- for ($i = 0; $i <= (strlen($response)-1) ; $i += 18) {
- if(substr($response, $i, 12) == str_repeat("\x00", 10)."\xff\xff")
- { // --- IPv4
- $serveraddresse = inet_ntop(substr($response, $i+12, 4));
- } else { // --- IPv6 - NOT TESTED !!!
- $serveraddresse = "[".inet_ntop(substr($response, $i, 16))."]";
- }
- // Add the Port
- $serveraddresse .= ":".strToint($response{$i+16}.$response{$i+17});
- $servers[] = $serveraddresse;
- }
- $response = fread($socket, 2048);
- }
- return $servers;
- } else {
- return FALSE;
- }
- }
- function strToint($string)
- {
- $hex = "";
- for ($i=0; $i < strlen($string); $i++)
- {
- $hex .= dechex(ord($string[$i]));
- }
- $int = hexdec($hex);
- return $int;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement