Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.23 KB | None | 0 0
  1. import threading
  2. import time
  3. import urllib2
  4. import cookielib
  5. import os
  6. import sys
  7. import socket
  8. import datetime
  9. import re
  10. socket.setdefaulttimeout(15.0)
  11.  
  12. cj = cookielib.CookieJar()
  13. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  14. opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1 ID:20120614114901')]
  15.  
  16.  
  17.  
  18. FORMER_ID = "682970"
  19. chars = ([
  20. "64960" #raider101
  21. ,"682665" #raidit01
  22. ,"682666" #raidit02
  23. ,"682792" #raidit03
  24. ,"682970" #raidit04
  25. ])
  26.  
  27. LOGIN_WITH_SESSION = False # Change to True to log in with session
  28. # or False to use the stored user/pass
  29.  
  30. ## There are 2 ways to login, session or user/pass
  31. ## to log in with session you dont need to put the
  32. ## username or password in below, but set the LOGIN_WITH_SESSION
  33. ## above to True, quite simple you will get the hang of it, if not
  34. ## I don't really care :)
  35. ## Happy hunting!
  36. # ___ _ _ _
  37. # | _ |_) | |_ _
  38. # | _ \ | | | || |
  39. # |___/_|_|_|\_, |.
  40. # |__/
  41. rg_sess_id = ""
  42. server = "torax"
  43. username = "raider101"
  44. password = "password1"
  45.  
  46.  
  47.  
  48. #####################
  49. ##### Dont Edit #####
  50. #####################
  51.  
  52. if server.lower() == "sigil":
  53. SERVER_ID = "1"
  54. elif server.lower() == "torax":
  55. SERVER_ID = "2"
  56. elif server.lower() == "fabar":
  57. SERVER_ID = "3"
  58. elif server.lower() == "zimbob":
  59. SERVER_ID = "4"
  60. elif server.lower() == "rancid":
  61. SERVER_ID = "5"
  62. elif server.lower() == "quiver":
  63. SERVER_ID = "6"
  64. else:
  65. SERVER_ID = "2"
  66.  
  67. RAID_ID = ""
  68. RAID_NAME = ""
  69. _startTime = datetime.datetime.now()
  70. _finishTime = datetime.datetime.now()
  71. bossToRaidId = ""
  72. bossToRaidName = ""
  73. totalRaidDamage = 0
  74. damageLastRaid = 0
  75.  
  76. #anti-lag-opener
  77. def alo(url):
  78. lagsafe = 1
  79. while lagsafe == 1:
  80. try:
  81. site = opener.open(url)
  82. lagsafe = 0
  83. except IOError:
  84. print "URLError: Site not loading. Retrying..."
  85. return site
  86.  
  87. def alo2(url, postData):
  88. lagsafe = 1
  89. while lagsafe == 1:
  90. try:
  91. site = opener.open(url, postData)
  92. lagsafe = 0
  93. except IOError:
  94. print "URLError: Site not loading. Retrying..."
  95. return site
  96.  
  97.  
  98. def msg(out):
  99. thetime = time.strftime("[%H:%M:%S]", time.localtime(time.time()))
  100. message = thetime + " " + out
  101. print message
  102. return message
  103.  
  104.  
  105. def getCharName(src):
  106. #<option value="2236250" selected>Eag1e</option>
  107. charName = "Unknown"
  108. try:
  109. charName = src.split('" selected>')[1].split('</option>')[0]
  110. except:
  111. print "Could not retrieve character name."
  112.  
  113. return charName
  114.  
  115. def iB(src, start, end):
  116. try:
  117. return src.split(start)[1].split(end)[0]
  118. except IndexError:
  119. print "Could not retrieve the inbetween value."
  120. return
  121.  
  122. def getRaidName(src):
  123. try:
  124. return iB(src, "<div ONMOUSEOVER=\"statspopup(event,'<b>", "</b>')\" ONMOUSEOUT=\"kill()\">")
  125. except IndexError:
  126. print "Couldn't retrieve raid name"
  127. return False
  128.  
  129. def bossSelector():
  130. bossPage = alo("http://"+server+".outwar.com/crew_bossspawns.php").read()
  131.  
  132. bossID = []
  133. bossName = []
  134.  
  135. try:
  136. exp = re.compile('target=[0-9]+" ONMOUSEOVER="popup\(event,\'<b>(.+)</b>')
  137. y = re.findall(exp, bossPage)
  138. bossName.extend(y)
  139. print "Found "+ str(len(y)) +" bosses\n"
  140. except:
  141. print "Unable to retrieve boss names or no bosses are spawned."
  142.  
  143. try:
  144. exp = re.compile('<a href="formraid.php\?target=([0-9]+)">')
  145. z = re.findall(exp, bossPage)
  146. bossID.extend(z)
  147. #print "found "+ str(len(z)) +" boss ids"
  148. except:
  149. print "Unable to retrieve boss ID's or no bosses are spawned."
  150.  
  151. if len(bossName) > 0 and len(bossID) > 0:
  152. # bosses found, print them
  153. print "Select a boss to raid:"
  154. d = 1
  155. for name in bossName:
  156. print str(d) + " - " + name
  157. d = d + 1
  158.  
  159. global bossToRaidName, bossToRaidId
  160.  
  161. x = 1
  162. while x == 1:
  163. print ""
  164. cho = raw_input("Number: ")
  165. if int(cho) < len(bossName)+1:
  166. print "You have chosen to raid, " + bossName[int(cho)-1]
  167. #print "ID: " + bossID[int(cho)-1]
  168. bossToRaidName = bossName[int(cho)-1]
  169. bossToRaidId = bossID[int(cho)-1]
  170. x = 0
  171. else:
  172. print "Invalid selection, please enter a valid number."
  173. else:
  174. print "No bosses found..."
  175. chk = raw_input("Try again? Y/N")
  176. if chk.lower() == "y":
  177. bossSelector()
  178. else:
  179. return False
  180.  
  181. return True
  182.  
  183.  
  184.  
  185. def formRaid():
  186. #print formerID
  187. one = 1
  188. while one == 1:
  189. try:
  190. global _startTime, bossToRaidName, bossToRaidId
  191. _startTime = datetime.datetime.now()
  192.  
  193. ##It's this formpage. It's not sending the correct data to form the raid, or it doesnt have the data to send
  194. ## I can try to look at it later, but I have to head out soon
  195. formpage = alo("http://"+server+".outwar.com/formraid.php?target=" + bossToRaidId +"&suid="+ FORMER_ID).read()
  196. codeID = formpage.split('codeid" value="')[1].split('">')[0]
  197.  
  198. Form = alo2("http://"+server+".outwar.com/formraid.php?target=" + bossToRaidId, "target=" + bossToRaidId + "&codeid=" + codeID + "&formtime=3&submit=Launch!").read()
  199.  
  200. global RAID_ID, RAID_NAME
  201. RAID_ID = getRaidID(Form)
  202. RAID_NAME = getRaidName(Form)
  203.  
  204. print ""
  205. print "***" + RAID_NAME + " Formed."
  206. one = 0
  207. return True
  208.  
  209. except IndexError:
  210. with open("formingTest.txt", "w") as fileID:
  211. fileID.write(formpage)
  212. fileID.close()
  213. print "Forming Error, retrying...."
  214. time.sleep(1)
  215.  
  216. def intC(x):
  217. if type(x) not in [type(0), type(0L)]:
  218. raise TypeError("Parameter must be an integer.")
  219. if x < 0:
  220. return '-' + intWithCommas(-x)
  221. result = ''
  222. #I dont understand this function... I'll indent it as best I cankie
  223. while x >= 1000:
  224. x, r = divmod(x, 1000)
  225. #If you start programming, dont use variables like "x"
  226. #Freaking name your variables for what they are
  227. #In this function, i have no idea what "x" is supposed to be (other than it's mathematical meaning due to divmod)
  228. # But in relation to how it helps the raider, I have no idea because the writer decided to take short cuts
  229. # instead of writing clear code got it
  230.  
  231. result = ",%03d%s" % (r, result)
  232.  
  233. ####Come back to this Return, may need to be indented
  234. return "%d%s" % (x, result)
  235.  
  236.  
  237. def getRaidID(src):
  238. #raids = alo("http://"+server+".outwar.com/crew_raidsforming.php")
  239. #srcraids = raids.read()
  240. try:
  241. return iB(src, "joinraid.php?raidid=", "&")
  242. except IndexError:
  243. print "Couldn't retrieve raid ID"
  244. return False
  245.  
  246. def launchRaid(launchURL):
  247. x = 1
  248. while x == 1:
  249. try:
  250. launch = alo(launchURL).read()
  251. if "Your raid will launch shortly" in launch:
  252. print "RAID LAUNCHED!"
  253. global _finishTime
  254. _finishTime = datetime.datetime.now()
  255. x = 0
  256. return True
  257. except IndexError:
  258. x = 1
  259. time.sleep(1)
  260.  
  261. def launchWait():
  262. checking = 1
  263. while checking == 1:
  264. check = alo('http://'+server+'.outwar.com/joinraid.php?raidid=' + RAID_ID).read()
  265.  
  266. if "Attacks!" in check:
  267. # Raid has launched, gather data
  268. # attacks for <font color="#FF9900"> 3,651</b><
  269. # CRITICAL!</font><font color="#FF9900"> 6,491</b>
  270. attackDamage = 0
  271. try:
  272. exp = re.compile('<font color="#FF9900"> (.+)</b><')
  273. attacks = re.findall(exp, check)
  274. for i in attacks:
  275. z = int(i.replace(',', ''))
  276. attackDamage = attackDamage + z
  277. except:
  278. pass
  279.  
  280. global damageLastRaid, totalRaidDamage
  281. damageLastRaid = attackDamage
  282. totalRaidDamage = totalRaidDamage + attackDamage
  283. checking = 0
  284. else:
  285. time.sleep(1)
  286.  
  287. ####This appears to be the beginning of the MAIN function
  288.  
  289. if LOGIN_WITH_SESSION:
  290. loginrpg = alo("http://"+server+".outwar.com/myaccount.php?rg_sess_id=" + rg_sess_id + "&serverid="+SERVER_ID+"&suid=" + FORMER_ID)
  291. print "Logged in RGA with session ID\n"
  292. else:
  293. loginrpg = alo2("http://"+server+".outwar.com/myaccount.php", "login_username="+username+"&login_password="+password)
  294. loginchar = alo("http://"+server+".outwar.com/world.php?suid="+FORMER_ID+"&serverid="+SERVER_ID)
  295. print "Logged in RGA\n"
  296.  
  297. ####bossSelector()
  298.  
  299. if bossSelector():
  300.  
  301. x = 1
  302. while x == 1:
  303. formRaid()
  304. chars_to_remove = []
  305. for i in chars:
  306. join = alo2('http://'+server+'.outwar.com/joinraid.php?raidid=' + RAID_ID + '&suid=' + i + '&serverid='+SERVER_ID, "join=1").read()
  307. time.sleep(0.1)
  308. if "rage to join this raid" in join:
  309. print i + " out of rage..."
  310. chars_to_remove.append(i)
  311. elif "must be a member of this crew" in join:
  312. print i + " not in crew..."
  313. chars_to_remove.append(i)
  314. else:
  315. print "Joined " + getCharName(join)
  316.  
  317. if len(chars_to_remove) > 0 :
  318. for character in chars_to_remove:
  319. if character in chars:
  320. chars.remove(character)
  321.  
  322.  
  323. launchURL = 'http://'+server+'.outwar.com/joinraid.php?raidid=' + RAID_ID + '&suid=' + FORMER_ID + '&serverid='+SERVER_ID+'&launchraid=yes&x=141&y=36'
  324. launchRaid(launchURL)
  325. tTime = _finishTime - _startTime
  326. print "Raid time: " + str(tTime.seconds) + " seconds.\n"
  327. # Wait for launch before reforming...
  328. launchWait()
  329. print "Raid Damage: " + intC(damageLastRaid)
  330. print "Damage Total: " + intC(totalRaidDamage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement