Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. <?php
  2. class Roblox {
  3. private $encryption = 'sha256',
  4. $user_id = null,
  5. $username = null,
  6. $password = null,
  7. $jar = null,
  8. $https = true;
  9.  
  10. public function __construct($username = null, $password = null, $jar = null, $login = false) {
  11. $this->username = $username;
  12. $this->password = $password;
  13. $this->jar = $jar;
  14.  
  15. if (!file_exists($this->jar)) {
  16. mkdir($this->jar, 0777, true);
  17. }
  18. if ($login) {
  19. $this->login();
  20. }
  21. }
  22.  
  23. private function request($url, $data = null, $header = false, $cookie = false, $token = false, $content_type = 'application/x-www-form-urlencodedapplication/x-www-form-urlencoded') {
  24. $url = ($this->https ? 'https://' : 'http://') . $url;
  25. $headers = array('Connection: keep-alive');
  26. $curl = curl_init();
  27. curl_setopt($curl, CURLOPT_URL, $url);
  28. curl_setopt($curl, CURLOPT_REFERER, $url);
  29. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  30. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  31. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  32.  
  33. if (isset($data)) {
  34. curl_setopt($curl, CURLOPT_POST, true);
  35. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  36. }
  37.  
  38. if ($header === true) {
  39. curl_setopt($curl, CURLOPT_HEADER, true);
  40. curl_setopt($curl, CURLINFO_HEADER_OUT, true);
  41. }
  42.  
  43. if ($cookie === true) {
  44. $cookie = $this->getCookie();
  45. curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
  46. curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
  47. }
  48.  
  49. if ($token === true) {
  50. array_push($headers, 'X-CSRF-TOKEN: ' . $this->getToken());
  51. }
  52.  
  53. if (isset($content_type)) {
  54. array_push($headers, 'Content-Type: ' . $content_type);
  55. }
  56.  
  57. if (!empty($headers)) {
  58. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  59. }
  60.  
  61. $info = curl_getinfo($curl);
  62. $response = curl_exec($curl);
  63.  
  64. if ($info['http_code'] === 200) {
  65. return true;
  66. } elseif ($info['http_code'] === 500 || $info['http_code'] === 403) {
  67. return false;
  68. }
  69.  
  70. return $response;
  71. }
  72.  
  73. private function getCookie($username = null) { //Thinking to store the cookies in a database...
  74. $username = (!isset($username) ? $this->username : $username);
  75.  
  76. return ($this->jar . (($this->encryption === null) ? $username : hash($this->encryption, $username)));
  77. }
  78.  
  79. private function removeCookie($username = null) {
  80. $username = (!isset($username) ? $this->username : $username);
  81. unlink($this->getCookie($username));
  82. }
  83.  
  84. private function getToken() {
  85. //$json = http_build_query(array('subject' => 'Token', 'body' => 'Token', 'recipientid' => 60802538, 'cacheBuster' => time())); //I don't think I need to even send data. Lel wut
  86. $request = $this->request('www.roblox.com/messages/send', '', true, true, false);
  87. $headers = http_parse_headers($request);
  88. return $headers['X-CSRF-TOKEN'];
  89. }
  90.  
  91. private function calculatePrice($rap) { //gotta make this better
  92. $price = round($rap/500, 0, PHP_ROUND_HALF_UP);
  93. $price = ($price <= 0) ? 1 : $price;
  94. return $price;
  95. }
  96.  
  97. //Public APIs
  98. public function login() { //Could set R$ amount here or I could make a function... Or both
  99. $json = json_encode(array('username' => $this->username, 'password' => $this->password));
  100. $data = json_decode($this->request('www.roblox.com/MobileAPI/Login', $json, false, true, false, 'application/json'));
  101.  
  102. if ($data->Status === 'OK') {
  103. $info = $data->UserInfo;
  104. $this->user_id = $info->UserID;
  105.  
  106. return true;
  107. }
  108.  
  109. return false;
  110. }
  111.  
  112. public function logout() {
  113. return $this->request('api.roblox.com/sign-out/v1', array(), false, true, false);
  114. }
  115.  
  116. public function isLoggedIn() {
  117. if ($this->request('www.roblox.com/Game/GetCurrentUser.ashx', null, false, true, false) !== 'null') {
  118. return true;
  119. }
  120.  
  121. $this->removeCookie();
  122. return false;
  123. }
  124.  
  125. public function getUserFund() {
  126. return json_decode($this->request('api.roblox.com/my/balance', null, false, true, false), true);
  127. }
  128.  
  129. public function getUserLimiteds($id = null) {
  130. $total = $this->request("www.roblox.com/Trade/inventoryhandler.ashx?filter=0&userid=$id&page=1&itemsPerPage=14", null, false, true, false, 'application/json');
  131. return $total;
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement