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