-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchecker.py
executable file
·229 lines (170 loc) · 5.15 KB
/
checker.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
#!/usr/bin/env python3
from gevent import monkey
monkey.patch_all()
import sys
import os
import string
import random
import copy
from checklib import *
argv = copy.deepcopy( sys.argv )
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from martian_lib import *
# my utils
def idg( size = 8, chars = alph ):
return ''.join( random.choice( chars ) for _ in range( size ) )
def generate_correct_random_name():
return idg( 1, string.ascii_uppercase ) + idg()
def generate_correct_random_password():
password = idg( 1, string.ascii_uppercase )
tmp = idg( 4, string.ascii_uppercase )
tmp += idg( 4, string.ascii_lowercase )
tmp += idg( 4, string.digits )
tmp = list( tmp )
random.shuffle( tmp )
password += ''.join( tmp )
return password
class Checker(BaseChecker):
def __init__(self, *args, **kwargs):
super(Checker, self).__init__(*args, **kwargs)
self.mch = CheckMachine(self)
def action(self, action, *args, **kwargs):
super( Checker, self ).action( action, *args, **kwargs )
def check( self ):
self.mch.connection()
# check register and login
username = generate_correct_random_name()
password = generate_correct_random_password()
self.mch.reg_user( username, password )
logined, err_msg = self.mch.login( username, password )
if not logined:
self.cquit( Status.MUMBLE,
"Can't login by registered user",
"Checker.login(): err_msg = {}".format( err_msg )
)
# test read book
_stats = self.mch.get_user_stats()
start_int = _stats[ 'intelligence' ]
if self.mch.read_book( 1 ):
# Check int diff
_stats = self.mch.get_user_stats()
if ( _stats[ 'intelligence' ] - start_int ) != 35:
self.cquit( Status.MUMBLE,
"Incorrect intelligence changing!",
"Checker.read_book(): INT changing error!"
)
else:
self.cquit( Status.MUMBLE,
"Read book error!",
"Checker.read_book(): basic read book"
)
# just farm book reading to increase INT and get some cap
self.mch.read_book( 20 )
# go to next day
self.mch.go_to_next_day()
_stats = self.mch.get_user_stats()
actions = _stats[ 'actions' ]
# check action-points changing
if actions != 24:
self.cquit( Status.MUMBLE,
"Actions difference error!",
"Recovering points when switching to another day does not work correctly"
)
# repair home
self.mch.repair_home()
# test easy raid
# go to raid
retcode, err_msg = self.mch.easy_raid()
if not retcode:
self.cquit( Status.MUMBLE,
"Can't do easy raid!",
"No actions to make easy raid!"
)
# farm INT and potatoes
self.mch.go_to_next_day()
# test medium raid
retcode, err_msg = self.mch.medium_raid()
if not retcode:
self.cquit( Status.MUMBLE,
"Can't do medium raid!",
"No actions to make medium raid!"
)
# regen HP
for i in range( 2 ):
ret_code, _ = self.mch.eat_potato()
if not retcode:
self.cquit( Status.MUMBLE,
"No potatoes, but many raids already completed!",
"No potatoes, but many raids already completed!"
)
self.mch.go_to_next_day()
# test hard raid
retcode, _ = self.mch.hard_raid()
if not retcode:
self.cquit( Status.MUMBLE,
"Can't do hard raid!",
"No actions to make hard raid!"
)
# view trophy and recycle it
retcode, msg = self.mch.view_trophy()
if not retcode:
self.cquit( Status.MUMBLE,
"Can't view trophy",
"Can't view trophy, msg: {}".format( msg )
)
valid_code = msg
retcode, msg = self.mch.recycle_trophy( valid_code )
if not retcode:
self.cquit( Status.MUMBLE,
"Can't recycle trophy",
"Can't recycle trophy, msg: {}".format( msg )
)
# check runaway in hard raid
self.mch.go_to_next_day()
self.mch.chek_runaway_hard_raid( idg( 8 ) )
# check power scheme changing
self.mch.check_change_power_scheme()
self.mch.save_file()
self.mch.safe_close_connection()
self.cquit( Status.OK )
def put( self, flag_id, flag, vuln ):
if vuln == '1':
username = generate_correct_random_name()
password = generate_correct_random_password()
else:
username = "Item" + idg()
password = generate_correct_random_password()
self.mch.connection()
self.mch.reg_user( username, password )
logined, err_msg = self.mch.login( username, password )
if not logined:
self.cquit( Status.MUMBLE,
"Can't login by registered user",
"Checker.login(): err_msg = {}".format( err_msg )
)
self.mch.set_status( flag )
self.mch.safe_close_connection()
self.cquit( Status.OK, f'{username}:{password}' )
def get( self, flag_id, flag, vuln ):
username, password = flag_id.split( ":" )
self.mch.connection()
logined, err_msg = self.mch.login( username, password )
if not logined:
self.cquit( Status.CORRUPT,
"Can't login and flag check!",
"Checker.login(): err_msg = {}".format( err_msg )
)
status = self.mch.get_status()
if status != flag:
self.cquit( Status.CORRUPT,
"Incorrect flag",
"Checker.get_status(): valid_flag = {}, user_flag = {}".format(
flag, status )
)
self.cquit( Status.OK )
if __name__ == '__main__':
c = Checker(argv[2])
try:
c.action(argv[1], *argv[3:])
except c.get_check_finished_exception():
cquit(Status(c.status), c.public, c.private)