mirror of
https://github.com/GIKExe/rust_mc_serv.git
synced 2025-06-24 10:22:57 +03:00
crate
This commit is contained in:
parent
3788bc36dd
commit
db89af6c07
@ -5,7 +5,7 @@ use rust_mc_proto::Packet;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
|
|
||||||
use crate::server::ServerError;
|
use crate::ServerError;
|
||||||
|
|
||||||
use super::ReadWriteNBT;
|
use super::ReadWriteNBT;
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
use rust_mc_proto::Packet;
|
use rust_mc_proto::Packet;
|
||||||
|
|
||||||
use super::protocol::ConnectionState;
|
use super::{ServerError, player::context::ClientContext, protocol::ConnectionState};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! generate_handlers {
|
macro_rules! generate_handlers {
|
||||||
@ -10,7 +11,7 @@ macro_rules! generate_handlers {
|
|||||||
0
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
use std::{error::Error, fmt::Display, net::TcpListener, sync::Arc, thread, time::Duration};
|
use std::{error::Error, fmt::Display, net::TcpListener, sync::Arc, thread, time::Duration};
|
||||||
|
|
||||||
|
use config::Config;
|
||||||
use context::ServerContext;
|
use context::ServerContext;
|
||||||
use ignore_result::Ignore;
|
use ignore_result::Ignore;
|
||||||
use log::{error, info};
|
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()))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ use std::{env::args, path::PathBuf, sync::Arc};
|
|||||||
|
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
use rust_mc_proto::Packet;
|
use rust_mc_proto::Packet;
|
||||||
use server::{
|
use rust_mc_serv::{
|
||||||
ServerError,
|
ServerError,
|
||||||
config::Config,
|
config::Config,
|
||||||
context::ServerContext,
|
context::ServerContext,
|
||||||
@ -13,8 +13,6 @@ use server::{
|
|||||||
start_server,
|
start_server,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod server;
|
|
||||||
|
|
||||||
struct ExampleListener;
|
struct ExampleListener;
|
||||||
|
|
||||||
impl Listener for ExampleListener {
|
impl Listener for ExampleListener {
|
||||||
|
@ -13,9 +13,8 @@ use std::{
|
|||||||
use rust_mc_proto::{MinecraftConnection, Packet};
|
use rust_mc_proto::{MinecraftConnection, Packet};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::server::{ServerError, context::ServerContext, protocol::ConnectionState};
|
|
||||||
|
|
||||||
use super::helper::ProtocolHelper;
|
use super::helper::ProtocolHelper;
|
||||||
|
use crate::{ServerError, context::ServerContext, protocol::ConnectionState};
|
||||||
|
|
||||||
// Клиент контекст
|
// Клиент контекст
|
||||||
// Должен быть обернут в Arc для передачи между потоками
|
// Должен быть обернут в Arc для передачи между потоками
|
@ -6,7 +6,7 @@ use std::{
|
|||||||
|
|
||||||
use rust_mc_proto::{DataReader, DataWriter, Packet};
|
use rust_mc_proto::{DataReader, DataWriter, Packet};
|
||||||
|
|
||||||
use crate::server::{
|
use crate::{
|
||||||
ServerError,
|
ServerError,
|
||||||
data::{ReadWriteNBT, text_component::TextComponent},
|
data::{ReadWriteNBT, text_component::TextComponent},
|
||||||
protocol::{
|
protocol::{
|
@ -1,6 +1,6 @@
|
|||||||
use std::{io::Read, sync::Arc};
|
use std::{io::Read, sync::Arc};
|
||||||
|
|
||||||
use crate::server::{
|
use crate::{
|
||||||
ServerError,
|
ServerError,
|
||||||
player::context::{ClientContext, ClientInfo, Handshake, PlayerInfo},
|
player::context::{ClientContext, ClientInfo, Handshake, PlayerInfo},
|
||||||
};
|
};
|
@ -7,7 +7,7 @@ use std::{
|
|||||||
|
|
||||||
use rust_mc_proto::{DataReader, DataWriter, Packet, read_packet};
|
use rust_mc_proto::{DataReader, DataWriter, Packet, read_packet};
|
||||||
|
|
||||||
use crate::server::{
|
use crate::{
|
||||||
ServerError,
|
ServerError,
|
||||||
data::{ReadWriteNBT, text_component::TextComponent},
|
data::{ReadWriteNBT, text_component::TextComponent},
|
||||||
player::context::ClientContext,
|
player::context::ClientContext,
|
Loading…
x
Reference in New Issue
Block a user