Language: EN FR PT ES NL DE SV RU
<?php

 
declare(ticks 1);
if (! 
function_exists('pcntl_fork')) die('PCNTL functions not available on this PHP installation');
echo 
"Start of program!\n";
if (isset(
$argv[1])) {
    if (
$argv[1] == 'verbose' || $argv[1] == '-v') {
        
$verbose 1;
        echo 
"Single Verbose\n";
    } elseif (
$argv[1] == 'vv' || $argv[1] == '-vv') {
        
$verbose 2;
        echo 
"Double Verbose\n";
    } else {
        
$verbose 0;
        echo 
"Parm passed, not verbose\n";
    }
} else {
    
$verbose 0;
    echo 
"No verbose\n";
}


require_once(
"/home/pugbot/tracker/q3query.php");
require_once(
"/home/pugbot/tracker/align.php");
include(
"/home/pugbot/tracker/dbconfig.php");

// connect to db

function mcrypt($data) {
    
$key 'ASsadfEYHr345REtrte74hHFGDsret7245dFDGDFer3D7hhs4467H85p';
    
$iv '82952684';
    
$todec base64_decode($data);
    
$decrypted mcrypt_decryptMCRYPT_BLOWFISH$key$todecMCRYPT_MODE_CBC$iv );
    return 
$decrypted;
}

function 
send_rcon($command$server_host$server_port$rcon_pass) {
    
    if (
$server_host == "" || !isset($server_host)) {
        return 
FALSE;
    }
    
    
// Set server, port and RCON for server to be used.
    
$q = new q3query($server_host$server_port);
    
$q->set_rconpassword($rcon_pass);

    
// Make sure variables are clean.
    
$failed 0;
    
$rconresponse 0;
    while (
$failed != 20 && !($rconresponse)) {
        
$q->rcon($command);
        
$rconresponse $q->get_response();
        
//echo $rconresponse;
        
$failed++;
        if (!(
$rconresponse)) { usleep(100000); }
    }
    if (
$failed == 20) {
        return 
FALSE;
    } else {
        return 
$rconresponse;
    }
}

function 
sig_handler($signo) {
    if(
$signo == SIGUSR1) {
        
// Handle SIGUSR1
        
echo "SIG: ".$signo."\n";
    } elseif(
$signo == SIGTERM) {
        
// Handle SIGTERM
        
echo "SIG: ".$signo."\n";
        
$sigterm true;
    } elseif(
$signo == SIGHUP) {
        
// Handle SIGHUP
        
echo "SIG: ".$signo."\n";
        
$sighup true;
    }
}

// Function for thread to track each server
function track_server($server_to$pid$verbose) {
    
    
// Setup the align class for thread
    
$align = new align($verbose);
    
$align->align($verbose);
    
// Include DB info
    
include("/home/pugbot/tracker/dbconfig.php");
    
    
//$align->align_d_echo_a($db);
    
    // Make the database connection for this thread.
    
$server_connection mysqli_connect($db['host'], $db['user'], $db['pass'], $db['db']) or die ("Unable to connect!");
    
    
startserver:
    
// setup the vars
    
$server_id     $server_to;
    
$server_query  $server_connection->prepare("SELECT * FROM `servers` WHERE `server_id`= ? ") or die("unable to query table! track_server, line: 84 ".$server_id);
    
$server_query->bind_param('s'$server_id);
    
$server_query->execute();
    
$server_query_r $server_query->get_result();
    
$server        $server_query_r->fetch_array();
    
$failed        $server['status'];

    
$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"TRACKING!"=>"STARTED!"), $server_id);    
    
    if (!
$server) {
        
$align->align_s_echo_a(array("SERVER_ID"=>$server_id,"RCON!"=>"FAILED!"), $server_id);    
    } else {
    
    
$server_host   gethostbyname($server['host']);
    
$server_port   $server['port'];
    
$rcon_pass_enc $server['rcon'];
    
$rcon_pass     mcrypt($rcon_pass_enc);
    
$rcon_pass     trim($rcon_pass,"\0");
    
$thread_name   "Thread for server ID ".$server_id;
    
    
// Set the process title (shows up in "ps aux")
    
cli_set_process_title($thread_name);
    
//setthreadtitle($thread_name);
    
    // Infinite tracking loop, never stop, at least try not to.
    
while (TRUE) {
        
        
// Like to sleep a lot with urt rcon commands to help prevent rcon flood conditions.
        
usleep(50000);

        
// Set the pid in the servers table
        
$update_pid_q $server_connection->prepare("UPDATE `servers` SET `tracker_pid`=0 WHERE `server_id`= ? ");
        
$update_pid_q->bind_param('s'$server_id);
        
$update_pid_q->execute();
        
// Echo to console some basic status information.
        
$align->align_d_echo_a(array("SERVER_ID"=>$server_id,"UPDATING!"=>"STARTED!"), $server_id);
        
        
// Set the time for this pass on tracking
        
$start_time time();
        unset(
$players_response);
        
// fetch connected players via rcon
        
$command         "players";
        
$players_response send_rcon($command$server_host$server_port$rcon_pass);
        
$align->align_d_echo_a(array("SERVER_ID"=>$server_id,"RCON RESPONSE!"=>"--".$players_response."--"), $server_id);
        
        
/* If statements for checking $status_response */
        
if (isset($players_response)) {
            if (
$players_response === FALSE || $players_response == FALSE || strpos($players_response"Bad rconpassword.")) {
                
$server_tracker_q $server_connection->prepare("UPDATE `servers` SET `status`=\"RCONFAIL\" WHERE `server_id`= ? ");
                
$server_tracker_q->bind_param('s'$server_id);
                
$server_tracker_q->execute();
                
// Some debug output
                
$align->align_s_echo_a(array("SERVER_ID"=>$server_id,"STATUS!"=>"FAILED!"), $server_id);
                
sleep(120);
                goto 
startserver;
            } elseif (
$failed == "RCONFAIL") {
                
// Some debug output
                
$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"STATUS!"=>"SUCCEEDED!"), $server_id);
                
$server_tracker_q $server_connection->prepare("UPDATE `servers` SET `status`=\"free\" WHERE `server_id`= ? ");
                
$server_tracker_q->bind_param('s'$server_id);
                
$server_tracker_q->execute();
            }        
        } else {
            
// Some debug output
            
$align->align_s_echo_a(array("SERVER_ID"=>$server_id,"STATUS!"=>"FAILED!"), $server_id);
            
$server_tracker_q $server_connection->prepare("UPDATE `servers` SET `status`=\"RCONFAIL\" WHERE `server_id`= ? ");
            
$server_tracker_q->bind_param('s'$server_id);
            
$server_tracker_q->execute();
            
sleep(120);
            goto 
startserver;
        }
            
        
        
// Some magic TheRick found/came up with.
        
unset($t);
        
$t explode(PHP_EOL$players_response);
        foreach (
$t as $ts) {
            
$tsplit explode(": "$ts);
            if (
$tsplit[0] != $ts) {
            
$type[$tsplit[0]] = $tsplit[1];
            }
        }
        
/*
        preg_match('/^map:\s+(.*)$/m', $status_response, $aMap);
        
        // This line sets the map on the server from the rcon status
        
        if (isset($aMap[1])) {
            $map = $aMap[1];
            $server_tracker_q = $server_connection->prepare(" UPDATE `servers` SET `current_map`= ? WHERE `server_id`= ? ");
            $server_tracker_q->bind_param('ss', $map, $server_id);
            $server_tracker_q->execute();
        } else {
            $align->align_v_echo_a($aMap, $server_id);
            $align->align_v_echo_a(array("SERVER_ID"=>$server_id,"STATUS"=>$status_response), $server_id);
        }
        */
        // Setup rcon to grab sv_hostname
        
$command "sv_hostname";
        
        
// Send sv_hostname command
        
