-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpow.js
More file actions
51 lines (43 loc) · 1.32 KB
/
pow.js
File metadata and controls
51 lines (43 loc) · 1.32 KB
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
'use strict';
require('console-stamp')(console, 'yyyy/mm/dd HH:MM:ss');
const cp = require('child_process');
const request = require('request-promise');
const zlib = require('zlib');
const bl = require('bl');
const api = require('./msaapi').api;
const getRequestOptions = require('./msaapi').getRequestOptions;
const affiliation = process.argv[2];
const job = (str, option) => {
return cp.execSync(str, { cwd: __dirname }).toString();
};
function start_pow() {
job(`/bin/bash utils/pow_restart.sh ${affiliation}`);
resume_pow();
}
function resume_pow() {
request(getRequestOptions(api.pow.top, {}))
.pipe(zlib.createGunzip())
.pipe(bl(function(err, data) {
data = JSON.parse(data.toString());
if (data.response.error_code != 0) {
console.log(`ERROR`);
return;
}
console.log(data.pow);
const { pow: { stage_type, stage_no }, user: { stamina } } = data;
console.log(`stage_types=${stage_type}, current_stage=${stage_no}`);
for (let i=parseInt(stage_no); i<=10; ++i) {
console.log(`next stage type=${stage_type[i-1]}`);
winOnePow(stage_type[i-1]);
}
}));
}
function winOnePow(type) {
job(`/bin/bash utils/pow_start.sh ${type}`);
job(`/bin/bash utils/pow_rescue.sh`);
}
if (affiliation === '-1') {
resume_pow();
} else {
start_pow();
}