Skip to content

Commit

Permalink
Split all client requests into seperate files
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas0008 committed Aug 5, 2024
1 parent 284db80 commit 4fa1cce
Show file tree
Hide file tree
Showing 30 changed files with 881 additions and 793 deletions.
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/bytebuf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{BitSet, VarInt, VarLong};
use bytes::{Buf, BufMut, BytesMut};
use core::str;
use std::io::{self, Error, ErrorKind};
use bytes::{Buf, BufMut, BytesMut};
use crate::{BitSet, VarInt, VarLong};

mod serializer;
pub mod packet_id;
mod serializer;

const SEGMENT_BITS: u8 = 0x7F;
const CONTINUE_BIT: u8 = 0x80;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/bytebuf/packet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
P: Packet + Serialize,
{
fn write(&self, bytebuf: &mut ByteBuffer) {
dbg!(P::PACKET_ID);
dbg!(P::PACKET_ID);
take_mut::take(bytebuf, |bytebuf| {
let mut serializer = serializer::Serializer::new(bytebuf);
self.serialize(&mut serializer)
Expand Down
98 changes: 49 additions & 49 deletions pumpkin-protocol/src/bytebuf/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ impl Serializer {
}
}

impl Into<ByteBuffer> for Serializer {
fn into(self) -> ByteBuffer {
self.output
impl From<Serializer> for ByteBuffer {
fn from(val: Serializer) -> Self {
val.output
}
}

Expand Down Expand Up @@ -65,38 +65,38 @@ impl<'a> ser::Serializer for &'a mut Serializer {
self.output.put_slice(v);
Ok(())
}
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> {
fn serialize_char(self, _v: char) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
fn serialize_f32(self, _v: f32) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> {
fn serialize_f64(self, _v: f64) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
fn serialize_i128(self, _v: i128) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
fn serialize_i16(self, _v: i16) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
fn serialize_i32(self, _v: i32) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
self.output.put_i64(v);
Ok(())
}
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
fn serialize_i8(self, _v: i8) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
todo!()
}
fn serialize_newtype_struct<T>(
self,
name: &'static str,
value: &T,
_name: &'static str,
_value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: ?Sized + Serialize,
Expand All @@ -105,10 +105,10 @@ impl<'a> ser::Serializer for &'a mut Serializer {
}
fn serialize_newtype_variant<T>(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
value: &T,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
_value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: ?Sized + Serialize,
Expand All @@ -118,10 +118,10 @@ impl<'a> ser::Serializer for &'a mut Serializer {
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
todo!()
}
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn serialize_some<T>(self, _value: &T) -> Result<Self::Ok, Self::Error>
where
T: ?Sized + Serialize,
{
Expand All @@ -133,65 +133,65 @@ impl<'a> ser::Serializer for &'a mut Serializer {
}
fn serialize_struct(
self,
name: &'static str,
len: usize,
_name: &'static str,
_len: usize,
) -> Result<Self::SerializeStruct, Self::Error> {
Ok(self)
}
fn serialize_struct_variant(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
len: usize,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
_len: usize,
) -> Result<Self::SerializeStructVariant, Self::Error> {
todo!()
}
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> {
todo!()
}
fn serialize_tuple_struct(
self,
name: &'static str,
len: usize,
_name: &'static str,
_len: usize,
) -> Result<Self::SerializeTupleStruct, Self::Error> {
todo!()
}
fn serialize_tuple_variant(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
len: usize,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
_len: usize,
) -> Result<Self::SerializeTupleVariant, Self::Error> {
todo!()
}
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
fn serialize_u128(self, _v: u128) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
fn serialize_u16(self, _v: u16) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
fn serialize_u32(self, _v: u32) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
fn serialize_u64(self, _v: u64) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
fn serialize_u8(self, _v: u8) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error> {
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
todo!()
}
fn serialize_unit_variant(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
) -> Result<Self::Ok, Self::Error> {
todo!()
}
Expand All @@ -204,7 +204,7 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
type Error = SerializerError;

// Serialize a single element of the sequence.
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, _value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand All @@ -221,7 +221,7 @@ impl<'a> ser::SerializeTuple for &'a mut Serializer {
type Ok = ();
type Error = SerializerError;

fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, _value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand All @@ -238,7 +238,7 @@ impl<'a> ser::SerializeTupleStruct for &'a mut Serializer {
type Ok = ();
type Error = SerializerError;

fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, _value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand All @@ -263,7 +263,7 @@ impl<'a> ser::SerializeTupleVariant for &'a mut Serializer {
type Ok = ();
type Error = SerializerError;

fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, _value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand Down Expand Up @@ -295,7 +295,7 @@ impl<'a> ser::SerializeMap for &'a mut Serializer {
// This can be done by using a different Serializer to serialize the key
// (instead of `&mut **self`) and having that other serializer only
// implement `serialize_str` and return an error on any other data type.
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
fn serialize_key<T>(&mut self, _key: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand All @@ -305,7 +305,7 @@ impl<'a> ser::SerializeMap for &'a mut Serializer {
// It doesn't make a difference whether the colon is printed at the end of
// `serialize_key` or at the beginning of `serialize_value`. In this case
// the code is a bit simpler having it here.
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_value<T>(&mut self, _value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand All @@ -323,7 +323,7 @@ impl<'a> ser::SerializeStruct for &'a mut Serializer {
type Ok = ();
type Error = SerializerError;

fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, _key: &'static str, value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand All @@ -346,7 +346,7 @@ impl<'a> ser::SerializeStructVariant for &'a mut Serializer {
type Ok = ();
type Error = SerializerError;

fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, _key: &'static str, _value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
Expand Down
16 changes: 16 additions & 0 deletions pumpkin-protocol/src/client/config/c_config_disconnect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::bytebuf::packet_id::Packet;

#[derive(serde::Serialize)]
pub struct CConfigDisconnect<'a> {
reason: &'a str,
}

impl<'a> Packet for CConfigDisconnect<'a> {
const PACKET_ID: i32 = 0x02;
}

impl<'a> CConfigDisconnect<'a> {
pub fn new(reason: &'a str) -> Self {
Self { reason }
}
}
18 changes: 18 additions & 0 deletions pumpkin-protocol/src/client/config/c_cookie_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::{
bytebuf::{packet_id::Packet, ByteBuffer},
ClientPacket, Identifier, VarInt,
};

pub struct CCookieRequest {
key: Identifier,
}

impl Packet for CCookieRequest {
const PACKET_ID: VarInt = 0x00;
}

impl ClientPacket for CCookieRequest {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_string(&self.key);
}
}
20 changes: 20 additions & 0 deletions pumpkin-protocol/src/client/config/c_finish_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::{bytebuf::packet_id::Packet, VarInt};

#[derive(serde::Serialize)]
pub struct CFinishConfig {}

impl Default for CFinishConfig {
fn default() -> Self {
Self::new()
}
}

impl CFinishConfig {
pub fn new() -> Self {
Self {}
}
}

impl Packet for CFinishConfig {
const PACKET_ID: VarInt = 0x03;
}
28 changes: 28 additions & 0 deletions pumpkin-protocol/src/client/config/c_known_packs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::{
bytebuf::{packet_id::Packet, ByteBuffer},
ClientPacket, KnownPack, VarInt,
};

pub struct CKnownPacks<'a> {
known_packs: &'a [KnownPack<'a>],
}

impl<'a> CKnownPacks<'a> {
pub fn new(known_packs: &'a [KnownPack]) -> Self {
Self { known_packs }
}
}

impl<'a> Packet for CKnownPacks<'a> {
const PACKET_ID: VarInt = 0x0E;
}

impl<'a> ClientPacket for CKnownPacks<'a> {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_list::<KnownPack>(self.known_packs, |p, v| {
p.put_string(v.namespace);
p.put_string(v.id);
p.put_string(v.version);
});
}
}
26 changes: 26 additions & 0 deletions pumpkin-protocol/src/client/config/c_plugin_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::{
bytebuf::{packet_id::Packet, ByteBuffer},
ClientPacket, VarInt,
};

pub struct CPluginMessage<'a> {
channel: &'a str,
data: &'a [u8],
}

impl<'a> CPluginMessage<'a> {
pub fn new(channel: &'a str, data: &'a [u8]) -> Self {
Self { channel, data }
}
}

impl<'a> Packet for CPluginMessage<'a> {
const PACKET_ID: VarInt = 0x01;
}

impl<'a> ClientPacket for CPluginMessage<'a> {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_string(self.channel);
bytebuf.put_slice(self.data);
}
}
Loading

0 comments on commit 4fa1cce

Please sign in to comment.