mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Logging changes, fixed sending larger datagrams than necessary
This commit is contained in:
parent
70e6f1efa9
commit
ca80f1ac60
6 changed files with 43 additions and 17 deletions
|
@ -21,7 +21,7 @@ end
|
||||||
|
|
||||||
function net.init()
|
function net.init()
|
||||||
local ready = false
|
local ready = false
|
||||||
net.sock = pollnet.open_ws("ws://127.0.0.1:41251")
|
net.sock = pollnet.open_ws("ws://127.0.0.1:21251")
|
||||||
reactor:run(function()
|
reactor:run(function()
|
||||||
local sock = net.sock
|
local sock = net.sock
|
||||||
--poll_until_open(sock)
|
--poll_until_open(sock)
|
||||||
|
|
|
@ -11,7 +11,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tungstenite = "0.21.0"
|
tungstenite = "0.21.0"
|
||||||
eframe = { version="0.27.2", features = ["persistence", "glow", "default_fonts"], default_features = false }
|
eframe = { version="0.27.2", features = ["persistence", "glow", "default_fonts"], default_features = false }
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tangled = { path = "tangled" }
|
tangled = { path = "tangled" }
|
||||||
serde = { version = "1.0.199", features = ["serde_derive"] }
|
serde = { version = "1.0.199", features = ["serde_derive"] }
|
||||||
|
|
|
@ -89,7 +89,7 @@ impl NetManager {
|
||||||
pub fn start(self: Arc<NetManager>) {
|
pub fn start(self: Arc<NetManager>) {
|
||||||
info!("Starting netmanager");
|
info!("Starting netmanager");
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let local_server = TcpListener::bind("127.0.0.1:41251").unwrap();
|
let local_server = TcpListener::bind("127.0.0.1:21251").unwrap();
|
||||||
// let local_server = TcpListener::bind("127.0.0.1:0").unwrap();
|
// let local_server = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||||
local_server
|
local_server
|
||||||
.set_nonblocking(true)
|
.set_nonblocking(true)
|
||||||
|
@ -288,15 +288,23 @@ impl eframe::App for App {
|
||||||
.local_connected
|
.local_connected
|
||||||
.load(std::sync::atomic::Ordering::Relaxed);
|
.load(std::sync::atomic::Ordering::Relaxed);
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
if accept_local {
|
if accept_local {
|
||||||
if local_connected {
|
if local_connected {
|
||||||
ui.colored_label(Color32::GREEN, "Local Noita instance connected");
|
ui.colored_label(Color32::GREEN, "Local Noita instance connected");
|
||||||
|
} else {
|
||||||
|
ui.colored_label(Color32::YELLOW, "Awaiting Noita connection. It's time to start new game in Noita now!");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ui.colored_label(Color32::YELLOW, "Awaiting Noita connection. It's time to start new game in Noita now!");
|
ui.label("Not yet ready");
|
||||||
}
|
}
|
||||||
} else {
|
ui.separator();
|
||||||
ui.label("Not yet ready");
|
ui.heading("Current users");
|
||||||
}});
|
for peer in netman.peer.iter_peer_ids() {
|
||||||
|
ui.label(peer.0.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.label(format!("Peer state: {}", netman.peer.state()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
use eframe::NativeOptions;
|
use eframe::NativeOptions;
|
||||||
use noita_proxy::App;
|
use noita_proxy::App;
|
||||||
|
use tracing::level_filters::LevelFilter;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
fn main() -> Result<(), eframe::Error> {
|
fn main() -> Result<(), eframe::Error> {
|
||||||
let my_subscriber = tracing_subscriber::FmtSubscriber::new();
|
let my_subscriber = tracing_subscriber::FmtSubscriber::builder()
|
||||||
|
.with_env_filter(
|
||||||
|
EnvFilter::builder()
|
||||||
|
.with_default_directive(LevelFilter::INFO.into())
|
||||||
|
.from_env_lossy(),
|
||||||
|
)
|
||||||
|
.finish();
|
||||||
tracing::subscriber::set_global_default(my_subscriber).expect("setting tracing default failed");
|
tracing::subscriber::set_global_default(my_subscriber).expect("setting tracing default failed");
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"Noita Proxy",
|
"Noita Proxy",
|
||||||
|
|
|
@ -84,6 +84,16 @@ pub enum PeerState {
|
||||||
Disconnected,
|
Disconnected,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for PeerState {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
PeerState::PendingConnection => write!(f, "Connection pending..."),
|
||||||
|
PeerState::Connected => write!(f, "Connected"),
|
||||||
|
PeerState::Disconnected => write!(f, "Disconnected"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Channel<T> = (Sender<T>, Receiver<T>);
|
type Channel<T> = (Sender<T>, Receiver<T>);
|
||||||
|
|
||||||
/// Represents a network endpoint. Can be constructed in either `host` or `client` mode.
|
/// Represents a network endpoint. Can be constructed in either `host` or `client` mode.
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub struct Settings {
|
||||||
/// Default: 1 second.
|
/// Default: 1 second.
|
||||||
pub confirm_max_period: Duration,
|
pub confirm_max_period: Duration,
|
||||||
/// Peers will be disconnected after this much time without any datagrams from them has passed.
|
/// Peers will be disconnected after this much time without any datagrams from them has passed.
|
||||||
/// Default: 1 second.
|
/// Default: 10 seconds.
|
||||||
pub connection_timeout: Duration,
|
pub connection_timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,11 +139,9 @@ impl TryFrom<&NetMessageVariant> for Datagram {
|
||||||
fn try_from(value: &NetMessageVariant) -> Result<Self, Self::Error> {
|
fn try_from(value: &NetMessageVariant) -> Result<Self, Self::Error> {
|
||||||
let mut data = Cursor::new([0; DATAGRAM_MAX_LEN]);
|
let mut data = Cursor::new([0; DATAGRAM_MAX_LEN]);
|
||||||
bincode::serialize_into(&mut data, value)?;
|
bincode::serialize_into(&mut data, value)?;
|
||||||
|
let size = data.position().try_into().unwrap();
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
Ok(Datagram {
|
Ok(Datagram { data, size })
|
||||||
data,
|
|
||||||
size: data.len(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,8 +532,9 @@ impl Reactor {
|
||||||
continue 'peers;
|
continue 'peers;
|
||||||
}
|
}
|
||||||
peer.resend_pending.push_back((resend_in, msg.clone()));
|
peer.resend_pending.push_back((resend_in, msg.clone()));
|
||||||
trace!("Sent {:?} to {}", msg, peer.addr);
|
trace!("Sent {:?} to {}", msg, peer.addr,);
|
||||||
let datagram = Datagram::try_from(&NetMessageVariant::Normal(msg)).unwrap();
|
let datagram = Datagram::try_from(&NetMessageVariant::Normal(msg)).unwrap();
|
||||||
|
trace!("size: {}", datagram.size);
|
||||||
self.shared
|
self.shared
|
||||||
.socket
|
.socket
|
||||||
.send_to(&datagram.data[..datagram.size], peer.addr)
|
.send_to(&datagram.data[..datagram.size], peer.addr)
|
||||||
|
@ -554,6 +553,7 @@ impl Reactor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let datagram = Datagram::try_from(&msg).unwrap();
|
let datagram = Datagram::try_from(&msg).unwrap();
|
||||||
|
trace!("sent msg size: {}", datagram.size);
|
||||||
self.shared
|
self.shared
|
||||||
.socket
|
.socket
|
||||||
.send_to(&datagram.data[..datagram.size], peer.addr)
|
.send_to(&datagram.data[..datagram.size], peer.addr)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue