Properly implement SyncRegistration

This additionally updates GetRegistrationInfo to use similar logic. The two are the exact same function within both the ECDK and the Wii Shop Channel's ESHOP SDK - they differ only in name, authentication level, and a single key.
This commit is contained in:
Spotlight 2020-12-25 04:27:53 -06:00
parent 8009f1a510
commit 3182d4dd7e
No known key found for this signature in database
GPG Key ID: 874AA355B3209BDC
2 changed files with 24 additions and 11 deletions

32
ias.go
View File

@ -30,6 +30,7 @@ import (
)
var registerUser *sql.Stmt
var syncUser *sql.Stmt
func iasInitialize() {
var err error
@ -37,6 +38,11 @@ func iasInitialize() {
if err != nil {
log.Fatalf("ias initialize: error preparing statement: %v\n", err)
}
syncUser, err = db.Prepare(`SELECT userbase.AccountId, userbase.DeviceCode, userbase.DeviceTokenUnhashed FROM userbase WHERE Language = ? AND Country = ? AND Region = ? AND DeviceId = ?`)
if err != nil {
log.Fatalf("ias initialize: error preparing statement: %v\n", err)
}
}
func checkRegistration(e *Envelope) {
@ -59,26 +65,32 @@ func getChallenge(e *Envelope) {
}
func getRegistrationInfo(e *Envelope) {
reason := "how dirty. ;3"
accountId, err := getKey(e.doc, "AccountId")
if err != nil {
e.Error(7, reason, err)
// GetRegistrationInfo is SyncRegistration with authentication and an additional key.
syncRegistration(e)
// This _must_ be POINTS.
// It does not appear to be observed by any known client,
// but is sent by Nintendo in official requests.
e.AddKVNode("Currency", "POINTS")
}
deviceCode, err := getKey(e.doc, "DeviceCode")
func syncRegistration(e *Envelope) {
var accountId string
var deviceCode string
var deviceToken string
user := syncUser.QueryRow(e.Language(), e.Country(), e.Region(), e.DeviceId())
err := user.Scan(&accountId, &deviceCode, &deviceToken)
if err != nil {
e.Error(7, reason, err)
e.Error(7, "An error occurred querying the database.", err)
}
e.AddKVNode("AccountId", accountId)
e.AddKVNode("DeviceToken", "00000000")
e.AddKVNode("DeviceToken", deviceToken)
e.AddKVNode("DeviceTokenExpired", "false")
e.AddKVNode("Country", e.Country())
e.AddKVNode("ExtAccountId", "")
e.AddKVNode("DeviceCode", deviceCode)
e.AddKVNode("DeviceStatus", "R")
// This _must_ be POINTS.
e.AddKVNode("Currency", "POINTS")
}
func register(e *Envelope) {

View File

@ -95,6 +95,7 @@ func main() {
ias.Unauthenticated("CheckRegistration", checkRegistration)
ias.Unauthenticated("GetChallenge", getChallenge)
ias.Authenticated("GetRegistrationInfo", getRegistrationInfo)
ias.Unauthenticated("SyncRegistration", syncRegistration)
ias.Unauthenticated("Register", register)
ias.Authenticated("Unregister", unregister)
}