10 // User flags are stored as a 2 byte bitmap and represent various user states
12 UserFlagAway = 0 // User is away
13 UserFlagAdmin = 1 // User is admin
14 UserFlagRefusePM = 2 // User refuses private messages
15 UserFlagRefusePChat = 3 // User refuses private chat
18 // FieldOptions flags are sent from v1.5+ clients as part of TranAgreed
20 UserOptRefusePM = 0 // User has "Refuse private messages" pref set
21 UserOptRefuseChat = 1 // User has "Refuse private chat" pref set
22 UserOptAutoResponse = 2 // User has "Automatic response" pref set
25 type UserFlags [2]byte
27 func (flag *UserFlags) IsSet(i int) bool {
28 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(flag[:])))
29 return flagBitmap.Bit(i) == 1
32 func (flag *UserFlags) Set(i int, newVal uint) {
33 flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(flag[:])))
34 flagBitmap.SetBit(flagBitmap, i, newVal)
35 binary.BigEndian.PutUint16(flag[:], uint16(flagBitmap.Int64()))
41 Flags []byte // Size 2
42 Name string // Variable length user name
44 readOffset int // Internal offset to track read progress
47 func (u *User) Read(p []byte) (int, error) {
48 nameLen := make([]byte, 2)
49 binary.BigEndian.PutUint16(nameLen, uint16(len(u.Name)))
55 if len(u.Flags) == 4 {
67 if u.readOffset >= len(b) {
68 return 0, io.EOF // All bytes have been read
77 func (u *User) Write(p []byte) (int, error) {
78 namelen := int(binary.BigEndian.Uint16(p[6:8]))
79 u.ID = [2]byte(p[0:2])
82 u.Name = string(p[8 : 8+namelen])
84 return 8 + namelen, nil
87 // encodeString takes []byte s containing cleartext and rotates by 255 into obfuscated cleartext.
88 // The Hotline protocol uses this format for sending passwords over network.
89 // Not secure, but hey, it was the 90s!
90 func encodeString(clearText []byte) []byte {
91 obfuText := make([]byte, len(clearText))
92 for i := 0; i < len(clearText); i++ {
93 obfuText[i] = 255 - clearText[i]