Skip to content

Commit

Permalink
Ignore 127.0.0.1 while mapping uPnP
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHellBox committed Jun 27, 2021
1 parent c6f6da1 commit d27f80e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions kissmp-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl Server {
}
println!("Server is running!");

loop {
'main: loop {
select! {
_ = ticks.next() => {
self.tick().await;
Expand All @@ -212,11 +212,11 @@ impl Server {
},
_ = destroyer => {
println!("Server shutdown requested. Shutting down");
break;
break 'main;
},
_ = ctrl_c => {
std::process::exit(0);
break;
break 'main;
}
}
}
Expand Down Expand Up @@ -602,7 +602,12 @@ pub fn upnp_pf(port: u16) -> Option<u16> {
continue;
};
let addr = match addr.address.unwrap() {
SocketAddr::V4(v4) => v4,
SocketAddr::V4(v4) => {
if v4.ip().octets()[1] == 127 {
continue
}
v4
},
_ => continue,
};
ip = Some(addr.ip().clone());
Expand All @@ -613,7 +618,8 @@ pub fn upnp_pf(port: u16) -> Option<u16> {
}
std::net::SocketAddrV4::new(ip.unwrap(), port)
};
match gateway.add_port(igd::PortMappingProtocol::UDP, port, ip, 0, "KissMP Server") {
println!("test {}", ip);
match gateway.add_port(igd::PortMappingProtocol::UDP, port, ip, 0, &format!("KissMP Server {}", rand::random::<u16>())) {
Ok(()) => Some(port),
Err(e) => match e {
igd::AddPortError::PortInUse => Some(port),
Expand Down

0 comments on commit d27f80e

Please sign in to comment.