Created
June 6, 2022 15:45
-
-
Save codecat/3428050103d4b6dfdf20eaf916b0c434 to your computer and use it in GitHub Desktop.
Converting between Nadeo account ID and encoded game logins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/base64" | |
"encoding/hex" | |
"regexp" | |
"strings" | |
) | |
func isUUID(id string) bool { | |
matched, _ := regexp.MatchString("^[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$", id) | |
return matched | |
} | |
func isGameLogin(id string) bool { | |
matched, _ := regexp.MatchString("^[a-zA-Z0-9\\-_]{22}$", id) | |
return matched | |
} | |
func accountIDToLogin(accountID string) string { | |
if !isUUID(accountID) { | |
return "" | |
} | |
bytes, err := hex.DecodeString(strings.ReplaceAll(accountID, "-", "")) | |
if err != nil { | |
return "" | |
} | |
return base64.RawURLEncoding.EncodeToString(bytes) | |
} | |
func loginToAccountID(login string) string { | |
if !isGameLogin(login) { | |
return "" | |
} | |
bytes, err := base64.RawURLEncoding.DecodeString(login) | |
if err != nil { | |
return "" | |
} | |
ret := hex.EncodeToString(bytes) | |
return ret[:8] + "-" + ret[8:12] + "-" + ret[12:16] + "-" + ret[16:20] + "-" + ret[20:] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment