crole
08/03/2007, 11h16
Le serveur ne peut pas t'envoyer les info sous un autre format ?
xml par exemple.
xml par exemple.
foreach($output['players'] AS $player)
Warning: Invalid argument supplied for foreach() in /home.10.6/fragandr/www/test/indexfull.php on line 45
setSortBy("frags"); // Sort players by Frags (supported: index, time, frags) $output = $css->status(); $wrap_template = new temp("wrapperfull"); $wrap_template->replace("net_protocol", $output['net_protocol']); $wrap_template->replace("ip", $output['ip']); $wrap_template->replace("port", $output['port']); $wrap_template->replace("skin", $output['skin']); $wrap_template->replace("hostname", $output['hostname']); $wrap_template->replace("map", strtolower($output['map'])); $wrap_template->replace("game_dir", $output['game_dir']); $wrap_template->replace("game_type", $output['game_type']); $wrap_template->replace("appid", $output['appid']); $player_status = ($output['num_players'] == $output['max_players']) ? "plein" : ""; $wrap_template->replace("player_status", $player_status); $wrap_template->replace("num_players", $output['num_players']); $wrap_template->replace("max_players", $output['max_players']); $wrap_template->replace("bot_players", $output['bot_players']); $dedicated = ($output['dedicated'] == "d") ? "Oui" : "Non"; $wrap_template->replace("dedicated", $dedicated); $server_os = ($output['server_os'] == "w") ? "Windows" : "Linux"; $wrap_template->replace("server_os", $server_os); $needpass = ($output['needpass'] == "1") ? "Oui" : "Non"; $wrap_template->replace("needpass", $needpass); $secure = ($output['secure'] == "1") ? "Oui" : "Non"; $wrap_template->replace("secure", $secure); $players_html = ""; foreach($output['players'] AS $player) { $player_template = new temp("player"); $player_template->replace("index", $player['index']); $player_template->replace("name", $player['name']); $player_template->replace("frags", $player['frags']); $player_template->replace("time", date("H:i:s", $player['time'])); $players_html .= $player_template->show(); } $wrap_template->replace("players", $players_html); $rules_html = ""; foreach($output['rules'] AS $rule => $value) { $rule_template = new temp("rule"); $rule_template->replace("rule", $rule); $rule_template->replace("value", $value); $rules_html .= $rule_template->show(); } $wrap_template->replace("rules", $rules_html); echo $wrap_template->show(); } else { $wrap_template = new temp("wrapper_empty"); echo $wrap_template->show(); } ?>
ip = $ip; $this->port = (empty($port)) ? 27015 : $port; $this->skin = $skin; $this->timeout = $timeout; } function status() { if(!$this->sock = @fsockopen("udp://".$this->ip, $this->port)) { die("Could not connect to the ."); } else { // Taz Get Challenge $challenge = "\xFF\xFF\xFF\xFF\x57"; fwrite($this->sock, $challenge); socket_set_timeout($this->sock, 1); $stringchal = fread($this->sock, 4096); // TAZ Server Info $querys[] = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00 "; // Taz Query Player $querys[] = "\xFF\xFF\xFF\xFF\x55".substr($stringchal,5,4); // Taz Query $querys[] = "\xFF\xFF\xFF\xFF\x56".substr($stringchal,5,4); foreach($querys AS $querystring) { fwrite($this->sock, $querystring); socket_set_timeout($this->sock, 1); $string = fread($this->sock, 4096); if(!empty($string)) { $this->data[] = $string; } } @fclose($this->sock); //if(empty($this->data[0])) //die("No data was returned from the query."); $this->parseStatus(); $this->parsePlayers(); $this->parseRules(); return $this->output; } } function parseStatus() { $status = $this->data[0]; $i = 5; $this->output['net_protocol'] = ord($status{$i++}); $this->output['ip'] = $this->ip; $this->output['port'] = $this->port; $this->output['skin'] = $this->skin; $this->output['hostname'] = $this->readString($status, $i); $this->output['map'] = $this->readString($status, $i); $this->output['game_dir'] = $this->readString($status, $i); $this->output['game_type'] = $this->readString($status, $i); $this->output['appid'] = ord($status{$i++}.$status{$i++}); $this->output['num_players'] = ord($status{$i++}); $this->output['max_players'] = ord($status{$i++}); $this->output['bot_players'] = ord($status{$i++}); $this->output['dedicated'] = $status{$i++}; $this->output['server_os'] = $status{$i++}; $this->output['needpass'] = ord($status{$i++}); $this->output['secure'] = ord($status{$i++}); return TRUE; } function parsePlayers() { $players = $this->data[1]; $i = 5; $num_players = ord($players{$i++}); $this->output['players'] = array(); if($num_players > 0) { for($p = 0; $p < $num_players; $p++) { if(!empty($players{$i+1})) { $this->output['players'][$p]['index'] = ord($players{$i++}); $this->output['players'][$p]['name'] = $this->readString($players, $i); $frags = unpack("L", substr($players, $i, $i+4)); $i+=4; $this->output['players'][$p]['frags'] = $frags[1]; $time = unpack("f", substr($players, $i, $i+4)); $i+=4; $time = mktime(0, 0, $time[1]); //$time = date("H:i:s", $time); $this->output['players'][$p]['time'] = $time; } } } $this->sortPlayers($this->sortBy); return TRUE; } function parseRules() { $rules = $this->data[2]; $rule = explode("\x00", $rules); $num_rules = count($rule); for($i = 6; $i < $num_rules; $i+=2) $this->output['rules'][$rule[$i-1]] = $rule[$i]; return TRUE; } function readString($string, &$i) { $begin = $i; $strlen = strlen($string); for ($i; ($i < $strlen) && ($string{$i} != chr(0)); $i++); $result = substr($string, $begin, $i-$begin); $i++; return $result; } function sortPlayers($sortvar="index") { $players = $this->output['players']; $num_players = count($players); for($i = 0; $i != $num_players; $i++) { $a = $i; $b = $num_players-1; while ($a != $b){ if ($players[$a][$sortvar] > $players[$b][$sortvar]) $b--; else $a++; } $h = $players[$i]; $players[$i] = $players[$a]; $players[$a] = $h; } $this->output['players'] = $players; return TRUE; } function setSortBy($sortvar) { $this->sortBy = $sortvar; } } ?>