Skip to content

Commit

Permalink
Restructured project for new single server layout
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtread committed Mar 22, 2023
1 parent 02dc738 commit 0d5654c
Show file tree
Hide file tree
Showing 40 changed files with 71 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use std::{
f32::consts::E,
future::ready,
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
};
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

use axum::{
extract::{ConnectInfo, FromRequestParts},
extract::FromRequestParts,
http::{Method, StatusCode},
};
use hyper::upgrade::{OnUpgrade, Upgraded};
use std::io;

pub struct BlazeUpgrade {
socket_addr: SocketAddr,
Expand Down Expand Up @@ -43,7 +38,7 @@ where

fn from_request_parts<'life0, 'life1, 'async_trait>(
parts: &'life0 mut axum::http::request::Parts,
state: &'life1 S,
_state: &'life1 S,
) -> core::pin::Pin<
Box<
dyn core::future::Future<Output = Result<Self, Self::Rejection>>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
servers::http::ext::ErrorStatusCode, services::tokens::VerifyError, state::GlobalState,
http::ext::ErrorStatusCode, services::tokens::VerifyError, state::GlobalState,
utils::types::BoxFuture,
};
use axum::{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
servers::http::middleware::auth::Auth,
http::middleware::auth::Auth,
services::game::{
manager::{SnapshotMessage, SnapshotQueryMessage},
GameSnapshot,
Expand Down
2 changes: 1 addition & 1 deletion src/servers/http/routes/gaw.rs → src/http/routes/gaw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! other than the Mass Effect 3 client itself.
use crate::{
servers::http::ext::{ErrorStatusCode, Xml},
http::ext::{ErrorStatusCode, Xml},
state::GlobalState,
utils::parsing::PlayerClass,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
servers::http::ext::ErrorStatusCode,
http::ext::ErrorStatusCode,
services::leaderboard::{models::*, QueryMessage},
state::GlobalState,
utils::types::PlayerID,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
servers::http::{
http::{
ext::ErrorStatusCode,
middleware::auth::{AdminAuth, Auth},
},
Expand Down
2 changes: 1 addition & 1 deletion src/servers/http/routes/qos.rs → src/http/routes/qos.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Routes for the Quality of Service server. Unknown whether any of the
//! response address and ports are correct however this request must succeed
//! or the client doesn't seem to know its external IP
use crate::{config::QOS_PORT, servers::http::ext::Xml};
use crate::{config::QOS_PORT, http::ext::Xml};
use axum::{extract::Query, routing::get, Router};
use log::debug;
use serde::Deserialize;
Expand Down
22 changes: 7 additions & 15 deletions src/servers/http/routes/server.rs → src/http/routes/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
use std::sync::atomic::{AtomicU32, Ordering};

use crate::{
servers::{
http::{
ext::{blaze_upgrade::BlazeUpgrade, ErrorStatusCode},
middleware::auth::AdminAuth,
},
main::session::Session,
http::{
ext::{blaze_upgrade::BlazeUpgrade, ErrorStatusCode},
middleware::auth::AdminAuth,
},
session::Session,
state,
utils::logging::LOG_FILE_NAME,
};
use axum::{
body::{BoxBody, Empty},
body::BoxBody,
http::{HeaderValue, StatusCode},
response::{IntoResponse, Response},
routing::get,
Expand All @@ -25,7 +23,6 @@ use blaze_pk::packet::PacketCodec;
use database::PlayerRole;
use hyper::header;
use interlink::service::Service;
use log::info;
use serde::Serialize;
use thiserror::Error;
use tokio::{
Expand Down Expand Up @@ -64,15 +61,10 @@ async fn upgrade(upgrade: BlazeUpgrade) -> Response {
});
});

#[allow(clippy::declare_interior_mutable_const)]
const UPGRADE: HeaderValue = HeaderValue::from_static("upgrade");
#[allow(clippy::declare_interior_mutable_const)]
const BLAZE: HeaderValue = HeaderValue::from_static("blaze");

Response::builder()
.status(StatusCode::SWITCHING_PROTOCOLS)
.header(header::CONNECTION, UPGRADE)
.header(header::UPGRADE, BLAZE)
.header(header::CONNECTION, HeaderValue::from_static("upgrade"))
.header(header::UPGRADE, HeaderValue::from_static("blaze"))
.body(BoxBody::default())
.unwrap()
}
Expand Down
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use config::load_config;
use log::info;
use servers::*;
use state::GlobalState;
use tokio::signal;
use utils::logging;

use crate::config::load_config;

mod config;
mod servers;
mod http;
mod services;
mod session;
mod state;
mod utils;

Expand All @@ -33,7 +32,7 @@ fn main() {
// Display the connection urls message
runtime.block_on(logging::log_connection_urls());

main::init_router();
session::init_router();

// Spawn the HTTP server in its own task
runtime.spawn(http::start_server());
Expand Down
23 changes: 0 additions & 23 deletions src/servers/main/mod.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/servers/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/services/game/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::matchmaking::rules::RuleSet;
use crate::{
servers::main::session::{DetailsMessage, InformSessions, PushExt, Session},
session::{DetailsMessage, InformSessions, PushExt, Session},
utils::{
components::{Components, GameManager, UserSessions},
types::{GameID, GameSlot, PlayerID, SessionID},
Expand Down
2 changes: 1 addition & 1 deletion src/services/game/player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::models::PlayerState;
use crate::{
servers::main::session::{Session, SetGameMessage},
session::{Session, SetGameMessage},
utils::{
models::NetData,
types::{GameID, PlayerID, SessionID},
Expand Down
2 changes: 1 addition & 1 deletion src/services/sessions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Service for storing links to all the currenly active
//! authenticated sessions on the server
use crate::{servers::main::session::Session, utils::types::PlayerID};
use crate::{session::Session, utils::types::PlayerID};
use interlink::prelude::*;
use std::collections::HashMap;

Expand Down
23 changes: 21 additions & 2 deletions src/servers/main/session.rs → src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! data such as player data for when they become authenticated and
//! networking data.
use super::router;
use crate::services::game::manager::RemovePlayerMessage;
use crate::services::game::models::RemoveReason;
use crate::services::matchmaking::RemoveQueueMessage;
Expand All @@ -21,7 +20,7 @@ use crate::{
};
use blaze_pk::packet::PacketDebug;
use blaze_pk::packet::{Packet, PacketComponents};
use blaze_pk::router::HandleError;
use blaze_pk::router::{HandleError, Router};
use blaze_pk::value_type;
use blaze_pk::{codec::Encodable, tag::TdfType, writer::TdfWriter};
use database::Player;
Expand All @@ -31,6 +30,26 @@ use std::fmt::Debug;
use std::io;
use std::net::SocketAddr;

pub mod models;
pub mod routes;

static mut ROUTER: Option<Router<Components, SessionLink>> = None;

pub fn router() -> &'static Router<Components, SessionLink> {
unsafe {
match &ROUTER {
Some(value) => value,
None => panic!("Main server router not yet initialized"),
}
}
}

pub fn init_router() {
unsafe {
ROUTER = Some(routes::router());
}
}

/// Structure for storing a client session. This includes the
/// network stream for the client along with global state and
/// other session state.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
servers::main::{
session::{
models::{
auth::*,
errors::{ServerError, ServerResult},
},
session::{GetPlayerIdMessage, GetPlayerMessage, SessionLink, SetPlayerMessage},
GetPlayerIdMessage, GetPlayerMessage, SessionLink, SetPlayerMessage,
},
state::GlobalState,
utils::{
Expand Down Expand Up @@ -534,9 +534,9 @@ impl LegalType {
}
let fallback = match self {
Self::TermsOfService => {
include_str!("../../../resources/defaults/terms_of_service.html")
include_str!("../../resources/defaults/terms_of_service.html")
}
Self::PrivacyPolicy => include_str!("../../../resources/defaults/privacy_policy.html"),
Self::PrivacyPolicy => include_str!("../../resources/defaults/privacy_policy.html"),
};

(Cow::Borrowed(fallback), web_path, col)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
use std::sync::Arc;

use crate::{
servers::main::{
models::{
errors::{ServerError, ServerResult},
game_manager::*,
},
session::{GetGamePlayerMessage, GetIdMessage, GetPlayerGameMessage, SessionLink},
},
services::{
game::{
manager::{
Expand All @@ -21,6 +14,13 @@ use crate::{
matchmaking::{GameCreatedMessage, QueuePlayerMessage},
sessions::LookupMessage,
},
session::{
models::{
errors::{ServerError, ServerResult},
game_manager::*,
},
GetGamePlayerMessage, GetIdMessage, GetPlayerGameMessage, SessionLink,
},
state::GlobalState,
utils::components::{Components as C, GameManager as G},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::{
servers::main::{
models::messaging::*,
session::{GetPlayerMessage, GetSocketMessage, PushExt, SessionLink},
},
session::{models::messaging::*, GetPlayerMessage, GetSocketMessage, PushExt, SessionLink},
state::{self, GlobalState},
utils::components::{Components as C, Messaging as M},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::components::Components;

use super::session::SessionLink;
use super::SessionLink;
use blaze_pk::router::Router;

mod auth;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::{
servers::main::{
models::other::*,
session::{PushExt, SessionLink},
},
session::{models::other::*, PushExt, SessionLink},
utils::components::{AssociationLists as A, Components as C, GameReporting as G},
};
use blaze_pk::{packet::Packet, router::Router};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::sync::Arc;

use crate::{
servers::main::{
services::leaderboard::{models::*, QueryMessage},
session::{
models::{
errors::{ServerError, ServerResult},
stats::*,
},
session::SessionLink,
SessionLink,
},
services::leaderboard::{models::*, QueryMessage},
state::GlobalState,
utils::components::{Components as C, Stats as S},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::{
servers::main::{
services::sessions::LookupMessage,
session::{
models::{
auth::AuthResponse,
errors::{ServerError, ServerResult},
user_sessions::*,
},
session::{
GetLookupMessage, HardwareFlagMessage, LookupResponse, NetworkInfoMessage, SessionLink,
SetPlayerMessage,
},
GetLookupMessage, HardwareFlagMessage, LookupResponse, NetworkInfoMessage, SessionLink,
SetPlayerMessage,
},
services::sessions::LookupMessage,
state::GlobalState,
utils::components::{Components as C, UserSessions as U},
};
Expand Down
Loading

0 comments on commit 0d5654c

Please sign in to comment.