Server.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package TeamSpeak3
  20. * @author Sven 'ScP' Paulsen
  21. * @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
  22. */
  23. /**
  24. * @class TeamSpeak3_Node_Server
  25. * @brief Class describing a TeamSpeak 3 virtual server and all it's parameters.
  26. */
  27. class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract
  28. {
  29. /**
  30. * @ignore
  31. */
  32. protected $channelList = null;
  33. /**
  34. * @ignore
  35. */
  36. protected $clientList = null;
  37. /**
  38. * @ignore
  39. */
  40. protected $sgroupList = null;
  41. /**
  42. * @ignore
  43. */
  44. protected $cgroupList = null;
  45. /**
  46. * The TeamSpeak3_Node_Server constructor.
  47. *
  48. * @param TeamSpeak3_Node_Host $host
  49. * @param array $info
  50. * @param string $index
  51. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  52. * @return TeamSpeak3_Node_Server
  53. */
  54. public function __construct(TeamSpeak3_Node_Host $host, array $info, $index = "virtualserver_id")
  55. {
  56. $this->parent = $host;
  57. $this->nodeInfo = $info;
  58. if(!array_key_exists($index, $this->nodeInfo))
  59. {
  60. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid serverID", 0x400);
  61. }
  62. $this->nodeId = $this->nodeInfo[$index];
  63. }
  64. /**
  65. * Sends a prepared command to the server and returns the result.
  66. *
  67. * @param string $cmd
  68. * @param boolean $throw
  69. * @return TeamSpeak3_Adapter_ServerQuery_Reply
  70. */
  71. public function request($cmd, $throw = TRUE)
  72. {
  73. if($this->getId() != $this->getParent()->serverSelectedId())
  74. {
  75. $this->getParent()->serverSelect($this->getId());
  76. }
  77. return $this->getParent()->request($cmd, $throw);
  78. }
  79. /**
  80. * Returns an array filled with TeamSpeak3_Node_Channel objects.
  81. *
  82. * @param array $filter
  83. * @return array|TeamSpeak3_Node_Channel[]
  84. */
  85. public function channelList(array $filter = array())
  86. {
  87. if($this->channelList === null)
  88. {
  89. $channels = $this->request("channellist -topic -flags -voice -limits -icon -banners")->toAssocArray("cid");
  90. $this->channelList = array();
  91. foreach($channels as $cid => $channel)
  92. {
  93. $this->channelList[$cid] = new TeamSpeak3_Node_Channel($this, $channel);
  94. }
  95. $this->resetNodeList();
  96. }
  97. return $this->filterList($this->channelList, $filter);
  98. }
  99. /**
  100. * Resets the list of channels online.
  101. *
  102. * @return void
  103. */
  104. public function channelListReset()
  105. {
  106. $this->resetNodeList();
  107. $this->channelList = null;
  108. }
  109. /**
  110. * Returns the TeamSpeak3_Node_Channel object representing the default channel.
  111. *
  112. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  113. * @return TeamSpeak3_Node_Channel
  114. */
  115. public function channelGetDefault()
  116. {
  117. foreach($this->channelList() as $channel)
  118. {
  119. if($channel["channel_flag_default"]) return $channel;
  120. }
  121. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
  122. }
  123. /**
  124. * Creates a new channel using given properties and returns the new ID.
  125. *
  126. * @param array $properties
  127. * @return integer
  128. */
  129. public function channelCreate(array $properties)
  130. {
  131. $cid = $this->execute("channelcreate", $properties)->toList();
  132. $this->channelListReset();
  133. if(!isset($properties["channel_flag_permanent"]) && !isset($properties["channel_flag_semi_permanent"]))
  134. {
  135. $this->getParent()->whoamiSet("client_channel_id", $cid["cid"]);
  136. }
  137. return $cid["cid"];
  138. }
  139. /**
  140. * Deletes the channel specified by $cid.
  141. *
  142. * @param integer $cid
  143. * @param boolean $force
  144. * @return void
  145. */
  146. public function channelDelete($cid, $force = FALSE)
  147. {
  148. $this->execute("channeldelete", array("cid" => $cid, "force" => $force));
  149. $this->channelListReset();
  150. if(($cid instanceof TeamSpeak3_Node_Abstract ? $cid->getId() : $cid) == $this->whoamiGet("client_channel_id"))
  151. {
  152. $this->getParent()->whoamiReset();
  153. }
  154. }
  155. /**
  156. * Moves the channel specified by $cid to the parent channel specified with $pid.
  157. *
  158. * @param integer $cid
  159. * @param integer $pid
  160. * @param integer $order
  161. * @return void
  162. */
  163. public function channelMove($cid, $pid, $order = null)
  164. {
  165. $this->execute("channelmove", array("cid" => $cid, "cpid" => $pid, "order" => $order));
  166. $this->channelListReset();
  167. }
  168. /**
  169. * Returns TRUE if the given TeamSpeak3_Node_Channel object is a spacer.
  170. *
  171. * @param TeamSpeak3_Node_Channel $channel
  172. * @return boolean
  173. */
  174. public function channelIsSpacer(TeamSpeak3_Node_Channel $channel)
  175. {
  176. return (preg_match("/\[[^\]]*spacer[^\]]*\]/", $channel) && $channel["channel_flag_permanent"] && !$channel["pid"]) ? TRUE : FALSE;
  177. }
  178. /**
  179. * Creates a new channel spacer and returns the new ID. The first parameter $ident is used to create a
  180. * unique spacer name on the virtual server.
  181. *
  182. * @param string $ident
  183. * @param mixed $type
  184. * @param integer $align
  185. * @param integer $order
  186. * @param integer $maxclients
  187. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  188. * @return integer
  189. */
  190. public function channelSpacerCreate($ident, $type = TeamSpeak3::SPACER_SOLIDLINE, $align = TeamSpeak3::SPACER_ALIGN_REPEAT, $order = null, $maxclients = 0)
  191. {
  192. $properties = array(
  193. "channel_name_phonetic" => "channel spacer",
  194. "channel_codec" => TeamSpeak3::CODEC_OPUS_VOICE,
  195. "channel_codec_quality" => 0x00,
  196. "channel_flag_permanent" => TRUE,
  197. "channel_flag_maxclients_unlimited" => FALSE,
  198. "channel_flag_maxfamilyclients_unlimited" => FALSE,
  199. "channel_flag_maxfamilyclients_inherited" => FALSE,
  200. "channel_maxclients" => $maxclients,
  201. "channel_order" => $order,
  202. );
  203. switch($align)
  204. {
  205. case TeamSpeak3::SPACER_ALIGN_REPEAT:
  206. $properties["channel_name"] = "[*spacer" . strval($ident) . "]";
  207. break;
  208. case TeamSpeak3::SPACER_ALIGN_LEFT:
  209. $properties["channel_name"] = "[lspacer" . strval($ident) . "]";
  210. break;
  211. case TeamSpeak3::SPACER_ALIGN_RIGHT:
  212. $properties["channel_name"] = "[rspacer" . strval($ident) . "]";
  213. break;
  214. case TeamSpeak3::SPACER_ALIGN_CENTER:
  215. $properties["channel_name"] = "[cspacer" . strval($ident) . "]";
  216. break;
  217. default:
  218. throw new TeamSpeak3_Adapter_ServerQuery_Exception("missing required parameter", 0x606);
  219. break;
  220. }
  221. switch($type)
  222. {
  223. case (string) TeamSpeak3::SPACER_SOLIDLINE:
  224. $properties["channel_name"] .= "___";
  225. break;
  226. case (string) TeamSpeak3::SPACER_DASHLINE:
  227. $properties["channel_name"] .= "---";
  228. break;
  229. case (string) TeamSpeak3::SPACER_DOTLINE:
  230. $properties["channel_name"] .= "...";
  231. break;
  232. case (string) TeamSpeak3::SPACER_DASHDOTLINE:
  233. $properties["channel_name"] .= "-.-";
  234. break;
  235. case (string) TeamSpeak3::SPACER_DASHDOTDOTLINE:
  236. $properties["channel_name"] .= "-..";
  237. break;
  238. default:
  239. $properties["channel_name"] .= strval($type);
  240. break;
  241. }
  242. return $this->channelCreate($properties);
  243. }
  244. /**
  245. * Returns the possible type of a channel spacer.
  246. *
  247. * @param integer $cid
  248. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  249. * @return integer
  250. */
  251. public function channelSpacerGetType($cid)
  252. {
  253. $channel = $this->channelGetById($cid);
  254. if(!$this->channelIsSpacer($channel))
  255. {
  256. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
  257. }
  258. switch($channel["channel_name"]->section("]", 1))
  259. {
  260. case "___":
  261. return TeamSpeak3::SPACER_SOLIDLINE;
  262. case "---":
  263. return TeamSpeak3::SPACER_DASHLINE;
  264. case "...":
  265. return TeamSpeak3::SPACER_DOTLINE;
  266. case "-.-":
  267. return TeamSpeak3::SPACER_DASHDOTLINE;
  268. case "-..":
  269. return TeamSpeak3::SPACER_DASHDOTDOTLINE;
  270. default:
  271. return TeamSpeak3::SPACER_CUSTOM;
  272. }
  273. }
  274. /**
  275. * Returns the possible alignment of a channel spacer.
  276. *
  277. * @param integer $cid
  278. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  279. * @return integer
  280. */
  281. public function channelSpacerGetAlign($cid)
  282. {
  283. $channel = $this->channelGetById($cid);
  284. if(!$this->channelIsSpacer($channel) || !preg_match("/\[(.*)spacer.*\]/", $channel, $matches) || !isset($matches[1]))
  285. {
  286. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channel flags", 0x307);
  287. }
  288. switch($matches[1])
  289. {
  290. case "*":
  291. return TeamSpeak3::SPACER_ALIGN_REPEAT;
  292. case "c":
  293. return TeamSpeak3::SPACER_ALIGN_CENTER;
  294. case "r":
  295. return TeamSpeak3::SPACER_ALIGN_RIGHT;
  296. default:
  297. return TeamSpeak3::SPACER_ALIGN_LEFT;
  298. }
  299. }
  300. /**
  301. * Returns a list of permissions defined for a specific channel.
  302. *
  303. * @param integer $cid
  304. * @param boolean $permsid
  305. * @return array
  306. */
  307. public function channelPermList($cid, $permsid = FALSE)
  308. {
  309. return $this->execute("channelpermlist", array("cid" => $cid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
  310. }
  311. /**
  312. * Adds a set of specified permissions to a channel. Multiple permissions can be added by
  313. * providing the two parameters of each permission.
  314. *
  315. * @param integer $cid
  316. * @param integer $permid
  317. * @param integer $permvalue
  318. * @return void
  319. */
  320. public function channelPermAssign($cid, $permid, $permvalue)
  321. {
  322. if(!is_array($permid))
  323. {
  324. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  325. }
  326. else
  327. {
  328. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  329. }
  330. $this->execute("channeladdperm", array("cid" => $cid, $permident => $permid, "permvalue" => $permvalue));
  331. }
  332. /**
  333. * Removes a set of specified permissions from a channel. Multiple permissions can be removed at once.
  334. *
  335. * @param integer $cid
  336. * @param integer $permid
  337. * @return void
  338. */
  339. public function channelPermRemove($cid, $permid)
  340. {
  341. if(!is_array($permid))
  342. {
  343. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  344. }
  345. else
  346. {
  347. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  348. }
  349. $this->execute("channeldelperm", array("cid" => $cid, $permident => $permid));
  350. }
  351. /**
  352. * Returns a list of permissions defined for a client in a specific channel.
  353. *
  354. * @param integer $cid
  355. * @param integer $cldbid
  356. * @param boolean $permsid
  357. * @return array
  358. */
  359. public function channelClientPermList($cid, $cldbid, $permsid = FALSE)
  360. {
  361. return $this->execute("channelclientpermlist", array("cid" => $cid, "cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
  362. }
  363. /**
  364. * Adds a set of specified permissions to a client in a specific channel. Multiple permissions can be added by
  365. * providing the two parameters of each permission.
  366. *
  367. * @param integer $cid
  368. * @param integer $cldbid
  369. * @param integer $permid
  370. * @param integer $permvalue
  371. * @return void
  372. */
  373. public function channelClientPermAssign($cid, $cldbid, $permid, $permvalue)
  374. {
  375. if(!is_array($permid))
  376. {
  377. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  378. }
  379. else
  380. {
  381. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  382. }
  383. $this->execute("channelclientaddperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue));
  384. }
  385. /**
  386. * Removes a set of specified permissions from a client in a specific channel. Multiple permissions can be removed at once.
  387. *
  388. * @param integer $cid
  389. * @param integer $cldbid
  390. * @param integer $permid
  391. * @return void
  392. */
  393. public function channelClientPermRemove($cid, $cldbid, $permid)
  394. {
  395. if(!is_array($permid))
  396. {
  397. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  398. }
  399. else
  400. {
  401. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  402. }
  403. $this->execute("channelclientdelperm", array("cid" => $cid, "cldbid" => $cldbid, $permident => $permid));
  404. }
  405. /**
  406. * Returns a list of files and directories stored in the specified channels file repository.
  407. *
  408. * @param integer $cid
  409. * @param string $cpw
  410. * @param string $path
  411. * @param boolean $recursive
  412. * @return array
  413. */
  414. public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE)
  415. {
  416. $files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray();
  417. $count = count($files);
  418. for($i = 0; $i < $count; $i++)
  419. {
  420. $files[$i]["sid"] = $this->getId();
  421. $files[$i]["cid"] = $files[0]["cid"];
  422. $files[$i]["path"] = $files[0]["path"];
  423. $files[$i]["src"] = new TeamSpeak3_Helper_String($cid ? $files[$i]["path"] : "/");
  424. if(!$files[$i]["src"]->endsWith("/"))
  425. {
  426. $files[$i]["src"]->append("/");
  427. }
  428. $files[$i]["src"]->append($files[$i]["name"]);
  429. if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY)
  430. {
  431. $files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive));
  432. }
  433. }
  434. uasort($files, array(__CLASS__, "sortFileList"));
  435. return $files;
  436. }
  437. /**
  438. * Returns detailed information about the specified file stored in a channels file repository.
  439. *
  440. * @param integer $cid
  441. * @param string $cpw
  442. * @param string $name
  443. * @return array
  444. */
  445. public function channelFileInfo($cid, $cpw = "", $name = "/")
  446. {
  447. $info = $this->execute("ftgetfileinfo", array("cid" => $cid, "cpw" => $cpw, "name" => $name))->toArray();
  448. return array_pop($info);
  449. }
  450. /**
  451. * Renames a file in a channels file repository. If the two parameters $tcid and $tcpw are specified, the file
  452. * will be moved into another channels file repository.
  453. *
  454. * @param integer $cid
  455. * @param string $cpw
  456. * @param string $oldname
  457. * @param string $newname
  458. * @param integer $tcid
  459. * @param string $tcpw
  460. * @return void
  461. */
  462. public function channelFileRename($cid, $cpw = "", $oldname = "/", $newname = "/", $tcid = null, $tcpw = null)
  463. {
  464. $this->execute("ftrenamefile", array("cid" => $cid, "cpw" => $cpw, "oldname" => $oldname, "newname" => $newname, "tcid" => $tcid, "tcpw" => $tcpw));
  465. }
  466. /**
  467. * Deletes one or more files stored in a channels file repository.
  468. *
  469. * @param integer $cid
  470. * @param string $cpw
  471. * @param string $name
  472. * @return void
  473. */
  474. public function channelFileDelete($cid, $cpw = "", $name = "/")
  475. {
  476. $this->execute("ftdeletefile", array("cid" => $cid, "cpw" => $cpw, "name" => $name));
  477. }
  478. /**
  479. * Creates new directory in a channels file repository.
  480. *
  481. * @param integer $cid
  482. * @param string $cpw
  483. * @param string $dirname
  484. * @return void
  485. */
  486. public function channelDirCreate($cid, $cpw = "", $dirname = "/")
  487. {
  488. $this->execute("ftcreatedir", array("cid" => $cid, "cpw" => $cpw, "dirname" => $dirname));
  489. }
  490. /**
  491. * Returns the level of a channel.
  492. *
  493. * @param integer $cid
  494. * @return integer
  495. */
  496. public function channelGetLevel($cid)
  497. {
  498. $channel = $this->channelGetById($cid);
  499. $levelno = 0;
  500. if($channel["pid"])
  501. {
  502. $levelno = $this->channelGetLevel($channel["pid"])+1;
  503. }
  504. return $levelno;
  505. }
  506. /**
  507. * Returns the pathway of a channel which can be used as a clients default channel.
  508. *
  509. * @param integer $cid
  510. * @return string
  511. */
  512. public function channelGetPathway($cid)
  513. {
  514. $channel = $this->channelGetById($cid);
  515. $pathway = $channel["channel_name"];
  516. if($channel["pid"])
  517. {
  518. $pathway = $this->channelGetPathway($channel["pid"]) . "/" . $channel["channel_name"];
  519. }
  520. return $pathway;
  521. }
  522. /**
  523. * Returns the TeamSpeak3_Node_Channel object matching the given ID.
  524. *
  525. * @param integer $cid
  526. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  527. * @return TeamSpeak3_Node_Channel
  528. */
  529. public function channelGetById($cid)
  530. {
  531. if(!array_key_exists((string) $cid, $this->channelList()))
  532. {
  533. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
  534. }
  535. return $this->channelList[intval((string) $cid)];
  536. }
  537. /**
  538. * Returns the TeamSpeak3_Node_Channel object matching the given name.
  539. *
  540. * @param string $name
  541. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  542. * @return TeamSpeak3_Node_Channel
  543. */
  544. public function channelGetByName($name)
  545. {
  546. foreach($this->channelList() as $channel)
  547. {
  548. if($channel["channel_name"] == $name) return $channel;
  549. }
  550. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid channelID", 0x300);
  551. }
  552. /**
  553. * Returns an array filled with TeamSpeak3_Node_Client objects.
  554. *
  555. * @param array $filter
  556. * @return array|TeamSpeak3_Node_Client[]
  557. */
  558. public function clientList(array $filter = array())
  559. {
  560. if($this->clientList === null)
  561. {
  562. $clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid");
  563. $this->clientList = array();
  564. foreach($clients as $clid => $client)
  565. {
  566. if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue;
  567. $this->clientList[$clid] = new TeamSpeak3_Node_Client($this, $client);
  568. }
  569. uasort($this->clientList, array(__CLASS__, "sortClientList"));
  570. $this->resetNodeList();
  571. }
  572. return $this->filterList($this->clientList, $filter);
  573. }
  574. /**
  575. * Resets the list of clients online.
  576. *
  577. * @return void
  578. */
  579. public function clientListReset()
  580. {
  581. $this->resetNodeList();
  582. $this->clientList = null;
  583. }
  584. /**
  585. * Returns a list of clients matching a given name pattern.
  586. *
  587. * @param string $pattern
  588. * @return array
  589. */
  590. public function clientFind($pattern)
  591. {
  592. return $this->execute("clientfind", array("pattern" => $pattern))->toAssocArray("clid");
  593. }
  594. /**
  595. * Returns a list of client identities known by the virtual server. By default, the server spits out 25 entries
  596. * at once.
  597. *
  598. * @param integer $offset
  599. * @param integer $limit
  600. * @return array
  601. */
  602. public function clientListDb($offset = null, $limit = null)
  603. {
  604. return $this->execute("clientdblist -count", array("start" => $offset, "duration" => $limit))->toAssocArray("cldbid");
  605. }
  606. /**
  607. * Returns the number of client identities known by the virtual server.
  608. *
  609. * @return integer
  610. */
  611. public function clientCountDb()
  612. {
  613. return current($this->execute("clientdblist -count", array("duration" => 1))->toList("count"));
  614. }
  615. /**
  616. * Returns a list of properties from the database for the client specified by $cldbid.
  617. *
  618. * @param integer $cldbid
  619. * @return array
  620. */
  621. public function clientInfoDb($cldbid)
  622. {
  623. return $this->execute("clientdbinfo", array("cldbid" => $cldbid))->toList();
  624. }
  625. /**
  626. * Returns a list of client database information matching a given pattern. You can either search for a clients
  627. * last known nickname or his unique identity by using the $uid option.
  628. *
  629. * @param string $pattern
  630. * @param boolean $uid
  631. * @return array
  632. */
  633. public function clientFindDb($pattern, $uid = FALSE)
  634. {
  635. return array_keys($this->execute("clientdbfind", array("pattern" => $pattern, ($uid) ? "-uid" : null, "-details"))->toAssocArray("cldbid"));
  636. }
  637. /**
  638. * Returns the number of regular clients online.
  639. *
  640. * @return integer
  641. */
  642. public function clientCount()
  643. {
  644. if($this->isOffline()) return 0;
  645. return $this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"];
  646. }
  647. /**
  648. * Returns the TeamSpeak3_Node_Client object matching the given ID.
  649. *
  650. * @param integer $clid
  651. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  652. * @return TeamSpeak3_Node_Client
  653. */
  654. public function clientGetById($clid)
  655. {
  656. if(!array_key_exists((string) $clid, $this->clientList()))
  657. {
  658. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
  659. }
  660. return $this->clientList[intval((string) $clid)];
  661. }
  662. /**
  663. * Returns the TeamSpeak3_Node_Client object matching the given name.
  664. *
  665. * @param string $name
  666. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  667. * @return TeamSpeak3_Node_Client
  668. */
  669. public function clientGetByName($name)
  670. {
  671. foreach($this->clientList() as $client)
  672. {
  673. if($client["client_nickname"] == $name) return $client;
  674. }
  675. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
  676. }
  677. /**
  678. * Returns the TeamSpeak3_Node_Client object matching the given unique identifier.
  679. *
  680. * @param string $uid
  681. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  682. * @return TeamSpeak3_Node_Client
  683. */
  684. public function clientGetByUid($uid)
  685. {
  686. foreach($this->clientList() as $client)
  687. {
  688. if($client["client_unique_identifier"] == $uid) return $client;
  689. }
  690. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
  691. }
  692. /**
  693. * Returns the TeamSpeak3_Node_Client object matching the given database ID.
  694. *
  695. * @param integer $dbid
  696. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  697. * @return TeamSpeak3_Node_Client
  698. */
  699. public function clientGetByDbid($dbid)
  700. {
  701. foreach($this->clientList() as $client)
  702. {
  703. if($client["client_database_id"] == $dbid) return $client;
  704. }
  705. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid clientID", 0x200);
  706. }
  707. /**
  708. * Returns an array containing the last known nickname and the database ID of the client matching
  709. * the unique identifier specified with $cluid.
  710. *
  711. * @param string $cluid
  712. * @return array
  713. */
  714. public function clientGetNameByUid($cluid)
  715. {
  716. return $this->execute("clientgetnamefromuid", array("cluid" => $cluid))->toList();
  717. }
  718. /**
  719. * Returns an array containing a list of active client connections using the unique identifier
  720. * specified with $cluid.
  721. *
  722. * @param string $cluid
  723. * @return array
  724. */
  725. public function clientGetIdsByUid($cluid)
  726. {
  727. return $this->execute("clientgetids", array("cluid" => $cluid))->toAssocArray("clid");
  728. }
  729. /**
  730. * Returns an array containing the last known nickname and the unique identifier of the client
  731. * matching the database ID specified with $cldbid.
  732. *
  733. * @param string $cldbid
  734. * @return array
  735. */
  736. public function clientGetNameByDbid($cldbid)
  737. {
  738. return $this->execute("clientgetnamefromdbid", array("cldbid" => $cldbid))->toList();
  739. }
  740. /**
  741. * Returns an array containing the names and IDs of all server groups the client specified with
  742. * $cldbid is is currently residing in.
  743. *
  744. * @param string $cldbid
  745. * @return array
  746. */
  747. public function clientGetServerGroupsByDbid($cldbid)
  748. {
  749. return $this->execute("servergroupsbyclientid", array("cldbid" => $cldbid))->toAssocArray("sgid");
  750. }
  751. /**
  752. * Moves a client to another channel.
  753. *
  754. * @param integer $clid
  755. * @param integer $cid
  756. * @param string $cpw
  757. * @return void
  758. */
  759. public function clientMove($clid, $cid, $cpw = null)
  760. {
  761. $this->clientListReset();
  762. $this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw));
  763. if($clid instanceof TeamSpeak3_Node_Abstract)
  764. {
  765. $clid = $clid->getId();
  766. }
  767. if($cid instanceof TeamSpeak3_Node_Abstract)
  768. {
  769. $cid = $cid->getId();
  770. }
  771. if(!is_array($clid) && $clid == $this->whoamiGet("client_id"))
  772. {
  773. $this->getParent()->whoamiSet("client_channel_id", $cid);
  774. }
  775. }
  776. /**
  777. * Kicks one or more clients from their currently joined channel or from the server.
  778. *
  779. * @param integer $clid
  780. * @param integer $reasonid
  781. * @param string $reasonmsg
  782. * @return void
  783. */
  784. public function clientKick($clid, $reasonid = TeamSpeak3::KICK_CHANNEL, $reasonmsg = null)
  785. {
  786. $this->clientListReset();
  787. $this->execute("clientkick", array("clid" => $clid, "reasonid" => $reasonid, "reasonmsg" => $reasonmsg));
  788. }
  789. /**
  790. * Sends a poke message to a client.
  791. *
  792. * @param integer $clid
  793. * @param string $msg
  794. * @return void
  795. */
  796. public function clientPoke($clid, $msg)
  797. {
  798. $this->execute("clientpoke", array("clid" => $clid, "msg" => $msg));
  799. }
  800. /**
  801. * Bans the client specified with ID $clid from the server. Please note that this will create three separate
  802. * ban rules for the targeted clients IP address, the unique identifier and the myTeamSpeak ID (if available).
  803. *
  804. * @param integer $clid
  805. * @param integer $timeseconds
  806. * @param string $reason
  807. * @return array
  808. */
  809. public function clientBan($clid, $timeseconds = null, $reason = null)
  810. {
  811. $this->clientListReset();
  812. $bans = $this->execute("banclient", array("clid" => $clid, "time" => $timeseconds, "banreason" => $reason))->toAssocArray("banid");
  813. return array_keys($bans);
  814. }
  815. /**
  816. * Changes the clients properties using given properties.
  817. *
  818. * @param string $cldbid
  819. * @param array $properties
  820. * @return void
  821. */
  822. public function clientModifyDb($cldbid, array $properties)
  823. {
  824. $properties["cldbid"] = $cldbid;
  825. $this->execute("clientdbedit", $properties);
  826. }
  827. /**
  828. * Deletes a clients properties from the database.
  829. *
  830. * @param string $cldbid
  831. * @return void
  832. */
  833. public function clientDeleteDb($cldbid)
  834. {
  835. $this->execute("clientdbdelete", array("cldbid" => $cldbid));
  836. }
  837. /**
  838. * Sets the channel group of a client to the ID specified.
  839. *
  840. * @param integer $cldbid
  841. * @param integer $cid
  842. * @param integer $cgid
  843. * @return void
  844. */
  845. public function clientSetChannelGroup($cldbid, $cid, $cgid)
  846. {
  847. $this->execute("setclientchannelgroup", array("cldbid" => $cldbid, "cid" => $cid, "cgid" => $cgid));
  848. }
  849. /**
  850. * Returns a list of permissions defined for a client.
  851. *
  852. * @param integer $cldbid
  853. * @param boolean $permsid
  854. * @return array
  855. */
  856. public function clientPermList($cldbid, $permsid = FALSE)
  857. {
  858. $this->clientListReset();
  859. return $this->execute("clientpermlist", array("cldbid" => $cldbid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
  860. }
  861. /**
  862. * Adds a set of specified permissions to a client. Multiple permissions can be added by providing
  863. * the three parameters of each permission.
  864. *
  865. * @param integer $cldbid
  866. * @param integer $permid
  867. * @param integer $permvalue
  868. * @param integer $permskip
  869. * @return void
  870. */
  871. public function clientPermAssign($cldbid, $permid, $permvalue, $permskip = FALSE)
  872. {
  873. if(!is_array($permid))
  874. {
  875. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  876. }
  877. else
  878. {
  879. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  880. }
  881. $this->execute("clientaddperm -continueonerror", array("cldbid" => $cldbid, $permident => $permid, "permvalue" => $permvalue, "permskip" => $permskip));
  882. }
  883. /**
  884. * Removes a set of specified permissions from a client. Multiple permissions can be removed at once.
  885. *
  886. * @param integer $cldbid
  887. * @param integer $permid
  888. * @return void
  889. */
  890. public function clientPermRemove($cldbid, $permid)
  891. {
  892. if(!is_array($permid))
  893. {
  894. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  895. }
  896. else
  897. {
  898. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  899. }
  900. $this->execute("clientdelperm", array("cldbid" => $cldbid, $permident => $permid));
  901. }
  902. /**
  903. * Returns a list of server groups available.
  904. *
  905. * @param filter $filter
  906. * @return array|TeamSpeak3_Node_Servergroup[]
  907. */
  908. public function serverGroupList(array $filter = array())
  909. {
  910. if($this->sgroupList === null)
  911. {
  912. $this->sgroupList = $this->request("servergrouplist")->toAssocArray("sgid");
  913. foreach($this->sgroupList as $sgid => $group)
  914. {
  915. $this->sgroupList[$sgid] = new TeamSpeak3_Node_Servergroup($this, $group);
  916. }
  917. uasort($this->sgroupList, array(__CLASS__, "sortGroupList"));
  918. }
  919. return $this->filterList($this->sgroupList, $filter);
  920. }
  921. /**
  922. * Resets the list of server groups.
  923. *
  924. * @return void
  925. */
  926. public function serverGroupListReset()
  927. {
  928. $this->sgroupList = null;
  929. }
  930. /**
  931. * Creates a new server group using the name specified with $name and returns its ID.
  932. *
  933. * @param string $name
  934. * @param integer $type
  935. * @return integer
  936. */
  937. public function serverGroupCreate($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  938. {
  939. $this->serverGroupListReset();
  940. $sgid = $this->execute("servergroupadd", array("name" => $name, "type" => $type))->toList();
  941. return $sgid["sgid"];
  942. }
  943. /**
  944. * Creates a copy of an existing server group specified by $ssgid and returns the new groups ID.
  945. *
  946. * @param integer $ssgid
  947. * @param string $name
  948. * @param integer $tsgid
  949. * @param integer $type
  950. * @return integer
  951. */
  952. public function serverGroupCopy($ssgid, $name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  953. {
  954. $this->serverGroupListReset();
  955. $sgid = $this->execute("servergroupcopy", array("ssgid" => $ssgid, "tsgid" => $tsgid, "name" => $name, "type" => $type))->toList();
  956. if($tsgid && $name)
  957. {
  958. $this->serverGroupRename($tsgid, $name);
  959. }
  960. return count($sgid) ? $sgid["sgid"] : intval($tsgid);
  961. }
  962. /**
  963. * Renames the server group specified with $sgid.
  964. *
  965. * @param integer $sgid
  966. * @param string $name
  967. * @return void
  968. */
  969. public function serverGroupRename($sgid, $name)
  970. {
  971. $this->serverGroupListReset();
  972. $this->execute("servergrouprename", array("sgid" => $sgid, "name" => $name));
  973. }
  974. /**
  975. * Deletes the server group specified with $sgid. If $force is set to 1, the server group
  976. * will be deleted even if there are clients within.
  977. *
  978. * @param integer $sgid
  979. * @param boolean $force
  980. * @return void
  981. */
  982. public function serverGroupDelete($sgid, $force = FALSE)
  983. {
  984. $this->serverGroupListReset();
  985. $this->execute("servergroupdel", array("sgid" => $sgid, "force" => $force));
  986. }
  987. /**
  988. * Returns the TeamSpeak3_Node_Servergroup object matching the given ID.
  989. *
  990. * @param integer $sgid
  991. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  992. * @return TeamSpeak3_Node_Servergroup
  993. */
  994. public function serverGroupGetById($sgid)
  995. {
  996. if(!array_key_exists((string) $sgid, $this->serverGroupList()))
  997. {
  998. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
  999. }
  1000. return $this->sgroupList[intval((string) $sgid)];
  1001. }
  1002. /**
  1003. * Returns the TeamSpeak3_Node_Servergroup object matching the given name.
  1004. *
  1005. * @param string $name
  1006. * @param integer $type
  1007. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  1008. * @return TeamSpeak3_Node_Servergroup
  1009. */
  1010. public function serverGroupGetByName($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  1011. {
  1012. foreach($this->serverGroupList() as $group)
  1013. {
  1014. if($group["name"] == $name && $group["type"] == $type) return $group;
  1015. }
  1016. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
  1017. }
  1018. /**
  1019. * Returns a list of permissions assigned to the server group specified.
  1020. *
  1021. * @param integer $sgid
  1022. * @param boolean $permsid
  1023. * @return array
  1024. */
  1025. public function serverGroupPermList($sgid, $permsid = FALSE)
  1026. {
  1027. return $this->execute("servergrouppermlist", array("sgid" => $sgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
  1028. }
  1029. /**
  1030. * Adds a set of specified permissions to the server group specified. Multiple permissions
  1031. * can be added by providing the four parameters of each permission in separate arrays.
  1032. *
  1033. * @param integer $sgid
  1034. * @param integer $permid
  1035. * @param integer $permvalue
  1036. * @param integer $permnegated
  1037. * @param integer $permskip
  1038. * @return void
  1039. */
  1040. public function serverGroupPermAssign($sgid, $permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
  1041. {
  1042. if(!is_array($permid))
  1043. {
  1044. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  1045. }
  1046. else
  1047. {
  1048. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  1049. }
  1050. $this->execute("servergroupaddperm", array("sgid" => $sgid, $permident => $permid, "permvalue" => $permvalue, "permnegated" => $permnegated, "permskip" => $permskip));
  1051. }
  1052. /**
  1053. * Removes a set of specified permissions from the server group specified with $sgid. Multiple
  1054. * permissions can be removed at once.
  1055. *
  1056. * @param integer $sgid
  1057. * @param integer $permid
  1058. * @return void
  1059. */
  1060. public function serverGroupPermRemove($sgid, $permid)
  1061. {
  1062. if(!is_array($permid))
  1063. {
  1064. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  1065. }
  1066. else
  1067. {
  1068. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  1069. }
  1070. $this->execute("servergroupdelperm", array("sgid" => $sgid, $permident => $permid));
  1071. }
  1072. /**
  1073. * Returns a list of clients assigned to the server group specified.
  1074. *
  1075. * @param integer $sgid
  1076. * @return array
  1077. */
  1078. public function serverGroupClientList($sgid)
  1079. {
  1080. if($this["virtualserver_default_server_group"] == $sgid)
  1081. {
  1082. return array();
  1083. }
  1084. return $this->execute("servergroupclientlist", array("sgid" => $sgid, "-names"))->toAssocArray("cldbid");
  1085. }
  1086. /**
  1087. * Adds a client to the server group specified. Please note that a client cannot be
  1088. * added to default groups or template groups.
  1089. *
  1090. * @param integer $sgid
  1091. * @param integer $cldbid
  1092. * @return void
  1093. */
  1094. public function serverGroupClientAdd($sgid, $cldbid)
  1095. {
  1096. $this->clientListReset();
  1097. $this->execute("servergroupaddclient", array("sgid" => $sgid, "cldbid" => $cldbid));
  1098. }
  1099. /**
  1100. * Removes a client from the server group specified.
  1101. *
  1102. * @param integer $sgid
  1103. * @param integer $cldbid
  1104. * @return void
  1105. */
  1106. public function serverGroupClientDel($sgid, $cldbid)
  1107. {
  1108. $this->execute("servergroupdelclient", array("sgid" => $sgid, "cldbid" => $cldbid));
  1109. }
  1110. /**
  1111. * Returns an ordered array of regular server groups available based on a pre-defined
  1112. * set of rules.
  1113. *
  1114. * @param integer $type
  1115. * @return array
  1116. */
  1117. public function serverGroupGetProfiles($type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  1118. {
  1119. $profiles = array();
  1120. foreach($this->serverGroupList() as $sgid => $sgroup)
  1121. {
  1122. if($sgroup["type"] != $type) continue;
  1123. $profiles[$sgid] = array(
  1124. "b_permission_modify_power_ignore" => 0,
  1125. "i_group_member_add_power" => 0,
  1126. "i_group_member_remove_power" => 0,
  1127. "i_needed_modify_power_count" => 0,
  1128. "i_needed_modify_power_total" => 0,
  1129. "i_permission_modify_power" => 0,
  1130. "i_group_modify_power" => 0,
  1131. "i_client_modify_power" => 0,
  1132. "b_virtualserver_servergroup_create" => 0,
  1133. "b_virtualserver_servergroup_delete" => 0,
  1134. "b_client_ignore_bans" => 0,
  1135. "b_client_ignore_antiflood" => 0,
  1136. "b_group_is_permanent" => 0,
  1137. "i_client_needed_ban_power" => 0,
  1138. "i_client_needed_kick_power" => 0,
  1139. "i_client_needed_move_power" => 0,
  1140. "i_client_talk_power" => 0,
  1141. "__sgid" => $sgid,
  1142. "__name" => $sgroup->toString(),
  1143. "__node" => $sgroup,
  1144. );
  1145. try
  1146. {
  1147. $perms = $this->serverGroupPermList($sgid, TRUE);
  1148. $grant = isset($perms["i_permission_modify_power"]) ? $perms["i_permission_modify_power"]["permvalue"] : null;
  1149. }
  1150. catch(TeamSpeak3_Adapter_ServerQuery_Exception $e)
  1151. {
  1152. /* ERROR_database_empty_result */
  1153. if($e->getCode() != 0x501) throw $e;
  1154. $perms = array();
  1155. $grant = null;
  1156. }
  1157. foreach($perms as $permsid => $perm)
  1158. {
  1159. if(in_array($permsid, array_keys($profiles[$sgid])))
  1160. {
  1161. $profiles[$sgid][$permsid] = $perm["permvalue"];
  1162. }
  1163. elseif(TeamSpeak3_Helper_String::factory($permsid)->startsWith("i_needed_modify_power_"))
  1164. {
  1165. if(!$grant || $perm["permvalue"] > $grant) continue;
  1166. $profiles[$sgid]["i_needed_modify_power_total"] = $profiles[$sgid]["i_needed_modify_power_total"]+$perm["permvalue"];
  1167. $profiles[$sgid]["i_needed_modify_power_count"]++;
  1168. }
  1169. }
  1170. }
  1171. array_multisort($profiles, SORT_DESC);
  1172. return $profiles;
  1173. }
  1174. /**
  1175. * Tries to identify the post powerful/weakest server group on the virtual server and returns
  1176. * the ID.
  1177. *
  1178. * @param integer $mode
  1179. * @param integer $type
  1180. * @return TeamSpeak3_Node_Servergroup
  1181. */
  1182. public function serverGroupIdentify($mode = TeamSpeak3::GROUP_IDENTIFIY_STRONGEST, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  1183. {
  1184. $profiles = $this->serverGroupGetProfiles($type);
  1185. $best_guess_profile = ($mode == TeamSpeak3::GROUP_IDENTIFIY_STRONGEST) ? array_shift($profiles) : array_pop($profiles);
  1186. return $this->serverGroupGetById($best_guess_profile["__sgid"]);
  1187. }
  1188. /**
  1189. * Returns a list of channel groups available.
  1190. *
  1191. * @param array $filter
  1192. * @return array|TeamSpeak3_Node_Channelgroup[]
  1193. */
  1194. public function channelGroupList(array $filter = array())
  1195. {
  1196. if($this->cgroupList === null)
  1197. {
  1198. $this->cgroupList = $this->request("channelgrouplist")->toAssocArray("cgid");
  1199. foreach($this->cgroupList as $cgid => $group)
  1200. {
  1201. $this->cgroupList[$cgid] = new TeamSpeak3_Node_Channelgroup($this, $group);
  1202. }
  1203. uasort($this->cgroupList, array(__CLASS__, "sortGroupList"));
  1204. }
  1205. return $this->filterList($this->cgroupList, $filter);
  1206. }
  1207. /**
  1208. * Resets the list of channel groups.
  1209. *
  1210. * @return void
  1211. */
  1212. public function channelGroupListReset()
  1213. {
  1214. $this->cgroupList = null;
  1215. }
  1216. /**
  1217. * Creates a new channel group using the name specified with $name and returns its ID.
  1218. *
  1219. * @param string $name
  1220. * @param integer $type
  1221. * @return integer
  1222. */
  1223. public function channelGroupCreate($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  1224. {
  1225. $this->channelGroupListReset();
  1226. $cgid = $this->execute("channelgroupadd", array("name" => $name, "type" => $type))->toList();
  1227. return $cgid["cgid"];
  1228. }
  1229. /**
  1230. * Creates a copy of an existing channel group specified by $scgid and returns the new groups ID.
  1231. *
  1232. * @param integer $scgid
  1233. * @param string $name
  1234. * @param integer $tcgid
  1235. * @param integer $type
  1236. * @return integer
  1237. */
  1238. public function channelGroupCopy($scgid, $name = null, $tcgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  1239. {
  1240. $this->channelGroupListReset();
  1241. $cgid = $this->execute("channelgroupcopy", array("scgid" => $scgid, "tcgid" => $tcgid, "name" => $name, "type" => $type))->toList();
  1242. if($tcgid && $name)
  1243. {
  1244. $this->channelGroupRename($tcgid, $name);
  1245. }
  1246. return count($cgid) ? $cgid["cgid"] : intval($tcgid);
  1247. }
  1248. /**
  1249. * Renames the channel group specified with $cgid.
  1250. *
  1251. * @param integer $cgid
  1252. * @param string $name
  1253. * @return void
  1254. */
  1255. public function channelGroupRename($cgid, $name)
  1256. {
  1257. $this->channelGroupListReset();
  1258. $this->execute("channelgrouprename", array("cgid" => $cgid, "name" => $name));
  1259. }
  1260. /**
  1261. * Deletes the channel group specified with $cgid. If $force is set to 1, the channel group
  1262. * will be deleted even if there are clients within.
  1263. *
  1264. * @param integer $sgid
  1265. * @param boolean $force
  1266. * @return void
  1267. */
  1268. public function channelGroupDelete($cgid, $force = FALSE)
  1269. {
  1270. $this->channelGroupListReset();
  1271. $this->execute("channelgroupdel", array("cgid" => $cgid, "force" => $force));
  1272. }
  1273. /**
  1274. * Returns the TeamSpeak3_Node_Channelgroup object matching the given ID.
  1275. *
  1276. * @param integer $cgid
  1277. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  1278. * @return TeamSpeak3_Node_Channelgroup
  1279. */
  1280. public function channelGroupGetById($cgid)
  1281. {
  1282. if(!array_key_exists((string) $cgid, $this->channelGroupList()))
  1283. {
  1284. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
  1285. }
  1286. return $this->cgroupList[intval((string) $cgid)];
  1287. }
  1288. /**
  1289. * Returns the TeamSpeak3_Node_Channelgroup object matching the given name.
  1290. *
  1291. * @param string $name
  1292. * @param integer $type
  1293. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  1294. * @return TeamSpeak3_Node_Channelgroup
  1295. */
  1296. public function channelGroupGetByName($name, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  1297. {
  1298. foreach($this->channelGroupList() as $group)
  1299. {
  1300. if($group["name"] == $name && $group["type"] == $type) return $group;
  1301. }
  1302. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid groupID", 0xA00);
  1303. }
  1304. /**
  1305. * Returns a list of permissions assigned to the channel group specified.
  1306. *
  1307. * @param integer $cgid
  1308. * @param boolean $permsid
  1309. * @return array
  1310. */
  1311. public function channelGroupPermList($cgid, $permsid = FALSE)
  1312. {
  1313. return $this->execute("channelgrouppermlist", array("cgid" => $cgid, $permsid ? "-permsid" : null))->toAssocArray($permsid ? "permsid" : "permid");
  1314. }
  1315. /**
  1316. * Adds a set of specified permissions to the channel group specified. Multiple permissions
  1317. * can be added by providing the two parameters of each permission in separate arrays.
  1318. *
  1319. * @param integer $cgid
  1320. * @param integer $permid
  1321. * @param integer $permvalue
  1322. * @return void
  1323. */
  1324. public function channelGroupPermAssign($cgid, $permid, $permvalue)
  1325. {
  1326. if(!is_array($permid))
  1327. {
  1328. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  1329. }
  1330. else
  1331. {
  1332. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  1333. }
  1334. $this->execute("channelgroupaddperm", array("cgid" => $cgid, $permident => $permid, "permvalue" => $permvalue));
  1335. }
  1336. /**
  1337. * Removes a set of specified permissions from the channel group specified with $cgid. Multiple
  1338. * permissions can be removed at once.
  1339. *
  1340. * @param integer $cgid
  1341. * @param integer $permid
  1342. * @return void
  1343. */
  1344. public function channelGroupPermRemove($cgid, $permid)
  1345. {
  1346. if(!is_array($permid))
  1347. {
  1348. $permident = (is_numeric($permid)) ? "permid" : "permsid";
  1349. }
  1350. else
  1351. {
  1352. $permident = (is_numeric(current($permid))) ? "permid" : "permsid";
  1353. }
  1354. $this->execute("channelgroupdelperm", array("cgid" => $cgid, $permident => $permid));
  1355. }
  1356. /**
  1357. * Returns all the client and/or channel IDs currently assigned to channel groups. All three
  1358. * parameters are optional so you're free to choose the most suitable combination for your
  1359. * requirements.
  1360. *
  1361. * @param integer $cgid
  1362. * @param integer $cid
  1363. * @param integer $cldbid
  1364. * @param boolean $resolve
  1365. * @return array
  1366. */
  1367. public function channelGroupClientList($cgid = null, $cid = null, $cldbid = null, $resolve = FALSE)
  1368. {
  1369. if($this["virtualserver_default_channel_group"] == $cgid)
  1370. {
  1371. return array();
  1372. }
  1373. try
  1374. {
  1375. $result = $this->execute("channelgroupclientlist", array("cgid" => $cgid, "cid" => $cid, "cldbid" => $cldbid))->toArray();
  1376. }
  1377. catch(TeamSpeak3_Adapter_ServerQuery_Exception $e)
  1378. {
  1379. /* ERROR_database_empty_result */
  1380. if($e->getCode() != 0x501) throw $e;
  1381. $result = array();
  1382. }
  1383. if($resolve)
  1384. {
  1385. foreach($result as $k => $v)
  1386. {
  1387. $result[$k] = array_merge($v, $this->clientInfoDb($v["cldbid"]));
  1388. }
  1389. }
  1390. return $result;
  1391. }
  1392. /**
  1393. * Restores the default permission settings on the virtual server and returns a new initial
  1394. * administrator privilege key.
  1395. *
  1396. * @return TeamSpeak3_Helper_String
  1397. */
  1398. public function permReset()
  1399. {
  1400. $token = $this->request("permreset")->toList();
  1401. TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
  1402. return $token["token"];
  1403. }
  1404. /**
  1405. * Removes any assignment of the permission specified with $permid on the selected virtual server
  1406. * and returns the number of removed assignments on success.
  1407. *
  1408. * @param integer $permid
  1409. * @return integer
  1410. */
  1411. public function permRemoveAny($permid)
  1412. {
  1413. $assignments = $this->permissionFind($permid);
  1414. foreach($assignments as $assignment)
  1415. {
  1416. switch($assignment["t"])
  1417. {
  1418. case TeamSpeak3::PERM_TYPE_SERVERGROUP:
  1419. $this->serverGroupPermRemove($assignment["id1"], $assignment["p"]);
  1420. break;
  1421. case TeamSpeak3::PERM_TYPE_CLIENT:
  1422. $this->clientPermRemove($assignment["id1"], $assignment["p"]);
  1423. break;
  1424. case TeamSpeak3::PERM_TYPE_CHANNEL:
  1425. $this->channelPermRemove($assignment["id1"], $assignment["p"]);
  1426. break;
  1427. case TeamSpeak3::PERM_TYPE_CHANNELGROUP:
  1428. $this->channelGroupPermRemove($assignment["id2"], $assignment["p"]);
  1429. break;
  1430. case TeamSpeak3::PERM_TYPE_CHANNELCLIENT:
  1431. $this->channelClientPermRemove($assignment["id1"], $assignment["id2"], $assignment["p"]);
  1432. break;
  1433. default:
  1434. throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
  1435. }
  1436. }
  1437. return count($assignments);
  1438. }
  1439. /**
  1440. * Initializes a file transfer upload. $clientftfid is an arbitrary ID to identify the file transfer on client-side.
  1441. *
  1442. * @param integer $clientftfid
  1443. * @param integer $cid
  1444. * @param string $name
  1445. * @param integer $size
  1446. * @param string $cpw
  1447. * @param boolean $overwrite
  1448. * @param boolean $resume
  1449. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  1450. * @return array
  1451. */
  1452. public function transferInitUpload($clientftfid, $cid, $name, $size, $cpw = "", $overwrite = FALSE, $resume = FALSE)
  1453. {
  1454. $upload = $this->execute("ftinitupload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "size" => $size, "overwrite" => $overwrite, "resume" => $resume))->toList();
  1455. if(array_key_exists("status", $upload) && $upload["status"] != 0x00)
  1456. {
  1457. throw new TeamSpeak3_Adapter_ServerQuery_Exception($upload["msg"], $upload["status"]);
  1458. }
  1459. $upload["cid"] = $cid;
  1460. $upload["file"] = $name;
  1461. if(!array_key_exists("ip", $upload) || $upload["ip"]->startsWith("0.0.0.0"))
  1462. {
  1463. $upload["ip"] = $this->getParent()->getAdapterHost();
  1464. $upload["host"] = $upload["ip"];
  1465. }
  1466. else
  1467. {
  1468. $upload["ip"] = $upload["ip"]->section(",");
  1469. $upload["host"] = $upload["ip"];
  1470. }
  1471. TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadInit", $upload["ftkey"], $upload);
  1472. return $upload;
  1473. }
  1474. /**
  1475. * Initializes a file transfer download. $clientftfid is an arbitrary ID to identify the file transfer on client-side.
  1476. *
  1477. * @param integer $clientftfid
  1478. * @param integer $cid
  1479. * @param string $name
  1480. * @param string $cpw
  1481. * @param integer $seekpos
  1482. * @throws TeamSpeak3_Adapter_ServerQuery_Exception
  1483. * @return array
  1484. */
  1485. public function transferInitDownload($clientftfid, $cid, $name, $cpw = "", $seekpos = 0)
  1486. {
  1487. $download = $this->execute("ftinitdownload", array("clientftfid" => $clientftfid, "cid" => $cid, "name" => $name, "cpw" => $cpw, "seekpos" => $seekpos))->toList();
  1488. if(array_key_exists("status", $download) && $download["status"] != 0x00)
  1489. {
  1490. throw new TeamSpeak3_Adapter_ServerQuery_Exception($download["msg"], $download["status"]);
  1491. }
  1492. $download["cid"] = $cid;
  1493. $download["file"] = $name;
  1494. if(!array_key_exists("ip", $download) || $download["ip"]->startsWith("0.0.0.0"))
  1495. {
  1496. $download["ip"] = $this->getParent()->getAdapterHost();
  1497. $download["host"] = $download["ip"];
  1498. }
  1499. else
  1500. {
  1501. $download["ip"] = $download["ip"]->section(",");
  1502. $download["host"] = $download["ip"];
  1503. }
  1504. TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadInit", $download["ftkey"], $download);
  1505. return $download;
  1506. }
  1507. /**
  1508. * Displays a list of running file transfers on the selected virtual server. The output contains the path to
  1509. * which a file is uploaded to, the current transfer rate in bytes per second, etc.
  1510. *
  1511. * @return array
  1512. */
  1513. public function transferList()
  1514. {
  1515. return $this->request("ftlist")->toAssocArray("serverftfid");
  1516. }
  1517. /**
  1518. * Stops the running file transfer with server-side ID $serverftfid.
  1519. *
  1520. * @param integer $serverftfid
  1521. * @param boolean $delete
  1522. * @return void
  1523. */
  1524. public function transferStop($serverftfid, $delete = FALSE)
  1525. {
  1526. $this->execute("ftstop", array("serverftfid" => $serverftfid, "delete" => $delete));
  1527. }
  1528. /**
  1529. * Downloads and returns the servers icon file content.
  1530. *
  1531. * @return TeamSpeak3_Helper_String
  1532. */
  1533. public function iconDownload()
  1534. {
  1535. if($this->iconIsLocal("virtualserver_icon_id") || $this["virtualserver_icon_id"] == 0) return;
  1536. $download = $this->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("virtualserver_icon_id"));
  1537. $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
  1538. return $transfer->download($download["ftkey"], $download["size"]);
  1539. }
  1540. /**
  1541. * Uploads a given icon file content to the server and returns the ID of the icon.
  1542. *
  1543. * @param string $data
  1544. * @return integer
  1545. */
  1546. public function iconUpload($data)
  1547. {
  1548. $crc = crc32($data);
  1549. $size = strlen($data);
  1550. $upload = $this->transferInitUpload(rand(0x0000, 0xFFFF), 0, "/icon_" . $crc, $size);
  1551. $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($upload["host"], ":") !== FALSE ? "[" . $upload["host"] . "]" : $upload["host"]) . ":" . $upload["port"]);
  1552. $transfer->upload($upload["ftkey"], $upload["seekpos"], $data);
  1553. return $crc;
  1554. }
  1555. /**
  1556. * Changes the virtual server configuration using given properties.
  1557. *
  1558. * @param array $properties
  1559. * @return void
  1560. */
  1561. public function modify(array $properties)
  1562. {
  1563. $this->execute("serveredit", $properties);
  1564. $this->resetNodeInfo();
  1565. }
  1566. /**
  1567. * Sends a text message to all clients on the virtual server.
  1568. *
  1569. * @param string $msg
  1570. * @return void
  1571. */
  1572. public function message($msg)
  1573. {
  1574. $this->execute("sendtextmessage", array("msg" => $msg, "target" => $this->getId(), "targetmode" => TeamSpeak3::TEXTMSG_SERVER));
  1575. }
  1576. /**
  1577. * Returns a list of offline messages you've received. The output contains the senders unique identifier,
  1578. * the messages subject, etc.
  1579. *
  1580. * @return array
  1581. */
  1582. public function messageList()
  1583. {
  1584. return $this->request("messagelist")->toAssocArray("msgid");
  1585. }
  1586. /**
  1587. * Sends an offline message to the client specified by $cluid.
  1588. *
  1589. * @param string $cluid
  1590. * @param string $subject
  1591. * @param string $message
  1592. * @return void
  1593. */
  1594. public function messageCreate($cluid, $subject, $message)
  1595. {
  1596. $this->execute("messageadd", array("cluid" => $cluid, "subject" => $subject, "message" => $message));
  1597. }
  1598. /**
  1599. * Deletes an existing offline message with ID $msgid from your inbox.
  1600. *
  1601. * @param integer $msgid
  1602. * @return void
  1603. */
  1604. public function messageDelete($msgid)
  1605. {
  1606. $this->execute("messagedel", array("msgid" => $msgid));
  1607. }
  1608. /**
  1609. * Returns an existing offline message with ID $msgid from your inbox.
  1610. *
  1611. * @param integer $msgid
  1612. * @param boolean $flag_read
  1613. * @return array
  1614. */
  1615. public function messageRead($msgid, $flag_read = TRUE)
  1616. {
  1617. $msg = $this->execute("messageget", array("msgid" => $msgid))->toList();
  1618. if($flag_read)
  1619. {
  1620. $this->execute("messageget", array("msgid" => $msgid, "flag" => $flag_read));
  1621. }
  1622. return $msg;
  1623. }
  1624. /**
  1625. * Creates and returns snapshot data for the selected virtual server.
  1626. *
  1627. * @param string $mode
  1628. * @return string
  1629. */
  1630. public function snapshotCreate($mode = TeamSpeak3::SNAPSHOT_STRING)
  1631. {
  1632. $snapshot = $this->request("serversnapshotcreate")->toString(FALSE);
  1633. switch($mode)
  1634. {
  1635. case TeamSpeak3::SNAPSHOT_BASE64:
  1636. return $snapshot->toBase64();
  1637. break;
  1638. case TeamSpeak3::SNAPSHOT_HEXDEC:
  1639. return $snapshot->toHex();
  1640. break;
  1641. default:
  1642. return (string) $snapshot;
  1643. break;
  1644. }
  1645. }
  1646. /**
  1647. * Deploys snapshot data on the selected virtual server. If no virtual server is selected (ID 0),
  1648. * the data will be used to create a new virtual server from scratch.
  1649. *
  1650. * @param string $data
  1651. * @param string $mode
  1652. * @return array
  1653. */
  1654. public function snapshotDeploy($data, $mode = TeamSpeak3::SNAPSHOT_STRING)
  1655. {
  1656. switch($mode)
  1657. {
  1658. case TeamSpeak3::SNAPSHOT_BASE64:
  1659. $data = TeamSpeak3_Helper_String::fromBase64($data);
  1660. break;
  1661. case TeamSpeak3::SNAPSHOT_HEXDEC:
  1662. $data = TeamSpeak3_Helper_String::fromHex($data);
  1663. break;
  1664. default:
  1665. $data = TeamSpeak3_Helper_String::factory($data);
  1666. break;
  1667. }
  1668. $detail = $this->request("serversnapshotdeploy -mapping -keepfiles " . $data)->toList();
  1669. if(isset($detail[0]["sid"]))
  1670. {
  1671. TeamSpeak3_Helper_Signal::getInstance()->emit("notifyServercreated", $this->getParent(), $detail[0]["sid"]);
  1672. $server = array_shift($detail);
  1673. }
  1674. else
  1675. {
  1676. $server = array();
  1677. }
  1678. $server["mapping"] = $detail;
  1679. return $server;
  1680. }
  1681. /**
  1682. * Registers for a specified category of events on a virtual server to receive notification
  1683. * messages. Depending on the notifications you've registered for, the server will send you
  1684. * a message on every event.
  1685. *
  1686. * @param string $event
  1687. * @param integer $id
  1688. * @return void
  1689. */
  1690. public function notifyRegister($event, $id = 0)
  1691. {
  1692. $this->execute("servernotifyregister", array("event" => $event, "id" => $id));
  1693. }
  1694. /**
  1695. * Unregisters all events previously registered with servernotifyregister so you will no
  1696. * longer receive notification messages.
  1697. *
  1698. * @return void
  1699. */
  1700. public function notifyUnregister()
  1701. {
  1702. $this->request("servernotifyunregister");
  1703. }
  1704. /**
  1705. * Alias for privilegeKeyList().
  1706. *
  1707. * @deprecated
  1708. */
  1709. public function tokenList($translate = FALSE)
  1710. {
  1711. return $this->privilegeKeyList();
  1712. }
  1713. /**
  1714. * Returns a list of privilege keys (tokens) available. If $resolve is set to TRUE the values
  1715. * of token_id1 and token_id2 will be translated into the appropriate group and/or channel
  1716. * names.
  1717. *
  1718. * @param boolean $resolve
  1719. * @return array
  1720. */
  1721. public function privilegeKeyList($resolve = FALSE)
  1722. {
  1723. $tokens = $this->request("privilegekeylist")->toAssocArray("token");
  1724. if($resolve)
  1725. {
  1726. foreach($tokens as $token => $array)
  1727. {
  1728. $func = $array["token_type"] ? "channelGroupGetById" : "serverGroupGetById";
  1729. try
  1730. {
  1731. $tokens[$token]["token_id1"] = $this->$func($array["token_id1"])->name;
  1732. }
  1733. catch(Exception $e)
  1734. {
  1735. /* ERROR_channel_invalid_id */
  1736. if($e->getCode() != 0xA00) throw $e;
  1737. }
  1738. try
  1739. {
  1740. if($array["token_type"]) $tokens[$token]["token_id2"] = $this->channelGetById($array["token_id2"])->getPathway();
  1741. }
  1742. catch(Exception $e)
  1743. {
  1744. /* ERROR_permission_invalid_group_id */
  1745. if($e->getCode() != 0x300) throw $e;
  1746. }
  1747. }
  1748. }
  1749. return $tokens;
  1750. }
  1751. /**
  1752. * Alias for privilegeKeyCreate().
  1753. *
  1754. * @deprecated
  1755. */
  1756. public function tokenCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null)
  1757. {
  1758. return $this->privilegeKeyCreate($type, $id1, $id2, $description, $customset);
  1759. }
  1760. /**
  1761. * Creates a new privilege key (token) and returns the key.
  1762. *
  1763. * @param integer $type
  1764. * @param integer $id1
  1765. * @param integer $id2
  1766. * @param string $description
  1767. * @param string $customset
  1768. * @return TeamSpeak3_Helper_String
  1769. */
  1770. public function privilegeKeyCreate($type = TeamSpeak3::TOKEN_SERVERGROUP, $id1, $id2 = 0, $description = null, $customset = null)
  1771. {
  1772. $token = $this->execute("privilegekeyadd", array("tokentype" => $type, "tokenid1" => $id1, "tokenid2" => $id2, "tokendescription" => $description, "tokencustomset" => $customset))->toList();
  1773. TeamSpeak3_Helper_Signal::getInstance()->emit("notifyTokencreated", $this, $token["token"]);
  1774. return $token["token"];
  1775. }
  1776. /**
  1777. * Alias for privilegeKeyDelete().
  1778. *
  1779. * @deprecated
  1780. */
  1781. public function tokenDelete($token)
  1782. {
  1783. $this->privilegeKeyDelete($token);
  1784. }
  1785. /**
  1786. * Deletes a token specified by key $token.
  1787. *
  1788. * @param string $token
  1789. * @return void
  1790. */
  1791. public function privilegeKeyDelete($token)
  1792. {
  1793. $this->execute("privilegekeydelete", array("token" => $token));
  1794. }
  1795. /**
  1796. * Alias for privilegeKeyUse().
  1797. *
  1798. * @deprecated
  1799. */
  1800. public function tokenUse($token)
  1801. {
  1802. $this->privilegeKeyUse($token);
  1803. }
  1804. /**
  1805. * Use a token key gain access to a server or channel group. Please note that the server will
  1806. * automatically delete the token after it has been used.
  1807. *
  1808. * @param string $token
  1809. * @return void
  1810. */
  1811. public function privilegeKeyUse($token)
  1812. {
  1813. $this->execute("privilegekeyuse", array("token" => $token));
  1814. }
  1815. /**
  1816. * Returns a list of custom client properties specified by $ident.
  1817. *
  1818. * @param string $ident
  1819. * @param string $pattern
  1820. * @return array
  1821. */
  1822. public function customSearch($ident, $pattern = "%")
  1823. {
  1824. return $this->execute("customsearch", array("ident" => $ident, "pattern" => $pattern))->toArray();
  1825. }
  1826. /**
  1827. * Returns a list of custom properties for the client specified by $cldbid.
  1828. *
  1829. * @param integer $cldbid
  1830. * @return array
  1831. */
  1832. public function customInfo($cldbid)
  1833. {
  1834. return $this->execute("custominfo", array("cldbid" => $cldbid))->toArray();
  1835. }
  1836. /**
  1837. * Creates or updates a custom property for the client specified by $cldbid.
  1838. *
  1839. * @param integer $cldbid
  1840. * @param string $ident
  1841. * @param string $value
  1842. * @return void
  1843. */
  1844. public function customSet($cldbid, $ident, $value)
  1845. {
  1846. $this->execute("customset", array("cldbid" => $cldbid, "ident" => $ident, "value" => $value));
  1847. }
  1848. /**
  1849. * Removes a custom property from the client specified by $cldbid.
  1850. *
  1851. * @param integer $cldbid
  1852. * @param string $ident
  1853. * @return void
  1854. */
  1855. public function customDelete($cldbid, $ident)
  1856. {
  1857. $this->execute("customdelete", array("cldbid" => $cldbid, "ident" => $ident));
  1858. }
  1859. /**
  1860. * Returns a list of active bans on the selected virtual server.
  1861. *
  1862. * @return array
  1863. */
  1864. public function banList($offset = null, $limit = null)
  1865. {
  1866. return $this->execute("banlist -count", array("start" => $offset, "duration" => $limit))->toAssocArray("banid");
  1867. }
  1868. /**
  1869. * Returns the number of bans on the selected virtual server.
  1870. *
  1871. * @return integer
  1872. */
  1873. public function banCount()
  1874. {
  1875. return current($this->execute("banlist -count", array("duration" => 1))->toList("count"));
  1876. }
  1877. /**
  1878. * Deletes all active ban rules from the server.
  1879. *
  1880. * @return void
  1881. */
  1882. public function banListClear()
  1883. {
  1884. $this->request("bandelall");
  1885. }
  1886. /**
  1887. * Adds a new ban rule on the selected virtual server. All parameters are optional but at least one
  1888. * of the following rules must be set: ip, name, or uid.
  1889. *
  1890. * @param array $rules
  1891. * @param integer $timeseconds
  1892. * @param string $reason
  1893. * @return integer
  1894. */
  1895. public function banCreate(array $rules, $timeseconds = null, $reason = null)
  1896. {
  1897. $rules["time"] = $timeseconds;
  1898. $rules["banreason"] = $reason;
  1899. $banid = $this->execute("banadd", $rules)->toList();
  1900. return $banid["banid"];
  1901. }
  1902. /**
  1903. * Deletes the specified ban rule from the server.
  1904. *
  1905. * @param integer $banid
  1906. * @return void
  1907. */
  1908. public function banDelete($banid)
  1909. {
  1910. $this->execute("bandel", array("banid" => $banid));
  1911. }
  1912. /**
  1913. * Returns a list of complaints on the selected virtual server. If $tcldbid is specified, only
  1914. * complaints about the targeted client will be shown.
  1915. *
  1916. * @param integer $tcldbid
  1917. * @return array
  1918. */
  1919. public function complaintList($tcldbid = null)
  1920. {
  1921. return $this->execute("complainlist", array("tcldbid" => $tcldbid))->toArray();
  1922. }
  1923. /**
  1924. * Deletes all active complaints about the client with database ID $tcldbid from the server.
  1925. *
  1926. * @param integer $tcldbid
  1927. * @return void
  1928. */
  1929. public function complaintListClear($tcldbid)
  1930. {
  1931. $this->execute("complaindelall", array("tcldbid" => $tcldbid));
  1932. }
  1933. /**
  1934. * Submits a complaint about the client with database ID $tcldbid to the server.
  1935. *
  1936. * @param integer $tcldbid
  1937. * @param string $message
  1938. * @return void
  1939. */
  1940. public function complaintCreate($tcldbid, $message)
  1941. {
  1942. $this->execute("complainadd", array("tcldbid" => $tcldbid, "message" => $message));
  1943. }
  1944. /**
  1945. * Deletes the complaint about the client with ID $tcldbid submitted by the client with ID $fcldbid from the server.
  1946. *
  1947. * @param integer $tcldbid
  1948. * @param integer $fcldbid
  1949. * @return void
  1950. */
  1951. public function complaintDelete($tcldbid, $fcldbid)
  1952. {
  1953. $this->execute("complaindel", array("tcldbid" => $tcldbid, "fcldbid" => $fcldbid));
  1954. }
  1955. /**
  1956. * Returns a list of temporary server passwords.
  1957. *
  1958. * @param boolean $resolve
  1959. * @return array
  1960. */
  1961. public function tempPasswordList($resolve = FALSE)
  1962. {
  1963. $passwords = $this->request("servertemppasswordlist")->toAssocArray("pw_clear");
  1964. if($resolve)
  1965. {
  1966. foreach($passwords as $password => $array)
  1967. {
  1968. try
  1969. {
  1970. $channel = $this->channelGetById($array["tcid"]);
  1971. $passwords[$password]["tcname"] = $channel->toString();
  1972. $passwords[$password]["tcpath"] = $channel->getPathway();
  1973. }
  1974. catch(Exception $e)
  1975. {
  1976. /* ERROR_channel_invalid_id */
  1977. if($e->getCode() != 0xA00) throw $e;
  1978. }
  1979. }
  1980. }
  1981. return $passwords;
  1982. }
  1983. /**
  1984. * Sets a new temporary server password specified with $pw. The temporary password will be
  1985. * valid for the number of seconds specified with $duration. The client connecting with this
  1986. * password will automatically join the channel specified with $tcid. If tcid is set to 0,
  1987. * the client will join the default channel.
  1988. *
  1989. * @param string $pw
  1990. * @param integer $duration
  1991. * @param integer $tcid
  1992. * @param string $tcpw
  1993. * @param string $desc
  1994. * @return void
  1995. */
  1996. public function tempPasswordCreate($pw, $duration, $tcid = 0, $tcpw = "", $desc = "")
  1997. {
  1998. $this->execute("servertemppasswordadd", array("pw" => $pw, "duration" => $duration, "tcid" => $tcid, "tcpw" => $tcpw, "desc" => $desc));
  1999. }
  2000. /**
  2001. * Deletes the temporary server password specified with $pw.
  2002. *
  2003. * @param string $pw
  2004. * @return void
  2005. */
  2006. public function tempPasswordDelete($pw)
  2007. {
  2008. $this->execute("servertemppassworddel", array("pw" => $pw));
  2009. }
  2010. /**
  2011. * Displays a specified number of entries (1-100) from the servers log.
  2012. *
  2013. * @param integer $lines
  2014. * @param integer $begin_pos
  2015. * @param boolean $reverse
  2016. * @param boolean $instance
  2017. * @return array
  2018. */
  2019. public function logView($lines = 30, $begin_pos = null, $reverse = null, $instance = null)
  2020. {
  2021. return $this->execute("logview", array("lines" => $lines, "begin_pos" => $begin_pos, "instance" => $instance, "reverse" => $reverse))->toArray();
  2022. }
  2023. /**
  2024. * Writes a custom entry into the virtual server log.
  2025. *
  2026. * @param string $logmsg
  2027. * @param integer $loglevel
  2028. * @return void
  2029. */
  2030. public function logAdd($logmsg, $loglevel = TeamSpeak3::LOGLEVEL_INFO)
  2031. {
  2032. $this->execute("logadd", array("logmsg" => $logmsg, "loglevel" => $loglevel));
  2033. }
  2034. /**
  2035. * Returns detailed connection information of the virtual server.
  2036. *
  2037. * @return array
  2038. */
  2039. public function connectionInfo()
  2040. {
  2041. return $this->request("serverrequestconnectioninfo")->toList();
  2042. }
  2043. /**
  2044. * Deletes the virtual server.
  2045. *
  2046. * @return void
  2047. */
  2048. public function delete()
  2049. {
  2050. $this->getParent()->serverDelete($this->getId());
  2051. }
  2052. /**
  2053. * Starts the virtual server.
  2054. *
  2055. * @return void
  2056. */
  2057. public function start()
  2058. {
  2059. $this->getParent()->serverStart($this->getId());
  2060. }
  2061. /**
  2062. * Stops the virtual server.
  2063. *
  2064. * @param string $msg
  2065. * @return void
  2066. */
  2067. public function stop($msg = null)
  2068. {
  2069. $this->getParent()->serverStop($this->getId(), $msg);
  2070. }
  2071. /**
  2072. * Sends a plugin command to all clients connected to the server.
  2073. *
  2074. * @param string $plugin
  2075. * @param string $data
  2076. * @return void
  2077. */
  2078. public function sendPluginCmd($plugin, $data)
  2079. {
  2080. $this->execute("plugincmd", array("name" => $plugin, "data" => $data, "targetmode" => TeamSpeak3::PLUGINCMD_SERVER));
  2081. }
  2082. /**
  2083. * Changes the properties of your own client connection.
  2084. *
  2085. * @param array $properties
  2086. * @return void
  2087. */
  2088. public function selfUpdate(array $properties)
  2089. {
  2090. $this->execute("clientupdate", $properties);
  2091. foreach($properties as $ident => $value)
  2092. {
  2093. $this->whoamiSet($ident, $value);
  2094. }
  2095. }
  2096. /**
  2097. * Updates your own ServerQuery login credentials using a specified username. The password
  2098. * will be auto-generated.
  2099. *
  2100. * @param string $username
  2101. * @return TeamSpeak3_Helper_String
  2102. */
  2103. public function selfUpdateLogin($username)
  2104. {
  2105. $password = $this->execute("clientsetserverquerylogin", array("client_login_name" => $username))->toList();
  2106. return $password["client_login_password"];
  2107. }
  2108. /**
  2109. * Returns an array containing the permission overview of your own client.
  2110. *
  2111. * @return array
  2112. */
  2113. public function selfPermOverview()
  2114. {
  2115. return $this->execute("permoverview", array("cldbid" => $this->whoamiGet("client_database_id"), "cid" => $this->whoamiGet("client_channel_id"), "permid" => 0))->toArray();
  2116. }
  2117. /**
  2118. * @ignore
  2119. */
  2120. protected function fetchNodeList()
  2121. {
  2122. $this->nodeList = array();
  2123. foreach($this->channelList() as $channel)
  2124. {
  2125. if($channel["pid"] == 0)
  2126. {
  2127. $this->nodeList[] = $channel;
  2128. }
  2129. }
  2130. }
  2131. /**
  2132. * @ignore
  2133. */
  2134. protected function fetchNodeInfo()
  2135. {
  2136. $this->nodeInfo = array_merge($this->nodeInfo, $this->request("serverinfo")->toList());
  2137. }
  2138. /**
  2139. * Internal callback funtion for sorting of client objects.
  2140. *
  2141. * @param TeamSpeak3_Node_Client $a
  2142. * @param TeamSpeak3_Node_Client $b
  2143. * @return integer
  2144. */
  2145. protected static function sortClientList(TeamSpeak3_Node_Client $a, TeamSpeak3_Node_Client $b)
  2146. {
  2147. if(get_class($a) != get_class($b))
  2148. {
  2149. return 0;
  2150. /* workaround for PHP bug #50688 */
  2151. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
  2152. }
  2153. if(!$a instanceof TeamSpeak3_Node_Client)
  2154. {
  2155. return 0;
  2156. /* workaround for PHP bug #50688 */
  2157. throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
  2158. }
  2159. if($a->getProperty("client_talk_power", 0) != $b->getProperty("client_talk_power", 0))
  2160. {
  2161. return ($a->getProperty("client_talk_power", 0) > $b->getProperty("client_talk_power", 0)) ? -1 : 1;
  2162. }
  2163. if($a->getProperty("client_is_talker", 0) != $b->getProperty("client_is_talker", 0))
  2164. {
  2165. return ($a->getProperty("client_is_talker", 0) > $b->getProperty("client_is_talker", 0)) ? -1 : 1;
  2166. }
  2167. return strcmp(strtolower($a["client_nickname"]), strtolower($b["client_nickname"]));
  2168. }
  2169. /**
  2170. * Internal callback funtion for sorting of group objects.
  2171. *
  2172. * @param TeamSpeak3_Node_Abstract $a
  2173. * @param TeamSpeak3_Node_Abstract $b
  2174. * @return integer
  2175. */
  2176. protected static function sortGroupList(TeamSpeak3_Node_Abstract $a, TeamSpeak3_Node_Abstract $b)
  2177. {
  2178. if(get_class($a) != get_class($b))
  2179. {
  2180. return 0;
  2181. /* workaround for PHP bug #50688 */
  2182. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
  2183. }
  2184. if(!$a instanceof TeamSpeak3_Node_Servergroup && !$a instanceof TeamSpeak3_Node_Channelgroup)
  2185. {
  2186. return 0;
  2187. /* workaround for PHP bug #50688 */
  2188. throw new TeamSpeak3_Adapter_ServerQuery_Exception("convert error", 0x604);
  2189. }
  2190. if($a->getProperty("sortid", 0) != $b->getProperty("sortid", 0) && $a->getProperty("sortid", 0) != 0 && $b->getProperty("sortid", 0) != 0)
  2191. {
  2192. return ($a->getProperty("sortid", 0) < $b->getProperty("sortid", 0)) ? -1 : 1;
  2193. }
  2194. return ($a->getId() < $b->getId()) ? -1 : 1;
  2195. }
  2196. /**
  2197. * Internal callback funtion for sorting of file list items.
  2198. *
  2199. * @param array $a
  2200. * @param array $b
  2201. * @return integer
  2202. */
  2203. protected static function sortFileList(array $a, array $b)
  2204. {
  2205. if(!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b))
  2206. {
  2207. return 0;
  2208. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
  2209. }
  2210. if($a["type"] != $b["type"])
  2211. {
  2212. return ($a["type"] < $b["type"]) ? -1 : 1;
  2213. }
  2214. return strcmp(strtolower($a["src"]), strtolower($b["src"]));
  2215. }
  2216. /**
  2217. * Returns TRUE if the virtual server is online.
  2218. *
  2219. * @return boolean
  2220. */
  2221. public function isOnline()
  2222. {
  2223. return ($this["virtualserver_status"] == "online") ? TRUE : FALSE;
  2224. }
  2225. /**
  2226. * Returns TRUE if the virtual server is offline.
  2227. *
  2228. * @return boolean
  2229. */
  2230. public function isOffline()
  2231. {
  2232. return ($this["virtualserver_status"] == "offline") ? TRUE : FALSE;
  2233. }
  2234. /**
  2235. * Returns a unique identifier for the node which can be used as a HTML property.
  2236. *
  2237. * @return string
  2238. */
  2239. public function getUniqueId()
  2240. {
  2241. return $this->getParent()->getUniqueId() . "_s" . $this->getId();
  2242. }
  2243. /**
  2244. * Returns the name of a possible icon to display the node object.
  2245. *
  2246. * @return string
  2247. */
  2248. public function getIcon()
  2249. {
  2250. if($this["virtualserver_clientsonline"]-$this["virtualserver_queryclientsonline"] >= $this["virtualserver_maxclients"])
  2251. {
  2252. return "server_full";
  2253. }
  2254. elseif($this["virtualserver_flag_password"])
  2255. {
  2256. return "server_pass";
  2257. }
  2258. else
  2259. {
  2260. return "server_open";
  2261. }
  2262. }
  2263. /**
  2264. * Returns a symbol representing the node.
  2265. *
  2266. * @return string
  2267. */
  2268. public function getSymbol()
  2269. {
  2270. return "$";
  2271. }
  2272. /**
  2273. * Returns a string representation of this node.
  2274. *
  2275. * @return string
  2276. */
  2277. public function __toString()
  2278. {
  2279. return (string) $this["virtualserver_name"];
  2280. }
  2281. }