2025-02-01 17:31:13 +01:00
|
|
|
#![allow(dead_code)]
|
2025-03-23 10:54:01 +01:00
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
|
|
|
|
|
//! # Splatoon RNEX server
|
|
|
|
|
//!
|
|
|
|
|
//! This server still includes the code for rnex itself as this is the first rnex server and thus
|
|
|
|
|
//! also the first and only current usage of rnex, expect this and rnex to be split into seperate
|
|
|
|
|
//! repos soon.
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-01 17:31:13 +01:00
|
|
|
use std::{env, fs};
|
2025-01-19 14:14:48 +01:00
|
|
|
use std::fs::File;
|
|
|
|
|
use std::net::{Ipv4Addr, SocketAddrV4};
|
2025-02-07 18:09:12 +01:00
|
|
|
use chrono::{Local, SecondsFormat};
|
2025-02-01 17:31:13 +01:00
|
|
|
use log::info;
|
2025-01-19 14:14:48 +01:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
use simplelog::{ColorChoice, CombinedLogger, Config, LevelFilter, TerminalMode, TermLogger, WriteLogger};
|
2025-02-01 19:42:45 +01:00
|
|
|
use crate::nex::account::Account;
|
2025-03-23 10:54:01 +01:00
|
|
|
use crate::prudp::socket::Unsecure;
|
2025-02-07 08:46:09 +01:00
|
|
|
use crate::prudp::packet::{VirtualPort};
|
2025-01-21 20:10:58 +01:00
|
|
|
use crate::prudp::router::Router;
|
2025-02-18 22:55:33 +01:00
|
|
|
use crate::prudp::sockaddr::PRUDPSockAddr;
|
2025-01-19 14:14:48 +01:00
|
|
|
|
2025-01-19 13:02:15 +01:00
|
|
|
mod endianness;
|
|
|
|
|
mod prudp;
|
2025-01-26 12:09:56 +01:00
|
|
|
pub mod rmc;
|
2025-02-18 22:55:33 +01:00
|
|
|
//mod protocols;
|
2025-01-19 13:02:15 +01:00
|
|
|
|
2025-02-01 19:42:45 +01:00
|
|
|
mod nex;
|
2025-02-02 00:46:04 +01:00
|
|
|
mod grpc;
|
2025-02-02 20:25:22 +01:00
|
|
|
mod kerberos;
|
2025-02-18 22:55:33 +01:00
|
|
|
mod web;
|
2025-02-01 19:42:45 +01:00
|
|
|
|
|
|
|
|
static KERBEROS_SERVER_PASSWORD: Lazy<String> = Lazy::new(||{
|
2025-02-02 20:25:22 +01:00
|
|
|
env::var("AUTH_SERVER_PASSWORD")
|
2025-02-01 19:42:45 +01:00
|
|
|
.ok()
|
|
|
|
|
.unwrap_or("password".to_owned())
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static AUTH_SERVER_ACCOUNT: Lazy<Account> = Lazy::new(|| Account::new(1, "Quazal Authentication", &KERBEROS_SERVER_PASSWORD));
|
|
|
|
|
static SECURE_SERVER_ACCOUNT: Lazy<Account> = Lazy::new(|| Account::new(2, "Quazal Rendez-Vous", &KERBEROS_SERVER_PASSWORD));
|
|
|
|
|
|
2025-01-19 14:14:48 +01:00
|
|
|
static AUTH_SERVER_PORT: Lazy<u16> = Lazy::new(||{
|
|
|
|
|
env::var("AUTH_SERVER_PORT")
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|s| s.parse().ok())
|
|
|
|
|
.unwrap_or(10000)
|
|
|
|
|
});
|
2025-02-03 20:43:24 +01:00
|
|
|
static SECURE_SERVER_PORT: Lazy<u16> = Lazy::new(||{
|
|
|
|
|
env::var("SECURE_SERVER_PORT")
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|s| s.parse().ok())
|
|
|
|
|
.unwrap_or(10001)
|
|
|
|
|
});
|
2025-01-19 14:14:48 +01:00
|
|
|
|
2025-02-05 16:02:32 +01:00
|
|
|
static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(||{
|
2025-01-19 14:41:32 +01:00
|
|
|
env::var("SERVER_IP")
|
|
|
|
|
.ok()
|
|
|
|
|
.and_then(|s| s.parse().ok())
|
|
|
|
|
.expect("no public ip specified")
|
|
|
|
|
});
|
2025-01-19 14:14:48 +01:00
|
|
|
|
2025-02-12 18:46:29 +01:00
|
|
|
static OWN_IP_PUBLIC: Lazy<String> = Lazy::new(||{
|
2025-02-05 16:02:32 +01:00
|
|
|
env::var("SERVER_IP_PUBLIC")
|
2025-02-12 18:46:29 +01:00
|
|
|
.unwrap_or(OWN_IP_PRIVATE.to_string())
|
2025-02-05 16:02:32 +01:00
|
|
|
});
|
|
|
|
|
|
2025-02-03 20:43:24 +01:00
|
|
|
static SECURE_STATION_URL: Lazy<String> = Lazy::new(||
|
2025-02-05 16:02:32 +01:00
|
|
|
format!("prudps:/PID=2;sid=1;stream=10;type=2;address={};port={};CID=1", *OWN_IP_PUBLIC, *SECURE_SERVER_PORT)
|
2025-02-03 20:43:24 +01:00
|
|
|
);
|
|
|
|
|
|
2025-01-21 20:10:58 +01:00
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
2025-01-19 14:14:48 +01:00
|
|
|
CombinedLogger::init(
|
|
|
|
|
vec![
|
|
|
|
|
TermLogger::new(LevelFilter::Info, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
|
2025-01-19 18:57:36 +01:00
|
|
|
WriteLogger::new(LevelFilter::max(), Config::default(), {
|
2025-01-19 14:14:48 +01:00
|
|
|
fs::create_dir_all("log").unwrap();
|
2025-02-07 18:09:12 +01:00
|
|
|
let date = Local::now().to_rfc3339_opts(SecondsFormat::Secs, false);
|
|
|
|
|
// this fixes windows being windows
|
|
|
|
|
let date = date.replace(":", "-");
|
|
|
|
|
let filename = format!("{}.log", date);
|
|
|
|
|
if cfg!(windows) {
|
|
|
|
|
File::create(format!("log\\{}", filename)).unwrap()
|
|
|
|
|
} else {
|
|
|
|
|
File::create(format!("log/{}", filename)).unwrap()
|
|
|
|
|
}
|
2025-01-19 14:14:48 +01:00
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
dotenv::dotenv().ok();
|
|
|
|
|
|
2025-01-21 20:10:58 +01:00
|
|
|
start_servers().await;
|
|
|
|
|
}
|
2025-02-18 22:55:33 +01:00
|
|
|
/*
|
2025-01-21 20:10:58 +01:00
|
|
|
|
2025-02-03 20:43:24 +01:00
|
|
|
struct AuthServer{
|
|
|
|
|
router: Arc<Router>,
|
|
|
|
|
join_handle: JoinHandle<()>,
|
|
|
|
|
socket: Socket
|
2025-01-26 12:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 20:43:24 +01:00
|
|
|
async fn start_auth_server() -> AuthServer{
|
2025-02-05 16:02:32 +01:00
|
|
|
info!("starting auth server on {}:{}", *OWN_IP_PRIVATE, *AUTH_SERVER_PORT);
|
2025-01-19 14:14:48 +01:00
|
|
|
|
2025-02-03 20:43:24 +01:00
|
|
|
let (router, join_handle) =
|
2025-02-05 16:02:32 +01:00
|
|
|
Router::new(SocketAddrV4::new(*OWN_IP_PRIVATE, *AUTH_SERVER_PORT)).await
|
2025-01-21 20:10:58 +01:00
|
|
|
.expect("unable to startauth server");
|
2025-01-19 14:14:48 +01:00
|
|
|
|
2025-01-19 18:57:36 +01:00
|
|
|
info!("setting up endpoints");
|
|
|
|
|
|
2025-01-26 12:09:56 +01:00
|
|
|
// dont assign it to the name _ as that will make it drop right here and now
|
2025-02-02 20:25:22 +01:00
|
|
|
|
|
|
|
|
let auth_protocol_config = AuthProtocolConfig{
|
|
|
|
|
secure_server_account: &SECURE_SERVER_ACCOUNT,
|
|
|
|
|
build_name: "branch:origin/project/wup-agmj build:3_8_15_2004_0",
|
2025-02-03 20:43:24 +01:00
|
|
|
station_url: &SECURE_STATION_URL
|
2025-02-02 20:25:22 +01:00
|
|
|
};
|
|
|
|
|
|
2025-01-26 23:21:35 +01:00
|
|
|
let rmcserver = RMCProtocolServer::new(Box::new([
|
2025-02-02 20:25:22 +01:00
|
|
|
Box::new(auth::bound_protocol(auth_protocol_config))
|
2025-01-26 23:21:35 +01:00
|
|
|
]));
|
|
|
|
|
|
2025-02-07 08:46:09 +01:00
|
|
|
let socket =
|
2025-01-21 20:10:58 +01:00
|
|
|
Socket::new(
|
2025-02-03 20:43:24 +01:00
|
|
|
router.clone(),
|
2025-01-21 20:10:58 +01:00
|
|
|
VirtualPort::new(1,10),
|
2025-01-26 12:09:56 +01:00
|
|
|
"6f599f81",
|
2025-02-03 21:33:07 +01:00
|
|
|
Box::new(|_, count|{
|
2025-01-26 12:09:56 +01:00
|
|
|
Box::pin(
|
|
|
|
|
async move {
|
|
|
|
|
|
|
|
|
|
|
2025-02-07 08:48:22 +01:00
|
|
|
let encryption_pairs = Vec::from_iter((0..=count).map(|_v| {
|
2025-02-03 21:33:07 +01:00
|
|
|
let rc4: Rc4<U5> = Rc4::new_from_slice( "CD&ML".as_bytes()).unwrap();
|
|
|
|
|
let cypher = Box::new(rc4);
|
|
|
|
|
let server_cypher: Box<dyn StreamCipher + Send> = cypher;
|
|
|
|
|
|
|
|
|
|
let rc4: Rc4<U5> = Rc4::new_from_slice( "CD&ML".as_bytes()).unwrap();
|
|
|
|
|
let cypher = Box::new(rc4);
|
|
|
|
|
let client_cypher: Box<dyn StreamCipher + Send> = cypher;
|
|
|
|
|
|
|
|
|
|
EncryptionPair{
|
|
|
|
|
recv: client_cypher,
|
|
|
|
|
send: server_cypher
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
Some((Vec::new(), encryption_pairs, None))
|
2025-02-03 20:43:24 +01:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}),
|
|
|
|
|
Box::new(move |packet, socket, connection|{
|
|
|
|
|
let rmcserver = rmcserver.clone();
|
2025-02-06 17:54:38 +01:00
|
|
|
Box::pin(async move { rmcserver.process_message(packet, socket, connection).await; })
|
2025-02-03 20:43:24 +01:00
|
|
|
})
|
|
|
|
|
).await.expect("unable to create socket");
|
|
|
|
|
|
|
|
|
|
AuthServer{
|
|
|
|
|
join_handle,
|
|
|
|
|
router,
|
|
|
|
|
socket,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct SecureServer{
|
|
|
|
|
router: Arc<Router>,
|
|
|
|
|
join_handle: JoinHandle<()>,
|
|
|
|
|
socket: Socket
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn start_secure_server() -> SecureServer{
|
2025-02-05 16:02:32 +01:00
|
|
|
info!("starting secure server on {}:{}", *OWN_IP_PRIVATE, *SECURE_SERVER_PORT);
|
2025-02-03 20:43:24 +01:00
|
|
|
|
|
|
|
|
let (router, join_handle) =
|
2025-02-05 16:02:32 +01:00
|
|
|
Router::new(SocketAddrV4::new(*OWN_IP_PRIVATE, *SECURE_SERVER_PORT)).await
|
2025-02-03 20:43:24 +01:00
|
|
|
.expect("unable to startauth server");
|
|
|
|
|
|
|
|
|
|
info!("setting up endpoints");
|
|
|
|
|
|
2025-02-06 17:54:38 +01:00
|
|
|
let matchmake_data = Arc::new(RwLock::new(
|
|
|
|
|
MatchmakeData{
|
|
|
|
|
matchmake_sessions: BTreeMap::new()
|
|
|
|
|
}
|
2025-02-04 22:07:22 +01:00
|
|
|
));
|
|
|
|
|
|
2025-02-04 16:31:56 +01:00
|
|
|
let rmcserver = RMCProtocolServer::new(Box::new([
|
2025-02-05 16:02:32 +01:00
|
|
|
Box::new(block_if_maintenance),
|
2025-02-04 22:07:22 +01:00
|
|
|
Box::new(protocols::secure::bound_protocol()),
|
2025-02-06 17:54:38 +01:00
|
|
|
Box::new(protocols::matchmake::bound_protocol(matchmake_data.clone())),
|
2025-02-12 18:46:29 +01:00
|
|
|
Box::new(protocols::matchmake_extension::bound_protocol(matchmake_data)),
|
|
|
|
|
Box::new(protocols::nat_traversal::bound_protocol())
|
2025-02-04 16:31:56 +01:00
|
|
|
]));
|
2025-02-03 20:43:24 +01:00
|
|
|
|
2025-02-07 08:46:09 +01:00
|
|
|
let socket =
|
2025-02-03 20:43:24 +01:00
|
|
|
Socket::new(
|
|
|
|
|
router.clone(),
|
|
|
|
|
VirtualPort::new(1,10),
|
|
|
|
|
"6f599f81",
|
2025-02-03 21:33:07 +01:00
|
|
|
Box::new(|p, count|{
|
2025-02-03 20:43:24 +01:00
|
|
|
Box::pin(
|
|
|
|
|
async move {
|
2025-02-04 16:31:56 +01:00
|
|
|
let (session_key, pid, check_value) = read_secure_connection_data(&p.payload, &SECURE_SERVER_ACCOUNT)?;
|
|
|
|
|
|
|
|
|
|
let check_value_response = check_value + 1;
|
|
|
|
|
|
|
|
|
|
let data = bytemuck::bytes_of(&check_value_response);
|
2025-02-03 20:43:24 +01:00
|
|
|
|
2025-02-04 16:31:56 +01:00
|
|
|
let mut response = Vec::new();
|
2025-02-03 20:43:24 +01:00
|
|
|
|
2025-02-04 16:31:56 +01:00
|
|
|
data.serialize(&mut response).ok()?;
|
|
|
|
|
|
|
|
|
|
let encryption_pairs = generate_secure_encryption_pairs(session_key, count);
|
|
|
|
|
|
|
|
|
|
Some((response, encryption_pairs, Some(
|
|
|
|
|
ActiveSecureConnectionData{
|
|
|
|
|
pid,
|
|
|
|
|
session_key
|
|
|
|
|
}
|
|
|
|
|
)))
|
2025-01-26 12:09:56 +01:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}),
|
2025-01-26 23:21:35 +01:00
|
|
|
Box::new(move |packet, socket, connection|{
|
|
|
|
|
let rmcserver = rmcserver.clone();
|
2025-02-06 17:54:38 +01:00
|
|
|
Box::pin(async move { rmcserver.process_message(packet, socket, connection).await; })
|
2025-01-26 12:09:56 +01:00
|
|
|
})
|
2025-01-21 20:10:58 +01:00
|
|
|
).await.expect("unable to create socket");
|
2025-01-19 14:14:48 +01:00
|
|
|
|
2025-02-03 20:43:24 +01:00
|
|
|
SecureServer{
|
|
|
|
|
join_handle,
|
|
|
|
|
router,
|
|
|
|
|
socket,
|
|
|
|
|
}
|
2025-02-18 22:55:33 +01:00
|
|
|
}*/
|
2025-03-23 10:54:01 +01:00
|
|
|
/*
|
|
|
|
|
define_rmc_proto!(
|
|
|
|
|
proto AuthClientProtocol{
|
|
|
|
|
Auth
|
|
|
|
|
}
|
|
|
|
|
);*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#[rmc_struct(AuthClientProtocol)]
|
|
|
|
|
struct AuthClient{
|
|
|
|
|
|
|
|
|
|
}
|
2025-02-03 20:43:24 +01:00
|
|
|
|
|
|
|
|
async fn start_servers(){
|
2025-02-08 13:30:43 +01:00
|
|
|
|
|
|
|
|
|
2025-02-03 20:43:24 +01:00
|
|
|
|
2025-01-26 12:09:56 +01:00
|
|
|
|
|
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let a = tokio::spawn(async{
|
|
|
|
|
let (router_auth, _) =
|
|
|
|
|
Router::new(SocketAddrV4::new(*OWN_IP_PRIVATE, *AUTH_SERVER_PORT)).await.expect("unable to start router");
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let mut socket_auth = router_auth.add_socket(VirtualPort::new(1,10), Unsecure("CD&ML")).await
|
|
|
|
|
.expect("unable to add socket");
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let mut conn = socket_auth.accept().await.unwrap();
|
|
|
|
|
info!("got conn");
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
if let Some(data) = conn.recv().await{
|
|
|
|
|
let str = String::from_utf8(data).unwrap();
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
println!("{}", str)
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let b = tokio::spawn(async{
|
|
|
|
|
let auth_ip = SocketAddrV4::new(*OWN_IP_PRIVATE, *AUTH_SERVER_PORT);
|
|
|
|
|
let auth_port = VirtualPort::new(1,10);
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let auth_sockaddr = PRUDPSockAddr::new(auth_ip,auth_port);
|
2025-01-26 12:09:56 +01:00
|
|
|
|
|
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let (router_secure, _) =
|
|
|
|
|
Router::new(SocketAddrV4::new(*OWN_IP_PRIVATE, *SECURE_SERVER_PORT)).await.expect("unable to start router");
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let mut socket_secure = router_secure.add_socket(VirtualPort::new(1,10), Unsecure("CD&ML")).await
|
|
|
|
|
.expect("unable to add socket");
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let conn = socket_secure.connect(auth_sockaddr).await.unwrap();
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
let conn = conn.duplicate_sender();
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
conn.send("Yippie".as_bytes().to_owned()).await;
|
2025-01-26 12:09:56 +01:00
|
|
|
|
2025-02-18 22:55:33 +01:00
|
|
|
info!("got conn");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
a.await;
|
|
|
|
|
b.await;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#[cfg(feature = "auth")]
|
|
|
|
|
let auth_server = start_auth_server().await;
|
|
|
|
|
#[cfg(feature = "secure")]
|
|
|
|
|
let secure_server = start_secure_server().await;
|
|
|
|
|
let web_server = web::start_web().await;
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "auth")]
|
|
|
|
|
auth_server.join_handle.await.expect("auth server crashed");
|
|
|
|
|
#[cfg(feature = "secure")]
|
|
|
|
|
secure_server.join_handle.await.expect("auth server crashed");
|
|
|
|
|
web_server.await.expect("webserver crashed");*/
|
2025-02-04 22:07:22 +01:00
|
|
|
}
|