9 // User flags are stored as a 2 byte bitmap and represent various user states
11 UserFlagAway = iota // User is away
12 UserFlagAdmin // User is admin
13 UserFlagRefusePM // User refuses private messages
14 UserFlagRefusePChat // User refuses private chat
17 // FieldOptions flags are sent from v1.5+ clients as part of TranAgreed
19 UserOptRefusePM = iota // User has "Refuse private messages" pref set
20 UserOptRefuseChat // User has "Refuse private chat" pref set
21 UserOptAutoResponse // User has "Automatic response" pref set
27 Flags []byte // Size 2
28 Name string // Variable length user name
30 readOffset int // Internal offset to track read progress
33 func (u *User) Read(p []byte) (int, error) {
34 nameLen := make([]byte, 2)
35 binary.BigEndian.PutUint16(nameLen, uint16(len(u.Name)))
41 if len(u.Flags) == 4 {
53 if u.readOffset >= len(b) {
54 return 0, io.EOF // All bytes have been read
62 func (u *User) Write(p []byte) (int, error) {
63 namelen := int(binary.BigEndian.Uint16(p[6:8]))
67 u.Name = string(p[8 : 8+namelen])
69 return 8 + namelen, nil
72 // encodeString takes []byte s containing cleartext and rotates by 255 into obfuscated cleartext.
73 // The Hotline protocol uses this format for sending passwords over network.
74 // Not secure, but hey, it was the 90s!
75 func encodeString(clearText []byte) []byte {
76 obfuText := make([]byte, len(clearText))
77 for i := 0; i < len(clearText); i++ {
78 obfuText[i] = 255 - clearText[i]