-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e97381a
commit a09ea2e
Showing
5 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package packet | ||
|
||
import ( | ||
protoutil "go.minekube.com/gate/pkg/edition/java/proto/util" | ||
"go.minekube.com/gate/pkg/gate/proto" | ||
"io" | ||
) | ||
|
||
type CustomReportDetails struct { | ||
Details map[string]string | ||
} | ||
|
||
func (p *CustomReportDetails) Encode(c *proto.PacketContext, wr io.Writer) error { | ||
w := protoutil.PanicWriter(wr) | ||
w.VarInt(len(p.Details)) | ||
for key, value := range p.Details { | ||
w.String(key) | ||
w.String(value) | ||
} | ||
return nil | ||
} | ||
|
||
func (p *CustomReportDetails) Decode(c *proto.PacketContext, rd io.Reader) (err error) { | ||
r := protoutil.PanicReader(rd) | ||
var detailsCount int | ||
r.VarInt(&detailsCount) | ||
p.Details = make(map[string]string, detailsCount) | ||
for i := 0; i < detailsCount; i++ { | ||
var key, value string | ||
r.String(&key) | ||
r.String(&value) | ||
p.Details[key] = value | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package packet | ||
|
||
import ( | ||
"go.minekube.com/gate/pkg/edition/java/proto/packet/chat" | ||
protoutil "go.minekube.com/gate/pkg/edition/java/proto/util" | ||
"go.minekube.com/gate/pkg/gate/proto" | ||
"io" | ||
) | ||
|
||
type ServerLinks struct { | ||
ServerLinks []*ServerLink | ||
} | ||
|
||
func (p *ServerLinks) Encode(c *proto.PacketContext, wr io.Writer) error { | ||
w := protoutil.PanicWriter(wr) | ||
w.VarInt(len(p.ServerLinks)) | ||
for _, serverLink := range p.ServerLinks { | ||
err := serverLink.Encode(c, wr) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (p *ServerLinks) Decode(c *proto.PacketContext, rd io.Reader) (err error) { | ||
r := protoutil.PanicReader(rd) | ||
var serverLinksCount int | ||
r.VarInt(&serverLinksCount) | ||
p.ServerLinks = make([]*ServerLink, serverLinksCount) | ||
for i := 0; i < serverLinksCount; i++ { | ||
p.ServerLinks[i] = new(ServerLink) | ||
err = p.ServerLinks[i].Decode(c, rd) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return | ||
} | ||
|
||
type ServerLink struct { | ||
ID int | ||
DisplayName chat.ComponentHolder | ||
URL string | ||
} | ||
|
||
func (p *ServerLink) Encode(c *proto.PacketContext, wr io.Writer) error { | ||
if p.ID >= 0 { | ||
protoutil.PWriteBool(wr, true) | ||
protoutil.PWriteVarInt(wr, p.ID) | ||
} else { | ||
protoutil.PWriteBool(wr, false) | ||
err := p.DisplayName.Write(wr, c.Protocol) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return protoutil.WriteString(wr, p.URL) | ||
} | ||
|
||
func (p *ServerLink) Decode(c *proto.PacketContext, rd io.Reader) (err error) { | ||
r := protoutil.PanicReader(rd) | ||
if r.Ok() { | ||
r.VarInt(&p.ID) | ||
r.String(&p.URL) | ||
} else { | ||
p.ID = -1 | ||
p.DisplayName, err = chat.ReadComponentHolderNP(rd, c.Protocol) | ||
if err != nil { | ||
return err | ||
} | ||
r.String(&p.URL) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters