mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-23 20:38:21 -06:00
server
This commit is contained in:
parent
209dc15f81
commit
f0f17bdf74
|
@ -1,4 +1,3 @@
|
|||
[server]
|
||||
address = "0.0.0.0"
|
||||
port = 1234
|
||||
address = "0.0.0.0:1234"
|
||||
max_clients = 254
|
||||
|
|
|
@ -11,3 +11,8 @@ log = "*"
|
|||
shipyard = "0.6"
|
||||
serde = "1.0"
|
||||
toml = "0.7"
|
||||
glam = { version = "0.22", features = ["debug-glam-assert", "fast-math"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
unstable = ["glam/core-simd"]
|
||||
|
|
4
kubi-server/src/client.rs
Normal file
4
kubi-server/src/client.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
use shipyard::Component;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Client;
|
23
kubi-server/src/config.rs
Normal file
23
kubi-server/src/config.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use shipyard::{AllStoragesView, Unique};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::{fs, net::SocketAddr};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ConfigTableServer {
|
||||
pub address: SocketAddr,
|
||||
pub max_clients: usize,
|
||||
}
|
||||
|
||||
#[derive(Unique, Serialize, Deserialize)]
|
||||
pub struct ConfigTable {
|
||||
pub server: ConfigTableServer
|
||||
}
|
||||
|
||||
pub fn read_config(
|
||||
storages: AllStoragesView,
|
||||
) {
|
||||
log::info!("Reading config...");
|
||||
let config_str = fs::read_to_string("Server.toml").expect("No config file found");
|
||||
let config: ConfigTable = toml::from_str(&config_str).expect("Invalid configuration file");
|
||||
storages.add_unique(config);
|
||||
}
|
|
@ -1,38 +1,17 @@
|
|||
use shipyard::{World, AllStoragesView, Unique, Workload, IntoWorkload, UniqueView, UniqueViewMut};
|
||||
use kubi_udp::server::{Server, ServerConfig};
|
||||
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage};
|
||||
use std::{thread, time::Duration, net::SocketAddr};
|
||||
use shipyard::{World, Workload, IntoWorkload};
|
||||
use std::{thread, time::Duration};
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct ServerAddr(SocketAddr);
|
||||
pub(crate) mod config;
|
||||
pub(crate) mod server;
|
||||
pub(crate) mod client;
|
||||
pub(crate) mod transform;
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct UdpServer(Server<ServerToClientMessage, ClientToServerMessage>);
|
||||
|
||||
fn bind_server(
|
||||
storages: AllStoragesView,
|
||||
) {
|
||||
log::info!("Creating server...");
|
||||
let addr = storages.borrow::<UniqueView<SocketAddr>>().expect("No server addr found");
|
||||
let server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
|
||||
"0.0.0.0:1234".parse().unwrap(),
|
||||
ServerConfig::default()
|
||||
).unwrap();
|
||||
storages.add_unique(UdpServer(server));
|
||||
}
|
||||
|
||||
fn update_server(
|
||||
mut server: UniqueViewMut<UdpServer>
|
||||
) {
|
||||
if let Err(error) = server.0.update() {
|
||||
log::error!("Server error: {error:?}")
|
||||
}
|
||||
}
|
||||
use config::read_config;
|
||||
use server::{bind_server, update_server};
|
||||
|
||||
fn initialize() -> Workload {
|
||||
(
|
||||
read_config,
|
||||
bind_server,
|
||||
).into_workload()
|
||||
}
|
||||
|
|
28
kubi-server/src/server.rs
Normal file
28
kubi-server/src/server.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use shipyard::{AllStoragesView, Unique, UniqueView, UniqueViewMut};
|
||||
use kubi_udp::server::{Server, ServerConfig};
|
||||
use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage};
|
||||
use crate::config::ConfigTable;
|
||||
|
||||
#[derive(Unique)]
|
||||
#[repr(transparent)]
|
||||
pub struct UdpServer(Server<ServerToClientMessage, ClientToServerMessage>);
|
||||
|
||||
pub fn bind_server(
|
||||
storages: AllStoragesView,
|
||||
) {
|
||||
log::info!("Creating server...");
|
||||
let config = storages.borrow::<UniqueView<ConfigTable>>().unwrap();
|
||||
let server: Server<ServerToClientMessage, ClientToServerMessage> = Server::bind(
|
||||
config.server.address,
|
||||
ServerConfig { max_clients: config.server.max_clients }
|
||||
).unwrap();
|
||||
storages.add_unique(UdpServer(server));
|
||||
}
|
||||
|
||||
pub fn update_server(
|
||||
mut server: UniqueViewMut<UdpServer>
|
||||
) {
|
||||
if let Err(error) = server.0.update() {
|
||||
log::error!("Server error: {error:?}")
|
||||
}
|
||||
}
|
6
kubi-server/src/transform.rs
Normal file
6
kubi-server/src/transform.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use shipyard::Component;
|
||||
use glam::Mat4;
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug, Default)]
|
||||
#[track(All)]
|
||||
pub struct Transform(pub Mat4);
|
|
@ -22,3 +22,7 @@ gilrs = { version = "0.10", default_features = false, features = ["xinput"] }
|
|||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version = "0.3" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
unstable = ["glam/core-simd"]
|
||||
|
|
|
@ -35,6 +35,7 @@ use crate::{
|
|||
use super::{RenderTarget, primitives::cube::CubePrimitive};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct ChunkVertex {
|
||||
pub position: [f32; 3],
|
||||
pub normal: [f32; 3],
|
||||
|
|
Loading…
Reference in a new issue