mirror of
https://github.com/PretendoNetwork/friends.git
synced 2026-04-25 23:37:46 -05:00
Add blocking features and refactor a bit
This commit is contained in:
parent
116a19631e
commit
598a75f37d
|
|
@ -27,7 +27,10 @@ func assignNEXProtocols() {
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/friends-secure/database"
|
||||
|
|
@ -9,7 +8,6 @@ import (
|
|||
"github.com/PretendoNetwork/nex-go"
|
||||
nexproto "github.com/PretendoNetwork/nex-protocols-go"
|
||||
"github.com/gocql/gocql"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func AcceptFriendRequestAndReturnFriendInfo(friendRequestID uint64) *nexproto.FriendInfo {
|
||||
|
|
@ -69,21 +67,9 @@ func AcceptFriendRequestAndReturnFriendInfo(friendRequestID uint64) *nexproto.Fr
|
|||
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
|
||||
|
||||
|
|
|
|||
27
database/wiiu/get_pids_by_friend_request_id.go
Normal file
27
database/wiiu/get_pids_by_friend_request_id.go
Normal 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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
|
@ -10,7 +9,6 @@ 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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,19 +10,26 @@ import (
|
|||
func SaveFriendRequest(senderPID uint32, recipientPID uint32, sentTime uint64, expireTime uint64, message string) uint64 {
|
||||
var id uint64
|
||||
|
||||
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 {
|
||||
return id
|
||||
// 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, false) RETURNING id`, senderPID, recipientPID, sentTime, expireTime, message).Scan(&id)
|
||||
|
||||
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
|
||||
|
|
|
|||
14
database/wiiu/set_friend_request_denied.go
Normal file
14
database/wiiu/set_friend_request_denied.go
Normal 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())
|
||||
}
|
||||
}
|
||||
24
database/wiiu/set_user_blocked.go
Normal file
24
database/wiiu/set_user_blocked.go
Normal 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())
|
||||
}
|
||||
}
|
||||
14
database/wiiu/unset_friend_request_denied.go
Normal file
14
database/wiiu/unset_friend_request_denied.go
Normal 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())
|
||||
}
|
||||
}
|
||||
15
database/wiiu/unset_user_blocked.go
Normal file
15
database/wiiu/unset_user_blocked.go
Normal 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())
|
||||
}
|
||||
}
|
||||
51
wiiu/add_blacklist.go
Normal file
51
wiiu/add_blacklist.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
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
|
||||
|
||||
database_wiiu.SetUserBlocked(client.PID(), senderPID, titleID, titleVersion)
|
||||
|
||||
date := nex.NewDateTime(0)
|
||||
date.FromTimestamp(time.Now())
|
||||
|
||||
currentBlacklistPrincipal.PrincipalBasicInfo = database_wiiu.GetUserInfoByPID(currentBlacklistPrincipal.PrincipalBasicInfo.PID)
|
||||
currentBlacklistPrincipal.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.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)
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ import (
|
|||
)
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func DeleteFriendRequest(err error, client *nex.Client, callID uint32, id uint64) {
|
||||
|
||||
database_wiiu.DeleteFriendRequestAndReturnFriendPID(id)
|
||||
database_wiiu.SetFriendRequestDenied(id)
|
||||
|
||||
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
|
||||
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodDeleteFriendRequest, nil)
|
||||
|
|
|
|||
54
wiiu/deny_friend_request.go
Normal file
54
wiiu/deny_friend_request.go
Normal 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)
|
||||
}
|
||||
|
|
@ -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
30
wiiu/remove_blacklist.go
Normal 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)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user