documentation improvements
This commit is contained in:
parent
9e634295ca
commit
530a5c8667
@ -21,14 +21,43 @@ Packets in the Pumpkin protocol are organized by functionality and state.
|
|||||||
### How to add a Packet ?
|
### How to add a Packet ?
|
||||||
You can find all Minecraft Java packets at https://wiki.vg/Protocol. There you also can see in which [State](State) they are.
|
You can find all Minecraft Java packets at https://wiki.vg/Protocol. There you also can see in which [State](State) they are.
|
||||||
You also can see all the information the Packets has which we can either Write or Read depending if its Serverbound or Clientbound
|
You also can see all the information the Packets has which we can either Write or Read depending if its Serverbound or Clientbound
|
||||||
#### Adding a Serverbound Packet
|
#### Adding a Packet
|
||||||
Serverbound Packets do use the trait `ServerPacket` which has an packet id (use hex) and can read incoming Client packets.
|
Adding a Packet is easy. First you have to dereive serde Serialize.
|
||||||
https://wiki.vg/Protocol gives you the Packet structure which you can than read. Feel free to orientate on already existing Packets.
|
```rust
|
||||||
Please use a name structure like `SPacketName` for the struct, The 'S' representing its Serverbound.
|
#[derive(Serialize)]
|
||||||
Registering: Don't forget to register the Packet. All Packets before the Player is created so before the Play state. Are using the `ClientPacketProcessor` which calls the packet at `Client::handle_packet` (both in the pumpkin crate)
|
```
|
||||||
#### Adding a Clientbound Packet
|
Next you have set the packet id using the packet macro
|
||||||
Clientbound Packets do use the trait `ClientPacket` which has an packet id (use hex) and can write outgoining Server packets.
|
```rust
|
||||||
https://wiki.vg/Protocol gives you the Packet structure which you can than write. Feel free to orientate on already existing Packets.
|
#[packet(0x1D)]
|
||||||
Please use a name structure like `CPacketName` for the struct, The 'C' representing its Clientbound.
|
```
|
||||||
You don't need to register the Packet anywhere, You should just be able now to send it via `Client::send_packet` this will get a result. You should kick the client when an important Packet could't been send. Otherwise
|
Now you can create the Field. Please start the Packet name with "C" if its Clientbound and with "S" if its Serverbound.
|
||||||
just log an warn.
|
Example:
|
||||||
|
```rust
|
||||||
|
pub struct CPlayDisconnect {
|
||||||
|
reason: TextComponent,
|
||||||
|
more fields...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Also don't forgot to impl a new function for Clientbound Packets so we can actaully send then by putting in the values :D
|
||||||
|
Example:
|
||||||
|
```rust
|
||||||
|
impl CPlayDisconnect {
|
||||||
|
pub fn new(reason: TextComponent) -> Self {
|
||||||
|
Self { reason }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
At the End everything should come together
|
||||||
|
```rust
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[packet(0x1D)]
|
||||||
|
pub struct CPlayDisconnect {
|
||||||
|
reason: TextComponent,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CPlayDisconnect {
|
||||||
|
pub fn new(reason: TextComponent) -> Self {
|
||||||
|
Self { reason }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
``
|
||||||
@ -132,14 +132,14 @@ pub enum ConnectionState {
|
|||||||
Play,
|
Play,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectionState {
|
impl From<VarInt> for ConnectionState {
|
||||||
pub fn from_varint(var_int: VarInt) -> Self {
|
fn from(value: VarInt) -> Self {
|
||||||
match var_int {
|
match value {
|
||||||
1 => Self::Status,
|
1 => Self::Status,
|
||||||
2 => Self::Login,
|
2 => Self::Login,
|
||||||
3 => Self::Transfer,
|
3 => Self::Transfer,
|
||||||
_ => {
|
_ => {
|
||||||
log::info!("Unexpected Status {}", var_int);
|
log::info!("Unexpected Status {}", value);
|
||||||
Self::Status
|
Self::Status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ impl ServerPacket for SHandShake {
|
|||||||
protocol_version: bytebuf.get_var_int(),
|
protocol_version: bytebuf.get_var_int(),
|
||||||
server_address: bytebuf.get_string_len(255).unwrap(),
|
server_address: bytebuf.get_string_len(255).unwrap(),
|
||||||
server_port: bytebuf.get_u16(),
|
server_port: bytebuf.get_u16(),
|
||||||
next_state: ConnectionState::from_varint(bytebuf.get_var_int()),
|
next_state: bytebuf.get_var_int().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use core::str;
|
|||||||
use fastnbt::SerOpts;
|
use fastnbt::SerOpts;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
// represents a text component
|
// Fepresents a Text component
|
||||||
// Reference: https://wiki.vg/Text_formatting#Text_components
|
// Reference: https://wiki.vg/Text_formatting#Text_components
|
||||||
#[derive(Clone, PartialEq, Default, Debug, Deserialize)]
|
#[derive(Clone, PartialEq, Default, Debug, Deserialize)]
|
||||||
pub struct TextComponent {
|
pub struct TextComponent {
|
||||||
|
|||||||
@ -29,49 +29,45 @@ impl Default for AdvancedConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct BasicConfiguration {
|
pub struct BasicConfiguration {
|
||||||
/// DO NOT CHANGE
|
/// A version identifier for the configuration format.
|
||||||
/// Generated to see if config may have been updated with an new Update
|
|
||||||
pub config_version: String,
|
pub config_version: String,
|
||||||
/// The Server Address to bind
|
/// The address to bind the server to.
|
||||||
pub server_address: String,
|
pub server_address: String,
|
||||||
/// The Server Port to bind
|
/// The port to listen on.
|
||||||
/// Minecraft java editon uses 25565 by default
|
|
||||||
pub server_port: u16,
|
pub server_port: u16,
|
||||||
/// The World sent to the Client
|
/// The seed for world generation.
|
||||||
pub seed: String,
|
pub seed: String,
|
||||||
/// The Maximum amout of player which can join the Server
|
/// The maximum number of players allowed on the server.
|
||||||
pub max_players: u32,
|
pub max_players: u32,
|
||||||
/// The Maximum view distance
|
/// The maximum view distance for players.
|
||||||
pub view_distances: u8,
|
pub view_distance: u8,
|
||||||
/// The Maximum simulated view distance
|
/// The maximum simulated view distance.
|
||||||
pub simulation_distance: u8,
|
pub simulation_distance: u8,
|
||||||
/// Path for resource pack
|
/// The path to the resource pack.
|
||||||
pub resource_pack: String,
|
pub resource_pack: String,
|
||||||
/// Sha1 hash of resource pack, when present
|
/// The SHA1 hash of the resource pack.
|
||||||
pub resource_pack_sha1: String,
|
pub resource_pack_sha1: String,
|
||||||
/// default difficulty
|
/// The default game difficulty.
|
||||||
pub default_difficulty: Difficulty,
|
pub default_difficulty: Difficulty,
|
||||||
/// allow nether dimension
|
/// Whether the Nether dimension is enabled.
|
||||||
pub allow_nether: bool,
|
pub allow_nether: bool,
|
||||||
/// is the server hardcore mode?
|
/// Whether the server is in hardcore mode.
|
||||||
pub hardcore: bool,
|
pub hardcore: bool,
|
||||||
/// Online Mode, Require a valid Minecraft account to join the Server, Also adds support for Skins and Capes
|
/// Whether online mode is enabled. Requires valid Minecraft accounts.
|
||||||
/// IMPORTANT: Be carefull when turning this off, Everyone could join your server and use any Nickname or UUID they want
|
|
||||||
pub online_mode: bool,
|
pub online_mode: bool,
|
||||||
/// Enable encryption for Packets send & received.
|
/// Whether packet encryption is enabled. Required when online mode is enabled.
|
||||||
/// IMPORTANT: When Online mode is enabled, encryption MUST be enabled also
|
|
||||||
pub encryption: bool,
|
pub encryption: bool,
|
||||||
/// When enabled, Client can't use a diffrent ip to login as they use for the Authentication Server
|
/// Whether to prevent proxy connections.
|
||||||
/// Usally preventing proxy connections
|
|
||||||
pub prevent_proxy_connections: bool,
|
pub prevent_proxy_connections: bool,
|
||||||
/// The description send when Client performs a Status request, (e.g Multiplayer Screen)
|
/// The server's description displayed on the status screen.
|
||||||
pub motd: String,
|
pub motd: String,
|
||||||
/// default gamemode (e.g. Survival, Creative...)
|
/// The default game mode for players.
|
||||||
pub default_gamemode: GameMode,
|
pub default_gamemode: GameMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Default for BasicConfiguration {
|
impl Default for BasicConfiguration {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -80,7 +76,7 @@ impl Default for BasicConfiguration {
|
|||||||
server_port: 25565,
|
server_port: 25565,
|
||||||
seed: "".to_string(),
|
seed: "".to_string(),
|
||||||
max_players: 100000,
|
max_players: 100000,
|
||||||
view_distances: 10,
|
view_distance: 10,
|
||||||
simulation_distance: 10,
|
simulation_distance: 10,
|
||||||
resource_pack: "".to_string(),
|
resource_pack: "".to_string(),
|
||||||
resource_pack_sha1: "".to_string(),
|
resource_pack_sha1: "".to_string(),
|
||||||
@ -129,9 +125,9 @@ impl BasicConfiguration {
|
|||||||
self.config_version, CURRENT_BASE_VERSION,
|
self.config_version, CURRENT_BASE_VERSION,
|
||||||
"Config version does not match used Config version. Please update your config"
|
"Config version does not match used Config version. Please update your config"
|
||||||
);
|
);
|
||||||
assert!(self.view_distances >= 2, "View distance must be atleast 2");
|
assert!(self.view_distance >= 2, "View distance must be atleast 2");
|
||||||
assert!(
|
assert!(
|
||||||
self.view_distances <= 32,
|
self.view_distance <= 32,
|
||||||
"View distance must be less than 32"
|
"View distance must be less than 32"
|
||||||
);
|
);
|
||||||
if self.online_mode {
|
if self.online_mode {
|
||||||
|
|||||||
@ -125,7 +125,7 @@ impl Server {
|
|||||||
self.base_config.hardcore,
|
self.base_config.hardcore,
|
||||||
vec!["minecraft:overworld".into()],
|
vec!["minecraft:overworld".into()],
|
||||||
self.base_config.max_players as VarInt,
|
self.base_config.max_players as VarInt,
|
||||||
self.base_config.view_distances as VarInt, // view distance todo
|
self.base_config.view_distance as VarInt, // view distance todo
|
||||||
self.base_config.simulation_distance as VarInt, // sim view dinstance todo
|
self.base_config.simulation_distance as VarInt, // sim view dinstance todo
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user