mirror of
https://github.com/PretendoNetwork/friends.git
synced 2026-09-11 21:05:11 -05:00
NintendoCreateAccount now one function
This commit is contained in:
1
main.go
1
main.go
@@ -58,7 +58,6 @@ func main() {
|
||||
|
||||
// Account Management protocol handles
|
||||
accountManagementServer.NintendoCreateAccount(nintendoCreateAccount)
|
||||
accountManagementServer.NintendoCreateAccount3DS(nintendoCreateAccount3DS)
|
||||
|
||||
// Secure protocol handles
|
||||
secureServer.Register(register)
|
||||
|
||||
@@ -6,17 +6,34 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
nexproto "github.com/PretendoNetwork/nex-protocols-go"
|
||||
)
|
||||
|
||||
func nintendoCreateAccount(err error, client *nex.Client, callID uint32, username string, key string, groups uint32, email string, nintendoCreateAccountData *nexproto.NintendoCreateAccountData) {
|
||||
func nintendoCreateAccount(err error, client *nex.Client, callID uint32, strPrincipalName string, strKey string, uiGroups uint32, strEmail string, oAuthData *nex.DataHolder) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
tokenBase64 := nintendoCreateAccountData.Token
|
||||
var tokenBase64 string
|
||||
|
||||
oAuthDataType := oAuthData.TypeName()
|
||||
|
||||
if oAuthDataType == "NintendoCreateAccountData" { // Wii U
|
||||
nintendoCreateAccountData := oAuthData.ObjectData().(*nexproto.NintendoCreateAccountData)
|
||||
|
||||
tokenBase64 = nintendoCreateAccountData.Token
|
||||
} else if oAuthDataType == "AccountExtraInfo" { // 3DS
|
||||
accountExtraInfo := oAuthData.ObjectData().(*nexproto.AccountExtraInfo)
|
||||
|
||||
tokenBase64 = accountExtraInfo.NEXToken
|
||||
tokenBase64 = strings.Replace(tokenBase64, ".", "+", -1)
|
||||
tokenBase64 = strings.Replace(tokenBase64, "-", "/", -1)
|
||||
tokenBase64 = strings.Replace(tokenBase64, "*", "=", -1)
|
||||
}
|
||||
|
||||
encryptedToken, _ := base64.StdEncoding.DecodeString(tokenBase64)
|
||||
|
||||
decryptedToken, err := decryptToken(encryptedToken)
|
||||
@@ -29,7 +46,7 @@ func nintendoCreateAccount(err error, client *nex.Client, callID uint32, usernam
|
||||
pidByteArray := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(pidByteArray, pid)
|
||||
|
||||
mac := hmac.New(md5.New, []byte(key))
|
||||
mac := hmac.New(md5.New, []byte(strKey))
|
||||
mac.Write(pidByteArray)
|
||||
|
||||
pidHmac := hex.EncodeToString(mac.Sum(nil))
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
nexproto "github.com/PretendoNetwork/nex-protocols-go"
|
||||
)
|
||||
|
||||
func nintendoCreateAccount3DS(err error, client *nex.Client, callID uint32, strPrincipalName string, strKey string, uiGroups uint32, strEmail string, oAuthData *nexproto.AccountExtraInfo) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
tokenBase64 := oAuthData.NEXToken
|
||||
tokenBase64 = strings.Replace(tokenBase64, ".", "+", -1)
|
||||
tokenBase64 = strings.Replace(tokenBase64, "-", "/", -1)
|
||||
tokenBase64 = strings.Replace(tokenBase64, "*", "=", -1)
|
||||
|
||||
encryptedToken, _ := base64.StdEncoding.DecodeString(tokenBase64)
|
||||
|
||||
decryptedToken, err := decryptToken(encryptedToken)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pid := decryptedToken.UserPID
|
||||
|
||||
pidByteArray := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(pidByteArray, pid)
|
||||
|
||||
mac := hmac.New(md5.New, []byte(strKey))
|
||||
mac.Write(pidByteArray)
|
||||
|
||||
pidHmac := hex.EncodeToString(mac.Sum(nil))
|
||||
|
||||
rmcResponseStream := nex.NewStreamOut(nexServer)
|
||||
|
||||
rmcResponseStream.WriteUInt32LE(pid)
|
||||
rmcResponseStream.WriteString(pidHmac)
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
rmcResponse := nex.NewRMCResponse(nexproto.AccountManagementProtocolID, callID)
|
||||
rmcResponse.SetSuccess(nexproto.AccountManagementMethodNintendoCreateAccount, rmcResponseBody)
|
||||
|
||||
rmcResponseBytes := rmcResponse.Bytes()
|
||||
|
||||
responsePacket, _ := nex.NewPacketV0(client, nil)
|
||||
|
||||
responsePacket.SetVersion(0)
|
||||
responsePacket.SetSource(0xA1)
|
||||
responsePacket.SetDestination(0xAF)
|
||||
responsePacket.SetType(nex.DataPacket)
|
||||
responsePacket.SetPayload(rmcResponseBytes)
|
||||
|
||||
responsePacket.AddFlag(nex.FlagNeedsAck)
|
||||
responsePacket.AddFlag(nex.FlagReliable)
|
||||
|
||||
nexServer.Send(responsePacket)
|
||||
}
|
||||
Reference in New Issue
Block a user