cvs: pear /Net_GameServerQuery/docs/examples example4.php example4.tpl.php example5.php example5.tpl.php
| From: | Aidan Lister | Date: | Sat, 22 Jan 2005 03:25:50 +0000 |
| Subject: | cvs: pear /Net_GameServerQuery/docs/examples example4.php example4.tpl.php example5.php example5.tpl.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-28737@lists.php.net to get a copy of this message | ||
aidan Fri Jan 21 22:25:50 2005 EDT
Added files:
/pear/Net_GameServerQuery/docs/examples example4.php
example4.tpl.php
example5.php
example5.tpl.php
Log:
Initial commits
http://cvs.php.net/co.php/pear/Net_GameServerQuery/docs/examples/example4.php?r=1.1&p=1
Index: pear/Net_GameServerQuery/docs/examples/example4.php
+++ pear/Net_GameServerQuery/docs/examples/example4.php
<html>
<head>
<title>Net_GameServerQuery Example 4: A server listing</title>
</head>
<body>
<h1>Net_GameServerQuery Example 4: A server listing</h1>
<p>This example shows how you could use Net_GameServerQuery to show a list of your favorite
servers.</p>
<?php
require_once 'Net/GameServerQuery.php';
// Add servers
$gsq = new Net_GameServerQuery;
$gsq->addServer('callofduty', 'games01.syd.optusnet.com.au',
'24020');
$gsq->addServer('callofduty', 'games01.syd.optusnet.com.au',
'24000');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24000');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24010');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24020');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24030');
$gsq->addServer('halflife', 'games12.syd.optusnet.com.au',
'24020');
$gsq->addServer('halflife', 'games06.syd.optusnet.com.au',
'24280');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22020');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22070');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22000');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22010');
// Execute
$template['results'] = $gsq->execute();
// Let the template file handle the display
require 'example4.tpl.php';
?>
</body>
</html>
http://cvs.php.net/co.php/pear/Net_GameServerQuery/docs/examples/example4.tpl.php?r=1.1&p=1
Index: pear/Net_GameServerQuery/docs/examples/example4.tpl.php
+++ pear/Net_GameServerQuery/docs/examples/example4.tpl.php
<?php
/*
* This is part of Example 5.
*
* This file handles the display of information gathered in example5.php
*/
?>
<table border="1">
<tr>
<th>Game</th>
<th>Server Name</th>
<th>Map</th>
<th>Players</th>
</tr>
<?php
foreach ($results as $result):
$status = $result['status'];
if ($status === false):
?>
<tr>
<td colspan="4">Server did not reply to request</td>
</tr>
<?php
else:
?>
<tr>
<td><?php echo $result['__gamename'];?></td>
<td><?php echo $status['hostname'];?></td>
<td><?php echo $status['map'];?></td>
<td><?php echo (int) $status['numplayers'];?> / <?php echo
(int) $status['maxplayers'];?></td>
</tr>
<?php
endif;
endforeach;
?>
</table>
</body>
</html>
http://cvs.php.net/co.php/pear/Net_GameServerQuery/docs/examples/example5.php?r=1.1&p=1
Index: pear/Net_GameServerQuery/docs/examples/example5.php
+++ pear/Net_GameServerQuery/docs/examples/example5.php
<html>
<head>
<title>Net_GameServerQuery Example 5: A more advanced server listing</title>
</head>
<body>
<h1>Net_GameServerQuery Example 5: A more advanced server listing</h1>
<p>This example, like Example 4, shows how you could use Net_GameServerQuery to show a list of
your favorite servers.</p>
<p>However, in this example, we go a little further showing the rules and players in each
server.</p>
<p>We also sort the players by kill, and the server list by the game.</p>
<?php
require_once 'Net/GameServerQuery.php';
// Add servers
$gsq = new Net_GameServerQuery;
$gsq->addServer('callofduty', 'games01.syd.optusnet.com.au',
'24020');
$gsq->addServer('callofduty', 'games01.syd.optusnet.com.au',
'24000');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24000');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24010');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24020');
$gsq->addServer('halflife', 'games07.syd.optusnet.com.au',
'24030');
$gsq->addServer('halflife', 'games12.syd.optusnet.com.au',
'24020');
$gsq->addServer('halflife', 'games06.syd.optusnet.com.au',
'24280');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22020');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22070');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22000');
$gsq->addServer('quake3', 'games02.syd.optusnet.com.au',
'22010');
// Execute
$results = $gsq->execute();
// Sort the data by the game
foreach ($results as $result) {
$data[$result['__game']][] = $result;
}
$template['data'] = $data;
// Check if we need to make additional queries
if (isset($_GET['view'])) {
$serverkey = $gsq->addServer($_GET['game'], $_GET['view'],
$_GET['port'], 'players|rules');
$result = $gsq->execute();
$template['moreinfo'] = $result[$serverkey];
}
// Let the template file handle the display
require 'example5.tpl.php';
?>
</body>
</html>
http://cvs.php.net/co.php/pear/Net_GameServerQuery/docs/examples/example5.tpl.php?r=1.1&p=1
Index: pear/Net_GameServerQuery/docs/examples/example5.tpl.php
+++ pear/Net_GameServerQuery/docs/examples/example5.tpl.php
<?php
/*
* This is part of Example 5.
*
* This file handles the display of information gathered in example5.php
*/
?>
<table border="1">
<tr>
<th>Server Name</th>
<th>Map</th>
<th>Players</th>
<th>View</th>
</tr>
<?php
$data = $template['data'];
foreach ($data as $game):
?>
<tr>
<th colspan="4"><?php echo $game[0]['__gametitle'];
?></th>
</tr>
<?php
foreach ($game as $result):
$status = $result['status'];
if ($status === false):
?>
<tr>
<td colspan="4">Server did not reply to request</td>
</tr>
<?php
else:
?>
<tr>
<td><?php echo $status['hostname'];?></td>
<td><?php echo $status['map'];?></td>
<td><?php echo (int) $status['numplayers'];?> / <?php
echo (int) $status['maxplayers'];?></td>
<td><a href="<?php
$url = $_SERVER['SCRIPT_NAME'] . '?view=' .
$result['__addr'] .
'&port=' . $result['__port'] .
'&game=' . $result['__game'];
echo $url;?>">View</a></td>
</tr>
<?php
endif;
endforeach;
endforeach;
?>
</table>
<?php
if ($template['moreinfo']):
?>
<h2>View Server</h2>
<h3>Players</h3>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<th>Nick</th>
<th>Score</th>
</tr>
<?php
$players = $template['moreinfo']['players'];
// Sort the players
$score = array();
foreach ($players as $player) {
$score[] = $player['score'];
}
array_multisort($score, SORT_DESC, SORT_NUMERIC, $players);
// List the info
foreach ($players as $player):
?>
<tr><td><?php echo
$player['name'];?></td><td><?php echo
$player['score'];?></td></tr>
<?php
endforeach;
?>
</table>
<h3>Rules</h3>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<th>Rule</th>
<th>Value</th>
</tr>
<?php
$rules = $template['moreinfo']['rules'];
foreach ($rules as $rule => $value):
?>
<tr><td><?php echo $rule;?></td><td><?php echo
$value;?></td></tr>
<?php
endforeach;
?>
</table>
<?php
endif;
?>