$sv_hostname_response send_rcon($command$server_host$server_port$rcon_pass);
        
        
usleep(50000);
        
        
$sv_first_split explode("is:\""$sv_hostname_response);
        if (isset(
$sv_first_split[1])) { 
            
$sv_second_split explode("^7\" default:\"",$sv_first_split[1]);
            
$sv_hostname $sv_second_split[0];
            
//$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"sv_hostname"=>$sv_hostname_response), $server_id);
            
$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"sv_hostname"=>$sv_hostname), $server_id);
        } else {
            
$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"sv_hostname"=>$sv_hostname_response), $server_id);
            
$sv_hostname "Bad server name query";
            
// Set num players and sv_hostname in servers database
            
$server_tracker_q $server_connection->prepare("UPDATE `servers` SET `name`= ? WHERE `server_id`= ? ");
            
$server_tracker_q->bind_param('ss'$sv_hostname$server_id);
            
$server_tracker_q->execute();
            goto 
startserver;
        }
                
                        
// Setup rcon to grab sv_maxclients
        
$command "sv_maxclients";
        
        
// Send sv_hostname command
        
$sv_maxclients_response send_rcon($command$server_host$server_port$rcon_pass);
        
        
usleep(50000);
        
        
$sv_first_split explode("is:\""$sv_maxclients_response);
        if (isset(
$sv_first_split[1])) { 
            
$sv_second_split explode("^7\" default:",$sv_first_split[1]);
            
$sv_maxclients $sv_second_split[0];
            
//$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"sv_maxclients_raw"=>$sv_maxclients_response), $server_id);
            
$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"sv_maxclients"=>$sv_maxclients), $server_id);
        } else {
            
$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"sv_maxclients_raw"=>$sv_maxclients_response), $server_id);
            
$sv_maxclients "0";
            
$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"sv_maxclients"=>$sv_maxclients), $server_id);
            
// Set num players and sv_maxclients in servers database
            
$server_tracker_q $server_connection->prepare("UPDATE `servers` SET `slots`= ? WHERE `server_id`= ? ");
            
$server_tracker_q->bind_param('ss'$sv_maxclients$server_id);
            
$server_tracker_q->execute();
            goto 
startserver;
        }
                
                
        
/*
        // Setup rcon to grab sv_hostname
        $command = "g_gametype";
        
        // Send sv_hostname command
        $gametype_response = send_rcon($command, $server_host, $server_port, $rcon_pass);
        
        usleep(50000);
        
        $gametype_first_split = explode("is:\"", $gametype_response);
        if (isset($gametype_first_split[1])) {
            $gametype_second_split = explode("^7",$gametype_first_split[1]);
            $gametype = $gametype_second_split[0];
            //$align->align_v_echo_a(array("SERVER_ID"=>$server_id,"g_gametype"=>$gametype_response), $server_id);
            $align->align_v_echo_a(array("SERVER_ID"=>$server_id,"g_gametype"=>$gametype), $server_id);
        } else {
            $align->align_v_echo_a(array("SERVER_ID"=>$server_id,"g_gametype"=>$gametype_response), $server_id);
            $gametype = 0;
            // Set num players and sv_hostname in servers database
            $server_tracker_q = $server_connection->prepare("UPDATE `servers` SET `gametype`= ? WHERE `server_id`= ? ");
            $server_tracker_q->bind_param('ss', $gametype, $server_id);
            $server_tracker_q->execute();
            goto startserver;
        }
            
        // Setup rcon to grab sv_hostname
        $command = "players";
        
        // Send sv_hostname command
        $players_response = send_rcon($command, $server_host, $server_port, $rcon_pass);
        */
        
