Servergroup.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * $Id: Servergroup.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_Servergroup
  28. * @brief Class describing a TeamSpeak 3 server group and all it's parameters.
  29. */
  30. class TeamSpeak3_Node_Servergroup extends TeamSpeak3_Node_Abstract
  31. {
  32. /**
  33. * The TeamSpeak3_Node_Servergroup constructor.
  34. *
  35. * @param TeamSpeak3_Node_Server $server
  36. * @param array $info
  37. * @param string $index
  38. * @throws TeamSpeak3_Node_Exception
  39. * @return TeamSpeak3_Node_Servergroup
  40. */
  41. public function __construct(TeamSpeak3_Node_Server $server, array $info, $index = "sgid")
  42. {
  43. $this->parent = $server;
  44. $this->nodeInfo = $info;
  45. if(!array_key_exists($index, $this->nodeInfo))
  46. {
  47. throw new TeamSpeak3_Node_Exception("invalid groupID", 0xA00);
  48. }
  49. $this->nodeId = $this->nodeInfo[$index];
  50. }
  51. /**
  52. * Renames the server group specified.
  53. *
  54. * @param string $name
  55. * @return void
  56. */
  57. public function rename($name)
  58. {
  59. $this->getParent()->serverGroupRename($this->getId(), $name);
  60. }
  61. /**
  62. * Deletes the server group. If $force is set to 1, the server group will be
  63. * deleted even if there are clients within.
  64. *
  65. * @param boolean $force
  66. * @return void
  67. */
  68. public function delete($force = FALSE)
  69. {
  70. $this->getParent()->serverGroupDelete($this->getId(), $force);
  71. }
  72. /**
  73. * Creates a copy of the server group and returns the new groups ID.
  74. *
  75. * @param string $name
  76. * @param integer $tsgid
  77. * @param integer $type
  78. * @return integer
  79. */
  80. public function copy($name = null, $tsgid = 0, $type = TeamSpeak3::GROUP_DBTYPE_REGULAR)
  81. {
  82. return $this->getParent()->serverGroupCopy($this->getId(), $name, $tsgid, $type);
  83. }
  84. /**
  85. * Returns a list of permissions assigned to the server group.
  86. *
  87. * @param boolean $permsid
  88. * @return array
  89. */
  90. public function permList($permsid = FALSE)
  91. {
  92. return $this->getParent()->serverGroupPermList($this->getId(), $permsid);
  93. }
  94. /**
  95. * Adds a set of specified permissions to the server group. Multiple permissions
  96. * can be added by providing the four parameters of each permission in separate arrays.
  97. *
  98. * @param integer $permid
  99. * @param integer $permvalue
  100. * @param integer $permnegated
  101. * @param integer $permskip
  102. * @return void
  103. */
  104. public function permAssign($permid, $permvalue, $permnegated = FALSE, $permskip = FALSE)
  105. {
  106. $this->getParent()->serverGroupPermAssign($this->getId(), $permid, $permvalue, $permnegated, $permskip);
  107. }
  108. /**
  109. * Alias for permAssign().
  110. *
  111. * @deprecated
  112. */
  113. public function permAssignByName($permname, $permvalue, $permnegated = FALSE, $permskip = FALSE)
  114. {
  115. $this->permAssign($permname, $permvalue, $permnegated, $permskip);
  116. }
  117. /**
  118. * Removes a set of specified permissions from the server group. Multiple
  119. * permissions can be removed at once.
  120. *
  121. * @param integer $permid
  122. * @return void
  123. */
  124. public function permRemove($permid)
  125. {
  126. $this->getParent()->serverGroupPermRemove($this->getId(), $permid);
  127. }
  128. /**
  129. * Alias for permRemove().
  130. *
  131. * @deprecated
  132. */
  133. public function permRemoveByName($permname)
  134. {
  135. $this->permRemove($permname);
  136. }
  137. /**
  138. * Returns a list of clients assigned to the server group specified.
  139. *
  140. * @return array
  141. */
  142. public function clientList()
  143. {
  144. return $this->getParent()->serverGroupClientList($this->getId());
  145. }
  146. /**
  147. * Adds a client to the server group specified. Please note that a client cannot be
  148. * added to default groups or template groups.
  149. *
  150. * @param integer $cldbid
  151. * @return void
  152. */
  153. public function clientAdd($cldbid)
  154. {
  155. $this->getParent()->serverGroupClientAdd($this->getId(), $cldbid);
  156. }
  157. /**
  158. * Removes a client from the server group.
  159. *
  160. * @param integer $cldbid
  161. * @return void
  162. */
  163. public function clientDel($cldbid)
  164. {
  165. $this->getParent()->serverGroupClientDel($this->getId(), $cldbid);
  166. }
  167. /**
  168. * Alias for privilegeKeyCreate().
  169. *
  170. * @deprecated
  171. */
  172. public function tokenCreate($description = null, $customset = null)
  173. {
  174. return $this->privilegeKeyCreate($description, $customset);
  175. }
  176. /**
  177. * Creates a new privilege key (token) for the server group and returns the key.
  178. *
  179. * @param string $description
  180. * @param string $customset
  181. * @return TeamSpeak3_Helper_String
  182. */
  183. public function privilegeKeyCreate($description = null, $customset = null)
  184. {
  185. return $this->getParent()->privilegeKeyCreate(TeamSpeak3::TOKEN_SERVERGROUP, $this->getId(), 0, $description, $customset);
  186. }
  187. /**
  188. * Sends a text message to all clients residing in the server group on the virtual server.
  189. *
  190. * @param string $msg
  191. * @return void
  192. */
  193. public function message($msg)
  194. {
  195. foreach($this as $client)
  196. {
  197. try
  198. {
  199. $this->execute("sendtextmessage", array("msg" => $msg, "target" => $client, "targetmode" => TeamSpeak3::TEXTMSG_CLIENT));
  200. }
  201. catch(TeamSpeak3_Adapter_ServerQuery_Exception $e)
  202. {
  203. /* ERROR_client_invalid_id */
  204. if($e->getCode() != 0x0200) throw $e;
  205. }
  206. }
  207. }
  208. /**
  209. * Downloads and returns the server groups icon file content.
  210. *
  211. * @return TeamSpeak3_Helper_String
  212. */
  213. public function iconDownload()
  214. {
  215. if($this->iconIsLocal("iconid") || $this["iconid"] == 0) return;
  216. $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->iconGetName("iconid"));
  217. $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]);
  218. return $transfer->download($download["ftkey"], $download["size"]);
  219. }
  220. /**
  221. * @ignore
  222. */
  223. protected function fetchNodeList()
  224. {
  225. $this->nodeList = array();
  226. foreach($this->getParent()->clientList() as $client)
  227. {
  228. if(in_array($this->getId(), explode(",", $client["client_servergroups"])))
  229. {
  230. $this->nodeList[] = $client;
  231. }
  232. }
  233. }
  234. /**
  235. * Returns a unique identifier for the node which can be used as a HTML property.
  236. *
  237. * @return string
  238. */
  239. public function getUniqueId()
  240. {
  241. return $this->getParent()->getUniqueId() . "_sg" . $this->getId();
  242. }
  243. /**
  244. * Returns the name of a possible icon to display the node object.
  245. *
  246. * @return string
  247. */
  248. public function getIcon()
  249. {
  250. return "group_server";
  251. }
  252. /**
  253. * Returns a symbol representing the node.
  254. *
  255. * @return string
  256. */
  257. public function getSymbol()
  258. {
  259. return "%";
  260. }
  261. /**
  262. * Returns a string representation of this node.
  263. *
  264. * @return string
  265. */
  266. public function __toString()
  267. {
  268. return (string) $this["name"];
  269. }
  270. }