diff options
Diffstat (limited to 'pkg/server/utils')
| -rw-r--r-- | pkg/server/utils/encode.go | 10 | ||||
| -rw-r--r-- | pkg/server/utils/hex.go | 31 |
2 files changed, 6 insertions, 35 deletions
diff --git a/pkg/server/utils/encode.go b/pkg/server/utils/encode.go index 86e5500..dc37b6b 100644 --- a/pkg/server/utils/encode.go +++ b/pkg/server/utils/encode.go @@ -3,6 +3,8 @@ package utils +import "github.com/Whirlsplash/munch/pkg/utilities" + const ( AutoServer = iota RoomServer @@ -28,10 +30,10 @@ func EncodeSessionInitialization(username string, password string, serverType in data += // Username - "\x02" + string(rune(len(username))) + ISO88591ToString(username) + + "\x02" + string(rune(len(username))) + utilities.ISO88591ToString(username) + // Password - "\x06" + string(rune(len(password))) + ISO88591ToString(password) + "\x06" + string(rune(len(password))) + utilities.ISO88591ToString(password) if serverType == AutoServer { data += "\x0c\x01\x31" @@ -45,7 +47,7 @@ func EncodeBuddyListUpdate(buddy string) []byte { data := "\x01\x1d" // Buddy UTF-8 length and UTF-8 - data += string(rune(len(buddy))) + ISO88591ToString(buddy) + data += string(rune(len(buddy))) + utilities.ISO88591ToString(buddy) // Buddy "add" data += "\x01" @@ -61,7 +63,7 @@ func EncodePropertyUpdate(avatar string) []byte { data := "\x01\x0f\x00\x05\x40\x01" // Avatar UTF-8 length and UTF-8 - data += string(rune(len("avatar:"+avatar))) + ISO88591ToString("avatar:"+avatar) + data += string(rune(len("avatar:"+avatar))) + utilities.ISO88591ToString("avatar:"+avatar) // Data length data = (string(rune(len(data) + 1))) + data diff --git a/pkg/server/utils/hex.go b/pkg/server/utils/hex.go deleted file mode 100644 index a5393aa..0000000 --- a/pkg/server/utils/hex.go +++ /dev/null @@ -1,31 +0,0 @@ -package utils - -import "unicode/utf8" - -// https://stackoverflow.com/a/43461796/14452787 -// -// I cannot explain the joy that flew through me once I found this ISO-8859-1 -// (Latin-1) to UTF-8 converter. I was looking for a valid solution on how to -// insert the username and password into a hex-escaped string sequence for -// EncodeSessionInitialization for hours and this finally solved all of my -// problems. -func ISO88591ToString(iso string) string { - var utf []rune - for i := 0; i < len(iso); i++ { - r := iso[i] - if utf == nil { - if r < utf8.RuneSelf { - continue - } - utf = make([]rune, len(iso)) - for j, r := range iso[:i] { - utf[j] = rune(r) - } - } - utf[i] = rune(r) - } - if utf == nil { - return string(iso) - } - return string(utf) -} |