usleep(50000);
        

        if (isset(
$type["Scores"])) {
            
$scores_ps preg_split("/[\s:]+/"$type["Scores"]);
            
$scores[$scores_ps[0]] = $scores_ps[1];
            
$scores[$scores_ps[2]] = $scores_ps[3];
        }
        if (isset(
$type["MatchReady"])) {
            
$matchready_ps preg_split("/[\s:]+/"$type["MatchReady"]);
            
$matchready[$matchready_ps[0]] = $matchready_ps[1];
            
$matchready[$matchready_ps[2]] = $matchready_ps[3];
        }
        if (isset(
$type["Half"])) {
            
$half $type["Half"];
        }
        if (isset(
$type["RoundTime"])) {
            
$roundtime $type["RoundTime"];
        }

        switch (
$type["GameType"]) {
            case 
"TS":
            
$gametype 4;
            break;
            case 
"BOMB":
            
$gametype 8;
            break;
            case 
"CTF":
            
$gametype 7;
            break;
            case 
"TM":
            
$gametype 3;
            break;
        }
        

        
// Clear the user records from temp table
        
$server_tracker_q $server_connection->prepare"DELETE FROM `tracker_active` WHERE `server_id`= ? " );
        
$server_tracker_q->bind_param('s'$server_id);
        
$server_tracker_q->execute();
        
        
$loop 0;
        unset(
$players_a);
        foreach (
$t as $tplayers) {
            if (
strpos($tplayers"TEAM") !== false) {
            
$pid substr($tplayers0strpos($tplayers":"));
            
$name substr($tplayers, (strpos($tplayers":") + 1), (strpos($tplayers" TEAM:") - 2));
            
$team_sp explode("TEAM:"$tplayers);
            
$team substr($team_sp[1], 0strpos($team_sp[1]," KILLS:"));
            
$kills_sp explode("KILLS:"$tplayers);
            
$kills substr($kills_sp[1], 0strpos($kills_sp[1]," DEATHS:"));
            
$deaths_sp explode("DEATHS:"$tplayers);
            
$deaths substr($deaths_sp[1], 0strpos($deaths_sp[1]," ASSISTS:"));
            
$assists_sp explode("ASSISTS:"$tplayers);
            
$assists substr($assists_sp[1], 0strpos($assists_sp[1]," PING:"));
            
$ping_sp explode("PING:"$tplayers);
            
$ping substr($ping_sp[1], 0strpos($ping_sp[1]," AUTH:"));
            
$auth_sp explode("AUTH:"$tplayers);
            
$auth substr($auth_sp[1], 0strpos($auth_sp[1]," IP:"));
            
$ipp_sp explode("IP:"$tplayers);
            
$ip_sp explode(":"$ipp_sp[1]);
            
$ip $ip_sp[0];
            
$port $ip_sp[1];
            if (
$gametype == "7") {
                
$ctf_sp explode("CTF: "$t[$loop 1]);
                
$ctf_ps preg_split("/[\s:]+/"$ctf_sp[1]);
                
$ctf_scores[$pid][$ctf_ps[0]] = $ctf_ps[1];
                
$ctf_scores[$pid][$ctf_ps[2]] = $ctf_ps[3];
                
$ctf_scores[$pid][$ctf_ps[4]] = $ctf_ps[5];
                
$ctf_scores[$pid][$ctf_ps[6]] = $ctf_ps[7];
                
$ctf_scores[$pid][$ctf_ps[8]] = $ctf_ps[9];
                
$align->align_v_echo_a($ctf_scores[$pid], $server_id);
                
//$kills = $kills - ((
            
}
            
$players_a[$pid]["pid"] = $pid;
            
$players_a[$pid]["name"] = $name;
            
$players_a[$pid]["team"] = $team;
            
$players_a[$pid]["kills"] = $kills;
            
$players_a[$pid]["deaths"] = $deaths;
            
$players_a[$pid]["assists"] = $assists;
            
$players_a[$pid]["auth"] = $auth;
            
$players_a[$pid]["ping"] = $ping;
            
$players_a[$pid]["ip"] = $ip;
            
$players_a[$pid]["port"] = $port;
            
$align->align_v_echo_a($players_a[$pid], $server_id);
            }
            
$loop++;
        }
        
$align->align_v_echo_a($t$server_id);
        if (isset(
$players_a)) {
            
$align->align_v_echo_a(array("IN LOOP FOR DATABASE"=>"DUH"),$server_id);
            foreach (
$players_a as $player) {
            
$align->align_v_echo_a(array("PLAYER ADDING TO DATABASE"=>$player["name"]),$server_id);
            
$server_tracker_q $server_connection->prepare("INSERT INTO `tracker_active` (`key`, `server_id`, `pid`, `score`, `ping`, `name`, `auth`, `ip`,`port`, `deaths`, `assists`,`team`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
            
$server_tracker_q->bind_param('sssssssssss'$server_id$player["pid"], $player["kills"], $player["ping"], $player["name"], $player["auth"], $player["ip"], $player["port"], $player["deaths"], $player["assists"], $player["team"]);
            
$server_tracker_q->execute();
            
//echo("\nStatement failed: ". $server_tracker_q->error . "\n");

            
}
        }

        
// Select all the players we just added to the temp database table for this server
        
$update_players_q $server_connection->prepare("SELECT * FROM `tracker_active` WHERE `server_id`= ? ");
        
$update_players_q->bind_param('s'$server_id);
        
$update_players_q->execute();
        
$update_players_r $update_players_q->get_result();
    
        
// Get num players in server
        
$server_num_players mysqli_num_rows($update_players_r);
    
        
// Set num players and sv_hostname in servers database
        
$update_info_q $server_connection->prepare("UPDATE `servers` SET `gametype`= ? ,`name`= ? ,`players`= ? ,`slots`= ?, `current_map`= ?, `gametime`= ?, `matchmode` = ? WHERE `server_id`= ? ");
        
//echo "\n".$gametype."||".$sv_hostname."||".$type["Players"]."||".$sv_maxclients."||".$type["Map"]."||".$type["GameTime"]."||".$server_id."\n";
        
$update_info_q->bind_param('ssssssss'$gametype$sv_hostname$type["Players"], $sv_maxclients$type["Map"], $type["GameTime"], $type["MatchMode"], $server_id);
        
$update_info_q->execute();
    
        if (isset(
$scores)) {
            
// Set num players and sv_hostname in servers database
            
$update_counts_q $server_connection->prepare("UPDATE `servers` SET `red_score`= ? , `blue_score`= ? WHERE `server_id`= ? ");
            
$update_counts_q->bind_param('sss'$scores["R"], $scores["B"], $server_id);
            
$update_counts_q->execute();
        }

        if (isset(
$matchready)) {
            
// Set num players and sv_hostname in servers database
            
$update_counts_q $server_connection->prepare("UPDATE `servers` SET `red_rup`= ? ,`blue_rup`= ? WHERE `server_id`= ? ");
            
$update_counts_q->bind_param('sss'$matchready["R"], $matchready["B"], $server_id);
            
$update_counts_q->execute();
        }

        if (isset(
$roundtime)) {
            
// Set num players and sv_hostname in servers database
            
$update_counts_q $server_connection->prepare("UPDATE `servers` SET `roundtime`=? WHERE `server_id`= ? ");
            
$update_counts_q->bind_param('ss'$roundtime$server_id);
            
$update_counts_q->execute();
        }

        if (isset(
$half)) {
            
// Set num players and sv_hostname in servers database
            
$update_counts_q $server_connection->prepare("UPDATE `servers` SET `half`=? WHERE `server_id`= ? ");
            
$update_counts_q->bind_param('ss'$half$server_id);
            
$update_counts_q->execute();
        }

        
// If the query failed, output some debug info, else query successful update the new temp table
        
if (!$update_players_r) {
        
            
// Output some debug info
            
$align->align_s_echo("FAILED SERVER_ID",$server_id$server_id);
        
        } else {
        
            
// Delete all players from the second temp table for this server
            
$delete_servers_q $server_connection->prepare"DELETE FROM `tracker_status` WHERE `server_id`= ? " );
            
$delete_servers_q->bind_param('s'$server_id);
            
$delete_servers_q->execute();
        
            
// Run this loop for each player, inserting them into the second temp table
            
while ($player_info $update_players_r->fetch_array()) {
            
                
//$align->align_d_echo_a($player_info);
                // Set the variables to be set in the second temp table
                
$name            $player_info['name'];
                
$auth            $player_info['auth'];
                
$server_id       $player_info['server_id'];
                
$pid             $player_info['pid'];
                
$score           $player_info['score'];
                
$ping            $player_info['ping'];
                
$deaths          $player_info['deaths'];
                
$ip              $player_info['ip'];
                
$assists         $player_info['assists'];
                
$port            $player_info['port'];
                
$team            $player_info['team'];

                
// Add the player to the second temp table here, second temp table gets handled by main thread from here
                
$server_tracker_q $server_connection->prepare(" INSERT INTO `tracker_status` (`key`, `server_id`, `pid`, `score`, `ping`, `name`, `auth`, `ip`, `port`, `deaths`, `assists`,`team`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?); ");
                
$server_tracker_q->bind_param('sssssssssss'$server_id$pid$score$ping$name$auth$ip$port$deaths$assists$team);
                
$server_tracker_q->execute();
            }
        }
    
        
