Merge pull request #2 from PretendoNetwork/feature-unfriendly-methods

Request rejection, blocking, and unfriending
This commit is contained in:
Jonathan Barrow 2023-04-08 09:56:01 -04:00 committed by GitHub
commit 1d82e2e39c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 574 additions and 166 deletions

View File

@ -23,8 +23,14 @@ func assignNEXProtocols() {
// Friends (WiiU) protocol handles
friendsWiiUServer.UpdateAndGetAllInformation(friends_wiiu.UpdateAndGetAllInformation)
friendsWiiUServer.AddFriendRequest(friends_wiiu.AddFriendRequest)
friendsWiiUServer.RemoveFriend(friends_wiiu.RemoveFriend)
friendsWiiUServer.CancelFriendRequest(friends_wiiu.CancelFriendRequest)
friendsWiiUServer.AcceptFriendRequest(friends_wiiu.AcceptFriendRequest)
friendsWiiUServer.DeleteFriendRequest(friends_wiiu.DeleteFriendRequest)
friendsWiiUServer.DenyFriendRequest(friends_wiiu.DenyFriendRequest)
friendsWiiUServer.MarkFriendRequestsAsReceived(friends_wiiu.MarkFriendRequestsAsReceived)
friendsWiiUServer.AddBlackList(friends_wiiu.AddBlacklist)
friendsWiiUServer.RemoveBlackList(friends_wiiu.RemoveBlacklist)
friendsWiiUServer.UpdatePresence(friends_wiiu.UpdatePresence)
friendsWiiUServer.UpdateComment(friends_wiiu.UpdateComment)
friendsWiiUServer.UpdatePreference(friends_wiiu.UpdatePreference)

View File

@ -13,7 +13,7 @@ func GetUserFriends(pid uint32) []*nexproto.FriendRelationship {
friendRelationships := make([]*nexproto.FriendRelationship, 0)
rows, err := database.Postgres.Query(`
SELECT user2_pid, type FROM "3ds".friendships WHERE user1_pid=$1 AND type=1`, pid)
SELECT user2_pid, type FROM "3ds".friendships WHERE user1_pid=$1 AND type=1 LIMIT 100`, pid)
if err != nil && err != sql.ErrNoRows {
globals.Logger.Critical(err.Error())
}

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

@ -15,11 +15,11 @@ func initPostgresWiiU() {
_, err = Postgres.Exec(`CREATE TABLE IF NOT EXISTS wiiu.user_data (
pid integer PRIMARY KEY,
show_online boolean,
show_current_game boolean,
block_friend_requests boolean,
comment text,
comment_changed bigint,
show_online boolean DEFAULT true,
show_current_game boolean DEFAULT true,
block_friend_requests boolean DEFAULT false,
comment text DEFAULT '',
comment_changed bigint DEFAULT 0,
last_online bigint
)`)
if err != nil {
@ -44,8 +44,10 @@ func initPostgresWiiU() {
id bigserial PRIMARY KEY,
blocker_pid integer,
blocked_pid integer,
title_id bigint,
title_version integer,
date bigint,
active boolean
UNIQUE (blocker_pid, blocked_pid)
)`)
if err != nil {
globals.Logger.Critical(err.Error())

View File

@ -1,7 +1,6 @@
package database_wiiu
import (
"encoding/base64"
"time"
"github.com/PretendoNetwork/friends-secure/database"
@ -9,10 +8,9 @@ import (
"github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
"github.com/gocql/gocql"
"go.mongodb.org/mongo-driver/bson"
)
func AcceptFriendshipAndReturnFriendInfo(friendRequestID uint64) *nexproto.FriendInfo {
func AcceptFriendRequestAndReturnFriendInfo(friendRequestID uint64) *nexproto.FriendInfo {
var senderPID uint32
var recipientPID uint32
@ -69,21 +67,9 @@ func AcceptFriendshipAndReturnFriendInfo(friendRequestID uint64) *nexproto.Frien
lastOnline.FromTimestamp(time.Now())
} else {
// Offline
senderUserInforation := GetUserInfoByPID(senderPID)
encodedMiiData := senderUserInforation["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
friendInfo.NNAInfo = nexproto.NewNNAInfo()
friendInfo.NNAInfo.PrincipalBasicInfo = nexproto.NewPrincipalBasicInfo()
friendInfo.NNAInfo.PrincipalBasicInfo.PID = senderPID
friendInfo.NNAInfo.PrincipalBasicInfo.NNID = senderUserInforation["username"].(string)
friendInfo.NNAInfo.PrincipalBasicInfo.Mii = nexproto.NewMiiV2()
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Name = senderUserInforation["mii"].(bson.M)["name"].(string)
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Unknown1 = 0
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Unknown2 = 0
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Data = decodedMiiData
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Datetime = nex.NewDateTime(0)
friendInfo.NNAInfo.PrincipalBasicInfo.Unknown = 0
friendInfo.NNAInfo.PrincipalBasicInfo = GetUserInfoByPID(senderPID)
friendInfo.NNAInfo.Unknown1 = 0
friendInfo.NNAInfo.Unknown2 = 0

View File

@ -0,0 +1,23 @@
package database_wiiu
import (
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
)
func DeleteFriendRequestAndReturnFriendPID(friendRequestID uint64) uint32 {
var recipientPID uint32
err := database.Postgres.QueryRow(`SELECT recipient_pid FROM wiiu.friend_requests WHERE id=$1`, friendRequestID).Scan(&recipientPID)
if err != nil {
globals.Logger.Critical(err.Error())
}
_, err = database.Postgres.Exec(`
DELETE FROM wiiu.friend_requests WHERE id=$1`, friendRequestID)
if err != nil {
globals.Logger.Critical(err.Error())
}
return recipientPID
}

View File

@ -0,0 +1,27 @@
package database_wiiu
import (
"database/sql"
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
)
// Get a users outgoing friend request
func GetPIDsByFriendRequestID(friendRequestID uint64) (uint32, uint32) {
var senderPID uint32
var recipientPID uint32
err := database.Postgres.QueryRow(`
SELECT sender_pid, recipient_pid FROM wiiu.friend_requests WHERE id=$1
`, friendRequestID).Scan(&senderPID, &recipientPID)
if err != nil {
if err == sql.ErrNoRows {
globals.Logger.Warning(err.Error())
} else {
globals.Logger.Critical(err.Error())
}
}
return senderPID, recipientPID
}

View File

@ -1,8 +1,40 @@
package database_wiiu
import nexproto "github.com/PretendoNetwork/nex-protocols-go"
import (
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
"github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
// Get a users blacklist
func GetUserBlockList(pid uint32) []*nexproto.BlacklistedPrincipal {
return make([]*nexproto.BlacklistedPrincipal, 0)
blockList := make([]*nexproto.BlacklistedPrincipal, 0)
rows, err := database.Postgres.Query(`SELECT blocked_pid, title_id, title_version, date FROM wiiu.blocks WHERE blocker_pid=$1`, pid)
if err != nil {
globals.Logger.Critical(err.Error())
return blockList
}
for rows.Next() {
var pid uint32
var titleId uint64
var titleVersion uint16
var date *nex.DateTime
rows.Scan(&pid, &titleId, &titleVersion, &date)
blacklistPrincipal := nexproto.NewBlacklistedPrincipal()
blacklistPrincipal.PrincipalBasicInfo = GetUserInfoByPID(pid)
blacklistPrincipal.GameKey = nexproto.NewGameKey()
blacklistPrincipal.GameKey.TitleID = titleId
blacklistPrincipal.GameKey.TitleVersion = titleVersion
blacklistPrincipal.BlackListedSince = date
blockList = append(blockList, blacklistPrincipal)
}
return blockList
}

View File

@ -1,7 +1,6 @@
package database_wiiu
import (
"encoding/base64"
"fmt"
"time"
@ -10,14 +9,13 @@ import (
"github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
"github.com/gocql/gocql"
"go.mongodb.org/mongo-driver/bson"
)
// Get a users friend list
func GetUserFriendList(pid uint32) []*nexproto.FriendInfo {
friendList := make([]*nexproto.FriendInfo, 0)
rows, err := database.Postgres.Query(`SELECT user2_pid, date FROM wiiu.friendships WHERE user1_pid=$1 AND active=true`, pid)
rows, err := database.Postgres.Query(`SELECT user2_pid, date FROM wiiu.friendships WHERE user1_pid=$1 AND active=true LIMIT 100`, pid)
if err != nil {
globals.Logger.Critical(err.Error())
return friendList
@ -53,21 +51,9 @@ func GetUserFriendList(pid uint32) []*nexproto.FriendInfo {
lastOnline.FromTimestamp(time.Now())
} else {
// Offline
friendUserInforation := GetUserInfoByPID(friendPID)
encodedMiiData := friendUserInforation["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
friendInfo.NNAInfo = nexproto.NewNNAInfo()
friendInfo.NNAInfo.PrincipalBasicInfo = nexproto.NewPrincipalBasicInfo()
friendInfo.NNAInfo.PrincipalBasicInfo.PID = friendPID
friendInfo.NNAInfo.PrincipalBasicInfo.NNID = friendUserInforation["username"].(string)
friendInfo.NNAInfo.PrincipalBasicInfo.Mii = nexproto.NewMiiV2()
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Name = friendUserInforation["mii"].(bson.M)["name"].(string)
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Unknown1 = 0
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Unknown2 = 0
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Data = decodedMiiData
friendInfo.NNAInfo.PrincipalBasicInfo.Mii.Datetime = nex.NewDateTime(0)
friendInfo.NNAInfo.PrincipalBasicInfo.Unknown = 0
friendInfo.NNAInfo.PrincipalBasicInfo = GetUserInfoByPID(friendPID)
friendInfo.NNAInfo.Unknown1 = 0
friendInfo.NNAInfo.Unknown2 = 0

View File

@ -1,13 +1,10 @@
package database_wiiu
import (
"encoding/base64"
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
"github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
"go.mongodb.org/mongo-driver/bson"
)
// Get a users received friend requests
@ -29,22 +26,9 @@ func GetUserFriendRequestsIn(pid uint32) []*nexproto.FriendRequest {
var received bool
rows.Scan(&id, &senderPID, &sentOn, &expiresOn, &message, &received)
senderUserInforation := GetUserInfoByPID(senderPID)
encodedMiiData := senderUserInforation["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
friendRequest := nexproto.NewFriendRequest()
friendRequest.PrincipalInfo = nexproto.NewPrincipalBasicInfo()
friendRequest.PrincipalInfo.PID = senderPID
friendRequest.PrincipalInfo.NNID = senderUserInforation["username"].(string)
friendRequest.PrincipalInfo.Mii = nexproto.NewMiiV2()
friendRequest.PrincipalInfo.Mii.Name = senderUserInforation["mii"].(bson.M)["name"].(string)
friendRequest.PrincipalInfo.Mii.Unknown1 = 0 // replaying from real server
friendRequest.PrincipalInfo.Mii.Unknown2 = 0 // replaying from real server
friendRequest.PrincipalInfo.Mii.Data = decodedMiiData
friendRequest.PrincipalInfo.Mii.Datetime = nex.NewDateTime(0)
friendRequest.PrincipalInfo.Unknown = 2 // replaying from real server
friendRequest.PrincipalInfo = GetUserInfoByPID(senderPID)
friendRequest.Message = nexproto.NewFriendRequestMessage()
friendRequest.Message.FriendRequestID = id

View File

@ -1,20 +1,17 @@
package database_wiiu
import (
"encoding/base64"
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
"github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
"go.mongodb.org/mongo-driver/bson"
)
// Get a users sent friend requests
func GetUserFriendRequestsOut(pid uint32) []*nexproto.FriendRequest {
friendRequestsOut := make([]*nexproto.FriendRequest, 0)
rows, err := database.Postgres.Query(`SELECT id, recipient_pid, sent_on, expires_on, message, received FROM wiiu.friend_requests WHERE sender_pid=$1 AND accepted=false AND denied=false`, pid)
rows, err := database.Postgres.Query(`SELECT id, recipient_pid, sent_on, expires_on, message, received FROM wiiu.friend_requests WHERE sender_pid=$1 AND accepted=false`, pid)
if err != nil {
globals.Logger.Critical(err.Error())
return friendRequestsOut
@ -29,22 +26,9 @@ func GetUserFriendRequestsOut(pid uint32) []*nexproto.FriendRequest {
var received bool
rows.Scan(&id, &recipientPID, &sentOn, &expiresOn, &message, &received)
recipientUserInforation := GetUserInfoByPID(recipientPID)
encodedMiiData := recipientUserInforation["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
friendRequest := nexproto.NewFriendRequest()
friendRequest.PrincipalInfo = nexproto.NewPrincipalBasicInfo()
friendRequest.PrincipalInfo.PID = recipientPID
friendRequest.PrincipalInfo.NNID = recipientUserInforation["username"].(string)
friendRequest.PrincipalInfo.Mii = nexproto.NewMiiV2()
friendRequest.PrincipalInfo.Mii.Name = recipientUserInforation["mii"].(bson.M)["name"].(string)
friendRequest.PrincipalInfo.Mii.Unknown1 = 0 // replaying from real server
friendRequest.PrincipalInfo.Mii.Unknown2 = 0 // replaying from real server
friendRequest.PrincipalInfo.Mii.Data = decodedMiiData
friendRequest.PrincipalInfo.Mii.Datetime = nex.NewDateTime(0)
friendRequest.PrincipalInfo.Unknown = 2 // replaying from real server
friendRequest.PrincipalInfo = GetUserInfoByPID(recipientPID)
friendRequest.Message = nexproto.NewFriendRequestMessage()
friendRequest.Message.FriendRequestID = id

View File

@ -2,15 +2,18 @@ package database_wiiu
import (
"context"
"encoding/base64"
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
"github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func GetUserInfoByPID(pid uint32) bson.M {
func GetUserInfoByPID(pid uint32) *nexproto.PrincipalBasicInfo {
var result bson.M
err := database.MongoCollection.FindOne(context.TODO(), bson.D{{Key: "pid", Value: pid}}, options.FindOne()).Decode(&result)
@ -23,5 +26,20 @@ func GetUserInfoByPID(pid uint32) bson.M {
globals.Logger.Critical(err.Error())
}
return result
info := nexproto.NewPrincipalBasicInfo()
info.PID = pid
info.NNID = result["username"].(string)
info.Mii = nexproto.NewMiiV2()
info.Unknown = 2
encodedMiiData := result["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
info.Mii.Name = result["mii"].(bson.M)["name"].(string)
info.Mii.Unknown1 = 0
info.Mii.Unknown2 = 0
info.Mii.Data = decodedMiiData
info.Mii.Datetime = nex.NewDateTime(0)
return info
}

View File

@ -7,7 +7,7 @@ import (
func IsFriendRequestBlocked(requesterPID uint32, requestedPID uint32) bool {
var found bool
err := database.Postgres.QueryRow(`SELECT COUNT(*) FROM wiiu.blocks WHERE blocker_pid=$1 AND blocked_pid=$2 AND active=true LIMIT 1`, requesterPID, requestedPID).Scan(&found)
err := database.Postgres.QueryRow(`SELECT COUNT(*) FROM wiiu.blocks WHERE blocker_pid=$1 AND blocked_pid=$2 LIMIT 1`, requesterPID, requestedPID).Scan(&found)
if err != nil {
globals.Logger.Critical(err.Error())
}

View File

@ -0,0 +1,21 @@
package database_wiiu
import (
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
)
// Remove a user's friend relationship
func RemoveFriendship(user1_pid uint32, user2_pid uint32) {
_, err := database.Postgres.Exec(`
DELETE FROM wiiu.friendships WHERE user1_pid=$1 AND user2_pid=$2`, user1_pid, user2_pid)
if err != nil {
globals.Logger.Critical(err.Error())
}
_, err = database.Postgres.Exec(`
UPDATE wiiu.friendships SET active=false WHERE user1_pid=$1 AND user2_pid=$2`, user2_pid, user1_pid)
if err != nil {
globals.Logger.Critical(err.Error())
}
}

View File

@ -1,16 +1,35 @@
package database_wiiu
import (
"database/sql"
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
)
func SaveFriendRequest(senderPID uint32, recipientPID uint32, sentTime uint64, expireTime uint64, message string) uint64 {
var id uint64
err := database.Postgres.QueryRow(`
INSERT INTO wiiu.friend_requests (sender_pid, recipient_pid, sent_on, expires_on, message, received, accepted, denied)
VALUES ($1, $2, $3, $4, $5, false, false, false) RETURNING id`, senderPID, recipientPID, sentTime, expireTime, message).Scan(&id)
friendRequestBlocked := IsFriendRequestBlocked(recipientPID, senderPID)
// Make sure we don't already have that friend request! If we do, give them the one we already have.
err := database.Postgres.QueryRow(`SELECT id FROM wiiu.friend_requests WHERE sender_pid=$1 AND recipient_pid=$2`, senderPID, recipientPID).Scan(&id)
if err != nil && err != sql.ErrNoRows {
globals.Logger.Critical(err.Error())
return 0
} else if id != 0 {
// If they aren't blocked, we want to unset the denied status on the previous request we have so that it appears again.
if friendRequestBlocked {
return id
} else {
UnsetFriendRequestDenied(id)
return id
}
}
err = database.Postgres.QueryRow(`
INSERT INTO wiiu.friend_requests (sender_pid, recipient_pid, sent_on, expires_on, message, received, accepted, denied)
VALUES ($1, $2, $3, $4, $5, false, false, $6) RETURNING id`, senderPID, recipientPID, sentTime, expireTime, message, friendRequestBlocked).Scan(&id)
if err != nil {
globals.Logger.Critical(err.Error())
return 0

View File

@ -0,0 +1,14 @@
package database_wiiu
import (
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
)
func SetFriendRequestDenied(friendRequestID uint64) {
_, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET denied=true WHERE id=$1`, friendRequestID)
if err != nil {
globals.Logger.Critical(err.Error())
}
}

View File

@ -0,0 +1,24 @@
package database_wiiu
import (
"time"
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
"github.com/PretendoNetwork/nex-go"
)
func SetUserBlocked(blockerPID uint32, blockedPID uint32, titleId uint64, titleVersion uint16) {
date := nex.NewDateTime(0)
date.FromTimestamp(time.Now())
_, err := database.Postgres.Exec(`
INSERT INTO wiiu.blocks (blocker_pid, blocked_pid, title_id, title_version, date)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (blocker_pid, blocked_pid)
DO UPDATE SET
date = $5`, blockerPID, blockedPID, titleId, titleVersion, date.Value())
if err != nil {
globals.Logger.Critical(err.Error())
}
}

View File

@ -0,0 +1,14 @@
package database_wiiu
import (
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
)
func UnsetFriendRequestDenied(friendRequestID uint64) {
_, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET denied=false WHERE id=$1`, friendRequestID)
if err != nil {
globals.Logger.Critical(err.Error())
}
}

View File

@ -0,0 +1,15 @@
package database_wiiu
import (
"github.com/PretendoNetwork/friends-secure/database"
"github.com/PretendoNetwork/friends-secure/globals"
)
// Remove a block from a user
func UnsetUserBlocked(user1_pid uint32, user2_pid uint32) {
_, err := database.Postgres.Exec(`
DELETE FROM wiiu.blocks WHERE blocker_pid=$1 AND blocked_pid=$2`, user1_pid, user2_pid)
if err != nil {
globals.Logger.Critical(err.Error())
}
}

14
go.mod
View File

@ -4,8 +4,8 @@ go 1.18
require (
github.com/PretendoNetwork/grpc-go v0.0.0-20220820112405-4798a22a13f3
github.com/PretendoNetwork/nex-go v1.0.11
github.com/PretendoNetwork/nex-protocols-go v1.0.13
github.com/PretendoNetwork/nex-go v1.0.14
github.com/PretendoNetwork/nex-protocols-go v1.0.19
github.com/PretendoNetwork/plogger-go v1.0.2
github.com/gocql/gocql v1.2.1
github.com/golang/protobuf v1.5.2
@ -17,17 +17,17 @@ require (
)
require (
github.com/fatih/color v1.13.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/jwalton/go-supportscolor v1.1.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/superwhiskers/crunch/v3 v3.5.6 // indirect
github.com/superwhiskers/crunch/v3 v3.5.7 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
@ -35,8 +35,8 @@ require (
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/sync v0.0.0-20220907140024-f12130a52804 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220909194730-69f6226f97e5 // indirect
google.golang.org/protobuf v1.28.1 // indirect

34
go.sum
View File

@ -1,9 +1,9 @@
github.com/PretendoNetwork/grpc-go v0.0.0-20220820112405-4798a22a13f3 h1:rXQLOWgjXYrmdBCMiZzoSWoe4VPxPCYbveyf0pCagKU=
github.com/PretendoNetwork/grpc-go v0.0.0-20220820112405-4798a22a13f3/go.mod h1:iONEVRP4H4OEkfzSWfAWf0Fvh9upLBv21bq2R2iy8Jk=
github.com/PretendoNetwork/nex-go v1.0.11 h1:aKd7pga0YVR7zpXOqclKNWPUgjHUORVGfaTa3lAqY+M=
github.com/PretendoNetwork/nex-go v1.0.11/go.mod h1:Bx2ONeSefnbJyE0IDIwGopxrjRrnszOV/uQv74Cx+m0=
github.com/PretendoNetwork/nex-protocols-go v1.0.13 h1:551jpLUq9FGwlV2EmMF6egO0lsnjZnafv5dc0GuU1zA=
github.com/PretendoNetwork/nex-protocols-go v1.0.13/go.mod h1:rmJrhlkNr8wuPqjgR1ozjTdqg4A8zG3bu0XvD4Aoz7Q=
github.com/PretendoNetwork/nex-go v1.0.14 h1:K5E9lh6vjtJ1nMeYOUk/iS7aYtORS0bbbmrNhIQ2AgI=
github.com/PretendoNetwork/nex-go v1.0.14/go.mod h1:Bx2ONeSefnbJyE0IDIwGopxrjRrnszOV/uQv74Cx+m0=
github.com/PretendoNetwork/nex-protocols-go v1.0.19 h1:SfD/8tIcuqeqZH/ySGxc+kd9EAyvMvH7+gSjG4nCKfc=
github.com/PretendoNetwork/nex-protocols-go v1.0.19/go.mod h1:wsa+sNxQj3+THXS2K+R8Ulg4VkCcEBmsg0SRnLnYrjw=
github.com/PretendoNetwork/plogger-go v1.0.2 h1:vWKEnEmJJzYwqLxLyiSsAvCrZV6qnnu/a0GQOjIfzY0=
github.com/PretendoNetwork/plogger-go v1.0.2/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
@ -13,8 +13,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/gocql/gocql v1.2.1 h1:G/STxUzD6pGvRHzG0Fi7S04SXejMKBbRZb7pwre1edU=
github.com/gocql/gocql v1.2.1/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJrHG8=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
@ -43,13 +43,11 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
@ -62,8 +60,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/superwhiskers/crunch/v3 v3.5.6 h1:gxAMb9Ga/DerwN8jg3U1OMAEPLww3WCW465R07owRUQ=
github.com/superwhiskers/crunch/v3 v3.5.6/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA=
github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg=
github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
@ -93,20 +91,18 @@ golang.org/x/sync v0.0.0-20220907140024-f12130a52804 h1:0SH2R3f1b1VmIMG7BXbEZCBU
golang.org/x/sync v0.0.0-20220907140024-f12130a52804/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=

View File

@ -0,0 +1,42 @@
package notifications_wiiu
import (
"github.com/PretendoNetwork/friends-secure/globals"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func SendFriendshipRemoved(client *nex.Client, senderPID uint32) {
nintendoNotificationEventGeneral := nexproto.NewNintendoNotificationEventGeneral()
eventObject := nexproto.NewNintendoNotificationEvent()
eventObject.Type = 26
eventObject.SenderPID = senderPID
eventObject.DataHolder = nex.NewDataHolder()
eventObject.DataHolder.SetTypeName("NintendoNotificationEventGeneral")
eventObject.DataHolder.SetObjectData(nintendoNotificationEventGeneral)
stream := nex.NewStreamOut(globals.NEXServer)
stream.WriteStructure(eventObject)
rmcRequest := nex.NewRMCRequest()
rmcRequest.SetProtocolID(nexproto.NintendoNotificationsProtocolID)
rmcRequest.SetCallID(3810693103)
rmcRequest.SetMethodID(nexproto.NintendoNotificationsMethodProcessNintendoNotificationEvent1)
rmcRequest.SetParameters(stream.Bytes())
rmcRequestBytes := rmcRequest.Bytes()
requestPacket, _ := nex.NewPacketV0(client, nil)
requestPacket.SetVersion(0)
requestPacket.SetSource(0xA1)
requestPacket.SetDestination(0xAF)
requestPacket.SetType(nex.DataPacket)
requestPacket.SetPayload(rmcRequestBytes)
requestPacket.AddFlag(nex.FlagNeedsAck)
requestPacket.AddFlag(nex.FlagReliable)
globals.NEXServer.Send(requestPacket)
}

View File

@ -9,7 +9,7 @@ import (
)
func AcceptFriendRequest(err error, client *nex.Client, callID uint32, id uint64) {
friendInfo := database_wiiu.AcceptFriendshipAndReturnFriendInfo(id)
friendInfo := database_wiiu.AcceptFriendRequestAndReturnFriendInfo(id)
friendPID := friendInfo.NNAInfo.PrincipalBasicInfo.PID
connectedUser := globals.ConnectedUsers[friendPID]

75
wiiu/add_blacklist.go Normal file
View File

@ -0,0 +1,75 @@
package friends_wiiu
import (
"time"
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
"github.com/PretendoNetwork/friends-secure/globals"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func AddBlacklist(err error, client *nex.Client, callID uint32, blacklistPrincipal *nexproto.BlacklistedPrincipal) {
currentBlacklistPrincipal := blacklistPrincipal
senderPID := currentBlacklistPrincipal.PrincipalBasicInfo.PID
titleID := currentBlacklistPrincipal.GameKey.TitleID
titleVersion := currentBlacklistPrincipal.GameKey.TitleVersion
date := nex.NewDateTime(0)
date.FromTimestamp(time.Now())
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)
rmcResponseBody := rmcResponseStream.Bytes()
// Build response packet
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodAddBlackList, 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.NEXServer.Send(responsePacket)
}

View File

@ -1,7 +1,6 @@
package friends_wiiu
import (
"encoding/base64"
"fmt"
"time"
@ -10,7 +9,6 @@ import (
notifications_wiiu "github.com/PretendoNetwork/friends-secure/notifications/wiiu"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
"go.mongodb.org/mongo-driver/bson"
)
func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32, unknown2 uint8, message string, unknown4 uint8, unknown5 string, gameKey *nexproto.GameKey, unknown6 *nex.DateTime) {
@ -53,24 +51,9 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32,
friendRequestID := database_wiiu.SaveFriendRequest(senderPID, recipientPID, sentTime.Value(), expireTime.Value(), message)
recipientUserInforation := database_wiiu.GetUserInfoByPID(recipientPID)
friendRequest := nexproto.NewFriendRequest()
friendRequest.PrincipalInfo = nexproto.NewPrincipalBasicInfo()
friendRequest.PrincipalInfo.PID = recipientPID
friendRequest.PrincipalInfo.NNID = recipientUserInforation["username"].(string)
friendRequest.PrincipalInfo.Mii = nexproto.NewMiiV2()
friendRequest.PrincipalInfo.Unknown = 2 // replaying from real server
encodedMiiData := recipientUserInforation["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
friendRequest.PrincipalInfo.Mii.Name = recipientUserInforation["mii"].(bson.M)["name"].(string)
friendRequest.PrincipalInfo.Mii.Unknown1 = 0 // replaying from real server
friendRequest.PrincipalInfo.Mii.Unknown2 = 0 // replaying from real server
friendRequest.PrincipalInfo.Mii.Data = decodedMiiData
friendRequest.PrincipalInfo.Mii.Datetime = nex.NewDateTime(0)
friendRequest.PrincipalInfo = database_wiiu.GetUserInfoByPID(recipientPID)
friendRequest.Message = nexproto.NewFriendRequestMessage()
friendRequest.Message.FriendRequestID = friendRequestID
@ -130,24 +113,10 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32,
recipientClient := client.Server().FindClientFromPID(recipientPID)
if recipientClient != nil {
senderUserInforation := database_wiiu.GetUserInfoByPID(senderPID)
friendRequestNotificationData := nexproto.NewFriendRequest()
friendRequestNotificationData.PrincipalInfo = nexproto.NewPrincipalBasicInfo()
friendRequestNotificationData.PrincipalInfo.PID = senderPID
friendRequestNotificationData.PrincipalInfo.NNID = senderUserInforation["username"].(string)
friendRequestNotificationData.PrincipalInfo.Mii = nexproto.NewMiiV2()
friendRequestNotificationData.PrincipalInfo.Unknown = 2 // replaying from real server
encodedMiiData := senderUserInforation["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
friendRequestNotificationData.PrincipalInfo.Mii.Name = senderUserInforation["mii"].(bson.M)["name"].(string)
friendRequestNotificationData.PrincipalInfo.Mii.Unknown1 = 0 // replaying from real server
friendRequestNotificationData.PrincipalInfo.Mii.Unknown2 = 0 // replaying from real server
friendRequestNotificationData.PrincipalInfo.Mii.Data = decodedMiiData
friendRequestNotificationData.PrincipalInfo.Mii.Datetime = nex.NewDateTime(0)
friendRequestNotificationData.PrincipalInfo = database_wiiu.GetUserInfoByPID(senderPID)
friendRequestNotificationData.Message = nexproto.NewFriendRequestMessage()
friendRequestNotificationData.Message.FriendRequestID = friendRequestID

View File

@ -0,0 +1,37 @@
package friends_wiiu
import (
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
"github.com/PretendoNetwork/friends-secure/globals"
notifications_wiiu "github.com/PretendoNetwork/friends-secure/notifications/wiiu"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func CancelFriendRequest(err error, client *nex.Client, callID uint32, id uint64) {
pid := database_wiiu.DeleteFriendRequestAndReturnFriendPID(id)
connectedUser := globals.ConnectedUsers[pid]
if connectedUser != nil {
// This may send the friend removed notification, but they are the same.
go notifications_wiiu.SendFriendshipRemoved(connectedUser.Client, client.PID())
}
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodCancelFriendRequest, 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.NEXServer.Send(responsePacket)
}

View File

@ -0,0 +1,30 @@
package friends_wiiu
import (
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
"github.com/PretendoNetwork/friends-secure/globals"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func DeleteFriendRequest(err error, client *nex.Client, callID uint32, id uint64) {
database_wiiu.SetFriendRequestDenied(id)
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodDeleteFriendRequest, 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.NEXServer.Send(responsePacket)
}

View File

@ -0,0 +1,54 @@
package friends_wiiu
import (
"time"
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
"github.com/PretendoNetwork/friends-secure/globals"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func DenyFriendRequest(err error, client *nex.Client, callID uint32, id uint64) {
database_wiiu.SetFriendRequestDenied(id)
senderPID, _ := database_wiiu.GetPIDsByFriendRequestID(id)
database_wiiu.SetUserBlocked(client.PID(), senderPID, 0, 0)
info := database_wiiu.GetUserInfoByPID(senderPID)
date := nex.NewDateTime(0)
date.FromTimestamp(time.Now())
// Create a new blacklist principal for the client, as unlike AddBlacklist they don't send one to us.
blacklistPrincipal := nexproto.NewBlacklistedPrincipal()
blacklistPrincipal.PrincipalBasicInfo = info
blacklistPrincipal.GameKey = nexproto.NewGameKey()
blacklistPrincipal.BlackListedSince = date
rmcResponseStream := nex.NewStreamOut(globals.NEXServer)
rmcResponseStream.WriteStructure(blacklistPrincipal)
rmcResponseBody := rmcResponseStream.Bytes()
// Build response packet
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodDenyFriendRequest, 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.NEXServer.Send(responsePacket)
}

View File

@ -1,13 +1,10 @@
package friends_wiiu
import (
"encoding/base64"
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
"github.com/PretendoNetwork/friends-secure/globals"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
"go.mongodb.org/mongo-driver/bson"
)
func GetBasicInfo(err error, client *nex.Client, callID uint32, pids []uint32) {
@ -15,24 +12,11 @@ func GetBasicInfo(err error, client *nex.Client, callID uint32, pids []uint32) {
for i := 0; i < len(pids); i++ {
pid := pids[i]
userInfo := database_wiiu.GetUserInfoByPID(pid)
info := database_wiiu.GetUserInfoByPID(pid)
info := nexproto.NewPrincipalBasicInfo()
info.PID = pid
info.NNID = userInfo["username"].(string)
info.Mii = nexproto.NewMiiV2()
info.Unknown = 2 // idk
encodedMiiData := userInfo["mii"].(bson.M)["data"].(string)
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
info.Mii.Name = userInfo["mii"].(bson.M)["name"].(string)
info.Mii.Unknown1 = 0
info.Mii.Unknown2 = 0
info.Mii.Data = decodedMiiData
info.Mii.Datetime = nex.NewDateTime(0)
infos = append(infos, info)
if info != nil {
infos = append(infos, info)
}
}
rmcResponseStream := nex.NewStreamOut(globals.NEXServer)

30
wiiu/remove_blacklist.go Normal file
View File

@ -0,0 +1,30 @@
package friends_wiiu
import (
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
"github.com/PretendoNetwork/friends-secure/globals"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func RemoveBlacklist(err error, client *nex.Client, callID uint32, blockedPID uint32) {
database_wiiu.UnsetUserBlocked(client.PID(), blockedPID)
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodRemoveBlackList, 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.NEXServer.Send(responsePacket)
}

36
wiiu/remove_friend.go Normal file
View File

@ -0,0 +1,36 @@
package friends_wiiu
import (
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
"github.com/PretendoNetwork/friends-secure/globals"
notifications_wiiu "github.com/PretendoNetwork/friends-secure/notifications/wiiu"
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func RemoveFriend(err error, client *nex.Client, callID uint32, pid uint32) {
connectedUser := globals.ConnectedUsers[pid]
if connectedUser != nil {
go notifications_wiiu.SendFriendshipRemoved(connectedUser.Client, pid)
}
database_wiiu.RemoveFriendship(client.PID(), pid)
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodRemoveFriend, 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.NEXServer.Send(responsePacket)
}