]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/user.go
Add support for trackers that require a password
[rbdr/mobius] / hotline / user.go
index 26625a2f59849060122ea3c216ab40a9f1444226..c4e0790afd08b8531e7f55f3ab70b54551d0c155 100644 (file)
@@ -15,7 +15,7 @@ const (
        UserFlagRefusePChat = 3 // User refuses private chat
 )
 
-// FieldOptions flags are sent from v1.5+ clients as part of TranAgreed
+// User options are sent from clients and represent options set in the client's preferences.
 const (
        UserOptRefusePM     = 0 // User has "Refuse private messages" pref set
        UserOptRefuseChat   = 1 // User has "Refuse private chat" pref set
@@ -24,15 +24,15 @@ const (
 
 type UserFlags [2]byte
 
-func (flag *UserFlags) IsSet(i int) bool {
-       flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(flag[:])))
+func (f *UserFlags) IsSet(i int) bool {
+       flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(f[:])))
        return flagBitmap.Bit(i) == 1
 }
 
-func (flag *UserFlags) Set(i int, newVal uint) {
-       flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(flag[:])))
+func (f *UserFlags) Set(i int, newVal uint) {
+       flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(f[:])))
        flagBitmap.SetBit(flagBitmap, i, newVal)
-       binary.BigEndian.PutUint16(flag[:], uint16(flagBitmap.Int64()))
+       binary.BigEndian.PutUint16(f[:], uint16(flagBitmap.Int64()))
 }
 
 type User struct {
@@ -84,10 +84,10 @@ func (u *User) Write(p []byte) (int, error) {
        return 8 + namelen, nil
 }
 
-// encodeString takes []byte s containing cleartext and rotates by 255 into obfuscated 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!
-func encodeString(clearText []byte) []byte {
+func EncodeString(clearText []byte) []byte {
        obfuText := make([]byte, len(clearText))
        for i := 0; i < len(clearText); i++ {
                obfuText[i] = 255 - clearText[i]