1
This commit is contained in:
parent
91f03316a2
commit
3aa216f5f2
@ -1,5 +1,6 @@
|
|||||||
const axios = require('axios').default;
|
const axios = require('axios').default;
|
||||||
const protobuf = require('protobufjs');
|
const ws = require('nodejs-websocket');
|
||||||
|
const ClientNet = require('./clientnet');
|
||||||
|
|
||||||
function get(url, params) {
|
function get(url, params) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@ -24,20 +25,36 @@ function get(url, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
const fiendMsg = await protobuf.load('proto/friend/cs_proto.proto');
|
let loginData = null;
|
||||||
const fiendMsgId = await protobuf.load('proto/friend/cs_msgid.proto');
|
//console.log(err, root);
|
||||||
console.log(friendMsg, friendMsgId);
|
{
|
||||||
const {err, response} = await get(
|
const {err, response} = await get(
|
||||||
'https://login-z2-test.cebg.games/webapp/index.php',
|
'https://login-z2-test.cebg.games/webapp/index.php',
|
||||||
{
|
{
|
||||||
'c': 'Login',
|
'c': 'Login',
|
||||||
'a': 'auth',
|
'a': 'auth',
|
||||||
'gameid': 2006,
|
'gameid': 2006,
|
||||||
'channel': 6513,
|
'channel': 6513,
|
||||||
'account': '123456',
|
'account': '123456',
|
||||||
'openid': '123456'
|
'openid': '123456'
|
||||||
|
});
|
||||||
|
loginData = response;
|
||||||
|
console.log(loginData);
|
||||||
|
}
|
||||||
|
const clientNet = new ClientNet(
|
||||||
|
'wss://relation-test.kingsome.cn/friend/websocket',
|
||||||
|
'proto/friend/cs_proto.proto',
|
||||||
|
'proto/friend/cs_msgid.proto'
|
||||||
|
);
|
||||||
|
await clientNet.init();
|
||||||
|
await clientNet.connect();
|
||||||
|
clientNet.on('connect', () => {
|
||||||
|
console.log('onConnect');
|
||||||
|
clientNet.sendMsg('CMLogin', {
|
||||||
|
accountId: loginData['account_id'],
|
||||||
|
sessionId: loginData['session_id'],
|
||||||
});
|
});
|
||||||
console.log(err, response);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
88
scripts/check_server/clientnet.js
Normal file
88
scripts/check_server/clientnet.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
const protobuf = require('protobufjs');
|
||||||
|
const ws = require('nodejs-websocket');
|
||||||
|
|
||||||
|
class ClientNet {
|
||||||
|
|
||||||
|
constructor(url, protoPbFile, msgIdPbFile) {
|
||||||
|
this.url = url;
|
||||||
|
this.conn = null;
|
||||||
|
this.protoPbFile = protoPbFile;
|
||||||
|
this.msgIdPbFile = msgIdPbFile;
|
||||||
|
this.protoPb = null;
|
||||||
|
this.msgIdPb = null;
|
||||||
|
this.cmMsgId = null;
|
||||||
|
this.smMsgId = null;
|
||||||
|
this.recvBuf = Buffer.alloc(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
{
|
||||||
|
const {err, root} = await protobuf.load(this.protoPbFile);
|
||||||
|
this.protoPb = root;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const {err, root} = await protobuf.load(this.msgIdPbFile);
|
||||||
|
this.msgIdPb = root;
|
||||||
|
this.cmMsgId = this.msgIdPb.lookup('CMMessageId_e');
|
||||||
|
this.smMsgId = this.msgIdPb.lookup('SMMessageId_e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async connect() {
|
||||||
|
this.conn = await ws.connect(this.url);
|
||||||
|
this.on('binary', this.#onReceive.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
async #onReceive(inStream) {
|
||||||
|
inStream.on('readable', async () => {
|
||||||
|
console.log('inStream.readable');
|
||||||
|
const newData = inStream.read();
|
||||||
|
if (newData) {
|
||||||
|
this.recvBuf = Buffer.concat([this.recvBuf, newData]);
|
||||||
|
await this.#onParsePacket();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
inStream.on('end', () => {
|
||||||
|
console.log('inStream.end', this.recvBuf.length);
|
||||||
|
});
|
||||||
|
inStream.on('close', () => {
|
||||||
|
console.log('inStream.close');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async #onParsePacket() {
|
||||||
|
while (this.recvBuf.length > 12) {
|
||||||
|
const msgSize = this.recvBuf.readUInt16LE(0);
|
||||||
|
const msgId = this.recvBuf.readUInt16LE(2);
|
||||||
|
const seqId = this.recvBuf.readUInt32LE(4);
|
||||||
|
const magicCode = this.recvBuf.readUInt16LE(8);
|
||||||
|
const ext = this.recvBuf.readUInt16LE(10);
|
||||||
|
if (this.recvBuf.length >= 12 + msgSize) {
|
||||||
|
this.recvBuf = this.recvBuf.slice(12 + msgSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
on(eventName, cb) {
|
||||||
|
this.conn.on(eventName, cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendMsg(name, msg) {
|
||||||
|
const msgType = this.protoPb.lookupType(name);
|
||||||
|
const msgId = this.cmMsgId.values['_' + name];
|
||||||
|
const msgPb = msgType.create(msg);
|
||||||
|
|
||||||
|
const msgBuf = msgType.encode(msg).finish();
|
||||||
|
let buf = Buffer.alloc(12);
|
||||||
|
buf.writeInt16LE(msgBuf.length, 0);
|
||||||
|
buf.writeInt16LE(msgId, 2);
|
||||||
|
buf.writeInt32LE(0, 4);
|
||||||
|
buf.writeUInt8('K'.charCodeAt(0), 8);
|
||||||
|
buf.writeUInt8('S'.charCodeAt(0), 9);
|
||||||
|
buf.writeInt16LE(0, 10);
|
||||||
|
this.conn.sendBinary(Buffer.concat([buf, msgBuf]));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ClientNet;
|
14
scripts/check_server/package-lock.json
generated
14
scripts/check_server/package-lock.json
generated
@ -9,6 +9,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.0",
|
"axios": "^0.27.0",
|
||||||
|
"nodejs-websocket": "^1.7.2",
|
||||||
"protobufjs": "^6.11.2"
|
"protobufjs": "^6.11.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -165,6 +166,14 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/nodejs-websocket": {
|
||||||
|
"version": "1.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodejs-websocket/-/nodejs-websocket-1.7.2.tgz",
|
||||||
|
"integrity": "sha512-PFX6ypJcCNDs7obRellR0DGTebfUhw1SXGKe2zpB+Ng1DQJhdzbzx1ob+AvJCLzy2TJF4r8cCDqMQqei1CZdPQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/protobufjs": {
|
"node_modules/protobufjs": {
|
||||||
"version": "6.11.2",
|
"version": "6.11.2",
|
||||||
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.2.tgz",
|
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.2.tgz",
|
||||||
@ -316,6 +325,11 @@
|
|||||||
"mime-db": "1.52.0"
|
"mime-db": "1.52.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nodejs-websocket": {
|
||||||
|
"version": "1.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodejs-websocket/-/nodejs-websocket-1.7.2.tgz",
|
||||||
|
"integrity": "sha512-PFX6ypJcCNDs7obRellR0DGTebfUhw1SXGKe2zpB+Ng1DQJhdzbzx1ob+AvJCLzy2TJF4r8cCDqMQqei1CZdPQ=="
|
||||||
|
},
|
||||||
"protobufjs": {
|
"protobufjs": {
|
||||||
"version": "6.11.2",
|
"version": "6.11.2",
|
||||||
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.2.tgz",
|
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.11.2.tgz",
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"scripts": {},
|
"scripts": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.0",
|
"axios": "^0.27.0",
|
||||||
|
"nodejs-websocket": "^1.7.2",
|
||||||
"protobufjs": "^6.11.2"
|
"protobufjs": "^6.11.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user