Advertisement
Guest User

Untitled

a guest
May 15th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. #!/usr/bin/python2.7
  2. # -*- coding: utf-8
  3.  
  4. from utils import Utils
  5. import config
  6. import json
  7. from player import Player
  8. import logging
  9.  
  10. class Botnet:
  11. ut = Utils()
  12. p = Player()
  13.  
  14. def __init__(self):
  15. self.username = config.user
  16. self.password = config.password
  17. self.botNetServers = config.botNetServers
  18. self.botnet = []
  19. self._initbot()
  20.  
  21. def _initbot(self):
  22. """
  23. Grab the amount of bots in the bot net and populate and array of Bot class
  24. :return: none
  25. """
  26. data = self._botnetInfo()
  27. bots = json.loads(data)
  28. for i in bots['data']:
  29. bot = Bot(i['bID'], i['bLVL'], i['bPRICE'])
  30. self.botnet.append(bot)
  31.  
  32. def printbots(self):
  33. """
  34. Print a list of player PCs in the botnet
  35. :return: None
  36. """
  37. for bot in self.botnet:
  38. print bot
  39.  
  40. def getbotnetdata(self):
  41. """
  42. Return an array of bot class. Contains all the bots in the bot net.
  43. :return: list of bot class
  44. """
  45. return self.botnet
  46.  
  47. def getInfo(self):
  48. """
  49. Get infor about the entire botnet. Including if you can attack bot net servers etc. Also bot net PC info
  50. :return: list of vHack serves that can be hacked. ['1','2','1']. '1' = can be hacked, '2' time not elapsed.
  51. """
  52. response = self.ut.botnetserverinfo()
  53. arr = response.split('","canAtt')
  54. l = []
  55. for i1 in arr[1:]:
  56. l.append(i1.split(':')[1].split('"')[1])
  57. return l
  58.  
  59. def _attackable(self):
  60. """
  61. Retrieve all vhack botnet info. Hack times and botnet pc data. Determine if can attack.
  62. :return: none
  63. """
  64. t = self.getInfo()
  65. attack = False
  66. for i1 in t:
  67. if "1" in i1:
  68. attack = True
  69. return attack
  70.  
  71. def _attackall(self):
  72. """
  73. Determine the amount of vHack servers from the config files, and attack each one.
  74. :return: none
  75. """
  76. for i in range(1, self.botNetServers+1):
  77. response = self.ut.attackbotnetserver(i)
  78.  
  79. def attack(self):
  80. """
  81. Check if vHack server botnet is attackable, then attack if can.
  82. :return: none
  83. """
  84. logging.info("Trying Bot Net")
  85. if self._attackable():
  86. self._attackall()
  87. else:
  88. logging.info("Botnet not hackable as yet")
  89.  
  90. def upgradebotnet(self):
  91. """
  92. Check if there is enough money to upgrade a botnet PC. Cycle through and upgrade until no money.
  93. :return: None
  94. """
  95. print "Attempting to upgrade bot net PC's"
  96. logging.info("Attempting to upgrade bot net PC's")
  97. for i in self.botnet:
  98. if i.botupgradable():
  99. while self.p.getmoney() > i.nextlevelcost():
  100. i.upgradesinglebot()
  101. self.p.updatemoney(i.nextlevelcost() * -1)
  102.  
  103. def _botnetInfo(self):
  104. """
  105. Get the botnet information including vHack servers and PC data.
  106. :return: string
  107. '{"count":"14",
  108. "data":[{"bID":"1","bLVL":"100","bSTR":"100","bPRICE":"10000000"},
  109. {"bID":"2","bLVL":"100","bSTR":"100","bPRICE":"10000000"}],
  110. "strength":23,"resethours1":"","resetminutes1":"14","resethours2":"4","resetminutes2":"15",
  111. "resethours3":"3","resetminutes3":"15",
  112. "canAtt1":"2","canAtt2":"2","canAtt3":"2"}'
  113. """
  114. temp = self.ut.botnetserverinfo()
  115. return temp
  116.  
  117. def __repr__(self):
  118. return "Botnet details: vHackServers: {0}, Bot Net PC's: {1}".format(self.botNetServers, self.botnet)
  119.  
  120.  
  121. class Bot:
  122. ut = Utils()
  123.  
  124. def __init__(self, botid, botlvl, price):
  125. self.id = int(botid)
  126. self.lvl = int(botlvl)
  127. self.upgradecost = int(price)
  128.  
  129. def botupgradable(self):
  130. """
  131. Determine if botnet PC is at max level or not.
  132. :return: Bool
  133. """
  134. if self.lvl < 100:
  135. return True
  136. else:
  137. return False
  138.  
  139. def nextlevelcost(self):
  140. """
  141. Return the cost of upgrading bot to the next level
  142. :return:int
  143. """
  144. return self.upgradecost
  145.  
  146. def upgradesinglebot(self):
  147. """
  148. Pass in bot class object and call upgrade function based on bot ID.
  149. :return: None
  150. """
  151. response = self.ut.upgradebot(self.id)
  152. details = json.loads(response)
  153. self.upgradecost += 100000
  154. # logging.info("Bot # {0} upgraded to level {1} at a cost of {2}".format(details['old'], details['lvl'], details['costs']))
  155.  
  156. def __repr__(self):
  157. return "Bot details: id: {0}, Level: {1}, Next Cost: {2}".format(self.id, self.lvl, self.upgradecost)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement