#!/usr/bin/php
<?php
//Display user location when they join your server
//Made by Light lightron.org
while (!feof(STDIN))
{
    $input = rtrim(fgets(STDIN));
    $param = explode(" ", $input);

    if ($param[0] == "PLAYER_ENTERED")
    {
        $username = implode(" ", array_slice($param, 3));

        if ($loc = ip_location($param[2]))
            echo "CONSOLE_MESSAGE 0xffffff{$username} 0xaaccddhas joined from 0xffffff{$loc -> REGION}0xaaccdd, 0xffffff{$loc -> COUNTRY}0xaaccdd!" . "\n";
    }
}

function ip_location($ip)
{
    if (preg_match('/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/', $ip))
        return json_decode( file_get_contents("https://lightron.org/Geolocation/" . $ip) );

    return false;
}

?>