-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsellcatch.py
250 lines (193 loc) · 7.22 KB
/
sellcatch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
from datetime import datetime
import html
import random
import threading
import time
from os.path import exists
from rocalert.cookiehelper import load_cookies_from_browser, load_cookies_from_path
from rocalert.captcha.captchaprovider import CaptchaProvider
from rocalert.roc_settings import SettingsSetupHelper, UserSettings
from rocalert.roc_web_handler import Captcha, RocWebHandler
from rocalert.services.captchaservices import ManualCaptchaSolverService
from rocalert.services.urlgenerator import ROCDecryptUrlGenerator
from rocalert.services.useragentgenerator import (
Browser,
OperatingSystem,
UserAgentGenerator,
)
targetids = [29428]
mingold = 10_000_000_000 # 10b
delay_min_ms = 200
delay_max_ms = 300
beep = True
cookie_filename = "cookies"
def getgoldfrompage(page: str) -> int:
index = page.index('playercard_gold c">')
endindex = page[index : index + 200].index(" Gold")
goldstr = page[index + len('playercard_gold c">?') - 1 : index + endindex]
if "?" in goldstr:
return -1
goldstr = html.unescape(goldstr).strip().replace(",", "")
return int(goldstr)
def getgold(roc: RocWebHandler, id: str):
url = roc.url_generator.get_home() + f"stats.php?id={id}"
roc.go_to_page(url)
if roc.r.status_code != 200:
return -1
else:
return getgoldfrompage(roc.r.text)
def __load_browser_cookies(roc: RocWebHandler, us: UserSettings) -> bool:
if us.get_setting("load_cookies_from_browser").value:
cookies = load_cookies_from_browser(
us.get_setting("browser").value, roc.url_generator.get_home()
)
roc.add_cookies(cookies)
return True
return False
def __load_cookies_file(roc: RocWebHandler, cookie_filename: str) -> bool:
if exists(cookie_filename):
print("Loading saved cookies")
cookies = load_cookies_from_path(cookie_filename)
if cookies is not None:
roc.add_cookies(cookies)
def __log(s: str):
print(s)
def login(roc: RocWebHandler, us: UserSettings):
__log("Logging in.")
if __load_browser_cookies(roc, us) and roc.is_logged_in():
__log(
"Successfully pulled cookie from {}".format(us.get_setting("browser").value)
)
return True
res = roc.login(us.get_setting("email").value, us.get_setting("password").value)
if res:
__log("Login success.")
else:
__log("Login failure.")
return False
def goldformat(gold: int) -> str:
if gold == -1:
return "???"
return "{:,}".format(gold)
def attack(roc: RocWebHandler, id: str, captchacache: CaptchaProvider) -> bool:
start = datetime.now()
captcha = captchacache.get_solved_captcha()
captcha_get_time = datetime.now() - start
if captcha_get_time.total_seconds() > 1.5:
print("took to long to get captcha.. resetting")
return False
attack_url = roc.url_generator.get_attack(id)
attack_page = roc.get_attack_page(id)
print(f"Received answer: '{captcha.ans}'")
if captcha is None or int(captcha.ans) not in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
raise Exception("Bad captcha received from solver")
post_captcha_gold = getgold(roc, id)
if not is_target_valid(post_captcha_gold, id):
print(f"Target {id} is no longer valid. Gold: {goldformat(post_captcha_gold)}")
return False
payload = {
"defender_id": id,
"mission_type": "attack",
"attacks": attack_page.max_attack_turns,
}
return roc.submit_captcha_url(captcha, attack_url, payload)
def playbeep(freq: int = 700):
try:
import winsound
winsound.Beep(freq, 2000)
except ImportError:
print("ERROR SETTING UP BEEPING!")
def get_randdelay(minms, maxms) -> float:
range = maxms - minms
waittime = minms + int(random.uniform(0, 1) * (range))
return waittime / 1000
def _get_default_headers():
default_agent = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
+ "Chrome/114.0.0.0 Safari/537.36"
)
agentgenerator = UserAgentGenerator(default=default_agent)
useragent = agentgenerator.get_useragent(
browser=Browser.Chrome, operatingsystem=OperatingSystem.Windows
)
print(f'Using user-agent: "{useragent}"')
return {
"Accept": "text/html,application/xhtml+xml,application/xml"
+ ";q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Connection": "keep-alive",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
"TE": "trailers",
"Upgrade-Insecure-Requests": "1",
"User-Agent": useragent,
}
def is_target_valid(gold: int, id: str) -> bool:
return gold >= mingold and id in targetids
def run():
user_settings_fp = "user.settings"
filepaths = {
"user": ("user.settings", UserSettings),
}
settings_file_error = False
for _, infotuple in filepaths.items():
path, settingtype = infotuple
if SettingsSetupHelper.needs_setup(path):
settings_file_error = True
SettingsSetupHelper.create_default_file(path, settingtype.DEFAULT_SETTINGS)
print(f"Created settings file {path}.")
if settings_file_error:
print("Exiting. Please fill out settings files")
quit()
user_settings = UserSettings(filepath=user_settings_fp)
url_generator = ROCDecryptUrlGenerator()
rochandler = RocWebHandler(
urlgenerator=url_generator, default_headers=_get_default_headers()
)
for i in range(len(targetids)):
targetids[i] = str(targetids[i])
login(rochandler, user_settings)
time.sleep(1)
print("Starting..")
def captcha_provider():
url = rochandler.url_generator.get_armory()
captcha = None
while (
captcha is None
or int(captcha.ans) not in [1, 2, 3, 4, 5, 6, 7, 8, 9]
and not captcha.is_expired
):
captcha = rochandler.get_url_img_captcha(url)
if captcha.type and captcha.type == Captcha.CaptchaType.TEXT:
print("Text captcha!!!")
quit()
mcs = ManualCaptchaSolverService()
captcha = mcs.solve_captcha(captcha)
print(f"got answer {captcha.ans}")
return captcha
captchacache = CaptchaProvider(captcha_provider, cachesize=3)
captchacache.start()
while True:
for id in targetids:
gold = getgold(rochandler, id)
print(f"ID: {id} | Gold: {goldformat(gold)}")
if is_target_valid(gold, id):
print("Target Found!")
if beep:
thr = threading.Thread(target=playbeep, args=(1000,), kwargs={})
thr.start()
hit = attack(rochandler, id, captchacache)
if hit:
print("target hit... quitting!")
quit()
else:
print("target hit failed")
time.sleep(get_randdelay(delay_min_ms, delay_max_ms))
print("-----------------------")
if beep:
thr = threading.Thread(target=playbeep, args=(750,), kwargs={})
thr.start()
run()