mirror of
https://github.com/PretendoNetwork/friends.git
synced 2024-06-01 11:37:53 -04:00
76 lines
2.3 KiB
Go
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
|
|
}
|