Guest User

Untitled

a guest
Mar 17th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.71 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3.  
  4.  
  5. require_once 'GameQ.php';
  6.  
  7.  
  8. // Define your servers,
  9. // see list.php for all supported games and identifiers.
  10. $servers = array(
  11.     'server 2' => array('mtasa', '94.23.59.62', 10000),
  12. );
  13.  
  14.  
  15. // Call the class, and add your servers.
  16. $gq = new GameQ();
  17. $gq->addServers($servers);
  18.  
  19.    
  20. // You can optionally specify some settings
  21. $gq->setOption('timeout', 200);
  22.  
  23.  
  24. // You can optionally specify some output filters,
  25. // these will be applied to the results obtained.
  26. $gq->setFilter('normalise');
  27. $gq->setFilter('sortplayers', 'gq_ping');
  28.  
  29. // Send requests, and parse the data
  30. $results = $gq->requestData();
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. // Some functions to print the results
  38. function print_results($results) {
  39.  
  40.     foreach ($results as $id => $data) {
  41.  
  42.         printf("<h2>%s</h2>\n", $id);
  43.         print_table($data);
  44.     }
  45.  
  46. }
  47.  
  48. function print_table($data) {
  49.  
  50.     $gqs = array('gq_online', 'gq_address', 'gq_port', 'gq_prot', 'gq_type');
  51.    
  52.  
  53.     if (!$data['gq_online']) {
  54.         printf("<p>The server did not respond within the specified time.</p>\n");
  55.         return;
  56.     }
  57.  
  58.     print("<table><thead><tr><td>Variable</td><td>Value</td></tr></thead><tbody>\n");
  59.  
  60.     foreach ($data as $key => $val) {
  61.  
  62.         if (is_array($val)) continue;
  63.  
  64.         $cls = empty($cls) ? ' class="uneven"' : '';
  65.  
  66.         if (substr($key, 0, 3) == 'gq_') {
  67.             $kcls = (in_array($key, $gqs)) ? 'always' : 'normalise';
  68.             $key = sprintf("<span class=\"key-%s\">%s</span>", $kcls, $key);
  69.         }
  70.  
  71.         printf("<tr%s><td>%s</td><td>%s</td></tr>\n", $cls, $key, $val);
  72.     }
  73.  
  74.     print("</tbody></table>\n");
  75.    
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. ?>
  86. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  87. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  88.     <head>
  89.         <title>GameQ - Example script</title>
  90.         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  91.         <style type="text/css">
  92.             * {
  93.                 font-size: 9pt;
  94.                 font-family: Verdana, sans-serif;
  95.             }
  96.             h1 {
  97.                 font-size: 12pt;
  98.             }
  99.             h2 {
  100.                 margin-top:2em;
  101.                 font-size: 10pt;
  102.             }
  103.             table {
  104.                 border: 1px solid #000;
  105.                 background-color: #DDD;
  106.                 border-spacing:1px 1px;
  107.             }
  108.             table thead {
  109.                 font-weight: bold;
  110.                 background-color: #CCC;
  111.             }
  112.             table tr.uneven td {
  113.                 background-color:#FFF;
  114.             }
  115.             table td {
  116.                 padding: 5px 8px;
  117.             }
  118.             table tbody {
  119.                 background-color: #F9F9F9;
  120.             }
  121.             .note {
  122.                 color: #333;
  123.                 font-style:italic;
  124.             }
  125.             .key-always {
  126.                 color:red;
  127.                 font-weight:bold;
  128.             }
  129.             .key-normalise {
  130.                 color:red;
  131.             }
  132.         </style>
  133.     </head>
  134.     <body>
  135.     <h1>GameQ - Example script</h1>
  136.     <div class="note">
  137.     Players are never displayed in this example. <br/>
  138.     <span class="key-always">Bold, red</span> variables are always set by gameq.
  139.     Additionally, the normal <span class="key-normalise">red</span> variables are always set when the normalise filter is enabled.<br/>
  140.     gq_online will always contain a boolean indicating if the server responded to the request.<br/>
  141.     <br/>
  142.     Click <a href="list.php">here</a> for a list of supported games.
  143.     </div>
  144. <?php
  145.     print_results($results);
  146. ?>
  147.     </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment