Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] GameQ - wyciaganie info o serwerze
Forum PHP.pl > Forum > Przedszkole
mazyl
Witam!

mam problem z wyciaganiem informacji o serwerze CS.

  1. $ip = $serwery['ip'];
  2.  
  3. $ip2 = explode(':', $ip);
  4.  
  5. require_once "jscripts/GameQ.php";
  6. $gq = new GameQ();
  7. // IP , Port
  8. $servers['serwery'] = array('cs', $ip2[0], $ip2[1]);
  9. $results['serwer']['players']['0']['name'];
  10. $gq->addServers($servers);
  11. $gq->setOption('timeout', 200);
  12. $gq->setFilter('normalise');
  13.  
  14. $row = $gq->requestData();
  15. $mapa = $row['serwery']['gq_mapname'];
  16. $nazwa = $row['serwery']['hostname'];

gdzie:
  1. $mapa = $row['serwery']['gq_mapname'];


odpowiada nazwie mapy

a

  1. $nazwa = $row['serwery']['hostname'];

nazwie serwera.

analogicznie chcialem zrobić z informacjami

udało mi sie pobrać ilość graczy na serwerze.
niestety tylko tyle.
jak pobrać informacje czy np serwer posiada hasło, ilość czasu do końca mapy?
i-skrypty.pl
  1. var_dump($row['serwery'])

może tak? smile.gif
mazyl
z tym ze te przykłady co podałem wyzej działaja, tutaj tylko jest problem jak wyciagnać wiecej informacji.

może pokaże jeszcze

  1. <?php
  2. /**
  3.  * This file is part of GameQ.
  4.  *
  5.  * GameQ is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 3 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * GameQ is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17.  *
  18.  * $Id: halflife.php,v 1.1 2007/06/30 12:43:43 tombuskens Exp $
  19.  */
  20.  
  21.  
  22. require_once GAMEQ_BASE . 'Protocol.php';
  23.  
  24.  
  25. /**
  26.  * HalfLife Protocol
  27.  *
  28.  * @author Aidan Lister <aidan@php.net>
  29.  * @author Tom Buskens <t.buskens@deviation.nl>
  30.  * @version $Revision: 1.1 $
  31.  */
  32. class GameQ_Protocol_halflife extends GameQ_Protocol
  33. {
  34. /*
  35.   * Status
  36.   */
  37. public function infostring()
  38. {
  39. // Header
  40. if ($this->p->readInt32() !== -1
  41. or $this->p->readString() !== 'infostringresponse'
  42. or $this->p->read() !== '\\'
  43. or $this->p->readLast() !== "\x00"
  44. ) {
  45. throw new GameQ_ParsingException($this->p);
  46. }
  47.  
  48. // Rules
  49. while ($this->p->getLength()) {
  50. $this->r->add($this->p->readString('\\'), $this->p->readString('\\'));
  51. }
  52. }
  53.  
  54. public function details()
  55. {
  56. // Header
  57. $this->header('m');
  58.  
  59. // Rules
  60. $this->r->add('address', $this->p->readString());
  61. $this->r->add('hostname', $this->p->readString());
  62. $this->r->add('map', $this->p->readString());
  63. $this->r->add('gamedir', $this->p->readString());
  64. $this->r->add('gamename', $this->p->readString());
  65. $this->r->add('num_players', $this->p->readInt8());
  66. $this->r->add('max_players', $this->p->readInt8());
  67. $this->r->add('protocol', $this->p->readInt8());
  68. $this->r->add('server_type', $this->p->read());
  69. $this->r->add('server_os', $this->p->read());
  70. $this->r->add('password', $this->p->readInt8());
  71. $this->r->add('mod', $this->p->readInt8());
  72.  
  73. // These only exist when the server is running a mod
  74. if ($this->p->getLength() > 2) {
  75. $this->r->add('mod_info', $this->p->readString());
  76. $this->r->add('mod_download', $this->p->readString());
  77. $this->r->add('mod_version', $this->p->readInt32());
  78. $this->r->add('mod_size', $this->p->readInt32());
  79. $this->r->add('mod_ssonly', $this->p->readInt8());
  80. $this->r->add('mod_customdll', $this->p->readInt8());
  81. }
  82. }
  83.  
  84.  
  85. /*
  86.   * Players
  87.   */
  88. public function players()
  89. {
  90. // Header
  91. $this->header('D');
  92.  
  93. // Player count
  94. $this->r->add('num_players', $this->p->readInt8());
  95.  
  96. // Players
  97. while ($this->p->getLength()) {
  98. $this->r->addPlayer('id', $this->p->readInt8());
  99. $this->r->addPlayer('name', $this->p->readString());
  100. $this->r->addPlayer('score', $this->p->readInt32());
  101. $this->r->addPlayer('time', $this->p->readFloat32());
  102. }
  103. }
  104.  
  105.  
  106. /*
  107.   * Rules
  108.   */
  109. public function rules()
  110. {
  111. // Header
  112. $this->header('E');
  113.  
  114. // Rule count
  115. $this->r->add('num_rules', $this->p->readInt16());
  116.  
  117. // Rules
  118. while ($this->p->getLength()) {
  119. $this->r->add($this->p->readString(), $this->p->readString());
  120. }
  121. }
  122.  
  123. /**
  124.   * Header
  125.   */
  126. private function header($char)
  127. {
  128. if ($this->p->readInt32() !== -1 or $this->p->read() !== $char) {
  129. throw new GameQ_ParsingException($this->p);
  130. }
  131. }
  132.  
  133.  
  134. /*
  135.   * Join multiple packets
  136.   */
  137. public function preprocess($packets)
  138. {
  139. if (count($packets) == 1) return $packets[0];
  140.  
  141. foreach ($packets as $packet) {
  142. // Make sure it's a valid packet
  143. if (strlen($packet) < 9) {
  144. continue;
  145. }
  146.  
  147. // Get the low nibble of the 9th bit
  148. $key = substr(bin2hex($packet{8}), 0, 1);
  149.  
  150. // Strip whole header
  151. $packet = substr($packet, 9);
  152.  
  153. // Order by low nibble
  154. $result[$key] = $packet;
  155. }
  156.  
  157. return implode('', $result);
  158. }
  159. }
  160. ?>
