mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-15 03:48:42 -06:00
60 lines
1.1 KiB
Rust
60 lines
1.1 KiB
Rust
use std::num::NonZeroUsize;
|
|
|
|
use bincode::{Encode, Decode};
|
|
use crate::chunk::BlockData;
|
|
|
|
type IVec3Arr = [i32; 3];
|
|
type Vec3Arr = [f32; 3];
|
|
type QuatArr = [f32; 3];
|
|
|
|
pub const PROTOCOL_ID: u16 = 1;
|
|
|
|
#[derive(Encode, Decode, Clone)]
|
|
pub enum ClientToServerMessage {
|
|
ClientHello {
|
|
username: String,
|
|
password: Option<String>,
|
|
},
|
|
PositionChanged {
|
|
position: Vec3Arr,
|
|
velocity: Vec3Arr,
|
|
direction: QuatArr,
|
|
},
|
|
ChunkRequest {
|
|
chunk: IVec3Arr,
|
|
},
|
|
}
|
|
|
|
#[derive(Encode, Decode, Clone)]
|
|
pub struct UserInitData {
|
|
pub client_id: NonZeroUsize, //maybe use the proper type instead
|
|
pub username: String,
|
|
pub position: Vec3Arr,
|
|
pub velocity: Vec3Arr,
|
|
pub direction: QuatArr,
|
|
}
|
|
|
|
#[derive(Encode, Decode, Clone)]
|
|
pub struct InitData {
|
|
pub users: Vec<UserInitData>
|
|
}
|
|
|
|
#[derive(Encode, Decode, Clone)]
|
|
pub enum ServerToClientMessage {
|
|
ServerHello {
|
|
init: InitData
|
|
},
|
|
ServerFuckOff {
|
|
reason: String,
|
|
},
|
|
PlayerPositionChanged {
|
|
client_id: u8,
|
|
position: Vec3Arr,
|
|
direction: QuatArr,
|
|
},
|
|
ChunkResponse {
|
|
chunk: IVec3Arr,
|
|
data: BlockData
|
|
}
|
|
}
|