X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/9cf66aeafbcbb9237fedc2efc97cc2856eb60f7f..5954ccad9c87063231f3a8bb3e5d01675a9865ca:/hotline/user.go?ds=inline diff --git a/hotline/user.go b/hotline/user.go index 7d6f851..02deb31 100644 --- a/hotline/user.go +++ b/hotline/user.go @@ -8,17 +8,17 @@ import ( // User flags are stored as a 2 byte bitmap and represent various user states const ( - UserFlagAway = 0 // User is away - UserFlagAdmin = 1 // User is admin - UserFlagRefusePM = 2 // User refuses private messages - UserFlagRefusePChat = 3 // User refuses private chat + UserFlagAway = iota // User is away + UserFlagAdmin // User is admin + UserFlagRefusePM // User refuses private messages + UserFlagRefusePChat // User refuses private chat ) // FieldOptions flags are sent from v1.5+ clients as part of TranAgreed const ( - refusePM = 0 // User has "Refuse private messages" pref set - refuseChat = 1 // User has "Refuse private chat" pref set - autoResponse = 2 // User has "Automatic response" pref set + UserOptRefusePM = iota // User has "Refuse private messages" pref set + UserOptRefuseChat // User has "Refuse private chat" pref set + UserOptAutoResponse // User has "Automatic response" pref set ) type User struct { @@ -26,6 +26,8 @@ type User struct { Icon []byte // Size 2 Flags []byte // Size 2 Name string // Variable length user name + + readOffset int // Internal offset to track read progress } func (u *User) Read(p []byte) (int, error) { @@ -40,18 +42,21 @@ func (u *User) Read(p []byte) (int, error) { u.Flags = u.Flags[2:] } - out := append(u.ID[:2], u.Icon[:2]...) - out = append(out, u.Flags[:2]...) - out = append(out, nameLen...) - out = append(out, u.Name...) - - return copy(p, slices.Concat( + b := slices.Concat( u.ID, u.Icon, u.Flags, nameLen, []byte(u.Name), - )), io.EOF + ) + + if u.readOffset >= len(b) { + return 0, io.EOF // All bytes have been read + } + + n := copy(p, b) + + return n, io.EOF } func (u *User) Write(p []byte) (int, error) { @@ -64,15 +69,6 @@ func (u *User) Write(p []byte) (int, error) { return 8 + namelen, nil } -// decodeString decodes an obfuscated user string from a client -// e.g. 98 8a 9a 8c 8b => "guest" -func decodeString(obfuText []byte) (clearText string) { - for _, char := range obfuText { - clearText += string(rune(255 - uint(char))) - } - return clearText -} - // encodeString takes []byte s containing cleartext and rotates by 255 into obfuscated cleartext. // The Hotline protocol uses this format for sending passwords over network. // Not secure, but hey, it was the 90s!