Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import mechanize
- import sys, logging
- import time
- import random
- import string
- import requests
- import re
- import math
- import email
- import smtplib
- import shutil
- from PIL import Image, ImageOps
- from pytesseract import image_to_string
- from random import randint
- from datetime import datetime, timedelta
- USERNAME = "markd315@mailinator.com"
- PASSWORD = "redacted lul"
- DEFAULT_RAID = '33'
- lastNewsflash = datetime(2011,8,15,8,15,12,0)
- def find_between( s, first, last ):
- try:
- start = s.index( first ) + len( first )
- end = s.index( last, start )
- return s[start:end]
- except ValueError:
- return ""
- def printHTML(html):
- p = re.compile(r'<.*?>')
- data = p.sub('', html)
- print(data)
- def meets(has, required):
- for ship in required:
- if(required[ship] == '' or int(required[ship])== 0): #None required
- continue
- if has[ship] == '' or int(has[ship]) < int(required[ship]):
- #print("lacks %s"%(ship))
- return False
- return True
- def extractResources(html):
- m = find_between(html, 'var metal_value = ', ';')
- c = find_between(html, 'var crystal_value = ', ';')
- d = find_between(html, 'var deuterium_value = ', ';')
- return [m, c, d]
- def extractShips(html):
- scs = find_between(html, 'alt="Small Cargo Ship', '"')
- lcs = find_between(html, 'alt="Large Cargo Ship', '"')
- bs = find_between(html, 'alt="Battleship', '"')
- r = find_between(html, 'alt="Recycler', '"')
- esp = find_between(html, 'alt="Espionage Ship', '"')
- bom = find_between(html, 'alt="Bomber', '"')
- rip = find_between(html, 'alt="Death Star', '"')
- bc = find_between(html, 'alt="Battlecruiser', '"')
- ec = find_between(html, 'alt="Elite Cargo', '"')
- voy = find_between(html, 'alt="Voyager', '"')
- return{'scs': scs,
- 'lcs': lcs,
- 'bs': bs,
- 'r': r,
- 'esp': esp,
- 'bom': bom,
- 'rip': rip,
- 'bc': bc,
- 'ec': ec,
- 'voy': voy}
- def detectSlots(cookies, target):
- html = getFleetData(cookies, target)
- try:
- used = int(find_between(html, 'transparent;">Fleets ', ' /'))
- prefix = 'transparent;">Fleets ' + str(used) + ' / '
- total = int(find_between(html, prefix, '<'))
- print("detected usage of %.0f of %.0f slots" % (used, total), flush=True)
- return total-used
- except ValueError:
- print("noticed fleets value error, logging fail html and switching to Harris")
- useEmail("Slots recovery", str(html))
- f = open("err.log", "w")
- f.write(html)
- f.close()
- changeLoc(cookies, target)
- return 0
- def sendemail(from_addr, to_addr_list, cc_addr_list,
- subject, message,
- login, password,
- smtpserver='smtp.gmail.com:587'):
- header = 'From: %s\n' % from_addr
- header += 'To: %s\n' % ','.join(to_addr_list)
- header += 'Cc: %s\n' % ','.join(cc_addr_list)
- header += 'Subject: %s\n' % subject
- message = header + message
- server = smtplib.SMTP(smtpserver)
- server.starttls()
- server.login(login,password)
- problems = server.sendmail(from_addr, to_addr_list, message)
- server.quit()
- def useEmail(subject, message):
- sendemail('markd315@gmail.com', ['markd315@gmail.com'], [],
- 'Z: '+subject, message,
- 'markd315', 'nOthXoh5&')
- def getFleetData(cookies, target):
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Connection': 'keep-alive',
- 'Host': 'www.zorgempire.net',
- 'Referer': 'https://www.zorgempire.net/uni/reloaded/galaxy.php?mode=1',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'cache-control': 'no-cache',
- }
- params = (
- ('galaxy', str(target[0])),
- ('system', str(target[1])),
- ('planet', str(target[2])),
- ('planettype', str(target[3])),
- ('target_mission', '1'), # 1 is attack, need to learn others
- )
- return str(requests.get('https://www.zorgempire.net/uni/reloaded/fleet.php', headers=headers, params=params, cookies=cookies).content)
- def getOverview(cookies, target):
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Connection': 'keep-alive',
- 'Host': 'www.zorgempire.net',
- 'Referer': 'https://www.zorgempire.net/uni/reloaded/galaxy.php?mode=1',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'cache-control': 'no-cache',
- }
- params = (
- ('galaxy', str(target[0])),
- ('system', str(target[1])),
- ('planet', str(target[2])),
- ('planettype', str(target[3])),
- ('target_mission', '1'), # 1 is attack, need to learn others
- )
- return requests.get('https://www.zorgempire.net/uni/reloaded/overview.php', headers=headers, params=params, cookies=cookies).content
- def flow1():
- headers = {
- 'Connection': 'keep-alive',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate',
- 'Accept-Language': 'en-US,en;q=0.9',
- }
- return requests.get('http://www.zorgempire.net/', headers=headers)
- def flow2(cookies):
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Connection': 'keep-alive',
- 'Referer': 'https://www.zorgempire.net/index.php?try=fail',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'cache-control': 'no-cache',
- }
- return requests.get('https://www.zorgempire.net/login_d.php', headers=headers, cookies=cookies)
- def flow3(cookies):
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Cache-Control': 'max-age=0',
- 'Connection': 'keep-alive',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Origin': 'https://www.zorgempire.net',
- 'Referer': 'https://www.zorgempire.net/login_d.php',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'cache-control': 'no-cache',
- }
- data = {
- 'email': USERNAME,
- 'password': PASSWORD,
- 'submit': 'Sign+in',
- 'undefined': ''
- }
- return requests.post('https://www.zorgempire.net/login.php', headers=headers, cookies=cookies, data=data)
- def flow4(cookies):
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Connection': 'keep-alive',
- 'Referer': 'https://www.zorgempire.net/login.php',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'cache-control': 'no-cache',
- }
- return requests.get('https://www.zorgempire.net/account.php', headers=headers, cookies=cookies)
- def flow5(cookies):
- headers = {
- 'Connection': 'keep-alive',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Referer': 'http://www.zorgempire.net/account.php',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- }
- return requests.get('https://www.zorgempire.net/uni/reloaded/', headers=headers, cookies=cookies)
- def loginFlow(USERNAME, PASSWORD):
- cookieResponse = flow1().headers['Set-Cookie']
- cookie = find_between(cookieResponse, 'PHPSESSID=', ';')
- cookies = {
- 'PHPSESSID': cookie
- }
- flow2(cookies)
- flow3(cookies)
- flow4(cookies)
- #If we don't want to redo the whole oauth flow for main, we can just read the cookie out of the console and take it in here, skipping 1-4
- flow5(cookies)
- return cookies
- def createFleet(cookies, target, ships):
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Cache-Control': 'max-age=0',
- 'Connection': 'keep-alive',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Origin': 'https://www.zorgempire.net',
- 'Referer': 'https://www.zorgempire.net/uni/reloaded/fleet.php',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'cache-control': 'no-cache',
- }
- data = {
- 'ship202': ships['scs'],
- 'ship203': ships['lcs'],
- 'ship207': ships['bs'],
- 'ship211': ships['bom'],
- 'ship215': ships['bc'],
- 'ship217': ships['ec'],
- 'ship209': ships['r'],
- 'ship210': ships['esp'],
- 'ship214': ships['rip'],
- 'ship220': ships['voy'],
- 'consumption202': '20',
- 'speed202': '8000',
- 'capacity202': '5000',
- 'consumption203': '50',
- 'speed203': '12000',
- 'capacity203': '25000',
- 'capacity207': '1500',
- 'consumption207': '500',
- 'speed207': '31000',
- 'capacity209': '20000',
- 'consumption209': '300',
- 'speed209': '4600',
- 'capacity210': '0',
- 'consumption210': '0',
- 'speed210': '230000000',
- 'capacity211': '500',
- 'consumption211': '750',
- 'speed211': '11200',
- 'capacity214': '1000000',
- 'consumption214': '500',
- 'speed214': '310',
- 'capacity215': '750',
- 'consumption215': '250',
- 'speed215': '31000',
- 'capacity217': '10000000',
- 'consumption217': '2500',
- 'speed217': '28000',
- 'capacity220': '50000',
- 'consumption220': '100',
- 'speed220': '28000',
- 'galaxy': '0',
- 'system': '0',
- 'planet': '0',
- 'planet_type': '0',
- 'acs_attack': '',
- 'mission': '0',
- 'maxepedition': '',
- 'curepedition': '',
- 'target_mission': '0'
- }
- response = requests.post('https://www.zorgempire.net/uni/reloaded/floten1.php', headers=headers, cookies=cookies, data=data)
- response = str(response.content).replace('"', '')
- return find_between(response, "name=usedfleet value=", " />")
- def giveOrders(cookies, target, usedfleet, ships, res, src, mission, speed):
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Cache-Control': 'max-age=0',
- 'Connection': 'keep-alive',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Origin': 'https://www.zorgempire.net',
- 'Referer': 'https://www.zorgempire.net/uni/reloaded/floten1.php',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'cache-control': 'no-cache',
- }
- data = {
- 'ship202' : ships['scs'],
- 'ship203': ships['lcs'],
- 'ship207': ships['bs'],
- 'ship211': ships['bom'],
- 'ship215': ships['bc'],
- 'ship217': ships['ec'],
- 'ship209': ships['r'],
- 'ship210': ships['esp'],
- 'ship214': ships['rip'],
- 'ship220': ships['voy'],
- 'consumption203': '50',
- 'speed203': '17250',
- 'consumption202': '20',
- 'speed202': '8000',
- 'capacity202': '5000',
- 'capacity203': '25000',
- 'capacity207': '1500',
- 'consumption207': '500',
- 'speed207': '31000',
- 'capacity211': '500',
- 'consumption211': '750',
- 'speed211': '11200',
- 'capacity217': '10000000',
- 'consumption217': '2500',
- 'speed217': '28000',
- 'capacity209': '20000',
- 'consumption209': '300',
- 'speed209': '4600',
- 'capacity210': '0',
- 'consumption210': '0',
- 'speed210': '230000000',
- 'capacity214': '1000000',
- 'consumption214': '500',
- 'speed214': '310',
- 'capacity215': '750',
- 'consumption215': '250',
- 'speed215': '31000',
- 'capacity220': '50000',
- 'consumption220': '100',
- 'speed220': '28000',
- 'speedallsmin': '8000',
- 'usedfleet': usedfleet,
- 'galaxyend': '0',
- 'systemend': '0',
- 'planetend': '0',
- 'speedfactor': '8',
- 'thisresource1': '612841',
- 'thisresource2': '583866',
- 'thisresource3': '229656',
- 'thisgalaxy': str(src[0]),
- 'thissystem': str(src[1]),
- 'thisplanet': str(src[2]),
- 'thisplanettype': str(src[3]),
- 'galaxy': str(target[0]),
- 'system': str(target[1]),
- 'planet': str(target[2]),
- 'planettype': str(target[3]),
- 'speed': str(speed*10),
- 'maxepedition': '1',
- 'curepedition': '0',
- 'acs_attack': '',
- 'target_mission': '1',
- 'undefined': ''
- }
- min = 100000
- for key in data:
- if str(key)[0:4] == "ship":
- if (data[key] != '') and (int(data[key]) > 0): # Only change min if we are sending some of these
- if min > int(data["speed"+str(key)[4:7]]): #Only change min if actually min
- min = int(data["speed"+str(key)[4:7]])
- data['speedsallmin'] = str(min)
- response = requests.post('https://www.zorgempire.net/uni/reloaded/floten2.php', headers=headers, cookies=cookies, data=data)
- headers = {
- 'Connection': 'keep-alive',
- 'Cache-Control': 'max-age=0',
- 'Origin': 'https://www.zorgempire.net',
- 'Upgrade-Insecure-Requests': '1',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Referer': 'https://www.zorgempire.net/uni/reloaded/floten2.php',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- }
- data = [
- #speedsallmin is a critical variable
- ('speedallsmin', '17250'),
- ('thisresource1', '612841'),
- ('thisresource2', '583866'),
- ('thisresource3', '229675'),
- ('consumption', '116'),
- ('dist', '1005'),
- ('speedfactor', '8'),
- ('speedfactor', '8'),
- ('thisgalaxy', str(src[0])),
- ('thissystem', str(src[1])),
- ('thisplanet', str(src[2])),
- ('galaxy', str(target[0])),
- ('system', str(target[1])),
- ('planet', str(target[2])),
- ('thisplanettype', str(src[3])),
- ('planettype', str(target[3])),
- ('speed', str(speed*10)),
- ('usedfleet', usedfleet),
- ('ship203', ships['lcs']),
- ('ship202', ships['scs']),
- ('ship202', ships['bs']),
- ('ship211', ships['bom']),
- ('ship215', ships['bc']),
- ('ship217', ships['ec']),
- ('ship209', ships['r']),
- ('ship210', ships['esp']),
- ('ship214', ships['rip']),
- ('ship220', ships['voy']),
- ('maxepedition', ''),
- ('curepedition', ''),
- ('acs_attack', ''),
- ('capacity203', '25000'),
- ('consumption203', '50'),
- ('speed203', '12000'),
- ('consumption202', '20'),
- ('speed202', '8000'),
- ('capacity202', '5000'),
- ('ship207', '1'),
- ('capacity207', '1500'),
- ('consumption207', '500'),
- ('speed207', '31000'),
- ('capacity211', '500'),
- ('consumption211', '750'),
- ('speed211', '11200'),
- ('capacity217', '10000000'),
- ('consumption217', '2500'),
- ('speed217', '28000'),
- ('capacity209', '20000'),
- ('consumption209', '300'),
- ('speed209', '4600'),
- ('capacity210', '0'),
- ('consumption210', '0'),
- ('speed210', '230000000'),
- ('capacity214', '1000000'),
- ('consumption214', '500'),
- ('speed214', '310'),
- ('capacity215', '750'),
- ('consumption215', '250'),
- ('speed215', '31000'),
- ('capacity220', '50000'),
- ('consumption220', '100'),
- ('speed220', '28000'),
- ('mission', str(mission)),
- ('resource1', res[0]),
- ('resource2', res[1]),
- ('resource3', res[2]),
- ('holdingtime', '0'),
- ]
- data[0] = ('speedallsmin', str(min))
- response = requests.post('https://www.zorgempire.net/uni/reloaded/floten3.php', headers=headers, cookies=cookies, data=data)
- return response.content
- def changeLoc(cookies, src):
- headers = {
- 'Connection': 'keep-alive',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- }
- if src[0] == 8:
- response = requests.get('https://www.zorgempire.net/uni/reloaded/overview.php?cp=9278&mode=&re=0', headers=headers, cookies=cookies)
- elif src[0] == 6:
- response = requests.get('https://www.zorgempire.net/uni/reloaded/overview.php?cp=21003&mode=&re=0', headers=headers, cookies=cookies)
- return response
- def deployFleet(cookies, target, ships, res, src, mission, speed):
- if(mission == 'atk'):
- misscode = 1
- if(mission == 'acs'):
- misscode = 5
- usedfleet = createFleet(cookies, target, ships)
- ordersResponse = giveOrders(cookies, target, usedfleet, ships, res, src, misscode, speed)
- def deploySafeLineRaid(cookies, line, src):
- line = line.strip()
- split = line.split(' ')
- target = split[0].split('/')
- ships = {
- 'ec': '0', 'scs': '0', 'lcs': '0', 'bom': '0', 'bs': '0', 'bc': '0', 'r': '0', 'rip': '0', 'esp': '0', 'voy': '0'
- }
- if len(split) > 1:
- if (split[1] == 'occ' or (len(split) > 2 and split[2] == 'occ')) and randint(0,9) != 1:
- #print("Skipping occasional target, will replace", flush=True)
- return "occ"
- if split[1] == 'e':
- ships['ec'] = '1'
- else:
- if split[1] != 'occ':
- shipList = split[1].split('/')
- ships['ec'] = shipList[0]
- ships['lcs'] = shipList[1]
- ships['bom'] = shipList[2]
- else:
- ships['lcs'] = DEFAULT_RAID
- else:
- ships['lcs'] = DEFAULT_RAID #42 if expect 550k max
- currentShips = extractShips(getFleetData(cookies, [6, 282, 14, 3]))
- if meets(currentShips, ships):
- print("deploying line %s"%(line), flush=True)
- deployFleet(cookies, [target[0], target[1], target[2], 1], ships, [0, 0, 0], src, 'atk', 1)
- return True
- else:
- print("line %s failed"%(line), flush=True)
- return False
- def bounceFleet(cookies, src, ships, res, speed): #bounce set to 10 minutes flat for one shove
- res[2] = str(int(res[2]) - 50000) #save some room for gas
- deployFleet(cookies, [src[0], src[1], src[2], 1], ships, res, src, 'acs', speed)
- def autoraider(cookies, lines, src, backupFile):
- retries = []
- srcs = []
- occFail = 0
- if lines is None or lines == []: #If nothing, deploy nothing
- return {"retries" : [], "srcs": []}
- for line in lines:
- raidSuccess = deploySafeLineRaid(cookies, line, src)
- while raidSuccess == 'occ':
- lines = open(backupFile, "r").readlines()
- selected = random.sample(lines, 1)
- raidSuccess = deploySafeLineRaid(cookies, selected[0], src)
- if raidSuccess != 'occ' and not raidSuccess:
- retries.append(line)
- srcs.append(src)
- time.sleep(2.35)
- ret = {"retries" : retries, "srcs": srcs}
- return ret
- def retryRaids(cookies, retries, srcs):
- if retries is None or retries == [] or len(retries) != len(srcs): #If nothing, deploy nothing
- return
- for idx, line in enumerate(retries):
- raidSuccess = deploySafeLineRaid(cookies, line, srcs[idx])
- def matchesIncoming(html):
- regex = r"<span class=\".*?\">(A|One of your).*?<a href=.*?fleet.*?(Attack|Espionage)<"
- matches = re.findall(regex, str(html))
- if len(matches) != 0:
- for match in matches:
- if match[0] == "A":
- # We are sending a warning
- print("alerting to email")
- useEmail('Incoming', str(match))
- return True
- return False
- def detectAndDefeatCaptcha(cookies, html, srcs):
- regex = r"Bot Protection"
- if re.search(regex, str(html)):
- useEmail('Botprot', "Check and make sure im ok :(")
- headers = {
- 'Connection': 'keep-alive',
- 'Cache-Control': 'max-age=0',
- 'Origin': 'https://www.zorgempire.net',
- 'Upgrade-Insecure-Requests': '1',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Referer': 'https://www.zorgempire.net/uni/reloaded/overview.php',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9'
- }
- response = requests.get('https://www.zorgempire.net/uni/reloaded/assign.php', headers=headers, cookies=cookies, stream=True)
- with open("assign.php", 'wb') as f:
- response.raw.decode_content = True
- shutil.copyfileobj(response.raw, f)
- time.sleep(2.6)
- #Read Image
- col = Image.open("assign.php")
- gray = col.convert('L')
- bw = gray.point(lambda x: 0 if x<128 else 255, '1')
- bw = bw.convert('L')
- inverted_image = ImageOps.invert(bw)
- inverted_image = ImageOps.crop(inverted_image, border=5)
- inverted_image.save("result_bw.png")
- defeated = image_to_string(inverted_image, config="-c tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz --psm 7 --oem 1")
- print("detected captcha " + defeated)
- data = {
- 'abpass': defeated,
- 'sprotect': 'Continue'
- }
- response = requests.post('https://www.zorgempire.net/uni/reloaded/overview.php', headers=headers, cookies=cookies, data=data).content
- with open("caplog.log", 'w') as f:
- f.write(str(response))
- page = getOverview(cookies, srcs[0])
- return detectAndDefeatCaptcha(cookies, page, srcs)
- return False
- def matchesProbe(html, lastNewsflash):
- #if() #not warned in a while
- regex = r"href=\"show_message.php\?id=\d*\" class=\"scifi\">(.*?)<\/a>\\r\\n.*?(\d\d .*? \d\d .*?)"
- matches = re.findall(regex, str(html))
- if len(matches) != 0:
- print(matches) # format (mission, 00 Hours 00 Mins 00 Secs)
- for match in matches:
- ignore = ["ACS DEFEND FLEET", "ESPIONAGE REPORT", "PARKING FLEET", "FLEET RETURN", "BACK FROM ACS DEFEND", "COMBAT REPORT", "TRANSPORT REPORT"]
- if match[0] in ignore:
- continue
- if "Hours" in match[1]: # outdated
- continue
- if int(match[1][:2]) > 5: # 3 mins outdated
- now = datetime.now()
- if (now - lastNewsflash) > timedelta(minutes=5):
- useEmail('Newsflash', str(match))
- lastNewsflash = datetime.now()
- return (True, lastNewsflash)
- return (False, lastNewsflash)
- #TODO reset warning timer
- def queryAndBounce(cookies, srcs, speed):
- for idx, src in enumerate(srcs):
- if src != srcs[0]: # if not in g8, switch first
- changeLoc(cookies, srcs[idx])
- print('bouncing nonraiding fleet', flush=True)
- try:
- fleetData = getFleetData(cookies, src)
- res = extractResources(fleetData)
- ships = extractShips(fleetData)
- bounceFleet(cookies, src, ships, res, speed)
- except ValueError:
- changeLoc(cookies, srcs[idx])
- fleetData = getFleetData(cookies, src)
- res = extractResources(fleetData)
- ships = extractShips(fleetData)
- bounceFleet(cookies, src, ships, res, speed)
- if src != srcs[0]: # if not in g8, switch after
- changeLoc(cookies, srcs[0])
- def autoraiderSelect(cookies, files, srcs, count, rates):
- if(count < 1):
- return
- #print('initiating raid behavior', flush=True)
- #Pick a file/src combo from the ones given
- ret = {"retries": [], "srcs": []}
- for fileSrcIndex, src in enumerate(srcs):
- toDeploy = round(count*rates[fileSrcIndex])
- print("deploying " + str(toDeploy) + " raids for g" + str(src[0]))
- f = open(files[fileSrcIndex], "r")
- lines = f.readlines()
- f.close()
- selected = lines[:toDeploy]
- f = open(files[fileSrcIndex], "w")
- for line in lines: #Rewrite the file without the selected raids
- if line not in selected:
- if line[-1] != '\n':
- line += '\n'
- f.write(line)
- for line in lines: #Write them back at the end of the file
- if line in selected:
- if line[-1] != '\n':
- line += '\n'
- f.write(line)
- f.close()
- if(fileSrcIndex != 0 and len(selected) > 0): #iF g6 or other
- changeLoc(cookies, srcs[fileSrcIndex])
- new = autoraider(cookies, selected, srcs[fileSrcIndex], files[fileSrcIndex])
- ret["retries"].extend(new["retries"])
- ret["srcs"].extend(new["srcs"])
- changeLoc(cookies, srcs[0])
- else:
- new = autoraider(cookies, selected, srcs[fileSrcIndex], files[fileSrcIndex])
- ret["retries"].extend(new["retries"])
- ret["srcs"].extend(new["srcs"])
- return ret
- def raidAndBounce(cookies, files, srcs, speed, passive, bounceFirst, rates):
- if(bounceFirst):
- queryAndBounce(cookies, srcs, speed)
- bounceCycle = (5.89*60 / speed)
- firstCycle = True
- loopTime = 26
- lastNewsflash = datetime(2011,8,15,8,15,12,0)
- if quiet:
- loopTime = 60
- while True:
- now = datetime.now()
- #Maybe try multiplying the delta for loop by two, or at least for no bouncefirst?
- #Seems to be checking around 9 seconds too late in fast mode
- #Calculate a simple case later
- soon_fleet_ret = now + timedelta(seconds=bounceCycle) - timedelta(seconds=loopTime)
- retries = {}
- while soon_fleet_ret > now:
- page = getOverview(cookies, srcs[0])
- F = open("overview.html","w")
- F.write(str(page))
- F.close()
- detectAndDefeatCaptcha(cookies, page, srcs)
- if(matchesIncoming(page)):
- print("incoming detected")
- newsflashUpdate = matchesProbe(page, lastNewsflash)
- if(newsflashUpdate[0] == True):
- lastNewsflash = newsflashUpdate[1]
- print("newsflash warning sent")
- #TODO seekData every loop and report attacks
- if passive != True: # TODO & no dangerstate
- slotsOpen = detectSlots(cookies, srcs[0])
- #Autoraider returns failed raids to attempt before a bounce
- retries = autoraiderSelect(cookies, files, srcs, slotsOpen - len(srcs), rates)
- if firstCycle and not bounceFirst: #Initial bounce after deploying raids
- firstCycle = False
- queryAndBounce(cookies, srcs, speed)
- now = datetime.now()
- soon_fleet_ret = now + timedelta(seconds=bounceCycle) - timedelta(seconds=loopTime)
- #print("resolved to %s"%(timedelta(seconds=bounceCycle)), flush=True)
- time.sleep(loopTime)
- now = datetime.now()
- #expect bounce fleet back v soon so drop everything else
- fleet_ret = soon_fleet_ret + timedelta(seconds=loopTime)
- wait = fleet_ret - datetime.now() #don't sleep the full loopTime, only until the fleet returns
- print('expecting fleet back in %s sec'%(wait), flush=True)
- if(wait.total_seconds() < 0):
- wait = timedelta(seconds=0)
- time.sleep(wait.total_seconds() + 2.1)
- if (retries is not None and retries != {}):
- print("Running retry raids before bouncing")
- retryRaids(cookies, retries["retries"], retries["srcs"])
- queryAndBounce(cookies, srcs, speed)
- #main
- speed = .59
- cookies = 'uninit'
- passive = False
- bounceFirst = False
- galFixed = None
- quiet = False
- for arg in sys.argv[1:]:
- if len(arg.strip()) == len('r26d5moho0cr2bf03ikk1ksm87'):
- cookies = {
- 'PHPSESSID': arg
- }
- elif arg.strip() == '-p':
- passive = True
- elif arg.strip() == '-b':
- bounceFirst = True
- elif arg.strip() == '-6':
- galFixed = 6
- elif arg.strip() == '-8':
- galFixed = 8
- elif arg.strip() == '-q':
- quiet = True
- elif len(arg.strip()) > 2 and arg.strip()[:2] == '-d':
- delayInitial = float(arg[2:])
- print("Sleeping for " + str(delayInitial) + " minutes", flush=True)
- time.sleep(60* delayInitial)
- print("Waking up (expecting any fs to be back)", flush=True)
- else:
- speed = math.ceil(5.89 / int(arg)*100)/100
- if speed > 1:
- print('using minimum bounce duration for moon 5m 54s', flush=True)
- speed = 1
- if speed < .01:
- speed = .01
- print('using maximum bounce duration for moon 9h 43m', flush=True)
- if cookies == 'uninit':
- cookies = loginFlow(USERNAME, PASSWORD)
- #deployFleet(cookies, [8, 76, 6, 1], {'scs': 20, 'lcs': 20}, ['1', '2'. '3'], [8, 76, 8, 3])
- #autoraider(cookies, 'g8.txt', [8, 76, 8, 3], 1)
- #deployLineRaid(cookies, '8/14/10 1/0/30', [8, 76, 8, 3])
- #useEmail('attacked', 'ping')
- if galFixed == 8:
- rates = [1, 0]
- elif galFixed == 6:
- rates = [0, 1]
- else:
- #rates = [.4999999, .50000001]
- rates = [.5000000001, .49999999999] #use weird nums to prevent bad both-round-up scenarios on division
- try:
- raidAndBounce(cookies,['g8.txt', 'g6.txt'], [[8, 76, 8, 3], [6, 282, 14, 3]], speed, passive, bounceFirst, rates)
- except KeyboardInterrupt:
- print('Interrupted', flush=True)
- sys.exit(0)
- except Exception:
- useEmail("Crashed", str(sys.exc_info()[0]))
- print(str(sys.exc_info()))
- raise
Add Comment
Please, Sign In to add comment