Justcause2.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. * Just Cause 2 Multiplayer Protocol Class
  23. *
  24. * Special thanks to Woet for some insight on packing
  25. *
  26. * @package GameQ\Protocols
  27. * @author Austin Bischoff <[email protected]>
  28. */
  29. class Justcause2 extends Gamespy4
  30. {
  31. /**
  32. * String name of this protocol class
  33. *
  34. * @type string
  35. */
  36. protected $name = 'justcause2';
  37. /**
  38. * Longer string name of this protocol class
  39. *
  40. * @type string
  41. */
  42. protected $name_long = "Just Cause 2 Multiplayer";
  43. /**
  44. * The client join link
  45. *
  46. * @type string
  47. */
  48. protected $join_link = "steam://connect/%s:%d/";
  49. /**
  50. * Change the packets used
  51. *
  52. * @var array
  53. */
  54. protected $packets = [
  55. self::PACKET_CHALLENGE => "\xFE\xFD\x09\x10\x20\x30\x40",
  56. self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40%s\xFF\xFF\xFF\x02",
  57. ];
  58. /**
  59. * Override the packet split
  60. *
  61. * @var string
  62. */
  63. protected $packetSplit = "/\\x00\\x00\\x00/m";
  64. /**
  65. * Normalize settings for this protocol
  66. *
  67. * @type array
  68. */
  69. protected $normalize = [
  70. 'general' => [
  71. // target => source
  72. 'dedicated' => 'dedicated',
  73. 'gametype' => 'gametype',
  74. 'hostname' => 'hostname',
  75. 'mapname' => 'mapname',
  76. 'maxplayers' => 'maxplayers',
  77. 'numplayers' => 'numplayers',
  78. 'password' => 'password',
  79. ],
  80. // Individual
  81. 'player' => [
  82. 'name' => 'name',
  83. 'ping' => 'ping',
  84. ],
  85. ];
  86. /**
  87. * Overload so we can add in some static data points
  88. *
  89. * @param Buffer $buffer
  90. * @param Result $result
  91. */
  92. protected function processDetails(Buffer &$buffer, Result &$result)
  93. {
  94. parent::processDetails($buffer, $result);
  95. // Add in map
  96. $result->add('mapname', 'Panau');
  97. $result->add('dedicated', 'true');
  98. }
  99. /**
  100. * Override the parent, this protocol is returned differently
  101. *
  102. * @param Buffer $buffer
  103. * @param Result $result
  104. *
  105. * @see Gamespy3::processPlayersAndTeams()
  106. */
  107. protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
  108. {
  109. // Loop until we run out of data
  110. while ($buffer->getLength()) {
  111. $result->addPlayer('name', $buffer->readString());
  112. $result->addPlayer('steamid', $buffer->readString());
  113. $result->addPlayer('ping', $buffer->readInt16());
  114. }
  115. }
  116. }