Skip to content

Commit

Permalink
Moved config into its own crate
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniD3v committed Aug 31, 2024
1 parent a17ed23 commit 070a508
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 29 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = [ "pumpkin-core", "pumpkin-entity", "pumpkin-inventory", "pumpkin-macros/", "pumpkin-plugin", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"]
members = [ "pumpkin-config", "pumpkin-core", "pumpkin-entity", "pumpkin-inventory", "pumpkin-macros/", "pumpkin-plugin", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"]

[workspace.package]
version = "0.1.0"
Expand Down
12 changes: 12 additions & 0 deletions pumpkin-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "pumpkin-config"
version.workspace = true
edition.workspace = true

[dependencies]
pumpkin-core = { path = "../pumpkin-core" }

serde = "1.0"
toml = "0.8"

log.workspace = true
3 changes: 1 addition & 2 deletions pumpkin/src/config/auth.rs → pumpkin-config/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use pumpkin_core::ProfileAction;
use serde::{Deserialize, Serialize};

use crate::client::authentication::ProfileAction;

#[derive(Deserialize, Serialize)]
pub struct AuthenticationConfig {
/// Whether to use Mojang authentication.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions pumpkin-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ pub enum Difficulty {
Normal,
Hard,
}

#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ProfileAction {
ForcedNameChange,
UsingBannedSkin,
}
1 change: 1 addition & 0 deletions pumpkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ default = []
[dependencies]
# pumpkin
pumpkin-core = { path = "../pumpkin-core"}
pumpkin-config = { path = "../pumpkin-config" }
pumpkin-plugin = { path = "../pumpkin-plugin"}
pumpkin-inventory = { path = "../pumpkin-inventory"}
pumpkin-world = { path = "../pumpkin-world"}
Expand Down
17 changes: 4 additions & 13 deletions pumpkin/src/client/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ use std::{collections::HashMap, net::IpAddr};

use base64::{engine::general_purpose, Engine};
use num_bigint::BigInt;
use pumpkin_config::{auth::TextureConfig, ADVANCED_CONFIG};
use pumpkin_core::ProfileAction;
use pumpkin_protocol::Property;
use reqwest::{StatusCode, Url};
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use thiserror::Error;
use uuid::Uuid;

use crate::{
config::{auth::TextureConfig, ADVANCED_CONFIG},
server::Server,
};
use crate::server::Server;

#[derive(Deserialize, Clone, Debug)]
#[allow(non_snake_case)]
Expand All @@ -32,14 +31,6 @@ pub struct Texture {
metadata: Option<HashMap<String, String>>,
}

#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
pub enum ProfileAction {
#[serde(rename = "FORCED_NAME_CHANGE")]
ForcedNameChange,
#[serde(rename = "USING_BANNED_SKIN")]
UsingBannedSkin,
}

#[derive(Deserialize, Clone, Debug)]
pub struct GameProfile {
pub id: Uuid,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/client/client_packet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use num_traits::FromPrimitive;
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
use pumpkin_core::text::TextComponent;
use pumpkin_protocol::{
client::{
Expand All @@ -19,7 +20,6 @@ use sha1::{Digest, Sha1};

use crate::{
client::authentication::{self, GameProfile},
config::{ADVANCED_CONFIG, BASIC_CONFIG},
entity::player::{ChatMode, Hand},
proxy::velocity::velocity_login,
server::{Server, CURRENT_MC_VERSION},
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::f32::consts::PI;

use crate::{
commands::{handle_command, CommandSender},
config::ADVANCED_CONFIG,
entity::player::{ChatMode, Hand, Player},
server::Server,
util::math::wrap_degrees,
};
use num_traits::FromPrimitive;
use pumpkin_config::ADVANCED_CONFIG;
use pumpkin_core::{text::TextComponent, GameMode};
use pumpkin_entity::EntityId;
use pumpkin_inventory::WindowType;
Expand Down
3 changes: 1 addition & 2 deletions pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use server::Server;

pub mod client;
pub mod commands;
pub mod config;
pub mod entity;
pub mod proxy;
pub mod rcon;
Expand All @@ -29,8 +28,8 @@ pub mod world;
fn main() -> io::Result<()> {
use std::sync::{Arc, Mutex};

use config::{ADVANCED_CONFIG, BASIC_CONFIG};
use entity::player::Player;
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
use pumpkin_core::text::{color::NamedColor, TextComponent};
use rcon::RCONServer;

Expand Down
3 changes: 2 additions & 1 deletion pumpkin/src/proxy/velocity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use std::net::SocketAddr;

use bytes::{BufMut, BytesMut};
use hmac::{Hmac, Mac};
use pumpkin_config::proxy::VelocityConfig;
use pumpkin_protocol::{
bytebuf::ByteBuffer, client::login::CLoginPluginRequest, server::login::SLoginPluginResponse,
};
use sha2::Sha256;

use crate::{client::Client, config::proxy::VelocityConfig};
use crate::client::Client;

type HmacSha256 = Hmac<Sha256>;

Expand Down
3 changes: 2 additions & 1 deletion pumpkin/src/rcon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use mio::{
Events, Interest, Poll, Token,
};
use packet::{Packet, PacketError, PacketType};
use pumpkin_config::RCONConfig;
use thiserror::Error;

use crate::{commands::handle_command, config::RCONConfig, server::Server};
use crate::{commands::handle_command, server::Server};

mod packet;

Expand Down
8 changes: 2 additions & 6 deletions pumpkin/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
use base64::{engine::general_purpose, Engine};
use image::GenericImageView;
use mio::Token;
use pumpkin_config::{BasicConfiguration, BASIC_CONFIG};
use pumpkin_core::GameMode;
use pumpkin_entity::EntityId;
use pumpkin_plugin::PluginLoader;
Expand All @@ -23,12 +24,7 @@ use pumpkin_world::dimension::Dimension;
use pumpkin_registry::Registry;
use rsa::{traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};

use crate::{
client::Client,
config::{BasicConfiguration, BASIC_CONFIG},
entity::player::Player,
world::World,
};
use crate::{client::Client, entity::player::Player, world::World};

pub const CURRENT_MC_VERSION: &str = "1.21.1";

Expand Down
3 changes: 2 additions & 1 deletion pumpkin/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{

use mio::Token;
use num_traits::ToPrimitive;
use pumpkin_config::BasicConfiguration;
use pumpkin_entity::{entity_type::EntityType, EntityId};
use pumpkin_protocol::{
client::play::{
Expand All @@ -19,7 +20,7 @@ use pumpkin_protocol::{
use pumpkin_world::{level::Level, radial_chunk_iterator::RadialIterator};
use tokio::sync::mpsc;

use crate::{config::BasicConfiguration, entity::player::Player};
use crate::entity::player::Player;

pub struct World {
pub level: Arc<Mutex<Level>>,
Expand Down

0 comments on commit 070a508

Please sign in to comment.