Skip to content

Commit

Permalink
fix: Received unknown packet id 130
Browse files Browse the repository at this point in the history
this was mostly because of poor naming, While there are two CServerLinks packets, I accidentally send the play CServerLinks in the login state which has a different packet id
  • Loading branch information
Snowiiii committed Dec 24, 2024
1 parent 3dae300 commit 1d96701
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 160 deletions.
79 changes: 4 additions & 75 deletions pumpkin-protocol/src/client/config/c_server_links.rs
Original file line number Diff line number Diff line change
@@ -1,87 +1,16 @@
use crate::VarInt;
use pumpkin_core::text::TextComponent;
use crate::{Link, VarInt};
use pumpkin_macros::client_packet;
use serde::{Serialize, Serializer};
use serde::Serialize;

#[derive(Serialize)]
#[client_packet("config:server_links")]
pub struct CServerLinks<'a> {
pub struct CConfigServerLinks<'a> {
links_count: &'a VarInt,
links: &'a [Link<'a>],
}

impl<'a> CServerLinks<'a> {
impl<'a> CConfigServerLinks<'a> {
pub fn new(links_count: &'a VarInt, links: &'a [Link<'a>]) -> Self {
Self { links_count, links }
}
}

pub enum Label<'a> {
BuiltIn(LinkType),
TextComponent(TextComponent<'a>),
}

impl Serialize for Label<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Label::BuiltIn(link_type) => link_type.serialize(serializer),
Label::TextComponent(component) => component.serialize(serializer),
}
}
}

#[derive(Serialize)]
pub struct Link<'a> {
pub is_built_in: bool,
pub label: Label<'a>,
pub url: &'a String,
}

impl<'a> Link<'a> {
pub fn new(label: Label<'a>, url: &'a String) -> Self {
Self {
is_built_in: match label {
Label::BuiltIn(_) => true,
Label::TextComponent(_) => false,
},
label,
url,
}
}
}

pub enum LinkType {
BugReport,
CommunityGuidelines,
Support,
Status,
Feedback,
Community,
Website,
Forums,
News,
Announcements,
}

impl Serialize for LinkType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
LinkType::BugReport => VarInt(0).serialize(serializer),
LinkType::CommunityGuidelines => VarInt(1).serialize(serializer),
LinkType::Support => VarInt(2).serialize(serializer),
LinkType::Status => VarInt(3).serialize(serializer),
LinkType::Feedback => VarInt(4).serialize(serializer),
LinkType::Community => VarInt(5).serialize(serializer),
LinkType::Website => VarInt(6).serialize(serializer),
LinkType::Forums => VarInt(7).serialize(serializer),
LinkType::News => VarInt(8).serialize(serializer),
LinkType::Announcements => VarInt(9).serialize(serializer),
}
}
}
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/client/login/c_cookie_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::codec::identifier::Identifier;
#[derive(Serialize)]
#[client_packet("login:cookie_request")]
/// Requests a cookie that was previously stored.
pub struct CCookieRequest<'a> {
pub struct CLoginCookieRequest<'a> {
key: &'a Identifier,
}

impl<'a> CCookieRequest<'a> {
impl<'a> CLoginCookieRequest<'a> {
pub fn new(key: &'a Identifier) -> Self {
Self { key }
}
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/client/play/c_cookie_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::codec::identifier::Identifier;
#[derive(Serialize)]
#[client_packet("play:cookie_request")]
/// Requests a cookie that was previously stored.
pub struct CCookieRequest<'a> {
pub struct CPlayCookieRequest<'a> {
key: &'a Identifier,
}

impl<'a> CCookieRequest<'a> {
impl<'a> CPlayCookieRequest<'a> {
pub fn new(key: &'a Identifier) -> Self {
Self { key }
}
Expand Down
79 changes: 4 additions & 75 deletions pumpkin-protocol/src/client/play/c_server_links.rs
Original file line number Diff line number Diff line change
@@ -1,87 +1,16 @@
use crate::VarInt;
use pumpkin_core::text::TextComponent;
use crate::{Link, VarInt};
use pumpkin_macros::client_packet;
use serde::{Serialize, Serializer};
use serde::Serialize;

#[derive(Serialize)]
#[client_packet("play:server_links")]
pub struct CServerLinks<'a> {
pub struct CPlayServerLinks<'a> {
links_count: &'a VarInt,
links: &'a [Link<'a>],
}

impl<'a> CServerLinks<'a> {
impl<'a> CPlayServerLinks<'a> {
pub fn new(links_count: &'a VarInt, links: &'a [Link<'a>]) -> Self {
Self { links_count, links }
}
}

pub enum Label<'a> {
BuiltIn(LinkType),
TextComponent(TextComponent<'a>),
}

impl Serialize for Label<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Label::BuiltIn(link_type) => link_type.serialize(serializer),
Label::TextComponent(component) => component.serialize(serializer),
}
}
}