// Count how long it took to track all players on server
        
$total_time time() - $start_time;
    
        
// Some debug output
        
$align->align_d_echo_a(array("SERVER_ID"=>$server_id,"DONE UPDATING!"=>"TOOK:","TIME"=>$total_time), $server_id);
    }
    }
}

function 
keep_tracking($verbose) {
    include(
"/home/pugbot/tracker/dbconfig.php");
    
$align = new align($verbose);
    
$align->align($verbose);
    while (
TRUE) {
        
$start_time time();

        
$align->align_s_echo("STARTING SERVERS!",$start_time"tracker");
        
        
$connection mysqli_connect($db['host'], $db['user'], $db['pass'], $db['db']) or die ("Unable to connect!");
        
        
// grab players in servers
        
$status_qp $connection->prepare(" SELECT * FROM `tracker_status` ");
        
$status_qp->execute();
        
$status_q $status_qp->get_result();
        
        
// Get all servers and try to check on the pid
        
$servers_qp $connection->prepare(" SELECT * FROM `servers`");
        
$servers_qp->execute();
        
$servers_q $servers_qp->get_result();
        
        
// For each server get pid n check
        
while ($server $servers_q->fetch_array()) {
            
            
// Set the $pid
            
$pid_count $server['tracker_pid'];
            
            
// Set server_id
            
$server_id $server['server_id'];
            
            if (
$pid_count 10) {
                
                
$pid pcntl_fork();
                if (
$pid == 0) {
                    
$align->align_s_echo("Forked child",$pid"tracker");
                } elseif (
$pid == -1) {
                    
$align->align_s_echo("Failed to fork!",$pid"tracker");
                } else {
                    
$align->align_s_echo("Child started!",$pid"tracker");
                    
track_server($server_id$pid$verbose);
                exit(
35);
                }
                
$pid_count 0;
            } else {
                
// add +1 to the pid
                
$pid_count++;
            }

            
// update the pid in the servers table
            
$servers_update $connection->prepare("UPDATE `servers` SET `tracker_pid` = ? WHERE `server_id` = ? ");
            
$servers_update->bind_param('ss'$pid_count$server_id);
            
$servers_update->execute();

            
// Output some debug info
            
$align->align_v_echo("TRACKER CHECKING!",$server_id"tracker");
            
$align->align_d_echo_a(array("SERVER_ID"=>$server_id,"TRACKER CHECKING!"=>"COMPLETE!"), "tracker");
        }


        
// start timer
        
$timer_start_urtplayers time();

        
// for each player, do the following
        
while ($status $status_q->fetch_array()) {
            
// setup the vars
            
$name            $status['name'];
            
$auth            $status['auth'];
            
$server_id       $status['server_id'];
            
$pid             $status['pid'];
            
$score           $status['score'];
            
$ping            $status['ping'];
            
$deaths          $status['deaths'];
            
$ip              $status['ip'];
            
$assists         $status['assists'];
            
$port            $status['port'];

            
$ip_search_q     $connection->prepare('SELECT `tuser_id` FROM `tracker_aliases` WHERE `ip`= ? AND `alias`= ? AND `server_id`= ? ');
            
$ip_search_q->bind_param('sss'$ip$name$server_id);
            
$ip_search_q->execute();
            
$ip_search_r     $ip_search_q->get_result();
            
$rows            mysqli_num_rows($ip_search_r);
            
$align->align_d_echo_a(array("SERVER_ID"=>$server_id,"TRACKER UPDATING!"=>"STARTING!"), "tracker");
            
            
// if it matches then do this stuff
            
if ($rows != 0) {
                
$user_array      $ip_search_r->fetch_array();

                
$tuser           $user_array[0];
                
// check if alias has been on this IP before
                
$alias_check_q $connection->prepare('SELECT * FROM `tracker_aliases` WHERE `alias`= ? AND `ip`= ? AND `server_id`= ? ');
                
$alias_check_q->bind_param('sss'$name$ip$server_id);
                
$alias_check_q->execute();
                
$alias_check_r $alias_check_q->get_result();

                
// if it has then update the counter
                
$rows mysqli_num_rows($alias_check_r);
                if (
$rows 0) {
                    
$update_tracker_q $connection->prepare('UPDATE `tracker_aliases` SET `counter`=`counter`+1 , `last_time`= ? WHERE `tuser_id`= ? ');
                    
$update_tracker_q->bind_param('ss'$start_time$tuser);
                    
$update_tracker_q->execute();
                } elseif (
$rows == && $guid != "") {
                    
$update_tracker_q $connection->prepare(" INSERT INTO `tracker_aliases`(`alias`,`auth`,`counter`,`ip`,`server_id`,`first_time`) VALUES( ? , ? ,'0', ? , ? , ? ) ");
                    
$update_tracker_q->bind_param('sssss'$name$auth$ip$server_id$start_time);
                    
$update_tracker_q->execute();
                }
            } elseif (
$rows == 0) {
                
$update_tracker_q $connection->prepare(" INSERT INTO `tracker_aliases`(`alias`,`auth`,`counter`,`ip`,`server_id`,`first_time`) VALUES( ? , ? ,'0', ? , ? , ? ) ");
                
$update_tracker_q->bind_param('sssss'$name$auth$ip$server_id$start_time);
                
$update_tracker_q->execute();
            }
        }
        
$total_time time() - $start_time;
        
$align->align_d_echo_a(array("SERVER_ID"=>$server_id,"TRACKER UPDATING!"=>"STARTING!","TIME"=>$total_time), "tracker");
        
sleep(1);
        
mysqli_close($connection);
    }
}


pcntl_signal(SIGUSR1"sig_handler");
pcntl_signal(SIGTERM"sig_handler");
pcntl_signal(SIGHUP"sig_handler");

//$connection = mysqli_connect($db['host'], $db['user'], $db['pass']) or die ("Unable to connect!");
//mysqli_select_db($db['db']) or die ("Unable to select database!");

/*
// grab server information
$server_q = mysqli_query(" SELECT * FROM `servers` WHERE `status`<>'badpass' ");

$server_id = array();
// for each server, do the following
while ($server = mysqli_fetch_array($server_q)) {
    $server_id[] = $server['server_id'];
}
mysqli_close($connection);

foreach ($server_id as $server_to) {
    $pid = pcntl_fork();

    if ($pid == 0) {
        echo "Forked child #{$pid}\n\n";
    } elseif ($pid == -1) {
        echo "Failed to fork! #{$pid}\n\n";
    } else {
        echo "Child! {$pid} =====================================================\n";
        track_server($server_to, $pid);
           exit(35);
    }
    
}
*/
cli_set_process_title  "Slacks multithreaded tracker"  );
keep_tracking($verbose);

print 
"Done! :^) PID: {$pid} \n\n";
?>