mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Proxy updates
This commit is contained in:
parent
c98a74dc17
commit
414e775e61
8 changed files with 66 additions and 10 deletions
|
@ -27,6 +27,10 @@ function net_handling.proxy.peer_id(_, value)
|
||||||
ctx.is_host = ctx.my_id == ctx.host_id
|
ctx.is_host = ctx.my_id == ctx.host_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function net_handling.proxy.debug(_, value)
|
||||||
|
ctx.debug = value == "true"
|
||||||
|
end
|
||||||
|
|
||||||
function net_handling.mod.player(peer_id, value)
|
function net_handling.mod.player(peer_id, value)
|
||||||
local input_data = value.i
|
local input_data = value.i
|
||||||
local pos_data = value.p
|
local pos_data = value.p
|
||||||
|
|
17
init.lua
17
init.lua
|
@ -128,11 +128,13 @@ function OnPlayerSpawned( player_entity ) -- This runs when player entity has be
|
||||||
|
|
||||||
EntityAddComponent2(player_entity, "LuaComponent", {script_wand_fired = "mods/quant.ew/files/cbs/count_times_wand_fired.lua"})
|
EntityAddComponent2(player_entity, "LuaComponent", {script_wand_fired = "mods/quant.ew/files/cbs/count_times_wand_fired.lua"})
|
||||||
|
|
||||||
dofile_once("data/scripts/perks/perk.lua")
|
if ctx.debug then
|
||||||
local x, y = EntityGetFirstHitboxCenter(player_entity)
|
dofile_once("data/scripts/perks/perk.lua")
|
||||||
perk_spawn(x, y, "LASER_AIM", true)
|
local x, y = EntityGetFirstHitboxCenter(player_entity)
|
||||||
perk_spawn(x-50, y, "GLASS_CANNON", true)
|
perk_spawn(x, y, "LASER_AIM", true)
|
||||||
perk_spawn(x-25, y, "EDIT_WANDS_EVERYWHERE", true)
|
perk_spawn(x-50, y, "GLASS_CANNON", true)
|
||||||
|
perk_spawn(x-25, y, "EDIT_WANDS_EVERYWHERE", true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_world_pre_update_inner()
|
local function on_world_pre_update_inner()
|
||||||
|
@ -154,6 +156,11 @@ local function on_world_pre_update_inner()
|
||||||
if hp == 0 then
|
if hp == 0 then
|
||||||
EntityInflictDamage(my_player.entity, 10000000, "DAMAGE_CURSE", "Out of shared health", "NONE", 0, 0, GameGetWorldStateEntity())
|
EntityInflictDamage(my_player.entity, 10000000, "DAMAGE_CURSE", "Out of shared health", "NONE", 0, 0, GameGetWorldStateEntity())
|
||||||
end
|
end
|
||||||
|
if not ctx.run_ended then
|
||||||
|
GamePrint("Notifying of run end")
|
||||||
|
net.proxy_notify_game_over()
|
||||||
|
ctx.run_ended = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Item sync
|
-- Item sync
|
||||||
|
|
1
noita-proxy/Cargo.lock
generated
1
noita-proxy/Cargo.lock
generated
|
@ -1227,6 +1227,7 @@ dependencies = [
|
||||||
"bitcode",
|
"bitcode",
|
||||||
"eframe",
|
"eframe",
|
||||||
"lz4_flex",
|
"lz4_flex",
|
||||||
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
"tangled",
|
"tangled",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
@ -17,6 +17,7 @@ tangled = { path = "tangled" }
|
||||||
serde = { version = "1.0.199", features = ["serde_derive"] }
|
serde = { version = "1.0.199", features = ["serde_derive"] }
|
||||||
bitcode = "0.6.0"
|
bitcode = "0.6.0"
|
||||||
lz4_flex = { version = "0.11.3", default_features = false, features = ["std"]}
|
lz4_flex = { version = "0.11.3", default_features = false, features = ["std"]}
|
||||||
|
rand = "0.8.5"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
|
|
|
@ -9,6 +9,7 @@ pub mod messages;
|
||||||
#[derive(Debug, Decode, Encode, Clone)]
|
#[derive(Debug, Decode, Encode, Clone)]
|
||||||
pub struct GameSettings {
|
pub struct GameSettings {
|
||||||
seed: u64,
|
seed: u64,
|
||||||
|
debug_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod net;
|
pub mod net;
|
||||||
|
@ -21,6 +22,8 @@ enum AppState {
|
||||||
pub struct App {
|
pub struct App {
|
||||||
state: AppState,
|
state: AppState,
|
||||||
addr: String,
|
addr: String,
|
||||||
|
debug_mode: bool,
|
||||||
|
use_constant_seed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
@ -28,6 +31,13 @@ impl App {
|
||||||
let bind_addr = "0.0.0.0:5123".parse().unwrap();
|
let bind_addr = "0.0.0.0:5123".parse().unwrap();
|
||||||
let peer = Peer::host(bind_addr, None).unwrap();
|
let peer = Peer::host(bind_addr, None).unwrap();
|
||||||
let netman = net::NetManager::new(peer);
|
let netman = net::NetManager::new(peer);
|
||||||
|
{
|
||||||
|
let mut settings = netman.settings.lock().unwrap();
|
||||||
|
settings.debug_mode = self.debug_mode;
|
||||||
|
if !self.use_constant_seed {
|
||||||
|
settings.seed = rand::random();
|
||||||
|
}
|
||||||
|
}
|
||||||
netman
|
netman
|
||||||
.accept_local
|
.accept_local
|
||||||
.store(true, std::sync::atomic::Ordering::SeqCst);
|
.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
@ -47,6 +57,8 @@ impl Default for App {
|
||||||
Self {
|
Self {
|
||||||
state: AppState::Init,
|
state: AppState::Init,
|
||||||
addr: "192.168.1.168:5123".to_string(),
|
addr: "192.168.1.168:5123".to_string(),
|
||||||
|
debug_mode: false,
|
||||||
|
use_constant_seed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,9 +70,12 @@ impl eframe::App for App {
|
||||||
AppState::Init => {
|
AppState::Init => {
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.heading("Noita Entangled Worlds proxy");
|
ui.heading("Noita Entangled Worlds proxy");
|
||||||
|
ui.checkbox(&mut self.debug_mode, "Debug mode");
|
||||||
|
ui.checkbox(&mut self.use_constant_seed, "Use specified seed");
|
||||||
if ui.button("Host").clicked() {
|
if ui.button("Host").clicked() {
|
||||||
self.start_server();
|
self.start_server();
|
||||||
}
|
}
|
||||||
|
ui.separator();
|
||||||
ui.text_edit_singleline(&mut self.addr);
|
ui.text_edit_singleline(&mut self.addr);
|
||||||
let addr = self.addr.parse();
|
let addr = self.addr.parse();
|
||||||
ui.add_enabled_ui(addr.is_ok(), |ui| {
|
ui.add_enabled_ui(addr.is_ok(), |ui| {
|
||||||
|
|
|
@ -58,7 +58,10 @@ impl NetManager {
|
||||||
pub fn new(peer: tangled::Peer) -> Arc<Self> {
|
pub fn new(peer: tangled::Peer) -> Arc<Self> {
|
||||||
Self {
|
Self {
|
||||||
peer,
|
peer,
|
||||||
settings: Mutex::new(GameSettings { seed: 1663107061 }),
|
settings: Mutex::new(GameSettings {
|
||||||
|
seed: 1663107061,
|
||||||
|
debug_mode: false,
|
||||||
|
}),
|
||||||
continue_running: AtomicBool::new(true),
|
continue_running: AtomicBool::new(true),
|
||||||
accept_local: AtomicBool::new(false),
|
accept_local: AtomicBool::new(false),
|
||||||
local_connected: AtomicBool::new(false),
|
local_connected: AtomicBool::new(false),
|
||||||
|
@ -114,6 +117,10 @@ impl NetManager {
|
||||||
self.peer.my_id().expect("Has peer id at this point"),
|
self.peer.my_id().expect("Has peer id at this point"),
|
||||||
));
|
));
|
||||||
state.try_ws_write(ws_encode_proxy("name", "test_name"));
|
state.try_ws_write(ws_encode_proxy("name", "test_name"));
|
||||||
|
state.try_ws_write(ws_encode_proxy(
|
||||||
|
"debug",
|
||||||
|
if settings.debug_mode { "true" } else { "false" },
|
||||||
|
));
|
||||||
state.try_ws_write(ws_encode_proxy("ready", ""));
|
state.try_ws_write(ws_encode_proxy("ready", ""));
|
||||||
// TODO? those are currently ignored by mod
|
// TODO? those are currently ignored by mod
|
||||||
for id in self.peer.iter_peer_ids() {
|
for id in self.peer.iter_peer_ids() {
|
||||||
|
@ -237,12 +244,28 @@ impl NetManager {
|
||||||
thread::spawn(move || self.start_inner());
|
thread::spawn(move || self.start_inner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resend_game_settings(&self) {
|
||||||
|
let settings = self.settings.lock().unwrap().clone();
|
||||||
|
self.broadcast(&NetMsg::StartGame { settings }, Reliability::Reliable);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_host(&self) -> bool {
|
||||||
|
self.peer.my_id() == Some(PeerId::HOST)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_message_to_proxy(&self, msg: &[u8]) {
|
pub(crate) fn handle_message_to_proxy(&self, msg: &[u8]) {
|
||||||
let msg = String::from_utf8_lossy(msg);
|
let msg = String::from_utf8_lossy(msg);
|
||||||
let mut msg = msg.split_ascii_whitespace();
|
let mut msg = msg.split_ascii_whitespace();
|
||||||
let key = msg.next();
|
let key = msg.next();
|
||||||
match key {
|
match key {
|
||||||
Some("game_over") => {}
|
Some("game_over") => {
|
||||||
|
if self.is_host() {
|
||||||
|
info!("Game over, resending game settings");
|
||||||
|
self.settings.lock().unwrap().seed += 1;
|
||||||
|
info!("New seed: {}", self.settings.lock().unwrap().seed);
|
||||||
|
self.resend_game_settings();
|
||||||
|
}
|
||||||
|
}
|
||||||
key => {
|
key => {
|
||||||
error!("Unknown msg from mod: {:?}", key)
|
error!("Unknown msg from mod: {:?}", key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@ struct Datagram {
|
||||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
||||||
pub struct PeerId(pub u16);
|
pub struct PeerId(pub u16);
|
||||||
|
|
||||||
|
impl PeerId {
|
||||||
|
pub const HOST: PeerId = PeerId(0);
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for PeerId {
|
impl Display for PeerId {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{}", self.0)
|
write!(f, "{}", self.0)
|
||||||
|
|
5
todo.txt
5
todo.txt
|
@ -23,11 +23,12 @@
|
||||||
k Лимит на длину сообщения
|
k Лимит на длину сообщения
|
||||||
- Улучшеная синхронизация инвентаря и перков
|
- Улучшеная синхронизация инвентаря и перков
|
||||||
+ ...и текущего предмета
|
+ ...и текущего предмета
|
||||||
- reliability
|
+ reliability
|
||||||
+ Сжатие пакетов
|
+ Сжатие пакетов
|
||||||
- Перекидывание предметов
|
+ Перекидывание предметов
|
||||||
? Фикс наведения на клиентов
|
? Фикс наведения на клиентов
|
||||||
- fungal shift-ы
|
- fungal shift-ы
|
||||||
- orbs sync
|
- orbs sync
|
||||||
- test tangled better
|
- test tangled better
|
||||||
- poly on clients
|
- poly on clients
|
||||||
|
- proxy: stop receiving connections before another start_game on game over, noita: try to reconnect to proxy.
|
Loading…
Add table
Add a link
Reference in a new issue