Skip to content

Commit

Permalink
Merge pull request #6140 from Xairooo/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcolomar authored Jul 26, 2017
2 parents c115cd2 + 4e40e53 commit 997b094
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
41 changes: 23 additions & 18 deletions MultiBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# 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
Expand All @@ -17,12 +18,15 @@
hashkeyCur = 0
accountNum = 0
try:
os.stat('configs/temp')
os.rmdir('configs/temp')
except:
os.mkdir('configs/temp')
pass
try:
os.mkdir('configs/temp')
except:
pass
AccountLock = Semaphore(value=1)
MultiBotConfig = json.loads(open('configs/MultiBotConfig.json').read())
ThreadNum = MultiBotConfig[u'Threads']

def getProxy():
try:
Expand Down Expand Up @@ -89,11 +93,9 @@ def AccountManager(Account=None):
Accounts.append(Account)
AccountLock.release()

def MakeConf(CurThread):
def MakeConf(CurThread, username, password):
try:
jsonData = json.loads(open('configs/' + MultiBotConfig[u'AuthJsonFile']).read())
Account = AccountManager()
username, password = Account.split(':')
jsonData[u'username'] = username
jsonData[u'password'] = password
jsonData[u'hashkey'] = getHashKey()
Expand All @@ -111,42 +113,45 @@ def MakeConf(CurThread):
except:
pass
try:
jsonData[u'websocket'][u'server_url'] = MultiBotConfig[u'WebSocket'][u'IP'] + ':' + str(MultiBotConfig[u'WebSocket'][u'Port'] + CurThread)
if jsonData[u'websocket'][u'start_embedded_server']:
jsonData[u'websocket'][u'server_url'] = MultiBotConfig[u'WebSocket'][u'IP'] + ':' + str(MultiBotConfig[u'WebSocket'][u'Port'] + CurThread)
except:
pass
print 'error websocket'

with open('configs/temp/config-' + str(CurThread) + '.json', 'w') as s:
s.write(json.dumps(jsonData))
s.close()

except IOError:
print 'config file error'
time.sleep(30)

class ThreadClass(threading.Thread):
def run(self):
CurThread = int(self.getName().replace('Thread-', '')) -1
self.CurThread = int(self.getName().replace('Thread-', '')) -1
while True:
Account = AccountManager()
username, password = Account.split(':')
self.Account = AccountManager()
self.username, self.password = self.Account.split(':')
print 'Thread-{0} using account {1}'.format(self.CurThread, self.username)
try:
MakeConf(CurThread)
MakeConf(self.CurThread, self.username, self.password)
if MultiBotConfig[u'UseProxy']:
proxy = getProxy()
self.proxy = getProxy()
if platform.system() == "Linux":
os.system('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"')
self.os.system('export HTTP_PROXY="http://' + proxy + '"; export HTTPS_PROXY="https://' + proxy + '"')
if platform.system() == "Windows":
os.system('')
self.os.system('')
os.system(
"python pokecli.py -af configs/temp/auth-{0}.json -cf configs/temp/config-{0}.json --walker_limit_output {1}".format(
CurThread, MultiBotConfig[u'walker_limit_output']))
self.CurThread, MultiBotConfig[u'walker_limit_output']))
except Exception as e:
import traceback
print("Generic Exception: " + traceback.format_exc())
finally:
AccountManager(Account)
AccountManager(self.Account)
time.sleep (60)
def start():
for i in range(ThreadNum):
for i in range(MultiBotConfig[u'Threads']):
t = ThreadClass()
time.sleep (0.1)
t.start()
Expand Down
3 changes: 2 additions & 1 deletion configs/MultiBotConfig.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"ConfigJsonFile": "config.json",
"CompleteTutorialNickName": true,
"WebSocket": {
"start_embedded_server": false,
"IP": "127.0.0.1",
"Port": "4000"
"Port": 4000
},
"walker_limit_output": true
}

0 comments on commit 997b094

Please sign in to comment.