-
Notifications
You must be signed in to change notification settings - Fork 42
/
cloud.lua
492 lines (446 loc) · 16.5 KB
/
cloud.lua
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
-- 云控对接
-- 为什么不用local,因为有些解释器的require有bug。
cloud = {}
m = cloud
m.deviceToken = ''
m.captchaToken = ''
m.server = ''
m.captchaServer = ''
m.heartBeatTid = -1
m.status = 1
m.setDeviceToken = function(deviceToken)
deviceToken = strOr(deviceToken):trim()
if #deviceToken < 5 then return end
m.deviceToken = deviceToken
end
m.setCaptcha = function(server, token)
server = strOr(server):trim()
server = server:gsub("/+$", '')
if #server < 5 then return end
m.captchaServer = server
token = strOr(token):trim()
if #token < 5 then return end
m.captchaToken = token
end
m.setServer = function(server)
server = strOr(server):trim()
server = server:gsub("/+$", '')
if #server < 5 then return end
m.server = server
end
m.setStatus = function(status) m.status = status end
m.enabled =
function() return #strOr(m.server) > 0 and #strOr(m.deviceToken) > 0 end
m.getTaskEnabled = function() return cloud_get_task and m.enabled() end
m.heartBeat = function()
-- log("32",32)
local data = { status = m.status, deviceToken = m.deviceToken }
local res, code = httpPost(m.server .. "/heartBeat", JsonEncode(data), 30,
"Content-Type: application/json")
-- log("res,code", res, code)
return res, code
end
m.getTask = function()
-- log("40",40)
local res, code = httpGet(m.server .. "/getTask?" .. "deviceToken=" ..
m.deviceToken, 30,
'Content-Type: application/json')
return res, code
end
-- m.addLog = function(img, info)
-- -- log("48",48)
-- if not m.enabled() then return end
-- local x = cloud_task or {}
-- local data = {
-- id = x.id or 0,
-- level = 'INFO',
-- taskType = x.taskType or '',
-- title = info or '',
-- detail = info or '',
-- imageUrl = img or '',
-- from = x.from or '',
-- name = x.name or '',
-- account = x.account or '',
-- password = x.password or '',
-- server = x.server or '',
-- time = os.date("!%Y-%m-%dT%TZ"),
-- }
-- -- log("data",data)
-- local res, code = httpPost(
-- m.server .. "/addLog?deviceToken=" .. m.deviceToken,
-- JsonEncode(data), 30, 'Content-Type: application/json')
-- -- log("res,code", res, code)
-- return res, code
-- end
-- Standardized log
-- Author: DazeCake
m.addLog = function(log_level, log_title, log_detail, img_url)
-- log("48",48)
if not m.enabled() then return end
local x = cloud_task or {}
local data = {
id = x.id or 0,
level = log_level or 'INFO',
taskType = x.taskType or '',
title = log_title or '',
detail = log_detail or '',
imageUrl = img_url or '',
from = x.from or '',
name = x.name or '',
account = x.account or '',
password = '',
server = x.server or '',
time = os.date("!%Y-%m-%dT%TZ"),
}
-- log("data",data)
local res, code = httpPost(
m.server .. "/addLog?deviceToken=" .. m.deviceToken,
JsonEncode(data), 30, 'Content-Type: application/json')
-- log("res,code", res, code)
return res, code
end
m.uploadImgToInquisition = function(img_path)
local base64Image = getFileBase64(img_path) or ""
local data = {
base64Image = base64Image,
deviceToken = m.deviceToken
}
local res, code = httpPost(m.server .. "/uploadImage", JsonEncode(data), 30,
"Content-Type: application/json")
if code == 200 then
status, data = pcall(JsonDecode, res)
if data.code == 200 then
log("云控日志", "截图上传成功")
return data.data
else
log("云控日志", "截图上传失败")
return ""
end
else
return ""
end
end
m.captcha = function()
if only_use_ttshitu then
return false
end
-- if m.captchaToken == '' or m.captchaServer == '' then
-- return false
-- end
local text_box = findOne("B服安全验证目标字符")
-- log("text_box_右坐标", text_box.bounds.r)
local text_slice_box = findOne("B服安全验证目标字符切片")
-- log("text_slice_box_右坐标", text_slice_box.bounds.r)
local big_image_box = findOne("B服安全验证泛目标图像")
local text_pos = { text_slice_box.bounds.r, text_box.bounds.t, big_image_box.bounds.r, text_box.bounds.b }
log("目标字符坐标", text_pos)
local image_box = findOne("B服安全验证目标图像")
local image_pos = { image_box.bounds.l, image_box.bounds.t, image_box.bounds.r, image_box.bounds.b }
log("图像坐标", image_pos)
local img = getWorkPath() .. "/capture_cloud.jpg"
snapShot(img, text_pos[1], text_pos[2], text_pos[3], text_pos[4])
local text_img_base64 = base64(img)
ssleep(.1)
snapShot(img, image_pos[1], image_pos[2], image_pos[3], image_pos[4])
local image_img_base64 = base64(img)
local data = {
text_base64 = text_img_base64,
image_base64 = image_img_base64,
token = m.captchaToken
}
local res, code = httpPost(m.captchaServer .. "/captcha/select/base64", JsonEncode(data), 30,
"Content-Type: application/json")
if code == 200 then
status, data = pcall(JsonDecode, res)
if data.code == 0 then
cloud_captcha_id = data.data.captcha_id or nil
log("云控打码数量", #data.data.points)
log("云控打码坐标", data.data.points)
for _, coord in pairs(data.data.points) do
x = coord[1] or 0
y = coord[2] or 0
tap({ image_pos[1] + x, image_pos[2] + y })
ssleep(0.3)
end
return true
else
log("云控打码", data.message)
return false
end
else
log("云控打码", "网络错误")
return false
end
end
m.captcha_report = function()
-- if m.captchaToken == '' or m.captchaServer == '' then
-- return false
-- end
if not cloud_captcha_id then
return
end
local data = {
captcha_id = cloud_captcha_id,
token = m.captchaToken
}
local res, code = httpPost(m.captchaServer .. "/captcha/select/report", JsonEncode(data), 30,
"Content-Type: application/json")
cloud_captcha_id = nil
log("云控打码失败上报", res, code)
end
m.FAILTASK_LINEBUSY = 'lineBusy'
m.FAILTASK_ACCOUNTERROR = 'accountError'
m.failTask = function(imageUrl, type)
-- log("73",73)
if not m.getTaskEnabled() then return end
imageUrl = imageUrl or ''
type = type or ''
local res, code = httpPost(m.server .. "/failTask?deviceToken=" ..
m.deviceToken .. "&imageUrl=" ..
encodeUrl(imageUrl) .. "&type=" .. type, '', 30,
'Content-Type: application/json')
return res, code
end
m.completeTask = function(imageUrl)
-- log("84",84)
if not m.getTaskEnabled() then return end
imageUrl = imageUrl or ''
local res, code = httpPost(m.server .. "/completeTask?deviceToken=" ..
m.deviceToken .. "&imageUrl=" ..
encodeUrl(imageUrl), '', 30,
'Content-Type: application/json')
return res, code
end
m.haltComplete = function()
print("停机上报")
local data = { status = m.status, deviceToken = m.deviceToken }
local res, code = httpPost(m.server .. "/haltComplete", JsonEncode(data), 30,
"Content-Type: application/json")
return res, code
end
m.solveTask = function(data) restartSimpleMode(data) end
m.fetchSolveTask = function()
if not m.getTaskEnabled() then return end
while true do
local res, code = m.getTask()
-- log("code", code)
-- log("res", res)
local status, data
status, data = pcall(JsonDecode, res)
log("云控", data)
if type(data) == 'table' and type(data.data) == 'table' and data.code ~= 500 then
m.solveTask(data.data)
end
m.setStatus(1)
ssleep(5)
end
end
m.startHeartBeat = function()
-- log("m.enabled()", m.enabled())
if not m.enabled() then return end
local f = function()
while true do
local res, code = m.heartBeat()
local status, data = pcall(JsonDecode, res)
if data.code == 500 then
m.haltComplete()
log("云控", "停机上报")
-- 子线程不能直接stop 需要使用setTimer延时函数回调stop到主线程
setTimer(stop, 100, "强制停机")
end
ssleep(5)
end
end
m.heartBeatTid = beginThread(f)
end
m.stopHeartBeat = function() stopThread(m.heartBeatTid) end
m.sanReport = function()
log("理智上报", m.enabled())
-- if not m.enabled() then return true end
local p = point["剩余理智"]
local ocrHander = createOcr()
local sanText = ocrText(ocrHander, p[1], p[2], p[3], p[4], "ffffff-a8a8a8") or "0/100"
releaseOcr(ocrHander)
sanText = string.match(sanText, "[%d]+[/][%d]+")
if sanText == "" or sanText == nil then
sanText = "0/100"
end
local index = 1
local san = {}
log("理智", '[' .. sanText .. ']')
for word in string.gmatch(sanText, "%d+") do
san[index] = word
index = index + 1
end
local res, code = httpPost(m.server .. "/sanReport?san=" .. san[1] ..
"&maxSan=" .. san[2] .. "&deviceToken=" ..
m.deviceToken, '', 30,
'Content-Type: application/json')
end
restartSimpleMode = function(data)
if not type(data) == 'table' then return end
if not table.includes({ "daily", "rogue", "sand_fire" }, data.taskType) then return end
local username = data.account
local password = data.password
local server = data.server
local config = data.config
local taskType = data.taskType
-- local x
-- set recommend config over default
-- x = loadOneUIConfig("main")
-- x["fight_ui"] = "jm hd ce ls ap pr"
-- for i = 1, 12 do x["now_job_ui" .. i] = true end
-- x["now_job_ui8"] = false
-- x["crontab_text"] = "4:00 12:00 20:00"
-- saveOneUIConfig("main", x)
--
-- x = loadOneUIConfig("debug")
-- x["max_jmfight_times"] = "1"
-- x["max_login_times_5min"] = "3"
-- x["QQ"] = strOr(config.QQ) .. '#' .. strOr(config.deviceName)
-- x["multi_account_choice_weekday_only"] =
-- strOr(config.weekdayOnly, x["multi_account_choice_weekday_only"])
--
-- x["qqnotify_beforemail"] = true
-- x["qqnotify_afterenter"] = true
-- x["qqnotify_beforeleaving"] = true
-- x["qqnotify_beforemission"] = true
-- x["qqnotify_save"] = true
-- x["collect_beforeleaving"] = true
-- -- 一是完成日常任务,二是间隔时间最长可以11小时,提高容错
-- x["zero_san_after_fight"] = true
-- x["max_drug_times_" .. str(1) .. "day"] = "99"
-- x["max_drug_times_" .. str(2) .. "day"] = "99"
-- x["max_drug_times_" .. str(3) .. "day"] = "1"
-- x["max_drug_times_" .. str(4) .. "day"] = "1"
-- x["max_drug_times_" .. str(5) .. "day"] = "1"
-- x["max_drug_times_" .. str(6) .. "day"] = "1"
-- x["max_drug_times_" .. str(7) .. "day"] = "1"
-- x["enable_log"] = false
-- x["disable_killacc"] = false
-- x["keepalive_interval"] = "900"
-- saveOneUIConfig("debug", x)
--
-- x = loadOneUIConfig("multi_account")
-- x["multi_account_end_closeotherapp"] = true
-- x["multi_account_end_closeapp"] = true
-- x["multi_account_choice"] = "1-30"
-- x["multi_account_enable"] = true
-- saveOneUIConfig("multi_account", x)
-- log("64",64)
-- set task config
-- log("62",61)
-- exit()
if #strOr(username) == 0 or #strOr(password) == 0 then return end
-- log("63",61)
if not table.includes({ 0, 1 }, server) then return end
-- log("64",61)
if not type(config) == 'table' then return end
-- log("65",61)
-- log("65", 64)
local hook = [[
cloud_task=JsonDecode(]] .. string.format("%q", JsonEncode(data)) .. [[);
crontab_enable=false
multi_account_enable=false
username=]] .. string.format("%q", username) .. [[;
password=]] .. string.format("%q", password) .. [[;
server=]] .. server
if taskType == 'rogue' then
hook = hook .. [[;extra_mode="战略前瞻投资"]]
elseif taskType == 'rogue2' then
hook = hook .. [[;extra_mode="水月与深蓝之树"]]
elseif taskType == 'sand_fire' then
hook = hook .. [[;extra_mode="生息演算沙中之火"]]
end
-- log("64",64)
-- log("config",config)
-- exit()
-- 日常
local x
x = get(config, 'daily', 'fight')
if istable(x) then
local y = ''
for _, v in pairs(x) do
if get(v, 'num') == 1 then
y = y .. str(get(v, 'level')) .. ' '
else
y = y .. str(get(v, 'level')) .. 'x' .. str2int(get(v, 'num')) .. ' '
end
end
hook = hook .. [[;fight_ui=]] .. string.format("%q", y)
hook = hook .. [[;now_job_ui2=]] .. str(#y > 0)
end
-- log("65",64)
x = get(config, 'daily', 'sanity', 'drug')
if x then hook = hook .. [[;max_drug_times=]] .. str2int(x) end
x = get(config, 'daily', 'sanity', 'stone')
if x then hook = hook .. [[;max_stone_times=]] .. str2int(x) end
hook = hook .. [[;now_job_ui1=]] .. str(get(config, 'daily', 'mail'))
hook = hook .. [[;now_job_ui3=]] .. str(get(config, 'daily', 'friend'))
hook = hook .. [[;now_job_ui4=]] ..
str(get(config, 'daily', 'infrastructure', 'harvest'))
hook = hook .. [[;now_job_ui5=]] ..
str(get(config, 'daily', 'infrastructure', 'shift'))
hook = hook .. [[;now_job_ui6=]] ..
str(get(config, 'daily', 'infrastructure', 'acceleration'))
hook = hook .. [[;now_job_ui7=]] ..
str(get(config, 'daily', 'infrastructure', 'communication'))
hook = hook .. [[;now_job_ui8=]] ..
str(get(config, 'daily', 'infrastructure', 'deputy'))
hook = hook .. [[;now_job_ui9=]] .. str(get(config, 'daily', 'credit'))
hook = hook .. [[;now_job_ui10=]] ..
str(get(config, 'daily', 'offer', 'enable'))
hook = hook .. [[;now_job_ui11=]] .. str(get(config, 'daily', 'task'))
hook = hook .. [[;now_job_ui12=]] .. str(get(config, 'daily', 'activity'))
--审判庭配置提前写在这里里,如果需要对接审判庭,青在daily属性中添加shopping
local shopping_cloud_switch = get(config, 'daily', 'shopping')
local main_config = loadOneUIConfig("main")
local shopping_ui_switch = main_config["now_job_ui13"]
--审判庭云控不存在则使用本地配置
shopping_ui_switch = (shopping_cloud_switch == nil) and shopping_ui_switch or str(shopping_cloud_switch)
hook = hook .. [[;now_job_ui13=]] .. str(shopping_ui_switch)
hook = hook .. [[;auto_recruit0=]] ..
str(get(config, 'daily', 'offer', 'other'))
hook = hook .. [[;auto_recruit1=]] ..
str(get(config, 'daily', 'offer', 'car'))
hook = hook .. [[;auto_recruit4=]] ..
str(get(config, 'daily', 'offer', 'star4'))
hook = hook .. [[;auto_recruit5=]] ..
str(get(config, 'daily', 'offer', 'star5'))
hook = hook .. [[;auto_recruit6=]] ..
str(get(config, 'daily', 'offer', 'star6'))
-- 肉鸽
hook = hook .. [[;zl_best_operator=]] ..
str2int(get(config, 'rogue', 'operator', 'index'))
hook = hook .. [[;zl_skill_times=]] ..
str2int(get(config, 'rogue', 'operator', 'num'))
hook = hook .. [[;zl_skill_idx=]] ..
str2int(get(config, 'rogue', 'operator', 'skill'))
hook = hook .. [[;zl_max_coin=]] .. str2int(get(config, 'rogue', 'coin'))
hook = hook .. [[;zl_max_level=]] .. str2int(get(config, 'rogue', 'level'))
hook = hook .. [[;zl_more_repertoire=false]]
hook = hook .. [[;zl_more_experience=true]]
hook = hook .. [[;zl_skip_coin=]] .. str(get(config, 'rogue', 'skip', 'coin'))
hook = hook .. [[;zl_skip_hard=]] ..
str(get(config, 'rogue', 'skip', 'beast'))
hook = hook .. [[;zl_no_waste=]] ..
str(not get(config, 'rogue', 'skip', 'daily'))
hook = hook .. [[;zl_accept_mg=]] ..
str(not get(config, 'rogue', 'skip', 'sensitive'))
hook = hook .. [[;zl_accept_yx=]] ..
str(not get(config, 'rogue', 'skip', 'illusion'))
hook = hook .. [[;zl_accept_sc=]] ..
str(not get(config, 'rogue', 'skip', 'survive'))
-- --- TODO debug
-- for i = 1,12 do
-- hook = hook .. [[;now_job_ui]]..i .. [[=false]]
-- end
-- ---
hook = hook .. [[;saveConfig("restart_mode_hook",]] ..
string.format("%q", hook) .. ')'
log("hook", hook)
-- ssleep(1000)
saveConfig("hideUIOnce", "true")
saveConfig("restart_mode_hook", hook)
restartPackage()
end