Guest User

Untitled

a guest
Mar 24th, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.19 KB | None | 0 0
  1. #import mechanize
  2. import sys, logging
  3. import time
  4. import random
  5. import string
  6. import requests
  7. import re
  8. import math
  9. import email
  10. import smtplib
  11. import shutil
  12. from PIL import Image, ImageOps
  13. from pytesseract import image_to_string
  14. from random import randint
  15. from datetime import datetime, timedelta
  16.  
  17. USERNAME = "markd315@mailinator.com"
  18. PASSWORD = "redacted lul"
  19. DEFAULT_RAID = '33'
  20. lastNewsflash = datetime(2011,8,15,8,15,12,0)
  21.  
  22. def find_between( s, first, last ):
  23. try:
  24. start = s.index( first ) + len( first )
  25. end = s.index( last, start )
  26. return s[start:end]
  27. except ValueError:
  28. return ""
  29.  
  30. def printHTML(html):
  31. p = re.compile(r'<.*?>')
  32. data = p.sub('', html)
  33. print(data)
  34.  
  35. def meets(has, required):
  36. for ship in required:
  37. if(required[ship] == '' or int(required[ship])== 0): #None required
  38. continue
  39. if has[ship] == '' or int(has[ship]) < int(required[ship]):
  40. #print("lacks %s"%(ship))
  41. return False
  42. return True
  43.  
  44. def extractResources(html):
  45. m = find_between(html, 'var metal_value = ', ';')
  46. c = find_between(html, 'var crystal_value = ', ';')
  47. d = find_between(html, 'var deuterium_value = ', ';')
  48. return [m, c, d]
  49.  
  50. def extractShips(html):
  51. scs = find_between(html, 'alt="Small Cargo Ship', '"')
  52. lcs = find_between(html, 'alt="Large Cargo Ship', '"')
  53. bs = find_between(html, 'alt="Battleship', '"')
  54. r = find_between(html, 'alt="Recycler', '"')
  55. esp = find_between(html, 'alt="Espionage Ship', '"')
  56. bom = find_between(html, 'alt="Bomber', '"')
  57. rip = find_between(html, 'alt="Death Star', '"')
  58. bc = find_between(html, 'alt="Battlecruiser', '"')
  59. ec = find_between(html, 'alt="Elite Cargo', '"')
  60. voy = find_between(html, 'alt="Voyager', '"')
  61. return{'scs': scs,
  62. 'lcs': lcs,
  63. 'bs': bs,
  64. 'r': r,
  65. 'esp': esp,
  66. 'bom': bom,
  67. 'rip': rip,
  68. 'bc': bc,
  69. 'ec': ec,
  70. 'voy': voy}
  71.  
  72. def detectSlots(cookies, target):
  73. html = getFleetData(cookies, target)
  74. try:
  75. used = int(find_between(html, 'transparent;">Fleets ', ' /'))
  76. prefix = 'transparent;">Fleets ' + str(used) + ' / '
  77. total = int(find_between(html, prefix, '<'))
  78. print("detected usage of %.0f of %.0f slots" % (used, total), flush=True)
  79. return total-used
  80. except ValueError:
  81. print("noticed fleets value error, logging fail html and switching to Harris")
  82. useEmail("Slots recovery", str(html))
  83. f = open("err.log", "w")
  84. f.write(html)
  85. f.close()
  86. changeLoc(cookies, target)
  87. return 0
  88.  
  89. def sendemail(from_addr, to_addr_list, cc_addr_list,
  90. subject, message,
  91. login, password,
  92. smtpserver='smtp.gmail.com:587'):
  93. header = 'From: %s\n' % from_addr
  94. header += 'To: %s\n' % ','.join(to_addr_list)
  95. header += 'Cc: %s\n' % ','.join(cc_addr_list)
  96. header += 'Subject: %s\n' % subject
  97. message = header + message
  98.  
  99. server = smtplib.SMTP(smtpserver)
  100. server.starttls()
  101. server.login(login,password)
  102. problems = server.sendmail(from_addr, to_addr_list, message)
  103. server.quit()
  104.  
  105. def useEmail(subject, message):
  106. sendemail('markd315@gmail.com', ['markd315@gmail.com'], [],
  107. 'Z: '+subject, message,
  108. 'markd315', 'nOthXoh5&')
  109.  
  110. def getFleetData(cookies, target):
  111. headers = {
  112. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  113. 'Accept-Encoding': 'gzip, deflate, br',
  114. 'Accept-Language': 'en-US,en;q=0.9',
  115. 'Connection': 'keep-alive',
  116. 'Host': 'www.zorgempire.net',
  117. 'Referer': 'https://www.zorgempire.net/uni/reloaded/galaxy.php?mode=1',
  118. 'Upgrade-Insecure-Requests': '1',
  119. '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',
  120. 'cache-control': 'no-cache',
  121. }
  122.  
  123. params = (
  124. ('galaxy', str(target[0])),
  125. ('system', str(target[1])),
  126. ('planet', str(target[2])),
  127. ('planettype', str(target[3])),
  128. ('target_mission', '1'), # 1 is attack, need to learn others
  129. )
  130. return str(requests.get('https://www.zorgempire.net/uni/reloaded/fleet.php', headers=headers, params=params, cookies=cookies).content)
  131.  
  132. def getOverview(cookies, target):
  133. headers = {
  134. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  135. 'Accept-Encoding': 'gzip, deflate, br',
  136. 'Accept-Language': 'en-US,en;q=0.9',
  137. 'Connection': 'keep-alive',
  138. 'Host': 'www.zorgempire.net',
  139. 'Referer': 'https://www.zorgempire.net/uni/reloaded/galaxy.php?mode=1',
  140. 'Upgrade-Insecure-Requests': '1',
  141. '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',
  142. 'cache-control': 'no-cache',
  143. }
  144. params = (
  145. ('galaxy', str(target[0])),
  146. ('system', str(target[1])),
  147. ('planet', str(target[2])),
  148. ('planettype', str(target[3])),
  149. ('target_mission', '1'), # 1 is attack, need to learn others
  150. )
  151. return requests.get('https://www.zorgempire.net/uni/reloaded/overview.php', headers=headers, params=params, cookies=cookies).content
  152.  
  153. def flow1():
  154. headers = {
  155. 'Connection': 'keep-alive',
  156. 'Upgrade-Insecure-Requests': '1',
  157. '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',
  158. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  159. 'Accept-Encoding': 'gzip, deflate',
  160. 'Accept-Language': 'en-US,en;q=0.9',
  161. }
  162. return requests.get('http://www.zorgempire.net/', headers=headers)
  163.  
  164.  
  165. def flow2(cookies):
  166. headers = {
  167. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  168. 'Accept-Encoding': 'gzip, deflate, br',
  169. 'Accept-Language': 'en-US,en;q=0.9',
  170. 'Connection': 'keep-alive',
  171. 'Referer': 'https://www.zorgempire.net/index.php?try=fail',
  172. 'Upgrade-Insecure-Requests': '1',
  173. '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',
  174. 'cache-control': 'no-cache',
  175. }
  176. return requests.get('https://www.zorgempire.net/login_d.php', headers=headers, cookies=cookies)
  177.  
  178. def flow3(cookies):
  179. headers = {
  180. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  181. 'Accept-Encoding': 'gzip, deflate, br',
  182. 'Accept-Language': 'en-US,en;q=0.9',
  183. 'Cache-Control': 'max-age=0',
  184. 'Connection': 'keep-alive',
  185. 'Content-Type': 'application/x-www-form-urlencoded',
  186. 'Origin': 'https://www.zorgempire.net',
  187. 'Referer': 'https://www.zorgempire.net/login_d.php',
  188. 'Upgrade-Insecure-Requests': '1',
  189. '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',
  190. 'cache-control': 'no-cache',
  191. }
  192. data = {
  193. 'email': USERNAME,
  194. 'password': PASSWORD,
  195. 'submit': 'Sign+in',
  196. 'undefined': ''
  197. }
  198. return requests.post('https://www.zorgempire.net/login.php', headers=headers, cookies=cookies, data=data)
  199.  
  200. def flow4(cookies):
  201. headers = {
  202. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  203. 'Accept-Encoding': 'gzip, deflate, br',
  204. 'Accept-Language': 'en-US,en;q=0.9',
  205. 'Connection': 'keep-alive',
  206. 'Referer': 'https://www.zorgempire.net/login.php',
  207. 'Upgrade-Insecure-Requests': '1',
  208. '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',
  209. 'cache-control': 'no-cache',
  210. }
  211. return requests.get('https://www.zorgempire.net/account.php', headers=headers, cookies=cookies)
  212.  
  213. def flow5(cookies):
  214. headers = {
  215. 'Connection': 'keep-alive',
  216. 'Upgrade-Insecure-Requests': '1',
  217. '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',
  218. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  219. 'Referer': 'http://www.zorgempire.net/account.php',
  220. 'Accept-Encoding': 'gzip, deflate, br',
  221. 'Accept-Language': 'en-US,en;q=0.9',
  222. }
  223. return requests.get('https://www.zorgempire.net/uni/reloaded/', headers=headers, cookies=cookies)
  224.  
  225. def loginFlow(USERNAME, PASSWORD):
  226. cookieResponse = flow1().headers['Set-Cookie']
  227. cookie = find_between(cookieResponse, 'PHPSESSID=', ';')
  228. cookies = {
  229. 'PHPSESSID': cookie
  230. }
  231. flow2(cookies)
  232. flow3(cookies)
  233. flow4(cookies)
  234. #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
  235. flow5(cookies)
  236. return cookies
  237.  
  238. def createFleet(cookies, target, ships):
  239. headers = {
  240. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  241. 'Accept-Encoding': 'gzip, deflate, br',
  242. 'Accept-Language': 'en-US,en;q=0.9',
  243. 'Cache-Control': 'max-age=0',
  244. 'Connection': 'keep-alive',
  245. 'Content-Type': 'application/x-www-form-urlencoded',
  246. 'Origin': 'https://www.zorgempire.net',
  247. 'Referer': 'https://www.zorgempire.net/uni/reloaded/fleet.php',
  248. 'Upgrade-Insecure-Requests': '1',
  249. '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',
  250. 'cache-control': 'no-cache',
  251. }
  252. data = {
  253. 'ship202': ships['scs'],
  254. 'ship203': ships['lcs'],
  255. 'ship207': ships['bs'],
  256. 'ship211': ships['bom'],
  257. 'ship215': ships['bc'],
  258. 'ship217': ships['ec'],
  259. 'ship209': ships['r'],
  260. 'ship210': ships['esp'],
  261. 'ship214': ships['rip'],
  262. 'ship220': ships['voy'],
  263. 'consumption202': '20',
  264. 'speed202': '8000',
  265. 'capacity202': '5000',
  266. 'consumption203': '50',
  267. 'speed203': '12000',
  268. 'capacity203': '25000',
  269. 'capacity207': '1500',
  270. 'consumption207': '500',
  271. 'speed207': '31000',
  272. 'capacity209': '20000',
  273. 'consumption209': '300',
  274. 'speed209': '4600',
  275. 'capacity210': '0',
  276. 'consumption210': '0',
  277. 'speed210': '230000000',
  278. 'capacity211': '500',
  279. 'consumption211': '750',
  280. 'speed211': '11200',
  281. 'capacity214': '1000000',
  282. 'consumption214': '500',
  283. 'speed214': '310',
  284. 'capacity215': '750',
  285. 'consumption215': '250',
  286. 'speed215': '31000',
  287. 'capacity217': '10000000',
  288. 'consumption217': '2500',
  289. 'speed217': '28000',
  290. 'capacity220': '50000',
  291. 'consumption220': '100',
  292. 'speed220': '28000',
  293. 'galaxy': '0',
  294. 'system': '0',
  295. 'planet': '0',
  296. 'planet_type': '0',
  297. 'acs_attack': '',
  298. 'mission': '0',
  299. 'maxepedition': '',
  300. 'curepedition': '',
  301. 'target_mission': '0'
  302. }
  303. response = requests.post('https://www.zorgempire.net/uni/reloaded/floten1.php', headers=headers, cookies=cookies, data=data)
  304. response = str(response.content).replace('"', '')
  305. return find_between(response, "name=usedfleet value=", " />")
  306.  
  307. def giveOrders(cookies, target, usedfleet, ships, res, src, mission, speed):
  308. headers = {
  309. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  310. 'Accept-Encoding': 'gzip, deflate, br',
  311. 'Accept-Language': 'en-US,en;q=0.9',
  312. 'Cache-Control': 'max-age=0',
  313. 'Connection': 'keep-alive',
  314. 'Content-Type': 'application/x-www-form-urlencoded',
  315. 'Origin': 'https://www.zorgempire.net',
  316. 'Referer': 'https://www.zorgempire.net/uni/reloaded/floten1.php',
  317. 'Upgrade-Insecure-Requests': '1',
  318. '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',
  319. 'cache-control': 'no-cache',
  320. }
  321. data = {
  322. 'ship202' : ships['scs'],
  323. 'ship203': ships['lcs'],
  324. 'ship207': ships['bs'],
  325. 'ship211': ships['bom'],
  326. 'ship215': ships['bc'],
  327. 'ship217': ships['ec'],
  328. 'ship209': ships['r'],
  329. 'ship210': ships['esp'],
  330. 'ship214': ships['rip'],
  331. 'ship220': ships['voy'],
  332. 'consumption203': '50',
  333. 'speed203': '17250',
  334. 'consumption202': '20',
  335. 'speed202': '8000',
  336. 'capacity202': '5000',
  337. 'capacity203': '25000',
  338. 'capacity207': '1500',
  339. 'consumption207': '500',
  340. 'speed207': '31000',
  341. 'capacity211': '500',
  342. 'consumption211': '750',
  343. 'speed211': '11200',
  344. 'capacity217': '10000000',
  345. 'consumption217': '2500',
  346. 'speed217': '28000',
  347. 'capacity209': '20000',
  348. 'consumption209': '300',
  349. 'speed209': '4600',
  350. 'capacity210': '0',
  351. 'consumption210': '0',
  352. 'speed210': '230000000',
  353. 'capacity214': '1000000',
  354. 'consumption214': '500',
  355. 'speed214': '310',
  356. 'capacity215': '750',
  357. 'consumption215': '250',
  358. 'speed215': '31000',
  359. 'capacity220': '50000',
  360. 'consumption220': '100',
  361. 'speed220': '28000',
  362. 'speedallsmin': '8000',
  363. 'usedfleet': usedfleet,
  364. 'galaxyend': '0',
  365. 'systemend': '0',
  366. 'planetend': '0',
  367. 'speedfactor': '8',
  368. 'thisresource1': '612841',
  369. 'thisresource2': '583866',
  370. 'thisresource3': '229656',
  371. 'thisgalaxy': str(src[0]),
  372. 'thissystem': str(src[1]),
  373. 'thisplanet': str(src[2]),
  374. 'thisplanettype': str(src[3]),
  375. 'galaxy': str(target[0]),
  376. 'system': str(target[1]),
  377. 'planet': str(target[2]),
  378. 'planettype': str(target[3]),
  379. 'speed': str(speed*10),
  380. 'maxepedition': '1',
  381. 'curepedition': '0',
  382. 'acs_attack': '',
  383. 'target_mission': '1',
  384. 'undefined': ''
  385. }
  386. min = 100000
  387. for key in data:
  388. if str(key)[0:4] == "ship":
  389. if (data[key] != '') and (int(data[key]) > 0): # Only change min if we are sending some of these
  390. if min > int(data["speed"+str(key)[4:7]]): #Only change min if actually min
  391. min = int(data["speed"+str(key)[4:7]])
  392. data['speedsallmin'] = str(min)
  393. response = requests.post('https://www.zorgempire.net/uni/reloaded/floten2.php', headers=headers, cookies=cookies, data=data)
  394. headers = {
  395. 'Connection': 'keep-alive',
  396. 'Cache-Control': 'max-age=0',
  397. 'Origin': 'https://www.zorgempire.net',
  398. 'Upgrade-Insecure-Requests': '1',
  399. 'Content-Type': 'application/x-www-form-urlencoded',
  400. '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',
  401. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  402. 'Referer': 'https://www.zorgempire.net/uni/reloaded/floten2.php',
  403. 'Accept-Encoding': 'gzip, deflate, br',
  404. 'Accept-Language': 'en-US,en;q=0.9',
  405. }
  406.  
  407. data = [
  408. #speedsallmin is a critical variable
  409. ('speedallsmin', '17250'),
  410. ('thisresource1', '612841'),
  411. ('thisresource2', '583866'),
  412. ('thisresource3', '229675'),
  413. ('consumption', '116'),
  414. ('dist', '1005'),
  415. ('speedfactor', '8'),
  416. ('speedfactor', '8'),
  417. ('thisgalaxy', str(src[0])),
  418. ('thissystem', str(src[1])),
  419. ('thisplanet', str(src[2])),
  420. ('galaxy', str(target[0])),
  421. ('system', str(target[1])),
  422. ('planet', str(target[2])),
  423. ('thisplanettype', str(src[3])),
  424. ('planettype', str(target[3])),
  425. ('speed', str(speed*10)),
  426. ('usedfleet', usedfleet),
  427. ('ship203', ships['lcs']),
  428. ('ship202', ships['scs']),
  429. ('ship202', ships['bs']),
  430. ('ship211', ships['bom']),
  431. ('ship215', ships['bc']),
  432. ('ship217', ships['ec']),
  433. ('ship209', ships['r']),
  434. ('ship210', ships['esp']),
  435. ('ship214', ships['rip']),
  436. ('ship220', ships['voy']),
  437. ('maxepedition', ''),
  438. ('curepedition', ''),
  439. ('acs_attack', ''),
  440. ('capacity203', '25000'),
  441. ('consumption203', '50'),
  442. ('speed203', '12000'),
  443. ('consumption202', '20'),
  444. ('speed202', '8000'),
  445. ('capacity202', '5000'),
  446. ('ship207', '1'),
  447. ('capacity207', '1500'),
  448. ('consumption207', '500'),
  449. ('speed207', '31000'),
  450. ('capacity211', '500'),
  451. ('consumption211', '750'),
  452. ('speed211', '11200'),
  453. ('capacity217', '10000000'),
  454. ('consumption217', '2500'),
  455. ('speed217', '28000'),
  456. ('capacity209', '20000'),
  457. ('consumption209', '300'),
  458. ('speed209', '4600'),
  459. ('capacity210', '0'),
  460. ('consumption210', '0'),
  461. ('speed210', '230000000'),
  462. ('capacity214', '1000000'),
  463. ('consumption214', '500'),
  464. ('speed214', '310'),
  465. ('capacity215', '750'),
  466. ('consumption215', '250'),
  467. ('speed215', '31000'),
  468. ('capacity220', '50000'),
  469. ('consumption220', '100'),
  470. ('speed220', '28000'),
  471. ('mission', str(mission)),
  472. ('resource1', res[0]),
  473. ('resource2', res[1]),
  474. ('resource3', res[2]),
  475. ('holdingtime', '0'),
  476. ]
  477. data[0] = ('speedallsmin', str(min))
  478. response = requests.post('https://www.zorgempire.net/uni/reloaded/floten3.php', headers=headers, cookies=cookies, data=data)
  479. return response.content
  480.  
  481. def changeLoc(cookies, src):
  482. headers = {
  483. 'Connection': 'keep-alive',
  484. 'Upgrade-Insecure-Requests': '1',
  485. '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',
  486. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  487. }
  488. if src[0] == 8:
  489. response = requests.get('https://www.zorgempire.net/uni/reloaded/overview.php?cp=9278&mode=&re=0', headers=headers, cookies=cookies)
  490. elif src[0] == 6:
  491. response = requests.get('https://www.zorgempire.net/uni/reloaded/overview.php?cp=21003&mode=&re=0', headers=headers, cookies=cookies)
  492. return response
  493.  
  494. def deployFleet(cookies, target, ships, res, src, mission, speed):
  495. if(mission == 'atk'):
  496. misscode = 1
  497. if(mission == 'acs'):
  498. misscode = 5
  499. usedfleet = createFleet(cookies, target, ships)
  500. ordersResponse = giveOrders(cookies, target, usedfleet, ships, res, src, misscode, speed)
  501.  
  502. def deploySafeLineRaid(cookies, line, src):
  503. line = line.strip()
  504. split = line.split(' ')
  505. target = split[0].split('/')
  506. ships = {
  507. 'ec': '0', 'scs': '0', 'lcs': '0', 'bom': '0', 'bs': '0', 'bc': '0', 'r': '0', 'rip': '0', 'esp': '0', 'voy': '0'
  508. }
  509. if len(split) > 1:
  510. if (split[1] == 'occ' or (len(split) > 2 and split[2] == 'occ')) and randint(0,9) != 1:
  511. #print("Skipping occasional target, will replace", flush=True)
  512. return "occ"
  513. if split[1] == 'e':
  514. ships['ec'] = '1'
  515. else:
  516. if split[1] != 'occ':
  517. shipList = split[1].split('/')
  518. ships['ec'] = shipList[0]
  519. ships['lcs'] = shipList[1]
  520. ships['bom'] = shipList[2]
  521. else:
  522. ships['lcs'] = DEFAULT_RAID
  523. else:
  524. ships['lcs'] = DEFAULT_RAID #42 if expect 550k max
  525. currentShips = extractShips(getFleetData(cookies, [6, 282, 14, 3]))
  526. if meets(currentShips, ships):
  527. print("deploying line %s"%(line), flush=True)
  528. deployFleet(cookies, [target[0], target[1], target[2], 1], ships, [0, 0, 0], src, 'atk', 1)
  529. return True
  530. else:
  531. print("line %s failed"%(line), flush=True)
  532. return False
  533.  
  534. def bounceFleet(cookies, src, ships, res, speed): #bounce set to 10 minutes flat for one shove
  535. res[2] = str(int(res[2]) - 50000) #save some room for gas
  536. deployFleet(cookies, [src[0], src[1], src[2], 1], ships, res, src, 'acs', speed)
  537.  
  538. def autoraider(cookies, lines, src, backupFile):
  539. retries = []
  540. srcs = []
  541. occFail = 0
  542. if lines is None or lines == []: #If nothing, deploy nothing
  543. return {"retries" : [], "srcs": []}
  544. for line in lines:
  545. raidSuccess = deploySafeLineRaid(cookies, line, src)
  546. while raidSuccess == 'occ':
  547. lines = open(backupFile, "r").readlines()
  548. selected = random.sample(lines, 1)
  549. raidSuccess = deploySafeLineRaid(cookies, selected[0], src)
  550. if raidSuccess != 'occ' and not raidSuccess:
  551. retries.append(line)
  552. srcs.append(src)
  553. time.sleep(2.35)
  554. ret = {"retries" : retries, "srcs": srcs}
  555. return ret
  556.  
  557. def retryRaids(cookies, retries, srcs):
  558. if retries is None or retries == [] or len(retries) != len(srcs): #If nothing, deploy nothing
  559. return
  560. for idx, line in enumerate(retries):
  561. raidSuccess = deploySafeLineRaid(cookies, line, srcs[idx])
  562.  
  563. def matchesIncoming(html):
  564. regex = r"<span class=\".*?\">(A|One of your).*?<a href=.*?fleet.*?(Attack|Espionage)<"
  565. matches = re.findall(regex, str(html))
  566. if len(matches) != 0:
  567. for match in matches:
  568. if match[0] == "A":
  569. # We are sending a warning
  570. print("alerting to email")
  571. useEmail('Incoming', str(match))
  572. return True
  573. return False
  574.  
  575. def detectAndDefeatCaptcha(cookies, html, srcs):
  576.  
  577. regex = r"Bot Protection"
  578. if re.search(regex, str(html)):
  579. useEmail('Botprot', "Check and make sure im ok :(")
  580. headers = {
  581. 'Connection': 'keep-alive',
  582. 'Cache-Control': 'max-age=0',
  583. 'Origin': 'https://www.zorgempire.net',
  584. 'Upgrade-Insecure-Requests': '1',
  585. 'Content-Type': 'application/x-www-form-urlencoded',
  586. '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',
  587. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  588. 'Referer': 'https://www.zorgempire.net/uni/reloaded/overview.php',
  589. 'Accept-Encoding': 'gzip, deflate, br',
  590. 'Accept-Language': 'en-US,en;q=0.9'
  591. }
  592. response = requests.get('https://www.zorgempire.net/uni/reloaded/assign.php', headers=headers, cookies=cookies, stream=True)
  593. with open("assign.php", 'wb') as f:
  594. response.raw.decode_content = True
  595. shutil.copyfileobj(response.raw, f)
  596. time.sleep(2.6)
  597. #Read Image
  598. col = Image.open("assign.php")
  599. gray = col.convert('L')
  600. bw = gray.point(lambda x: 0 if x<128 else 255, '1')
  601. bw = bw.convert('L')
  602. inverted_image = ImageOps.invert(bw)
  603. inverted_image = ImageOps.crop(inverted_image, border=5)
  604. inverted_image.save("result_bw.png")
  605. defeated = image_to_string(inverted_image, config="-c tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz --psm 7 --oem 1")
  606. print("detected captcha " + defeated)
  607. data = {
  608. 'abpass': defeated,
  609. 'sprotect': 'Continue'
  610. }
  611.  
  612. response = requests.post('https://www.zorgempire.net/uni/reloaded/overview.php', headers=headers, cookies=cookies, data=data).content
  613. with open("caplog.log", 'w') as f:
  614. f.write(str(response))
  615. page = getOverview(cookies, srcs[0])
  616. return detectAndDefeatCaptcha(cookies, page, srcs)
  617. return False
  618.  
  619. def matchesProbe(html, lastNewsflash):
  620. #if() #not warned in a while
  621. regex = r"href=\"show_message.php\?id=\d*\" class=\"scifi\">(.*?)<\/a>\\r\\n.*?(\d\d .*? \d\d .*?)"
  622. matches = re.findall(regex, str(html))
  623. if len(matches) != 0:
  624. print(matches) # format (mission, 00 Hours 00 Mins 00 Secs)
  625. for match in matches:
  626. ignore = ["ACS DEFEND FLEET", "ESPIONAGE REPORT", "PARKING FLEET", "FLEET RETURN", "BACK FROM ACS DEFEND", "COMBAT REPORT", "TRANSPORT REPORT"]
  627. if match[0] in ignore:
  628. continue
  629. if "Hours" in match[1]: # outdated
  630. continue
  631. if int(match[1][:2]) > 5: # 3 mins outdated
  632. now = datetime.now()
  633. if (now - lastNewsflash) > timedelta(minutes=5):
  634. useEmail('Newsflash', str(match))
  635. lastNewsflash = datetime.now()
  636. return (True, lastNewsflash)
  637. return (False, lastNewsflash)
  638. #TODO reset warning timer
  639.  
  640. def queryAndBounce(cookies, srcs, speed):
  641. for idx, src in enumerate(srcs):
  642. if src != srcs[0]: # if not in g8, switch first
  643. changeLoc(cookies, srcs[idx])
  644. print('bouncing nonraiding fleet', flush=True)
  645. try:
  646. fleetData = getFleetData(cookies, src)
  647. res = extractResources(fleetData)
  648. ships = extractShips(fleetData)
  649. bounceFleet(cookies, src, ships, res, speed)
  650. except ValueError:
  651. changeLoc(cookies, srcs[idx])
  652. fleetData = getFleetData(cookies, src)
  653. res = extractResources(fleetData)
  654. ships = extractShips(fleetData)
  655. bounceFleet(cookies, src, ships, res, speed)
  656. if src != srcs[0]: # if not in g8, switch after
  657. changeLoc(cookies, srcs[0])
  658.  
  659. def autoraiderSelect(cookies, files, srcs, count, rates):
  660. if(count < 1):
  661. return
  662. #print('initiating raid behavior', flush=True)
  663. #Pick a file/src combo from the ones given
  664. ret = {"retries": [], "srcs": []}
  665. for fileSrcIndex, src in enumerate(srcs):
  666. toDeploy = round(count*rates[fileSrcIndex])
  667. print("deploying " + str(toDeploy) + " raids for g" + str(src[0]))
  668. f = open(files[fileSrcIndex], "r")
  669. lines = f.readlines()
  670. f.close()
  671. selected = lines[:toDeploy]
  672. f = open(files[fileSrcIndex], "w")
  673. for line in lines: #Rewrite the file without the selected raids
  674. if line not in selected:
  675. if line[-1] != '\n':
  676. line += '\n'
  677. f.write(line)
  678. for line in lines: #Write them back at the end of the file
  679. if line in selected:
  680. if line[-1] != '\n':
  681. line += '\n'
  682. f.write(line)
  683. f.close()
  684. if(fileSrcIndex != 0 and len(selected) > 0): #iF g6 or other
  685. changeLoc(cookies, srcs[fileSrcIndex])
  686. new = autoraider(cookies, selected, srcs[fileSrcIndex], files[fileSrcIndex])
  687. ret["retries"].extend(new["retries"])
  688. ret["srcs"].extend(new["srcs"])
  689. changeLoc(cookies, srcs[0])
  690. else:
  691. new = autoraider(cookies, selected, srcs[fileSrcIndex], files[fileSrcIndex])
  692. ret["retries"].extend(new["retries"])
  693. ret["srcs"].extend(new["srcs"])
  694. return ret
  695.  
  696. def raidAndBounce(cookies, files, srcs, speed, passive, bounceFirst, rates):
  697. if(bounceFirst):
  698. queryAndBounce(cookies, srcs, speed)
  699. bounceCycle = (5.89*60 / speed)
  700. firstCycle = True
  701. loopTime = 26
  702. lastNewsflash = datetime(2011,8,15,8,15,12,0)
  703. if quiet:
  704. loopTime = 60
  705. while True:
  706. now = datetime.now()
  707. #Maybe try multiplying the delta for loop by two, or at least for no bouncefirst?
  708. #Seems to be checking around 9 seconds too late in fast mode
  709. #Calculate a simple case later
  710. soon_fleet_ret = now + timedelta(seconds=bounceCycle) - timedelta(seconds=loopTime)
  711. retries = {}
  712. while soon_fleet_ret > now:
  713. page = getOverview(cookies, srcs[0])
  714. F = open("overview.html","w")
  715. F.write(str(page))
  716. F.close()
  717. detectAndDefeatCaptcha(cookies, page, srcs)
  718. if(matchesIncoming(page)):
  719. print("incoming detected")
  720. newsflashUpdate = matchesProbe(page, lastNewsflash)
  721. if(newsflashUpdate[0] == True):
  722. lastNewsflash = newsflashUpdate[1]
  723. print("newsflash warning sent")
  724. #TODO seekData every loop and report attacks
  725. if passive != True: # TODO & no dangerstate
  726. slotsOpen = detectSlots(cookies, srcs[0])
  727. #Autoraider returns failed raids to attempt before a bounce
  728. retries = autoraiderSelect(cookies, files, srcs, slotsOpen - len(srcs), rates)
  729. if firstCycle and not bounceFirst: #Initial bounce after deploying raids
  730. firstCycle = False
  731. queryAndBounce(cookies, srcs, speed)
  732. now = datetime.now()
  733. soon_fleet_ret = now + timedelta(seconds=bounceCycle) - timedelta(seconds=loopTime)
  734. #print("resolved to %s"%(timedelta(seconds=bounceCycle)), flush=True)
  735. time.sleep(loopTime)
  736. now = datetime.now()
  737. #expect bounce fleet back v soon so drop everything else
  738. fleet_ret = soon_fleet_ret + timedelta(seconds=loopTime)
  739. wait = fleet_ret - datetime.now() #don't sleep the full loopTime, only until the fleet returns
  740. print('expecting fleet back in %s sec'%(wait), flush=True)
  741. if(wait.total_seconds() < 0):
  742. wait = timedelta(seconds=0)
  743. time.sleep(wait.total_seconds() + 2.1)
  744. if (retries is not None and retries != {}):
  745. print("Running retry raids before bouncing")
  746. retryRaids(cookies, retries["retries"], retries["srcs"])
  747. queryAndBounce(cookies, srcs, speed)
  748.  
  749. #main
  750. speed = .59
  751. cookies = 'uninit'
  752. passive = False
  753. bounceFirst = False
  754. galFixed = None
  755. quiet = False
  756. for arg in sys.argv[1:]:
  757. if len(arg.strip()) == len('r26d5moho0cr2bf03ikk1ksm87'):
  758. cookies = {
  759. 'PHPSESSID': arg
  760. }
  761. elif arg.strip() == '-p':
  762. passive = True
  763. elif arg.strip() == '-b':
  764. bounceFirst = True
  765. elif arg.strip() == '-6':
  766. galFixed = 6
  767. elif arg.strip() == '-8':
  768. galFixed = 8
  769. elif arg.strip() == '-q':
  770. quiet = True
  771. elif len(arg.strip()) > 2 and arg.strip()[:2] == '-d':
  772. delayInitial = float(arg[2:])
  773. print("Sleeping for " + str(delayInitial) + " minutes", flush=True)
  774. time.sleep(60* delayInitial)
  775. print("Waking up (expecting any fs to be back)", flush=True)
  776. else:
  777. speed = math.ceil(5.89 / int(arg)*100)/100
  778. if speed > 1:
  779. print('using minimum bounce duration for moon 5m 54s', flush=True)
  780. speed = 1
  781. if speed < .01:
  782. speed = .01
  783. print('using maximum bounce duration for moon 9h 43m', flush=True)
  784.  
  785. if cookies == 'uninit':
  786. cookies = loginFlow(USERNAME, PASSWORD)
  787. #deployFleet(cookies, [8, 76, 6, 1], {'scs': 20, 'lcs': 20}, ['1', '2'. '3'], [8, 76, 8, 3])
  788. #autoraider(cookies, 'g8.txt', [8, 76, 8, 3], 1)
  789. #deployLineRaid(cookies, '8/14/10 1/0/30', [8, 76, 8, 3])
  790. #useEmail('attacked', 'ping')
  791. if galFixed == 8:
  792. rates = [1, 0]
  793. elif galFixed == 6:
  794. rates = [0, 1]
  795. else:
  796. #rates = [.4999999, .50000001]
  797. rates = [.5000000001, .49999999999] #use weird nums to prevent bad both-round-up scenarios on division
  798.  
  799. try:
  800. raidAndBounce(cookies,['g8.txt', 'g6.txt'], [[8, 76, 8, 3], [6, 282, 14, 3]], speed, passive, bounceFirst, rates)
  801. except KeyboardInterrupt:
  802. print('Interrupted', flush=True)
  803. sys.exit(0)
  804. except Exception:
  805. useEmail("Crashed", str(sys.exc_info()[0]))
  806. print(str(sys.exc_info()))
  807. raise
Add Comment
Please, Sign In to add comment