Server.php 68 KB

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