This commit is contained in:
Maple 2026-01-20 20:26:44 +01:00
commit fc94f655b2
43 changed files with 1957 additions and 694 deletions

View file

@ -1,27 +1,23 @@
use once_cell::sync::Lazy;
use rnex_core::nex::account::Account;
use rnex_core::rmc::protocols::{RmcCallable, RmcConnection, new_rmc_gateway_connection};
use rnex_core::rmc::structures::RmcSerialize;
use rnex_core::rnex_proxy_common::ConnectionInitData;
use std::env;
use std::io::Cursor;
use std::net::{Ipv4Addr, SocketAddrV4};
use std::sync::Arc;
use once_cell::sync::Lazy;
use rnex_core::nex::account::Account;
use rnex_core::rmc::protocols::{RmcCallable, RmcConnection, new_rmc_gateway_connection};
use rnex_core::rnex_proxy_common::ConnectionInitData;
use rnex_core::rmc::structures::RmcSerialize;
use tokio::net::TcpListener;
use std::error::Error;
use log::error;
use std::error::Error;
use crate::reggie::UnitPacketRead;
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
let mut req = ureq::get(IP_REQ_SERVICE_URL)
.call()?;
pub fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?;
Ok(req.body_mut().read_to_string()?.parse()?)
}
@ -37,16 +33,14 @@ pub static OWN_IP_PUBLIC: Lazy<Ipv4Addr> = Lazy::new(|| {
env::var("SERVER_IP_PUBLIC")
.ok()
.map(|s| s.parse().expect("invalid ip address"))
.unwrap_or_else(||{
try_get_ip().unwrap()
})
.unwrap_or_else(|| try_get_ip().unwrap())
});
pub static SERVER_PORT: Lazy<u16> = Lazy::new(|| {
env::var("SERVER_PORT")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(10000)
.unwrap_or(6000)
});
pub static KERBEROS_SERVER_PASSWORD: Lazy<String> = Lazy::new(|| {
@ -60,24 +54,28 @@ pub static AUTH_SERVER_ACCOUNT: Lazy<Account> =
pub static SECURE_SERVER_ACCOUNT: Lazy<Account> =
Lazy::new(|| Account::new(2, "Quazal Rendez-Vous", &KERBEROS_SERVER_PASSWORD));
pub async fn new_simple_backend<T: RmcCallable + Sync + Send + 'static,F>(mut creation_function: F)
pub async fn new_simple_backend<T: RmcCallable + Sync + Send + 'static, F>(mut creation_function: F)
where
F: FnMut(ConnectionInitData, RmcConnection) -> Arc<T>,
{
let listen = TcpListener::bind(SocketAddrV4::new(*OWN_IP_PRIVATE, *SERVER_PORT)).await.unwrap();
let listen = TcpListener::bind(SocketAddrV4::new(*OWN_IP_PRIVATE, *SERVER_PORT))
.await
.unwrap();
while let Ok((mut stream, _addr)) = listen.accept().await {
let buffer = match stream.read_buffer().await{
let buffer = match stream.read_buffer().await {
Ok(v) => v,
Err(e) => {
error!("an error ocurred whilest reading connection data buffer: {:?}", e);
error!(
"an error ocurred whilest reading connection data buffer: {:?}",
e
);
continue;
}
};
let user_connection_data = ConnectionInitData::deserialize(&mut Cursor::new(buffer));
let user_connection_data = match user_connection_data{
let user_connection_data = match user_connection_data {
Ok(v) => v,
Err(e) => {
error!("an error ocurred whilest reading connection data: {:?}", e);
@ -85,8 +83,6 @@ where
}
};
let fun_ref = &mut creation_function;
new_rmc_gateway_connection(stream.into(), move |r|{
fun_ref(user_connection_data, r)
});
new_rmc_gateway_connection(stream.into(), move |r| fun_ref(user_connection_data, r));
}
}
}