Advertisement
Guest User

Outwar py updated

a guest
Mar 20th, 2013
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.73 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(100.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. FORMER_ID = ""
  18. chars = (["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""])
  19.  
  20. LOGIN_WITH_SESSION = False# Change to True to log in with session
  21. # or False to use the stored user/pass
  22.  
  23. rg_sess_id = ""
  24. server = ""
  25. username = ""
  26. password = ""
  27.  
  28.  
  29.  
  30. #####################
  31. ##### Dont Edit #####
  32. #####################
  33.  
  34. if server.lower() == "sigil":
  35. SERVER_ID = "1"
  36. elif server.lower() == "torax":
  37. SERVER_ID = "2"
  38. elif server.lower() == "fabar":
  39. SERVER_ID = "3"
  40. elif server.lower() == "zimbob":
  41. SERVER_ID = "4"
  42. elif server.lower() == "rancid":
  43. SERVER_ID = "5"
  44. elif server.lower() == "quiver":
  45. SERVER_ID = "6"
  46. else:
  47. SERVER_ID = "1"
  48.  
  49. RAID_ID = ""
  50. RAID_NAME = ""
  51. _startTime = datetime.datetime.now()
  52. _finishTime = datetime.datetime.now()
  53. bossToRaidId = ""
  54. bossToRaidName = ""
  55. totalRaidDamage = 0
  56. damageLastRaid = 0
  57.  
  58. #anti-lag-opener
  59. def alo(url):
  60. lagsafe = 1
  61. while lagsafe == 1:
  62. try:
  63. site = opener.open(url)
  64. lagsafe = 0
  65. except IOError:
  66. print "URLError: Site not loading. Retrying..."
  67. except Exception:
  68. print "Unknown error, retrying..."
  69. return site
  70.  
  71. def alo2(url, pData):
  72. lagsafe = 1
  73. while lagsafe == 1:
  74. try:
  75. site = opener.open(url, pData)
  76. lagsafe = 0
  77. except IOError:
  78. print "URLError: Site not loading. Retrying..."
  79. except Exception:
  80. print "Unknown error, retrying..."
  81. return site
  82.  
  83.  
  84. def msg(out):
  85. thetime = time.strftime("[%H:%M:%S]", time.localtime(time.time()))
  86. message = thetime + " " + out
  87. print message
  88. return message
  89.  
  90.  
  91. def getCharName(src):
  92. #<option value="2236250" selected>Eag1e</option>
  93. charName = "Unknown"
  94. try:
  95. charName = src.split('" selected>')[1].split('</option>')[0]
  96. except:
  97. print "Could not retrieve character name."
  98.  
  99. return charName
  100.  
  101. def iB(src, start, end):
  102. try:
  103. return src.split(start)[1].split(end)[0]
  104. except IndexError:
  105. print "Could not retrieve the inbetween value."
  106. return
  107.  
  108. def getRaidName(src):
  109. try:
  110. return iB(src, "<div ONMOUSEOVER=\"statspopup(event,'<b>", "</b>')\" ONMOUSEOUT=\"kill()\">")
  111. except IndexError:
  112. print "Couldn't retrieve raid name"
  113. return False
  114.  
  115. def bossSelector():
  116. bossPage = alo("http://"+server+".outwar.com/crew_bossspawns.php").read()
  117.  
  118. bossID = []
  119. bossName = []
  120.  
  121. try:
  122. exp = re.compile('target=[0-9]+" ONMOUSEOVER="popup\(event,\'<b>(.+)</b>')
  123. y = re.findall(exp, bossPage)
  124. bossName.extend(y)
  125. print "Found "+ str(len(y)) +" bosses\n"
  126. except:
  127. print "Unable to retrieve boss names or no bosses are spawned."
  128.  
  129. try:
  130. exp = re.compile('<a href="formraid.php\?target=([0-9]+)">')
  131. z = re.findall(exp, bossPage)
  132. bossID.extend(z)
  133. #print "found "+ str(len(z)) +" boss ids"
  134. except:
  135. print "Unable to retrieve boss ID's or no bosses are spawned."
  136.  
  137. if len(bossName) > 0 and len(bossID) > 0:
  138. # bosses found, print them
  139. print "Select a boss to raid:"
  140. d = 1
  141. for name in bossName:
  142. print str(d) + " - " + name
  143. d = d + 1
  144.  
  145. global bossToRaidName, bossToRaidId
  146.  
  147. x = 1
  148. while x == 1:
  149. print ""
  150. cho = raw_input("Number: ")
  151. if int(cho) < len(bossName)+1:
  152. print "You have chosen to raid, " + bossName[int(cho)-1]
  153. #print "ID: " + bossID[int(cho)-1]
  154. bossToRaidName = bossName[int(cho)-1]
  155. bossToRaidId = bossID[int(cho)-1]
  156. x = 0
  157. else:
  158. print "Invalid selection, please enter a valid number."
  159. else:
  160. print "No bosses found..."
  161. chk = raw_input("Try again? Y/N")
  162. if chk.lower() == "y":
  163. bossSelector()
  164. else:
  165. return False
  166.  
  167. return True
  168.  
  169.  
  170.  
  171. def formRaid():
  172. #print formerID
  173. one = 1
  174. while one == 1:
  175. try:
  176. global _startTime
  177. _startTime = datetime.datetime.now()
  178.  
  179. formpage = alo("http://"+server+".outwar.com/formraid.php?target=" + bossToRaidId+"&suid="+FORMER_ID).read()
  180. codeID = formpage.split('codeid" value="Join this Raid!">')[0]
  181.  
  182. Form = alo2("http://"+server+".outwar.com/formraid.php?target=" + bossToRaidId, "target=" + bossToRaidId + "&codeid=" + codeID + "&formtime=3&submit=Launch!").read()
  183.  
  184. global RAID_ID, RAID_NAME
  185. RAID_ID = getRaidID(Form)
  186. RAID_NAME = getRaidName(Form)
  187.  
  188. print ""
  189. print "***" + RAID_NAME + " Formed."
  190. one = 0
  191. return True
  192.  
  193. except IndexError:
  194. print "Forming Error, retrying...."
  195. time.sleep(1)
  196.  
  197. def intC(x):
  198. if type(x) not in [type(0), type(0L)]:
  199. raise TypeError("Parameter must be an integer.")
  200. if x < 0:
  201. return '-' + intWithCommas(-x)
  202. result = ''
  203. while x >= 1000:
  204. x, r = divmod(x, 1000)
  205. result = ",%03d%s" % (r, result)
  206. return "%d%s" % (x, result)
  207.  
  208.  
  209. def getRaidID(src):
  210. #raids = alo("http://"+server+".outwar.com/crew_raidsforming.php")
  211. #srcraids = raids.read()
  212. try:
  213. return iB(src, "joinraid.php?raidid=", "&")
  214. except IndexError:
  215. print "Couldn't retrieve raid ID"
  216. return False
  217.  
  218. def launchRaid(launchURL):
  219. x = 1
  220. while x == 1:
  221. try:
  222. launch = alo(launchURL).read()
  223. if "Your raid will launch shortly" in launch:
  224. print "RAID LAUNCHED!"
  225. global _finishTime
  226. _finishTime = datetime.datetime.now()
  227. x = 0
  228. return True
  229. except IndexError:
  230. x = 1
  231. time.sleep(1)
  232.  
  233. def launchWait():
  234. checking = 1
  235. while checking == 1:
  236. check = alo('http://'+server+'.outwar.com/joinraid.php?raidid=' + RAID_ID).read()
  237.  
  238. if "Attacks!" in check:
  239. # Raid has launched, gather data
  240. # attacks for <font color="#FF9900"> 3,651</b><
  241. # CRITICAL!</font><font color="#FF9900"> 6,491</b>
  242. attackDamage = 0
  243. try:
  244. exp = re.compile('<font color="#FF9900"> (.+)</b><')
  245. attacks = re.findall(exp, check)
  246. for i in attacks:
  247. z = int(i.replace(',', ''))
  248. attackDamage = attackDamage + z
  249. except:
  250. pass
  251.  
  252. global damageLastRaid, totalRaidDamage
  253. damageLastRaid = attackDamage
  254. totalRaidDamage = totalRaidDamage + attackDamage
  255. checking = 0
  256. else:
  257. time.sleep(1)
  258.  
  259.  
  260.  
  261. if LOGIN_WITH_SESSION:
  262. loginrpg = alo("http://"+server+".outwar.com/myaccount.php?rg_sess_id=" + rg_sess_id + "&serverid="+SERVER_ID+"&suid=" + FORMER_ID)
  263. print "Logged in RGA with session ID\n"
  264. else:
  265. loginrpg = alo2("http://"+server+".outwar.com/myaccount.php", "login_username="+username+"&login_password="+password)
  266. loginchar = alo("http://"+server+".outwar.com/world.php?suid="+FORMER_ID+"&serverid="+SERVER_ID)
  267. print "Logged in RGA\n"
  268.  
  269. if bossSelector():
  270.  
  271. x = 1
  272. while x == 1:
  273. formRaid()
  274.  
  275. for i in chars:
  276. join = alo2('http://'+server+'.outwar.com/joinraid.php?raidid=' + RAID_ID + '&suid=' + i + '&serverid='+SERVER_ID, "join=1").read()
  277. time.sleep(0.1)
  278. if "rage to join this raid" in join:
  279. print i + " out of rage..."
  280. elif "must be a member of this crew" in join:
  281. print i + " not in crew..."
  282. else:
  283. print "Joined " + getCharName(join)
  284.  
  285.  
  286. launchURL = 'http://'+server+'.outwar.com/joinraid.php?raidid=' + RAID_ID + '&suid=' + FORMER_ID + '&serverid='+SERVER_ID+'&launchraid=yes&x=141&y=36'
  287. launchRaid(launchURL)
  288. tTime = _finishTime - _startTime
  289. print "Raid time: " + str(tTime.seconds) + " seconds.\n"
  290. # Wait for launch before reforming...
  291. launchWait()
  292. print "Raid Damage: " + intC(damageLastRaid)
  293. print "Damage Total: " + intC(totalRaidDamage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement