Quake4.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 Lesser 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 Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. namespace GameQ\Protocols;
  19. use GameQ\Buffer;
  20. use GameQ\Result;
  21. /**
  22. * Quake 4 Protocol Class
  23. *
  24. * @package GameQ\Protocols
  25. *
  26. * @author Wilson Jesus <>
  27. */
  28. class Quake4 extends Doom3
  29. {
  30. /**
  31. * String name of this protocol class
  32. *
  33. * @type string
  34. */
  35. protected $name = 'quake4';
  36. /**
  37. * Longer string name of this protocol class
  38. *
  39. * @type string
  40. */
  41. protected $name_long = "Quake 4";
  42. /**
  43. * Handle processing of player data
  44. *
  45. * @param \GameQ\Buffer $buffer
  46. *
  47. * @return array
  48. */
  49. protected function processPlayers(Buffer $buffer)
  50. {
  51. // Some games do not have a number of current players
  52. $playerCount = 0;
  53. // Set the result to a new result instance
  54. $result = new Result();
  55. // Parse players
  56. // Loop thru the buffer until we run out of data
  57. while (($id = $buffer->readInt8()) != 32) {
  58. // Add player info results
  59. $result->addPlayer('id', $id);
  60. $result->addPlayer('ping', $buffer->readInt16());
  61. $result->addPlayer('rate', $buffer->readInt32());
  62. // Add player name, encoded
  63. $result->addPlayer('name', utf8_encode(trim($buffer->readString())));
  64. $result->addPlayer('clantag', $buffer->readString());
  65. // Increment
  66. $playerCount++;
  67. }
  68. // Add the number of players to the result
  69. $result->add('numplayers', $playerCount);
  70. // Clear
  71. unset($buffer, $playerCount);
  72. return $result->fetch();
  73. }
  74. }