190 lines
4.5 KiB
JavaScript
190 lines
4.5 KiB
JavaScript
const axios = require('axios').default;
|
|
const ClientNet = require('./clientnet');
|
|
|
|
function httpGet(url, params) {
|
|
return new Promise((resolve) => {
|
|
const ret = {
|
|
err: null,
|
|
response: null,
|
|
};
|
|
axios({
|
|
method: 'get',
|
|
url: url,
|
|
timeout: 1000 * 3,
|
|
params: params,
|
|
responseType: 'text'
|
|
}).then((response) => {
|
|
ret.response = response.data;
|
|
resolve(ret);
|
|
}).catch((error) => {
|
|
ret.err = error;
|
|
resolve(ret);
|
|
});
|
|
});
|
|
}
|
|
|
|
class TestCase {
|
|
|
|
constructor(urls) {
|
|
this.urls = urls;
|
|
this.loginData = '';
|
|
this.relationWs = new ClientNet(
|
|
this.urls['relation'],
|
|
'proto/friend/cs_proto.proto',
|
|
'proto/friend/cs_msgid.proto'
|
|
);
|
|
console.log(this.urls['game2006']);
|
|
this.battleWs = new ClientNet(
|
|
this.urls['game2006'],
|
|
'proto/battle/cs_proto.proto',
|
|
'proto/battle/cs_msgid.proto'
|
|
);
|
|
}
|
|
|
|
async init() {
|
|
await this.step1();
|
|
await this.step2();
|
|
await this.step3();
|
|
await this.step4();
|
|
await this.step5();
|
|
await this.step6();
|
|
await this.step7();
|
|
await this.step8();
|
|
await this.step9();
|
|
await this.step10();
|
|
await this.step11();
|
|
}
|
|
|
|
async step1() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['login'] + '/webapp/index.php',
|
|
{
|
|
'c': 'Login',
|
|
'a': 'auth',
|
|
'gameid': 2006,
|
|
'channel': 6513,
|
|
'account': '123456',
|
|
'openid': '123456'
|
|
});
|
|
this.loginData = response;
|
|
console.log('login auth@Login', String(err), response);
|
|
}
|
|
|
|
async step2() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['cloud'] + '/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'selfChecking',
|
|
});
|
|
console.log('cloud selfChecking@Ops', String(err), response);
|
|
}
|
|
|
|
async step3() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['service'] + '/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'selfChecking',
|
|
});
|
|
console.log('service selfChecking@Ops', String(err), response);
|
|
}
|
|
|
|
async step4() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['gamelog'] + '/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'selfChecking',
|
|
});
|
|
console.log('gamelog selfChecking@Ops', String(err), response);
|
|
}
|
|
|
|
async step5() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['mail'] + '/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'selfChecking',
|
|
});
|
|
console.log('mail selfChecking@Ops', String(err), response);
|
|
}
|
|
|
|
async step6() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['game2006api'] + '/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'selfChecking',
|
|
});
|
|
console.log('game2006api selfChecking@Ops', String(err), response);
|
|
}
|
|
|
|
async step7() {
|
|
await this.relationWs.init();
|
|
await this.relationWs.connect();
|
|
this.relationWs.on('connect', () => {
|
|
console.log('relation onConnect');
|
|
this.relationWs.registerMsgHandle('SMLogin', (msg) => {
|
|
console.log(msg);
|
|
});
|
|
this.relationWs.sendMsg('CMLogin', {
|
|
accountId: this.loginData['account_id'],
|
|
sessionId: this.loginData['session_id'],
|
|
});
|
|
});
|
|
}
|
|
|
|
async step8() {
|
|
await this.battleWs.init();
|
|
await this.battleWs.connect();
|
|
this.battleWs.on('connect', () => {
|
|
console.log('battle onConnect');
|
|
this.battleWs.registerMsgHandle('SMJoinedNotify', (msg) => {
|
|
console.log(msg);
|
|
});
|
|
this.battleWs.sendMsg('CMJoin', {
|
|
accountId: this.loginData['account_id'],
|
|
sessionId: this.loginData['session_id'],
|
|
});
|
|
});
|
|
}
|
|
|
|
async step9() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['game2006'].replace('wss://', 'https://').
|
|
replace('ws://', 'https://') +
|
|
'/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'getNodeId',
|
|
});
|
|
console.log('game2006 getNodeId@Ops', String(err), response);
|
|
}
|
|
|
|
async step10() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['game2006-n1'].replace('wss://', 'https://').
|
|
replace('ws://', 'https://') +
|
|
'/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'getNodeId',
|
|
});
|
|
console.log('game2006-n1 getNodeId@Ops', String(err), response);
|
|
}
|
|
|
|
async step11() {
|
|
const {err, response} = await httpGet(
|
|
this.urls['stat'] + '/webapp/index.php',
|
|
{
|
|
'c': 'Ops',
|
|
'a': 'selfChecking',
|
|
});
|
|
console.log('stat selfChecking@Ops', String(err), response);
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = TestCase;
|