/
client.go
122 lines (97 loc) · 2.07 KB
/
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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package mnet
import (
"net"
"github.com/Hucaru/Valhalla/constant"
"github.com/Hucaru/Valhalla/mnet/crypt"
"github.com/Hucaru/Valhalla/mpacket"
)
type Client interface {
MConn
GetLogedIn() bool
SetLogedIn(bool)
GetAccountID() int32
SetAccountID(int32)
GetGender() byte
SetGender(byte)
GetWorldID() byte
SetWorldID(byte)
GetChannelID() byte
SetChannelID(byte)
GetAdminLevel() int
SetAdminLevel(int)
}
type client struct {
baseConn
logedIn bool
accountID int32
gender byte
worldID byte
channelID byte
adminLevel int
}
func NewClient(conn net.Conn, eRecv chan *Event, queueSize int, keySend, keyRecv [4]byte, latency, jitter int) *client {
c := &client{}
c.Conn = conn
c.eSend = make(chan mpacket.Packet, queueSize)
c.eRecv = eRecv
c.cryptSend = crypt.New(keySend, constant.MapleVersion)
c.cryptRecv = crypt.New(keyRecv, constant.MapleVersion)
c.reader = func() {
clientReader(c, c.eRecv, constant.MapleVersion, constant.ClientHeaderSize, c.cryptRecv)
}
c.interServer = false
c.latency = latency
c.jitter = jitter
c.pSend = make(chan func(), queueSize*10) // Used only when simulating latency
if latency > 0 {
go func(pSend chan func(), conn net.Conn) {
for {
select {
case p, ok := <-pSend:
if !ok {
return
}
p()
default:
}
}
}(c.pSend, conn)
}
return c
}
func (c *client) GetLogedIn() bool {
return c.logedIn
}
func (c *client) SetLogedIn(logedIn bool) {
c.logedIn = logedIn
}
func (c *client) GetAccountID() int32 {
return c.accountID
}
func (c *client) SetAccountID(accountID int32) {
c.accountID = accountID
}
func (c *client) GetGender() byte {
return c.gender
}
func (c *client) SetGender(gender byte) {
c.gender = gender
}
func (c *client) GetWorldID() byte {
return c.worldID
}
func (c *client) SetWorldID(id byte) {
c.worldID = id
}
func (c *client) GetChannelID() byte {
return c.channelID
}
func (c *client) SetChannelID(id byte) {
c.channelID = id
}
func (c *client) GetAdminLevel() int {
return c.adminLevel
}
func (c *client) SetAdminLevel(level int) {
c.adminLevel = level
}