TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: TSDNS.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_TSDNS 00030 * @brief Provides methods to query a TSDNS server. 00031 */ 00032 class TeamSpeak3_Adapter_TSDNS extends TeamSpeak3_Adapter_Abstract 00033 { 00034 /** 00035 * The TCP port number used by any TSDNS server. 00036 * 00037 * @var integer 00038 */ 00039 protected $default_port = 41144; 00040 00041 /** 00042 * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 00043 * server. 00044 * 00045 * @throws TeamSpeak3_Adapter_Exception 00046 * @return void 00047 */ 00048 public function syn() 00049 { 00050 if(!isset($this->options["port"]) || empty($this->options["port"])) $this->options["port"] = $this->default_port; 00051 00052 $this->initTransport($this->options); 00053 $this->transport->setAdapter($this); 00054 00055 TeamSpeak3_Helper_Profiler::init(spl_object_hash($this)); 00056 00057 TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsConnected", $this); 00058 } 00059 00060 /** 00061 * The TeamSpeak3_Adapter_FileTransfer destructor. 00062 * 00063 * @return void 00064 */ 00065 public function __destruct() 00066 { 00067 if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected()) 00068 { 00069 $this->getTransport()->disconnect(); 00070 } 00071 } 00072 00073 /** 00074 * Queries the TSDNS server for a specified virtual hostname and returns the result. 00075 * 00076 * @param string $tsdns 00077 * @throws TeamSpeak3_Adapter_TSDNS_Exception 00078 * @return TeamSpeak3_Helper_String 00079 */ 00080 public function resolve($tsdns) 00081 { 00082 $this->getTransport()->sendLine($tsdns); 00083 $repl = $this->getTransport()->readLine(); 00084 $this->getTransport()->disconnect(); 00085 00086 if($repl->section(":", 0)->toInt() == 404) 00087 { 00088 throw new TeamSpeak3_Adapter_TSDNS_Exception("unable to resolve TSDNS hostname (" . $tsdns . ")"); 00089 } 00090 00091 TeamSpeak3_Helper_Signal::getInstance()->emit("tsdnsResolved", $tsdns, $repl); 00092 00093 return $repl; 00094 } 00095 }