Created
November 26, 2017 14:30
-
-
Save lwl12/a34191badfd514553e0837fba2856402 to your computer and use it in GitHub Desktop.
Minecraft whitelist adder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function curl($url) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
$r = curl_exec($ch); | |
curl_close($ch); | |
return $r; | |
} | |
try{ | |
@$username = $argv[1]; | |
if (empty($username)) { | |
throw new Exception('NO USERNAME!'); | |
} | |
$url = "https://api.mojang.com/users/profiles/minecraft/" . urlencode($username); | |
$content = curl($url); | |
$uuid = json_decode($content, true) ["id"]; | |
if (!empty($uuid)) { | |
$uuid = substr($uuid, 0, 8) . '-' . substr($uuid, 8, 4) . '-' . substr($uuid, 12, 4) . '-' . substr($uuid, 16, 4) . '-' . substr($uuid, 20, 12); | |
echo "Found \033[4m\033[41mOnline\033[0m UUID: \033[42m$uuid\033[0m" . PHP_EOL; | |
} else { | |
$uuid = md5("OfflinePlayer:$username"); | |
$uuid = substr($uuid, 0, 8) . '-' . substr($uuid, 8, 4) . '-' . substr($uuid, 12, 4) . '-' . substr($uuid, 16, 4) . '-' . substr($uuid, 20, 12); | |
echo "Found \033[4m\033[45mOffline\033[0m UUID: \033[42m$uuid\033[0m" . PHP_EOL; | |
} | |
echo "\033[94mAre you sure you want to add UUID which belongs to \033[7m$username\033[27m to the whitelist? Type 'y' to continue: \033[0m"; | |
$handle = fopen("php://stdin", "r"); | |
$line = fgets($handle); | |
if (trim($line) != 'y') { | |
die("\033[4mABORTING!\033[0m" . PHP_EOL); | |
} | |
fclose($handle); | |
echo "\033[93mCommand Accepted. Processing...\033[0m" . PHP_EOL; | |
$whitelist = json_decode(file_get_contents("./whitelist.json"), true); | |
foreach ($whitelist as & $value) { | |
if ($value["name"] == $username || $value["uuid"] == $uuid) { | |
throw new Exception("Found duplicate users: " . json_encode($value, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); | |
} | |
} | |
array_push($whitelist, array( | |
"uuid" => $uuid, | |
"name" => $username | |
)); | |
if(!file_put_contents("./whitelist.json", json_encode($whitelist, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), LOCK_EX)) throw new Exception("Write file failed!"); | |
require('Rcon.php'); | |
$rcon = new Rcon("localhost", 25575, 'Rcon Passwd', 3); | |
if ($rcon->connect()){ | |
$rcon->sendCommand("whitelist reload"); | |
} else { | |
throw new Exception("Rcon connect failed!"); | |
} | |
} catch (Exception $e) { | |
echo("\033[1;31mCaught exception: " . $e->getMessage() . "\033[0m" . PHP_EOL); | |
die(); | |
} | |
echo("\033[1;4;32mSuccessfully!\033[0m" . PHP_EOL); | |
exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment