109 lines
2.8 KiB
JavaScript
109 lines
2.8 KiB
JavaScript
const net = require("net");
|
|
const { Stick, MaxBodyLen } = require("./lib/stick");
|
|
const port = 4999;
|
|
const host = "192.168.100.83";
|
|
const { Message } = require("./Message");
|
|
|
|
const stick = new Stick(1024);
|
|
stick.setMaxBodyLen(MaxBodyLen["32K"], true);
|
|
|
|
var client = new net.Socket();
|
|
var game;
|
|
|
|
client.connect(port, host, function () {
|
|
console.log("Connected");
|
|
let param = {
|
|
serial: 123456,
|
|
route: "gate.gateHandler.queryEntry",
|
|
params: {
|
|
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
|
|
},
|
|
};
|
|
client.write(stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param)));
|
|
});
|
|
|
|
client.on("data", function (data) {
|
|
client.destroy(); // kill client after server's response
|
|
stick.putData(data);
|
|
});
|
|
|
|
client.on("error", function (error) {
|
|
console.log("Error: " + error);
|
|
});
|
|
|
|
client.on("close", function () {
|
|
console.log("Connection closed");
|
|
});
|
|
|
|
stick.onBody((msgId, data) => {
|
|
const len = data.readUInt16LE(0);
|
|
const buf1 = data.subarray(2, 2 + len);
|
|
const msg = JSON.parse(buf1);
|
|
console.log(msgId, msg);
|
|
data = JSON.parse(buf1);
|
|
setTimeout(() => {
|
|
const stick = new Stick(1024);
|
|
stick.setMaxBodyLen(MaxBodyLen["32K"], true);
|
|
game = new net.Socket();
|
|
let step = 0;
|
|
game.connect(data.port, data.host, function () {
|
|
console.log("Connected");
|
|
let param = {
|
|
serial: 123457,
|
|
route: "connector.entryHandler.entry",
|
|
params: {
|
|
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
|
|
},
|
|
};
|
|
|
|
game.write(stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param)));
|
|
});
|
|
|
|
game.on("error", function (error) {
|
|
console.log("Error: " + error);
|
|
});
|
|
game.on("close", function () {
|
|
console.log("Connection closed");
|
|
});
|
|
game.on("data", function (data) {
|
|
stick.putData(data);
|
|
});
|
|
|
|
stick.onBody((msgId, data) => {
|
|
const len = data.readUInt16LE(0);
|
|
const buf1 = data.subarray(2, 2 + len);
|
|
const msg = JSON.parse(buf1);
|
|
|
|
console.log(msgId, msg);
|
|
switch (step) {
|
|
case 0:
|
|
let param = {
|
|
serial: 123457,
|
|
route: "chat.chatHandler.joinWorldChannel",
|
|
params: {
|
|
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
|
|
},
|
|
};
|
|
game.write(
|
|
stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param))
|
|
);
|
|
step++;
|
|
break;
|
|
case 1:
|
|
let param1 = {
|
|
serial: 123457,
|
|
route: "chat.chatHandler.worldChat",
|
|
params: {
|
|
content: "test world message",
|
|
},
|
|
};
|
|
game.write(
|
|
stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param1))
|
|
);
|
|
step++;
|
|
break;
|
|
}
|
|
});
|
|
}, 1000);
|
|
});
|