From 9bfb3d2474ab871ff7b0122d5bf52600fecfdbac Mon Sep 17 00:00:00 2001 From: light <57009359+hauntii@users.noreply.github.com> Date: Sat, 1 Apr 2023 18:30:02 -0400 Subject: [PATCH] Add defaults to table and stop invalid blacklists --- database/3ds/update_user_last_online_time.go | 4 +-- database/init_postgres_3ds.go | 4 +-- wiiu/add_blacklist.go | 30 ++++++++++++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/database/3ds/update_user_last_online_time.go b/database/3ds/update_user_last_online_time.go index 9839b76..dc0d499 100644 --- a/database/3ds/update_user_last_online_time.go +++ b/database/3ds/update_user_last_online_time.go @@ -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 } diff --git a/database/init_postgres_3ds.go b/database/init_postgres_3ds.go index 489c64b..e218bf4 100644 --- a/database/init_postgres_3ds.go +++ b/database/init_postgres_3ds.go @@ -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, diff --git a/wiiu/add_blacklist.go b/wiiu/add_blacklist.go index b5c2e7b..9ae1808 100644 --- a/wiiu/add_blacklist.go +++ b/wiiu/add_blacklist.go @@ -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)