This commit is contained in:
MeexReay 2025-05-06 16:18:13 +03:00
parent 3788bc36dd
commit db89af6c07
16 changed files with 39 additions and 11 deletions

View File

@ -5,7 +5,7 @@ use rust_mc_proto::Packet;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use crate::server::ServerError;
use crate::ServerError;
use super::ReadWriteNBT;

View File

@ -1,6 +1,7 @@
use rust_mc_proto::Packet;
use super::protocol::ConnectionState;
use super::{ServerError, player::context::ClientContext, protocol::ConnectionState};
use std::sync::Arc;
#[macro_export]
macro_rules! generate_handlers {
@ -10,7 +11,7 @@ macro_rules! generate_handlers {
0
}
fn [<on_ $name>](&self, _: std::sync::Arc<crate::server::player::context::ClientContext> $(, _: $arg_ty)*) -> Result<(), crate::server::ServerError> {
fn [<on_ $name>](&self, _: Arc<ClientContext> $(, _: $arg_ty)*) -> Result<(), ServerError> {
Ok(())
}
}

View File

@ -1,5 +1,6 @@
use std::{error::Error, fmt::Display, net::TcpListener, sync::Arc, thread, time::Duration};
use config::Config;
use context::ServerContext;
use ignore_result::Ignore;
use log::{error, info};
@ -104,3 +105,32 @@ pub fn start_server(server: Arc<ServerContext>) {
});
}
}
// server start helper
pub struct Server {
context: Arc<ServerContext>,
}
impl Server {
pub fn new(context: ServerContext) -> Self {
Self {
context: Arc::new(context),
}
}
pub fn context(&self) -> &ServerContext {
&self.context
}
pub fn start(&self) {
start_server(self.context.clone());
}
}
impl Default for Server {
fn default() -> Self {
Self {
context: Arc::new(ServerContext::new(Arc::new(Config::default()))),
}
}
}

View File

@ -2,7 +2,7 @@ use std::{env::args, path::PathBuf, sync::Arc};
use log::{debug, error, info};
use rust_mc_proto::Packet;
use server::{
use rust_mc_serv::{
ServerError,
config::Config,
context::ServerContext,
@ -13,8 +13,6 @@ use server::{
start_server,
};
pub mod server;
struct ExampleListener;
impl Listener for ExampleListener {

View File

@ -13,9 +13,8 @@ use std::{
use rust_mc_proto::{MinecraftConnection, Packet};
use uuid::Uuid;
use crate::server::{ServerError, context::ServerContext, protocol::ConnectionState};
use super::helper::ProtocolHelper;
use crate::{ServerError, context::ServerContext, protocol::ConnectionState};
// Клиент контекст
// Должен быть обернут в Arc для передачи между потоками

View File

@ -6,7 +6,7 @@ use std::{
use rust_mc_proto::{DataReader, DataWriter, Packet};
use crate::server::{
use crate::{
ServerError,
data::{ReadWriteNBT, text_component::TextComponent},
protocol::{

View File

@ -1,6 +1,6 @@
use std::{io::Read, sync::Arc};
use crate::server::{
use crate::{
ServerError,
player::context::{ClientContext, ClientInfo, Handshake, PlayerInfo},
};

View File

@ -7,7 +7,7 @@ use std::{
use rust_mc_proto::{DataReader, DataWriter, Packet, read_packet};
use crate::server::{
use crate::{
ServerError,
data::{ReadWriteNBT, text_component::TextComponent},
player::context::ClientContext,