mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
81
Cargo.lock
generated
81
Cargo.lock
generated
@@ -187,6 +187,12 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "equivalent"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fdeflate"
|
name = "fdeflate"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
@@ -227,6 +233,12 @@ dependencies = [
|
|||||||
"wasi",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@@ -245,6 +257,16 @@ dependencies = [
|
|||||||
"png",
|
"png",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "2.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
||||||
|
dependencies = [
|
||||||
|
"equivalent",
|
||||||
|
"hashbrown",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inout"
|
name = "inout"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
@@ -287,6 +309,12 @@ version = "0.4.21"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.7.4"
|
version = "0.7.4"
|
||||||
@@ -467,6 +495,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"simple_logger",
|
"simple_logger",
|
||||||
|
"toml",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -575,6 +604,15 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "0.6.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signature"
|
name = "signature"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
@@ -707,6 +745,40 @@ dependencies = [
|
|||||||
"time-core",
|
"time-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.8.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a44eede9b727419af8095cb2d72fab15487a541f54647ad4414b34096ee4631"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_edit",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_datetime"
|
||||||
|
version = "0.6.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.22.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1490595c74d930da779e944f5ba2ecdf538af67df1a9848cbd156af43c1b7cf0"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"winnow",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.17.0"
|
version = "1.17.0"
|
||||||
@@ -876,6 +948,15 @@ version = "0.52.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winnow"
|
||||||
|
version = "0.6.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zeroize"
|
name = "zeroize"
|
||||||
version = "1.8.1"
|
version = "1.8.1"
|
||||||
|
|||||||
@@ -29,5 +29,6 @@ byteorder = "1"
|
|||||||
mio = { version = "1.0.1", features = ["os-poll", "net"]}
|
mio = { version = "1.0.1", features = ["os-poll", "net"]}
|
||||||
crossbeam-channel = "0.5.13"
|
crossbeam-channel = "0.5.13"
|
||||||
uuid = "1.10"
|
uuid = "1.10"
|
||||||
|
toml = "0.8.17"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use std::{rc::Rc, sync::Mutex};
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
client::{
|
client::{
|
||||||
config::CFinishConfig,
|
config::CFinishConfig,
|
||||||
@@ -44,7 +42,7 @@ impl ClientPacketProcessor for Client {
|
|||||||
dbg!("sending status");
|
dbg!("sending status");
|
||||||
|
|
||||||
dbg!("test first");
|
dbg!("test first");
|
||||||
|
|
||||||
let guard = self.server.try_lock().unwrap();
|
let guard = self.server.try_lock().unwrap();
|
||||||
dbg!("test");
|
dbg!("test");
|
||||||
|
|
||||||
|
|||||||
93
pumpkin/src/configuration.rs
Normal file
93
pumpkin/src/configuration.rs
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
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,5 +1,3 @@
|
|||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::Client,
|
client::Client,
|
||||||
protocol::{ClientPacket, RawPacket, VarInt},
|
protocol::{ClientPacket, RawPacket, VarInt},
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
use mio::net::TcpListener;
|
use mio::net::TcpListener;
|
||||||
use mio::{Events, Interest, Poll, Token};
|
use mio::{Events, Interest, Poll, Token};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::io::{self};
|
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.
|
// Setup some tokens to allow us to identify which event is for which socket.
|
||||||
const SERVER: Token = Token(0);
|
const SERVER: Token = Token(0);
|
||||||
|
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
pub mod configuration;
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod protocol;
|
pub mod protocol;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
@@ -14,13 +20,11 @@ pub mod util;
|
|||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
#[cfg(not(target_os = "wasi"))]
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
use std::{
|
use configuration::AdvancedConfiguration;
|
||||||
rc::Rc,
|
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
|
||||||
|
|
||||||
use client::{interrupted, Client};
|
let basic_config = BasicConfiguration::load("configuration.toml");
|
||||||
use server::Server;
|
|
||||||
|
let advanced_configuration = AdvancedConfiguration::load("features.toml");
|
||||||
|
|
||||||
simple_logger::SimpleLogger::new().init().unwrap();
|
simple_logger::SimpleLogger::new().init().unwrap();
|
||||||
|
|
||||||
@@ -42,7 +46,7 @@ fn main() -> io::Result<()> {
|
|||||||
|
|
||||||
log::info!("You now can connect to the server");
|
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 {
|
loop {
|
||||||
if let Err(err) = poll.poll(&mut events, None) {
|
if let Err(err) = poll.poll(&mut events, None) {
|
||||||
@@ -86,10 +90,12 @@ fn main() -> io::Result<()> {
|
|||||||
let mut guard = server.try_lock().unwrap();
|
let mut guard = server.try_lock().unwrap();
|
||||||
guard.new_client(rc_server, connection, token);
|
guard.new_client(rc_server, connection, token);
|
||||||
},
|
},
|
||||||
|
|
||||||
token => {
|
token => {
|
||||||
// Maybe received an event for a TCP connection.
|
// 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.poll(poll.registry(), event).unwrap();
|
||||||
client.closed
|
client.closed
|
||||||
} else {
|
} else {
|
||||||
@@ -97,7 +103,9 @@ fn main() -> io::Result<()> {
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
if done {
|
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)?;
|
poll.registry().deregister(&mut client.connection)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ pub type VarLong = i64;
|
|||||||
pub enum ConnectionState {
|
pub enum ConnectionState {
|
||||||
HandShake,
|
HandShake,
|
||||||
Status,
|
Status,
|
||||||
Login,
|
Login,
|
||||||
Transfer,
|
Transfer,
|
||||||
Config,
|
Config,
|
||||||
Play,
|
Play,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use std::{
|
|||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{engine::general_purpose, Engine};
|
||||||
use mio::{net::TcpStream, Token};
|
use mio::{net::TcpStream, Token};
|
||||||
use rsa::{rand_core::OsRng, traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
use rsa::{rand_core::OsRng, traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::Client,
|
client::Client,
|
||||||
@@ -163,8 +164,9 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq, Serialize, Deserialize)]
|
||||||
pub enum Difficulty {
|
pub enum Difficulty {
|
||||||
|
Peaceful,
|
||||||
Easy,
|
Easy,
|
||||||
Normal,
|
Normal,
|
||||||
Hard,
|
Hard,
|
||||||
|
|||||||
Reference in New Issue
Block a user