]> git.r.bdr.sh - rbdr/mobius/blame - hotline/user.go
Fix handling of symlinks in Files dir
[rbdr/mobius] / hotline / user.go
CommitLineData
6988a057
JH
1package hotline
2
3import (
4 "encoding/binary"
5)
6
b1658a46 7// User flags are stored as a 2 byte bitmap and represent various user states
6988a057 8const (
b1658a46
JH
9 UserFlagAway = 0 // User is away
10 UserFlagAdmin = 1 // User is admin
11 UserFlagRefusePM = 2 // User refuses private messages
12 UserFlagRefusePChat = 3 // User refuses private chat
6988a057
JH
13)
14
d005ef04 15// FieldOptions flags are sent from v1.5+ clients as part of TranAgreed
003a743e
JH
16const (
17 refusePM = 0 // User has "Refuse private messages" pref set
18 refuseChat = 1 // User has "Refuse private chat" pref set
19 autoResponse = 2 // User has "Automatic response" pref set
20)
21
6988a057
JH
22type User struct {
23 ID []byte // Size 2
24 Icon []byte // Size 2
25 Flags []byte // Size 2
26 Name string // Variable length user name
27}
28
29func (u User) Payload() []byte {
30 nameLen := make([]byte, 2)
31 binary.BigEndian.PutUint16(nameLen, uint16(len(u.Name)))
32
33 if len(u.Icon) == 4 {
34 u.Icon = u.Icon[2:]
35 }
36
37 if len(u.Flags) == 4 {
38 u.Flags = u.Flags[2:]
39 }
40
41 out := append(u.ID[:2], u.Icon[:2]...)
42 out = append(out, u.Flags[:2]...)
43 out = append(out, nameLen...)
44 out = append(out, u.Name...)
45
46 return out
47}
48
49func ReadUser(b []byte) (*User, error) {
50 u := &User{
51 ID: b[0:2],
52 Icon: b[2:4],
53 Flags: b[4:6],
54 Name: string(b[8:]),
55 }
56 return u, nil
57}
58
76d0c1f6 59// decodeString decodes an obfuscated user string from a client
6988a057 60// e.g. 98 8a 9a 8c 8b => "guest"
76d0c1f6 61func decodeString(obfuText []byte) (clearText string) {
b25c4a19
JH
62 for _, char := range obfuText {
63 clearText += string(rune(255 - uint(char)))
6988a057 64 }
b25c4a19 65 return clearText
6988a057
JH
66}
67
76d0c1f6 68// encodeString takes []byte s containing cleartext and rotates by 255 into obfuscated cleartext.
b25c4a19
JH
69// The Hotline protocol uses this format for sending passwords over network.
70// Not secure, but hey, it was the 90s!
76d0c1f6 71func encodeString(clearText []byte) []byte {
b25c4a19
JH
72 obfuText := make([]byte, len(clearText))
73 for i := 0; i < len(clearText); i++ {
74 obfuText[i] = 255 - clearText[i]
6988a057 75 }
b25c4a19 76 return obfuText
6988a057 77}