Browse Source

login_server crate

pull/142/head
jake 1 year ago
parent
commit
e359501be6
  1. 3
      Cargo.toml
  2. 21
      login_server/Cargo.toml
  3. 2
      login_server/src/character.rs
  4. 2
      login_server/src/lib.rs
  5. 12
      login_server/src/login.rs
  6. 10
      src/bin/login.rs
  7. 16
      src/bin/main.rs
  8. 2
      src/bin/ship.rs
  9. 2
      src/lib.rs
  10. 3
      src/login/mod.rs
  11. 2
      src/ship/packet/handler/auth.rs

3
Cargo.toml

@ -20,6 +20,7 @@ members = [
"stats", "stats",
"trade", "trade",
"patch_server", "patch_server",
"login_server",
] ]
[workspace.dependencies] [workspace.dependencies]
@ -37,6 +38,7 @@ drops = { path = "./drops" }
trade = { path = "./trade" } trade = { path = "./trade" }
room = { path = "./room" } room = { path = "./room" }
patch_server = { path = "./patch_server" } patch_server = { path = "./patch_server" }
login_server = { path = "./login_server" }
libpso = { git = "http://git.sharnoth.com/jake/libpso" } libpso = { git = "http://git.sharnoth.com/jake/libpso" }
@ -83,6 +85,7 @@ drops = { workspace = true }
trade = { workspace = true } trade = { workspace = true }
room = { workspace = true } room = { workspace = true }
patch_server = { workspace = true } patch_server = { workspace = true }
login_server = { workspace = true }
libpso = { workspace = true } libpso = { workspace = true }

21
login_server/Cargo.toml

@ -0,0 +1,21 @@
[package]
name = "login_server"
version = "0.1.0"
edition = "2021"
[dependencies]
entity = { workspace = true }
networking = { workspace = true }
pktbuilder = { workspace = true }
stats = { workspace = true }
libpso = { workspace = true }
async-std = { workspace = true }
async-trait = { workspace = true }
anyhow = { workspace = true }
bcrypt = { workspace = true }
crc = { workspace = true }
thiserror = { workspace = true }
chrono = { workspace = true }
rand= { workspace = true }

2
src/login/character.rs → login_server/src/character.rs

@ -31,7 +31,7 @@ use entity::item::tool::Tool;
use entity::item::mag::Mag; use entity::item::mag::Mag;
use entity::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel}; use entity::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel};
use crate::login::login::{get_login_status};
use crate::login::get_login_status;
use networking::interserver::AuthToken; use networking::interserver::AuthToken;
use pktbuilder::ship::SHIP_MENU_ID; use pktbuilder::ship::SHIP_MENU_ID;

2
login_server/src/lib.rs

@ -0,0 +1,2 @@
pub mod login;
pub mod character;

12
src/login/login.rs → login_server/src/login.rs

@ -83,21 +83,13 @@ pub async fn get_login_status(entity_gateway: &mut impl EntityGateway, pkt: &Log
pub fn check_if_already_online(user: UserAccountEntity) -> Result<UserAccountEntity, AccountStatus> { pub fn check_if_already_online(user: UserAccountEntity) -> Result<UserAccountEntity, AccountStatus> {
Ok(user) Ok(user)
/*
if user.is_currently_online() {
Err(AccountStatus::PayUp)
}
else {
Ok(user)
}
*/
} }
#[derive(Clone)] #[derive(Clone)]
pub struct LoginServerState<EG: EntityGateway + Clone> { pub struct LoginServerState<EG: EntityGateway + Clone> {
character_server_ip: net::Ipv4Addr, character_server_ip: net::Ipv4Addr,
entity_gateway: EG, entity_gateway: EG,
clients: HashMap<ClientId, String>,
clients: HashMap<ClientId, String>, // TODO: this should be arc/mutex'd?
} }
impl<EG: EntityGateway + Clone> LoginServerState<EG> { impl<EG: EntityGateway + Clone> LoginServerState<EG> {
@ -119,7 +111,7 @@ impl<EG: EntityGateway + Clone> LoginServerState<EG> {
let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.session)); let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.session));
let ip = u32::from_ne_bytes(self.character_server_ip.octets()); let ip = u32::from_ne_bytes(self.character_server_ip.octets());
Ok(vec![response, Ok(vec![response,
SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::login::character::CHARACTER_PORT))])
SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::character::CHARACTER_PORT))])
}, },
Err(err) => { Err(err) => {
Ok(vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.session))]) Ok(vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.session))])

