Codmw2.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * Call of Duty: Modern Warfare 2 Protocol Class
  23. *
  24. * @package GameQ\Protocols
  25. * @author Wilson Jesus <>
  26. */
  27. class Codmw2 extends Quake3
  28. {
  29. /**
  30. * String name of this protocol class
  31. *
  32. * @type string
  33. */
  34. protected $name = 'codmw2';
  35. /**
  36. * Longer string name of this protocol class
  37. *
  38. * @type string
  39. */
  40. protected $name_long = "Call of Duty: Modern Warfare 2";
  41. protected function processPlayers(Buffer $buffer)
  42. {
  43. // Temporarily cache players in order to remove last
  44. $players = [];
  45. // Loop until we are out of data
  46. while ($buffer->getLength()) {
  47. // Make a new buffer with this block
  48. $playerInfo = new Buffer($buffer->readString("\x0A"));
  49. // Read player info
  50. $player = [
  51. 'frags' => $playerInfo->readString("\x20"),
  52. 'ping' => $playerInfo->readString("\x20"),
  53. ];
  54. // Skip first "
  55. $playerInfo->skip(1);
  56. // Add player name, encoded
  57. $player['name'] = utf8_encode(trim(($playerInfo->readString('"'))));
  58. // Add player
  59. $players[] = $player;
  60. }
  61. // Remove last, empty player
  62. array_pop($players);
  63. // Set the result to a new result instance
  64. $result = new Result();
  65. // Add players
  66. $result->add('players', $players);
  67. // Add Playercount
  68. $result->add('clients', count($players));
  69. // Clear
  70. unset($buffer, $players);
  71. return $result->fetch();
  72. }
  73. }