TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Update.php 2/18/2012 12:42:46 scp@orilla $ 00008 * 00009 * This program is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * @package TeamSpeak3 00023 * @version 1.1.12 00024 * @author Sven 'ScP' Paulsen 00025 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 00026 */ 00027 00028 /** 00029 * @class TeamSpeak3_Adapter_Update 00030 * @brief Provides methods to query the latest TeamSpeak 3 build numbers from the master server. 00031 */ 00032 class TeamSpeak3_Adapter_Update extends TeamSpeak3_Adapter_Abstract 00033 { 00034 /** 00035 * The IPv4 address or FQDN of the TeamSpeak Systems update server. 00036 * 00037 * @var string 00038 */ 00039 protected $default_host = "update.teamspeak.com"; 00040 00041 /** 00042 * The UDP port number of the TeamSpeak Systems update server. 00043 * 00044 * @var integer 00045 */ 00046 protected $default_port = 17384; 00047 00048 /** 00049 * Stores an array containing the latest build numbers (integer timestamps). 00050 * 00051 * @var array 00052 */ 00053 protected $build_datetimes = null; 00054 00055 /** 00056 * Stores an array containing the latest version strings. 00057 * 00058 * @var array 00059 */ 00060 protected $version_strings = null; 00061 00062 /** 00063 * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 00064 * server. 00065 * 00066 * @throws TeamSpeak3_Adapter_Update_Exception 00067 * @return void 00068 */ 00069 public function syn() 00070 { 00071 if(!isset($this->options["host"]) || empty($this->options["host"])) $this->options["host"] = $this->default_host; 00072 if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port; 00073 00074 $this->initTransport($this->options, "TeamSpeak3_Transport_UDP"); 00075 $this->transport->setAdapter($this); 00076 00077 TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 00078 00079 $this->getTransport()->send(TeamSpeak3_Helper_String::fromHex(33)); 00080 00081 if(!preg_match_all("/,?(\d+)#([0-9a-zA-Z\._-]+),?/", $this->getTransport()->read(96), $matches) || !isset($matches[1]) || !isset($matches[2])) 00082 { 00083 throw new TeamSpeak3_Adapter_Update_Exception("invalid reply from the server"); 00084 } 00085 00086 $this->build_datetimes = $matches[1]; 00087 $this->version_strings = $matches[2]; 00088 00089 TeamSpeak3_Helper_Signal::getInstance()->emit("updateConnected", $this); 00090 } 00091 00092 /** 00093 * The TeamSpeak3_Adapter_Update destructor. 00094 * 00095 * @return void 00096 */ 00097 public function __destruct() 00098 { 00099 if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected()) 00100 { 00101 $this->getTransport()->disconnect(); 00102 } 00103 } 00104 00105 /** 00106 * Returns the current build number for a specified update channel. Note that since version 00107 * 3.0.0, the build number represents an integer timestamp. $channel must be set to one of 00108 * the following values: 00109 * 00110 * - stable 00111 * - beta 00112 * - alpha 00113 * - server 00114 * 00115 * @param string $channel 00116 * @throws TeamSpeak3_Adapter_Update_Exception 00117 * @return integer 00118 */ 00119 public function getRev($channel = "stable") 00120 { 00121 switch($channel) 00122 { 00123 case "stable": 00124 return isset($this->build_datetimes[0]) ? $this->build_datetimes[0] : null; 00125 00126 case "beta": 00127 return isset($this->build_datetimes[1]) ? $this->build_datetimes[1] : null; 00128 00129 case "alpha": 00130 return isset($this->build_datetimes[2]) ? $this->build_datetimes[2] : null; 00131 00132 case "server": 00133 return isset($this->build_datetimes[3]) ? $this->build_datetimes[3] : null; 00134 00135 default: 00136 throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")"); 00137 } 00138 } 00139 00140 /** 00141 * Returns the current version string for a specified update channel. $channel must be set to 00142 * one of the following values: 00143 * 00144 * - stable 00145 * - beta 00146 * - alpha 00147 * - server 00148 * 00149 * @param string $channel 00150 * @throws TeamSpeak3_Adapter_Update_Exception 00151 * @return integer 00152 */ 00153 public function getVersion($channel = "stable") 00154 { 00155 switch($channel) 00156 { 00157 case "stable": 00158 return isset($this->version_strings[0]) ? $this->version_strings[0] : null; 00159 00160 case "beta": 00161 return isset($this->version_strings[1]) ? $this->version_strings[1] : null; 00162 00163 case "alpha": 00164 return isset($this->version_strings[2]) ? $this->version_strings[2] : null; 00165 00166 case "server": 00167 return isset($this->version_strings[3]) ? $this->version_strings[3] : null; 00168 00169 default: 00170 throw new TeamSpeak3_Adapter_Update_Exception("invalid update channel identifier (" . $channel . ")"); 00171 } 00172 } 00173 00174 /** 00175 * Alias for getRev() using the 'stable' update channel. 00176 * 00177 * @param string $channel 00178 * @return integer 00179 */ 00180 public function getClientRev() 00181 { 00182 return $this->getRev("stable"); 00183 } 00184 00185 /** 00186 * Alias for getRev() using the 'server' update channel. 00187 * 00188 * @param string $channel 00189 * @return integer 00190 */ 00191 public function getServerRev() 00192 { 00193 return $this->getRev("server"); 00194 } 00195 00196 /** 00197 * Alias for getVersion() using the 'stable' update channel. 00198 * 00199 * @param string $channel 00200 * @return integer 00201 */ 00202 public function getClientVersion() 00203 { 00204 return $this->getVersion("stable"); 00205 } 00206 00207 /** 00208 * Alias for getVersion() using the 'server' update channel. 00209 * 00210 * @param string $channel 00211 * @return integer 00212 */ 00213 public function getServerVersion() 00214 { 00215 return $this->getVersion("server"); 00216 } 00217 }