mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
Format
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
use crate::protocol::{
|
||||
client::{
|
||||
config::CFinishConfig,
|
||||
@@ -43,7 +42,7 @@ impl ClientPacketProcessor for Client {
|
||||
dbg!("sending status");
|
||||
|
||||
dbg!("test first");
|
||||
|
||||
|
||||
let guard = self.server.try_lock().unwrap();
|
||||
dbg!("test");
|
||||
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
use std::{path::Path};
|
||||
use std::path::Path;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::server::Difficulty;
|
||||
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct AdvancedConfiguration {
|
||||
|
||||
liquid_physics: bool,
|
||||
encryption: bool,
|
||||
|
||||
}
|
||||
|
||||
impl Default for AdvancedConfiguration {
|
||||
fn default() -> Self {
|
||||
|
||||
|
||||
Self {
|
||||
liquid_physics: true,
|
||||
encryption: true,
|
||||
@@ -27,7 +22,7 @@ impl Default for AdvancedConfiguration {
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct BasicConfiguration {
|
||||
pub server_address: String,
|
||||
pub server_port: u16,
|
||||
pub server_port: u16,
|
||||
pub seed: String,
|
||||
pub max_plyers: i32,
|
||||
pub view_distances: u8,
|
||||
@@ -44,7 +39,6 @@ pub struct BasicConfiguration {
|
||||
|
||||
impl Default for BasicConfiguration {
|
||||
fn default() -> Self {
|
||||
|
||||
Self {
|
||||
server_address: "127.0.0.1".to_string(),
|
||||
server_port: 25565,
|
||||
@@ -62,55 +56,38 @@ impl Default for BasicConfiguration {
|
||||
motd: "A Blazing fast Pumpkin Server!".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl AdvancedConfiguration {
|
||||
|
||||
pub fn load<P: AsRef<Path>>(path: P) -> AdvancedConfiguration {
|
||||
if path.as_ref().exists() {
|
||||
let toml = std::fs::read_to_string(path).expect("Couldn't read configuration");
|
||||
let configuration: AdvancedConfiguration = toml::from_str(toml.as_str()).expect("Couldn't parse");
|
||||
configuration
|
||||
} else {
|
||||
let config = AdvancedConfiguration::default();
|
||||
let toml = toml::to_string(&config).expect("Couldn't create toml!");
|
||||
|
||||
std::fs::write(path, toml).expect("Couldn't save configuration");
|
||||
config
|
||||
}
|
||||
if path.as_ref().exists() {
|
||||
let toml = std::fs::read_to_string(path).expect("Couldn't read configuration");
|
||||
let configuration: AdvancedConfiguration =
|
||||
toml::from_str(toml.as_str()).expect("Couldn't parse");
|
||||
configuration
|
||||
} else {
|
||||
let config = AdvancedConfiguration::default();
|
||||
let toml = toml::to_string(&config).expect("Couldn't create toml!");
|
||||
|
||||
std::fs::write(path, toml).expect("Couldn't save configuration");
|
||||
config
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl BasicConfiguration {
|
||||
|
||||
pub fn load<P: AsRef<Path>>(path: P) -> BasicConfiguration {
|
||||
if path.as_ref().exists() {
|
||||
let toml = std::fs::read_to_string(path).expect("Couldn't read configuration");
|
||||
let configuration: BasicConfiguration = toml::from_str(toml.as_str()).expect("Couldn't parse");
|
||||
configuration
|
||||
} else {
|
||||
let config = BasicConfiguration::default();
|
||||
let toml = toml::to_string(&config).expect("Couldn't create toml!");
|
||||
|
||||
std::fs::write(path, toml).expect("Couldn't save configuration");
|
||||
config
|
||||
}
|
||||
if path.as_ref().exists() {
|
||||
let toml = std::fs::read_to_string(path).expect("Couldn't read configuration");
|
||||
let configuration: BasicConfiguration =
|
||||
toml::from_str(toml.as_str()).expect("Couldn't parse");
|
||||
configuration
|
||||
} else {
|
||||
let config = BasicConfiguration::default();
|
||||
let toml = toml::to_string(&config).expect("Couldn't create toml!");
|
||||
|
||||
std::fs::write(path, toml).expect("Couldn't save configuration");
|
||||
config
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
use crate::{
|
||||
client::Client,
|
||||
protocol::{ClientPacket, RawPacket, VarInt},
|
||||
|
||||
@@ -2,11 +2,9 @@ use mio::net::TcpListener;
|
||||
use mio::{Events, Interest, Poll, Token};
|
||||
use std::io::{self};
|
||||
|
||||
use std::{
|
||||
sync::{Arc, Mutex}
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use client::{interrupted};
|
||||
use client::interrupted;
|
||||
use configuration::BasicConfiguration;
|
||||
use server::Server;
|
||||
|
||||
@@ -14,23 +12,19 @@ use server::Server;
|
||||
const SERVER: Token = Token(0);
|
||||
|
||||
pub mod client;
|
||||
pub mod configuration;
|
||||
pub mod entity;
|
||||
pub mod protocol;
|
||||
pub mod server;
|
||||
pub mod util;
|
||||
pub mod configuration;
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
fn main() -> io::Result<()> {
|
||||
use configuration::AdvancedConfiguration;
|
||||
|
||||
|
||||
|
||||
let basic_config = BasicConfiguration::load("configuration.toml");
|
||||
|
||||
|
||||
|
||||
let advanced_configuration = AdvancedConfiguration::load("features.toml");
|
||||
|
||||
|
||||
simple_logger::SimpleLogger::new().init().unwrap();
|
||||
|
||||
@@ -53,7 +47,7 @@ fn main() -> io::Result<()> {
|
||||
log::info!("You now can connect to the server");
|
||||
|
||||
let server = Arc::new(Mutex::new(Server::new()));
|
||||
|
||||
|
||||
loop {
|
||||
if let Err(err) = poll.poll(&mut events, None) {
|
||||
if interrupted(&err) {
|
||||
@@ -96,10 +90,12 @@ fn main() -> io::Result<()> {
|
||||
let mut guard = server.try_lock().unwrap();
|
||||
guard.new_client(rc_server, connection, token);
|
||||
},
|
||||
|
||||
|
||||
token => {
|
||||
// Maybe received an event for a TCP connection.
|
||||
let done = if let Some(client) = server.try_lock().unwrap().connections.get_mut(&token) {
|
||||
let done = if let Some(client) =
|
||||
server.try_lock().unwrap().connections.get_mut(&token)
|
||||
{
|
||||
client.poll(poll.registry(), event).unwrap();
|
||||
client.closed
|
||||
} else {
|
||||
@@ -107,7 +103,9 @@ fn main() -> io::Result<()> {
|
||||
false
|
||||
};
|
||||
if done {
|
||||
if let Some(mut client) = server.try_lock().unwrap().connections.remove(&token) {
|
||||
if let Some(mut client) =
|
||||
server.try_lock().unwrap().connections.remove(&token)
|
||||
{
|
||||
poll.registry().deregister(&mut client.connection)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ pub type VarLong = i64;
|
||||
pub enum ConnectionState {
|
||||
HandShake,
|
||||
Status,
|
||||
Login,
|
||||
Login,
|
||||
Transfer,
|
||||
Config,
|
||||
Play,
|
||||
|
||||
Reference in New Issue
Block a user