Skip to content

Commit

Permalink
2.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
JadlionHD committed Jan 24, 2025
1 parent 21d169c commit f3f64d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ crate-type = ["cdylib"]

[dependencies]
rusty_enet = { git = "/~https://github.com/JadlionHD/rusty_enet.git" }
# rusty_enet = { path = "D:\\Projects\\NodeJS_Projects\\StileDevs\\rusty_enet" }
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.12.2", default-features = false, features = ["napi4"] }
napi-derive = "2.12.2"
Expand Down
21 changes: 7 additions & 14 deletions __test__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ const { Client } = require("../dist/index.js");
const server = new Client({
enet: {
useNewPacket: {
asServer: true
asServer: false,
asClient: false
}
}
});

// server.connect("0.0.0.0", 17091);
// server.host.disconnectNow(0);

server.on("connect", (netID) => {
console.log("Connected ", netID);
server.send(netID, 0, TextPacket.from(0x1));
Expand All @@ -39,7 +43,6 @@ server.listen();

await item.decode();
await item.encode();
console.log(server.host.port);
})();

async function Web() {
Expand Down Expand Up @@ -67,9 +70,9 @@ async function Web() {
let str = "";

str += `server|127.0.0.1\n`;
// str += `type2|1\n`;

const randPort = 17091;
str += `port|${randPort}\nloginurl|login.growserver.app:8080\ntype|1\n#maint|test\nmeta|ignoremeta\nRTENDMARKERBS1001`;
str += `port|17091\nloginurl|login.growserver.app:8080\ntype|1\n#maint|test\nmeta|ignoremeta\nRTENDMARKERBS1001`;

return ctx.body(str);
});
Expand Down Expand Up @@ -98,16 +101,6 @@ async function Web() {
return ctx.html(html);
});

serve(
{
fetch: app.fetch,
port: 80
},
(info) => {
console.log(`⛅ Running HTTP server on http://localhost`);
}
);

serve(
{
fetch: app.fetch,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "growtopia.js",
"description": "A Rust based, cross-platform, high-performance Growtopia private server framework utilizing Node.js, Bun.js.",
"version": "2.0.9",
"version": "2.0.10",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
21 changes: 13 additions & 8 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ use std::{net::SocketAddr, net::UdpSocket};
pub struct Host {
host: enet::Host<UdpSocket>,
emitter: Option<Ref<()>>,
ip_address: String,
port: u16,
using_new_packet: bool,
}

#[napi]
Expand All @@ -30,7 +27,11 @@ impl Host {
let host_addr: String = format!("{ip_address}:{port}");

let socket = if using_new_packet {
UdpSocket::bind(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0))).unwrap()
UdpSocket::bind(SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::UNSPECIFIED,
port,
)))
.unwrap()
} else {
UdpSocket::bind(SocketAddr::from_str(&host_addr).unwrap()).unwrap()
};
Expand All @@ -52,9 +53,6 @@ impl Host {
Host {
host,
emitter: None,
ip_address,
port,
using_new_packet,
}
}

Expand Down Expand Up @@ -102,6 +100,12 @@ impl Host {
format!("Failed to set 'ip': {:?}", err),
));
}
if let Err(err) = js_peer.set("state", peer.state() as u8) {
return Err(Error::new(
Status::GenericFailure,
format!("Failed to set 'ip': {:?}", err),
));
}

Ok(js_peer)
} else {
Expand Down Expand Up @@ -237,10 +241,11 @@ impl Host {
},
Ok(None) => {}
Err(e) if e.kind() == std::io::ErrorKind::ConnectionReset => {
// eprintln!("Connection reset. Retrying...");
// eprintln!("Connection reset: {:?}", e);
// ignore
}
Err(e) => {
// eprintln!("Error connection: {:?}", e);
return Err(Error::new(
Status::GenericFailure,
format!("ENet service error: {}", e),
Expand Down

0 comments on commit f3f64d7

Please sign in to comment.