]> git.r.bdr.sh - rbdr/mobius/blame_incremental - hotline/user.go
Making it so the container restarts on host reboot
[rbdr/mobius] / hotline / user.go
... / ...
CommitLineData
1package hotline
2
3import (
4 "encoding/binary"
5)
6
7// User flags are stored as a 2 byte bitmap and represent various user states
8const (
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
13)
14
15// FieldOptions flags are sent from v1.5+ clients as part of TranAgreed
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
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
59// DecodeUserString decodes an obfuscated user string from a client
60// e.g. 98 8a 9a 8c 8b => "guest"
61func DecodeUserString(obfuText []byte) (clearText string) {
62 for _, char := range obfuText {
63 clearText += string(rune(255 - uint(char)))
64 }
65 return clearText
66}
67
68// negateString takes []byte s containing cleartext and rotates by 255 into obfuscated cleartext.
69// The Hotline protocol uses this format for sending passwords over network.
70// Not secure, but hey, it was the 90s!
71func negateString(clearText []byte) []byte {
72 obfuText := make([]byte, len(clearText))
73 for i := 0; i < len(clearText); i++ {
74 obfuText[i] = 255 - clearText[i]
75 }
76 return obfuText
77}