Skip to content

Commit

Permalink
Implement Query protocol (Snowiiii#218)
Browse files Browse the repository at this point in the history
* Add query options to config
Added packet data types
Correctly parse a handshake packet
Add tokio to pumpkin protocol for `AsyncReadExt` convenience functions

* Add repr(u8) so that PacketType is a byte

* Respond to handshake correctly

* Allow for proper decoding of status packets and properly handle errors in decoding

* Implement challange tokens and verify with token and address

* Encode Basic status packet
Switch to CString since its better to and null errors higher up the code

* Encode Full status packet

* Add forgotten fields to full status packet

* Correctly respond to query clients when requesting full status

* Return actual address and port of server
Respect config options
Remove uncessary debug derives

* Remove packet type as it is redundant/unnecssary

* Implement basic status request
Refactor code for better error handling

* Update README

* Show players correctly in full status packet

* Store all packets in structs instead of enums
Break up en/decoding for each packet
Reduce client tracking
Get rid of QueryClients struct
Stop storing of magic value and check during decoding
Added tests for all decoding and encoding
Fix all sugestions from @StripedMonkey
  • Loading branch information
neeleshpoli authored and lokka30 committed Nov 7, 2024
1 parent ff4a710 commit 11c2c0d
Show file tree
Hide file tree
Showing 8 changed files with 553 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ and customizable experience. It prioritizes performance and player enjoyment whi
- [x] Player Combat
- Server
- [ ] Plugins
- [ ] Query
- [x] Query
- [x] RCON
- [x] Inventories
- [x] Particles
Expand Down
3 changes: 3 additions & 0 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use log::warn;
use logging::LoggingConfig;
use pumpkin_core::{Difficulty, GameMode};
use query::QueryConfig;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

// TODO: when https://github.com/rust-lang/rfcs/pull/3681 gets merged, replace serde-inline-default with native syntax
Expand All @@ -16,6 +17,7 @@ use std::{
pub mod auth;
pub mod logging;
pub mod proxy;
pub mod query;
pub mod resource_pack;

pub use auth::AuthenticationConfig;
Expand Down Expand Up @@ -53,6 +55,7 @@ pub struct AdvancedConfiguration {
pub rcon: RCONConfig,
pub pvp: PVPConfig,
pub logging: LoggingConfig,
pub query: QueryConfig,
}

#[serde_inline_default]
Expand Down
12 changes: 12 additions & 0 deletions pumpkin-config/src/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use serde::{Deserialize, Serialize};
use serde_inline_default::serde_inline_default;

#[serde_inline_default]
#[derive(Deserialize, Serialize, Default)]
pub struct QueryConfig {
#[serde_inline_default(false)]
pub enabled: bool,
// Optional so if not specified the port server is running on will be used
#[serde_inline_default(None)]
pub port: Option<u16>,
}
2 changes: 1 addition & 1 deletion pumpkin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde.workspace = true
thiserror.workspace = true
itertools.workspace = true
log.workspace = true

tokio.workspace = true
num-traits.workspace = true
num-derive.workspace = true

Expand Down
1 change: 1 addition & 0 deletions pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod bytebuf;
pub mod client;
pub mod packet_decoder;
pub mod packet_encoder;
pub mod query;
pub mod server;
pub mod slot;

Expand Down
Loading

0 comments on commit 11c2c0d

Please sign in to comment.