Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] GameQ - wyciaganie info o serwerze
mazyl
post 9.02.2012, 22:11:39
Post #1





Grupa: Zarejestrowani
Postów: 139
Pomógł: 2
Dołączył: 2.12.2011

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post
i-skrypty.pl
post 9.02.2012, 22:26:31
Post #2





Grupa: Zarejestrowani
Postów: 65
Pomógł: 9
Dołączył: 8.02.2012

Ostrzeżenie: (0%)
-----


  1. var_dump($row['serwery'])

może tak? smile.gif
Go to the top of the page
+Quote Post
mazyl
post 9.02.2012, 22:32:00
Post #3





Grupa: Zarejestrowani
Postów: 139
Pomógł: 2
Dołączył: 2.12.2011

Ostrzeżenie: (0%)
-----


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. ?>
Go to the top of the page
+Quote Post
i-skrypty.pl
post 10.02.2012, 00:00:39
Post #4





Grupa: Zarejestrowani
Postów: 65
Pomógł: 9
Dołączył: 8.02.2012

Ostrzeżenie: (0%)
-----


  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
Go to the top of the page
+Quote Post
mazyl
post 10.02.2012, 11:41:29
Post #5





Grupa: Zarejestrowani
Postów: 139
Pomógł: 2
Dołączył: 2.12.2011

Ostrzeżenie: (0%)
-----


Probowałem tak i niestety też nie działa. co do czasu gry chyba raczej nie idzie.

a może by tak zastosobwać PQ ?
Go to the top of the page
+Quote Post
i-skrypty.pl
post 10.02.2012, 11:54:01
Post #6





Grupa: Zarejestrowani
Postów: 65
Pomógł: 9
Dołączył: 8.02.2012

Ostrzeżenie: (0%)
-----


ściągnij najnowszą wersje gameq, bo widzę, że masz starą smile.gif
Go to the top of the page
+Quote Post
mazyl
post 10.02.2012, 12:11:23
Post #7





Grupa: Zarejestrowani
Postów: 139
Pomógł: 2
Dołączył: 2.12.2011

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post
karolo_k
post 11.02.2012, 11:06:45
Post #8





Grupa: Zarejestrowani
Postów: 84
Pomógł: 5
Dołączył: 12.01.2010

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
mazyl
post 21.02.2012, 01:41:18
Post #9





Grupa: Zarejestrowani
Postów: 139
Pomógł: 2
Dołączył: 2.12.2011

Ostrzeżenie: (0%)
-----


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ć?
Go to the top of the page
+Quote Post
xxdrago
post 21.02.2012, 14:10:13
Post #10





Grupa: Zarejestrowani
Postów: 654
Pomógł: 42
Dołączył: 27.07.2010
Skąd: Jaworzno

Ostrzeżenie: (0%)
-----


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.

Ten post edytował xxdrago 21.02.2012, 14:11:41


--------------------
GG: 10972302 :)
Go to the top of the page
+Quote Post
mazyl
post 21.02.2012, 15:51:30
Post #11





Grupa: Zarejestrowani
Postów: 139
Pomógł: 2
Dołączył: 2.12.2011

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post
xxdrago
post 21.02.2012, 16:09:41
Post #12





Grupa: Zarejestrowani
Postów: 654
Pomógł: 42
Dołączył: 27.07.2010
Skąd: Jaworzno

Ostrzeżenie: (0%)
-----


Kod
$row['serwery']['max_players'];


--------------------
GG: 10972302 :)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.07.2025 - 12:02