kubi/kubi-server/src/auth.rs

49 lines
1.6 KiB
Rust
Raw Normal View History

2023-02-13 21:27:27 -06:00
use shipyard::{UniqueView, UniqueViewMut};
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage, InitData};
use crate::{server::{ServerEvents, UdpServer}, config::ConfigTable, util::log_error};
pub fn authenticate_players(
mut server: UniqueViewMut<UdpServer>,
events: UniqueView<ServerEvents>,
config: UniqueView<ConfigTable>
) {
for event in &events.0 {
if let ServerEvent::MessageReceived {
from,
message: ClientToServerMessage::ClientHello {
username,
password
}
} = event {
2023-03-06 18:51:19 -06:00
log::info!("ClientHello from {} with username {} and password {:?}", from, username, password);
2023-02-13 21:27:27 -06:00
// Handle password auth
if let Some(server_password) = &config.server.password {
if let Some(user_password) = &password {
if server_password != user_password {
server.0.send_message(*from, ServerToClientMessage::ServerFuckOff {
reason: "Passwords don't match".into()
}).map_err(log_error).ok();
continue
}
} else {
server.0.send_message(*from, ServerToClientMessage::ServerFuckOff {
reason: "This server is password-protected".into()
}).map_err(log_error).ok();
continue
}
}
2023-02-13 21:31:17 -06:00
//Spawn the user
2023-03-06 18:51:19 -06:00
//TODO Spawn the user on server side
2023-02-13 21:52:11 -06:00
2023-02-13 21:27:27 -06:00
//Approve the user
server.0.send_message(*from, ServerToClientMessage::ServerHello {
2023-02-13 21:52:11 -06:00
init: InitData {
2023-03-06 18:51:19 -06:00
users: vec![] //TODO create init data
2023-02-13 21:52:11 -06:00
}
2023-02-13 21:27:27 -06:00
}).map_err(log_error).ok();
}
}
}