Skip to content

Commit

Permalink
Merge pull request #5 from dreamscached/chat-type
Browse files Browse the repository at this point in the history
Make Description field a Chat type
  • Loading branch information
dreamscached authored Dec 23, 2021
2 parents af8cff9 + c495343 commit 8e25502
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ping/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func TestPing(t *testing.T) {
t.Errorf("Expected protocol version 4, got %d", res.Version.Protocol)
}

if res.Description.Text != "A Minecraft Server" {
t.Errorf("Expected description A Minecraft Server, got %s", res.Description.Text)
if res.Description.(string) != "A Minecraft Server" {
t.Errorf("Expected description A Minecraft Server, got %s", res.Description.(string))
}

if res.Players.Max != 20 {
Expand Down
21 changes: 2 additions & 19 deletions ping/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,7 @@ func writePing(w io.Writer, p ping) error {

const packetResponse unsignedVarInt32 = 0x0

type description struct {
Text string `json:"text"`
}

type descriptionObj struct {
Text string `json:"text"`
}

func (r *description) UnmarshalJSON(data []byte) error {
f := &descriptionObj{}
if err := json.Unmarshal(data, f); err != nil {
r.Text = string(data[1 : len(data)-1])
return nil
}

r.Text = f.Text
return nil
}
type Chat interface{}

type Response struct {
Version struct {
Expand All @@ -137,7 +120,7 @@ type Response struct {
} `json:"sample"`
}

Description description `json:"description"`
Description Chat `json:"description"`

Favicon string `json:"favicon"`
}
Expand Down

0 comments on commit 8e25502

Please sign in to comment.