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):
<?php/* here goes a list of server groups which the bot is able to assign to members* please adapt this list of server group to your requirements!* ATTENTION: make sure that there is no ID of a server admin group listed below!* NOTE: -PLEASE WRITE ALL NAMES IN LOWER CASE LETTERS-*/$server_groups = array("minecraft" => "566","testgrp" => "922","vip" => "747",);/* should there be a limit to how many server groups a client can be assigned to?* note: only server groups the client can assign count here.* set to 0 for "no limit", else to the maximum number of groups*/$limit_server_groups = "0";?>
Meine angepasste settings.php(selber Teil):
<?php/* here goes a list of server groups which the bot is able to assign to members* please adapt this list of server group to your requirements!* ATTENTION: make sure that there is no ID of a server admin group listed below!* NOTE: -PLEASE WRITE ALL NAMES IN LOWER CASE LETTERS-*/$server_groups['gamegroup'] = array("league of legends" => "12","age of empires 2" => "13","h1z1" => "14","cs:go" => "15","overwatch" => "48",);$server_groups['leagueoflegendsrank'] = array("bronze" => "39","silver" => "41","gold" => "42","platinum" => "43","diamond" => "44","master" => "45","challenger" => "46",);$server_groups['csgorank'] = array("silver 1" => "38","silver 2" => "20","silver 3" => "21","silver 4" => "22","silver elite" => "23","silver elite master" => "24","gold nova 1" => "25","gold nova 2" => "26","gold nova 3" => "27","gold nova master" => "28","master guardian 1" => "29","master guardian 2" => "30","master guardian elite" => "31","distinguished master guardian" => "32","legendary eagle" => "33","legendary eagle master" => "34","supreme master first class" => "35","the global elite" => "36",);/* should there be a limit to how many server groups a client can be assigned to?* note: only server groups the client can assign count here.* set to 0 for "no limit", else to the maximum number of groups*/$limit_server_groups['gamegroup'] = "1";$limit_server_groups['leagueoflegendsrank'] = "1";$limit_server_groups['csgorank'] = "1";?>
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:
#!/usr/bin/php
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
require_once("settings.php");
// connect to local server in non-blocking mode, authenticate and spawn an object for virtual server
$ts3_VirtualServer
=
TeamSpeak3::factory("serverquery://".$login_name.":".$login_password."@".$ip.":".$query_port."/?server_port=".$virtualserver_port."&blocking=0");
// get a list of all query clients which are connected to this virtual server
$arr_ClientList = $ts3_VirtualServer->clientList(array("client_platform" => "ServerQuery"));
foreach($arr_ClientList as $ts3_Client)
{
if($ts3_Client['client_nickname'] == $bot_name)
{
//there is already an active bot running
$ts3_VirtualServer->request("quit");
exit;
}
}
// change nick name to the name specified in the config
$ts3_VirtualServer->selfUpdate(array("client_nickname" => $bot_name));
// register a callback to prevent the bot for timing out for idling
TeamSpeak3_Helper_Signal::getInstance()->subscribe("serverqueryWaitTimeout", "onWaitTimeout");
// register a callback to be notified about connecting clients
$ts3_VirtualServer->notifyRegister("server");
// this allows the bot to receive private textmessages
$ts3_VirtualServer->notifyRegister("textprivate");
TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyEvent", "onEvent");
// main loop. waiting for events
while(1)
{
$ts3_VirtualServer->getAdapter()->wait();
}
function onWaitTimeout($time, TeamSpeak3_Adapter_Abstract $adapter)
{
if($adapter->getQueryLastTimestamp() < time()-300)
{
$adapter->request('clientupdate');
}
}
// this function is called when a textmessage is received or when a client connects to the server
function onEvent(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host)
{
include("settings.php");
$type = $event->getType();
$data = $event->getData();
$server = $host->serverGetSelected();
if($type == "textmessage")
{
if($data['invokername'] == $bot_name)
{
return;
}
$invoker_uid = $data['invokeruid'];
$client = $server->clientGetByUid($invoker_uid);
/* if($usage_members_only != "0")
{
$clientlist = $server->serverGroupClientList($member_group_id);
foreach($clientlist as $cl)
{
if($invoker_uid == $cl['client_unique_identifier'])
{
$permission = "ok";
break;
}
}
}*/
if($usage_members_only != "0")
{
$member_group_ids = explode('|', $member_group_ids);
foreach($member_group_ids as $member_group_id)
{
$clientlist = $server->serverGroupClientList($member_group_ids);
foreach($clientlist as $cl)
{
if($invoker_uid == $cl['client_unique_identifier'])
{
$permission = "ok";
break;
}
}
if(isset($permission) && $permission == "ok")
{
break;
}
}
}
else
{
$permission = "ok";
}
if(isset($permission) && $permission == "ok")
{
$message = strtolower($data['msg']);
if(strtolower(substr($message, '0', '6')) == "assign")
{
$command = "assign";
$sg_name = substr($message, '7');
}
else if(strtolower(substr($message, '0', '6')) == "revoke")
{
$command = "revoke";
$sg_name = substr($message, '7');
}
else if($message == "help" || $message == "!help" || $message == ".help")
{
try
{
$client->message($help_text);
}
catch(Exception $e)
{
}
return;
}
else
{
try
{
$client->message("Unknown command. Type \"help\" for information about command usage.");
}
catch(Exception $e)
{
}
return;
}
if(array_key_exists($sg_name, $server_groups))
{
$server_group_id = $server_groups[$sg_name];
if($limit_server_groups != "0")
{
$groups = array();
$member_of = "false";
foreach(explode(",", $client["client_servergroups"]) as $sgid)
{
if($server_group_id == $sgid)
{
if($command == "assign")
{
try
{
$client->message("You are already member of that group.");
return;
}
catch(Exception $e)
{
}
}
if($command == "revoke")
{
$member_of = "true";
}
}
//only count groups which the bot can assign
if(in_array($sgid, $server_groups))
{
$groups[] = $client->getParent()->serverGroupGetById($sgid);
}
}
if($command == "assign")
{
if(count($groups) >= $limit_server_groups)
{
try
{
$client->message("You have reached the limit of server groups allowed.");
}
catch(Exception $e)
{
}
}
else
{
$sg_count = "ok";
}
}
}
if($command == "revoke" || $limit_server_groups == "0" || (isset($sg_count) && $sg_count == "ok"))
{
if($limit_server_groups == "0")
{
$member_of = "false";
foreach(explode(",", $client["client_servergroups"]) as $sgid)
{
if($server_group_id == $sgid)
{
$member_of = "true";
break;
}
}
}
try
{
if($command == "assign")
{
$client->addServerGroup($server_group_id);
}
else if($command == "revoke")
{
if(isset($member_of) && $member_of == "true")
{
$client->remServerGroup($server_group_id);
}
else
{
try
{
$client->message("You are not in that server group.");
}
catch(Exception $ex)
{
}
}
}
}
catch(Exception $e)
{
//some error occured. Maybe the group ID provided in the settings does not exist?
//$client->message("An error has occured.
Please contact a server admin and ask him to verify the bot settings.");
}
}
}
else
{
try
{
$client->message("You have provided an invalid server group.");
}
catch(Exception $e)
{
}
}
}
}
else if($type == "cliententerview")
{
$invoker_cldbid = $data['client_database_id'];
$client = $server->clientGetByDbid($invoker_cldbid);
if($usage_members_only != "0")
{
$member_group_ids = explode('|', $member_group_ids);
foreach($member_group_ids as $member_group_id)
{
$clientlist = $server->serverGroupClientList($member_group_id);
foreach($clientlist as $cl)
{
if($invoker_cldbid == $cl['cldbid'])
{
$permission = "ok";
break;
}
}
if(isset($permission) && $permission == "ok")
{
break;
}
}
}
else
{
$permission = "ok";
}
if(isset($permission) && $permission == "ok")
{
$msg = str_replace('%nickname%',$client['client_nickname'],$welcome_message);
try
{
$client->message($msg);
}
catch(Exception $e)
{
}
}
}
}
?>
Alles anzeigen
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:
http://forum.teamspeak.com/thr…5-Server-Group-Assign-Bot
http://madmatti.de/download.php?fileID=3 (download)