7 // User flags are stored as a 2 byte bitmap and represent various user states
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
15 // FieldOptions flags are sent from v1.5+ clients as part of TranAgreed
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
25 Flags []byte // Size 2
26 Name string // Variable length user name
29 func (u User) Payload() []byte {
30 nameLen := make([]byte, 2)
31 binary.BigEndian.PutUint16(nameLen, uint16(len(u.Name)))
37 if len(u.Flags) == 4 {
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...)
49 func ReadUser(b []byte) (*User, error) {
59 // DecodeUserString decodes an obfuscated user string from a client
60 // e.g. 98 8a 9a 8c 8b => "guest"
61 func DecodeUserString(obfuText []byte) (clearText string) {
62 for _, char := range obfuText {
63 clearText += string(rune(255 - uint(char)))
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!
71 func negateString(clearText []byte) []byte {
72 obfuText := make([]byte, len(clearText))
73 for i := 0; i < len(clearText); i++ {
74 obfuText[i] = 255 - clearText[i]