progress
Some checks failed
Build and Test / friends (push) Successful in 9m35s
Build and Test / wii-u-chat (push) Has been cancelled
Build and Test / puyopuyo (push) Has been cancelled
Build and Test / sonic-transformed (push) Has been cancelled
Build and Test / super-mario-maker (push) Has been cancelled
Build and Test / minecraft-wiiu (push) Has been cancelled
Build and Test / wii-sports-club (push) Has been cancelled
Build and Test / splatoon (push) Has been cancelled
Build and Test / splatoon-testfire (push) Has been cancelled
Build and Test / fast-racing-neo (push) Has been cancelled
Build and Test / mario-tennis (push) Has been cancelled
Some checks failed
Build and Test / friends (push) Successful in 9m35s
Build and Test / wii-u-chat (push) Has been cancelled
Build and Test / puyopuyo (push) Has been cancelled
Build and Test / sonic-transformed (push) Has been cancelled
Build and Test / super-mario-maker (push) Has been cancelled
Build and Test / minecraft-wiiu (push) Has been cancelled
Build and Test / wii-sports-club (push) Has been cancelled
Build and Test / splatoon (push) Has been cancelled
Build and Test / splatoon-testfire (push) Has been cancelled
Build and Test / fast-racing-neo (push) Has been cancelled
Build and Test / mario-tennis (push) Has been cancelled
This commit is contained in:
parent
8db02c00ec
commit
47f7dea859
27 changed files with 160 additions and 170 deletions
19
prudpv1-proxy/Cargo.toml
Normal file
19
prudpv1-proxy/Cargo.toml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[package]
|
||||
name = "prudpv1-proxy"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
prudpv1 = {path = "../prudpv1"}
|
||||
proxy-common = {path = "../proxy-common"}
|
||||
rnex-server = {path = "../rnex-server"}
|
||||
rnex-prudp = {path = "../rnex-prudp"}
|
||||
rnex-util = {path = "../rnex-util"}
|
||||
tracing = "0.1.44"
|
||||
tokio = { version = "1.52.3", features = ["rt"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[features]
|
||||
prudpv1 = []
|
||||
13
prudpv1-proxy/src/lib.rs
Normal file
13
prudpv1-proxy/src/lib.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#![cfg(feature = "prudpv1")]
|
||||
use proxy_common::ProxyStartupParam;
|
||||
|
||||
pub mod proxy_insecure;
|
||||
pub mod proxy_secure;
|
||||
|
||||
pub async fn start_secure(param: ProxyStartupParam) {
|
||||
proxy_secure::start(param).await;
|
||||
}
|
||||
|
||||
pub async fn start_insecure(param: ProxyStartupParam) {
|
||||
proxy_insecure::start(param).await;
|
||||
}
|
||||
87
prudpv1-proxy/src/proxy_insecure.rs
Normal file
87
prudpv1-proxy/src/proxy_insecure.rs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
use proxy_common::{ProxyStartupParam, RNEX_ACCESS_KEY};
|
||||
use prudpv1::prudp::router::Router;
|
||||
use prudpv1::prudp::unsecure::Unsecure;
|
||||
use rnex_prudp::virtual_port::VirtualPort;
|
||||
use rnex_server::ConnectionInitData;
|
||||
use rnex_server::rmc::serialization::RmcSerialize;
|
||||
use rnex_util::UnitPacketRead;
|
||||
use rnex_util::UnitPacketWrite;
|
||||
use std::time::Duration;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::task;
|
||||
use tokio::time::sleep;
|
||||
use tracing::error;
|
||||
|
||||
pub async fn start(param: ProxyStartupParam) {
|
||||
let (router_secure, _) = Router::new(param.self_private)
|
||||
.await
|
||||
.expect("unable to start router");
|
||||
|
||||
let mut socket_secure = router_secure
|
||||
.add_socket(VirtualPort::new(1, 10), Unsecure(RNEX_ACCESS_KEY))
|
||||
.await
|
||||
.expect("unable to add socket");
|
||||
|
||||
loop {
|
||||
let Some(mut conn) = socket_secure.accept().await else {
|
||||
error!("server crashed");
|
||||
return;
|
||||
};
|
||||
|
||||
task::spawn(async move {
|
||||
let mut stream = match TcpStream::connect(param.forward_destination).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("unable to connect: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = stream
|
||||
.send_buffer(
|
||||
&ConnectionInitData {
|
||||
addr: conn.socket_addr.regular_socket_addr,
|
||||
pid: conn.user_id,
|
||||
}
|
||||
.to_data()
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
error!("error connecting to backend: {}", e);
|
||||
return;
|
||||
};
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
data = conn.recv() => {
|
||||
let Some(data) = data else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Err(e) = stream.send_buffer(&data[..]).await{
|
||||
error!("error sending data to backend: {}", e);
|
||||
return;
|
||||
}
|
||||
},
|
||||
data = stream.read_buffer() => {
|
||||
let data = match data{
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
error!("error reveiving data from backend: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if conn.send(data).await == None{
|
||||
return;
|
||||
}
|
||||
},
|
||||
_ = sleep(Duration::from_secs(10)) => {
|
||||
conn.send([0,0,0,0,0].to_vec()).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
116
prudpv1-proxy/src/proxy_secure.rs
Normal file
116
prudpv1-proxy/src/proxy_secure.rs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
use proxy_common::{ProxyStartupParam, RNEX_ACCESS_KEY};
|
||||
use prudpv1::prudp::{router::Router, secure::Secure};
|
||||
use rnex_prudp::virtual_port::VirtualPort;
|
||||
use rnex_server::ConnectionInitData;
|
||||
use rnex_server::rmc::serialization::RmcSerialize;
|
||||
use rnex_util::account::Account;
|
||||
use rnex_util::{UnitPacketRead, UnitPacketWrite};
|
||||
use std::ops::Deref;
|
||||
use std::time::Duration;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::task;
|
||||
use tokio::time::sleep;
|
||||
use tracing::error;
|
||||
|
||||
pub async fn start(param: ProxyStartupParam) {
|
||||
let (router_secure, _) = Router::new(param.self_private)
|
||||
.await
|
||||
.expect("unable to start router");
|
||||
|
||||
let mut socket_secure = router_secure
|
||||
.add_socket(
|
||||
VirtualPort::new(1, 10),
|
||||
Secure(
|
||||
RNEX_ACCESS_KEY,
|
||||
Account::from_nexact(2, "Quazal Rendez-Vous")
|
||||
.await
|
||||
.expect("failed to get account"),
|
||||
),
|
||||
)
|
||||
.await
|
||||
.expect("unable to add socket");
|
||||
|
||||
loop {
|
||||
let Some(mut conn) = socket_secure.accept().await else {
|
||||
error!("server crashed");
|
||||
return;
|
||||
};
|
||||
|
||||
task::spawn(async move {
|
||||
// todo: add support for checking this to nex-account
|
||||
/*
|
||||
let Ok(mut c) = rnex_core::grpc::account::Client::new().await else {
|
||||
error!("failed to initialize gql client");
|
||||
return;
|
||||
};
|
||||
|
||||
let v = match c.get_user_level(conn.user_id).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("failed to get user level: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if v < 0 {
|
||||
warn!("person with too low account level joined");
|
||||
return;
|
||||
} */
|
||||
|
||||
let mut stream = match TcpStream::connect(param.forward_destination).await {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("unable to connect: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = stream
|
||||
.send_buffer(
|
||||
&ConnectionInitData {
|
||||
addr: conn.socket_addr.regular_socket_addr,
|
||||
pid: conn.user_id,
|
||||
}
|
||||
.to_data()
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
error!("error connecting to backend: {}", e);
|
||||
return;
|
||||
};
|
||||
|
||||
'a: loop {
|
||||
tokio::select! {
|
||||
data = conn.recv() => {
|
||||
let Some(data) = data else {
|
||||
break 'a;
|
||||
};
|
||||
|
||||
if let Err(e) = stream.send_buffer(&data[..]).await{
|
||||
error!("error sending data to backend: {}", e);
|
||||
break 'a;
|
||||
}
|
||||
},
|
||||
data = stream.read_buffer() => {
|
||||
let data = match data{
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
error!("error reveiving data from backend: {}", e);
|
||||
break 'a;
|
||||
}
|
||||
};
|
||||
|
||||
if conn.send(data).await == None{
|
||||
break 'a;
|
||||
}
|
||||
},
|
||||
_ = sleep(Duration::from_secs(10)) => {
|
||||
conn.send([0,0,0,0,0].to_vec()).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.deref().close_connection().await;
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue