Update.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * $Id: Update.php 06/06/2016 22:27:13 scp@Svens-iMac $
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * @package TeamSpeak3
  22. * @version 1.1.24
  23. * @author Sven 'ScP' Paulsen
  24. * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
  25. */
  26. /**
  27. * @class TeamSpeak3_Adapter_Update
  28. * @brief Provides methods to query the latest TeamSpeak 3 build numbers from the master server.
  29. */
  30. class TeamSpeak3_Adapter_Update extends TeamSpeak3_Adapter_Abstract
  31. {
  32. /**
  33. * The IPv4 address or FQDN of the TeamSpeak Systems update server.
  34. *
  35. * @var string
  36. */
  37. protected $default_host = "update.teamspeak.com";
  38. /**
  39. * The UDP port number of the TeamSpeak Systems update server.
  40. *
  41. * @var integer
  42. */
  43. protected $default_port = 17384;
  44. /**
  45. * Stores an array containing the latest build numbers (integer timestamps).
  46. *
  47. * @var array
  48. */
  49. protected $build_datetimes = null;
  50. /**
  51. * Stores an array containing the latest version strings.
  52. *
  53. * @var array
  54. */
  55. protected $version_strings = null;
  56. /**
  57. * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
  58. * server.
  59. *
  60. * @throws TeamSpeak3_Adapter_Update_Exception
  61. * @return void
  62. */
  63. public function syn()
  64. {
  65. if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host;
  66. if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port;
  67. $this->initTransport($this->options, "TeamSpeak3_Transport_UDP");
  68. $this->transport->setAdapter($this);
  69. TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
  70. $this->getTransport()->send(TeamSpeak3_Helper_String::fromHex(33));
  71. if(!preg_match_all("/,?(\d+)#([0-9a-zA-Z\._-]+),?/", $this->getTransport()->read(96), $matches) || !isset($matches[1]) || !isset($matches[2]))
  72. {
  73. throw new TeamSpeak3_Adapter_Update_Exception("invalid reply from the server");
  74. }
  75. $this->build_datetimes = $matches[1];
  76. $this->version_strings = $matches[2];
  77. TeamSpeak3_Helper_Signal::getInstance()->emit("updateConnected", $this);
  78. }
  79. /**
  80. * The TeamSpeak3_Adapter_Update destructor.
  81. *
  82. * @return void
  83. */
  84. public function __destruct()
  85. {
  86. if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
  87. {
  88. $this->getTransport()->disconnect();
  89. }
  90. }
  91. /**
  92. * Returns the current build number for a specified update channel. Note that since version
  93. * 3.0.0, the build number represents an integer timestamp. $channel must be set to one of
  94. * the following values:
  95. *
  96. * - stable
  97. * - beta
  98. * - alpha
  99. * - server
  100. *
  101. * @param string $channel
  102. * @throws TeamSpeak3_Adapter_Update_Exception
  103. * @return integer
  104. */
  105. public function getRev($channel = "stable")
  106. {
  107. switch($channel)
  108. {
  109. case "stable":
  110. return isset($this->build_datetimes[0]) ? $this->build_datetimes[0] : null;
  111. case "beta":
  112. return isset($this->build_datetimes[1]) ? $this->build_datetimes[1] : null;
  113. case "alpha":
  114. return isset($this->build_datetimes[2]) ? $this->build_datetimes[2] : null;
  115. case "server":
  116. return isset($this->build_datetimes[3]) ? $this->build_datetimes[3] : null;
  117. default:
  118. throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")");
  119. }
  120. }
  121. /**
  122. * Returns the current version string for a specified update channel. $channel must be set to
  123. * one of the following values:
  124. *
  125. * - stable
  126. * - beta
  127. * - alpha
  128. * - server
  129. *
  130. * @param string $channel
  131. * @throws TeamSpeak3_Adapter_Update_Exception
  132. * @return integer
  133. */
  134. public function getVersion($channel = "stable")
  135. {
  136. switch($channel)
  137. {
  138. case "stable":
  139. return isset($this->version_strings[0]) ? $this->version_strings[0] : null;
  140. case "beta":
  141. return isset($this->version_strings[1]) ? $this->version_strings[1] : null;
  142. case "alpha":
  143. return isset($this->version_strings[2]) ? $this->version_strings[2] : null;
  144. case "server":
  145. return isset($this->version_strings[3]) ? $this->version_strings[3] : null;
  146. default:
  147. throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")");
  148. }
  149. }
  150. /**
  151. * Alias for getRev() using the 'stable' update channel.
  152. *
  153. * @param string $channel
  154. * @return integer
  155. */
  156. public function getClientRev()
  157. {
  158. return $this->getRev("stable");
  159. }
  160. /**
  161. * Alias for getRev() using the 'server' update channel.
  162. *
  163. * @param string $channel
  164. * @return integer
  165. */
  166. public function getServerRev()
  167. {
  168. return $this->getRev("server");
  169. }
  170. /**
  171. * Alias for getVersion() using the 'stable' update channel.
  172. *
  173. * @param string $channel
  174. * @return integer
  175. */
  176. public function getClientVersion()
  177. {
  178. return $this->getVersion("stable");
  179. }
  180. /**
  181. * Alias for getVersion() using the 'server' update channel.
  182. *
  183. * @param string $channel
  184. * @return integer
  185. */
  186. public function getServerVersion()
  187. {
  188. return $this->getVersion("server");
  189. }
  190. }