mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
Added configuration
This commit is contained in:
@@ -29,5 +29,6 @@ byteorder = "1"
|
||||
mio = { version = "1.0.1", features = ["os-poll", "net"]}
|
||||
crossbeam-channel = "0.5.13"
|
||||
uuid = "1.10"
|
||||
toml = "0.8.17"
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::{rc::Rc, sync::Mutex};
|
||||
|
||||
use crate::protocol::{
|
||||
client::{
|
||||
|
||||
116
pumpkin/src/configuration.rs
Normal file
116
pumpkin/src/configuration.rs
Normal file
@@ -0,0 +1,116 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct BasicConfiguration {
|
||||
pub server_address: String,
|
||||
pub server_port: u16,
|
||||
pub seed: String,
|
||||
pub max_plyers: i32,
|
||||
pub view_distances: u8,
|
||||
pub simulation_distance: u8,
|
||||
pub resource_pack: String,
|
||||
pub resource_pack_sha1: String,
|
||||
pub default_difficulty: Difficulty,
|
||||
pub allow_nether: bool,
|
||||
pub hardcore: bool,
|
||||
pub online_mode: bool,
|
||||
pub spawn_protection: u32,
|
||||
pub motd: String,
|
||||
}
|
||||
|
||||
impl Default for BasicConfiguration {
|
||||
fn default() -> Self {
|
||||
|
||||
Self {
|
||||
server_address: "127.0.0.1".to_string(),
|
||||
server_port: 25565,
|
||||
seed: "".to_string(),
|
||||
max_plyers: -1,
|
||||
view_distances: 10,
|
||||
simulation_distance: 10,
|
||||
resource_pack: "".to_string(),
|
||||
resource_pack_sha1: "".to_string(),
|
||||
default_difficulty: Difficulty::Normal,
|
||||
allow_nether: true,
|
||||
hardcore: false,
|
||||
online_mode: true,
|
||||
spawn_protection: 16,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{
|
||||
client::Client,
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
use mio::net::TcpListener;
|
||||
use mio::{Events, Interest, Poll, Token};
|
||||
use std::collections::HashMap;
|
||||
use std::io::{self};
|
||||
|
||||
use std::{
|
||||
sync::{Arc, Mutex}
|
||||
};
|
||||
|
||||
use client::{interrupted};
|
||||
use configuration::BasicConfiguration;
|
||||
use server::Server;
|
||||
|
||||
// Setup some tokens to allow us to identify which event is for which socket.
|
||||
const SERVER: Token = Token(0);
|
||||
|
||||
@@ -11,16 +18,19 @@ 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 std::{
|
||||
rc::Rc,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use configuration::AdvancedConfiguration;
|
||||
|
||||
use client::{interrupted, Client};
|
||||
use server::Server;
|
||||
|
||||
|
||||
let basic_config = BasicConfiguration::load("configuration.toml");
|
||||
|
||||
|
||||
let advanced_configuration = AdvancedConfiguration::load("features.toml");
|
||||
|
||||
|
||||
simple_logger::SimpleLogger::new().init().unwrap();
|
||||
|
||||
@@ -42,8 +52,8 @@ fn main() -> io::Result<()> {
|
||||
|
||||
log::info!("You now can connect to the server");
|
||||
|
||||
let mut server = Arc::new(Mutex::new(Server::new()));
|
||||
|
||||
let server = Arc::new(Mutex::new(Server::new()));
|
||||
|
||||
loop {
|
||||
if let Err(err) = poll.poll(&mut events, None) {
|
||||
if interrupted(&err) {
|
||||
|
||||
@@ -11,6 +11,7 @@ use std::{
|
||||
use base64::{engine::general_purpose, Engine};
|
||||
use mio::{net::TcpStream, Token};
|
||||
use rsa::{rand_core::OsRng, traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
client::Client,
|
||||
@@ -163,8 +164,9 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(PartialEq, Serialize, Deserialize)]
|
||||
pub enum Difficulty {
|
||||
Peaceful,
|
||||
Easy,
|
||||
Normal,
|
||||
Hard,
|
||||
|
||||
Reference in New Issue
Block a user