Browse Source

tell loginserv the ip of charserv

pbs
jake 4 years ago
parent
commit
1ac85b9a5c
  1. 3
      src/bin/login.rs
  2. 4
      src/bin/main.rs
  3. 8
      src/login/login.rs

3
src/bin/login.rs

@ -9,10 +9,11 @@ fn main() {
let db_username = std::env::var("DB_USERNAME").unwrap();
let db_password = std::env::var("DB_PASSWORD").unwrap();
let db_dbname = std::env::var("DB_DBNAME").unwrap();
let charserv_ip = std::env::var("CHARSERV_IP").unwrap().parse().unwrap();
let entity_gateway = PostgresGateway::new(&db_host, &db_dbname, &db_username, &db_password);
let thread_entity_gateway = entity_gateway.clone();
let login_state = LoginServerState::new(thread_entity_gateway);
let login_state = LoginServerState::new(thread_entity_gateway, charserv_ip);
let login_loop = login_mainloop(login_state, elseware::login::login::LOGIN_PORT);
let char_state = CharacterServerState::new(entity_gateway);

4
src/bin/main.rs

@ -54,7 +54,7 @@ fn main() {
for i in 0..5 {
let fake_user = NewUserAccountEntity {
email: format!("fake{}@email.com", i),
username: if i == 0 { "hi".to_string() } else { format!("hi{}", i+1) },
username: if i == 0 { "hiz".to_string() } else { format!("hi{}", i+1) },
password: bcrypt::hash("qwer", 5).unwrap(),
guildcard: i + 1,
team_id: None,
@ -315,7 +315,7 @@ fn main() {
let thread_entity_gateway = entity_gateway.clone();
info!("[auth] starting server");
let login_state = LoginServerState::new(thread_entity_gateway);
let login_state = LoginServerState::new(thread_entity_gateway, "127.0.0.1".parse().unwrap());
let login_loop = login_mainloop(login_state, elseware::login::login::LOGIN_PORT);
let thread_entity_gateway = entity_gateway.clone();

8
src/login/login.rs

@ -75,13 +75,15 @@ pub async fn get_login_status(entity_gateway: &impl EntityGateway, pkt: &Login)
pub struct LoginServerState<EG: EntityGateway> {
character_server_ip: net::Ipv4Addr,
entity_gateway: EG,
}
impl<EG: EntityGateway> LoginServerState<EG> {
pub fn new(entity_gateway: EG) -> LoginServerState<EG> {
pub fn new(entity_gateway: EG, character_server_ip: net::Ipv4Addr) -> LoginServerState<EG> {
LoginServerState {
entity_gateway: entity_gateway,
character_server_ip: character_server_ip.into(),
}
}
@ -89,8 +91,8 @@ impl<EG: EntityGateway> LoginServerState<EG> {
match get_login_status(&self.entity_gateway, pkt).await {
Ok(_user) => {
let response = SendLoginPacket::LoginResponse(LoginResponse::by_status(AccountStatus::Ok, pkt.session));
let ip = net::Ipv4Addr::new(127,0,0,1);
let ip = u32::from_ne_bytes(ip.octets());
//let ip = net::Ipv4Addr::new(127,0,0,1);
let ip = u32::from_ne_bytes(self.character_server_ip.octets());
vec![response,
SendLoginPacket::RedirectClient(RedirectClient::new(ip, crate::login::character::CHARACTER_PORT))]
},

Loading…
Cancel
Save