friends/nex/friends-wiiu/remove_blacklist.go
Daniel López Guimaraes 8d8a05a7e2
Add missing error handling
Now database getters do error handling aswell, and in case of any error,
the NEX or GRPC method throws a proper error about it.

There are still some doubts on how to handle errors when a list of data
is processed, so for now skip that element on the list and continue.

Also add some constant errors to do better error handling.
2023-08-13 23:19:34 +01:00

47 lines
1.3 KiB
Go

package nex_friends_wiiu
import (
"github.com/PretendoNetwork/friends/database"
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
"github.com/PretendoNetwork/friends/globals"
nex "github.com/PretendoNetwork/nex-go"
friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu"
)
func RemoveBlacklist(err error, client *nex.Client, callID uint32, blockedPID uint32) uint32 {
if err != nil {
globals.Logger.Error(err.Error())
return nex.Errors.FPD.InvalidArgument
}
err = database_wiiu.UnsetUserBlocked(client.PID(), blockedPID)
if err != nil {
if err == database.ErrPIDNotFound {
return nex.Errors.FPD.NotInMyBlacklist
} else {
globals.Logger.Critical(err.Error())
return nex.Errors.FPD.Unknown
}
}
rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID)
rmcResponse.SetSuccess(friends_wiiu.MethodRemoveBlackList, nil)
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
}