10
src/bin/login.rs

@ -1,7 +1,7 @@
use log::{info}; use log::{info};
use entity::gateway::postgres::PostgresGateway; use entity::gateway::postgres::PostgresGateway;
use elseware::login::login::LoginServerState;
use elseware::login::character::CharacterServerState;
use login_server::login::LoginServerState;
use login_server::character::CharacterServerState;
use networking::interserver::AuthToken; use networking::interserver::AuthToken;
fn main() { fn main() {
@ -38,17 +38,17 @@ fn main() {
let login_state = LoginServerState::new(entity_gateway.clone(), charserv_ip); let login_state = LoginServerState::new(entity_gateway.clone(), charserv_ip);
let login_loop = async_std::task::spawn(async move { let login_loop = async_std::task::spawn(async move {
networking::mainloop::run_server(login_state, elseware::login::login::LOGIN_PORT).await;
networking::mainloop::run_server(login_state, login_server::login::LOGIN_PORT).await;
}); });
let char_state = CharacterServerState::new(entity_gateway, AuthToken(shipgate_token)); let char_state = CharacterServerState::new(entity_gateway, AuthToken(shipgate_token));
let sub_char_state = char_state.clone(); let sub_char_state = char_state.clone();
let character_loop = async_std::task::spawn(async move { let character_loop = async_std::task::spawn(async move {
networking::mainloop::run_server(sub_char_state, elseware::login::character::CHARACTER_PORT).await;
networking::mainloop::run_server(sub_char_state, login_server::character::CHARACTER_PORT).await;
}); });
let inter_character_loop = async_std::task::spawn(async move { let inter_character_loop = async_std::task::spawn(async move {
networking::mainloop::run_interserver_listen(char_state, elseware::login::login::COMMUNICATION_PORT).await;
networking::mainloop::run_interserver_listen(char_state, login_server::login::COMMUNICATION_PORT).await;
}); });
info!("[auth/character] starting server"); info!("[auth/character] starting server");

16
src/bin/main.rs

@ -2,8 +2,8 @@ use std::net::Ipv4Addr;
use log::{info}; use log::{info};
use networking::interserver::AuthToken; use networking::interserver::AuthToken;
use elseware::login::login::LoginServerState;
use elseware::login::character::CharacterServerState;
use login_server::login::LoginServerState;
use login_server::character::CharacterServerState;
use patch_server::{PatchServerState, generate_patch_tree, load_config, load_motd}; use patch_server::{PatchServerState, generate_patch_tree, load_config, load_motd};
use elseware::ship::ship::ShipServerStateBuilder; use elseware::ship::ship::ShipServerStateBuilder;
@ -344,19 +344,19 @@ fn main() {
info!("[auth] starting server"); info!("[auth] starting server");
let login_state = LoginServerState::new(entity_gateway.clone(), "127.0.0.1".parse().unwrap()); let login_state = LoginServerState::new(entity_gateway.clone(), "127.0.0.1".parse().unwrap());
let login_loop = async_std::task::spawn(async move { let login_loop = async_std::task::spawn(async move {
networking::mainloop::run_server(login_state, elseware::login::login::LOGIN_PORT).await;
networking::mainloop::run_server(login_state, login_server::login::LOGIN_PORT).await;
}); });
info!("[character] starting server"); info!("[character] starting server");
let char_state = CharacterServerState::new(entity_gateway.clone(), AuthToken("".into())); let char_state = CharacterServerState::new(entity_gateway.clone(), AuthToken("".into()));
let sub_char_state = char_state.clone(); let sub_char_state = char_state.clone();
let character_loop = async_std::task::spawn(async move { let character_loop = async_std::task::spawn(async move {
networking::mainloop::run_server(sub_char_state, elseware::login::character::CHARACTER_PORT).await;
networking::mainloop::run_server(sub_char_state, login_server::character::CHARACTER_PORT).await;
}); });
let sub_char_state = char_state.clone(); let sub_char_state = char_state.clone();
let inter_character_loop = async_std::task::spawn(async move { let inter_character_loop = async_std::task::spawn(async move {
networking::mainloop::run_interserver_listen(sub_char_state, elseware::login::login::COMMUNICATION_PORT).await;
networking::mainloop::run_interserver_listen(sub_char_state, login_server::login::COMMUNICATION_PORT).await;
}); });
info!("[ship] starting servers"); info!("[ship] starting servers");
@ -373,7 +373,7 @@ fn main() {
}); });
let sub_ship_state = ship_state.clone(); let sub_ship_state = ship_state.clone();
let inter_ship_loop1 = async_std::task::spawn(async move { let inter_ship_loop1 = async_std::task::spawn(async move {
networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT).await;
networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await;
}); });
let ship_state = ShipServerStateBuilder::default() let ship_state = ShipServerStateBuilder::default()
@ -389,7 +389,7 @@ fn main() {
}); });
let sub_ship_state = ship_state.clone(); let sub_ship_state = ship_state.clone();
let inter_ship_loop2 = async_std::task::spawn(async move { let inter_ship_loop2 = async_std::task::spawn(async move {
networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT).await;
networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await;
}); });
let ship_state = ShipServerStateBuilder::default() let ship_state = ShipServerStateBuilder::default()
@ -404,7 +404,7 @@ fn main() {
}); });
let sub_ship_state = ship_state.clone(); let sub_ship_state = ship_state.clone();
let inter_ship_loop3 = async_std::task::spawn(async move { let inter_ship_loop3 = async_std::task::spawn(async move {
networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), elseware::login::login::COMMUNICATION_PORT).await;
networking::mainloop::run_interserver_connect(sub_ship_state, std::net::Ipv4Addr::new(127, 0, 0, 1), login_server::login::COMMUNICATION_PORT).await;
}); });
futures::future::join_all(vec![patch_loop, login_loop, character_loop, inter_character_loop, futures::future::join_all(vec![patch_loop, login_loop, character_loop, inter_character_loop,

2
src/bin/ship.rs

@ -52,7 +52,7 @@ fn main() {
networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT).await; networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT).await;
}); });
let inter_ship_loop = async_std::task::spawn(async move { let inter_ship_loop = async_std::task::spawn(async move {
networking::mainloop::run_interserver_connect(ship_state, shipgate_ip, elseware::login::login::COMMUNICATION_PORT).await;
networking::mainloop::run_interserver_connect(ship_state, shipgate_ip, login_server::login::COMMUNICATION_PORT).await;
}); });
info!("[auth/character] starting server"); info!("[auth/character] starting server");

2
src/lib.rs

@ -11,5 +11,5 @@ extern crate test;
//pub mod common; //pub mod common;
//pub mod entity; //pub mod entity;
//pub mod patch; //pub mod patch;
pub mod login;
//pub mod login;
pub mod ship; pub mod ship;

3
src/login/mod.rs

@ -1,3 +0,0 @@
#[allow(clippy::module_inception)]
pub mod login;
pub mod character;

2
src/ship/packet/handler/auth.rs

@ -2,7 +2,7 @@ use libpso::packet::login::{Login, LoginResponse, AccountStatus, Session};
use libpso::packet::ship::*; use libpso::packet::ship::*;
use networking::serverstate::ClientId; use networking::serverstate::ClientId;
use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients};
use crate::login::login::get_login_status;
use login_server::login::get_login_status;
use entity::gateway::EntityGateway; use entity::gateway::EntityGateway;
use items::state::ItemState; use items::state::ItemState;
use networking::interserver::ShipMessage; use networking::interserver::ShipMessage;

Loading…
Cancel
Save