From 7f0641a094a78b834eab7ebf477f917c15b4722b Mon Sep 17 00:00:00 2001 From: MscBaiMeow Date: Sat, 19 Jun 2021 16:02:43 +0800 Subject: [PATCH] correct loginplugindata type --- bot/mcbot.go | 2 +- net/packet/types.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bot/mcbot.go b/bot/mcbot.go index f3a8b2f..b2805e7 100644 --- a/bot/mcbot.go +++ b/bot/mcbot.go @@ -145,7 +145,7 @@ func (c *Client) join(d *net.Dialer, addr string) error { var ( msgid pk.VarInt channel pk.Identifier - data pk.ByteArray + data pk.PluginMessageData ) if err := p.Scan(&msgid, &channel, &data); err != nil { return LoginErr{"Login Plugin", err} diff --git a/net/packet/types.go b/net/packet/types.go index 281d941..6ae25d4 100644 --- a/net/packet/types.go +++ b/net/packet/types.go @@ -70,6 +70,9 @@ type ( //ByteArray is []byte with prefix VarInt as length ByteArray []byte + + //PluginMessageData is only used in LoginPlugin,and it will read all left bytes + PluginMessageData []byte ) const MaxVarIntLen = 5 @@ -490,3 +493,15 @@ func (u *UUID) ReadFrom(r io.Reader) (n int64, err error) { nn, err := io.ReadFull(r, (*u)[:]) return int64(nn), err } + +// Encode a PluginsMessageData +func (p *PluginMessageData) WriteTo(w io.Writer) (n int64, err error) { + nn, err := w.Write(*p) + return int64(nn), err +} + +// Decode a PluginsMessageData +func (p *PluginMessageData) ReadFrom(r io.Reader) (n int64, err error) { + *p, err = io.ReadAll(r) + return int64(len(*p)), err +}