Last active
August 29, 2015 14:02
-
-
Save robot56/e5f6f91652943d1b190e to your computer and use it in GitHub Desktop.
TODO, finish this script to get skins, capes, textures, etc via sessionserver.mojang.com
This file contains hidden or 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 getProfile($name) { | |
$uri = "https://api.mojang.com/profiles/minecraft"; | |
$request = Requests::post($uri, ["Content-Type" => "application/json", "User-Agent" => "ShockyIRC/1.0"], json_encode($name)); | |
try { | |
$json = json_decode($request->body, true); | |
$id = @$json[0]["id"]; | |
return $id?$id:"No profile."; | |
} catch (Exception $e) { | |
return "Failed to connect to API server."; | |
} | |
} | |
function sessionRequest($uuid) { | |
$uri = "https://sessionserver.mojang.com/session/minecraft/profile/"; | |
$request = Requests::get($uri.$uuid); | |
try { | |
if ($request->status_code == 204) return "Invalid profile."; | |
$json = json_decode($request, true); | |
} except (Exception $e) { | |
return "Failed to connect to the session server, is it down?"; | |
} | |
$data = ( | |
"id" => $json["id"], "name" => $json["name"], "textures" => base64_decode() | |
) | |
} | |
if (!$args) return "You need to specify a username or UUID."; | |
switch (strlen($args)) { | |
case 32 or 36: | |
$uuid = str_replace("-", "", $args); | |
echo sessionRequest($uuid); | |
break; | |
case <17: | |
$profile = getProfile($args); | |
if (strlen($profile) !== 32) return $profile; | |
echo sessionRequest($profile); | |
break; | |
default: | |
echo "You need to specify a valid username or UUID."; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment