mirror of
https://wiilab.wiimart.org/wiimart/WiiSOAP
synced 2025-09-05 21:11:02 +02:00
Add a whitelist for testing
This commit is contained in:
parent
115c33efbb
commit
2b37235666
44
ias.go
44
ias.go
@ -18,6 +18,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -26,6 +27,8 @@ import (
|
|||||||
"github.com/jackc/pgx/v4"
|
"github.com/jackc/pgx/v4"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +37,7 @@ const (
|
|||||||
(device_id, device_token, device_token_hashed, account_id, region, serial_number)
|
(device_id, device_token, device_token_hashed, account_id, region, serial_number)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)`
|
VALUES ($1, $2, $3, $4, $5, $6)`
|
||||||
SyncUserStatement = `SELECT
|
SyncUserStatement = `SELECT
|
||||||
account_id, device_token
|
account_id, device_token, serial_number
|
||||||
FROM userbase WHERE
|
FROM userbase WHERE
|
||||||
region = $1 AND
|
region = $1 AND
|
||||||
device_id = $2`
|
device_id = $2`
|
||||||
@ -92,16 +95,47 @@ func getRegistrationInfo(e *Envelope) {
|
|||||||
e.AddKVNode("Currency", "POINTS")
|
e.AddKVNode("Currency", "POINTS")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getWhitelistedSerialNumbers() []string {
|
||||||
|
file, err := os.Open("whitelist.txt")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
|
||||||
|
// Read each line
|
||||||
|
var sns []string
|
||||||
|
for scanner.Scan() {
|
||||||
|
sns = append(sns, scanner.Text())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for errors during scanning
|
||||||
|
if err = scanner.Err(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return sns
|
||||||
|
}
|
||||||
|
|
||||||
func syncRegistration(e *Envelope) {
|
func syncRegistration(e *Envelope) {
|
||||||
var accountId int64
|
var accountId int64
|
||||||
var deviceToken string
|
var deviceToken string
|
||||||
|
var serialNumber string
|
||||||
|
|
||||||
user := pool.QueryRow(ctx, SyncUserStatement, e.Region(), e.DeviceId())
|
user := pool.QueryRow(ctx, SyncUserStatement, e.Region(), e.DeviceId())
|
||||||
err := user.Scan(&accountId, &deviceToken)
|
err := user.Scan(&accountId, &deviceToken, &serialNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Error(7, "An error occurred querying the database.", err)
|
e.Error(7, "An error occurred querying the database.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !slices.Contains(getWhitelistedSerialNumbers(), serialNumber) {
|
||||||
|
// Since HTTP server runs on a separate Goroutine, this won't shut off the server,
|
||||||
|
// rather kill communication with the requesting console
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
e.AddKVNode("AccountId", strconv.FormatInt(accountId, 10))
|
e.AddKVNode("AccountId", strconv.FormatInt(accountId, 10))
|
||||||
e.AddKVNode("DeviceToken", deviceToken)
|
e.AddKVNode("DeviceToken", deviceToken)
|
||||||
e.AddKVNode("DeviceTokenExpired", "false")
|
e.AddKVNode("DeviceTokenExpired", "false")
|
||||||
@ -133,6 +167,12 @@ func register(e *Envelope) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !slices.Contains(getWhitelistedSerialNumbers(), serialNo) {
|
||||||
|
// Since HTTP server runs on a separate Goroutine, this won't shut off the server,
|
||||||
|
// rather kill communication with the requesting console
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Validate given friend code.
|
// Validate given friend code.
|
||||||
userId, err := strconv.ParseUint(deviceCode, 10, 64)
|
userId, err := strconv.ParseUint(deviceCode, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user