6
6
import json
7
7
import logging
8
8
import random
9
+ import config
9
10
logger = logging .getLogger (__name__ )
10
11
11
12
@@ -19,7 +20,7 @@ def __init__(self, player):
19
20
self .botNetServers = 3
20
21
self .botnet = []
21
22
self .p = player
22
- self .ofwhat = [ "fw" , "av" , "smash" , "mwk" ]
23
+ self .ofwhat = config . BotNet_updates
23
24
self .energy = 0
24
25
self ._initbot ()
25
26
@@ -29,12 +30,14 @@ def _initbot(self):
29
30
and populate and array of Bot class
30
31
:return: none
31
32
"""
33
+ if (self .ofwhat == "ALL" ):
34
+ self .ofwhat = ["fw" , "av" , "smash" , "mwk" ]
32
35
data = self ._botnetInfo ()
33
36
bots = json .loads (data )
34
37
self .botnet = []
35
38
if int (bots ['count' ]) > 0 :
36
39
for i in bots ['data' ]:
37
- bot = Bot (i ['running' ], self .ofwhat [random .randint (0 ,3 )], self .energy , i ['hostname' ], self .username , self .password , self .uhash )
40
+ bot = Bot (i ['running' ], self .ofwhat [random .randint (0 ,len ( self . ofwhat ) - 1 )], self .energy , i ['hostname' ], self .username , self .password , self .uhash )
38
41
self .botnet .append (bot )
39
42
40
43
def printbots (self ):
@@ -77,46 +80,47 @@ def attack(self):
77
80
78
81
for i in range (1 , self .botNetServers + 1 ):
79
82
if cinfo [i - 1 ] == '1' :
80
- logger .debug ('attacking #{}' .format (i ))
83
+ logger .debug ('I am attacking #{}' .format (i ))
81
84
if i == 1 :
82
85
response = self .ut .requestString (self .username , self .password , self .uhash , "vh_attackCompany.php" , company = str (i ))
83
86
else :
84
87
response = self .ut .requestString (self .username , self .password , self .uhash , "vh_attackCompany" + str (i ) + ".php" , company = str (i ))
85
- logger .debug ('attack #{} response {}' .format (i , response ))
88
+ logger .debug ('I attacked #{} with response {}' .format (i , response ))
86
89
if response == '0' :
87
90
logger .info ('#{} Netcoins gained' .format (i ))
88
91
else :
89
92
logger .info ('#{} Failed! No netcoins...' .format (i ))
90
93
else :
91
- logger .info ("Botnet #{} not hackable as yet" .format (i ))
94
+ logger .info ("Botnet #{} not hackable yet" .format (i ))
92
95
93
96
def upgradebotnet (self , hostname , running , count ):
94
97
"""
95
98
Check if there is enough money to upgrade a botnet PC.
96
99
Cycle through and upgrade until no money.
97
100
:return: None
98
101
"""
99
- logger .info ("Prepare attempting to upgrade bot net PC's " + hostname )
102
+ ofwhat = self .ofwhat [random .randint (0 ,len (self .ofwhat )- 1 )]
103
+ logger .info ("Prepare attempting to upgrade bot net PC '" + hostname + "'" )
100
104
get_infobot = self .getInfo ()
101
105
102
106
if (int (get_infobot ['data' ][count ]['strength' ]) == 1120 and int (get_infobot ['data' ][count ]['stars' ]) == 4 ):
103
- logger .info ("bot is complet [ max strength 1120] " + hostname + " for level " + str (get_infobot ['data' ][count ]['stars' ]))
107
+ logger .info ("Bot '" + hostname + "' has max strength [ 1120] for level " + str (get_infobot ['data' ][count ]['stars' ]))
104
108
return False
105
109
106
110
elif (int (get_infobot ['data' ][count ]['strength' ]) == 840 and int (get_infobot ['data' ][count ]['stars' ]) == 3 ):
107
- logger .info ("bot is complet [ max strength 840] " + hostname + " for level " + str (get_infobot ['data' ][count ]['stars' ]))
111
+ logger .info ("Bot '" + hostname + "' has max strength [ 840] for level " + str (get_infobot ['data' ][count ]['stars' ]))
108
112
return False
109
113
110
114
elif (int (get_infobot ['data' ][count ]['strength' ]) == 600 and int (get_infobot ['data' ][count ]['stars' ]) == 2 ):
111
- logger .info ("bot is complet [ max strength 600] " + hostname + " for level " + str (get_infobot ['data' ][count ]['stars' ]))
115
+ logger .info ("Bot '" + hostname + "' has max strength [ 600] for level " + str (get_infobot ['data' ][count ]['stars' ]))
112
116
return False
113
117
114
118
elif (int (get_infobot ['data' ][count ]['strength' ]) == 400 and int (get_infobot ['data' ][count ]['stars' ]) == 1 ):
115
- logger .info ("bot is complet [ max strength 400] " + hostname + " for level " + str (get_infobot ['data' ][count ]['stars' ]))
119
+ logger .info ("Bot '" + hostname + "' has max strength [ 400] for level " + str (get_infobot ['data' ][count ]['stars' ]))
116
120
return False
117
121
118
122
elif (int (get_infobot ['data' ][count ]['strength' ]) == 3000 and int (get_infobot ['data' ][count ]['stars' ]) == 0 ):
119
- logger .info ("bot is complet [ max strength 3000] " + hostname + " for level " + str (get_infobot ['data' ][count ]['stars' ]))
123
+ logger .info ("Bot '" + hostname + "' has max strength [ 3000] for level " + str (get_infobot ['data' ][count ]['stars' ]))
120
124
return False
121
125
122
126
if (int (get_infobot ['data' ][count ]['running' ]) == 0 and int (get_infobot ['energy' ]) > 0 ):
@@ -129,29 +133,29 @@ def upgradebotnet(self, hostname, running, count):
129
133
130
134
remove = 0
131
135
132
- for a , i in enumerate (xrange (0 , 4 )):
136
+ for a , i in enumerate (xrange (0 , len ( self . ofwhat ) - 1 )):
133
137
if int (get_infobot ['data' ][count ][unicode (self .ofwhat [i - remove ])]) == int (maxofwhat ):
134
138
self .ofwhat .remove (self .ofwhat [i - remove ])
135
- remove = remove + 1
136
-
139
+ remove = remove + 1
137
140
if i == 3 :
138
141
break
139
142
140
143
ofwhat = self .ofwhat [random .randint (0 ,(len (self .ofwhat )- 1 ))]
144
+
141
145
new_bal = self .upgradesinglebot (hostname , ofwhat )
142
146
if new_bal :
143
- logger .info ("wait botnet update working for " + hostname + ", [" + ofwhat + "]" )
147
+ logger .info ("Waiting! Doing updates for bot ' " + hostname + "' , [" + ofwhat + "]" )
144
148
return True
145
149
146
150
elif (int (get_infobot ['energy' ]) == 0 ):
147
- logger .info ("your are not energy for update " + hostname + " :(" )
151
+ logger .info ("You don't have enough energy to upgrade ' " + hostname + "'! :(" )
148
152
return False
149
153
150
154
elif (int (get_infobot ['data' ][count ]['running' ]) == 1 ):
151
- logger .info (hostname + " running update please wait... " )
155
+ logger .info ("Waiting! Doing updates for bot '" + hostname + "', [" + ofwhat + "] " )
152
156
return False
153
157
154
- logger .debug ("#{} not upgradeable" .format (hostname ))
158
+ logger .debug ("The bot '{}' is not upgradeable" .format (hostname ))
155
159
return False
156
160
157
161
def _botnetInfo (self ):
@@ -183,7 +187,7 @@ def upgradesinglebot(self, hostname, ofwhat):
183
187
if int (jsons ['result' ]) == 0 :
184
188
return True
185
189
else :
186
- logger .error ("Upgrade " + hostname + " Failed !" )
190
+ logger .error ("Upgrades on " + hostname + " Failed !" )
187
191
return False
188
192
189
193
def __repr__ (self ):
@@ -237,10 +241,9 @@ def upgradesinglebot(self, hostname, ofwhat):
237
241
:return: None
238
242
"""
239
243
response = self .ut .requestString (self .username , self .password , self .uhash , "vh_upgradePC.php" , hostname = hostname , ofwhat = ofwhat )
240
- response = response .split ('}{' )[0 ] + '}'
241
- print (response )
242
- jsons = json .loads (response )
243
- logger .info (jsons )
244
+ #response = response.split('}{')[0] + '}'
245
+ #jsons = json.loads(response)
246
+ #logger.info(jsons)
244
247
return True
245
248
246
249
0 commit comments