gpt4 book ai didi

java - 数据包从 Game Maker 到 Node,js 不分离

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:38 25 4
gpt4 key购买 nike

这可能有点长,因为我需要解释一下。

我有一大块数据从 Game Maker 客户端发送到 i Node 服务器应用程序,来自客户端的数据正在像这样组装:

//argument0: socket
//argument1: buffer of data

//init
var packetSize = buffer_tell(argument1);
var bufPacket = buffer_create(1, buffer_grow, 1);
//write size, packet into new one
buffer_write(bufPacket, buffer_u8, packetSize + 1);
buffer_copy(argument1, 0, packetSize, bufPacket, 1);
buffer_seek(bufPacket, 0, packetSize + 1);

//send packet
network_send_raw(argument0, bufPacket, buffer_tell(bufPacket));
// destry buffers
buffer_delete(argument1);
buffer_delete(bufPacket);

并从此发送:

 var register_packet = buffer_create(1, buffer_grow, 1);
buffer_write(register_packet, buffer_string, "register");
buffer_write(register_packet, buffer_string, txt_Username.text);
buffer_write(register_packet, buffer_string, txt_Password.text);
network_write(Network.socket, register_packet);

它被解释为:解释:loginassasa应该在哪里解释:login ass asa

解析器代码是:

parse: function(c, data) {
var idx = 0;
while (idx < data.length) {
var packetSize = data.readUInt8(idx);
var extractedPacket = new Buffer(packetSize);
data.copy(extractedPacket, 0, idx, idx + packetSize);
this.interpret(c, extractedPacket);
idx += packetSize;
}
}

和解释函数:

interpret: function(c, datapacket){
var header = PacketModels.header.parse(datapacket);
console.log("Interpret: " + header.command);
switch (header.command.toUpperCase()){
case "LOGIN":
var data = PacketModels.login.parse(datapacket);
User.login(data.username, data.password, function(result, user){
console.log('Login result: ' + result)
if(result){
c.user = user;
c.enterroom(c.user.current_room);
c.socket.write(packet.build(["LOGIN", "TRUE", c.user.current_room, c.user.pos_x, c.user.pos_y, c.user.username]))
}else{
c.socket.write(packet.build(["LOGIN", "FALSE"]))
}
});
break;
case "REGISTER":
var data = PacketModels.register.parse(datapacket);
User.register(data.username, data.password, function(result){
if(result){
c.socket.write(packet.build(["REGISTER", "TRUE"]))
}else{
c.socket.write(packet.build(["REGISTER", "FALSE"]))
}
});
break;
}

它不会删除标题命令以使大小写切换起作用,不太确定为什么失败,我在本地计算机上工作得像一个魅力,但现在我正在尝试转移到 digital ocean 云服务器,它似乎无法分解数据包,任何帮助都会很棒。提前致谢,杰夫

最佳答案

事实证明,我从来没有真正能够解决这个问题,经过几天的故障排除,服务器似乎没有以预期的格式接收数据包,因为这个项目是我自己的,与客户端无关,我不得不把它放在一边并继续。我希望有一天能够恢复这个项目。

关于java - 数据包从 Game Maker 到 Node,js 不分离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27977546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com