mirror of
https://github.com/PretendoNetwork/friends.git
synced 2024-05-17 20:30:47 -04:00
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.
This commit is contained in:
parent
2f80336681
commit
8d8a05a7e2
|
@ -1,27 +1,21 @@
|
|||
package database_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types"
|
||||
)
|
||||
|
||||
// GetFriendMiis returns the Mii of all friends
|
||||
func GetFriendMiis(pids []uint32) []*friends_3ds_types.FriendMii {
|
||||
func GetFriendMiis(pids []uint32) ([]*friends_3ds_types.FriendMii, error) {
|
||||
friendMiis := make([]*friends_3ds_types.FriendMii, 0)
|
||||
|
||||
rows, err := database.Postgres.Query(`
|
||||
SELECT pid, mii_name, mii_data FROM "3ds".user_data WHERE pid IN ($1)`, database.PIDArrayToString(pids))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
globals.Logger.Warning(err.Error())
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
return friendMiis, err
|
||||
}
|
||||
|
||||
changedTime := nex.NewDateTime(0)
|
||||
|
@ -44,5 +38,5 @@ func GetFriendMiis(pids []uint32) []*friends_3ds_types.FriendMii {
|
|||
friendMiis = append(friendMiis, friendMii)
|
||||
}
|
||||
|
||||
return friendMiis
|
||||
return friendMiis, nil
|
||||
}
|
||||
|
|
|
@ -11,17 +11,13 @@ import (
|
|||
)
|
||||
|
||||
// GetFriendPersistentInfos returns the persistent information of all friends
|
||||
func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) []*friends_3ds_types.FriendPersistentInfo {
|
||||
func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) ([]*friends_3ds_types.FriendPersistentInfo, error) {
|
||||
persistentInfos := make([]*friends_3ds_types.FriendPersistentInfo, 0)
|
||||
|
||||
rows, err := database.Postgres.Query(`
|
||||
SELECT pid, region, area, language, favorite_title, favorite_title_version, comment, comment_changed, last_online FROM "3ds".user_data WHERE pid IN ($1)`, database.PIDArrayToString(pids))
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
globals.Logger.Warning(err.Error())
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
return persistentInfos, err
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
|
@ -44,6 +40,7 @@ func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) []*friends_3ds_ty
|
|||
friendedAtTime = uint64(time.Now().Unix())
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,5 +53,5 @@ func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) []*friends_3ds_ty
|
|||
persistentInfos = append(persistentInfos, persistentInfo)
|
||||
}
|
||||
|
||||
return persistentInfos
|
||||
return persistentInfos, nil
|
||||
}
|
||||
|
|
|
@ -4,18 +4,21 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types"
|
||||
)
|
||||
|
||||
// GetUserFriends returns all friend relationships of a user
|
||||
func GetUserFriends(pid uint32) []*friends_3ds_types.FriendRelationship {
|
||||
func GetUserFriends(pid uint32) ([]*friends_3ds_types.FriendRelationship, error) {
|
||||
friendRelationships := make([]*friends_3ds_types.FriendRelationship, 0)
|
||||
|
||||
rows, err := database.Postgres.Query(`
|
||||
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())
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return friendRelationships, database.ErrEmptyList
|
||||
} else {
|
||||
return friendRelationships, err
|
||||
}
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
|
@ -26,5 +29,5 @@ func GetUserFriends(pid uint32) []*friends_3ds_types.FriendRelationship {
|
|||
friendRelationships = append(friendRelationships, relationship)
|
||||
}
|
||||
|
||||
return friendRelationships
|
||||
return friendRelationships, nil
|
||||
}
|
||||
|
|
|
@ -6,12 +6,17 @@ import (
|
|||
|
||||
// RemoveFriendship removes a user's friend relationship
|
||||
func RemoveFriendship(user1_pid uint32, user2_pid uint32) error {
|
||||
_, err := database.Postgres.Exec(`
|
||||
result, err := database.Postgres.Exec(`
|
||||
DELETE FROM "3ds".friendships WHERE user1_pid=$1 AND user2_pid=$2`, user1_pid, user2_pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return database.ErrFriendshipNotFound
|
||||
}
|
||||
|
||||
_, err = database.Postgres.Exec(`
|
||||
UPDATE "3ds".friendships SET type=0 WHERE user1_pid=$1 AND user2_pid=$2`, user2_pid, user1_pid)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrPIDNotFound is returned if a given PID is not found in the database
|
||||
ErrPIDNotFound = errors.New("PID not found")
|
||||
|
||||
// ErrFriendRequestNotFound is returned if a given friend request is not found in the database
|
||||
ErrFriendRequestNotFound = errors.New("Friend request not found")
|
||||
|
||||
// ErrFriendshipNotFound is returned if a given friendship is not found in the database
|
||||
ErrFriendshipNotFound = errors.New("Friendship not found")
|
||||
|
||||
// ErrBlockListNotFound is returned if a given PID does not have a blacklist
|
||||
ErrBlacklistNotFound = errors.New("Blacklist not found")
|
||||
|
||||
// ErrEmptyList is returned if a given PID returned an empty list on an operation
|
||||
ErrEmptyList = errors.New("List is empty")
|
||||
)
|
||||
|
||||
// PIDArrayToString converts an array of PIDs to a string usable in Postgres queries
|
||||
func PIDArrayToString(array []uint32) string {
|
||||
return strings.Trim(strings.Replace(fmt.Sprint(array), " ", ",", -1), "[]")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
|
@ -9,13 +10,18 @@ import (
|
|||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
)
|
||||
|
||||
// AcceptFriendRequestAndReturnFriendInfo accepts the given friend reuqest and returns the friend's information
|
||||
func AcceptFriendRequestAndReturnFriendInfo(friendRequestID uint64) (*friends_wiiu_types.FriendInfo, error) {
|
||||
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 {
|
||||
return nil, err
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, database.ErrFriendRequestNotFound
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
acceptedTime := nex.NewDateTime(0)
|
||||
|
@ -66,9 +72,18 @@ func AcceptFriendRequestAndReturnFriendInfo(friendRequestID uint64) (*friends_wi
|
|||
lastOnline.FromTimestamp(time.Now())
|
||||
} else {
|
||||
// Offline
|
||||
userData, err := globals.GetUserData(senderPID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
friendInfo.NNAInfo = friends_wiiu_types.NewNNAInfo()
|
||||
friendInfo.NNAInfo.PrincipalBasicInfo = GetUserInfoByPID(senderPID)
|
||||
userInfo, err := GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
friendInfo.NNAInfo.PrincipalBasicInfo = userInfo
|
||||
friendInfo.NNAInfo.Unknown1 = 0
|
||||
friendInfo.NNAInfo.Unknown2 = 0
|
||||
|
||||
|
@ -92,18 +107,24 @@ func AcceptFriendRequestAndReturnFriendInfo(friendRequestID uint64) (*friends_wi
|
|||
friendInfo.Presence.Unknown7 = 0
|
||||
|
||||
var lastOnlineTime uint64
|
||||
err := database.Postgres.QueryRow(`SELECT last_online FROM wiiu.user_data WHERE pid=$1`, senderPID).Scan(&lastOnlineTime)
|
||||
err = database.Postgres.QueryRow(`SELECT last_online FROM wiiu.user_data WHERE pid=$1`, senderPID).Scan(&lastOnlineTime)
|
||||
if err != nil {
|
||||
lastOnlineTime = nex.NewDateTime(0).Now()
|
||||
|
||||
// TODO: Should we return the error here?
|
||||
globals.Logger.Critical(err.Error())
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, database.ErrPIDNotFound
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
lastOnline = nex.NewDateTime(lastOnlineTime) // TODO: Change this
|
||||
}
|
||||
|
||||
friendInfo.Status = GetUserComment(senderPID)
|
||||
status, err := GetUserComment(senderPID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
friendInfo.Status = status
|
||||
friendInfo.BecameFriend = acceptedTime
|
||||
friendInfo.LastOnline = lastOnline // TODO: Change this
|
||||
friendInfo.Unknown = 0
|
||||
|
|
|
@ -1,22 +1,34 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
)
|
||||
|
||||
// DeleteFriendRequestAndReturnFriendPID deletes a given friend request and returns the friend's PID
|
||||
func DeleteFriendRequestAndReturnFriendPID(friendRequestID uint64) (uint32, error) {
|
||||
var recipientPID uint32
|
||||
|
||||
err := database.Postgres.QueryRow(`SELECT recipient_pid FROM wiiu.friend_requests WHERE id=$1`, friendRequestID).Scan(&recipientPID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, database.ErrFriendRequestNotFound
|
||||
} else {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = database.Postgres.Exec(`
|
||||
result, err := database.Postgres.Exec(`
|
||||
DELETE FROM wiiu.friend_requests WHERE id=$1`, friendRequestID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return 0, database.ErrFriendRequestNotFound
|
||||
}
|
||||
|
||||
return recipientPID, nil
|
||||
}
|
||||
|
|
|
@ -4,11 +4,10 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
)
|
||||
|
||||
// Get a users outgoing friend request
|
||||
func GetPIDsByFriendRequestID(friendRequestID uint64) (uint32, uint32) {
|
||||
// GetPIDsByFriendRequestID returns the users outgoing friend request
|
||||
func GetPIDsByFriendRequestID(friendRequestID uint64) (uint32, uint32, error) {
|
||||
var senderPID uint32
|
||||
var recipientPID uint32
|
||||
|
||||
|
@ -17,11 +16,11 @@ func GetPIDsByFriendRequestID(friendRequestID uint64) (uint32, uint32) {
|
|||
`, friendRequestID).Scan(&senderPID, &recipientPID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
globals.Logger.Warning(err.Error())
|
||||
return 0, 0, database.ErrFriendRequestNotFound
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return 0, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return senderPID, recipientPID
|
||||
return senderPID, recipientPID, nil
|
||||
}
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
)
|
||||
|
||||
// Get a users blacklist
|
||||
func GetUserBlockList(pid uint32) []*friends_wiiu_types.BlacklistedPrincipal {
|
||||
// GetUserBlockList returns a user's blacklist
|
||||
func GetUserBlockList(pid uint32) ([]*friends_wiiu_types.BlacklistedPrincipal, error) {
|
||||
blockList := make([]*friends_wiiu_types.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
|
||||
if err == sql.ErrNoRows {
|
||||
return blockList, database.ErrBlacklistNotFound
|
||||
} else {
|
||||
return blockList, err
|
||||
}
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
|
@ -24,9 +29,21 @@ func GetUserBlockList(pid uint32) []*friends_wiiu_types.BlacklistedPrincipal {
|
|||
var date *nex.DateTime
|
||||
rows.Scan(&pid, &titleId, &titleVersion, &date)
|
||||
|
||||
userData, err := globals.GetUserData(pid)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
userInfo, err := GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
blacklistPrincipal := friends_wiiu_types.NewBlacklistedPrincipal()
|
||||
|
||||
blacklistPrincipal.PrincipalBasicInfo = GetUserInfoByPID(pid)
|
||||
blacklistPrincipal.PrincipalBasicInfo = userInfo
|
||||
|
||||
blacklistPrincipal.GameKey = friends_wiiu_types.NewGameKey()
|
||||
blacklistPrincipal.GameKey.TitleID = titleId
|
||||
|
@ -36,5 +53,5 @@ func GetUserBlockList(pid uint32) []*friends_wiiu_types.BlacklistedPrincipal {
|
|||
blockList = append(blockList, blacklistPrincipal)
|
||||
}
|
||||
|
||||
return blockList
|
||||
return blockList, nil
|
||||
}
|
||||
|
|
|
@ -4,13 +4,12 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
)
|
||||
|
||||
// Get a users comment
|
||||
func GetUserComment(pid uint32) *friends_wiiu_types.Comment {
|
||||
// GetUserComment returns a user's comment
|
||||
func GetUserComment(pid uint32) (*friends_wiiu_types.Comment, error) {
|
||||
comment := friends_wiiu_types.NewComment()
|
||||
comment.Unknown = 0
|
||||
|
||||
|
@ -19,13 +18,13 @@ func GetUserComment(pid uint32) *friends_wiiu_types.Comment {
|
|||
err := database.Postgres.QueryRow(`SELECT comment, comment_changed FROM wiiu.user_data WHERE pid=$1`, pid).Scan(&comment.Contents, &changed)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
globals.Logger.Warning(err.Error())
|
||||
return nil, database.ErrPIDNotFound
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
comment.LastChanged = nex.NewDateTime(changed)
|
||||
|
||||
return comment
|
||||
return comment, nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
@ -8,17 +9,19 @@ import (
|
|||
"github.com/PretendoNetwork/friends/globals"
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
"github.com/gocql/gocql"
|
||||
)
|
||||
|
||||
// Get a users friend list
|
||||
func GetUserFriendList(pid uint32) []*friends_wiiu_types.FriendInfo {
|
||||
// GetUserFriendList returns a user's friend list
|
||||
func GetUserFriendList(pid uint32) ([]*friends_wiiu_types.FriendInfo, error) {
|
||||
friendList := make([]*friends_wiiu_types.FriendInfo, 0)
|
||||
|
||||
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
|
||||
if err == sql.ErrNoRows {
|
||||
return friendList, database.ErrEmptyList
|
||||
} else {
|
||||
return friendList, err
|
||||
}
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
|
@ -52,8 +55,21 @@ func GetUserFriendList(pid uint32) []*friends_wiiu_types.FriendInfo {
|
|||
} else {
|
||||
// Offline
|
||||
|
||||
userData, err := globals.GetUserData(friendPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
userInfo, err := GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
friendInfo.NNAInfo = friends_wiiu_types.NewNNAInfo()
|
||||
friendInfo.NNAInfo.PrincipalBasicInfo = GetUserInfoByPID(friendPID)
|
||||
|
||||
friendInfo.NNAInfo.PrincipalBasicInfo = userInfo
|
||||
friendInfo.NNAInfo.Unknown1 = 0
|
||||
friendInfo.NNAInfo.Unknown2 = 0
|
||||
|
||||
|
@ -77,21 +93,23 @@ func GetUserFriendList(pid uint32) []*friends_wiiu_types.FriendInfo {
|
|||
friendInfo.Presence.Unknown7 = 0
|
||||
|
||||
var lastOnlineTime uint64
|
||||
err := database.Postgres.QueryRow(`SELECT last_online FROM wiiu.user_data WHERE pid=$1`, friendPID).Scan(&lastOnlineTime)
|
||||
err = database.Postgres.QueryRow(`SELECT last_online FROM wiiu.user_data WHERE pid=$1`, friendPID).Scan(&lastOnlineTime)
|
||||
if err != nil {
|
||||
lastOnlineTime = nex.NewDateTime(0).Now()
|
||||
|
||||
if err == gocql.ErrNotFound {
|
||||
globals.Logger.Error(err.Error())
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
lastOnline = nex.NewDateTime(lastOnlineTime) // TODO: Change this
|
||||
}
|
||||
|
||||
friendInfo.Status = GetUserComment(friendPID)
|
||||
status, err := GetUserComment(friendPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
friendInfo.Status = status
|
||||
|
||||
friendInfo.BecameFriend = nex.NewDateTime(date)
|
||||
friendInfo.LastOnline = lastOnline
|
||||
friendInfo.Unknown = 0
|
||||
|
@ -99,5 +117,5 @@ func GetUserFriendList(pid uint32) []*friends_wiiu_types.FriendInfo {
|
|||
friendList = append(friendList, friendInfo)
|
||||
}
|
||||
|
||||
return friendList
|
||||
return friendList, nil
|
||||
}
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
)
|
||||
|
||||
// Get a users friend PIDs list
|
||||
func GetUserFriendPIDs(pid uint32) []uint32 {
|
||||
// GetUserFriendPIDs returns a user's friend PIDs list
|
||||
func GetUserFriendPIDs(pid uint32) ([]uint32, error) {
|
||||
pids := make([]uint32, 0)
|
||||
|
||||
rows, err := database.Postgres.Query(`SELECT user2_pid FROM wiiu.friendships WHERE user1_pid=$1 AND active=true LIMIT 100`, pid)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return pids
|
||||
if err == sql.ErrNoRows {
|
||||
return pids, database.ErrEmptyList
|
||||
} else {
|
||||
return pids, err
|
||||
}
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
@ -23,5 +27,5 @@ func GetUserFriendPIDs(pid uint32) []uint32 {
|
|||
pids = append(pids, pid)
|
||||
}
|
||||
|
||||
return pids
|
||||
return pids, nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
|
@ -9,14 +10,17 @@ import (
|
|||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
)
|
||||
|
||||
// Get a users received friend requests
|
||||
func GetUserFriendRequestsIn(pid uint32) []*friends_wiiu_types.FriendRequest {
|
||||
// GetUserFriendRequestsIn returns the friend requests received by a user
|
||||
func GetUserFriendRequestsIn(pid uint32) ([]*friends_wiiu_types.FriendRequest, error) {
|
||||
friendRequestsIn := make([]*friends_wiiu_types.FriendRequest, 0)
|
||||
|
||||
rows, err := database.Postgres.Query(`SELECT id, sender_pid, sent_on, expires_on, message, received FROM wiiu.friend_requests WHERE recipient_pid=$1 AND accepted=false AND denied=false`, pid)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return friendRequestsIn
|
||||
if err == sql.ErrNoRows {
|
||||
return friendRequestsIn, database.ErrEmptyList
|
||||
} else {
|
||||
return friendRequestsIn, err
|
||||
}
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
|
@ -28,10 +32,21 @@ func GetUserFriendRequestsIn(pid uint32) []*friends_wiiu_types.FriendRequest {
|
|||
var received bool
|
||||
rows.Scan(&id, &senderPID, &sentOn, &expiresOn, &message, &received)
|
||||
|
||||
userData, err := globals.GetUserData(senderPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
userInfo, err := GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
friendRequest := friends_wiiu_types.NewFriendRequest()
|
||||
|
||||
friendRequest.PrincipalInfo = GetUserInfoByPID(senderPID)
|
||||
|
||||
friendRequest.PrincipalInfo = userInfo
|
||||
friendRequest.Message = friends_wiiu_types.NewFriendRequestMessage()
|
||||
friendRequest.Message.FriendRequestID = id
|
||||
friendRequest.Message.Received = received
|
||||
|
@ -52,5 +67,5 @@ func GetUserFriendRequestsIn(pid uint32) []*friends_wiiu_types.FriendRequest {
|
|||
}
|
||||
}
|
||||
|
||||
return friendRequestsIn
|
||||
return friendRequestsIn, nil
|
||||
}
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
package database_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
)
|
||||
|
||||
// Get a users sent friend requests
|
||||
func GetUserFriendRequestsOut(pid uint32) []*friends_wiiu_types.FriendRequest {
|
||||
// GetUserFriendRequestsOut returns the friend requests sent by a user
|
||||
func GetUserFriendRequestsOut(pid uint32) ([]*friends_wiiu_types.FriendRequest, error) {
|
||||
friendRequestsOut := make([]*friends_wiiu_types.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`, pid)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return friendRequestsOut
|
||||
if err == sql.ErrNoRows {
|
||||
return friendRequestsOut, database.ErrEmptyList
|
||||
} else {
|
||||
return friendRequestsOut, err
|
||||
}
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
|
@ -26,10 +31,21 @@ func GetUserFriendRequestsOut(pid uint32) []*friends_wiiu_types.FriendRequest {
|
|||
var received bool
|
||||
rows.Scan(&id, &recipientPID, &sentOn, &expiresOn, &message, &received)
|
||||
|
||||
userData, err := globals.GetUserData(recipientPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
userInfo, err := GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
friendRequest := friends_wiiu_types.NewFriendRequest()
|
||||
|
||||
friendRequest.PrincipalInfo = GetUserInfoByPID(recipientPID)
|
||||
|
||||
friendRequest.PrincipalInfo = userInfo
|
||||
friendRequest.Message = friends_wiiu_types.NewFriendRequestMessage()
|
||||
friendRequest.Message.FriendRequestID = id
|
||||
friendRequest.Message.Received = received
|
||||
|
@ -47,5 +63,5 @@ func GetUserFriendRequestsOut(pid uint32) []*friends_wiiu_types.FriendRequest {
|
|||
friendRequestsOut = append(friendRequestsOut, friendRequest)
|
||||
}
|
||||
|
||||
return friendRequestsOut
|
||||
return friendRequestsOut, nil
|
||||
}
|
||||
|
|
|
@ -3,29 +3,25 @@ package database_wiiu
|
|||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
pb "github.com/PretendoNetwork/grpc-go/account"
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
)
|
||||
|
||||
func GetUserInfoByPID(pid uint32) *friends_wiiu_types.PrincipalBasicInfo {
|
||||
// GetUserInfoByPNIDData converts the account's PNID data into user info for friends
|
||||
func GetUserInfoByPNIDData(userData *pb.GetUserDataResponse) (*friends_wiiu_types.PrincipalBasicInfo, error) {
|
||||
info := friends_wiiu_types.NewPrincipalBasicInfo()
|
||||
|
||||
userData, err := globals.GetUserData(pid)
|
||||
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
info.PID = pid
|
||||
info.PID = userData.Pid
|
||||
info.NNID = userData.Username
|
||||
info.Mii = friends_wiiu_types.NewMiiV2()
|
||||
info.Unknown = 2
|
||||
|
||||
encodedMiiData := userData.Mii.Data
|
||||
decodedMiiData, _ := base64.StdEncoding.DecodeString(encodedMiiData)
|
||||
decodedMiiData, err := base64.StdEncoding.DecodeString(encodedMiiData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info.Mii.Name = userData.Mii.Name
|
||||
info.Mii.Unknown1 = 0
|
||||
|
@ -33,5 +29,5 @@ func GetUserInfoByPID(pid uint32) *friends_wiiu_types.PrincipalBasicInfo {
|
|||
info.Mii.MiiData = decodedMiiData
|
||||
info.Mii.Datetime = nex.NewDateTime(0)
|
||||
|
||||
return info
|
||||
return info, nil
|
||||
}
|
|
@ -2,7 +2,7 @@ package database_wiiu
|
|||
|
||||
import friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
|
||||
// Get notifications for a user
|
||||
// GetUserNotifications returns notifications for a user
|
||||
func GetUserNotifications(pid uint32) []*friends_wiiu_types.PersistentNotification {
|
||||
return make([]*friends_wiiu_types.PersistentNotification, 0)
|
||||
}
|
||||
|
|
|
@ -4,21 +4,21 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types"
|
||||
)
|
||||
|
||||
func GetUserPrincipalPreference(pid uint32) *friends_wiiu_types.PrincipalPreference {
|
||||
// GetUserPrincipalPreference returns the user preferences
|
||||
func GetUserPrincipalPreference(pid uint32) (*friends_wiiu_types.PrincipalPreference, error) {
|
||||
preference := friends_wiiu_types.NewPrincipalPreference()
|
||||
|
||||
err := database.Postgres.QueryRow(`SELECT show_online, show_current_game, block_friend_requests FROM wiiu.user_data WHERE pid=$1`, pid).Scan(&preference.ShowOnlinePresence, &preference.ShowCurrentTitle, &preference.BlockFriendRequests)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
globals.Logger.Warning(err.Error())
|
||||
return nil, database.ErrPIDNotFound
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return preference
|
||||
return preference, nil
|
||||
}
|
||||
|
|
|
@ -2,15 +2,15 @@ package database_wiiu
|
|||
|
||||
import (
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
)
|
||||
|
||||
func IsFriendRequestBlocked(requesterPID uint32, requestedPID uint32) bool {
|
||||
// IsFriendRequestBlocked determines if a requester PID has blocked a requested PID
|
||||
func IsFriendRequestBlocked(requesterPID uint32, requestedPID uint32) (bool, error) {
|
||||
var found bool
|
||||
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())
|
||||
return false, err
|
||||
}
|
||||
|
||||
return found
|
||||
return found, nil
|
||||
}
|
||||
|
|
|
@ -4,14 +4,19 @@ import (
|
|||
"github.com/PretendoNetwork/friends/database"
|
||||
)
|
||||
|
||||
// Remove a user's friend relationship
|
||||
// RemoveFriendship removes a user's friend relationship
|
||||
func RemoveFriendship(user1_pid uint32, user2_pid uint32) error {
|
||||
_, err := database.Postgres.Exec(`
|
||||
result, err := database.Postgres.Exec(`
|
||||
DELETE FROM wiiu.friendships WHERE user1_pid=$1 AND user2_pid=$2`, user1_pid, user2_pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return database.ErrFriendshipNotFound
|
||||
}
|
||||
|
||||
_, 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 {
|
||||
|
|
|
@ -6,13 +6,17 @@ import (
|
|||
"github.com/PretendoNetwork/friends/database"
|
||||
)
|
||||
|
||||
// SaveFriendRequest registers a new friend request
|
||||
func SaveFriendRequest(senderPID uint32, recipientPID uint32, sentTime uint64, expireTime uint64, message string) (uint64, error) {
|
||||
var id uint64
|
||||
|
||||
friendRequestBlocked := IsFriendRequestBlocked(recipientPID, senderPID)
|
||||
friendRequestBlocked, err := IsFriendRequestBlocked(recipientPID, senderPID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 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)
|
||||
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 {
|
||||
return 0, err
|
||||
} else if id != 0 {
|
||||
|
|
|
@ -4,11 +4,17 @@ import (
|
|||
"github.com/PretendoNetwork/friends/database"
|
||||
)
|
||||
|
||||
// SetFriendRequestAccepted marks a friend request as accepted
|
||||
func SetFriendRequestAccepted(friendRequestID uint64) error {
|
||||
_, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET accepted=true WHERE id=$1`, friendRequestID)
|
||||
result, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET accepted=true WHERE id=$1`, friendRequestID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return database.ErrFriendRequestNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,12 +4,17 @@ import (
|
|||
"github.com/PretendoNetwork/friends/database"
|
||||
)
|
||||
|
||||
// SetFriendRequestDenied marks a friend request as denied
|
||||
func SetFriendRequestDenied(friendRequestID uint64) error {
|
||||
_, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET denied=true WHERE id=$1`, friendRequestID)
|
||||
|
||||
result, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET denied=true WHERE id=$1`, friendRequestID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return database.ErrFriendRequestNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,12 +4,17 @@ import (
|
|||
"github.com/PretendoNetwork/friends/database"
|
||||
)
|
||||
|
||||
// SetFriendRequestReceived marks a friend request as received
|
||||
func SetFriendRequestReceived(friendRequestID uint64) error {
|
||||
_, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET received=true WHERE id=$1`, friendRequestID)
|
||||
|
||||
result, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET received=true WHERE id=$1`, friendRequestID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return database.ErrFriendRequestNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/PretendoNetwork/nex-go"
|
||||
)
|
||||
|
||||
// SetUserBlocked marks a blocked PID as blocked on a bloker PID block list
|
||||
func SetUserBlocked(blockerPID uint32, blockedPID uint32, titleId uint64, titleVersion uint16) error {
|
||||
date := nex.NewDateTime(0)
|
||||
date.FromTimestamp(time.Now())
|
||||
|
|
|
@ -4,12 +4,17 @@ import (
|
|||
"github.com/PretendoNetwork/friends/database"
|
||||
)
|
||||
|
||||
// UnsetFriendRequestDenied unmarks a friend request as denied
|
||||
func UnsetFriendRequestDenied(friendRequestID uint64) error {
|
||||
_, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET denied=false WHERE id=$1`, friendRequestID)
|
||||
|
||||
result, err := database.Postgres.Exec(`UPDATE wiiu.friend_requests SET denied=false WHERE id=$1`, friendRequestID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return database.ErrFriendRequestNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,11 +6,16 @@ import (
|
|||
|
||||
// Remove a block from a user
|
||||
func UnsetUserBlocked(user1_pid uint32, user2_pid uint32) error {
|
||||
_, err := database.Postgres.Exec(`
|
||||
result, err := database.Postgres.Exec(`
|
||||
DELETE FROM wiiu.blocks WHERE blocker_pid=$1 AND blocked_pid=$2`, user1_pid, user2_pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return database.ErrPIDNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
|
||||
pb "github.com/PretendoNetwork/grpc-go/account"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/globals"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
|
@ -13,7 +12,6 @@ func GetUserData(pid uint32) (*pb.GetUserDataResponse, error) {
|
|||
|
||||
response, err := GRPCAccountClient.GetUserData(ctx, &pb.GetUserDataRequest{Pid: pid})
|
||||
if err != nil {
|
||||
globals.Logger.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
pb "github.com/PretendoNetwork/grpc-go/account"
|
||||
"github.com/PretendoNetwork/nex-go"
|
||||
"github.com/PretendoNetwork/nex-protocols-go/globals"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
|
@ -14,7 +13,7 @@ func PasswordFromPID(pid uint32) (string, uint32) {
|
|||
|
||||
response, err := GRPCAccountClient.GetNEXPassword(ctx, &pb.GetNEXPasswordRequest{Pid: pid})
|
||||
if err != nil {
|
||||
globals.Logger.Error(err.Error())
|
||||
Logger.Error(err.Error())
|
||||
return "", nex.Errors.RendezVous.InvalidUsername
|
||||
}
|
||||
|
||||
|
|
4
go.mod
4
go.mod
|
@ -8,7 +8,6 @@ require (
|
|||
github.com/PretendoNetwork/nex-protocols-common-go v1.0.25
|
||||
github.com/PretendoNetwork/nex-protocols-go v1.0.49
|
||||
github.com/PretendoNetwork/plogger-go v1.0.4
|
||||
github.com/gocql/gocql v1.5.2
|
||||
github.com/golang/protobuf v1.5.3
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/lib/pq v1.10.9
|
||||
|
@ -18,8 +17,6 @@ require (
|
|||
|
||||
require (
|
||||
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.2.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
|
@ -30,5 +27,4 @@ require (
|
|||
golang.org/x/text v0.12.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
)
|
||||
|
|
22
go.sum
22
go.sum
|
@ -8,34 +8,17 @@ github.com/PretendoNetwork/nex-protocols-go v1.0.49 h1:CIAjb9H11uTLj4JT2/4eedX1N
|
|||
github.com/PretendoNetwork/nex-protocols-go v1.0.49/go.mod h1:ztsrVFHaJc5MDBpL1rv4PgriLsTjl3R8u5XVxJHUzCk=
|
||||
github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc=
|
||||
github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU=
|
||||
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
|
||||
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
|
||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
|
||||
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
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.5.2 h1:WnKf8xRQImcT/KLaEWG2pjEeryDB7K0qQN9mPs1C58Q=
|
||||
github.com/gocql/gocql v1.5.2/go.mod h1:3gM2c4D3AnkISwBxGnMMsS8Oy4y2lhbPRsH4xnJrHG8=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
|
||||
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE8y6bre4H8=
|
||||
github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
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.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
|
@ -43,9 +26,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
|
|||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg=
|
||||
github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA=
|
||||
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA=
|
||||
|
@ -72,5 +52,3 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
|
|||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
|
|
|
@ -2,22 +2,36 @@ package grpc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
pb "github.com/PretendoNetwork/grpc-go/friends"
|
||||
)
|
||||
|
||||
func (s *gRPCFriendsServer) AcceptFriendRequest(ctx context.Context, in *pb.AcceptFriendRequestRequest) (*pb.AcceptFriendRequestResponse, error) {
|
||||
|
||||
friendInfo, err := database_wiiu.AcceptFriendRequestAndReturnFriendInfo(in.GetFriendRequestId())
|
||||
if err == sql.ErrNoRows {
|
||||
if err != nil {
|
||||
if err == database.ErrFriendRequestNotFound {
|
||||
return &pb.AcceptFriendRequestResponse{
|
||||
Success: false,
|
||||
}, status.Errorf(codes.NotFound, "friend request not found")
|
||||
}
|
||||
|
||||
if err == database.ErrPIDNotFound {
|
||||
return &pb.AcceptFriendRequestResponse{
|
||||
Success: false,
|
||||
}, status.Errorf(codes.FailedPrecondition, "friend request has invalid PID")
|
||||
}
|
||||
|
||||
globals.Logger.Critical(err.Error())
|
||||
return &pb.AcceptFriendRequestResponse{
|
||||
Success: false,
|
||||
}, status.Errorf(codes.NotFound, "friend request not found")
|
||||
}, status.Errorf(codes.Internal, "internal server error")
|
||||
}
|
||||
|
||||
return &pb.AcceptFriendRequestResponse{
|
||||
|
|
|
@ -3,14 +3,31 @@ package grpc
|
|||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
pb "github.com/PretendoNetwork/grpc-go/friends"
|
||||
)
|
||||
|
||||
func (s *gRPCFriendsServer) DenyFriendRequest(ctx context.Context, in *pb.DenyFriendRequestRequest) (*pb.DenyFriendRequestResponse, error) {
|
||||
err := database_wiiu.SetFriendRequestDenied(in.GetFriendRequestId())
|
||||
if err != nil {
|
||||
if err == database.ErrFriendRequestNotFound {
|
||||
return &pb.DenyFriendRequestResponse{
|
||||
Success: false,
|
||||
}, status.Errorf(codes.NotFound, "friend request not found")
|
||||
}
|
||||
|
||||
globals.Logger.Critical(err.Error())
|
||||
return &pb.DenyFriendRequestResponse{
|
||||
Success: false,
|
||||
}, status.Errorf(codes.Internal, "internal server error")
|
||||
}
|
||||
|
||||
return &pb.DenyFriendRequestResponse{
|
||||
Success: err == nil,
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -3,16 +3,26 @@ package grpc
|
|||
import (
|
||||
"context"
|
||||
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
pb "github.com/PretendoNetwork/grpc-go/friends"
|
||||
)
|
||||
|
||||
func (s *gRPCFriendsServer) GetUserFriendPIDs(ctx context.Context, in *pb.GetUserFriendPIDsRequest) (*pb.GetUserFriendPIDsResponse, error) {
|
||||
var pids []uint32
|
||||
var err error
|
||||
|
||||
// * Try Wii U database first
|
||||
pids = database_wiiu.GetUserFriendPIDs(in.GetPid())
|
||||
pids, err = database_wiiu.GetUserFriendPIDs(in.GetPid())
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nil, status.Errorf(codes.Internal, "internal server error")
|
||||
}
|
||||
|
||||
if len(pids) > 0 {
|
||||
return &pb.GetUserFriendPIDsResponse{
|
||||
|
@ -21,7 +31,11 @@ func (s *gRPCFriendsServer) GetUserFriendPIDs(ctx context.Context, in *pb.GetUse
|
|||
}
|
||||
|
||||
// * If no PIDs are given, try with 3DS database instead
|
||||
relationships := database_3ds.GetUserFriends(in.GetPid())
|
||||
relationships, err := database_3ds.GetUserFriends(in.GetPid())
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nil, status.Errorf(codes.Internal, "internal server error")
|
||||
}
|
||||
|
||||
for _, relationship := range relationships {
|
||||
// * Only add complete relationships to the list
|
||||
|
|
|
@ -3,13 +3,22 @@ package grpc
|
|||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
pb "github.com/PretendoNetwork/grpc-go/friends"
|
||||
)
|
||||
|
||||
func (s *gRPCFriendsServer) GetUserFriendRequestsIncoming(ctx context.Context, in *pb.GetUserFriendRequestsIncomingRequest) (*pb.GetUserFriendRequestsIncomingResponse, error) {
|
||||
|
||||
friendRequestsIn := database_wiiu.GetUserFriendRequestsIn(in.GetPid())
|
||||
friendRequestsIn, err := database_wiiu.GetUserFriendRequestsIn(in.GetPid())
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nil, status.Errorf(codes.Internal, "internal server error")
|
||||
}
|
||||
|
||||
friendRequests := make([]*pb.FriendRequest, 0, len(friendRequestsIn))
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package nex_friends_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -13,7 +15,11 @@ func GetAllFriends(err error, client *nex.Client, callID uint32) uint32 {
|
|||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
friendRelationships := database_3ds.GetUserFriends(client.PID())
|
||||
friendRelationships, err := database_3ds.GetUserFriends(client.PID())
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewStreamOut(globals.SecureServer)
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package nex_friends_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -13,7 +15,11 @@ func GetFriendMii(err error, client *nex.Client, callID uint32, pids []uint32) u
|
|||
return nex.Errors.FPD.InvalidArgument
|
||||
}
|
||||
|
||||
miiList := database_3ds.GetFriendMiis(pids)
|
||||
miiList, err := database_3ds.GetFriendMiis(pids)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewStreamOut(globals.SecureServer)
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package nex_friends_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -13,7 +15,11 @@ func GetFriendPersistentInfo(err error, client *nex.Client, callID uint32, pids
|
|||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
infoList := database_3ds.GetFriendPersistentInfos(client.PID(), pids)
|
||||
infoList, err := database_3ds.GetFriendPersistentInfos(client.PID(), pids)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
rmcResponseStream := nex.NewStreamOut(globals.SecureServer)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package nex_friends_3ds
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
notifications_3ds "github.com/PretendoNetwork/friends/notifications/3ds"
|
||||
|
@ -16,8 +17,14 @@ func RemoveFriendByPrincipalID(err error, client *nex.Client, callID uint32, pid
|
|||
|
||||
err = database_3ds.RemoveFriendship(client.PID(), pid)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
if err == database.ErrFriendshipNotFound {
|
||||
// * Official servers don't actually check this, but
|
||||
// * we'll do it ourselves
|
||||
return nex.Errors.FPD.NotFriend
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
go notifications_3ds.SendUserWentOffline(client, pid)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package nex_friends_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
notifications_3ds "github.com/PretendoNetwork/friends/notifications/3ds"
|
||||
|
@ -16,12 +19,16 @@ func SyncFriend(err error, client *nex.Client, callID uint32, lfc uint64, pids [
|
|||
return nex.Errors.FPD.InvalidArgument
|
||||
}
|
||||
|
||||
friendRelationships := database_3ds.GetUserFriends(client.PID())
|
||||
friendRelationships, err := database_3ds.GetUserFriends(client.PID())
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendRelationships); i++ {
|
||||
if !slices.Contains(pids, friendRelationships[i].PID) {
|
||||
err := database_3ds.RemoveFriendship(client.PID(), friendRelationships[i].PID)
|
||||
if err != nil {
|
||||
if err != nil && err != database.ErrFriendshipNotFound {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package nex_friends_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
notifications_wiiu "github.com/PretendoNetwork/friends/notifications/wiiu"
|
||||
|
@ -19,7 +18,7 @@ func AcceptFriendRequest(err error, client *nex.Client, callID uint32, id uint64
|
|||
|
||||
friendInfo, err := database_wiiu.AcceptFriendRequestAndReturnFriendInfo(id)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if err == database.ErrFriendRequestNotFound {
|
||||
return nex.Errors.FPD.InvalidMessageID
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
|
@ -38,7 +37,15 @@ func AcceptFriendRequest(err error, client *nex.Client, callID uint32, id uint64
|
|||
|
||||
senderFriendInfo.NNAInfo = senderConnectedUser.NNAInfo
|
||||
senderFriendInfo.Presence = senderConnectedUser.PresenceV2
|
||||
senderFriendInfo.Status = database_wiiu.GetUserComment(senderPID)
|
||||
status, err := database_wiiu.GetUserComment(senderPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
senderFriendInfo.Status = friends_wiiu_types.NewComment()
|
||||
senderFriendInfo.Status.LastChanged = nex.NewDateTime(0)
|
||||
} else {
|
||||
senderFriendInfo.Status = status
|
||||
}
|
||||
|
||||
senderFriendInfo.BecameFriend = friendInfo.BecameFriend
|
||||
senderFriendInfo.LastOnline = friendInfo.LastOnline // TODO: Change this
|
||||
senderFriendInfo.Unknown = 0
|
||||
|
|
|
@ -3,6 +3,9 @@ package nex_friends_wiiu
|
|||
import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -25,10 +28,20 @@ func AddBlacklist(err error, client *nex.Client, callID uint32, blacklistPrincip
|
|||
date := nex.NewDateTime(0)
|
||||
date.FromTimestamp(time.Now())
|
||||
|
||||
userInfo := database_wiiu.GetUserInfoByPID(currentBlacklistPrincipal.PrincipalBasicInfo.PID)
|
||||
userData, err := globals.GetUserData(currentBlacklistPrincipal.PrincipalBasicInfo.PID)
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.InvalidArgument {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
if userInfo.PID == 0 {
|
||||
return nex.Errors.FPD.InvalidPrincipalID // TODO: Not sure if this is the correct error.
|
||||
userInfo, err := database_wiiu.GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
currentBlacklistPrincipal.PrincipalBasicInfo = userInfo
|
||||
|
|
|
@ -3,6 +3,9 @@ package nex_friends_wiiu
|
|||
import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
notifications_wiiu "github.com/PretendoNetwork/friends/notifications/wiiu"
|
||||
|
@ -20,10 +23,33 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32,
|
|||
senderPID := client.PID()
|
||||
recipientPID := pid
|
||||
|
||||
recipient := database_wiiu.GetUserInfoByPID(recipientPID)
|
||||
if recipient.PID == 0 {
|
||||
globals.Logger.Errorf("User %d has sent friend request to invalid PID %d", senderPID, pid)
|
||||
return nex.Errors.FPD.InvalidPrincipalID
|
||||
senderUserData, err := globals.GetUserData(senderPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
senderPrincipalInfo, err := database_wiiu.GetUserInfoByPNIDData(senderUserData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
recipientUserData, err := globals.GetUserData(recipientPID)
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.InvalidArgument {
|
||||
globals.Logger.Errorf("User %d has sent friend request to invalid PID %d", senderPID, pid)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
recipientPrincipalInfo, err := database_wiiu.GetUserInfoByPNIDData(recipientUserData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
currentTimestamp := time.Now()
|
||||
|
@ -43,7 +69,7 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32,
|
|||
|
||||
friendRequest := friends_wiiu_types.NewFriendRequest()
|
||||
|
||||
friendRequest.PrincipalInfo = database_wiiu.GetUserInfoByPID(recipientPID)
|
||||
friendRequest.PrincipalInfo = recipientPrincipalInfo
|
||||
|
||||
friendRequest.Message = friends_wiiu_types.NewFriendRequestMessage()
|
||||
friendRequest.Message.FriendRequestID = friendRequestID
|
||||
|
@ -106,7 +132,7 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32,
|
|||
|
||||
friendRequestNotificationData := friends_wiiu_types.NewFriendRequest()
|
||||
|
||||
friendRequestNotificationData.PrincipalInfo = database_wiiu.GetUserInfoByPID(senderPID)
|
||||
friendRequestNotificationData.PrincipalInfo = senderPrincipalInfo
|
||||
|
||||
friendRequestNotificationData.Message = friends_wiiu_types.NewFriendRequestMessage()
|
||||
friendRequestNotificationData.Message.FriendRequestID = friendRequestID
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package nex_friends_wiiu
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
notifications_wiiu "github.com/PretendoNetwork/friends/notifications/wiiu"
|
||||
|
@ -18,7 +17,7 @@ func CancelFriendRequest(err error, client *nex.Client, callID uint32, id uint64
|
|||
|
||||
pid, err := database_wiiu.DeleteFriendRequestAndReturnFriendPID(id)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
if err == database.ErrFriendRequestNotFound {
|
||||
return nex.Errors.FPD.InvalidMessageID
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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"
|
||||
|
@ -15,8 +16,12 @@ func DeleteFriendRequest(err error, client *nex.Client, callID uint32, id uint64
|
|||
|
||||
err = database_wiiu.SetFriendRequestDenied(id)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
if err == database.ErrFriendRequestNotFound {
|
||||
return nex.Errors.FPD.InvalidMessageID
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID)
|
||||
|
|
|
@ -3,6 +3,7 @@ package nex_friends_wiiu
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -22,14 +23,33 @@ func DenyFriendRequest(err error, client *nex.Client, callID uint32, id uint64)
|
|||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
senderPID, _ := database_wiiu.GetPIDsByFriendRequestID(id)
|
||||
senderPID, _, err := database_wiiu.GetPIDsByFriendRequestID(id)
|
||||
if err != nil {
|
||||
if err == database.ErrFriendRequestNotFound {
|
||||
return nex.Errors.FPD.InvalidMessageID
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
err = database_wiiu.SetUserBlocked(client.PID(), senderPID, 0, 0)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
info := database_wiiu.GetUserInfoByPID(senderPID)
|
||||
userData, err := globals.GetUserData(senderPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
info, err := database_wiiu.GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
date := nex.NewDateTime(0)
|
||||
date.FromTimestamp(time.Now())
|
||||
|
|
|
@ -18,7 +18,18 @@ func GetBasicInfo(err error, client *nex.Client, callID uint32, pids []uint32) u
|
|||
|
||||
for i := 0; i < len(pids); i++ {
|
||||
pid := pids[i]
|
||||
info := database_wiiu.GetUserInfoByPID(pid)
|
||||
|
||||
userData, err := globals.GetUserData(pid)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
info, err := database_wiiu.GetUserInfoByPNIDData(userData)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if info.PID != 0 {
|
||||
infos = append(infos, info)
|
||||
|
|
|
@ -23,7 +23,13 @@ func GetRequestBlockSettings(err error, client *nex.Client, callID uint32, pids
|
|||
|
||||
setting := friends_wiiu_types.NewPrincipalRequestBlockSetting()
|
||||
setting.PID = requestedPID
|
||||
setting.IsBlocked = database_wiiu.IsFriendRequestBlocked(client.PID(), requestedPID)
|
||||
isBlocked, err := database_wiiu.IsFriendRequestBlocked(client.PID(), requestedPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
setting.IsBlocked = isBlocked
|
||||
|
||||
settings = append(settings, setting)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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"
|
||||
|
@ -15,8 +16,12 @@ func RemoveBlacklist(err error, client *nex.Client, callID uint32, blockedPID ui
|
|||
|
||||
err = database_wiiu.UnsetUserBlocked(client.PID(), blockedPID)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
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)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package nex_friends_wiiu
|
||||
|
||||
import (
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
notifications_wiiu "github.com/PretendoNetwork/friends/notifications/wiiu"
|
||||
|
@ -16,8 +17,12 @@ func RemoveFriend(err error, client *nex.Client, callID uint32, pid uint32) uint
|
|||
|
||||
err = database_wiiu.RemoveFriendship(client.PID(), pid)
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
if err == database.ErrFriendshipNotFound {
|
||||
return nex.Errors.FPD.NotInMyFriendList
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
connectedUser := globals.ConnectedUsers[pid]
|
||||
|
|
|
@ -3,6 +3,7 @@ package nex_friends_wiiu
|
|||
import (
|
||||
"os"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
notifications_wiiu "github.com/PretendoNetwork/friends/notifications/wiiu"
|
||||
|
@ -18,13 +19,6 @@ func UpdateAndGetAllInformation(err error, client *nex.Client, callID uint32, nn
|
|||
return nex.Errors.FPD.InvalidArgument
|
||||
}
|
||||
|
||||
// Update user information
|
||||
|
||||
presence.Online = true // Force online status. I have no idea why this is always false
|
||||
presence.PID = client.PID() // WHY IS THIS SET TO 0 BY DEFAULT??
|
||||
|
||||
notifications_wiiu.SendPresenceUpdate(presence)
|
||||
|
||||
// Get user information
|
||||
pid := client.PID()
|
||||
|
||||
|
@ -41,14 +35,59 @@ func UpdateAndGetAllInformation(err error, client *nex.Client, callID uint32, nn
|
|||
globals.ConnectedUsers[pid].NNAInfo = nnaInfo
|
||||
globals.ConnectedUsers[pid].PresenceV2 = presence
|
||||
|
||||
principalPreference := database_wiiu.GetUserPrincipalPreference(pid)
|
||||
comment := database_wiiu.GetUserComment(pid)
|
||||
friendList := database_wiiu.GetUserFriendList(pid)
|
||||
friendRequestsOut := database_wiiu.GetUserFriendRequestsOut(pid)
|
||||
friendRequestsIn := database_wiiu.GetUserFriendRequestsIn(pid)
|
||||
blockList := database_wiiu.GetUserBlockList(pid)
|
||||
principalPreference, err := database_wiiu.GetUserPrincipalPreference(pid)
|
||||
if err != nil {
|
||||
if err == database.ErrPIDNotFound {
|
||||
return nex.Errors.FPD.InvalidPrincipalID
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
comment, err := database_wiiu.GetUserComment(pid)
|
||||
if err != nil {
|
||||
if err == database.ErrPIDNotFound {
|
||||
return nex.Errors.FPD.InvalidPrincipalID
|
||||
} else {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
friendList, err := database_wiiu.GetUserFriendList(pid)
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
friendRequestsOut, err := database_wiiu.GetUserFriendRequestsOut(pid)
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
friendRequestsIn, err := database_wiiu.GetUserFriendRequestsIn(pid)
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
blockList, err := database_wiiu.GetUserBlockList(pid)
|
||||
if err != nil && err != database.ErrBlacklistNotFound {
|
||||
globals.Logger.Critical(err.Error())
|
||||
return nex.Errors.FPD.Unknown
|
||||
}
|
||||
|
||||
notifications := database_wiiu.GetUserNotifications(pid)
|
||||
|
||||
// Update user information
|
||||
|
||||
presence.Online = true // Force online status. I have no idea why this is always false
|
||||
presence.PID = pid // WHY IS THIS SET TO 0 BY DEFAULT??
|
||||
|
||||
notifications_wiiu.SendPresenceUpdate(presence)
|
||||
|
||||
if os.Getenv("PN_FRIENDS_CONFIG_ENABLE_BELLA") == "true" {
|
||||
bella := friends_wiiu_types.NewFriendInfo()
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ func RegisterEx(err error, client *nex.Client, callID uint32, stationUrls []*nex
|
|||
return nex.Errors.Core.InvalidArgument
|
||||
}
|
||||
|
||||
retval := nex.NewResultSuccess(nex.Errors.Core.Unknown)
|
||||
rmcResponseStream := nex.NewStreamOut(globals.SecureServer)
|
||||
|
||||
// TODO: Validate loginData
|
||||
pid := client.PID()
|
||||
user := globals.ConnectedUsers[pid]
|
||||
|
@ -36,25 +39,28 @@ func RegisterEx(err error, client *nex.Client, callID uint32, stationUrls []*nex
|
|||
database_3ds.UpdateUserLastOnlineTime(pid, lastOnline)
|
||||
default:
|
||||
globals.Logger.Errorf("Unknown loginData data type %s!", loginDataType)
|
||||
return nex.Errors.Authentication.TokenParseError
|
||||
retval = nex.NewResultError(nex.Errors.Authentication.ValidationFailed)
|
||||
}
|
||||
|
||||
localStation := stationUrls[0]
|
||||
if retval.IsSuccess() {
|
||||
localStation := stationUrls[0]
|
||||
|
||||
address := client.Address().IP.String()
|
||||
port := strconv.Itoa(client.Address().Port)
|
||||
address := client.Address().IP.String()
|
||||
port := strconv.Itoa(client.Address().Port)
|
||||
|
||||
localStation.SetAddress(address)
|
||||
localStation.SetPort(port)
|
||||
localStation.SetAddress(address)
|
||||
localStation.SetPort(port)
|
||||
|
||||
localStationURL := localStation.EncodeToString()
|
||||
localStationURL := localStation.EncodeToString()
|
||||
|
||||
rmcResponseStream := nex.NewStreamOut(globals.SecureServer)
|
||||
|
||||
retval := nex.NewResultSuccess(nex.Errors.Core.Unknown)
|
||||
rmcResponseStream.WriteResult(retval)
|
||||
rmcResponseStream.WriteUInt32LE(globals.SecureServer.ConnectionIDCounter().Increment())
|
||||
rmcResponseStream.WriteString(localStationURL)
|
||||
rmcResponseStream.WriteResult(retval)
|
||||
rmcResponseStream.WriteUInt32LE(globals.SecureServer.ConnectionIDCounter().Increment())
|
||||
rmcResponseStream.WriteString(localStationURL)
|
||||
} else {
|
||||
rmcResponseStream.WriteResult(retval)
|
||||
rmcResponseStream.WriteUInt32LE(0)
|
||||
rmcResponseStream.WriteString("prudp:/")
|
||||
}
|
||||
|
||||
rmcResponseBody := rmcResponseStream.Bytes()
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package notifications_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -30,7 +32,10 @@ func SendCommentUpdate(client *nex.Client, comment string) {
|
|||
|
||||
rmcRequestBytes := rmcRequest.Bytes()
|
||||
|
||||
friendsList := database_3ds.GetUserFriends(client.PID())
|
||||
friendsList, err := database_3ds.GetUserFriends(client.PID())
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendsList); i++ {
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package notifications_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -28,7 +30,10 @@ func SendFavoriteUpdate(client *nex.Client, gameKey *friends_3ds_types.GameKey)
|
|||
|
||||
rmcRequestBytes := rmcRequest.Bytes()
|
||||
|
||||
friendsList := database_3ds.GetUserFriends(client.PID())
|
||||
friendsList, err := database_3ds.GetUserFriends(client.PID())
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendsList); i++ {
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package notifications_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -29,7 +31,10 @@ func SendMiiUpdateNotification(client *nex.Client) {
|
|||
|
||||
rmcRequestBytes := rmcRequest.Bytes()
|
||||
|
||||
friendsList := database_3ds.GetUserFriends(client.PID())
|
||||
friendsList, err := database_3ds.GetUserFriends(client.PID())
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendsList); i++ {
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package notifications_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -28,7 +30,10 @@ func SendPresenceUpdate(client *nex.Client, presence *friends_3ds_types.Nintendo
|
|||
|
||||
rmcRequestBytes := rmcRequest.Bytes()
|
||||
|
||||
friendsList := database_3ds.GetUserFriends(client.PID())
|
||||
friendsList, err := database_3ds.GetUserFriends(client.PID())
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendsList); i++ {
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package notifications_3ds
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -9,7 +11,10 @@ import (
|
|||
)
|
||||
|
||||
func SendUserWentOfflineGlobally(client *nex.Client) {
|
||||
friendsList := database_3ds.GetUserFriends(client.PID())
|
||||
friendsList, err := database_3ds.GetUserFriends(client.PID())
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendsList); i++ {
|
||||
SendUserWentOffline(client, friendsList[i].PID)
|
||||
|
|
|
@ -3,6 +3,7 @@ package notifications_wiiu
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -30,7 +31,10 @@ func SendPresenceUpdate(presence *friends_wiiu_types.NintendoPresenceV2) {
|
|||
|
||||
rmcRequestBytes := rmcRequest.Bytes()
|
||||
|
||||
friendList := database_wiiu.GetUserFriendList(presence.PID)
|
||||
friendList, err := database_wiiu.GetUserFriendList(presence.PID)
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendList); i++ {
|
||||
if friendList[i] == nil || friendList[i].NNAInfo == nil || friendList[i].NNAInfo.PrincipalBasicInfo == nil {
|
||||
|
|
|
@ -3,6 +3,7 @@ package notifications_wiiu
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/PretendoNetwork/friends/database"
|
||||
database_wiiu "github.com/PretendoNetwork/friends/database/wiiu"
|
||||
"github.com/PretendoNetwork/friends/globals"
|
||||
nex "github.com/PretendoNetwork/nex-go"
|
||||
|
@ -11,7 +12,10 @@ import (
|
|||
)
|
||||
|
||||
func SendUserWentOfflineGlobally(client *nex.Client) {
|
||||
friendsList := database_wiiu.GetUserFriendList(client.PID())
|
||||
friendsList, err := database_wiiu.GetUserFriendList(client.PID())
|
||||
if err != nil && err != database.ErrEmptyList {
|
||||
globals.Logger.Critical(err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < len(friendsList); i++ {
|
||||
SendUserWentOffline(client, friendsList[i].NNAInfo.PrincipalBasicInfo.PID)
|
||||
|
|
Loading…
Reference in a new issue