Warsow.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * Warsow Protocol Class
  23. *
  24. * @package GameQ\Protocols
  25. * @author Austin Bischoff <[email protected]>
  26. */
  27. class Warsow extends Quake3
  28. {
  29. /**
  30. * String name of this protocol class
  31. *
  32. * @type string
  33. */
  34. protected $name = 'warsow';
  35. /**
  36. * Longer string name of this protocol class
  37. *
  38. * @type string
  39. */
  40. protected $name_long = "Warsow";
  41. /**
  42. * The client join link
  43. *
  44. * @type string
  45. */
  46. protected $join_link = "warsow://%s:%d/";
  47. /**
  48. * Handle player info, different than quake3 base
  49. *
  50. * @param Buffer $buffer
  51. *
  52. * @return array
  53. * @throws \GameQ\Exception\Protocol
  54. */
  55. protected function processPlayers(Buffer $buffer)
  56. {
  57. // Set the result to a new result instance
  58. $result = new Result();
  59. // Loop until we are out of data
  60. while ($buffer->getLength()) {
  61. // Make a new buffer with this block
  62. $playerInfo = new Buffer($buffer->readString("\x0A"));
  63. // Add player info
  64. $result->addPlayer('frags', $playerInfo->readString("\x20"));
  65. $result->addPlayer('ping', $playerInfo->readString("\x20"));
  66. // Skip first "
  67. $playerInfo->skip(1);
  68. // Add player name, encoded
  69. $result->addPlayer('name', utf8_encode(trim(($playerInfo->readString('"')))));
  70. // Skip space
  71. $playerInfo->skip(1);
  72. // Add team
  73. $result->addPlayer('team', $playerInfo->read());
  74. // Clear
  75. unset($playerInfo);
  76. }
  77. // Clear
  78. unset($buffer);
  79. return $result->fetch();
  80. }
  81. }