Bf4.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * Battlefield 4 Protocol class
  23. *
  24. * Good place for doc status and info is http://battlelog.battlefield.com/bf4/forum/view/2955064768683911198/
  25. *
  26. * @package GameQ\Protocols
  27. * @author Austin Bischoff <[email protected]>
  28. */
  29. class Bf4 extends Bf3
  30. {
  31. /**
  32. * String name of this protocol class
  33. *
  34. * @type string
  35. */
  36. protected $name = 'bf4';
  37. /**
  38. * Longer string name of this protocol class
  39. *
  40. * @type string
  41. */
  42. protected $name_long = "Battlefield 4";
  43. /**
  44. * Handle processing details since they are different than BF3
  45. *
  46. * @param \GameQ\Buffer $buffer
  47. *
  48. * @return array
  49. */
  50. protected function processDetails(Buffer $buffer)
  51. {
  52. // Decode into items
  53. $items = $this->decode($buffer);
  54. // Set the result to a new result instance
  55. $result = new Result();
  56. // Server is always dedicated
  57. $result->add('dedicated', 1);
  58. // These are the same no matter what mode the server is in
  59. $result->add('hostname', $items[1]);
  60. $result->add('num_players', (int) $items[2]);
  61. $result->add('max_players', (int) $items[3]);
  62. $result->add('gametype', $items[4]);
  63. $result->add('map', $items[5]);
  64. $result->add('roundsplayed', (int) $items[6]);
  65. $result->add('roundstotal', (int) $items[7]);
  66. $result->add('num_teams', (int) $items[8]);
  67. // Set the current index
  68. $index_current = 9;
  69. // Pull the team count
  70. $teamCount = $result->get('num_teams');
  71. // Loop for the number of teams found, increment along the way
  72. for ($id = 1; $id <= $teamCount; $id++, $index_current++) {
  73. // Shows the tickets
  74. $result->addTeam('tickets', $items[$index_current]);
  75. // We add an id so we know which team this is
  76. $result->addTeam('id', $id);
  77. }
  78. // Get and set the rest of the data points.
  79. $result->add('targetscore', (int) $items[$index_current]);
  80. $result->add('online', 1); // Forced true, it seems $words[$index_current + 1] is always empty
  81. $result->add('ranked', (int) $items[$index_current + 2]);
  82. $result->add('punkbuster', (int) $items[$index_current + 3]);
  83. $result->add('password', (int) $items[$index_current + 4]);
  84. $result->add('uptime', (int) $items[$index_current + 5]);
  85. $result->add('roundtime', (int) $items[$index_current + 6]);
  86. $result->add('ip_port', $items[$index_current + 7]);
  87. $result->add('punkbuster_version', $items[$index_current + 8]);
  88. $result->add('join_queue', (int) $items[$index_current + 9]);
  89. $result->add('region', $items[$index_current + 10]);
  90. $result->add('pingsite', $items[$index_current + 11]);
  91. $result->add('country', $items[$index_current + 12]);
  92. //$result->add('quickmatch', (int) $items[$index_current + 13]); Supposed to be here according to R42 but is not
  93. $result->add('blaze_player_count', (int) $items[$index_current + 13]);
  94. $result->add('blaze_game_state', (int) $items[$index_current + 14]);
  95. unset($items, $index_current, $teamCount, $buffer);
  96. return $result->fetch();
  97. }
  98. }