Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
theaddonn committed Jan 27, 2025
1 parent 0adf633 commit 21bad60
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 48 deletions.
18 changes: 18 additions & 0 deletions crates/proto/src/adapter/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::v662::types::ActorRuntimeID;
use xuid::Xuid;

pub enum GamePacketEvents {
EmoteEvent(EmotePacketEvent),
}

pub struct EmotePacketEvent {
pub actor_runtime_id: ActorRuntimeID,
pub emote_id: String,
pub xuid: Xuid,
}

impl From<crate::v748::gamepackets::GamePackets> for GamePacketEvents {
fn from(packet: crate::v748::gamepackets::GamePackets) -> Self {

Check warning on line 15 in crates/proto/src/adapter/mod.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `packet`
todo!()
}
}
1 change: 1 addition & 0 deletions crates/proto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod adapter;
pub mod codec;
pub mod compression;
pub mod connection;
Expand Down
4 changes: 1 addition & 3 deletions crates/server/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ pub enum LoginError {
FormatError(&'static str),
}

pub enum ServerError {

}
pub enum ServerError {}
1 change: 0 additions & 1 deletion crates/server/src/events/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ macro_rules! export {
}

export!(spawn);

4 changes: 2 additions & 2 deletions crates/server/src/events/handle/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod player;
mod entity;
mod player;

pub use player::*;
pub use entity::*;
pub use player::*;
2 changes: 0 additions & 2 deletions crates/server/src/events/handle/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ impl PlayerHandle {
pub fn id(&self) -> EntityId {
self.0
}


}
8 changes: 3 additions & 5 deletions crates/server/src/events/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::events::handle::PlayerHandle;

mod handle;
mod events;
mod handle;

pub trait EventListener {
type Event;

async fn handle(&self, event: &Self::Event);
}

pub enum Event {
PlayerSpawn {
player: PlayerHandle,
}
PlayerSpawn { player: PlayerHandle },
}
4 changes: 2 additions & 2 deletions crates/server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod components;
pub mod error;
mod events;
pub mod login;
mod server;
pub mod components;
pub mod systems;
mod events;

pub use server::*;
14 changes: 7 additions & 7 deletions crates/server/src/server/builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::server::Server;
use crate::systems::movement::movement_system;
use crate::{ServerHandle, ShutdownKind};
use bedrockrs_proto::listener::Listener;
use shipyard::{IntoWorkload, World};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
use shipyard::{IntoWorkload, World};
use tokio::sync::{oneshot, Notify};
use crate::{ServerHandle, ShutdownKind};
use crate::systems::movement::movement_system;

pub struct ServerBuilder {
name: String,
Expand Down Expand Up @@ -53,22 +53,22 @@ impl ServerBuilder {
)
}

let world= World::new();
let world = World::new();

world.add_workload(|| (movement_system).into_workload());

let notify = Arc::new(Notify::new());
let (sender, receiver) = oneshot::channel::<ShutdownKind>();

let server = Server {
listeners,
world,
shutdown_notify: notify.clone(),
shutdown_recv: receiver,
};

let handle = ServerHandle::new(sender, notify.clone());

(server, handle)
}
}
Expand Down
18 changes: 12 additions & 6 deletions crates/server/src/server/handle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;
use tokio::sync::{Notify, oneshot::Sender};
use bedrockrs_proto::listener::Listener;
use std::sync::Arc;
use tokio::sync::{oneshot::Sender, Notify};

pub struct ServerHandle {
shutdown_sender: Sender<ShutdownKind>,
Expand All @@ -14,10 +14,16 @@ pub enum ShutdownKind {
}

impl ServerHandle {
pub fn new(shutdown_sender: Sender<ShutdownKind>, shutdown_notify: Arc<Notify>) -> ServerHandle {
Self { shutdown_sender, shutdown_notify }
pub fn new(
shutdown_sender: Sender<ShutdownKind>,
shutdown_notify: Arc<Notify>,
) -> ServerHandle {
Self {
shutdown_sender,
shutdown_notify,
}
}

/// Initiates a graceful shutdown and waits for completion.
pub async fn shutdown_graceful(self) {
let _ = self.shutdown_sender.send(ShutdownKind::Graceful);
Expand All @@ -39,7 +45,7 @@ impl ServerHandle {
pub fn shutdown_forceful_now(self) {
let _ = self.shutdown_sender.send(ShutdownKind::Forceful);
}

pub fn add_listener(&mut self, listener: Listener) {
todo!()
}
Expand Down
16 changes: 8 additions & 8 deletions crates/server/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Server {
listeners: Vec<Listener>,
world: World,
shutdown_notify: Arc<Notify>,
shutdown_recv: Receiver<ShutdownKind>
shutdown_recv: Receiver<ShutdownKind>,
}

impl Server {
Expand All @@ -24,36 +24,36 @@ impl Server {

pub async fn run(&mut self) {
self.load().await;

for listener in &mut self.listeners {
listener.start().await.unwrap();
}

loop {
if let Ok(kind) = self.shutdown_recv.try_recv() {
if kind == ShutdownKind::Graceful {
self.save().await;
}

break;
};

let tick_start = Instant::now();

self.tick();

println!("TICK");

let elapsed = tick_start.elapsed();

if elapsed < Self::TICK_DURATION {
sleep(Self::TICK_DURATION - elapsed).await;
}
}

self.shutdown_notify.notify_one();
}

fn tick(&mut self) {
self.world.run_default_workload().unwrap()
}
Expand Down
1 change: 0 additions & 1 deletion crates/server/src/systems/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub struct Pos(pub Vec3<f32>);
#[derive(Component)]
pub struct Vel(pub Vec3<f32>);


pub fn movement_system(v_vel: View<Vel>, mut v_pos: ViewMut<Pos>) {
println!("- MOVEMENT");
for (pos, vel) in (&mut v_pos, &v_vel).iter() {
Expand Down
15 changes: 9 additions & 6 deletions crates/server/src/systems/packet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use shipyard::{Component, ViewMut};
use bedrockrs_proto::connection::shard::arc::ConnectionShared;
use bedrockrs_proto::ProtoHelper;
use shipyard::{Component, ViewMut};

#[derive(Component)]
pub struct Connected<T: ProtoHelper + 'static>
Expand All @@ -10,11 +10,14 @@ where
pub connection: ConnectionShared<T>,
}

pub fn packet_recv_system<T: ProtoHelper>(v_con: ViewMut<Connected<T>>) where <T as ProtoHelper>::GamePacketType: Sync {

pub fn packet_recv_system<T: ProtoHelper>(v_con: ViewMut<Connected<T>>)
where
<T as ProtoHelper>::GamePacketType: Sync,
{
}

pub fn packet_send_system<T: ProtoHelper>(v_con: ViewMut<Connected<T>>) where <T as ProtoHelper>::GamePacketType: Sync {

pub fn packet_send_system<T: ProtoHelper>(v_con: ViewMut<Connected<T>>)
where
<T as ProtoHelper>::GamePacketType: Sync,
{
}

10 changes: 5 additions & 5 deletions examples/server_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ async fn main() {
.sub_name("bedrock-rs")
.build()
.await;

println!("Server started");

tokio::spawn(async move {
println!("Server starting");
server.run().await
});

sleep(Duration::from_secs(5)).await;

handle.shutdown_graceful().await;

println!("server shutdown");
}

0 comments on commit 21bad60

Please sign in to comment.