-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
MultiBot.py
315 lines (275 loc) · 11.6 KB
/
MultiBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# encoding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import json, traceback
import multiprocessing
import os, sys, random, time, platform, re, urllib2
import shutil
import threading
from time import gmtime, strftime, sleep
from threading import *
from subprocess import call
import requests
import urllib3
urllib3.disable_warnings()
Null = ""
proxyCur = 0
hashkeyCur = 0
try:
os.mkdir('configs/temp')
except:
pass
AccountLock = Semaphore(value=1)
screen_lock = Semaphore(value=1)
MultiBotConfig = json.loads(open('configs/MultiBotConfig.json').read())
def Lprint(content):
content = "{0} {1}".format(strftime("%Y-%m-%d %H:%M:%S"), content)
screen_lock.acquire()
print(content)
screen_lock.release()
def stop():
Lprint('Interrupted stopping')
try:
sys.exit(0)
except SystemExit:
os._exit(0)
class Manager:
def __init__(self):
# Accounts = []
# self.Accounts = Accounts
self.hashkeyCur = 0
self.proxyCur = 0
self.accountNum = 0
self.accountLeft = 0
# Loading accounts
try:
with open('configs/' + MultiBotConfig[u'AccountsFile']) as accountsFile:
self.Accounts = accountsFile.read().splitlines()
if MultiBotConfig[u'AccountRunOrder']:
Accounts = random.sample(self.Accounts, len(self.Accounts))
except IOError:
Lprint('configs/{} does not exist'.format(MultiBotConfig[u'AccountsFile']))
self.accountNum = len(self.Accounts)
self.accountLeft = self.accountNum
# Loading proxies
try:
with open('configs/' + MultiBotConfig[u'ProxyFile']) as proxyFile:
self.proxyAll = proxyFile.read().splitlines()
except IOError:
print('configs/{} does not exist'.format(MultiBotConfig[u'ProxyFile']))
# Loading hashkeys
try:
with open('configs/' + MultiBotConfig[u'HashKeyFile']) as hashkeyFile:
self.hashkeyAll = hashkeyFile.read().splitlines()
self.hashkeyNum = len(self.hashkeyAll)
except IOError:
Lprint('configs/{} does not exist'.format(MultiBotConfig[u'HashKeyFile']))
# get a account to run
def GetAccount(self):
if self.accountLeft > 0:
AccountLock.acquire()
AccountTemp = self.Accounts[0]
del self.Accounts[0]
AccountLock.release()
self.accountLeft = self.accountLeft - 1
return AccountTemp
else:
return None
# back to the pool
def SetAccount(self, Account):
AccountLock.acquire()
self.Accounts.append(Account)
AccountLock.release()
return True
# check hashkey if valid and use it
@property
def GetHashKey(self):
while True:
try:
hashkey = self.hashkeyAll[0]
del self.hashkeyAll[0]
headers = {'X-AuthToken': hashkey}
r = requests.post('http://pokehash.buddyauth.com/api/v133_1/hash', data='', headers=headers)
if str(r.headers).find("X-MaxRequestCount") != -1:
Lprint("{} is valid".format(hashkey[:-10]))
self.hashkeyAll.append(hashkey)
return hashkey
elif r.text.find("Could not verify your authentication details") != -1:
Lprint("key not valid")
elif r.status_code == 401:
self.hashkeyAll.append(hashkey)
Lprint("temp banned waiting 3 min")
time.sleep(180)
except KeyboardInterrupt:
stop()
except IndexError:
Lprint("no valid hashkey! exit in 10s")
sleep(10)
stop()
except Exception:
pass
def getProxy(self):
while True:
try:
proxy = self.proxyAll[0]
del self.proxyAll[0]
proxies = {"http": "http://{0}".format(proxy), "https": "https://" + proxy}
headers = {'user-agent': 'Niantic App'}
if requests.get('https://pgorelease.nianticlabs.com/plfe/', headers=headers,
proxies=proxies).status_code == 200:
headers = {'user-agent': 'pokemongo/1 CFNetwork/758.5.3 Darwin/15.6.0'}
if requests.get('https://sso.pokemon.com/', headers=headers, proxies=proxies).status_code == 200:
self.proxyAll.append(proxy)
return str(proxy)
else:
Lprint("Proxy {} is Banned or offline".format(proxy))
else:
Lprint("Proxy {} is Banned or offline".format(proxy))
except IndexError:
Lprint("no valid Proxy found exit in 10s")
sleep(10)
stop()
except Exception:
pass
def MakeConf(CurThread, username, password):
killswitch_url = 'https://raw.githubusercontent.com/PokemonGoF/PokemonGo-Bot/dev/killswitch.json'
try:
jsonData = json.loads(open('configs/' + MultiBotConfig[u'AuthJsonFile']).read())
jsonData[u'username'] = username
jsonData[u'password'] = password
jsonData[u'hashkey'] = Manager.GetHashKey
with open('configs/temp/auth-' + str(CurThread) + '.json', 'w') as s:
s.write(json.dumps(jsonData))
s.close()
jsonData = json.loads(open('configs/' + MultiBotConfig[u'ConfigJsonFile']).read())
# Thanks to MerlionRock for the killswitch
if jsonData.get('killswitch'):
response = urllib2.urlopen(killswitch_url)
killswitch_data = json.load(response)
response.close()
if killswitch_data['killswitch']:
print "\033[91mKill Switch Activated By: \033[0m" + format(killswitch_data['activated_by'])
print "\033[91mMessage: \033[0m\n" + format(killswitch_data['message']) + "\n\n\n"
stop()
if MultiBotConfig.get(u'CompleteTutorialNickName'):
for i in range(len(jsonData[u'tasks'])):
try:
if jsonData[u'tasks'][i][u'config'][u'nickname']:
jsonData[u'tasks'][i][u'config'][u'nickname'] = username.replace('_', '')
break
except KeyboardInterrupt:
stop()
except:
pass
if MultiBotConfig.get(u'WebSocket')[u'start_embedded_server']:
for i in range(len(jsonData[u'tasks'])):
try:
if jsonData[u'websocket'][u'server_url']:
jsonData[u'websocket'][u'server_url'] = MultiBotConfig[u'WebSocket'][u'IP'] + ':' + str(
MultiBotConfig[u'WebSocket'][u'Port'] + CurThread)
break
except KeyboardInterrupt:
stop()
except:
jsonData.items().append(
"{u'websocket':,{u'server_url': u'" + MultiBotConfig[u'WebSocket'][u'IP'] + ":" + str(
MultiBotConfig[u'WebSocket'][u'Port'] + CurThread) + "u'start_embedded_server': True}")
elif not MultiBotConfig[u'WebSocket'][u'start_embedded_server']:
try:
del jsonData[u'websocket']
except KeyboardInterrupt:
stop()
except:
pass
if MultiBotConfig.get('TelegramTask'):
try:
for i in range(len(jsonData[u'tasks'])):
if jsonData[u'tasks'][1][u'type'] == u'TelegramTask':
jsonData[u'tasks'][i][u'config'][u'enabled'] = True
break
except KeyboardInterrupt:
stop()
except:
pass
if not MultiBotConfig.get('TelegramTask'):
try:
for i in range(len(jsonData[u'tasks'])):
if jsonData[u'tasks'][1][u'type'] == u'TelegramTask':
jsonData[u'tasks'][i][u'config'][u'enabled'] = False
break
except KeyboardInterrupt:
stop()
except:
pass
with open('configs/temp/config-' + str(CurThread) + '.json', 'w') as s:
s.write(json.dumps(jsonData))
s.close()
except IOError:
Lprint('config file error')
time.sleep(30)
except KeyboardInterrupt:
stop()
class ThreadClass(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.paused = True # start out paused
self.state = threading.Condition()
self.Manager = Manager
def run(self):
time.sleep(.1)
self.resume() # unpause self
while Manager.accountLeft > 0:
with self.state:
if self.paused:
self.state.wait() # block until notified
self.CurThread = int(self.getName().replace('Thread-', '')) - 1
self.Account = Manager.GetAccount()
if self.Account == None:
break
username, password = self.Account.split(':')
Lprint('Thread-{0} using account {1}'.format(self.CurThread, username))
try:
MakeConf(self.CurThread, username, password)
StartCmd = "python pokecli.py -af configs/temp/auth-{0}.json -cf configs/temp/config-{0}.json --walker_limit_output {1}".format(
self.CurThread, MultiBotConfig[u'walker_limit_output'])
if MultiBotConfig[u'UseProxy']:
proxy = Manager.getProxy()
if platform.system() == "Linux" or platform.system() == "darwin":
call('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"; ' + StartCmd, shell=True)
if platform.system() == "Windows" or platform.system() == "win32" or platform.system() == "cygwin":
call('set HTTP_PROXY="http://' + proxy + '" & set HTTPS_PROXY="https://' + proxy + '" & ' + StartCmd, shell=True)
else:
call(StartCmd, shell=True)
except Exception as e:
Lprint(e)
time.sleep(60)
except KeyboardInterrupt:
stop()
finally:
self.Manager.SetAccount(self.Account)
Lprint('Thread-{0} has no more accounts run. Thread stopped.'.format(self.CurThread))
def resume(self):
with self.state:
self.paused = False
self.state.notify() # unblock self if waiting
def pause(self):
with self.state:
self.paused = True # make self block and wait
def stop(self):
self.stopped = True
def start():
global Manager
Manager = Manager()
try:
for i in range(MultiBotConfig[u'Threads']):
t = ThreadClass()
time.sleep(0.1)
t.start()
time.sleep(5)
except KeyboardInterrupt:
Lprint("stopping all Threads")
for i in range(MultiBotConfig[u'Threads']):
t.stop()
stop()
exit(0)
if __name__ == "__main__":
start()