Advertisement
Guest User

testexample

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