-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
426 lines (348 loc) · 14.4 KB
/
main.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
import json
import time
import random
import requests
from web3 import Web3
from config import USER_INFO, RPC
SUM_TMNK, WAIT_TMNK = 0, 0
ALL_SPEED = 0
HEADERS = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Accept-Language': 'en,zh-CN;q=0.9,zh;q=0.8',
'Content-Length': '23',
'Content-Type': 'application/json',
'Cookie': 'PHPSESSID=',
'Origin': 'chrome-extension://igimfdmnnijclcfdgimooedbealfpndj',
'Priority': 'u=1, i',
'Sec-Ch-Ua': '"Google Chrome";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': '"macOS"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'none',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
}
URL = 'https://x.metacene.io/cmd.php'
data_wakePet = {"user": {"wakePet": {}}} # 唤醒宠物
data_levelUp = {"user": {"petLvUp": {}}} # 宠物升级
data_levelUp1 = {"user": {"roleLvUp": {"role_id": 1}}} # 角色1升级
data_levelUp2 = {"user": {"roleLvUp": {"role_id": 2}}} # 角色2升级
data_login = {"guide": {"login": {}}} # 登录
data_recharge = {"user": {"recharge": {"spar": "10000000"}}} # 充值
data_useEnergy1 = {"user": {"useEnergy": {"role_id": 1, "count": 1}}} # 角色1使用1个电池
data_useEnergy2 = {"user": {"useEnergy": {"role_id": 2, "count": 1}}} # 角色2使用1个电池
data_MineBoxInfo = {"user": {"getMineBoxInfo": {}}} # 宝箱信息
data_OpenMineBox = {"user": {"openMineBox": {}}} # 开宝箱
data_checkIn = {"user": {"getCheckInSign": {}}} # 每日签到
data_lockRole1 = {"user": {"lockRole": {"role_id": 1}}} # 解锁角色1
data_getConfig = {"guide": {"getConfig": {}}} # 获取配置信息
data_getExchangeRate = {"user": {"getExchangeRate": {}}} # 获取积分数和兑换比例
data_exchange = {"user": {"exchange": {"integral": 164}}} # 兑换积分
data_getNumTMAK = {"user": {"getHdAllGet": {}}} # 获取TMNK数量
data_getDailyTask = {"user": {"getTaskList": {"type": 0}}} # 获取每日任务
def get_time_to_7am():
import datetime
current_time = datetime.datetime.now()
next_7am = current_time.replace(hour=7, minute=0, second=0, microsecond=0)
if current_time >= next_7am:
next_7am = next_7am + datetime.timedelta(days=1)
time_difference = next_7am - current_time
seconds_left = time_difference.total_seconds()
return seconds_left
def get_headers(user):
time.sleep(random.randint(5, 15))
headers = HEADERS
headers['Cookie'] = 'PHPSESSID=' + user[1]
return headers
def login(user):
headers = get_headers(user)
response = requests.post(URL, json=data_login, headers=headers)
print('> Login@' + user[0] + ' ' + response.text)
return response.text
def wakePet(user):
headers = get_headers(user)
response = requests.post(URL, json=data_wakePet, headers=headers)
print('> wakePet@' + user[0] + ' ' + response.text)
return response.text
def levelUp(user):
headers = get_headers(user)
response = requests.post(URL, json=data_levelUp, headers=headers)
print('> levelUp@' + user[0] + ' ' + response.text)
return response.text
def levelUp1(user):
headers = get_headers(user)
response = requests.post(URL, json=data_levelUp1, headers=headers)
print('> levelUp1@' + user[0] + ' ' + response.text)
return response.text
def levelUp2(user):
headers = get_headers(user)
response = requests.post(URL, json=data_levelUp2, headers=headers)
print('> levelUp2@' + user[0] + ' ' + response.text)
return response.text
def lockRole1(user):
headers = get_headers(user)
response = requests.post(URL, json=data_lockRole1, headers=headers)
print('> lockRole1@' + user[0] + ' ' + response.text)
return response.text
def recharge(user, spar):
headers = get_headers(user)
data_recharge['user']['recharge']['spar'] = str(int(spar))
response = requests.post(URL, json=data_recharge, headers=headers)
print('> recharge@' + user[0] + ' ' + response.text)
return response.text
def getMineBoxInfo(user):
headers = get_headers(user)
response = requests.post(URL, json=data_MineBoxInfo, headers=headers)
print('> getMineBoxInfo@' + user[0] + ' ' + response.text)
return response.text
def getDailyTask(user):
headers = get_headers(user)
response = requests.post(URL, json=data_getDailyTask, headers=headers)
print('> getDailyTask@' + user[0] + ' ' + response.text)
return response.text
def openMineBox(user):
headers = get_headers(user)
response = requests.post(URL, json=data_OpenMineBox, headers=headers)
print('> openMineBox@' + user[0] + ' ' + response.text)
mine_box_info = json.loads(response.text)
to_ = mine_box_info['check']['to']
expired = mine_box_info['check']['expired']
mnt = mine_box_info['check']['mnt']
tmak = mine_box_info['check']['tmak']
nonce = mine_box_info['check']['nonce']
signature = mine_box_info['check']['signature']
uid = mine_box_info['check']['uid']
type_ = mine_box_info['check']['type']
web3 = Web3(Web3.HTTPProvider(RPC))
if not web3.is_connected():
print("RPC Connection Error")
return
caller, private_key = user[2], user[3]
abi = json.loads(open("abi.json", "r").read())
contract_address = "0x9B63C5B7a68573Bbc47336Ec0247798411f561b9"
contract = web3.eth.contract(address=contract_address, abi=abi)
tx_obj = contract.functions.openLuckyChest(nonce, expired, signature)
transaction = tx_obj.build_transaction({
'from': caller,
'gas': int(_getEstimateGas(caller, contract_address) * 2.5),
'gasPrice': _getGasPrice(),
'nonce': web3.eth.get_transaction_count(caller),
})
signed_txn = web3.eth.account.sign_transaction(transaction, private_key=private_key)
tx_hash = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx_status = web3.eth.wait_for_transaction_receipt(tx_hash)['status']
tx_status_msg = 'Success' if tx_status == 1 else 'Failed'
print('> openMineBox@' + user[0] + ' Status: ' + tx_status_msg + ' TxHash: ', tx_hash.hex())
def dailyCheckIn(user):
daily_check = json.loads(getDailyTask(user))
has_daily_check = False
for task in daily_check['data']:
if task['type'] == 5 and task['name'] == 'Daily check-in':
has_daily_check = True
break
if has_daily_check:
headers = get_headers(user)
response = requests.post(URL, json=data_checkIn, headers=headers)
print('> dailyCheckIn@' + user[0] + ' ' + response.text)
daily_box_info = json.loads(response.text)
to_ = daily_box_info['check']['to']
expired = daily_box_info['check']['expired']
mnt = daily_box_info['check']['mnt']
tmak = daily_box_info['check']['tmak']
nonce = daily_box_info['check']['nonce']
signature = daily_box_info['check']['signature']
uid = daily_box_info['check']['uid']
type_ = daily_box_info['check']['type']
task_id = daily_box_info['check']['task_id']
web3 = Web3(Web3.HTTPProvider(RPC))
if not web3.is_connected():
print("RPC Connection Error")
return
caller, private_key = user[2], user[3]
abi = json.loads(open("abi.json", "r").read())
contract_address = "0x9B63C5B7a68573Bbc47336Ec0247798411f561b9"
contract = web3.eth.contract(address=contract_address, abi=abi)
tx_obj = contract.functions.signIn(int(nonce), int(expired), int(tmak), int(mnt), signature)
transaction = tx_obj.build_transaction({
'from': caller,
'gas': int(_getEstimateGas(caller, contract_address) * 3.5),
'gasPrice': _getGasPrice(),
'nonce': web3.eth.get_transaction_count(caller),
})
signed_txn = web3.eth.account.sign_transaction(transaction, private_key=private_key)
tx_hash = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx_status = web3.eth.wait_for_transaction_receipt(tx_hash)['status']
tx_status_msg = 'Success' if tx_status == 1 else 'Failed'
print('> dailyCheckIn@' + user[0] + ' Status: ' + tx_status_msg + ' TxHash: ', tx_hash.hex())
def getNumTMAK(user):
try:
headers = get_headers(user)
response = requests.post(URL, json=data_getNumTMAK, headers=headers)
print('> getNumTMAK@' + user[0] + ' ' + response.text)
sum_gat = json.loads(response.text)['data']['sum_gat']
wait_get = json.loads(response.text)['data']['wait_get']
sum_tmak, wait_tmak = 0, 0
for it in sum_gat:
if it['item_name'] == 'TMAK':
sum_tmak = it['count']
for it in wait_get:
if it['item_name'] == 'TMAK':
wait_tmak = it['count']
return sum_tmak, wait_tmak
except Exception as e:
print('Error > getNumTMAK: ', e)
return 0, 0
def _getGasPrice():
payload = json.dumps({
"method": "eth_gasPrice",
"params": [],
"id": 1,
"jsonrpc": "2.0"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", RPC, headers=headers, data=payload)
res = json.loads(response.text)['result']
return int(res, 16)
def _getEstimateGas(caller, contract_addr):
payload = json.dumps({
"method": "eth_estimateGas",
"params": [
{
"from": caller,
"to": contract_addr
}
],
"id": 1,
"jsonrpc": "2.0"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", RPC, headers=headers, data=payload)
res = json.loads(response.text)['result']
return int(res, 16)
def getExchangeRate(user):
try:
headers = get_headers(user)
response = requests.post(URL, json=data_getExchangeRate, headers=headers)
print('> getExchangeRate@' + user[0] + ' ' + response.text)
data_json = json.loads(response.text)
return data_json['data']['integral'], data_json['data']['rate']
except Exception as e:
print('Error > getExchangeRate: ', e)
return 0, 0
def exchange(user, integral):
headers = get_headers(user)
data_exchange['user']['exchange']['integral'] = integral
response = requests.post(URL, json=data_exchange, headers=headers)
print('> exchange@' + user[0] + ' ' + response.text)
return response.text
def useEnergy1(user):
headers = get_headers(user)
response = requests.post(URL, json=data_useEnergy1, headers=headers)
print('> useEnergy1@' + user[0] + ' ' + response.text)
return response.text
def useEnergy2(user):
headers = get_headers(user)
response = requests.post(URL, json=data_useEnergy2, headers=headers)
print('> useEnergy2@' + user[0] + ' ' + response.text)
return response.text
def op(user):
info = login(user)
info = json.loads(info)
# 计算总速度
global ALL_SPEED
all_speed = info['data']['pet']['all_speed']
ALL_SPEED += all_speed
# 宠物唤醒逻辑
end_time = info['data']['pet']['end_time']
now = time.time()
if end_time - now < 3600 * 4: # 如果now距离end_time小于4h,则唤醒宠物
wakePet(user)
spar = info['data']['header']['spar']
energy = info['data']['header']['energy']
integral = info['data']['header']['integral']
# 充值逻辑
if get_time_to_7am() < 3600 * 7 and spar > 100000: # 如果距离7点不足7小时
recharge(user, spar)
spar = 0
lv0 = info['data']['pet']['lv']
# 宠物升级逻辑,优先升级pet
pet_level_up = False
up_need_spar = info['data']['pet']['upNeedSpar']
if lv0 < 500:
while spar >= up_need_spar:
pet_level_up = True
rsp = json.loads(levelUp(user))
spar -= up_need_spar
up_need_spar = rsp['data']['pet']['upNeedSpar']
else:
pet_level_up = True
# 角色1解锁逻辑
if info['data']['roleMan']['lv'] == 0: # 未解锁
if spar >= info['data']['roleMan']['unlock_cost']['count']:
spar -= info['data']['roleMan']['unlock_cost']['count']
lockRole1(user)
# 角色1升级逻辑
if 0 < info['data']['roleMan']['lv'] < 500 and pet_level_up:
up_need_spar = info['data']['roleMan']['upNeedSpar']
while spar >= up_need_spar:
rsp = json.loads(levelUp1(user))
spar -= up_need_spar
up_need_spar = rsp['data']['roleMan']['upNeedSpar']
# 角色1使用电池
energy1 = info['data']['roleMan']['energy']
while energy1 < 4 and energy > 0:
useEnergy1(user)
energy1 += 1
energy -= 1
# 角色2升级逻辑
if 0 < info['data']['roleWoman']['lv'] < 500 and pet_level_up:
up_need_spar = info['data']['roleWoman']['upNeedSpar']
while spar >= up_need_spar:
rsp = json.loads(levelUp2(user))
spar -= up_need_spar
up_need_spar = rsp['data']['roleWoman']['upNeedSpar']
# 角色2使用电池
if info['data']['roleWoman']['lv'] > 0:
energy2 = info['data']['roleWoman']['energy']
while energy2 < 4 and energy > 0:
useEnergy2(user)
energy2 += 1
energy -= 1
# 开宝箱
if len(user) == 4:
mine_box_info = json.loads(getMineBoxInfo(user))
if mine_box_info['data']['cd'] == 0:
openMineBox(user)
# 每日签到
if len(user) == 4:
dailyCheckIn(user)
# 兑换tmak
# integral, rate = getExchangeRate(user)
if integral > 0:
exchange(user, integral)
# 获取tmak数量
sum_tmak, wait_tmak = getNumTMAK(user)
global SUM_TMNK, WAIT_TMNK
SUM_TMNK += sum_tmak
WAIT_TMNK += wait_tmak
print('> NumTMNK@' + user[0] + ' sum_tmak: ', sum_tmak, ' wait_tmak: ', wait_tmak)
if __name__ == '__main__':
loop_cnt = 0
while True:
SUM_TMNK, WAIT_TMNK = 0, 0
ALL_SPEED = 0
loop_cnt += 1
print('Loop Start: ', loop_cnt, '-------------------------',
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
time.sleep(random.randint(5, 15))
for user in USER_INFO:
try:
op(user)
except Exception as e:
print('Error @' + user[0] + ': ', e)
print('Loop End: ', loop_cnt, '-------------------------', 'SUM_TMNK: ', SUM_TMNK, 'WAIT_TMNK: ', WAIT_TMNK, 'ALL_SPEED: ', ALL_SPEED)