Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MinecraftAPI {
- public $minecraftUsername = '';
- public $sessionID = '';
- public function haspaid($username) {
- $result = file_get_contents("http://www.minecraft.net/haspaid.jsp?user=".$username);
- if ($result == "true") {
- return true;
- }
- else {
- return false;
- }
- }
- public function serverstatus($ip,$port = "2256") {
- $status = file_get_contents("http://let.fudgie.undo.it/mc_server.php?ip=".$ip."&port=".$port);
- if ($status == "true") {
- return true;
- }
- else {
- return false;
- }
- }
- public function login($username, $password, $version=13){
- // create connection
- $minecraftSocket = fopen("http://login.minecraft.net/?user=$username&password=$password&version=$version", "rb");
- // variable for output
- $minecraftOutput = '';
- // read output by minecraft.net
- while (!feof($minecraftSocket)) {
- // write output
- $minecraftOutput .= fgets($minecraftSocket, 128);
- }
- // close connection
- fclose($minecraftSocket);
- // check if user has a bad login
- if(strpos($minecraftOutput, 'Bad login') === false){
- // split values
- $minecraftValues = explode(':', $minecraftOutput);
- if(count($minecraftValues) > 0){
- // we just read the second and third entry (the rest is uninteresting for that what we are doing)
- $this->minecraftUsername = $minecraftValues[2];
- $this->sessionID = $minecraftValues[3];
- return true;
- }else{
- // something else went wrong
- return false;
- }
- }else{
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement