-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
49 lines (41 loc) · 992 Bytes
/
client.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
package common
import (
"bytes"
"encoding/json"
"time"
"git.iptq.io/nso/common/models"
"git.iptq.io/nso/common/packets"
)
type Client struct {
Uuid string
UserID uint
Rank uint
LastSeen time.Time
PacketQueue []packets.Packet
}
func (client *Client) Serialize() (repr []byte, err error) {
return json.Marshal(client)
}
func (client *Client) QueuePacket(packet packets.Packet) {
client.PacketQueue = append(client.PacketQueue, packet)
}
func (client *Client) GetPacketQueue() (result []byte) {
buf := new(bytes.Buffer)
for _, packet := range client.PacketQueue {
buf.Write(packet.GetData())
}
client.PacketQueue = make([]packets.Packet, 0)
return buf.Bytes()
}
func DeserializeClient(repr []byte) (client Client, err error) {
return
}
func NewClient(uuid string, user *models.User) (client Client) {
client = Client{
Uuid: uuid,
UserID: user.ID,
Rank: user.Rank,
PacketQueue: make([]packets.Packet, 0),
}
return
}