V0 #1

Closed
RusticMaple wants to merge 105 commits from v0 into main
11 changed files with 249 additions and 2225 deletions
Showing only changes of commit 11ba2b1470 - Show all commits

reduce dependency bloat

Maple 2025-11-13 09:51:05 +01:00

3
.gitmodules vendored
View file

@ -1,3 +0,0 @@
[submodule "grpc-protobufs"]
path = grpc-protobufs
url = https://github.com/PretendoNetwork/grpc-protobufs.git

2039
Cargo.lock generated

File diff suppressed because it is too large Load diff

@ -1 +0,0 @@
Subproject commit 405fe9b47b416e76b21d7087b2ed11606deccfcf

View file

@ -18,19 +18,17 @@ rand = "0.8.5"
hmac = "0.12.1"
md-5 = "^0.10.6"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread", "net", "sync", "fs"] }
tonic = "0.12.3"
hex = "0.4.3"
macros = { path = "../macros" }
rocket = { version = "0.5.1", features = ["json", "serde_json"] }
async-trait = "0.1.86"
paste = "1.0.15"
typenum = "1.18.0"
reqwest = { version= "0.12.18", features = ["blocking"]}
json = "0.12.4"
ctrlc = "3.4.7"
criterion = "0.7.0"
anyhow = "1.0.100"
ureq = "3.1.4"
[dev-dependencies]
criterion = "0.7.0"
[features]
rmc_struct_header = []

View file

@ -19,8 +19,11 @@ const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
let req = reqwest::blocking::get(IP_REQ_SERVICE_URL)?;
Ok(req.text()?.parse()?)
let mut req = ureq::get(IP_REQ_SERVICE_URL)
.call()?;
Ok(req.body_mut().read_to_string()?.parse()?)
}
pub static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {

View file

@ -1,11 +1,11 @@
use std::{env, result};
use std::array::TryFromSliceError;
use std::ops::Deref;
use std::str::FromStr;
use json::{object, JsonValue};
use once_cell::sync::Lazy;
use reqwest::{Body, Method, Url};
use reqwest::header::HeaderValue;
use thiserror::Error;
use tokio::task::{spawn_blocking, JoinError};
use crate::grpc::account::Error::SomethingHappened;
static API_KEY: Lazy<String> = Lazy::new(||{
let key = env::var("ACCOUNT_GQL_API_KEY")
@ -26,27 +26,38 @@ static CLIENT_URI: Lazy<String> = Lazy::new(||{
#[derive(Error, Debug)]
pub enum Error{
#[error(transparent)]
Creation(#[from] reqwest::Error),
RequestError(#[from] ureq::Error),
#[error(transparent)]
Json(#[from] json::Error),
#[error(transparent)]
Status(#[from] tonic::Status),
//#[error(transparent)]
//Status(#[from] tonic::Status),
#[error("invalid password size: {0}")]
PasswordConversion(#[from] TryFromSliceError),
#[error("something happened")]
SomethingHappened
SomethingHappened,
#[error("error joining blocking task: {0}")]
Join(#[from] JoinError)
}
pub type Result<T> = result::Result<T, Error>;
pub struct Client(reqwest::Client);
pub struct Client;//(reqwest::Client);
impl Client{
pub async fn new() -> Result<Self> {
Ok(Self(reqwest::ClientBuilder::new().build()?))
//Ok(Self(reqwest::ClientBuilder::new().build()?))
Ok(Self)
}
async fn do_request(&self, request_data: JsonValue) -> Result<JsonValue>{
let mut request = ureq::post(CLIENT_URI.as_str())
.header("X-API-Key", API_KEY.deref())
.content_type("application/json");
let mut response = spawn_blocking(move || request.send(request_data.to_string())).await??;
let str_body = response.body_mut().read_to_string()?;
Ok(json::parse(&str_body)?)
/*
let mut request = reqwest::Request::new(Method::POST, Url::from_str(CLIENT_URI.as_str()).unwrap());
*(request.body_mut()) = Some(Body::from(request_data.to_string()));
@ -56,6 +67,8 @@ impl Client{
let response = self.0.execute(request).await?;
Ok(json::parse(&response.text().await?)?)
*/
}
pub async fn get_nex_password(&mut self , pid: u32) -> Result<[u8; 16]>{

View file

@ -2,7 +2,7 @@
//! before account rs is finished.
//!
//! This WILL be deprecated as soon as account rs is in a stable state.
use tonic::{Request, Status};
//use tonic::{Request, Status};
type InterceptorFunc = Box<dyn Fn(Request<()>) -> Result<Request<()>, Status> + Send>;
//type InterceptorFunc = Box<dyn Fn(Request<()>) -> Result<Request<()>, Status> + Send>;
pub mod account;

View file

@ -17,7 +17,6 @@ pub mod kerberos;
pub mod nex;
pub mod result;
pub mod versions;
pub mod web;
pub mod common;
pub mod reggie;
pub mod rnex_proxy_common;

View file

@ -32,7 +32,6 @@ mod kerberos;
mod nex;
mod result;
mod versions;
mod web;
pub mod reggie;
pub mod util;
pub mod common;

View file

@ -1,7 +1,6 @@
use std::io::{Read, Write};
use bytemuck::bytes_of;
use log::error;
use rocket::form::validate::Len;
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
use super::{Result, RmcSerialize};

View file

@ -1,92 +0,0 @@
use std::sync::Arc;
use async_trait::async_trait;
use rocket::{get, routes, Request, State};
use rocket::request::{FromRequest, Outcome};
use rocket::serde::json::Json;
use tokio::task::JoinHandle;
use crate::nex::matchmake::MatchmakeManager;
use crate::rmc::protocols::notifications::NotificationEvent;
struct RnexApiAuth;
#[async_trait]
impl<'r> FromRequest<'r> for RnexApiAuth{
type Error = ();
async fn from_request<'a>(_request: &'r Request<'a>) -> Outcome<Self, Self::Error> {
Outcome::Success(RnexApiAuth)
}
}
#[get("/gatherings")]
async fn gatherings(mmm: &State<Arc<MatchmakeManager>>) -> Json<Vec<u32>>{
let matches = mmm.sessions.read().await;
Json(matches.keys().map(|v| *v).collect())
}
#[get("/gathering/<gid>/players")]
async fn players_in_match(mmm: &State<Arc<MatchmakeManager>>, gid: u32) -> Option<Json<Vec<u32>>>{
let mmm = mmm.sessions.read().await;
let gathering = mmm.get(&gid)?;
let gathering = gathering.clone();
drop(mmm);
let gathering = gathering.lock().await;
Some(Json(gathering.connected_players.iter().filter_map(|p| p.upgrade()).map(|p| p.pid).collect()))
}
/*
#[get("/player/<pid>/disconnect")]
async fn disconnect_player(_auth: RnexApiAuth, mmm: &State<Arc<MatchmakeManager>>, pid: u32) -> Option<()>{
// this doesnt work and is broken, there might be some other way to remotely close gatherings...
// also if anyone gets this working change it to POST cause the only reason its get is because
// that makes testing it easier
let mmm = mmm.users.read().await;
for player in mmm.values().filter_map(|p| p.upgrade()).filter(|p| p.pid == pid) {
player.remote.get_connection().0.close_connection().await;
}
Some(())
}*/
#[get("/gathering/<gid>/close")]
async fn close_gathering(_auth: RnexApiAuth, mmm: &State<Arc<MatchmakeManager>>, gid: u32) -> Option<()>{
// this doesnt work and is broken, there might be some other way to remotely close gatherings...
// also if anyone gets this working change it to POST cause the only reason its get is because
// that makes testing it easier
let mmm = mmm.sessions.read().await;
let gathering = mmm.get(&gid)?;
let gathering = gathering.clone();
drop(mmm);
let gathering = gathering.lock().await;
gathering.broadcast_notification(&NotificationEvent{
pid_source: gathering.session.gathering.owner_pid,
notif_type: 109000,
param_1: gathering.session.gathering.self_gid,
..Default::default()
}).await;
Some(())
}
pub async fn start_web(mgr: Arc<MatchmakeManager>) -> JoinHandle<()> {
tokio::spawn(async move {
rocket::build()
.mount("/", routes![gatherings, players_in_match, close_gathering])
.manage(mgr)
.launch().await
.expect("unable to start webserver");
})
}