reduce dependency bloat
This commit is contained in:
parent
5782951e68
commit
11ba2b1470
11 changed files with 249 additions and 2225 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
[submodule "grpc-protobufs"]
|
|
||||||
path = grpc-protobufs
|
|
||||||
url = https://github.com/PretendoNetwork/grpc-protobufs.git
|
|
||||||
2039
Cargo.lock
generated
2039
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 405fe9b47b416e76b21d7087b2ed11606deccfcf
|
|
||||||
|
|
@ -18,19 +18,17 @@ rand = "0.8.5"
|
||||||
hmac = "0.12.1"
|
hmac = "0.12.1"
|
||||||
md-5 = "^0.10.6"
|
md-5 = "^0.10.6"
|
||||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread", "net", "sync", "fs"] }
|
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread", "net", "sync", "fs"] }
|
||||||
tonic = "0.12.3"
|
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
|
|
||||||
macros = { path = "../macros" }
|
macros = { path = "../macros" }
|
||||||
rocket = { version = "0.5.1", features = ["json", "serde_json"] }
|
|
||||||
async-trait = "0.1.86"
|
|
||||||
paste = "1.0.15"
|
paste = "1.0.15"
|
||||||
typenum = "1.18.0"
|
typenum = "1.18.0"
|
||||||
reqwest = { version= "0.12.18", features = ["blocking"]}
|
|
||||||
json = "0.12.4"
|
json = "0.12.4"
|
||||||
ctrlc = "3.4.7"
|
|
||||||
criterion = "0.7.0"
|
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.100"
|
||||||
|
ureq = "3.1.4"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = "0.7.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
rmc_struct_header = []
|
rmc_struct_header = []
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,11 @@ const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
|
||||||
|
|
||||||
|
|
||||||
fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
|
fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
|
||||||
let req = reqwest::blocking::get(IP_REQ_SERVICE_URL)?;
|
let mut req = ureq::get(IP_REQ_SERVICE_URL)
|
||||||
Ok(req.text()?.parse()?)
|
.call()?;
|
||||||
|
|
||||||
|
|
||||||
|
Ok(req.body_mut().read_to_string()?.parse()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {
|
pub static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use std::{env, result};
|
use std::{env, result};
|
||||||
use std::array::TryFromSliceError;
|
use std::array::TryFromSliceError;
|
||||||
|
use std::ops::Deref;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use json::{object, JsonValue};
|
use json::{object, JsonValue};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use reqwest::{Body, Method, Url};
|
|
||||||
use reqwest::header::HeaderValue;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use tokio::task::{spawn_blocking, JoinError};
|
||||||
use crate::grpc::account::Error::SomethingHappened;
|
use crate::grpc::account::Error::SomethingHappened;
|
||||||
static API_KEY: Lazy<String> = Lazy::new(||{
|
static API_KEY: Lazy<String> = Lazy::new(||{
|
||||||
let key = env::var("ACCOUNT_GQL_API_KEY")
|
let key = env::var("ACCOUNT_GQL_API_KEY")
|
||||||
|
|
@ -26,27 +26,38 @@ static CLIENT_URI: Lazy<String> = Lazy::new(||{
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Creation(#[from] reqwest::Error),
|
RequestError(#[from] ureq::Error),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Json(#[from] json::Error),
|
Json(#[from] json::Error),
|
||||||
#[error(transparent)]
|
//#[error(transparent)]
|
||||||
Status(#[from] tonic::Status),
|
//Status(#[from] tonic::Status),
|
||||||
#[error("invalid password size: {0}")]
|
#[error("invalid password size: {0}")]
|
||||||
PasswordConversion(#[from] TryFromSliceError),
|
PasswordConversion(#[from] TryFromSliceError),
|
||||||
#[error("something happened")]
|
#[error("something happened")]
|
||||||
SomethingHappened
|
SomethingHappened,
|
||||||
|
#[error("error joining blocking task: {0}")]
|
||||||
|
Join(#[from] JoinError)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
pub struct Client(reqwest::Client);
|
pub struct Client;//(reqwest::Client);
|
||||||
|
|
||||||
impl Client{
|
impl Client{
|
||||||
pub async fn new() -> Result<Self> {
|
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>{
|
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());
|
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()));
|
*(request.body_mut()) = Some(Body::from(request_data.to_string()));
|
||||||
|
|
@ -56,6 +67,8 @@ impl Client{
|
||||||
let response = self.0.execute(request).await?;
|
let response = self.0.execute(request).await?;
|
||||||
|
|
||||||
Ok(json::parse(&response.text().await?)?)
|
Ok(json::parse(&response.text().await?)?)
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_nex_password(&mut self , pid: u32) -> Result<[u8; 16]>{
|
pub async fn get_nex_password(&mut self , pid: u32) -> Result<[u8; 16]>{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
//! before account rs is finished.
|
//! before account rs is finished.
|
||||||
//!
|
//!
|
||||||
//! This WILL be deprecated as soon as account rs is in a stable state.
|
//! 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;
|
pub mod account;
|
||||||
|
|
@ -17,7 +17,6 @@ pub mod kerberos;
|
||||||
pub mod nex;
|
pub mod nex;
|
||||||
pub mod result;
|
pub mod result;
|
||||||
pub mod versions;
|
pub mod versions;
|
||||||
pub mod web;
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod reggie;
|
pub mod reggie;
|
||||||
pub mod rnex_proxy_common;
|
pub mod rnex_proxy_common;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ mod kerberos;
|
||||||
mod nex;
|
mod nex;
|
||||||
mod result;
|
mod result;
|
||||||
mod versions;
|
mod versions;
|
||||||
mod web;
|
|
||||||
pub mod reggie;
|
pub mod reggie;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use bytemuck::bytes_of;
|
use bytemuck::bytes_of;
|
||||||
use log::error;
|
use log::error;
|
||||||
use rocket::form::validate::Len;
|
|
||||||
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
use v_byte_helpers::{IS_BIG_ENDIAN, ReadExtensions};
|
||||||
use super::{Result, RmcSerialize};
|
use super::{Result, RmcSerialize};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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");
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue