Skip to content

Commit dbd0f7b

Browse files
committed
moved status to types folder
1 parent 952b0e3 commit dbd0f7b

File tree

7 files changed

+23
-24
lines changed

7 files changed

+23
-24
lines changed

server/src/network/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::network::protocol::login::serverbound::LoginStart;
1010
use crate::network::protocol::play::serverbound::Play;
1111
use crate::network::protocol::status::clientbound::{StatusPong, StatusResponse};
1212
use crate::network::protocol::status::serverbound::StatusPing;
13-
use crate::network::status::StatusBytes;
13+
use crate::types::status::StatusBytes;
1414
use crate::player::player::{ClientId, GameProfile};
1515
use crate::GameProfileProperty;
1616
use anyhow::bail;

server/src/network/internal_packets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::network::protocol::play::serverbound::Play;
2-
use crate::network::status::StatusUpdate;
32
use crate::player::player::{ClientId, GameProfile};
3+
use crate::types::status::StatusUpdate;
44
use bytes::Bytes;
55

66
pub enum NetworkThreadMessage {

server/src/network/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ pub mod network;
44
pub mod connection_state;
55
pub mod internal_packets;
66
pub mod protocol;
7-
pub mod binary;
8-
pub mod status;
7+
pub mod binary;

server/src/network/network.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::network::client::handle_client;
2-
use crate::network::status::Status;
2+
use crate::types::status::Status;
33
use core::panic;
44
use std::collections::HashMap;
5-
use std::sync::Arc;
65
use tokio::net::TcpListener;
76
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
87

server/src/types/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pub mod block_position;
33
pub mod direction;
44
pub mod aabb;
55
pub mod chat_component;
6-
pub mod sized_string_mut;
6+
pub mod sized_string_mut;
7+
pub mod status;
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
use bytes::Bytes;
22
use crate::types::chat_component::ChatComponent;
33

4-
#[derive(Debug, Clone)]
5-
pub struct StatusBytes(Bytes);
6-
impl StatusBytes {
7-
#[inline(always)]
8-
pub fn get_str(&self) -> &str {
9-
// SAFETY: These should always be constructed from a String.
10-
unsafe { str::from_utf8_unchecked(&self.0) }
11-
}
12-
}
13-
144
pub struct Status {
155
players: u32,
166
max_players: u32,
17-
7+
188
serialized_info: String,
199
icon: &'static str,
20-
10+
2111
cached: Option<StatusBytes>,
2212
}
2313

2414
impl Status {
2515
pub fn new(players: u32, max_players: u32, info: ChatComponent, icon: &'static str) -> Self {
2616
Self { players, max_players, serialized_info: info.serialize(), icon, cached: None, }
2717
}
28-
18+
2919
pub fn set(&mut self, update: StatusUpdate) {
3020
match update {
3121
StatusUpdate::Players(count) => self.players = count,
@@ -35,7 +25,7 @@ impl Status {
3525
}
3626
self.cached = None;
3727
}
38-
28+
3929
pub fn get(&mut self) -> StatusBytes {
4030
self.cached.get_or_insert_with(|| {
4131
StatusBytes(Bytes::from(format!(r#"{{
@@ -59,4 +49,14 @@ pub enum StatusUpdate {
5949
MaxPlayers(u32),
6050
Info(ChatComponent),
6151
Icon(&'static str),
62-
}
52+
}
53+
54+
#[derive(Debug, Clone)]
55+
pub struct StatusBytes(Bytes);
56+
impl StatusBytes {
57+
#[inline(always)]
58+
pub fn get_str(&self) -> &str {
59+
// SAFETY: These should always be constructed from a String.
60+
unsafe { str::from_utf8_unchecked(&self.0) }
61+
}
62+
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use server::entity::entity_metadata::{EntityMetadata, EntityVariant};
1010
use server::inventory::menu::OpenContainer;
1111
use server::network::internal_packets::NetworkThreadMessage;
1212
use server::network::network::start_network;
13-
use server::network::status::Status;
13+
use server::types::status::Status;
1414
use server::types::chat_component::{ChatComponent, MCColors};
1515
use server::utils::seeded_rng::{seeded_rng, SeededRng};
1616
use server::world::world::World;
@@ -88,10 +88,10 @@ async fn main() -> anyhow::Result<()> {
8888
let status = Status::new(1, 0, text, get_assets().icon_data);
8989
let (tx, mut rx) = start_network("127.0.0.1:4972", status);
9090

91-
let mut tick_interval = tokio::time::interval(Duration::from_millis(50));
9291
let mut world = initialize_world(tx)?;
9392
spawn_mort(&mut world);
9493

94+
let mut tick_interval = tokio::time::interval(Duration::from_millis(50));
9595
loop {
9696
tick_interval.tick().await;
9797
// let start = std::time::Instant::now();

0 commit comments

Comments
 (0)