Ut3.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /**
  20. * Unreal Tournament 3 Protocol Class
  21. *
  22. * Note: The response from UT3 appears to not be consistent. Many times packets are incomplete or there are extra
  23. * "echoes" in the responses. This may cause issues like odd characters showing up in the keys for the player and team
  24. * array responses. Not sure much can be done about it.
  25. *
  26. * @author Austin Bischoff <[email protected]>
  27. */
  28. class Ut3 extends Gamespy3
  29. {
  30. /**
  31. * String name of this protocol class
  32. *
  33. * @type string
  34. */
  35. protected $name = 'ut3';
  36. /**
  37. * Longer string name of this protocol class
  38. *
  39. * @type string
  40. */
  41. protected $name_long = "Unreal Tournament 3";
  42. /**
  43. * Normalize settings for this protocol
  44. *
  45. * @type array
  46. */
  47. protected $normalize = [
  48. // General
  49. 'general' => [
  50. 'dedicated' => 'bIsDedicated',
  51. 'hostname' => 'hostname',
  52. 'numplayers' => 'numplayers',
  53. ],
  54. ];
  55. /**
  56. * Overload the response process so we can make some changes
  57. *
  58. * @return array
  59. */
  60. public function processResponse()
  61. {
  62. // Grab the result from the parent
  63. /** @type array $result */
  64. $result = parent::processResponse();
  65. // Move some stuff around
  66. $this->renameResult($result, 'OwningPlayerName', 'hostname');
  67. $this->renameResult($result, 'p1073741825', 'mapname');
  68. $this->renameResult($result, 'p1073741826', 'gametype');
  69. $this->renameResult($result, 'p1073741827', 'servername');
  70. $this->renameResult($result, 'p1073741828', 'custom_mutators');
  71. $this->renameResult($result, 'gamemode', 'open');
  72. $this->renameResult($result, 's32779', 'gamemode');
  73. $this->renameResult($result, 's0', 'bot_skill');
  74. $this->renameResult($result, 's6', 'pure_server');
  75. $this->renameResult($result, 's7', 'password');
  76. $this->renameResult($result, 's8', 'vs_bots');
  77. $this->renameResult($result, 's10', 'force_respawn');
  78. $this->renameResult($result, 'p268435704', 'frag_limit');
  79. $this->renameResult($result, 'p268435705', 'time_limit');
  80. $this->renameResult($result, 'p268435703', 'numbots');
  81. $this->renameResult($result, 'p268435717', 'stock_mutators');
  82. // Put custom mutators into an array
  83. if (isset($result['custom_mutators'])) {
  84. $result['custom_mutators'] = explode("\x1c", $result['custom_mutators']);
  85. }
  86. // Delete some unknown stuff
  87. $this->deleteResult($result, ['s1', 's9', 's11', 's12', 's13', 's14']);
  88. // Return the result
  89. return $result;
  90. }
  91. /**
  92. * Dirty hack to rename result entries into something more useful
  93. *
  94. * @param array $result
  95. * @param string $old
  96. * @param string $new
  97. */
  98. protected function renameResult(array &$result, $old, $new)
  99. {
  100. // Check to see if the old item is there
  101. if (isset($result[$old])) {
  102. $result[$new] = $result[$old];
  103. unset($result[$old]);
  104. }
  105. }
  106. /**
  107. * Dirty hack to delete result items
  108. *
  109. * @param array $result
  110. * @param array $array
  111. */
  112. protected function deleteResult(array &$result, array $array)
  113. {
  114. foreach ($array as $key) {
  115. unset($result[$key]);
  116. }
  117. }
  118. }