forked from PokemonGoF/PokemonGo-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiBot.py
251 lines (226 loc) · 9 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
#encoding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import gzip
import json
import multiprocessing
import os
import platform
import re
import shutil
import sys
import threading
import time
from time import gmtime, strftime, sleep
from threading import *
import requests
Null = ""
proxyCur = 0
hashkeyCur = 0
accountNum = 0
try:
os.rmdir('configs/temp')
except:
pass
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 getProxy():
try:
while True:
try:
with open('configs/' + MultiBotConfig[u'ProxyFile']) as proxyFile:
proxyAll = proxyFile.readlines()
proxyNum = sum(1 for line in open('configs/' + MultiBotConfig[u'ProxyFile']))
global proxyCur
global proxy
proxy = proxyAll[proxyCur].replace('\n', '').replace('\r', '')
proxies = {"http": "http://" + proxy, "https": "https://" + proxy}
proxyCur += 1
if proxyCur >= proxyNum:
proxyCur = 0
headers = {'user-agent': 'Niantic App'}
if requests.get('https://pgorelease.nianticlabs.com/plfe/', headers=headers, proxies=proxies, timeout=15).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, timeout=15).status_code == 200:
return proxy
else:
Lprint ("Proxy {} is Banned or offline".format(proxy))
else:
Lprint ("Proxy {} is Banned or offline".format(proxy))
except Exception as e:
Lprint (e)
pass
except KeyboardInterrupt:
stop()
except IOError:
Lprint ('configs/{} does not exist'.format(MultiBotConfig[u'ProxyFile']))
except KeyboardInterrupt:
stop()
try:
Accounts = []
with open('configs/' + MultiBotConfig[u'AccountsFile']) as f:
for line in f:
line = line.replace('\n', '').replace('\r', '').replace(',', '.')
Accounts.append(line)
except IOError:
Lprint ('configs/{} does not exist'.format(MultiBotConfig[u'AccountsFile']))
except KeyboardInterrupt:
stop()
def getHashKey():
try:
with open('configs/' + MultiBotConfig[u'HashKeyFile']) as hashkeyFile:
hashkeyAll = hashkeyFile.readlines()
hashkeyNum = sum(1 for line in open('configs/' + MultiBotConfig[u'HashKeyFile']))-1
global hashkeyCur
global hashkey
if hashkeyCur is hashkeyNum:
hashkeyCur = 0
hashkeyCur += 1
return hashkeyAll[hashkeyCur].replace('\n', '').replace('\r', '')
except IOError:
Lprint ('configs/{} does not exist'.format(MultiBotConfig[u'HashKeyFile']))
except KeyboardInterrupt:
stop()
def stop():
Lprint ('Interrupted stopping')
try:
sys.exit(0)
except SystemExit:
os._exit(0)
def AccountManager(Account=None):
AccountLock.acquire()
global Accounts
if Account is None:
AccountTemp = Accounts[0]
del Accounts[0]
AccountLock.release()
return AccountTemp
else:
Accounts.append(Account)
AccountLock.release()
def Lprint (content):
content = "{0} {1}".format(strftime("%Y-%m-%d %H:%M:%S"), content)
screen_lock.acquire()
print (content)
screen_lock.release()
def MakeConf(CurThread, username, password):
try:
jsonData = json.loads(open('configs/' + MultiBotConfig[u'AuthJsonFile']).read())
jsonData[u'username'] = username
jsonData[u'password'] = password
jsonData[u'hashkey'] = 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())
if MultiBotConfig[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('_', '')
except KeyboardInterrupt:
stop()
except:
pass
if MultiBotConfig[u'WebSocket'][u'start_embedded_server']:
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)
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[u'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
except KeyboardInterrupt:
stop()
except:
pass
if not MultiBotConfig[u'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
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()
def run(self):
time.sleep(.1)
self.resume() # unpause self
while True:
with self.state:
if self.paused:
self.state.wait() # block until notified
self.CurThread = int(self.getName().replace('Thread-', '')) -1
self.Account = AccountManager()
self.username, self.password = self.Account.split(':')
Lprint ('Thread-{0} using account {1}'.format(self.CurThread, self.username))
try:
MakeConf(self.CurThread, self.username, self.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']:
self.proxy = getProxy()
if platform.system() == "Linux":
os.system('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"; ' + StartCmd)
if platform.system() == "Windows":
os.system('set HTTP_PROXY="http://' + proxy + '" & set HTTPS_PROXY="https://' + proxy + '" & ' + StartCmd)
os.system(StartCmd)
except Exception as e:
import traceback
Lprint ((e))
time.sleep (60)
except KeyboardInterrupt:
stop()
finally:
AccountManager(self.Account)
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():
try:
for i in range(MultiBotConfig[u'Threads']):
t = ThreadClass()
time.sleep (0.1)
t.start()
time.sleep (10)
except KeyboardInterrupt:
Lprint("stopping all Threads")
for i in range(MultiBotConfig[u'Threads']):
t.stop()
stop()
if __name__ == "__main__":
start()