Guest User

Untitled

a guest
May 11th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. <?php
  2. require __DIR__ . '/../SourceQuery/bootstrap.php';
  3.  
  4. use xPaw\SourceQuery\SourceQuery;
  5.  
  6. // Edit this ->
  7. define( 'SQ_SERVER_ADDR', '74.91.122.45' );
  8. define( 'SQ_SERVER_PORT', 28015 );
  9. define( 'SQ_TIMEOUT', 3 );
  10. define( 'SQ_ENGINE', SourceQuery::SOURCE );
  11. // Edit this <-
  12.  
  13. $Timer = MicroTime( true );
  14.  
  15. $Query = new SourceQuery( );
  16.  
  17. $Info = Array( );
  18. $Rules = Array( );
  19. $Players = Array( );
  20.  
  21. try
  22. {
  23. $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
  24. //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
  25.  
  26. $Info = $Query->GetInfo( );
  27. $Players = $Query->GetPlayers( );
  28. $Rules = $Query->GetRules( );
  29. }
  30. catch( Exception $e )
  31. {
  32. $Exception = $e;
  33. }
  34. finally
  35. {
  36. $Query->Disconnect( );
  37. }
  38.  
  39. $Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' );
  40. ?>
  41. <!DOCTYPE html>
  42. <html>
  43. <head>
  44. <meta charset="utf-8">
  45. <title>Source Query PHP Library</title>
  46.  
  47. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  48. <style type="text/css">
  49. .table {
  50. table-layout: fixed;
  51. border-top-color: #428BCA;
  52. }
  53.  
  54. .table td {
  55. overflow-x: auto;
  56. }
  57.  
  58. .table thead th {
  59. background-color: #428BCA;
  60. border-color: #428BCA !important;
  61. color: #FFF;
  62. }
  63.  
  64. .info-column {
  65. width: 120px;
  66. }
  67.  
  68. .frags-column {
  69. width: 80px;
  70. }
  71. </style>
  72. </head>
  73.  
  74. <body>
  75. <div class="jumbotron">
  76. <div class="container">
  77. <h1>Source Query PHP Library</h1>
  78.  
  79. <p class="lead">This library was created to query game server which use the Source (Steamworks) query protocol.</p>
  80.  
  81. <p>
  82. <a class="btn btn-large btn-primary" href="https://xpaw.me">Made by xPaw</a>
  83. <a class="btn btn-large btn-primary" href="https://github.com/xPaw/PHP-Source-Query">View on GitHub</a>
  84. <a class="btn btn-large btn-danger" href="https://github.com/xPaw/PHP-Source-Query/blob/master/LICENSE">LGPL v2.1</a>
  85. </p>
  86. </div>
  87. </div>
  88.  
  89. <div class="container">
  90. <?php if( isset( $Exception ) ): ?>
  91. <div class="panel panel-primary">
  92. <div class="panel-heading"><?php echo Get_Class( $Exception ); ?> at line <?php echo $Exception->getLine( ); ?></div>
  93. <p><b><?php echo htmlspecialchars( $Exception->getMessage( ) ); ?></b></p>
  94. <p><?php echo nl2br( $e->getTraceAsString(), false ); ?></p>
  95. </div>
  96. <?php else: ?>
  97. <div class="col-sm-12">
  98. <table class="table table-bordered table-striped">
  99. <thead>
  100. <tr>
  101. <th>Player <span class="label label-info"><?php echo count( $Players ); ?></span></th>
  102. <th class="frags-column">Frags</th>
  103. <th class="frags-column">Time</th>
  104. </tr>
  105. </thead>
  106. <tbody>
  107. <?php if( !empty( $Players ) ): ?>
  108. <?php foreach( $Players as $Player ): ?>
  109. <tr>
  110. <td><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></td>
  111. <td><?php echo $Player[ 'Frags' ]; ?></td>
  112. <td><?php echo $Player[ 'TimeF' ]; ?></td>
  113. </tr>
  114. <?php endforeach; ?>
  115. <?php else: ?>
  116. <tr>
  117. <td colspan="3">No players received</td>
  118. </tr>
  119. <?php endif; ?>
  120. </tbody>
  121. </table>
  122. </div>
  123. </div>
  124. <?php endif; ?>
  125. </div>
  126. </body>
  127. </html>
Advertisement
Add Comment
Please, Sign In to add comment