friends/nex/friends-wiiu/add_blacklist.go
2023-08-14 13:17:48 +01:00

76 lines
2.3 KiB
Go

package nex_friends_wiiu
import (
"time"
"github.com/PretendoNetwork/friends/database"
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
"github.com/PretendoNetwork/friends/globals"
"github.com/PretendoNetwork/friends/utility"
nex "github.com/PretendoNetwork/nex-go"
friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu"
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
)
func AddBlacklist(err error, client *nex.Client, callID uint32, blacklistPrincipal *friends_wiiu_types.BlacklistedPrincipal) uint32 {
if err != nil {
globals.Logger.Error(err.Error())
return nex.Errors.FPD.InvalidArgument
}
currentBlacklistPrincipal := blacklistPrincipal
senderPID := currentBlacklistPrincipal.PrincipalBasicInfo.PID
titleID := currentBlacklistPrincipal.GameKey.TitleID
titleVersion := currentBlacklistPrincipal.GameKey.TitleVersion
date := nex.NewDateTime(0)
date.FromTimestamp(time.Now())
userInfo, err := utility.GetUserInfoByPID(currentBlacklistPrincipal.PrincipalBasicInfo.PID)
if err != nil {
if err == database.ErrPIDNotFound {
return nex.Errors.FPD.InvalidPrincipalID // TODO: Not sure if this is the correct error.
} else {
globals.Logger.Critical(err.Error())
return nex.Errors.FPD.Unknown
}
}
currentBlacklistPrincipal.PrincipalBasicInfo = userInfo
currentBlacklistPrincipal.BlackListedSince = date
err = database_wiiu.SetUserBlocked(client.PID(), senderPID, titleID, titleVersion)
if err != nil {
globals.Logger.Critical(err.Error())
return nex.Errors.FPD.Unknown
}
rmcResponseStream := nex.NewStreamOut(globals.SecureServer)
rmcResponseStream.WriteStructure(blacklistPrincipal)
rmcResponseBody := rmcResponseStream.Bytes()
// Build response packet
rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID)
rmcResponse.SetSuccess(friends_wiiu.MethodAddBlackList, 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)
globals.SecureServer.Send(responsePacket)
return 0
}