mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-24 15:58:43 -06:00
restore basic auth services
This commit is contained in:
parent
56dd1a3bda
commit
b20c6fe552
|
@ -1,48 +1,84 @@
|
||||||
use shipyard::{UniqueView, UniqueViewMut};
|
use shipyard::{UniqueView, UniqueViewMut, NonSendSync};
|
||||||
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage, InitData};
|
use uflow::{server::Event as ServerEvent, SendMode};
|
||||||
use crate::{server::{ServerEvents, UdpServer}, config::ConfigTable, util::log_error};
|
use kubi_shared::networking::messages::{
|
||||||
|
ClientToServerMessage,
|
||||||
|
ServerToClientMessage,
|
||||||
|
InitData,
|
||||||
|
C_CLIENT_HELLO
|
||||||
|
};
|
||||||
|
use crate::{
|
||||||
|
server::{ServerEvents, UdpServer, IsMessageOfType},
|
||||||
|
config::ConfigTable, util::log_error
|
||||||
|
};
|
||||||
|
|
||||||
pub fn authenticate_players(
|
pub fn authenticate_players(
|
||||||
mut server: UniqueViewMut<UdpServer>,
|
mut server: NonSendSync<UniqueViewMut<UdpServer>>,
|
||||||
events: UniqueView<ServerEvents>,
|
events: UniqueView<ServerEvents>,
|
||||||
config: UniqueView<ConfigTable>
|
config: UniqueView<ConfigTable>
|
||||||
) {
|
) {
|
||||||
for event in &events.0 {
|
for event in &events.0 {
|
||||||
if let ServerEvent::MessageReceived {
|
// if let ServerEvent::MessageReceived {
|
||||||
from,
|
// from,
|
||||||
message: ClientToServerMessage::ClientHello {
|
// message: ClientToServerMessage::ClientHello {
|
||||||
username,
|
// username,
|
||||||
password
|
// password
|
||||||
}
|
// }
|
||||||
} = event {
|
// } = event {
|
||||||
log::info!("ClientHello from {} with username {} and password {:?}", from, username, password);
|
|
||||||
|
|
||||||
// Handle password auth
|
let ServerEvent::Receive(client_addr, data) = event else{
|
||||||
if let Some(server_password) = &config.server.password {
|
continue
|
||||||
if let Some(user_password) = &password {
|
};
|
||||||
if server_password != user_password {
|
let Some(client) = server.0.client(client_addr) else {
|
||||||
server.0.send_message(*from, ServerToClientMessage::ServerFuckOff {
|
log::error!("Client doesn't exist");
|
||||||
reason: "Passwords don't match".into()
|
continue
|
||||||
}).map_err(log_error).ok();
|
};
|
||||||
continue
|
if !event.is_message_of_type::<C_CLIENT_HELLO>() {
|
||||||
}
|
continue
|
||||||
} else {
|
}
|
||||||
server.0.send_message(*from, ServerToClientMessage::ServerFuckOff {
|
let Ok(parsed_message) = postcard::from_bytes(data) else {
|
||||||
reason: "This server is password-protected".into()
|
log::error!("Malformed message 00");
|
||||||
}).map_err(log_error).ok();
|
continue
|
||||||
|
};
|
||||||
|
let ClientToServerMessage::ClientHello { username, password } = parsed_message else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
|
||||||
|
log::info!("ClientHello; username={} password={:?}", username, password);
|
||||||
|
|
||||||
|
// Handle password auth
|
||||||
|
if let Some(server_password) = &config.server.password {
|
||||||
|
if let Some(user_password) = &password {
|
||||||
|
if server_password != user_password {
|
||||||
|
let res = postcard::to_allocvec(&ServerToClientMessage::ServerFuckOff {
|
||||||
|
reason: "Passwords don't match".into()
|
||||||
|
}).unwrap().into_boxed_slice();
|
||||||
|
client.borrow_mut().send(
|
||||||
|
res, 0, SendMode::Reliable
|
||||||
|
);
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
let res = postcard::to_allocvec(&ServerToClientMessage::ServerFuckOff {
|
||||||
|
reason: "This server is password protected".into()
|
||||||
|
}).unwrap().into_boxed_slice();
|
||||||
|
client.borrow_mut().send(
|
||||||
|
res, 0, SendMode::Reliable
|
||||||
|
);
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
//Spawn the user
|
|
||||||
//TODO Spawn the user on server side
|
|
||||||
|
|
||||||
//Approve the user
|
|
||||||
server.0.send_message(*from, ServerToClientMessage::ServerHello {
|
|
||||||
init: InitData {
|
|
||||||
users: vec![] //TODO create init data
|
|
||||||
}
|
|
||||||
}).map_err(log_error).ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Spawn the user
|
||||||
|
//TODO Spawn the user on server side
|
||||||
|
|
||||||
|
//Approve the user
|
||||||
|
let res = postcard::to_allocvec(&ServerToClientMessage::ServerHello {
|
||||||
|
init: InitData {
|
||||||
|
users: vec![] //TODO create init data
|
||||||
|
}
|
||||||
|
}).unwrap().into_boxed_slice();
|
||||||
|
client.borrow_mut().send(
|
||||||
|
res, 0, SendMode::Reliable
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,19 @@ pub(crate) mod util;
|
||||||
pub(crate) mod config;
|
pub(crate) mod config;
|
||||||
pub(crate) mod server;
|
pub(crate) mod server;
|
||||||
pub(crate) mod client;
|
pub(crate) mod client;
|
||||||
pub(crate) mod world;
|
//pub(crate) mod world;
|
||||||
pub(crate) mod auth;
|
pub(crate) mod auth;
|
||||||
|
|
||||||
use config::read_config;
|
use config::read_config;
|
||||||
use server::{bind_server, update_server, log_server_errors};
|
use server::{bind_server, update_server, log_server_errors};
|
||||||
use auth::authenticate_players;
|
use auth::authenticate_players;
|
||||||
use world::{update_world, init_world};
|
//use world::{update_world, init_world};
|
||||||
|
|
||||||
fn initialize() -> Workload {
|
fn initialize() -> Workload {
|
||||||
(
|
(
|
||||||
read_config,
|
read_config,
|
||||||
bind_server,
|
bind_server,
|
||||||
init_world,
|
//init_world,
|
||||||
).into_workload()
|
).into_workload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ fn update() -> Workload {
|
||||||
(
|
(
|
||||||
log_server_errors,
|
log_server_errors,
|
||||||
authenticate_players,
|
authenticate_players,
|
||||||
update_world,
|
//update_world,
|
||||||
).into_workload()
|
).into_workload()
|
||||||
).into_sequential_workload()
|
).into_sequential_workload()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue