Add defaults to table and stop invalid blacklists

This commit is contained in:
light 2023-04-01 18:30:02 -04:00
parent 598a75f37d
commit 9bfb3d2474
3 changed files with 31 additions and 7 deletions

View File

@ -10,13 +10,13 @@ import (
// Update a user's last online time
func UpdateUserLastOnlineTime(pid uint32, lastOnline *nex.DateTime) {
var showOnline sql.NullBool
var showOnline bool
err := database.Postgres.QueryRow(`SELECT show_online FROM "3ds".user_data WHERE pid=$1`, pid).Scan(&showOnline)
if err != nil && err != sql.ErrNoRows {
globals.Logger.Critical(err.Error())
}
if showOnline.Valid && !showOnline.Bool {
if !showOnline {
return
}

View File

@ -15,8 +15,8 @@ func initPostgres3DS() {
_, err = Postgres.Exec(`CREATE TABLE IF NOT EXISTS "3ds".user_data (
pid integer PRIMARY KEY,
show_online boolean,
show_current_game boolean,
show_online boolean DEFAULT true,
show_current_game boolean DEFAULT true,
comment text,
comment_changed bigint,
last_online bigint,

View File

@ -16,14 +16,38 @@ func AddBlacklist(err error, client *nex.Client, callID uint32, blacklistPrincip
titleID := currentBlacklistPrincipal.GameKey.TitleID
titleVersion := currentBlacklistPrincipal.GameKey.TitleVersion
database_wiiu.SetUserBlocked(client.PID(), senderPID, titleID, titleVersion)
date := nex.NewDateTime(0)
date.FromTimestamp(time.Now())
currentBlacklistPrincipal.PrincipalBasicInfo = database_wiiu.GetUserInfoByPID(currentBlacklistPrincipal.PrincipalBasicInfo.PID)
userInfo := database_wiiu.GetUserInfoByPID(currentBlacklistPrincipal.PrincipalBasicInfo.PID)
if userInfo == nil {
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
rmcResponse.SetError(nex.Errors.FPD.FriendNotExists) // TODO: Not sure if this is the correct error.
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)
globals.NEXServer.Send(responsePacket)
return
}
currentBlacklistPrincipal.PrincipalBasicInfo = userInfo
currentBlacklistPrincipal.BlackListedSince = date
database_wiiu.SetUserBlocked(client.PID(), senderPID, titleID, titleVersion)
rmcResponseStream := nex.NewStreamOut(globals.NEXServer)
rmcResponseStream.WriteStructure(blacklistPrincipal)