i-skrypty.pl
  1. $row['serwery']['gq_password'];

0 - brak hasła
1 - hasło

z tym drugim nie wiem jak to zrobić, o ile w ogóle się da. Poczytaj dokumentacje smile.gif
mazyl
Probowałem tak i niestety też nie działa. co do czasu gry chyba raczej nie idzie.

a może by tak zastosobwać PQ ?
i-skrypty.pl
ściągnij najnowszą wersje gameq, bo widzę, że masz starą smile.gif
mazyl
podziałało. wielkie dzieki smile.gif

teraz jeszcze taki problem gdy mam sortowanie graczy:

  1. $gq->setFilter('sortplayers', 'score');

sortuje mi od najmniejszego do najwiekszego wyniku, jak to zrobić aby sortowało odwrotnie?
karolo_k
Zapisz graczy do tablicy a po użyj pętli, tylko nie inkrementuj a dekrementuj (czyli nie licz 1 2 3 ....) tylko (... 3 2 1) i będziesz miał odwrotnie Lkingsmiley.png
mazyl
nie zauważyłem że w gameq jest sortowanie graczy wpisane. tam tez ustawia sie jakie jakie ma ono być.

Teraz pytanie moje.

Potrzebuje takie informacje jak
Czas mapy, kasa na start, Friendly Fire.
Czy ktoś wie jak to dokładniej uzyskać?
xxdrago
http://gameq.sourceforge.net/ - pierwsze.

Ładnie ci wyjaśnię co można wyciągnąć... biggrin.gif

Kod
sciezka\gameq\GameQ\Protocol


Patrz otwierasz plik na którym stoi gra czyli w przypadku cs jest to
halflife.php



Szukasz:
  1. public function details()
  2. {
  3. // Header
  4. $this->header('m');
  5.  
  6. // Rules
  7. $this->r->add('address', $this->p->readString());
  8. $this->r->add('hostname', $this->p->readString());
  9. $this->r->add('map', $this->p->readString());
  10. $this->r->add('gamedir', $this->p->readString());
  11. $this->r->add('gamename', $this->p->readString());
  12. $this->r->add('num_players', $this->p->readInt8());
  13. $this->r->add('max_players', $this->p->readInt8());
  14. $this->r->add('protocol', $this->p->readInt8());
  15. $this->r->add('server_type', $this->p->read());
  16. $this->r->add('server_os', $this->p->read());
  17. $this->r->add('password', $this->p->readInt8());
  18. $this->r->add('mod', $this->p->readInt8());
  19.  
  20. // These only exist when the server is running a mod
  21. if ($this->p->getLength() > 2) {
  22. $this->r->add('mod_info', $this->p->readString());
  23. $this->r->add('mod_download', $this->p->readString());
  24. $this->r->add('mod_version', $this->p->readInt32());
  25. $this->r->add('mod_size', $this->p->readInt32());
  26. $this->r->add('mod_ssonly', $this->p->readInt8());
  27. $this->r->add('mod_customdll', $this->p->readInt8());
  28. }
  29. }


Gdzie:
Kod
$this->r->add('max_players', $this->p->readInt8());


I tutaj z tego wiesz , że możesz wyciągnąć max_players czy też password

Pamiętaj tą biblioteką nie da się wszystkiego.
mazyl
no dobrze. teraz takie pytanie
czy jeżeli mamy np:

  1. $this->r->add('max_players', $this->p->readInt8());

czy ja moge dopisac jakos do funkcy wyciaganie dodatkowych danych?
xxdrago
Kod
$row['serwery']['max_players'];
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.