Advertisement
Guest User

Untitled

a guest
Sep 26th, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. <?php
  2.  
  3. class MinecraftAPI {
  4.  
  5. public $minecraftUsername = '';
  6. public $sessionID = '';
  7.  
  8. public function haspaid($username) {
  9. $result = file_get_contents("http://www.minecraft.net/haspaid.jsp?user=".$username);
  10. if ($result == "true") {
  11. return true;
  12. }
  13. else {
  14. return false;
  15. }
  16. }
  17. public function serverstatus($ip,$port = "2256") {
  18. $status = file_get_contents("http://let.fudgie.undo.it/mc_server.php?ip=".$ip."&port=".$port);
  19. if ($status == "true") {
  20. return true;
  21. }
  22. else {
  23. return false;
  24. }
  25. }
  26. public function login($username, $password, $version=13){
  27.  
  28. // create connection
  29. $minecraftSocket = fopen("http://login.minecraft.net/?user=$username&password=$password&version=$version", "rb");
  30.  
  31. // variable for output
  32. $minecraftOutput = '';
  33.  
  34. // read output by minecraft.net
  35. while (!feof($minecraftSocket)) {
  36. // write output
  37. $minecraftOutput .= fgets($minecraftSocket, 128);
  38. }
  39.  
  40. // close connection
  41. fclose($minecraftSocket);
  42.  
  43. // check if user has a bad login
  44. if(strpos($minecraftOutput, 'Bad login') === false){
  45. // split values
  46. $minecraftValues = explode(':', $minecraftOutput);
  47.  
  48. if(count($minecraftValues) > 0){
  49. // we just read the second and third entry (the rest is uninteresting for that what we are doing)
  50. $this->minecraftUsername = $minecraftValues[2];
  51. $this->sessionID = $minecraftValues[3];
  52.  
  53. return true;
  54. }else{
  55. // something else went wrong
  56. return false;
  57. }
  58.  
  59. }else{
  60. return false;
  61. }
  62. }
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement