Fix conditional compilaton

This commit is contained in:
red binder 2026-04-21 21:41:44 +02:00
commit 458c651cd4
3 changed files with 58 additions and 28 deletions

View file

@ -10,33 +10,41 @@ use std::sync::Arc;
use tokio::net::TcpListener;
use std::sync::LazyLock;
use std::sync::OnceLock;
use sqlx::postgres::PgPool;
cfg_if! {
if #[cfg(feature = "datastore")] {
use sqlx::postgres::PgPool;
}
}
use log::error;
use std::error::Error;
use std::string::ToString;
use cfg_if::cfg_if;
use crate::reggie::UnitPacketRead;
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
pub static RNEX_DATASTORE_DATABASE_URL: LazyLock<String> = LazyLock::new(|| {
cfg_if! {
if #[cfg(feature = "datastore")] {
pub static RNEX_DATASTORE_DATABASE_URL: LazyLock<String> = LazyLock::new(|| {
std::env::var("RNEX_DATASTORE_DATABASE_URL")
.expect("RNEX_DATASTORE_DATABASE_URL must be set")
});
});
pub static DB_POOL: OnceLock<PgPool> = OnceLock::new();
pub static DB_POOL: OnceLock<PgPool> = OnceLock::new();
pub fn get_db() -> &'static PgPool {
pub fn get_db() -> &'static PgPool {
DB_POOL.get().expect("db_pool not initialized")
}
pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock<String> = LazyLock::new(|| {
}
pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock<String> = LazyLock::new(|| {
std::env::var("RNEX_DATASTORE_S3_ENDPOINT")
.expect("RNEX_DATASTORE_S3_ENDPOINT must be set")
});
pub static RNEX_DATASTORE_S3_BUCKET: LazyLock<String> = LazyLock::new(|| {
});
pub static RNEX_DATASTORE_S3_BUCKET: LazyLock<String> = LazyLock::new(|| {
std::env::var("RNEX_DATASTORE_S3_BUCKET")
.expect("RNEX_DATASTORE_S3_BUCKET must be set")
});
});
}
}
pub fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?;

View file

@ -1,3 +1,5 @@
use cfg_if::cfg_if;
pub mod account;
pub mod auth_handler;
pub mod common;
@ -6,4 +8,8 @@ pub mod matchmake;
pub mod remote_console;
pub mod user;
pub mod datastore;
pub mod s3presigner;
cfg_if! {
if #[cfg(feature = "datastore")] {
pub mod s3presigner;
}
}

View file

@ -41,11 +41,14 @@ use rnex_core::prudp::socket_addr::PRUDPSockAddr;
use rnex_core::rmc::response::ErrorCode::{Core_InvalidArgument, RendezVous_AccountExpired};
use rnex_core::rmc::structures::qresult::QResult;
use std::sync::{Arc, Weak};
use cfg_if::cfg_if;
use rnex_core::rmc::protocols::ranking::{CompetitionRankingScoreData, CompetitionRankingGetParam, CompetitionRankingScoreInfo};
use rnex_core::rmc::structures::ranking::{UploadCompetitionData};
use tokio::sync::{Mutex, RwLock};
define_rmc_proto!(
cfg_if! {
if #[cfg(feature = "datastore")] {
define_rmc_proto!(
proto UserProtocol{
Secure,
MatchmakeExtension,
@ -55,7 +58,20 @@ define_rmc_proto!(
Ranking,
DataStore
}
);
);
} else {
define_rmc_proto!(
proto UserProtocol{
Secure,
MatchmakeExtension,
MatchmakeExt,
Matchmake,
NatTraversal,
Ranking
}
);
}
}
#[rmc_struct(UserProtocol)]
pub struct User {