]>
Commit | Line | Data |
---|---|---|
6988a057 JH |
1 | package hotline |
2 | ||
3 | import ( | |
4 | "encoding/binary" | |
5 | "github.com/jhalter/mobius/concat" | |
6 | ) | |
7 | ||
8 | const GuestAccount = "guest" // default account used when no login is provided for a connection | |
9 | ||
10 | type Account struct { | |
11 | Login string `yaml:"Login"` | |
12 | Name string `yaml:"Name"` | |
13 | Password string `yaml:"Password"` | |
14 | Access *[]byte `yaml:"Access"` // 8 byte bitmap | |
15 | } | |
16 | ||
17 | // Payload marshals an account to byte slice | |
18 | // Example: | |
19 | // 00 04 // fieldCount? | |
20 | // 00 66 // 102 - fieldUserName | |
21 | // 00 0d // 13 | |
22 | // 61 64 6d 69 6e 69 73 74 72 61 74 6f 72 // administrator | |
23 | // 00 69 // 105 fieldUserLogin (encoded) | |
24 | // 00 05 // len | |
25 | // 9e 9b 92 96 91 // encoded login name | |
26 | // 00 6a // 106 fieldUserPassword | |
27 | // 00 01 // len | |
28 | // 78 | |
29 | // 00 6e // fieldUserAccess | |
30 | // 00 08 | |
31 | // ff d3 cf ef ff 80 00 00 | |
32 | func (a *Account) Payload() (out []byte) { | |
33 | nameLen := make([]byte, 2) | |
34 | binary.BigEndian.PutUint16(nameLen, uint16(len(a.Name))) | |
35 | ||
36 | loginLen := make([]byte, 2) | |
37 | binary.BigEndian.PutUint16(loginLen, uint16(len(a.Login))) | |
38 | ||
39 | return concat.Slices( | |
40 | []byte{0x00, 0x3}, // param count -- always 3 | |
41 | ||
42 | []byte{0x00, 0x66}, // fieldUserName | |
43 | nameLen, | |
44 | []byte(a.Name), | |
45 | ||
46 | []byte{0x00, 0x69}, // fieldUserLogin | |
47 | loginLen, | |
48 | []byte(NegatedUserString([]byte(a.Login))), | |
49 | ||
50 | []byte{0x00, 0x6e}, // fieldUserAccess | |
51 | []byte{0x00, 0x08}, | |
52 | *a.Access, | |
53 | ) | |
54 | } |