#[derive(Serialize)]
pub struct Link<'a> {
pub is_built_in: bool,
pub label: Label<'a>,
pub url: &'a String,
}

impl<'a> Link<'a> {
pub fn new(label: Label<'a>, url: &'a String) -> Self {
Self {
is_built_in: match label {
Label::BuiltIn(_) => true,
Label::TextComponent(_) => false,
},
label,
url,
}
}
}

pub enum LinkType {
BugReport,
CommunityGuidelines,
Support,
Status,
Feedback,
Community,
Website,
Forums,
News,
Announcements,
}

impl Serialize for LinkType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
LinkType::BugReport => VarInt(0).serialize(serializer),
LinkType::CommunityGuidelines => VarInt(1).serialize(serializer),
LinkType::Support => VarInt(2).serialize(serializer),
LinkType::Status => VarInt(3).serialize(serializer),
LinkType::Feedback => VarInt(4).serialize(serializer),
LinkType::Community => VarInt(5).serialize(serializer),
LinkType::Website => VarInt(6).serialize(serializer),
LinkType::Forums => VarInt(7).serialize(serializer),
LinkType::News => VarInt(8).serialize(serializer),
LinkType::Announcements => VarInt(9).serialize(serializer),
}
}
}
72 changes: 71 additions & 1 deletion pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bytebuf::{packet_id::Packet, ReadingError};
use bytes::{Buf, BufMut, Bytes};
use codec::{identifier::Identifier, var_int::VarInt};
use pumpkin_core::text::{style::Style, TextComponent};
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Serialize, Serializer};

pub mod bytebuf;
#[cfg(feature = "clientbound")]
Expand Down Expand Up @@ -186,3 +186,73 @@ impl PositionFlag {
flags.iter().fold(0, |acc, flag| acc | flag.get_mask())
}
}

pub enum Label<'a> {
BuiltIn(LinkType),
TextComponent(TextComponent<'a>),
}

impl Serialize for Label<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Label::BuiltIn(link_type) => link_type.serialize(serializer),
Label::TextComponent(component) => component.serialize(serializer),
}
}
}

#[derive(Serialize)]
pub struct Link<'a> {
pub is_built_in: bool,
pub label: Label<'a>,
pub url: &'a String,
}

impl<'a> Link<'a> {
pub fn new(label: Label<'a>, url: &'a String) -> Self {
Self {
is_built_in: match label {
Label::BuiltIn(_) => true,
Label::TextComponent(_) => false,
},
label,
url,
}
}
}

pub enum LinkType {
BugReport,
CommunityGuidelines,
Support,
Status,
Feedback,
Community,
Website,
Forums,
News,
Announcements,
}

impl Serialize for LinkType {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
LinkType::BugReport => VarInt(0).serialize(serializer),
LinkType::CommunityGuidelines => VarInt(1).serialize(serializer),
LinkType::Support => VarInt(2).serialize(serializer),
LinkType::Status => VarInt(3).serialize(serializer),
LinkType::Feedback => VarInt(4).serialize(serializer),
LinkType::Community => VarInt(5).serialize(serializer),
LinkType::Website => VarInt(6).serialize(serializer),
LinkType::Forums => VarInt(7).serialize(serializer),
LinkType::News => VarInt(8).serialize(serializer),
LinkType::Announcements => VarInt(9).serialize(serializer),
}
}
}
12 changes: 7 additions & 5 deletions pumpkin/src/net/packet/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
use pumpkin_core::text::TextComponent;
use pumpkin_protocol::{
client::{
config::{CConfigAddResourcePack, CKnownPacks},
config::{CConfigAddResourcePack, CConfigServerLinks, CKnownPacks},
login::{CLoginSuccess, CSetCompression},
play::{CServerLinks, Label, Link, LinkType},
},
codec::var_int::VarInt,
server::login::{SEncryptionResponse, SLoginCookieResponse, SLoginPluginResponse, SLoginStart},
ConnectionState, KnownPack,
ConnectionState, KnownPack, Label, Link, LinkType,
};
use uuid::Uuid;

Expand Down Expand Up @@ -326,8 +325,11 @@ impl Client {
}

if ADVANCED_CONFIG.server_links.enabled {
self.send_packet(&CServerLinks::new(&VarInt(LINKS.len() as i32), &LINKS))
.await;
self.send_packet(&CConfigServerLinks::new(
&VarInt(LINKS.len() as i32),
&LINKS,
))
.await;
}

// known data packs
Expand Down

0 comments on commit 1d96701

Please sign in to comment.