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,
|
||||
|
||||
@@ -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,
|
||||
@@ -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!");
|
||||
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
|
||||
}
|
||||
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!");
|
||||
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
|
||||
}
|
||||
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,24 +12,20 @@ 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();
|
||||
|
||||
// Create a poll instance.
|
||||
@@ -99,7 +93,9 @@ fn main() -> io::Result<()> {
|
||||
|
||||
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)?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user