-
Notifications
You must be signed in to change notification settings - Fork 6
/
player_list.go
75 lines (68 loc) · 2.1 KB
/
player_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package packet
import (
"dotcs/minecraft/protocol"
)
const (
PlayerListActionAdd = iota
PlayerListActionRemove
)
// PlayerList is sent by the server to update the client-side player list in the in-game menu screen. It shows
// the icon of each player if the correct XUID is written in the packet.
// Sending the PlayerList packet is obligatory when sending an AddPlayer packet. The added player will not
// show up to a client if it has not been added to the player list, because several properties of the player
// are obtained from the player list, such as the skin.
type PlayerList struct {
// ActionType is the action to execute upon the player list. The entries that follow specify which entries
// are added or removed from the player list.
ActionType byte
// Entries is a list of all player list entries that should be added/removed from the player list,
// depending on the ActionType set.
Entries []protocol.PlayerListEntry
}
// ID ...
func (*PlayerList) ID() uint32 {
return IDPlayerList
}
// Marshal ...
func (pk *PlayerList) Marshal(w *protocol.Writer) {
l := uint32(len(pk.Entries))
w.Uint8(&pk.ActionType)
w.Varuint32(&l)
for _, entry := range pk.Entries {
switch pk.ActionType {
case PlayerListActionAdd:
protocol.WritePlayerAddEntry(w, &entry)
case PlayerListActionRemove:
w.UUID(&entry.UUID)
default:
w.UnknownEnumOption(pk.ActionType, "player list action type")
}
}
if pk.ActionType == PlayerListActionAdd {
for _, entry := range pk.Entries {
w.Bool(&entry.Skin.Trusted)
}
}
}
// Unmarshal ...
func (pk *PlayerList) Unmarshal(r *protocol.Reader) {
var count uint32
r.Uint8(&pk.ActionType)
r.Varuint32(&count)
pk.Entries = make([]protocol.PlayerListEntry, count)
for i := uint32(0); i < count; i++ {
switch pk.ActionType {
case PlayerListActionAdd:
protocol.PlayerAddEntry(r, &pk.Entries[i])
case PlayerListActionRemove:
r.UUID(&pk.Entries[i].UUID)
default:
r.UnknownEnumOption(pk.ActionType, "player list action type")
}
}
if pk.ActionType == PlayerListActionAdd {
for i := uint32(0); i < count; i++ {
r.Bool(&pk.Entries[i].Skin.Trusted)
}
}
}