Skip to content

Commit

Permalink
allow unbanning, allow seeing other peoples mods
Browse files Browse the repository at this point in the history
  • Loading branch information
bgkillas committed Dec 4, 2024
1 parent 3843685 commit e2347c4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 22 deletions.
12 changes: 12 additions & 0 deletions noita-proxy/src/bookkeeping/mod_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,18 @@ impl Mods {
}
}

pub fn get_mods(saves_path: &Path) -> Result<Vec<String>, Box<dyn Error>> {
let mod_config_path = saves_path.join("save00/mod_config.xml");
let data: Mods = quick_xml::de::from_reader(BufReader::new(File::open(&mod_config_path)?))?;
let mut res = Vec::new();
for m in data.mod_entries {
if m.enabled == 1 {
res.push(m.name)
}
}
Ok(res)
}

fn enable_mod(saves_path: &Path) -> Result<(), Box<dyn Error>> {
let shared_config_path = saves_path.join("save_shared/config.xml");
// Certainly not the cleanest solution, but parsing that config properly is _hard_.
Expand Down
86 changes: 65 additions & 21 deletions noita-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::{
};
use std::{net::IpAddr, path::PathBuf};
use steamworks::{LobbyId, SteamAPIInitError};
use tangled::Peer;
use tangled::{Peer, Reliability};
use tracing::info;
use unic_langid::LanguageIdentifier;

Expand All @@ -45,6 +45,7 @@ use util::args::Args;
pub use util::{args, lang, steam_helper};

mod bookkeeping;
use crate::net::messages::NetMsg;
use crate::player_cosmetics::{
display_player_skin, player_path, player_select_current_color_slot,
player_skin_display_color_picker, shift_hue,
Expand Down Expand Up @@ -348,6 +349,8 @@ enum AppState {
enum ConnectedMenu {
Normal,
Settings,
Mods,
BanList,
ConnectionInfo,
}

Expand Down Expand Up @@ -1153,16 +1156,21 @@ impl App {
} else {
for peer in netman.peer.iter_peer_ids() {
ui.label(peer.to_string());
if netman.peer.is_host() && peer != netman.peer.my_id() {
ui.horizontal(|ui| {
if ui.button("kick").clicked() {
netman.kick_list.lock().unwrap().push(peer)
ui.horizontal(|ui| {
if peer != netman.peer.my_id() {
if netman.peer.is_host() {
if ui.button("kick").clicked() {
netman.kick_list.lock().unwrap().push(peer)
}
if ui.button("ban").clicked() {
netman.ban_list.lock().unwrap().push(peer)
}
}
if ui.button("ban").clicked() {
netman.ban_list.lock().unwrap().push(peer)
if ui.button("mods").clicked() {
netman.send(peer, &NetMsg::RequestMods, Reliability::Reliable);
}
});
}
}
});
}
}
});
Expand All @@ -1180,6 +1188,16 @@ impl App {
ConnectedMenu::ConnectionInfo,
"Connection Info",
);
if !netman.ban_list.lock().unwrap().is_empty() {
ui.selectable_value(
&mut self.connected_menu,
ConnectedMenu::BanList,
"Ban List",
);
}
if !netman.active_mods.lock().unwrap().is_empty() {
ui.selectable_value(&mut self.connected_menu, ConnectedMenu::Mods, "Mod List");
}
if last == ConnectedMenu::Settings && last != self.connected_menu {
let new_settings = self.app_saved_state.game_settings.clone();
*netman.pending_settings.lock().unwrap() = new_settings.clone();
Expand Down Expand Up @@ -1259,6 +1277,28 @@ impl App {
}
}
}
ConnectedMenu::Mods => {
let mods_list = netman.active_mods.lock().unwrap();
for mods in mods_list.iter() {
ui.label(mods);
}
if mods_list.is_empty() {
self.connected_menu = ConnectedMenu::Normal
}
}
ConnectedMenu::BanList => {
let mut ban_list = netman.ban_list.lock().unwrap();
let mut i = ban_list.len();
while i != 0 {
i -= 1;
if ui.button(format!("unban {}", ban_list[i])).clicked() {
ban_list.remove(i);
}
}
if ban_list.is_empty() {
self.connected_menu = ConnectedMenu::Normal
}
}
ConnectedMenu::Settings => {
self.app_saved_state
.game_settings
Expand Down Expand Up @@ -1484,24 +1524,28 @@ fn show_player_list_steam(
} else {
ui.label(&username);
}
if netman.peer.is_host() && peer != netman.peer.my_id() {
if avatar.is_some() {
ui.add_space(5.0);
}
ui.horizontal(|ui| {
if ui.button("Kick").clicked() {
netman.kick_list.lock().unwrap().push(peer)
ui.horizontal(|ui| {
if peer != netman.peer.my_id() {
if avatar.is_some() {
ui.add_space(5.0);
}
if netman.peer.is_host() {
if ui.button("Kick").clicked() {
netman.kick_list.lock().unwrap().push(peer)
}
if ui.button("Ban").clicked() {
netman.ban_list.lock().unwrap().push(peer)
}
}
if ui.button("Ban").clicked() {
netman.ban_list.lock().unwrap().push(peer)
if ui.button("mods").clicked() {
netman.send(peer, &NetMsg::RequestMods, Reliability::Reliable);
}
});
}
}
});
});
}
});
}

fn add_per_status_ui(
report: &net::steam_networking::ConnectionStatusReport,
steam: &steam_helper::SteamState,
Expand Down
19 changes: 18 additions & 1 deletion noita-proxy/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use world::{world_info::WorldInfo, NoitaWorldUpdate, WorldManager};
use tangled::Reliability;
use tracing::{error, info, warn};

use crate::mod_manager::ModmanagerSettings;
use crate::mod_manager::{get_mods, ModmanagerSettings};
use crate::player_cosmetics::{create_player_png, PlayerPngDesc};
use crate::{
bookkeeping::save_state::{SaveState, SaveStateEntry},
Expand Down Expand Up @@ -128,6 +128,7 @@ pub struct NetManager {
dont_kick: Mutex<Vec<OmniPeerId>>,
pub dirty: AtomicBool,
pub actual_noita_port: AtomicU16,
pub active_mods: Mutex<Vec<String>>,
}

impl NetManager {
Expand All @@ -152,6 +153,7 @@ impl NetManager {
dont_kick: Default::default(),
dirty: AtomicBool::new(false),
actual_noita_port: AtomicU16::new(0),
active_mods: Default::default(),
}
.into()
}
Expand Down Expand Up @@ -361,6 +363,21 @@ impl NetManager {
continue;
};
match net_msg {
NetMsg::RequestMods => {
if let Some(n) =
&self.init_settings.modmanager_settings.game_save_path
{
let res = get_mods(&n);
if let Ok(mods) = res {
self.send(
src,
&NetMsg::Mods { mods },
Reliability::Reliable,
)
}
}
}
NetMsg::Mods { mods } => *self.active_mods.lock().unwrap() = mods,
NetMsg::Welcome => {}
NetMsg::PeerDisconnected { id } => {
info!("player kicked: {}", id);
Expand Down
2 changes: 2 additions & 0 deletions noita-proxy/src/net/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub(crate) struct MessageRequest<T> {
#[derive(Debug, Decode, Encode)]
pub(crate) enum NetMsg {
Welcome,
RequestMods,
Mods { mods: Vec<String> },
EndRun,
Kick,
PeerDisconnected { id: OmniPeerId },
Expand Down

0 comments on commit e2347c4

Please sign in to comment.