function lgsl_server_html($server) { if (isset($server['s'])) { foreach ($server['s'] as $key => $value) { $server['s'][$key] = lgsl_string_html($value); } } if (isset($server['e'])) { foreach ($server['e'] as $key => $value) { $value = wordwrap($value, 90, "", TRUE); // \x00\x01 PLACEHOLDER FOR <BR /> TO PREVENT IT BEING ENTITIED $value = lgsl_string_html($value); $value = str_replace("", "<br />", $value); // CHANGE PLACEHOLDER INTO ACTUALY <BR /> $server['e'][$key] = $value; } } if (isset($server['p'])) { foreach ($server['p'] as $key => $player) { @($server['p'][$key]['name'] = lgsl_string_html($player['name'])); } } return $server; }
function lgsl_query_feed(&$server, $request, $lgsl_feed_method, $lgsl_feed_url) { //---------------------------------------------------------+ $host = parse_url($lgsl_feed_url); if (!$host['path']) { exit("LGSL FEED PROBLEM: INVALID URL"); } $host_query = "?type={$server['b']['type']}&ip={$server['b']['ip']}&c_port={$server['b']['c_port']}&q_port={$server['b']['q_port']}&s_port={$server['b']['s_port']}&request={$request}&version=5.7"; if (function_exists("json_decode")) { $host_query .= function_exists("gzuncompress") ? "&format=4" : "&format=3"; } else { $host_query .= function_exists("gzuncompress") ? "&format=2" : "&format=1"; } $referrer = preg_replace("/(.*):\\/\\//i", "", $_SERVER['HTTP_HOST']) . "/{$_SERVER['SCRIPT_NAME']}"; $referrer = "http://" . str_replace("//", "/", $referrer); $referrer = $_SERVER['QUERY_STRING'] ? "{$referrer}?{$_SERVER['QUERY_STRING']}" : $referrer; //---------------------------------------------------------+ if (function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec') && $lgsl_feed_method == 1) { $lgsl_curl = curl_init(); curl_setopt($lgsl_curl, CURLOPT_HEADER, 0); curl_setopt($lgsl_curl, CURLOPT_HTTPGET, 1); curl_setopt($lgsl_curl, CURLOPT_TIMEOUT, 6); curl_setopt($lgsl_curl, CURLOPT_ENCODING, ""); curl_setopt($lgsl_curl, CURLOPT_FORBID_REUSE, 1); curl_setopt($lgsl_curl, CURLOPT_FRESH_CONNECT, 1); curl_setopt($lgsl_curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($lgsl_curl, CURLOPT_CONNECTTIMEOUT, 6); curl_setopt($lgsl_curl, CURLOPT_REFERER, $referrer); curl_setopt($lgsl_curl, CURLOPT_URL, "http://{$host['host']}{$host['path']}{$host_query}"); $http_reply = curl_exec($lgsl_curl); if (curl_error($lgsl_curl)) { $lgsl_feed_error = 1; } curl_close($lgsl_curl); } elseif (function_exists('fsockopen')) { $lgsl_fp = @fsockopen($host['host'], "80", $errno, $errstr, 6); if (!$lgsl_fp) { $lgsl_feed_error = 1; } else { stream_set_timeout($lgsl_fp, 6, 0); stream_set_blocking($lgsl_fp, TRUE); $http_send = "GET {$host['path']}{$host_query} HTTP/1.0\r\n"; $http_send .= "Host: {$host['host']}\r\n"; $http_send .= "Referer: {$referrer}\r\n"; $http_send .= "Pragma: no-cache\r\n"; $http_send .= "Cache-Control: max-age=0\r\n"; $http_send .= "Accept-Encoding: \r\n"; $http_send .= "Accept-Language: en-us,en;q=0.5\r\n"; $http_send .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"; $http_send .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"; $http_send .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.1.4) Gecko/20091028\r\n"; $http_send .= "Connection: Close\r\n\r\n"; fwrite($lgsl_fp, $http_send); $http_reply = ""; while (!feof($lgsl_fp)) { $http_chunk = fread($lgsl_fp, 4096); if ($http_chunk === "") { break; } $http_reply .= $http_chunk; } @fclose($lgsl_fp); } } else { exit("LGSL FEED PROBLEM: NO CURL OR FSOCKOPEN SUPPORT"); } //---------------------------------------------------------+ if (!$lgsl_feed_error) { if (preg_match("/_F([1-4])_(.*)_F([1-4])_/U", $http_reply, $match)) { if ($match[1] == 4 && $match[3] == 4) { $server = json_decode(gzuncompress(base64_decode($match[2])), TRUE); } elseif ($match[1] == 3 && $match[3] == 3) { $server = json_decode(base64_decode($match[2]), TRUE); } elseif ($match[1] == 2 && $match[3] == 2) { $server = unserialize(gzuncompress(base64_decode($match[2]))); } elseif ($match[1] == 1 && $match[3] == 1) { $server = unserialize(base64_decode($match[2])); } } elseif (preg_match("/_SLGSLF_(.*)_SLGSLF_/U", $http_reply, $match)) { $server = unserialize($match[1]); } else { $lgsl_feed_error = 2; } if (!$lgsl_feed_error && !$server) { $lgsl_feed_error = 3; } } //---------------------------------------------------------+ if ($lgsl_feed_error == "1") { // CONNECTION PROBLEM - FEED MAYBE TEMPORARLY OFFLINE $server['s']['name'] = "---"; $server['s']['map'] = "---"; $server['e'] = array("feed" => "Failed To Connect"); $server['p'] = array(); } elseif ($lgsl_feed_error == "2") { // NO FEED DATA - MAYBE WRONG FEED URL exit("<div style='width:100%;overflow:auto'>FEED MISSING FROM: {$host['host']}{$host['path']} RETURNED: " . lgsl_string_html($http_reply) . " :END</div>"); } elseif ($lgsl_feed_error == "3") { // UNABLE TO UNPACK FEED DATA - MAYBE ERRORS ON FEED exit("<div style='width:100%;overflow:auto'>FEED CORRUPTION FROM: {$host['host']}{$host['path']} RETURNED: " . lgsl_string_html($http_reply) . " :END</div>"); } elseif (!$server['b']['status']) { // IGNORE CACHE AND RETURN SO LOCAL CODE HANDLES THE SERVER BEING OFFLINE return FALSE; } //---------------------------------------------------------+ return TRUE; }
function lgsl_server_html($server, $word_wrap = 20) { foreach ($server as $key => $value) { $server[$key] = is_array($value) ? lgsl_server_html($value, $word_wrap) : lgsl_string_html($value, FALSE, $word_wrap); } return $server; }
} else { $output .= $lgsl_config['text']['aan']; } $output .= "\n <br />\n <br />\n </div>\n\n <div>\n <br />\n </div>"; return; } } //-----------------------------------------------------------------------------------------------------------+ $server = lgsl_query_live($type, $ip, $c_port, $q_port, $s_port, "s"); $server = lgsl_server_html($server); if (!$server['b']['status']) { $output .= "\n <div style='text-align:center;" . lgsl_bg() . "'>\n <br />\n {$lgsl_config['text']['anr']}\n <br />\n <br />\n </div>\n\n <div>\n <br />\n </div>"; return; } //-----------------------------------------------------------------------------------------------------------+ if (!empty($_POST['lgsl_submit_add'])) { $disabled = $lgsl_config['public_add'] == "2" ? "0" : "1"; $mysql_query = "INSERT INTO `{$lgsl_config['db']['prefix']}{$lgsl_config['db']['table']}` (`type`,`ip`,`c_port`,`q_port`,`s_port`,`disabled`,`cache`,`cache_time`) VALUES ('{$type}','{$ip}','{$c_port}','{$q_port}','{$s_port}','{$disabled}','','')"; $mysql_result = mysql_query($mysql_query) or die(mysql_error()); $output .= "\n <div style='text-align:center;" . lgsl_bg() . "'>\n <br />"; if ($disabled) { $output .= $lgsl_config['text']['ada']; } else { $output .= $lgsl_config['text']['adn']; } $output .= "\n <br />\n <br />\n </div>\n\n <div>\n <br />\n </div>"; return; } //-----------------------------------------------------------------------------------------------------------+ $output .= "\n <form method='post' action=''>\n <div style='text-align:center;" . lgsl_bg() . "'>\n <br />\n {$lgsl_config['text']['asc']}\n <br />\n <br />\n </div>\n\n <div>\n <br />\n </div>\n\n <table cellpadding='4' cellspacing='2' style='margin:auto; text-align:left'>\n <tr style='" . lgsl_bg() . "'> <td> <b> Name: </b> </td> <td style='white-space:nowrap'> {$server['s']['name']} </td> </tr>\n <tr style='" . lgsl_bg() . "'> <td> <b> {$lgsl_config['text']['gme']} </b> </td> <td style='white-space:nowrap'> {$server['s']['game']} </td> </tr>\n <tr style='" . lgsl_bg() . "'> <td> <b> {$lgsl_config['text']['map']} </b> </td> <td style='white-space:nowrap'> {$server['s']['map']} </td> </tr>\n <tr style='" . lgsl_bg() . "'> <td> <b> {$lgsl_config['text']['plr']} </b> </td> <td style='white-space:nowrap'> {$server['s']['players']} / {$server['s']['playersmax']} </td> </tr>\n </table>\n\n <div>\n <br />\n </div>\n\n <div style='text-align:center;" . lgsl_bg() . "'>\n <br />\n <input type='hidden' name='form_type' value='" . lgsl_string_html($type) . "' />\n <input type='hidden' name='form_ip' value='" . lgsl_string_html($ip) . "' />\n <input type='hidden' name='form_c_port' value='" . lgsl_string_html($c_port) . "' />\n <input type='hidden' name='form_q_port' value='" . lgsl_string_html($q_port) . "' />\n <input type='submit' name='lgsl_submit_add' value='{$lgsl_config['text']['aas']}' />\n <br />\n <br />\n </div>\n\n <div>\n <br />\n </div>\n\n </form>"; //------------------------------------------------------------------------------------------------------------+
$output .= "\r\n <tr>\r\n <td>\r\n <a href='" . lgsl_link($id) . "' style='text-decoration:none'>{$id}</a>\r\n </td>\r\n <td>\r\n <select name='form_type[{$id}]'>"; //---------------------------------------------------------+ foreach ($lgsl_type_list as $type => $description) { $output .= "\r\n <option " . ($type == $mysql_row['type'] ? "selected='selected'" : "") . " value='{$type}'>{$description}</option>"; } if (!isset($lgsl_type_list[$mysql_row['type']])) { $output .= "\r\n <option selected='selected' value='" . lgsl_string_html($mysql_row['type']) . "'>" . lgsl_string_html($mysql_row['type']) . "</option>"; } //---------------------------------------------------------+ $output .= "\r\n </select>\r\n </td>\r\n <td style='text-align:center'><input type='text' name='form_ip[{$id}]' value='" . lgsl_string_html($mysql_row['ip']) . "' size='15' maxlength='255' /></td>\r\n <td style='text-align:center'><input type='text' name='form_c_port[{$id}]' value='" . lgsl_string_html($mysql_row['c_port']) . "' size='5' maxlength='5' /></td>\r\n <td style='text-align:center'><input type='text' name='form_q_port[{$id}]' value='" . lgsl_string_html($mysql_row['q_port']) . "' size='5' maxlength='5' /></td>\r\n <td style='text-align:center'><input type='text' name='form_s_port[{$id}]' value='" . lgsl_string_html($mysql_row['s_port']) . "' size='5' maxlength='5' /></td>\r\n <td>\r\n <select name='form_zone[{$id}]'>"; //---------------------------------------------------------+ foreach ($zone_list as $zone) { $output .= "\r\n <option " . ($zone == $mysql_row['zone'] ? "selected='selected'" : "") . " value='{$zone}'>{$zone}</option>"; } if (!isset($zone_list[$mysql_row['zone']])) { $output .= "\r\n <option selected='selected' value='" . lgsl_string_html($mysql_row['zone']) . "'>" . lgsl_string_html($mysql_row['zone']) . "</option>"; } //---------------------------------------------------------+ //---------------------------------------------------------+ $output .= "\r\n </select>\r\n </td>\r\n <td style='text-align:center'><input type='checkbox' name='form_disabled[{$id}]' value='1' " . (empty($mysql_row['disabled']) ? "" : "checked='checked'") . " /></td>\r\n <td style='text-align:center'><input type='text' name='form_comment[{$id}]' value='{$mysql_row['comment']}' size='20' maxlength='255' /></td>\r\n </tr>"; $last_type = $mysql_row['type']; // SET LAST TYPE ( $mysql_row EXISTS ONLY WITHIN THE LOOP ) } //---------------------------------------------------------+ $id++; // NEW SERVER ID CONTINUES ON FROM LAST $output .= "\r\n <tr>\r\n <td>NEW</td>\r\n <td>\r\n <select name='form_type[{$id}]'>"; //---------------------------------------------------------+ foreach ($lgsl_type_list as $type => $description) { $output .= "\r\n <option " . ($type == $last_type ? "selected='selected'" : "") . " value='{$type}'>{$description}</option>"; }
exit("_F3_" . base64_encode(json_encode($server)) . "_F3_"); } } else { if ($format == 2 && function_exists("gzcompress")) { exit("_F2_" . base64_encode(gzcompress(serialize($server))) . "_F2_"); } else { exit("_F1_" . base64_encode(serialize($server)) . "_F1_"); } } } //------------------------------------------------------------------------------------------------------------+ // XML OUTPUT header("content-type: text/xml"); echo "<?xml version='1.0' encoding='UTF-8' ?>\r\n<server>\r\n"; foreach ($server as $a => $b) { echo "<" . lgsl_string_html($a, TRUE) . ">"; foreach ($b as $c => $d) { if (is_array($d)) { echo "<player>\r\n"; foreach ($d as $e => $f) { echo "<" . lgsl_string_html($e, TRUE) . ">" . lgsl_string_html($f, TRUE) . "</" . lgsl_string_html($e, TRUE) . ">\r\n"; } echo "</player>\r\n"; } else { echo "<" . lgsl_string_html($c, TRUE) . ">" . lgsl_string_html($d, TRUE) . "</" . lgsl_string_html($c, TRUE) . ">\r\n"; } } echo "</" . lgsl_string_html($a, TRUE) . ">\r\n"; } echo "</server>\r\n"; //------------------------------------------------------------------------------------------------------------+