Browse Source

login_server crate

pull/135/head
jake 1 year ago
committed by andy
parent
commit
0fed0da24b
  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",
"trade",
"patch_server",
"login_server",
]
[workspace.dependencies]
@ -37,6 +38,7 @@ drops = { path = "./drops" }
trade = { path = "./trade" }
room = { path = "./room" }
patch_server = { path = "./patch_server" }
login_server = { path = "./login_server" }
libpso = { git = "http://git.sharnoth.com/jake/libpso" }
@ -83,6 +85,7 @@ drops = { workspace = true }
trade = { workspace = true }
room = { workspace = true }
patch_server = { workspace = true }
login_server = { 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::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel};
use crate::login::login::{get_login_status};
use crate::login::get_login_status;
use networking::interserver::AuthToken;
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> {
Ok(user)
/*
if user.is_currently_online() {
Err(AccountStatus::PayUp)
}
else {
Ok(user)
}
*/
}
#[derive(Clone)]
pub struct LoginServerState<EG: EntityGateway + Clone> {
character_server_ip: net::Ipv4Addr,
entity_gateway: EG,
clients: HashMap<ClientId, String>,
clients: HashMap<ClientId, String>, // TODO: this should be arc/mutex'd?
}
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 ip = u32::from_ne_bytes(self.character_server_ip.octets());
Ok(vec![response,
SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::login::character::CHARACTER_PORT))])
SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::character::CHARACTER_PORT))])
},
Err(err) => {
Ok(vec![SendLoginPacket::LoginResponse(LoginResponse::by_status(err, pkt.session))])

10
src/bin/login.rs

@ -1,7 +1,7 @@
use log::{info};
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;
fn main() {
@ -38,17 +38,17 @@ fn main() {
let login_state = LoginServerState::new(entity_gateway.clone(), charserv_ip);
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 sub_char_state = char_state.clone();
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 {
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");

16
src/bin/main.rs

@ -2,8 +2,8 @@ use std::net::Ipv4Addr;
use log::{info};
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 elseware::ship::ship::ShipServerStateBuilder;
@ -344,19 +344,19 @@ fn main() {
info!("[auth] starting server");
let login_state = LoginServerState::new(entity_gateway.clone(), "127.0.0.1".parse().unwrap());
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");
let char_state = CharacterServerState::new(entity_gateway.clone(), AuthToken("".into()));
let sub_char_state = char_state.clone();
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 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");
@ -373,7 +373,7 @@ fn main() {
});
let sub_ship_state = ship_state.clone();
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()
@ -389,7 +389,7 @@ fn main() {
});
let sub_ship_state = ship_state.clone();
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()
@ -404,7 +404,7 @@ fn main() {
});
let sub_ship_state = ship_state.clone();
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,

2
src/bin/ship.rs

@ -52,7 +52,7 @@ fn main() {
networking::mainloop::run_server(sub_ship_state, elseware::ship::ship::SHIP_PORT).await;
});
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");

2
src/lib.rs

@ -11,5 +11,5 @@ extern crate test;
//pub mod common;
//pub mod entity;
//pub mod patch;
pub mod login;
//pub mod login;
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 networking::serverstate::ClientId;
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 items::state::ItemState;
use networking::interserver::ShipMessage;

Loading…
Cancel
Save