mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 05:08:21 -06:00
wtf
This commit is contained in:
parent
ce4cc08d2f
commit
0e4c6a94ef
|
@ -16,6 +16,8 @@ pub fn authenticate_players(
|
||||||
password
|
password
|
||||||
}
|
}
|
||||||
} = event {
|
} = event {
|
||||||
|
log::info!("ClientHello from {} with username {} and password {:?}", from, username, password);
|
||||||
|
|
||||||
// Handle password auth
|
// Handle password auth
|
||||||
if let Some(server_password) = &config.server.password {
|
if let Some(server_password) = &config.server.password {
|
||||||
if let Some(user_password) = &password {
|
if let Some(user_password) = &password {
|
||||||
|
@ -34,12 +36,12 @@ pub fn authenticate_players(
|
||||||
}
|
}
|
||||||
|
|
||||||
//Spawn the user
|
//Spawn the user
|
||||||
// TODO
|
//TODO Spawn the user on server side
|
||||||
|
|
||||||
//Approve the user
|
//Approve the user
|
||||||
server.0.send_message(*from, ServerToClientMessage::ServerHello {
|
server.0.send_message(*from, ServerToClientMessage::ServerHello {
|
||||||
init: InitData {
|
init: InitData {
|
||||||
users: todo!()
|
users: vec![] //TODO create init data
|
||||||
}
|
}
|
||||||
}).map_err(log_error).ok();
|
}).map_err(log_error).ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
//TODO server-side chunk manager
|
||||||
|
|
||||||
pub struct Chunk {
|
pub struct Chunk {
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ChunkManager {
|
pub struct ChunkManager {
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_chunk_response(
|
pub fn server_chunk_response(
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use shipyard::{Unique, Component};
|
use shipyard::{Unique, Component};
|
||||||
|
|
||||||
// disconnected => connect => join => load => ingame
|
// disconnected => connect => join => load => ingame
|
||||||
#[derive(Unique, Component, PartialEq, Eq, Clone, Copy)]
|
#[derive(Unique, Component, PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
|
#[repr(u8)]
|
||||||
pub enum ClientJoinState {
|
pub enum ClientJoinState {
|
||||||
/// Not connected yet
|
/// Not connected yet
|
||||||
Disconnected,
|
Disconnected,
|
||||||
|
|
|
@ -20,7 +20,6 @@ fn update_perspective_matrix(
|
||||||
mut vm_camera: ViewMut<Camera>,
|
mut vm_camera: ViewMut<Camera>,
|
||||||
resize: View<WindowResizedEvent>,
|
resize: View<WindowResizedEvent>,
|
||||||
) {
|
) {
|
||||||
//TODO update on launch
|
|
||||||
let Some(&size) = resize.iter().next() else {
|
let Some(&size) = resize.iter().next() else {
|
||||||
return
|
return
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, EntitiesViewMut, Component, ViewMut, SystemModificator, View, IntoIter};
|
use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, EntitiesViewMut, Component, ViewMut, SystemModificator, View, IntoIter, WorkloadModificator};
|
||||||
use glium::glutin::event_loop::ControlFlow;
|
use glium::glutin::event_loop::ControlFlow;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use kubi_udp::client::{Client, ClientConfig, ClientEvent};
|
use kubi_udp::client::{Client, ClientConfig, ClientEvent};
|
||||||
|
@ -6,7 +6,6 @@ use kubi_shared::networking::{
|
||||||
messages::{ClientToServerMessage, ServerToClientMessage},
|
messages::{ClientToServerMessage, ServerToClientMessage},
|
||||||
state::ClientJoinState
|
state::ClientJoinState
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{events::EventComponent, control_flow::SetControlFlow};
|
use crate::{events::EventComponent, control_flow::SetControlFlow};
|
||||||
|
|
||||||
#[derive(Unique, Clone, Copy, PartialEq, Eq)]
|
#[derive(Unique, Clone, Copy, PartialEq, Eq)]
|
||||||
|
@ -36,15 +35,17 @@ fn create_client(
|
||||||
storages.add_unique(ClientJoinState::Disconnected);
|
storages.add_unique(ClientJoinState::Disconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connect_client_if_needed(
|
fn connect_client(
|
||||||
mut client: UniqueViewMut<UdpClient>
|
mut client: UniqueViewMut<UdpClient>
|
||||||
) {
|
) {
|
||||||
//NOTE: this used to be a condition function
|
log::info!("Connect called");
|
||||||
//but that caused some issues for no reason
|
client.0.connect().unwrap();
|
||||||
if client.0.has_not_made_connection_attempts() {
|
}
|
||||||
log::info!("Connect called");
|
|
||||||
client.0.connect().unwrap();
|
fn should_connect(
|
||||||
}
|
client: UniqueView<UdpClient>
|
||||||
|
) -> bool {
|
||||||
|
client.0.has_not_made_connection_attempts()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_client(
|
fn update_client(
|
||||||
|
@ -67,12 +68,49 @@ fn insert_client_events(
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_client_join_state_to_connected(
|
||||||
|
mut join_state: UniqueViewMut<ClientJoinState>
|
||||||
|
) {
|
||||||
|
log::info!("Setting ClientJoinState");
|
||||||
|
*join_state = ClientJoinState::Connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn say_hello(
|
||||||
|
client: UniqueViewMut<UdpClient>,
|
||||||
|
) {
|
||||||
|
log::info!("Authenticating");
|
||||||
|
client.0.send_message(ClientToServerMessage::ClientHello {
|
||||||
|
username: "Sbeve".into(),
|
||||||
|
password: None
|
||||||
|
}).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_server_hello_response(
|
||||||
|
network_events: View<NetworkEvent>,
|
||||||
|
mut join_state: UniqueViewMut<ClientJoinState>
|
||||||
|
) {
|
||||||
|
for event in network_events.iter() {
|
||||||
|
if let ClientEvent::MessageReceived(ServerToClientMessage::ServerHello { init }) = &event.0 {
|
||||||
|
log::info!("Joined the server!");
|
||||||
|
//TODO handle init data
|
||||||
|
*join_state = ClientJoinState::Joined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_networking() -> Workload {
|
pub fn update_networking() -> Workload {
|
||||||
(
|
(
|
||||||
create_client.run_if_missing_unique::<UdpClient>(),
|
create_client.run_if_missing_unique::<UdpClient>(),
|
||||||
connect_client_if_needed,
|
connect_client.run_if(should_connect),
|
||||||
update_client,
|
update_client,
|
||||||
insert_client_events,
|
insert_client_events,
|
||||||
|
(
|
||||||
|
set_client_join_state_to_connected,
|
||||||
|
say_hello,
|
||||||
|
).into_workload().run_if(if_just_connected),
|
||||||
|
(
|
||||||
|
check_server_hello_response,
|
||||||
|
).into_workload().run_if(is_join_state::<{ClientJoinState::Connected as u8}>)
|
||||||
).into_workload()
|
).into_workload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +128,20 @@ pub fn disconnect_on_exit(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// conditions
|
||||||
|
|
||||||
|
fn if_just_connected(
|
||||||
|
network_events: View<NetworkEvent>,
|
||||||
|
) -> bool {
|
||||||
|
network_events.iter().any(|event| matches!(event.0, ClientEvent::Connected(_)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_join_state<const STATE: u8>(
|
||||||
|
join_state: UniqueView<ClientJoinState>
|
||||||
|
) -> bool {
|
||||||
|
(*join_state as u8) == STATE
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_multiplayer(
|
pub fn is_multiplayer(
|
||||||
game_type: UniqueView<GameType>
|
game_type: UniqueView<GameType>
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
|
|
@ -18,9 +18,6 @@ use chunk::{Chunk, ChunkMesh, CHUNK_SIZE};
|
||||||
use tasks::ChunkTaskManager;
|
use tasks::ChunkTaskManager;
|
||||||
use queue::BlockUpdateQueue;
|
use queue::BlockUpdateQueue;
|
||||||
|
|
||||||
//TODO separate world struct for render data
|
|
||||||
// because this is not send-sync
|
|
||||||
|
|
||||||
#[derive(Default, Unique)]
|
#[derive(Default, Unique)]
|
||||||
pub struct ChunkStorage {
|
pub struct ChunkStorage {
|
||||||
pub chunks: HashMap<IVec3, Chunk>
|
pub chunks: HashMap<IVec3, Chunk>
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub fn update_chunks_if_player_moved(
|
||||||
mut vm_world: UniqueViewMut<ChunkStorage>,
|
mut vm_world: UniqueViewMut<ChunkStorage>,
|
||||||
) {
|
) {
|
||||||
//Check if the player actually moved
|
//Check if the player actually moved
|
||||||
//TODO fix this also triggers on rotation, only activate when the player crosses the chnk border
|
//TODO fix this also triggers on rotation, only activate when the player crosses the chunk border
|
||||||
let Some((_, transform)) = (&v_local_player, v_transform.inserted_or_modified()).iter().next() else {
|
let Some((_, transform)) = (&v_local_player, v_transform.inserted_or_modified()).iter().next() else {
|
||||||
return
|
return
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue