Guest User

Aa

a guest
Jun 30th, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. from multiprocessing.pool import ThreadPool
  2. import threading
  3. import subprocess
  4. import configparser
  5. import requests
  6. import signal
  7. import psutil
  8. import random
  9. import string
  10. import os.path
  11. import time
  12. import sys
  13. import os
  14.  
  15.  
  16. class RobloxBot:
  17. """A simple Roblox bot class"""
  18. def __init__(self):
  19. # creates a request session
  20. self.session = requests.session()
  21. # creates headers
  22. self.headers = {'User-Agent': 'Roblox/WinInet'}
  23. # sets sessions headers
  24. self.session.headers.update(self.headers)
  25.  
  26. def sign_in(self, username, password):
  27. # creates login payload
  28. payload = {'username': username, 'password': password, 'submitLogin': 'Log+In'}
  29. # loops until successful
  30. while True:
  31. # grabs random proxy
  32. proxy = random.choice(proxies)
  33. # notifies user
  34. # print('Trying proxy:', proxy)
  35. # adds proxy to the proxies dict to be used with requests
  36. proxy_payload = {'http': 'http://' + proxy, 'https': 'https://' + proxy}
  37. # sets sessions proxy
  38. self.session.proxies.update(proxy_payload)
  39. # attempts to log in via proxy
  40. try:
  41. # posts login data to roblox
  42. r = self.session.post('https://www.roblox.com/newlogin', data=payload, headers={'Referer': 'https://www.roblox.com/'}, timeout=5)
  43. # checks status
  44. r.raise_for_status()
  45. # notifies user
  46. # print('Found working proxy:', proxy)
  47. except:
  48. # print(proxy, 'could not connect.')
  49. continue
  50. # validates log in
  51. if 'My Feed' in r.text:
  52. # notifies user
  53. print('Successfully logged into:', username)
  54. return True
  55. elif 'not a robot!' in r.text:
  56. # if a captcha is present
  57. # print('Captcha found. Retrying.')
  58. continue
  59. else:
  60. # notifies user
  61. # print('Login failed for:', username)
  62. return False
  63.  
  64. def like_game(self, game_id):
  65. # creates referer headers
  66. referer = {'Referer': 'https://www.roblox.com/games/{}'.format(game_id)}
  67. # gets authticket for user
  68. auth_ticket = self.session.get('https://www.roblox.com/game-auth/getauthticket', headers=referer).text
  69. # gets browser tracker
  70. browser = ''.join(str(random.randint(0,9)) for x in range(10))
  71. # formats uri parameters for game launch
  72. mapped_uri = "roblox-player:1+launchmode:play+gameinfo:{}+launchtime:1493656459622+placelauncherurl:https%3A%2F%2Fassetgame.roblox.com%2Fgame%2FPlaceLauncher.ashx%3Frequest%3DRequestGame%26browserTrackerId%3D{}%26placeId%3D{}%26isPartyLeader%3Dfalse+browsertrackerid:{}".format(auth_ticket, browser, game_id, browser)
  73. with launch_lock:
  74. # launches roblox
  75. roblox = subprocess.Popen([game_path, mapped_uri])
  76. # notifies user
  77. print('Successfully launched Roblox and joined game:', game_id)
  78. # waits 10 seconds
  79. time.sleep(game_launch_time)
  80. # kills process
  81. for process in psutil.process_iter():
  82. # check whether the process name matches
  83. if process.name() == 'RobloxPlayerBeta.exe':
  84. # kills process
  85. process.kill()
  86. # gets cookies
  87. r = self.session.get('https://www.roblox.com/games/{}'.format(game_id))
  88. # extracts csrf token
  89. csrf_token = r.text.split("Roblox.XsrfToken.setToken('")[-1].split("');")[0]
  90. # creates like payload
  91. payload = {'assetId': game_id, 'vote': 'true'}
  92. # creates like headers
  93. headers = {'X-CSRF-TOKEN': csrf_token, 'Referer': r.url}
  94. # sends like post request to roblox
  95. r = self.session.post('https://www.roblox.com/voting/vote', params=payload, headers=headers)
  96. # validates like
  97. if r.json()['Success']:
  98. # notifies user
  99. print('Successfully liked game:', game_id)
  100. else:
  101. # notifies user
  102. print('There was a problem liking the game:', game_id)
  103. print('Reason:', r.json()['Model']['ReasonForNotVoteable'])
  104. # sends favourite to roblox
  105. r = self.session.post('https://www.roblox.com/favorite/toggle', params={'assetId': game_id}, headers=headers)
  106. # validates favourite
  107. if r.json()['success']:
  108. # notifies user
  109. print('Successfully favourited game:', game_id)
  110. else:
  111. # notifies user
  112. print('There was a problem favoriting game:', game_id)
  113.  
  114. def start(userpass):
  115. # instantiates roblox bot
  116. bot = RobloxBot()
  117. # signs up on roblox with username and password
  118. if bot.sign_in(username=userpass[0], password=userpass[1]):
  119. # likes game with certain id
  120. bot.like_game(game_id=game_id)
  121.  
  122. if __name__ == '__main__':
  123. launch_lock = threading.Lock()
  124. # reads config file
  125. config = configparser.ConfigParser()
  126. config.read('config.ini')
  127. try:
  128. # sets game path
  129. game_path = config['general']['game_path']
  130. # verifies game exists
  131. if os.path.isfile(game_path):
  132. print('Verified game exists.')
  133. else:
  134. sys.exit('Could not find your Roblox launcher.')
  135. # sets proxy list path
  136. proxy_list_path = config['general']['proxy_list_path']
  137. # gets proxy list
  138. proxies = open(proxy_list_path).read().split('\n')
  139. # notifies user
  140. print('Loaded proxies.')
  141. # sets account list path
  142. account_list_path = config['general']['account_list_path']
  143. # notifies user
  144. print('Loaded accounts.')
  145. # gets thread count
  146. thread_count = int(config['general']['thread_count'])
  147. game_launch_time = int(config['general']['game_launch_time'])
  148. except KeyError:
  149. sys.exit('Config file error.')
  150. # prompts user for game id
  151. game_id = input('Please enter the game mode ID: ')
  152. # gets accounts
  153. accounts = [x.split(':') for x in open(account_list_path).read().split('\n')]
  154. # iterates through accounts
  155. # multi-threaded processes
  156. p = ThreadPool(processes=thread_count) # creates a pool of workers
  157. p.map(start, accounts) # calls check_proxy with the proxy as parameter
  158. p.close() # closes the multi-threaded processes
Add Comment
Please, Sign In to add comment