Server Group Auto Assign Bot Modifikationshilfe

    Server Group Auto Assign Bot Modifikationshilfe

    Hey Leute,
    ich bräuchte auch mal eure Hilfe, und zwar habe ich den "Server Group Assign Bot" heruntergeladen, funktioniert auch einwandfrei, nur fehlt mir eine Funktion, aber ich bin zu blöde das zum laufen zu kriegen ;)
    Der Bot kann, wenn man ihm einen bestimmten Befehl schickt(im client) einem vorher bestimmte servergruppen zuweisen(man kann auch einstellen, wie viele dieser servergruppen jemand maximal haben darf)... Mir fehlt hier allerdings dass man verschieden
    ServerGruppen gruppieren kann und dann z.b. bis zu 1 ServerGruppe aus Gruppe XXX zugewiesen haben darf und bis zu 2 aus Gruppe YYY
    Die Originale settings.php(nur der interessante Teil):
    Spoiler anzeigen

    PHP-Quellcode

    1. <?php
    2. /* here goes a list of server groups which the bot is able to assign to members
    3. * please adapt this list of server group to your requirements!
    4. * ATTENTION: make sure that there is no ID of a server admin group listed below!
    5. * NOTE: -PLEASE WRITE ALL NAMES IN LOWER CASE LETTERS-
    6. */
    7. $server_groups = array(
    8. "minecraft" => "566",
    9. "testgrp" => "922",
    10. "vip" => "747",
    11. );
    12. /* should there be a limit to how many server groups a client can be assigned to?
    13. * note: only server groups the client can assign count here.
    14. * set to 0 for "no limit", else to the maximum number of groups
    15. */
    16. $limit_server_groups = "0";
    17. ?>

    Meine angepasste settings.php(selber Teil):
    Spoiler anzeigen

    PHP-Quellcode

    1. <?php
    2. /* here goes a list of server groups which the bot is able to assign to members
    3. * please adapt this list of server group to your requirements!
    4. * ATTENTION: make sure that there is no ID of a server admin group listed below!
    5. * NOTE: -PLEASE WRITE ALL NAMES IN LOWER CASE LETTERS-
    6. */
    7. $server_groups['gamegroup'] = array(
    8. "league of legends" => "12",
    9. "age of empires 2" => "13",
    10. "h1z1" => "14",
    11. "cs:go" => "15",
    12. "overwatch" => "48",
    13. );
    14. $server_groups['leagueoflegendsrank'] = array(
    15. "bronze" => "39",
    16. "silver" => "41",
    17. "gold" => "42",
    18. "platinum" => "43",
    19. "diamond" => "44",
    20. "master" => "45",
    21. "challenger" => "46",
    22. );
    23. $server_groups['csgorank'] = array(
    24. "silver 1" => "38",
    25. "silver 2" => "20",
    26. "silver 3" => "21",
    27. "silver 4" => "22",
    28. "silver elite" => "23",
    29. "silver elite master" => "24",
    30. "gold nova 1" => "25",
    31. "gold nova 2" => "26",
    32. "gold nova 3" => "27",
    33. "gold nova master" => "28",
    34. "master guardian 1" => "29",
    35. "master guardian 2" => "30",
    36. "master guardian elite" => "31",
    37. "distinguished master guardian" => "32",
    38. "legendary eagle" => "33",
    39. "legendary eagle master" => "34",
    40. "supreme master first class" => "35",
    41. "the global elite" => "36",
    42. );
    43. /* should there be a limit to how many server groups a client can be assigned to?
    44. * note: only server groups the client can assign count here.
    45. * set to 0 for "no limit", else to the maximum number of groups
    46. */
    47. $limit_server_groups['gamegroup'] = "1";
    48. $limit_server_groups['leagueoflegendsrank'] = "1";
    49. $limit_server_groups['csgorank'] = "1";
    50. ?>

    Ich habe also einfach aus $server_groups ein multidimensionales Array gemacht, und aus $limit_server_groups ein Array statt einer Funktion.
    Soweit so gut. Jetzt das allerdings in den Bot selber zu implementieren, übersteigt meine Fähigkeiten...
    Hier der Code:
    Spoiler anzeigen

    PHP-Quellcode

    1. #!/usr/bin/php
    2. <?php
    3. require_once("libraries/TeamSpeak3/TeamSpeak3.php");
    4. require_once("settings.php");
    5. // connect to local server in non-blocking mode, authenticate and spawn an object for virtual server
    6. $ts3_VirtualServer
    7. =
    8. TeamSpeak3::factory("serverquery://".$login_name.":".$login_password."@".$ip.":".$query_port."/?server_port=".$virtualserver_port."&blocking=0");
    9. // get a list of all query clients which are connected to this virtual server
    10. $arr_ClientList = $ts3_VirtualServer->clientList(array("client_platform" => "ServerQuery"));
    11. foreach($arr_ClientList as $ts3_Client)
    12. {
    13. if($ts3_Client['client_nickname'] == $bot_name)
    14. {
    15. //there is already an active bot running
    16. $ts3_VirtualServer->request("quit");
    17. exit;
    18. }
    19. }
    20. // change nick name to the name specified in the config
    21. $ts3_VirtualServer->selfUpdate(array("client_nickname" => $bot_name));
    22. // register a callback to prevent the bot for timing out for idling
    23. TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onWaitTimeout");
    24. // register a callback to be notified about connecting clients
    25. $ts3_VirtualServer->notifyRegister("server");
    26. // this allows the bot to receive private textmessages
    27. $ts3_VirtualServer->notifyRegister("textprivate");
    28. TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyEvent", "onEvent");
    29. // main loop. waiting for events
    30. while(1)
    31. {
    32. $ts3_VirtualServer->getAdapter()->wait();
    33. }
    34. function onWaitTimeout($time, TeamSpeak3_Adapter_Abstract $adapter)
    35. {
    36. if($adapter->getQueryLastTimestamp() < time()-300)
    37. {
    38. $adapter->request('clientupdate');
    39. }
    40. }
    41. // this function is called when a textmessage is received or when a client connects to the server
    42. function onEvent(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host)
    43. {
    44. include("settings.php");
    45. $type = $event->getType();
    46. $data = $event->getData();
    47. $server = $host->serverGetSelected();
    48. if($type == "textmessage")
    49. {
    50. if($data['invokername'] == $bot_name)
    51. {
    52. return;
    53. }
    54. $invoker_uid = $data['invokeruid'];
    55. $client = $server->clientGetByUid($invoker_uid);
    56. /* if($usage_members_only != "0")
    57. {
    58. $clientlist = $server->serverGroupClientList($member_group_id);
    59. foreach($clientlist as $cl)
    60. {
    61. if($invoker_uid == $cl['client_unique_identifier'])
    62. {
    63. $permission = "ok";
    64. break;
    65. }
    66. }
    67. }*/
    68. if($usage_members_only != "0")
    69. {
    70. $member_group_ids = explode('|', $member_group_ids);
    71. foreach($member_group_ids as $member_group_id)
    72. {
    73. $clientlist = $server->serverGroupClientList($member_group_ids);
    74. foreach($clientlist as $cl)
    75. {
    76. if($invoker_uid == $cl['client_unique_identifier'])
    77. {
    78. $permission = "ok";
    79. break;
    80. }
    81. }
    82. if(isset($permission) && $permission == "ok")
    83. {
    84. break;
    85. }
    86. }
    87. }
    88. else
    89. {
    90. $permission = "ok";
    91. }
    92. if(isset($permission) && $permission == "ok")
    93. {
    94. $message = strtolower($data['msg']);
    95. if(strtolower(substr($message, '0', '6')) == "assign")
    96. {
    97. $command = "assign";
    98. $sg_name = substr($message, '7');
    99. }
    100. else if(strtolower(substr($message, '0', '6')) == "revoke")
    101. {
    102. $command = "revoke";
    103. $sg_name = substr($message, '7');
    104. }
    105. else if($message == "help" || $message == "!help" || $message == ".help")
    106. {
    107. try
    108. {
    109. $client->message($help_text);
    110. }
    111. catch(Exception $e)
    112. {
    113. }
    114. return;
    115. }
    116. else
    117. {
    118. try
    119. {
    120. $client->message("Unknown command. Type \"help\" for information about command usage.");
    121. }
    122. catch(Exception $e)
    123. {
    124. }
    125. return;
    126. }
    127. if(array_key_exists($sg_name, $server_groups))
    128. {
    129. $server_group_id = $server_groups[$sg_name];
    130. if($limit_server_groups != "0")
    131. {
    132. $groups = array();
    133. $member_of = "false";
    134. foreach(explode(",", $client["client_servergroups"]) as $sgid)
    135. {
    136. if($server_group_id == $sgid)
    137. {
    138. if($command == "assign")
    139. {
    140. try
    141. {
    142. $client->message("You are already member of that group.");
    143. return;
    144. }
    145. catch(Exception $e)
    146. {
    147. }
    148. }
    149. if($command == "revoke")
    150. {
    151. $member_of = "true";
    152. }
    153. }
    154. //only count groups which the bot can assign
    155. if(in_array($sgid, $server_groups))
    156. {
    157. $groups[] = $client->getParent()->serverGroupGetById($sgid);
    158. }
    159. }
    160. if($command == "assign")
    161. {
    162. if(count($groups) >= $limit_server_groups)
    163. {
    164. try
    165. {
    166. $client->message("You have reached the limit of server groups allowed.");
    167. }
    168. catch(Exception $e)
    169. {
    170. }
    171. }
    172. else
    173. {
    174. $sg_count = "ok";
    175. }
    176. }
    177. }
    178. if($command == "revoke" || $limit_server_groups == "0" || (isset($sg_count) && $sg_count == "ok"))
    179. {
    180. if($limit_server_groups == "0")
    181. {
    182. $member_of = "false";
    183. foreach(explode(",", $client["client_servergroups"]) as $sgid)
    184. {
    185. if($server_group_id == $sgid)
    186. {
    187. $member_of = "true";
    188. break;
    189. }
    190. }
    191. }
    192. try
    193. {
    194. if($command == "assign")
    195. {
    196. $client->addServerGroup($server_group_id);
    197. }
    198. else if($command == "revoke")
    199. {
    200. if(isset($member_of) && $member_of == "true")
    201. {
    202. $client->remServerGroup($server_group_id);
    203. }
    204. else
    205. {
    206. try
    207. {
    208. $client->message("You are not in that server group.");
    209. }
    210. catch(Exception $ex)
    211. {
    212. }
    213. }
    214. }
    215. }
    216. catch(Exception $e)
    217. {
    218. //some error occured. Maybe the group ID provided in the settings does not exist?
    219. //$client->message("An error has occured.
    220. Please contact a server admin and ask him to verify the bot settings.");
    221. }
    222. }
    223. }
    224. else
    225. {
    226. try
    227. {
    228. $client->message("You have provided an invalid server group.");
    229. }
    230. catch(Exception $e)
    231. {
    232. }
    233. }
    234. }
    235. }
    236. else if($type == "cliententerview")
    237. {
    238. $invoker_cldbid = $data['client_database_id'];
    239. $client = $server->clientGetByDbid($invoker_cldbid);
    240. if($usage_members_only != "0")
    241. {
    242. $member_group_ids = explode('|', $member_group_ids);
    243. foreach($member_group_ids as $member_group_id)
    244. {
    245. $clientlist = $server->serverGroupClientList($member_group_id);
    246. foreach($clientlist as $cl)
    247. {
    248. if($invoker_cldbid == $cl['cldbid'])
    249. {
    250. $permission = "ok";
    251. break;
    252. }
    253. }
    254. if(isset($permission) && $permission == "ok")
    255. {
    256. break;
    257. }
    258. }
    259. }
    260. else
    261. {
    262. $permission = "ok";
    263. }
    264. if(isset($permission) && $permission == "ok")
    265. {
    266. $msg = str_replace('%nickname%',$client['client_nickname'],$welcome_message);
    267. try
    268. {
    269. $client->message($msg);
    270. }
    271. catch(Exception $e)
    272. {
    273. }
    274. }
    275. }
    276. }
    277. ?>

    Meine PHP-Kentnisse sind leider noch nicht auf sehr hohem Stand, deshalb wäre ich für Lösungen/Denkanstöße dankbar :)
    LG Jonny

    Quelle des Bots:
    forum.teamspeak.com/threads/117775-Server-Group-Assign-Bot
    madmatti.de/download.php?fileID=3 (download)