Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Roblox {
- private $encryption = 'sha256',
- $user_id = null,
- $username = null,
- $password = null,
- $jar = null,
- $https = true;
- public function __construct($username = null, $password = null, $jar = null, $login = false) {
- $this->username = $username;
- $this->password = $password;
- $this->jar = $jar;
- if (!file_exists($this->jar)) {
- mkdir($this->jar, 0777, true);
- }
- if ($login) {
- $this->login();
- }
- }
- private function request($url, $data = null, $header = false, $cookie = false, $token = false, $content_type = 'application/x-www-form-urlencodedapplication/x-www-form-urlencoded') {
- $url = ($this->https ? 'https://' : 'http://') . $url;
- $headers = array('Connection: keep-alive');
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_REFERER, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- if (isset($data)) {
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- }
- if ($header === true) {
- curl_setopt($curl, CURLOPT_HEADER, true);
- curl_setopt($curl, CURLINFO_HEADER_OUT, true);
- }
- if ($cookie === true) {
- $cookie = $this->getCookie();
- curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
- curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
- }
- if ($token === true) {
- array_push($headers, 'X-CSRF-TOKEN: ' . $this->getToken());
- }
- if (isset($content_type)) {
- array_push($headers, 'Content-Type: ' . $content_type);
- }
- if (!empty($headers)) {
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- }
- $info = curl_getinfo($curl);
- $response = curl_exec($curl);
- if ($info['http_code'] === 200) {
- return true;
- } elseif ($info['http_code'] === 500 || $info['http_code'] === 403) {
- return false;
- }
- return $response;
- }
- private function getCookie($username = null) { //Thinking to store the cookies in a database...
- $username = (!isset($username) ? $this->username : $username);
- return ($this->jar . (($this->encryption === null) ? $username : hash($this->encryption, $username)));
- }
- private function removeCookie($username = null) {
- $username = (!isset($username) ? $this->username : $username);
- unlink($this->getCookie($username));
- }
- private function getToken() {
- //$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
- $request = $this->request('www.roblox.com/messages/send', '', true, true, false);
- $headers = http_parse_headers($request);
- return $headers['X-CSRF-TOKEN'];
- }
- private function calculatePrice($rap) { //gotta make this better
- $price = round($rap/500, 0, PHP_ROUND_HALF_UP);
- $price = ($price <= 0) ? 1 : $price;
- return $price;
- }
- //Public APIs
- public function login() { //Could set R$ amount here or I could make a function... Or both
- $json = json_encode(array('username' => $this->username, 'password' => $this->password));
- $data = json_decode($this->request('www.roblox.com/MobileAPI/Login', $json, false, true, false, 'application/json'));
- if ($data->Status === 'OK') {
- $info = $data->UserInfo;
- $this->user_id = $info->UserID;
- return true;
- }
- return false;
- }
- public function logout() {
- return $this->request('api.roblox.com/sign-out/v1', array(), false, true, false);
- }
- public function isLoggedIn() {
- if ($this->request('www.roblox.com/Game/GetCurrentUser.ashx', null, false, true, false) !== 'null') {
- return true;
- }
- $this->removeCookie();
- return false;
- }
- public function getUserFund() {
- return json_decode($this->request('api.roblox.com/my/balance', null, false, true, false), true);
- }
- public function getUserLimiteds($id = null) {
- $total = $this->request("www.roblox.com/Trade/inventoryhandler.ashx?filter=0&userid=$id&page=1&itemsPerPage=14", null, false, true, false, 'application/json');
- return $total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement