@@ -5,7 +5,6 @@ use pumpkin_util::{Difficulty, GameMode, PermissionLvl, random};
55use recipe:: RecipeConfig ;
66use serde:: { Deserialize , Serialize , de:: DeserializeOwned } ;
77
8- use std:: net:: SocketAddr ;
98use std:: path:: PathBuf ;
109use std:: { fs, num:: NonZeroU8 , path:: Path } ;
1110use tracing:: { debug, warn} ;
@@ -20,7 +19,9 @@ pub mod resource_pack;
2019pub use chat:: ChatConfig ;
2120pub use commands:: CommandsConfig ;
2221pub use networking:: auth:: AuthenticationConfig ;
22+ pub use networking:: bedrock:: BedrockConfig ;
2323pub use networking:: compression:: CompressionConfig ;
24+ pub use networking:: java:: JavaConfig ;
2425pub use networking:: lan_broadcast:: LANBroadcastConfig ;
2526pub use networking:: rcon:: RCONConfig ;
2627pub use plugins:: PluginsConfig ;
@@ -64,6 +65,48 @@ impl LoadConfiguration for PumpkinConfig {
6465 fn validate ( & self ) {
6566 self . basic . validate ( ) ;
6667 self . advanced . validate ( ) ;
68+
69+ let min_vd = NonZeroU8 :: new ( 2 ) . unwrap ( ) ;
70+ let max_vd = NonZeroU8 :: new ( 64 ) . unwrap ( ) ;
71+
72+ // Validate Java
73+ assert ! (
74+ self . advanced. networking. java. view_distance >= min_vd,
75+ "Java View distance must be at least 2"
76+ ) ;
77+ assert ! (
78+ self . advanced. networking. java. view_distance <= max_vd,
79+ "Java View distance must be less than 64"
80+ ) ;
81+ if self . advanced . networking . java . online_mode {
82+ assert ! (
83+ self . advanced. networking. java. encryption,
84+ "When online mode is enabled, encryption must be enabled"
85+ ) ;
86+ }
87+
88+ // Validate Bedrock
89+ assert ! (
90+ self . advanced. networking. bedrock. view_distance >= min_vd,
91+ "Bedrock View distance must be at least 2"
92+ ) ;
93+ assert ! (
94+ self . advanced. networking. bedrock. view_distance <= max_vd,
95+ "Bedrock View distance must be less than 64"
96+ ) ;
97+ if self . advanced . networking . bedrock . online_mode {
98+ assert ! (
99+ self . advanced. networking. bedrock. encryption,
100+ "When online mode is enabled, bedrock_encryption must be enabled"
101+ ) ;
102+ }
103+
104+ if self . basic . allow_chat_reports {
105+ assert ! (
106+ self . advanced. networking. java. online_mode,
107+ "When allow_chat_reports is enabled, java.online_mode must be enabled"
108+ ) ;
109+ }
67110 }
68111}
69112
@@ -110,24 +153,8 @@ pub struct AdvancedConfiguration {
110153#[ derive( Serialize , Deserialize ) ]
111154#[ serde( default ) ]
112155pub struct BasicConfiguration {
113- /// Whether Java Edition Clients are Accepted.
114- pub java_edition : bool ,
115- /// The address and port to which the Java Edition server will bind.
116- pub java_edition_address : SocketAddr ,
117- /// Whether Bedrock Edition Clients are Accepted.
118- pub bedrock_edition : bool ,
119- /// Whether Bedrock Edition Clients are Accepted.
120- pub bedrock_edition_address : SocketAddr ,
121- /// Whether packet encryption is enabled for Bedrock Edition.
122- pub bedrock_encryption : bool ,
123156 /// The seed for the world generation.
124157 pub seed : Seed ,
125- /// The maximum number of players allowed on the server. Specifying `0` disables the limit.
126- pub max_players : u32 ,
127- /// The maximum view distance for players.
128- pub view_distance : NonZeroU8 ,
129- /// The maximum simulated view distance.
130- pub simulation_distance : NonZeroU8 ,
131158 /// The default game difficulty.
132159 pub default_difficulty : Difficulty ,
133160 /// The op level assigned by the /op command.
@@ -138,12 +165,6 @@ pub struct BasicConfiguration {
138165 pub allow_end : bool ,
139166 /// Whether the server is in hardcore mode.
140167 pub hardcore : bool ,
141- /// Whether online mode is enabled. Requires valid Minecraft accounts.
142- pub online_mode : bool ,
143- /// Whether packet encryption is enabled. Required when online mode is enabled.
144- pub encryption : bool ,
145- /// Message of the Day; the server's description displayed on the status screen.
146- pub motd : String ,
147168 /// The server's ticks per second.
148169 pub tps : f32 ,
149170 /// The default gamemode for players.
@@ -169,23 +190,12 @@ pub struct BasicConfiguration {
169190impl Default for BasicConfiguration {
170191 fn default ( ) -> Self {
171192 Self {
172- java_edition : true ,
173- java_edition_address : "0.0.0.0:25565" . parse ( ) . unwrap ( ) ,
174- bedrock_edition : true ,
175- bedrock_edition_address : "0.0.0.0:19132" . parse ( ) . unwrap ( ) ,
176- bedrock_encryption : true ,
177193 seed : Seed ( random:: get_seed ( ) ) ,
178- max_players : 1000 ,
179- view_distance : NonZeroU8 :: new ( 16 ) . unwrap ( ) ,
180- simulation_distance : NonZeroU8 :: new ( 10 ) . unwrap ( ) ,
181194 default_difficulty : Difficulty :: Normal ,
182195 op_permission_level : PermissionLvl :: Four ,
183196 allow_nether : true ,
184197 allow_end : true ,
185198 hardcore : false ,
186- online_mode : true ,
187- encryption : true ,
188- motd : "A blazingly fast Pumpkin server!" . to_string ( ) ,
189199 tps : 20.0 ,
190200 default_gamemode : GameMode :: Survival ,
191201 force_gamemode : false ,
@@ -207,35 +217,7 @@ impl BasicConfiguration {
207217 PathBuf :: from ( & self . default_level_name )
208218 }
209219
210- pub fn validate ( & self ) {
211- let min = NonZeroU8 :: new ( 2 ) . unwrap ( ) ;
212- let max = NonZeroU8 :: new ( 64 ) . unwrap ( ) ;
213-
214- assert ! (
215- self . view_distance. ge( & min) ,
216- "View distance must be at least 2"
217- ) ;
218- assert ! (
219- self . view_distance. le( & max) ,
220- "View distance must be less than 64"
221- ) ;
222- if self . online_mode {
223- assert ! (
224- self . encryption,
225- "When online mode is enabled, encryption must be enabled"
226- ) ;
227- assert ! (
228- self . bedrock_encryption,
229- "When online mode is enabled, bedrock_encryption must be enabled"
230- ) ;
231- }
232- if self . allow_chat_reports {
233- assert ! (
234- self . online_mode,
235- "When allow_chat_reports is enabled, online_mode must be enabled"
236- ) ;
237- }
238- }
220+ pub const fn validate ( & self ) { }
239221}
240222
241223impl AdvancedConfiguration {
0 commit comments