1
0

Servergroup.php 7.4 KB

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