release 1.00

This commit is contained in:
Newcomer1989
2016-04-17 14:11:49 +02:00
parent 5429ffb819
commit 916cb41794
112 changed files with 14170 additions and 9797 deletions

115
jobs/bot.php Normal file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/php
<?PHP
set_time_limit(0);
ini_set('default_charset', 'UTF-8');
setlocale(LC_ALL, 'UTF-8');
error_reporting(0);
echo "Initialize Bot...";
require_once(substr(__DIR__,0,-4).'other/config.php');
require_once(substr(__DIR__,0,-4).'ts3_lib/TeamSpeak3.php');
require_once(substr(__DIR__,0,-4).'jobs/calc_user.php');
require_once(substr(__DIR__,0,-4).'jobs/get_avatars.php');
require_once(substr(__DIR__,0,-4).'jobs/update_groups.php');
require_once(substr(__DIR__,0,-4).'jobs/calc_serverstats.php');
require_once(substr(__DIR__,0,-4).'jobs/calc_userstats.php');
require_once(substr(__DIR__,0,-4).'jobs/clean.php');
echo " finished\n";
function log_mysql($jobname, $mysqlcon) {
$timestamp = time();
if($mysqlcon->exec("INSERT INTO $dbname.job_log (timestamp,job_name,status) VALUES ('$timestamp','$jobname','9')") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),print_r($mysqlcon->errorInfo()),"\n";
} else {
return $jobid = $mysqlcon->lastInsertId();
}
}
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Connect to TS3 Server (Address: \"",$ts['host'],"\" Voice-Port: \"",$ts['voice'],"\" Query-Port: \"",$ts['query'],"\") ...";
try {
$ts3 = TeamSpeak3::factory("serverquery://" . $ts['user'] . ":" . $ts['pass'] . "@" . $ts['host'] . ":" . $ts['query'] . "/?server_port=" . $ts['voice'] . "&blocking=0");
echo " finished\n";
try {
usleep($slowmode);
$ts3->selfUpdate(array('client_nickname' => $queryname));
}
catch (Exception $e) {
try {
usleep($slowmode);
$ts3->selfUpdate(array('client_nickname' => $queryname2));
}
catch (Exception $e) {
echo "\n",DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),$lang['error'], $e->getCode(), ': ', $e->getMessage(),"\n";
}
}
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Join to specified Channel...";
usleep($slowmode);
$whoami = $ts3->whoami();
if($defchid != 0) {
try {
usleep($slowmode);
$ts3->clientMove($whoami['client_id'],$defchid);
echo " finished\n";
} catch (Exception $e) {
if($e->getCode() != 770) {
echo "\n",DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),$lang['error'], $e->getCode(), ': ', $e->getMessage(),"\n";
} else {
echo " finished\n";
}
}
} else {
echo " no Channel defined\n";
}
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Bot starts now his work!\n";
while(1) {
usleep($slowmode);
$ts3->clientListReset();
$allclients = $ts3->clientList();
usleep($slowmode);
$ts3->serverInfoReset();
$serverinfo = $ts3->serverInfo();
if($defchid != 0) {
try { usleep($slowmode); $ts3->clientMove($whoami['client_id'],$defchid); } catch (Exception $e) {}
}
$jobid = log_mysql('calc_user',$mysqlcon);
calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$showgen,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients);
usleep($slowmode);
$jobid = log_mysql('get_avatars',$mysqlcon);
get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone);
usleep($slowmode);
$jobid = log_mysql('update_groups',$mysqlcon);
update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo);
usleep($slowmode);
$jobid = log_mysql('calc_serverstats',$mysqlcon);
calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo,$substridle,$grouptime);
usleep($slowmode);
$jobid = log_mysql('calc_userstats',$mysqlcon);
calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone);
usleep($slowmode);
$jobid = log_mysql('clean',$mysqlcon);
clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$cleanclients,$cleanperiod);
usleep($slowmode);
//check auf fehler in job_log
if(!is_file(substr(__DIR__,0,-4).'logs/pid')) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Received signal to stop. Shutting down...\n";
exit;
}
}
}
catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),$lang['error'] . $e->getCode() . ': ' . $e->getMessage(),"\n";
$offline_status = array(110,257,258,1024,1026,1031,1032,1033,1034,1280,1793);
if(in_array($e->getCode(), $offline_status)) {
if($mysqlcon->exec("UPDATE $dbname.stats_server SET server_status='0'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),$lang['error'],print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
?>

317
jobs/calc_serverstats.php Normal file
View File

@@ -0,0 +1,317 @@
<?PHP
function calc_serverstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo,$substridle,$grouptime) {
$starttime = microtime(true);
$nowtime = time();
$sqlmsg = '';
$sqlerr = 0;
$total_user = 0;
$total_online_time = 0;
$total_active_time = 0;
$total_inactive_time = 0;
$country_string = '';
$platform_string = '';
$server_used_slots = 0;
$server_channel_amount = 0;
if(($uuids = $mysqlcon->query("SELECT uuid,count,idle,platform,nation FROM $dbname.user")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 1:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$uuids = $uuids->fetchAll();
foreach($uuids as $uuid) {
$sqlhis[$uuid['uuid']] = array(
"uuid" => $uuid['uuid'],
"count" => $uuid['count'],
"idle" => $uuid['idle']
);
if ($uuid['nation']!=NULL) $country_string .= $uuid['nation'] . ' ';
if ($uuid['platform']!=NULL) {
$uuid_platform = str_replace(' ','',$uuid['platform']);
$platform_string .= $uuid_platform . ' ';
}
$total_online_time = $total_online_time + $uuid['count'];
$total_active_time = $total_active_time + $uuid['count'] - $uuid['idle'];
$total_inactive_time = $total_inactive_time + $uuid['idle'];
}
// Event Handling each 6 hours
// Duplicate users Table in snapshot Table
if(($max_entry_usersnap = $mysqlcon->query("SELECT MAX(DISTINCT(timestamp)) AS timestamp FROM $dbname.user_snapshot")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 2:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$max_entry_usersnap = $max_entry_usersnap->fetch(PDO::FETCH_ASSOC);
$diff_max_usersnap = $nowtime - $max_entry_usersnap['timestamp'];
if($diff_max_usersnap > 21600) {
if(isset($sqlhis)) {
$allinsertsnap = '';
foreach ($sqlhis as $insertsnap) {
$allinsertsnap = $allinsertsnap . "('$nowtime','" . $insertsnap['uuid'] . "', '" . $insertsnap['count'] . "', '" . $insertsnap['idle'] . "'),";
}
$allinsertsnap = substr($allinsertsnap, 0, -1);
if ($allinsertsnap != '') {
if($mysqlcon->exec("INSERT INTO $dbname.user_snapshot (timestamp, uuid, count, idle) VALUES $allinsertsnap") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 3:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
//Delete old Entries in user_snapshot
$deletiontime = $nowtime - 2678400;
if($mysqlcon->exec("DELETE FROM $dbname.user_snapshot WHERE timestamp=$deletiontime") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 4:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
if($serverinfo['virtualserver_status']=="online") {
$server_status = 1;
} elseif($serverinfo['virtualserver_status']=="offline") {
$server_status = 2;
} elseif($serverinfo['virtualserver_status']=="virtual online") {
$server_status = 3;
} else {
$server_status = 4;
}
// Calc Values for server stats
if(($entry_snapshot_count = $mysqlcon->query("SELECT count(DISTINCT(timestamp)) AS timestamp FROM $dbname.user_snapshot")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 5:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$entry_snapshot_count = $entry_snapshot_count->fetch(PDO::FETCH_ASSOC);
if ($entry_snapshot_count['timestamp'] > 27) {
// Calc total_online_week
if(($snapshot_count_week = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) AS count")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 6:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$snapshot_count_week = $snapshot_count_week->fetch(PDO::FETCH_ASSOC);
$total_online_week = $snapshot_count_week['count'];
} else {
$total_online_week = 0;
}
if ($entry_snapshot_count['timestamp'] > 119) {
// Calc total_online_month
if(($snapshot_count_month = $mysqlcon->query("SELECT (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) - (SELECT SUM(count) FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)) AS count")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 7:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$snapshot_count_month = $snapshot_count_month->fetch(PDO::FETCH_ASSOC);
$total_online_month = $snapshot_count_month['count'];
} else {
$total_online_month = 0;
}
$country_array = array_count_values(str_word_count($country_string, 1));
arsort($country_array);
$country_counter = 0;
$country_nation_other = 0;
$country_nation_name_2 = 0;
$country_nation_name_3 = 0;
$country_nation_name_4 = 0;
$country_nation_name_5 = 0;
$country_nation_2 = 0;
$country_nation_3 = 0;
$country_nation_4 = 0;
$country_nation_5 = 0;
foreach ($country_array as $k => $v) {
$country_counter++;
if ($country_counter == 1) {
$country_nation_name_1 = $k;
$country_nation_1 = $v;
} elseif ($country_counter == 2) {
$country_nation_name_2 = $k;
$country_nation_2 = $v;
} elseif ($country_counter == 3) {
$country_nation_name_3 = $k;
$country_nation_3 = $v;
} elseif ($country_counter == 4) {
$country_nation_name_4 = $k;
$country_nation_4 = $v;
} elseif ($country_counter == 5) {
$country_nation_name_5 = $k;
$country_nation_5 = $v;
} else {
$country_nation_other = $country_nation_other + $v;
}
}
$platform_array = array_count_values(str_word_count($platform_string, 1));
$platform_other = 0;
$platform_1 = 0;
$platform_2 = 0;
$platform_3 = 0;
$platform_4 = 0;
$platform_5 = 0;
foreach ($platform_array as $k => $v) {
if ($k == "Windows") {
$platform_1 = $v;
} elseif ($k == "iOS") {
$platform_2 = $v;
} elseif ($k == "Linux") {
$platform_3 = $v;
} elseif ($k == "Android") {
$platform_4 = $v;
} elseif ($k == "OSX") {
$platform_5 = $v;
} else {
$platform_other = $platform_other + $v;
}
}
$version_1 = 0;
$version_2 = 0;
$version_3 = 0;
$version_4 = 0;
$version_5 = 0;
$version_name_1 = 0;
$version_name_2 = 0;
$version_name_3 = 0;
$version_name_4 = 0;
$version_name_5 = 0;
$client_versions = $mysqlcon->query("SELECT version, COUNT(version) AS count FROM $dbname.user GROUP BY version ORDER BY count DESC LIMIT 5")->fetchAll(PDO::FETCH_ASSOC);
$count_version = 0;
$version_other = $mysqlcon->query("SELECT COUNT(version) AS count FROM $dbname.user ORDER BY count DESC")->fetchAll(PDO::FETCH_ASSOC);
foreach($client_versions as $version) {
$count_version++;
if ($count_version == 1) {
$version_1 = $version['count'];
$version_name_1 = $version['version'];
} elseif ($count_version == 2) {
$version_2 = $version['count'];
$version_name_2 = $version['version'];
} elseif ($count_version == 3) {
$version_3 = $version['count'];
$version_name_3 = $version['version'];
} elseif ($count_version == 4) {
$version_4 = $version['count'];
$version_name_4 = $version['version'];
} elseif ($count_version == 5) {
$version_5 = $version['count'];
$version_name_5 = $version['version'];
}
}
$version_other = $version_other[0]['count'] - $version_1 + $version_2 + $version_3 + $version_4 + $version_5;
$total_user = count($sqlhis);
$server_used_slots = $serverinfo['virtualserver_clientsonline'] - $serverinfo['virtualserver_queryclientsonline'];
$server_free_slots = $serverinfo['virtualserver_maxclients'] - $server_used_slots;
$server_channel_amount = $serverinfo['virtualserver_channelsonline'];
$server_ping = $serverinfo['virtualserver_total_ping'];
$server_packet_loss = $serverinfo['virtualserver_total_packetloss_total'];
$server_bytes_down = $serverinfo['connection_bytes_received_total'];
$server_bytes_up = $serverinfo['connection_bytes_sent_total'];
$server_uptime = $serverinfo['virtualserver_uptime'];
$server_id = $serverinfo['virtualserver_id'];
$server_name = $serverinfo['virtualserver_name'];
$server_pass = $serverinfo['virtualserver_flag_password'];
$server_creation_date = $serverinfo['virtualserver_created'];
$server_platform = $serverinfo['virtualserver_platform'];
$server_weblist = $serverinfo['virtualserver_weblist_enabled'];
$server_version = $serverinfo['virtualserver_version'];
if($mysqlcon->exec("UPDATE $dbname.stats_server SET total_user='$total_user', total_online_time='$total_online_time', total_online_month='$total_online_month', total_online_week='$total_online_week', total_active_time='$total_active_time', total_inactive_time='$total_inactive_time', country_nation_name_1='$country_nation_name_1', country_nation_name_2='$country_nation_name_2', country_nation_name_3='$country_nation_name_3', country_nation_name_4='$country_nation_name_4', country_nation_name_5='$country_nation_name_5', country_nation_1='$country_nation_1', country_nation_2='$country_nation_2', country_nation_3='$country_nation_3', country_nation_4='$country_nation_4', country_nation_5='$country_nation_5', country_nation_other='$country_nation_other', platform_1='$platform_1', platform_2='$platform_2', platform_3='$platform_3', platform_4='$platform_4', platform_5='$platform_5', platform_other='$platform_other', version_name_1='$version_name_1', version_name_2='$version_name_2', version_name_3='$version_name_3', version_name_4='$version_name_4', version_name_5='$version_name_5', version_1='$version_1', version_2='$version_2', version_3='$version_3', version_4='$version_4', version_5='$version_5', version_other='$version_other', version_name_1='$version_name_1', server_status='$server_status', server_free_slots='$server_free_slots', server_used_slots='$server_used_slots', server_channel_amount='$server_channel_amount', server_ping='$server_ping', server_packet_loss='$server_packet_loss', server_bytes_down='$server_bytes_down', server_bytes_up='$server_bytes_up', server_uptime='$server_uptime', server_id='$server_id', server_name='$server_name', server_pass='$server_pass', server_creation_date='$server_creation_date', server_platform='$server_platform', server_weblist='$server_weblist', server_version='$server_version'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 8:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
// Stats for Server Usage
if(($max_entry_serverusage = $mysqlcon->query("SELECT MAX(timestamp) AS timestamp FROM $dbname.server_usage")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 9:",print_r($mysqlcon->errorInfo()),"\n";
$sqlerr++;
}
$max_entry_serverusage = $max_entry_serverusage->fetch(PDO::FETCH_ASSOC);
$diff_max_serverusage = $nowtime - $max_entry_serverusage['timestamp'];
if ($max_entry_serverusage['timestamp'] == 0 || $diff_max_serverusage > 899) { // every 15 mins
if($mysqlcon->exec("INSERT INTO $dbname.server_usage (timestamp, clients, channel) VALUES ($nowtime,$server_used_slots,$server_channel_amount)") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 10:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
//Calc time next rankup
$upnextuptime = $nowtime - 86400;
if(($uuidsoff = $mysqlcon->query("SELECT uuid,idle,count FROM $dbname.user WHERE online<>1 AND lastseen>$upnextuptime")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 11:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($uuidsoff->rowCount() != 0) {
$uuidsoff = $uuidsoff->fetchAll(PDO::FETCH_ASSOC);
foreach($uuidsoff as $uuid) {
$idle = $uuid['idle'];
$count = $uuid['count'];
if ($substridle == 1) {
$activetime = $count - $idle;
$dtF = new DateTime("@0");
$dtT = new DateTime("@$activetime");
} else {
$activetime = $count;
$dtF = new DateTime("@0");
$dtT = new DateTime("@$count");
}
foreach ($grouptime as $time => $groupid) {
if ($activetime > $time) {
$nextup = 0;
} else {
$nextup = $time - $activetime;
}
}
$updatenextup[] = array(
"uuid" => $uuid['uuid'],
"nextup" => $nextup
);
}
}
if (isset($updatenextup)) {
$allupdateuuid = '';
$allupdatenextup = '';
foreach ($updatenextup as $updatedata) {
$allupdateuuid = $allupdateuuid . "'" . $updatedata['uuid'] . "',";
$allupdatenextup = $allupdatenextup . "WHEN '" . $updatedata['uuid'] . "' THEN '" . $updatedata['nextup'] . "' ";
}
$allupdateuuid = substr($allupdateuuid, 0, -1);
if ($mysqlcon->exec("UPDATE $dbname.user set nextup = CASE uuid $allupdatenextup END WHERE uuid IN ($allupdateuuid)") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 12:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
//Calc Rank
if($mysqlcon->exec("SET @a:=0") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 13:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if($mysqlcon->exec("UPDATE $dbname.user u INNER JOIN (SELECT @a:=@a+1 nr,uuid FROM $dbname.user WHERE except!=1 ORDER BY count DESC) s USING (uuid) SET u.rank=s.nr") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 14:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$buildtime = microtime(true) - $starttime;
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 15:",print_r($mysqlcon->errorInfo()),"\n";
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_serverstats 16:",print_r($mysqlcon->errorInfo()),"\n";
}
}
}
?>

357
jobs/calc_user.php Normal file
View File

@@ -0,0 +1,357 @@
<?PHP
function calc_user($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$showgen,$update,$grouptime,$boostarr,$resetbydbchange,$msgtouser,$uniqueid,$updateinfotime,$currvers,$substridle,$exceptuuid,$exceptgroup,$allclients) {
$starttime = microtime(true);
$nowtime = time();
$sqlmsg = '';
$sqlerr = 0;
if ($update == 1) {
$updatetime = $nowtime - $updateinfotime;
if(($lastupdate = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_update'")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 1:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$lastupdate = $lastupdate->fetchAll();
if ($lastupdate[0]['timestamp'] < $updatetime) {
set_error_handler(function() { });
$newversion = file_get_contents('http://ts-n.net/ranksystem/version');
restore_error_handler();
if (substr($newversion, 0, 4) != substr($currvers, 0, 4) && $newversion != '') {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),$lang['upinf'],"\n";
foreach ($uniqueid as $clientid) {
usleep($slowmode);
try {
$ts3->clientGetByUid($clientid)->message(sprintf($lang['upmsg'], $currvers, $newversion));
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['upusrinf'], $clientid),"\n";
}
catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['upusrerr'], $clientid),"\n";
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
}
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp=$nowtime WHERE job_name='check_update'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 3:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
if(($dbdata = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='calc_user_lastscan'")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 4:",print_r($mysqlcon->errorInfo()),"\n";
exit;
}
$lastscanarr = $dbdata->fetchAll();
$lastscan = $lastscanarr[0]['timestamp'];
if($lastscan < ($nowtime - 86400)) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Much time gone since last scan.. reset time difference to zero.\n";
$lastscan = $nowtime;
}
if ($dbdata->rowCount() != 0) {
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='calc_user_lastscan'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 5:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if(($dbuserdata = $mysqlcon->query("SELECT uuid,cldbid,count,grpid,nextup,idle,boosttime FROM $dbname.user")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 6:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$uuids = $dbuserdata->fetchAll();
foreach($uuids as $uuid) {
$sqlhis[$uuid['uuid']] = array(
"uuid" => $uuid['uuid'],
"cldbid" => $uuid['cldbid'],
"count" => $uuid['count'],
"grpid" => $uuid['grpid'],
"nextup" => $uuid['nextup'],
"idle" => $uuid['idle'],
"boosttime" => $uuid['boosttime']
);
$uidarr[] = $uuid['uuid'];
}
}
unset($uuids);
usleep($slowmode);
$yetonline[] = '';
$insertdata = '';
if(empty($grouptime)) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 7:",$lang['wiconferr'],"\n";
exit;
}
krsort($grouptime);
$sumentries = 0;
$boosttime = 0;
$nextupforinsert = key($grouptime) - 1;
foreach ($allclients as $client) {
$sumentries++;
$cldbid = $client['client_database_id'];
$ip = ip2long($client['connection_client_ip']);
$name = str_replace('\\', '\\\\', htmlspecialchars($client['client_nickname'], ENT_QUOTES));
$uid = htmlspecialchars($client['client_unique_identifier'], ENT_QUOTES);
$cldgroup = $client['client_servergroups'];
$sgroups = explode(",", $cldgroup);
$platform=$client['client_platform'];
$nation=$client['client_country'];
$version=$client['client_version'];
$firstconnect=$client['client_created'];
if (!in_array($uid, $yetonline) && $client['client_version'] != "ServerQuery") {
$clientidle = floor($client['client_idle_time'] / 1000);
$yetonline[] = $uid;
if(in_array($uid, $exceptuuid) || array_intersect($sgroups, $exceptgroup)) {
$except = 1;
} else {
$except = 0;
}
if (in_array($uid, $uidarr)) {
$idle = $sqlhis[$uid]['idle'] + $clientidle;
$grpid = $sqlhis[$uid]['grpid'];
$nextup = $sqlhis[$uid]['nextup'];
if ($sqlhis[$uid]['cldbid'] != $cldbid && $resetbydbchange == 1) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['changedbid'], $name, $uid, $cldbid, $sqlhis[$uid]['cldbid']),"\n";
$count = 1;
$idle = 0;
} else {
$hitboost = 0;
if($boostarr!=0) {
foreach($boostarr as $boost) {
if(in_array($boost['group'], $sgroups)) {
$boostfactor = $boost['factor'];
$hitboost = 1;
$boosttime = $sqlhis[$uid]['boosttime'];
if($sqlhis[$uid]['boosttime']==0) {
$boosttime = $nowtime;
} else {
if ($nowtime > $sqlhis[$uid]['boosttime'] + $boost['time']) {
usleep($slowmode);
try {
$ts3->serverGroupClientDel($boost['group'], $cldbid);
$boosttime = 0;
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['sgrprm'], $sqlhis[$uid]['grpid'], $name, $uid, $cldbid),"\n";
}
catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 8:",sprintf($lang['sgrprerr'], $name, $uid, $cldbid),"\n";
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
}
$count = ($nowtime - $lastscan) * $boost['factor'] + $sqlhis[$uid]['count'];
if ($clientidle > ($nowtime - $lastscan)) {
$idle = ($nowtime - $lastscan) * $boost['factor'] + $sqlhis[$uid]['idle'];
}
}
}
}
if($boostarr == 0 or $hitboost == 0) {
$count = $nowtime - $lastscan + $sqlhis[$uid]['count'];
if ($clientidle > ($nowtime - $lastscan)) {
$idle = $nowtime - $lastscan + $sqlhis[$uid]['idle'];
}
}
}
$dtF = new DateTime("@0");
if ($substridle == 1) {
$activetime = $count - $idle;
} else {
$activetime = $count;
}
$dtT = new DateTime("@$activetime");
foreach ($grouptime as $time => $groupid) {
if (in_array($groupid, $sgroups)) {
$grpid = $groupid;
break;
}
}
$grpcount=0;
foreach ($grouptime as $time => $groupid) {
$grpcount++;
if ($activetime > $time && !in_array($uid, $exceptuuid) && !array_intersect($sgroups, $exceptgroup)) {
if ($sqlhis[$uid]['grpid'] != $groupid) {
if ($sqlhis[$uid]['grpid'] != 0 && in_array($sqlhis[$uid]['grpid'], $sgroups)) {
usleep($slowmode);
try {
$ts3->serverGroupClientDel($sqlhis[$uid]['grpid'], $cldbid);
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['sgrprm'], $sqlhis[$uid]['grpid'], $name, $uid, $cldbid),"\n";
}
catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 9:",sprintf($lang['sgrprerr'], $name, $uid, $cldbid),"\n";
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
if (!in_array($groupid, $sgroups)) {
usleep($slowmode);
try {
$ts3->serverGroupClientAdd($groupid, $cldbid);
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['sgrpadd'], $groupid, $name, $uid, $cldbid),"\n";
}
catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 10:",sprintf($lang['sgrprerr'], $name, $uid, $cldbid),"\n";
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
$grpid = $groupid;
if ($msgtouser == 1) {
usleep($slowmode);
$days = $dtF->diff($dtT)->format('%a');
$hours = $dtF->diff($dtT)->format('%h');
$mins = $dtF->diff($dtT)->format('%i');
$secs = $dtF->diff($dtT)->format('%s');
if ($substridle == 1) {
try {
$ts3->clientGetByUid($uid)->message(sprintf($lang['usermsgactive'], $days, $hours, $mins, $secs));
} catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 11:",sprintf($lang['sgrprerr'], $name, $uid, $cldbid),"\n";
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
} else {
try {
$ts3->clientGetByUid($uid)->message(sprintf($lang['usermsgonline'], $days, $hours, $mins, $secs));
} catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 12:",sprintf($lang['sgrprerr'], $name, $uid, $cldbid),"\n";
$sqlmsg .= $e->getCode() . ': ' . $e->getMessage();
$sqlerr++;
}
}
}
}
if($grpcount == 1) {
$nextup = 0;
}
break;
} else {
$nextup = $time - $activetime;
}
}
$updatedata[] = array(
"uuid" => $uid,
"cldbid" => $cldbid,
"count" => $count,
"ip" => $ip,
"name" => $name,
"lastseen" => $nowtime,
"grpid" => $grpid,
"nextup" => $nextup,
"idle" => $idle,
"cldgroup" => $cldgroup,
"boosttime" => $boosttime,
"platform" => $platform,
"nation" => $nation,
"version" => $version,
"except" => $except
);
} else {
$grpid = '0';
foreach ($grouptime as $time => $groupid) {
if (in_array($groupid, $sgroups)) {
$grpid = $groupid;
break;
}
}
$insertdata[] = array(
"uuid" => $uid,
"cldbid" => $cldbid,
"ip" => $ip,
"name" => $name,
"lastseen" => $nowtime,
"grpid" => $grpid,
"nextup" => $nextupforinsert,
"cldgroup" => $cldgroup,
"platform" => $platform,
"nation" => $nation,
"version" => $version,
"firstcon" => $firstconnect,
"except" => $except
);
$uidarr[] = $uid;
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['adduser'], $name, $uid, $cldbid),"\n";
}
}
}
if($mysqlcon->exec("UPDATE $dbname.user SET online='0'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 13:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($insertdata != '') {
$allinsertdata = '';
foreach ($insertdata as $insertarr) {
$allinsertdata = $allinsertdata . "('" . $insertarr['uuid'] . "', '" . $insertarr['cldbid'] . "', '1', '" . $insertarr['ip'] . "', '" . $insertarr['name'] . "', '" . $insertarr['lastseen'] . "', '" . $insertarr['grpid'] . "', '" . $insertarr['nextup'] . "', '" . $insertarr['cldgroup'] . "', '" . $insertarr['platform'] . "', '" . $insertarr['nation'] . "', '" . $insertarr['version'] . "', '" . $insertarr['firstcon'] . "', '" . $insertarr['except'] . "','1'),";
}
$allinsertdata = substr($allinsertdata, 0, -1);
if ($allinsertdata != '') {
if($mysqlcon->exec("INSERT INTO $dbname.user (uuid, cldbid, count, ip, name, lastseen, grpid, nextup, cldgroup, platform, nation, version, firstcon, except, online) VALUES $allinsertdata") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 14:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
unset($insertdata);
unset($allinsertdata);
if ($updatedata != 0) {
$allupdateuuid = '';
$allupdatecldbid = '';
$allupdatecount = '';
$allupdateip = '';
$allupdatename = '';
$allupdatelastseen = '';
$allupdategrpid = '';
$allupdatenextup = '';
$allupdateidle = '';
$allupdatecldgroup = '';
$allupdateboosttime = '';
$allupdateplatform = '';
$allupdatenation = '';
$allupdateversion = '';
$allupdateexcept = '';
foreach ($updatedata as $updatearr) {
$allupdateuuid = $allupdateuuid . "'" . $updatearr['uuid'] . "',";
$allupdatecldbid = $allupdatecldbid . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['cldbid'] . "' ";
$allupdatecount = $allupdatecount . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['count'] . "' ";
$allupdateip = $allupdateip . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['ip'] . "' ";
$allupdatename = $allupdatename . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['name'] . "' ";
$allupdatelastseen = $allupdatelastseen . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['lastseen'] . "' ";
$allupdategrpid = $allupdategrpid . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['grpid'] . "' ";
$allupdatenextup = $allupdatenextup . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['nextup'] . "' ";
$allupdateidle = $allupdateidle . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['idle'] . "' ";
$allupdatecldgroup = $allupdatecldgroup . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['cldgroup'] . "' ";
$allupdateboosttime = $allupdateboosttime . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['boosttime'] . "' ";
$allupdateplatform = $allupdateplatform . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['platform'] . "' ";
$allupdatenation = $allupdatenation . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['nation'] . "' ";
$allupdateversion = $allupdateversion . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['version'] . "' ";
$allupdateexcept = $allupdateexcept . "WHEN '" . $updatearr['uuid'] . "' THEN '" . $updatearr['except'] . "' ";
}
$allupdateuuid = substr($allupdateuuid, 0, -1);
if($mysqlcon->exec("UPDATE $dbname.user set cldbid = CASE uuid $allupdatecldbid END, count = CASE uuid $allupdatecount END, ip = CASE uuid $allupdateip END, name = CASE uuid $allupdatename END, lastseen = CASE uuid $allupdatelastseen END, grpid = CASE uuid $allupdategrpid END, nextup = CASE uuid $allupdatenextup END, idle = CASE uuid $allupdateidle END, cldgroup = CASE uuid $allupdatecldgroup END, boosttime = CASE uuid $allupdateboosttime END, platform = CASE uuid $allupdateplatform END, nation = CASE uuid $allupdatenation END, version = CASE uuid $allupdateversion END, except = CASE uuid $allupdateexcept END, online = 1 WHERE uuid IN ($allupdateuuid)") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 15:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
$buildtime = microtime(true) - $starttime;
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 16:",print_r($mysqlcon->errorInfo()),"\n";
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_user 17:",print_r($mysqlcon->errorInfo()),"\n";
}
}
}
?>

178
jobs/calc_userstats.php Normal file
View File

@@ -0,0 +1,178 @@
<?PHP
function calc_userstats($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
if(($count_user = $mysqlcon->query("SELECT count(*) as count FROM ((SELECT u.uuid FROM $dbname.user AS u INNER JOIN $dbname.stats_user As s On u.uuid=s.uuid) UNION (SELECT u.uuid FROM $dbname.user AS u LEFT JOIN $dbname.stats_user As s On u.uuid=s.uuid WHERE s.uuid IS NULL)) x")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 1:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$count_user = $count_user->fetchAll(PDO::FETCH_ASSOC);
$total_user = $count_user[0]['count'];
if(($job_begin = $mysqlcon->query("SELECT timestamp FROM $dbname.job_check WHERE job_name='calc_user_limit'")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 2:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$job_begin = $job_begin->fetchAll();
$job_begin = $job_begin[0]['timestamp'];
$job_end = ceil($total_user / 10) * 10;
if ($job_begin >= $job_end) {
$job_begin = 0;
$job_end = 10;
} else {
$job_end = $job_begin + 10;
}
if(($uuids = $mysqlcon->query("(SELECT u.uuid,u.rank,u.cldbid FROM $dbname.user AS u INNER JOIN $dbname.stats_user As s On u.uuid=s.uuid) UNION (SELECT u.uuid,u.rank,u.cldbid FROM $dbname.user AS u LEFT JOIN $dbname.stats_user As s On u.uuid=s.uuid WHERE s.uuid IS NULL) ORDER BY cldbid ASC LIMIT $job_begin, 10")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 3:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$uuids = $uuids->fetchAll();
foreach($uuids as $uuid) {
$sqlhis[$uuid['uuid']] = array(
"uuid" => $uuid['uuid'],
"rank" => $uuid['rank'],
"cldbid" => $uuid['cldbid']
);
}
// Calc Client Stats
if ($mysqlcon->exec("UPDATE $dbname.stats_user AS t LEFT JOIN $dbname.user AS u ON t.uuid=u.uuid SET t.removed='1' WHERE u.uuid IS NULL") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 4:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if(($statsuserhis = $mysqlcon->query("SELECT uuid, removed FROM $dbname.stats_user")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 5:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$statsuserhis = $statsuserhis->fetchAll();
foreach($statsuserhis as $userhis) {
$uidarrstats[$userhis['uuid']] = $userhis['removed'];
}
unset($statsuserhis);
if(isset($sqlhis)) {
//echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Update User Stats between ",$job_begin," and ",$job_end,":\n";
if(($userdataweekbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 6:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdataweekbegin = $userdataweekbegin->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
if(($userdataweekend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 28) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 7:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdataweekend = $userdataweekend->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
if(($userdatamonthbegin = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MIN(s2.timestamp) AS value2 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 8:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdatamonthbegin = $userdatamonthbegin->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
if(($userdatamonthend = $mysqlcon->query("SELECT uuid,count,idle FROM $dbname.user_snapshot WHERE timestamp=(SELECT MAX(s2.timestamp) AS value1 FROM (SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 120) AS s2, $dbname.user_snapshot AS s1 WHERE s1.timestamp=s2.timestamp)")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 9:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$userdatamonthend = $userdatamonthend->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$allupdateuuid = '';
$allupdaterank = '';
$allupdatecountw = '';
$allupdatecountm = '';
$allupdateidlew = '';
$allupdateidlem = '';
$allupdatetotac = '';
$allupdatebase64 = '';
$allupdatecldtup = '';
$allupdatecldtdo = '';
$allupdateclddes = '';
$allinsertuserstats = '';
foreach ($sqlhis as $userstats) {
try {
$clientinfo = $ts3->clientInfoDb($userstats['cldbid']);
if(isset($userdataweekend[$userstats['uuid']]) && isset($userdataweekbegin[$userstats['uuid']])) {
$count_week = $userdataweekend[$userstats['uuid']][0]['count'] - $userdataweekbegin[$userstats['uuid']][0]['count'];
$idle_week = $userdataweekend[$userstats['uuid']][0]['idle'] - $userdataweekbegin[$userstats['uuid']][0]['idle'];
} else {
$count_week = 0;
$idle_week = 0;
}
if(isset($userdatamonthend[$userstats['uuid']]) && isset($userdatamonthbegin[$userstats['uuid']])) {
$count_month = $userdatamonthend[$userstats['uuid']][0]['count'] - $userdatamonthbegin[$userstats['uuid']][0]['count'];
$idle_month = $userdatamonthend[$userstats['uuid']][0]['idle'] - $userdatamonthbegin[$userstats['uuid']][0]['idle'];
} else {
$count_month = 0;
$idle_month = 0;
}
if(isset($uidarrstats[$userstats['uuid']])) {
$allupdateuuid = $allupdateuuid . "'" . $userstats['uuid'] . "',";
$allupdaterank = $allupdaterank . "WHEN '" . $userstats['uuid'] . "' THEN '" . $userstats['rank'] . "' ";
$allupdatecountw = $allupdatecountw . "WHEN '" . $userstats['uuid'] . "' THEN '" . $count_week . "' ";
$allupdatecountm = $allupdatecountm . "WHEN '" . $userstats['uuid'] . "' THEN '" . $count_month . "' ";
$allupdateidlew = $allupdateidlew . "WHEN '" . $userstats['uuid'] . "' THEN '" . $idle_week . "' ";
$allupdateidlem = $allupdateidlem . "WHEN '" . $userstats['uuid'] . "' THEN '" . $idle_month . "' ";
$allupdatetotac = $allupdatetotac . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_totalconnections'] . "' ";
$allupdatebase64 = $allupdatebase64 . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_base64HashClientUID'] . "' ";
$allupdatecldtup = $allupdatecldtup . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_total_bytes_uploaded'] . "' ";
$allupdatecldtdo = $allupdatecldtdo . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_total_bytes_downloaded'] . "' ";
$allupdateclddes = $allupdateclddes . "WHEN '" . $userstats['uuid'] . "' THEN '" . $clientinfo['client_description'] . "' ";
} else {
$allinsertuserstats = $allinsertuserstats . "('" . $userstats['uuid'] . "', '" .$userstats['rank'] . "', '" . $count_week . "', '" . $count_month . "', '" . $idle_week . "', '" . $idle_month . "', '" . $clientinfo['client_totalconnections'] . "', '" . $clientinfo['client_base64HashClientUID'] . "', '" . $clientinfo['client_total_bytes_uploaded'] . "', '" . $clientinfo['client_total_bytes_downloaded'] . "', '" . $clientinfo['client_description'] . "'),";
}
} catch (Exception $e) {
//error would be, when client is missing in ts db
}
}
if ($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp=$job_end WHERE job_name='calc_user_limit'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 11:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($allupdateuuid != '') {
$allupdateuuid = substr($allupdateuuid, 0, -1);
if ($mysqlcon->exec("UPDATE $dbname.stats_user set rank = CASE uuid $allupdaterank END, count_week = CASE uuid $allupdatecountw END, count_month = CASE uuid $allupdatecountm END, idle_week = CASE uuid $allupdateidlew END, idle_month = CASE uuid $allupdateidlem END, total_connections = CASE uuid $allupdatetotac END, base64hash = CASE uuid $allupdatebase64 END, client_total_up = CASE uuid $allupdatecldtup END, client_total_down = CASE uuid $allupdatecldtdo END, client_description = CASE uuid $allupdateclddes END WHERE uuid IN ($allupdateuuid)") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 12:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
if($allinsertuserstats != '') {
$allinsertuserstats = substr($allinsertuserstats, 0, -1);
if ($mysqlcon->exec("INSERT INTO $dbname.stats_user (uuid,rank,count_week,count_month,idle_week,idle_month,total_connections,base64hash,client_total_up,client_total_down,client_description) VALUES $allinsertuserstats") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 13:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
$buildtime = microtime(true) - $starttime;
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 14:",print_r($mysqlcon->errorInfo()),"\n";
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"calc_userstats 15:",print_r($mysqlcon->errorInfo()),"\n";
}
}
}
?>

118
jobs/clean.php Normal file
View File

@@ -0,0 +1,118 @@
<?PHP
function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$cleanclients,$cleanperiod) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
$count_tsuser['count'] = 0;
$nowtime = time();
// clean old logs
if($mysqlcon->query("DELETE a FROM $dbname.job_log AS a CROSS JOIN(SELECT id FROM $dbname.job_log ORDER BY id DESC LIMIT 1 OFFSET 1000) AS b WHERE b.id>a.id") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 1:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
// clean usersnaps older then 1 month
if($mysqlcon->query("DELETE a FROM $dbname.user_snapshot AS a CROSS JOIN(SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 1000 OFFSET 121) AS b WHERE a.timestamp=b.timestamp") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 2:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
// clean old clients out of the database
if ($cleanclients == 1) {
$cleantime = $nowtime - $cleanperiod;
if(($lastclean = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_clean'")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 3:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$lastclean = $lastclean->fetchAll();
if(($dbuserdata = $mysqlcon->query("SELECT uuid FROM $dbname.user")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 4:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
$countrs = $dbuserdata->rowCount();
$uuids = $dbuserdata->fetchAll();
if ($lastclean[0]['timestamp'] < $cleantime) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),$lang['clean'],"\n";
$start=0;
$break=200;
$clientdblist=array();
$countdel=0;
$countts=0;
while($getclientdblist=$ts3->clientListDb($start, $break)) {
$clientdblist=array_merge($clientdblist, $getclientdblist);
$start=$start+$break;
$count_tsuser=array_shift($getclientdblist);
if ($start == 100000 || $count_tsuser['count'] <= $start) {
break;
}
usleep($slowmode);
}
foreach($clientdblist as $uuidts) {
$single_uuid = $uuidts['client_unique_identifier']->toString();
$uidarrts[$single_uuid]= 1;
}
unset($clientdblist);
foreach($uuids as $uuid) {
if(isset($uidarrts[$uuid[0]])) {
$countts++;
} else {
$deleteuuids[] = $uuid[0];
$countdel++;
}
}
unset($uidarrts);
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['cleants'], $countts, $count_tsuser['count']),"\n";
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['cleanrs'], $countrs),"\n";
if(isset($deleteuuids)) {
$alldeldata = '';
foreach ($deleteuuids as $dellarr) {
$alldeldata = $alldeldata . "'" . $dellarr . "',";
}
$alldeldata = substr($alldeldata, 0, -1);
$alldeldata = "(".$alldeldata.")";
if ($alldeldata != '') {
if($mysqlcon->exec("DELETE FROM $dbname.user WHERE uuid IN $alldeldata") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 5:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
} else {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),sprintf($lang['cleandel'], $countdel),"\n";
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 6:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
} else {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),$lang['cleanno'],"\n";
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 7:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
}
$buildtime = microtime(true) - $starttime;
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 8:",print_r($mysqlcon->errorInfo()),"\n";
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"clean 9:",print_r($mysqlcon->errorInfo()),"\n";
}
}
}
?>

63
jobs/get_avatars.php Normal file
View File

@@ -0,0 +1,63 @@
<?PHP
function get_avatars($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
$count = 0;
try {
usleep($slowmode);
$tsfilelist = $ts3->channelFileList($cid="0", $cpw="", $path="/");
} catch (Exception $e) {
if ($e->getCode() != 1281) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"get_avatars 1:",$e->getCode(),': ',"Error by getting Avatarlist: ",$e->getMessage(),"\n";
$sqlmsg .= $e->getCode() . ': ' . "Error by getting Avatarlist: " . $e->getMessage();
$sqlerr++;
}
}
$fsfilelist = opendir(substr(__DIR__,0,-4).'avatars/');
while (false !== ($fsfile = readdir($fsfilelist))) {
if ($fsfile != '.' && $fsfile != '..') {
$fsfilelistarray[$fsfile] = filemtime(substr(__DIR__,0,-4).'avatars/'.$fsfile);
}
}
if (isset($tsfilelist)) {
foreach($tsfilelist as $tsfile) {
$fullfilename = '/'.$tsfile['name'];
$uuidasbase16 = substr($tsfile['name'],7);
if (!isset($fsfilelistarray[$uuidasbase16.'.png']) || $tsfile['datetime']>$fsfilelistarray[$uuidasbase16.'.png']) {
if (substr($tsfile['name'],0,7) == 'avatar_') {
try {
usleep($slowmode);
$avatar = $ts3->transferInitDownload($clientftfid="5",$cid="0",$name=$fullfilename,$cpw="", $seekpos=0);
$transfer = TeamSpeak3::factory("filetransfer://" . $avatar["host"] . ":" . $avatar["port"]);
$tsfile = $transfer->download($avatar["ftkey"], $avatar["size"]);
$avatarfilepath = substr(__DIR__,0,-4).'avatars/'.$uuidasbase16.'.png';
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Download avatar: ",$fullfilename,"\n";
file_put_contents($avatarfilepath, $tsfile);
$count++;
}
catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"get_avatars 2:",$e->getCode(),': ',"Error by download Avatar: ",$e->getMessage(),"\n";
$sqlmsg .= $e->getCode() . ': ' . "Error by download Avatar: " . $e->getMessage();
$sqlerr++;
}
}
}
}
}
$buildtime = microtime(true) - $starttime;
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"get_avatars 3:",print_r($mysqlcon->errorInfo()),"\n";
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"get_avatars 4:",print_r($mysqlcon->errorInfo()),"\n";
}
}
}
?>

206
jobs/update_groups.php Normal file
View File

@@ -0,0 +1,206 @@
<?PHP
function update_groups($ts3,$mysqlcon,$lang,$dbname,$slowmode,$jobid,$timezone,$serverinfo) {
$starttime = microtime(true);
$sqlmsg = '';
$sqlerr = 0;
try {
usleep($slowmode);
$iconlist = $ts3->channelFileList($cid="0", $cpw="", $path="/icons/");
} catch (Exception $e) {
if ($e->getCode() != 1281) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 1:",$e->getCode(),': ',"Error by getting servergrouplist: ",$e->getMessage(),"\n";
$sqlmsg .= $e->getCode() . ': ' . "Error by getting servergrouplist: " . $e->getMessage();
$sqlerr++;
}
}
foreach($iconlist as $icon) {
$iconid = "i".substr($icon['name'], 5);
$iconarr[$iconid] = $icon['datetime'];
}
try {
usleep($slowmode);
$ts3->serverGroupListReset();
$ts3groups = $ts3->serverGroupList();
} catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 3:",$e->getCode(),': ',"Error by getting servergrouplist: ",$e->getMessage(),"\n";
$sqlmsg .= $e->getCode() . ': ' . "Error by getting servergrouplist: " . $e->getMessage();
$sqlerr++;
}
if(($dbgroups = $mysqlcon->query("SELECT * FROM $dbname.groups")) === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 2:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
if ($dbgroups->rowCount() == 0) {
$sqlhisgroup = "empty";
} else {
$servergroups = $dbgroups->fetchAll(PDO::FETCH_ASSOC);
foreach($servergroups as $servergroup) {
$sqlhisgroup[$servergroup['sgid']] = array (
"sgid" => $servergroup['sgid'],
"iconid" => $servergroup['iconid'],
"sgidname" => $servergroup['sgidname'],
"icondate" => $servergroup['icondate']
);
}
}
// ServerIcon
$sIconId = $serverinfo['virtualserver_icon_id'];
$sIconId = ($sIconId < 0) ? (pow(2, 32)) - ($sIconId * -1) : $sIconId;
$sIconFile = 0;
if (!isset($sqlhisgroup['0']) || $sqlhisgroup['0']['iconid'] != $sIconId || $iconarr["i".$sIconId] > $sqlhisgroup['0']['icondate']) {
if($sIconId > 600) {
try {
usleep($slowmode);
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Download new ServerIcon\n";
$sIconFile = $ts3->iconDownload();
file_put_contents(substr(dirname(__FILE__),0,-4) . "icons/servericon.png", $sIconFile);
} catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 1:",$e->getCode(),': ',"Error by downloading Icon: ",$e->getMessage(),"\n";
$sqlmsg .= $e->getCode() . ': ' . "Error by downloading Icon: " . $e->getMessage();
$sqlerr++;
}
}
if (!isset($sqlhisgroup['0'])) {
$insertgroups[] = array(
"sgid" => "0",
"sgidname" => "ServerIcon",
"iconid" => $sIconId,
"icon" => $sIconFile,
"icondate" => $iconarr["i".$sIconId]
);
} else {
$updategroups[] = array(
"sgid" => "0",
"sgidname" => "ServerIcon",
"iconid" => $sIconId,
"icon" => $sIconFile,
"icondate" => $iconarr["i".$sIconId]
);
}
}
// GroupIcons
foreach ($ts3groups as $servergroup) {
$tsgroupids[] = $servergroup['sgid'];
$sgid = $servergroup['sgid'];
$gefunden = 2;
$iconid = $servergroup['iconid'];
$iconid = ($iconid < 0) ? (pow(2, 32)) - ($iconid * -1) : $iconid;
$iconfile = 0;
if($iconid > 600) {
if (!isset($sqlhisgroup[$sgid]) || $sqlhisgroup[$sgid]['iconid'] != $iconid || $iconarr["i".$iconid] > $sqlhisgroup[$sgid]['icondate']) {
try {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"Download new ServerGroupIcon for group ",$servergroup['name']," with ID: ",$sgid,"\n";
$iconfile = $servergroup->iconDownload();
file_put_contents(substr(dirname(__FILE__),0,-4) . "icons/" . $sgid . ".png", $iconfile);
} catch (Exception $e) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 4:",$e->getCode(),': ',"Error by downloading Icon: ",$e->getMessage(),"\n";
$sqlmsg .= $e->getCode() . ': ' . "Error by downloading Icon: " . $e->getMessage();
$sqlerr++;
}
}
}
$sgname = str_replace('\\', '\\\\', htmlspecialchars($servergroup['name'], ENT_QUOTES));
if ($sqlhisgroup != "empty") {
foreach ($sqlhisgroup as $groups) {
if ($groups['sgid'] == $sgid) {
$gefunden = 1;
$updategroups[] = array(
"sgid" => $sgid,
"sgidname" => $sgname,
"iconid" => $iconid,
"icon" => $iconfile,
"icondate" => $iconarr["i".$iconid]
);
break;
}
}
if ($gefunden != 1) {
$insertgroups[] = array(
"sgid" => $servergroup['sgid'],
"sgidname" => $sgname,
"iconid" => $iconid,
"icon" => $iconfile,
"icondate" => $iconarr["i".$iconid]
);
}
} else {
$insertgroups[] = array(
"sgid" => $servergroup['sgid'],
"sgidname" => $sgname,
"iconid" => $iconid,
"icon" => $iconfile,
"icondate" => $iconarr["i".$iconid]
);
}
}
if (isset($insertgroups)) {
$allinsertdata = '';
foreach ($insertgroups as $insertarr) {
if($insertarr['sgidname'] != "ServerIcon" && $insertarr['icondate'] != 0) {
$allinsertdata = $allinsertdata . "('" . $insertarr['sgid'] . "', '" . $insertarr['sgidname'] . "', '" . $insertarr['iconid'] . "', '" . $insertarr['icondate'] . "'),";
}
}
$allinsertdata = substr($allinsertdata, 0, -1);
if ($allinsertdata != '') {
if($mysqlcon->exec("INSERT INTO $dbname.groups (sgid, sgidname, iconid, icondate) VALUES $allinsertdata") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 5:",$allinsertdata,print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
}
if (isset($updategroups)) {
$allsgids = '';
$allupdatesgid = '';
$allupdateiconid = '';
foreach ($updategroups as $updatedata) {
$allsgids = $allsgids . "'" . $updatedata['sgid'] . "',";
$allupdatesgid = $allupdatesgid . "WHEN '" . $updatedata['sgid'] . "' THEN '" . $updatedata['sgidname'] . "' ";
$allupdateiconid = $allupdateiconid . "WHEN '" . $updatedata['sgid'] . "' THEN '" . $updatedata['iconid'] . "' ";
$allupdatedate = $allupdatedate . "WHEN '" . $updatedata['sgid'] . "' THEN '" . $updatedata['icondate'] . "' ";
}
$allsgids = substr($allsgids, 0, -1);
if($mysqlcon->exec("UPDATE $dbname.groups set sgidname = CASE sgid $allupdatesgid END, iconid = CASE sgid $allupdateiconid END, icondate = CASE sgid $allupdatedate END WHERE sgid IN ($allsgids)") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 6:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
foreach ($sqlhisgroup as $groups) {
if(!in_array($groups['sgid'], $tsgroupids) && $groups['sgid'] != 0) {
$delsgroupids = $delsgroupids . "'" . $groups['sgid'] . "',";
}
}
if(isset($delsgroupids)) {
$delsgroupids = substr($delsgroupids, 0, -1);
if($mysqlcon->exec("DELETE FROM groups WHERE sgid IN ($delsgroupids)") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 7:",print_r($mysqlcon->errorInfo()),"\n";
$sqlmsg .= print_r($mysqlcon->errorInfo());
$sqlerr++;
}
}
$buildtime = microtime(true) - $starttime;
if ($sqlerr == 0) {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='0', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 8:",print_r($mysqlcon->errorInfo()),"\n";
}
} else {
if($mysqlcon->exec("UPDATE $dbname.job_log SET status='1', err_msg='$sqlmsg', runtime='$buildtime' WHERE id='$jobid'") === false) {
echo DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))->setTimeZone(new DateTimeZone($timezone))->format("Y-m-d H:i:s.u "),"update_groups 9:",print_r($mysqlcon->errorInfo()),"\n";
}
}
}
?>