Skip to content

Commit

Permalink
Merge branch 'master' into pumpkinerror-trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryntet authored Oct 14, 2024
2 parents 950ab21 + f970c4b commit f6cdc7a
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: npm
- name: Setup Pages
uses: actions/configure-pages@v5
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ jobs:
- run: cargo test --verbose
build_release:
name: Build project in release
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
toolchain:
- stable

Expand All @@ -65,6 +66,12 @@ jobs:
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}

- run: cargo build --verbose --release
- name: Export executable
uses: actions/upload-artifact@v4
with:
name: pumpkin-${{ matrix.os }}
compression-level: 9
path: target/${{ matrix.target }}/release/pumpkin*
clippy_release:
name: Run lints in release mode
runs-on: ubuntu-latest
Expand All @@ -77,5 +84,5 @@ jobs:
- uses: actions/checkout@v4

- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo clippy --release --all-targets --all-features --no-default-features -- -D warnings

- run: cargo clippy --release --all-targets --all-features --no-default-features -- -D warnings
3 changes: 3 additions & 0 deletions docs/developer/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ For Players:
}
```

### Compression
Minecraft Packets **can** use the ZLib compression for decoding/encoding there is usally a threshold set when compression is applied, This most often affects Chunk Packets.

### Porting

To port to a new Minecraft version, You can compare difference in Protocol on wiki.vg https://wiki.vg/index.php?title=Protocol&action=history
Expand Down
21 changes: 21 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "pumpkin-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

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

libfuzzer-sys = "0.4"


[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
test = false
doc = false
bench = false
7 changes: 7 additions & 0 deletions fuzz/fuzz_targets/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
});
18 changes: 8 additions & 10 deletions pumpkin-world/src/cylindrical_chunk_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ impl Cylindrical {
just_removed: impl FnMut(Vector2<i32>),
ignore: bool,
) {
let min_x = old_cylindrical.get_left().min(new_cylindrical.get_left());
let max_x = old_cylindrical.get_right().max(new_cylindrical.get_right());
let min_z = old_cylindrical
.get_bottom()
.min(new_cylindrical.get_bottom());
let max_z = old_cylindrical.get_top().max(new_cylindrical.get_top());
let min_x = old_cylindrical.left().min(new_cylindrical.left());
let max_x = old_cylindrical.right().max(new_cylindrical.right());
let min_z = old_cylindrical.bottom().min(new_cylindrical.bottom());
let max_z = old_cylindrical.top().max(new_cylindrical.top());

for x in min_x..=max_x {
for z in min_z..=max_z {
Expand Down Expand Up @@ -55,19 +53,19 @@ impl Cylindrical {
}
}

fn get_left(&self) -> i32 {
fn left(&self) -> i32 {
self.center.x - self.view_distance - 1
}

fn get_bottom(&self) -> i32 {
fn bottom(&self) -> i32 {
self.center.z - self.view_distance - 1
}

fn get_right(&self) -> i32 {
fn right(&self) -> i32 {
self.center.x + self.view_distance + 1
}

fn get_top(&self) -> i32 {
fn top(&self) -> i32 {
self.center.z + self.view_distance + 1
}

Expand Down
21 changes: 10 additions & 11 deletions pumpkin/src/client/authentication.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, net::IpAddr, sync::Arc};
use std::{collections::HashMap, net::IpAddr};

use base64::{engine::general_purpose, Engine};
use pumpkin_config::{auth::TextureConfig, ADVANCED_CONFIG};
Expand All @@ -9,8 +9,6 @@ use serde::Deserialize;
use thiserror::Error;
use uuid::Uuid;

use crate::server::Server;

#[derive(Deserialize, Clone, Debug)]
#[expect(dead_code)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -50,15 +48,14 @@ pub struct GameProfile {
/// 2. Mojang's servers verify the client's credentials and add the player to the their Servers
/// 3. Now our server will send a Request to the Session servers and check if the Player has joined the Session Server .
///
/// **Note:** This process helps prevent unauthorized access to the server and ensures that only legitimate Minecraft accounts can connect.
/// See <https://snowiiii.github.io/Pumpkin/developer/authentication.html>
pub async fn authenticate(
username: &str,
server_hash: &str,
ip: &IpAddr,
server: &Arc<Server>,
auth_client: &reqwest::Client,
) -> Result<GameProfile, AuthError> {
assert!(ADVANCED_CONFIG.authentication.enabled);
assert!(server.auth_client.is_some());
let address = if ADVANCED_CONFIG.authentication.prevent_proxy_connections {
ADVANCED_CONFIG
.authentication
Expand All @@ -73,10 +70,6 @@ pub async fn authenticate(
.replace("{username}", username)
.replace("{server_hash}", server_hash)
};
let auth_client = server
.auth_client
.as_ref()
.ok_or(AuthError::MissingAuthClient)?;

let response = auth_client
.get(address)
Expand All @@ -92,7 +85,7 @@ pub async fn authenticate(
Ok(profile)
}

pub fn unpack_textures(property: &Property, config: &TextureConfig) -> Result<(), TextureError> {
pub fn validate_textures(property: &Property, config: &TextureConfig) -> Result<(), TextureError> {
let from64 = general_purpose::STANDARD
.decode(&property.value)
.map_err(|e| TextureError::DecodeError(e.to_string()))?;
Expand Down Expand Up @@ -134,6 +127,12 @@ pub enum AuthError {
FailedResponse,
#[error("Failed to verify username")]
UnverifiedUsername,
#[error("You are banned from Authentication servers")]
Banned,
#[error("Texture Error {0}")]
TextureError(TextureError),
#[error("You have disallowed actions from Authentication servers")]
DisallowedAction,
#[error("Failed to parse JSON into Game Profile")]
FailedParse,
#[error("Unknown Status Code")]
Expand Down
Loading

0 comments on commit f6cdc7a

Please sign in to comment.