mirror of
https://github.com/PretendoNetwork/friends.git
synced 2026-10-02 06:48:00 -05:00
fix(grpc): updated timestamps to be accurate, more cleanup
This commit is contained in:
@@ -4,19 +4,19 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"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/v2"
|
||||
"github.com/PretendoNetwork/nex-go/v2/types"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func (s *gRPCFriendsV2Server) GetUserDataWiiU(ctx context.Context, in *pb.GetUserDataWiiURequest) (*pb.GetUserDataWiiUResponse, error) {
|
||||
friend, err := database_wiiu.GetUserData(in.GetPid())
|
||||
friend, err := database_wiiu.GetUserData(types.PID(in.GetPid()))
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
if err == database.ErrPIDNotFound {
|
||||
@@ -25,28 +25,34 @@ func (s *gRPCFriendsV2Server) GetUserDataWiiU(ctx context.Context, in *pb.GetUse
|
||||
return nil, status.Errorf(codes.Internal, "Internal error")
|
||||
}
|
||||
}
|
||||
var comment = &pb.Comment{
|
||||
|
||||
comment := &pb.Comment{
|
||||
Contents: string(friend.Status.Contents),
|
||||
LastChanged: timestamppb.New(time.Unix(int64(friend.Status.LastChanged.Second()), 0)),
|
||||
}
|
||||
var mii = &pb.MiiV2{
|
||||
|
||||
mii := &pb.MiiV2{
|
||||
Name: string(friend.NNAInfo.PrincipalBasicInfo.Mii.Name),
|
||||
MiiData: friend.NNAInfo.PrincipalBasicInfo.Mii.MiiData,
|
||||
Datetime: timestamppb.New(time.Unix(int64(friend.NNAInfo.PrincipalBasicInfo.Mii.Datetime.Second()), 0)),
|
||||
}
|
||||
var principal = &pb.PrincipalBasicInfo{
|
||||
|
||||
principal := &pb.PrincipalBasicInfo{
|
||||
Pid: uint32(friend.NNAInfo.PrincipalBasicInfo.PID),
|
||||
Nnid: string(friend.NNAInfo.PrincipalBasicInfo.NNID),
|
||||
Mii: mii,
|
||||
}
|
||||
var nnaInfo = &pb.NNAInfo{
|
||||
|
||||
nnaInfo := &pb.NNAInfo{
|
||||
PrincipalBasicInfo: principal,
|
||||
}
|
||||
var gameKey = &pb.GameKey{
|
||||
|
||||
gameKey := &pb.GameKey{
|
||||
TitleId: uint64(friend.Presence.GameKey.TitleID),
|
||||
TitleVersion: uint32(friend.Presence.GameKey.TitleVersion),
|
||||
}
|
||||
var presence = &pb.NintendoPresenceV2{
|
||||
|
||||
presence := &pb.NintendoPresenceV2{
|
||||
ChangedFlags: uint32(friend.Presence.ChangedFlags),
|
||||
Online: bool(friend.Presence.Online),
|
||||
GameKey: gameKey,
|
||||
@@ -56,12 +62,13 @@ func (s *gRPCFriendsV2Server) GetUserDataWiiU(ctx context.Context, in *pb.GetUse
|
||||
GatheringId: uint32(friend.Presence.GatheringID),
|
||||
ApplicationData: friend.Presence.ApplicationData,
|
||||
}
|
||||
var info = &pb.FriendInfoWiiU{
|
||||
|
||||
info := &pb.FriendInfoWiiU{
|
||||
NnaInfo: nnaInfo,
|
||||
Presence: presence,
|
||||
Status: comment,
|
||||
BecameFriend: timestamppb.New(time.Unix(int64(friend.BecameFriend.Second()), 0)),
|
||||
LastOnline: timestamppb.New(time.Unix(int64(friend.LastOnline.Second()), 0)),
|
||||
BecameFriend: timestamppb.New(friend.BecameFriend.Standard()),
|
||||
LastOnline: timestamppb.New(friend.LastOnline.Standard()),
|
||||
}
|
||||
return &pb.GetUserDataWiiUResponse{
|
||||
User: info,
|
||||
@@ -69,7 +76,7 @@ func (s *gRPCFriendsV2Server) GetUserDataWiiU(ctx context.Context, in *pb.GetUse
|
||||
}
|
||||
|
||||
func (s *gRPCFriendsV2Server) GetUserData3DS(ctx context.Context, in *pb.GetUserData3DSRequest) (*pb.GetUserData3DSResponse, error) {
|
||||
friend, err := database_3ds.GetUserData(in.GetPid())
|
||||
friend, err := database_3ds.GetUserData(types.PID(in.GetPid()))
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
if err == database.ErrPIDNotFound {
|
||||
@@ -79,7 +86,7 @@ func (s *gRPCFriendsV2Server) GetUserData3DS(ctx context.Context, in *pb.GetUser
|
||||
}
|
||||
}
|
||||
|
||||
miiData, err := database_3ds.GetMii(in.GetPid())
|
||||
miiData, err := database_3ds.GetMii(types.PID(in.GetPid()))
|
||||
if err != nil {
|
||||
globals.Logger.Critical(err.Error())
|
||||
if err == database.ErrPIDNotFound {
|
||||
@@ -89,25 +96,25 @@ func (s *gRPCFriendsV2Server) GetUserData3DS(ctx context.Context, in *pb.GetUser
|
||||
}
|
||||
}
|
||||
|
||||
var gameKey = &pb.GameKey{
|
||||
gameKey := &pb.GameKey{
|
||||
TitleId: uint64(friend.GameKey.TitleID),
|
||||
TitleVersion: uint32(friend.GameKey.TitleVersion),
|
||||
}
|
||||
|
||||
var mii = &pb.Mii{
|
||||
mii := &pb.Mii{
|
||||
Name: string(miiData.Mii.Name),
|
||||
ProfanityFlag: bool(miiData.Mii.ProfanityFlag),
|
||||
CharacterSet: uint32(miiData.Mii.CharacterSet),
|
||||
MiiDataEncrypted: miiData.Mii.MiiData,
|
||||
// TODO: Implement MiiData
|
||||
}
|
||||
var friendMii = &pb.FriendMii{
|
||||
friendMii := &pb.FriendMii{
|
||||
Pid: uint32(miiData.PID),
|
||||
Mii: mii,
|
||||
ModifiedAt: timestamppb.New(time.Unix(int64(miiData.ModifiedAt.Second()), 0)),
|
||||
}
|
||||
|
||||
var presence = &pb.NintendoPresence{}
|
||||
presence := &pb.NintendoPresence{}
|
||||
connectedUser, ok := globals.ConnectedUsers.Get(uint32(friend.PID))
|
||||
if ok && connectedUser != nil {
|
||||
presence.ChangedFlags = uint32(connectedUser.Presence.ChangedFlags)
|
||||
@@ -125,7 +132,7 @@ func (s *gRPCFriendsV2Server) GetUserData3DS(ctx context.Context, in *pb.GetUser
|
||||
presence.ApplicationArg = connectedUser.Presence.ApplicationArg
|
||||
}
|
||||
|
||||
var info = &pb.FriendInfo3DS{
|
||||
info := &pb.FriendInfo3DS{
|
||||
Pid: uint32(friend.PID),
|
||||
Region: uint32(friend.Region),
|
||||
Country: uint32(friend.Country),
|
||||
@@ -135,9 +142,9 @@ func (s *gRPCFriendsV2Server) GetUserData3DS(ctx context.Context, in *pb.GetUser
|
||||
Presence: presence,
|
||||
GameKey: gameKey,
|
||||
Message: string(friend.Message),
|
||||
MessageUpdatedAt: timestamppb.New(time.Unix(int64(friend.MessageUpdatedAt.Second()), 0)),
|
||||
MiiModifiedAt: timestamppb.New(time.Unix(int64(friend.MiiModifiedAt.Second()), 0)),
|
||||
LastOnline: timestamppb.New(time.Unix(int64(friend.LastOnline.Second()), 0)),
|
||||
MessageUpdatedAt: timestamppb.New(friend.MessageUpdatedAt.Standard()),
|
||||
MiiModifiedAt: timestamppb.New(friend.MiiModifiedAt.Standard()),
|
||||
LastOnline: timestamppb.New(friend.LastOnline.Standard()),
|
||||
Mii: friendMii,
|
||||
}
|
||||
return &pb.GetUserData3DSResponse{
|
||||
|
||||
@@ -90,29 +90,33 @@ func (s *gRPCFriendsV2Server) GetUserFriendsDataWiiU(ctx context.Context, in *pb
|
||||
}
|
||||
|
||||
for _, friend := range friendList {
|
||||
// TODO: Is there a better way to do this? I really don't know what I'm doing here
|
||||
var comment = &pb.Comment{
|
||||
comment := &pb.Comment{
|
||||
Contents: string(friend.Status.Contents),
|
||||
LastChanged: timestamppb.New(time.Unix(int64(friend.Status.LastChanged.Second()), 0)),
|
||||
}
|
||||
var mii = &pb.MiiV2{
|
||||
|
||||
mii := &pb.MiiV2{
|
||||
Name: string(friend.NNAInfo.PrincipalBasicInfo.Mii.Name),
|
||||
MiiData: friend.NNAInfo.PrincipalBasicInfo.Mii.MiiData,
|
||||
Datetime: timestamppb.New(time.Unix(int64(friend.NNAInfo.PrincipalBasicInfo.Mii.Datetime.Second()), 0)),
|
||||
}
|
||||
var principal = &pb.PrincipalBasicInfo{
|
||||
|
||||
principal := &pb.PrincipalBasicInfo{
|
||||
Pid: uint32(friend.NNAInfo.PrincipalBasicInfo.PID),
|
||||
Nnid: string(friend.NNAInfo.PrincipalBasicInfo.NNID),
|
||||
Mii: mii,
|
||||
}
|
||||
var nnaInfo = &pb.NNAInfo{
|
||||
|
||||
nnaInfo := &pb.NNAInfo{
|
||||
PrincipalBasicInfo: principal,
|
||||
}
|
||||
var gameKey = &pb.GameKey{
|
||||
|
||||
gameKey := &pb.GameKey{
|
||||
TitleId: uint64(friend.Presence.GameKey.TitleID),
|
||||
TitleVersion: uint32(friend.Presence.GameKey.TitleVersion),
|
||||
}
|
||||
var presence = &pb.NintendoPresenceV2{
|
||||
|
||||
presence := &pb.NintendoPresenceV2{
|
||||
ChangedFlags: uint32(friend.Presence.ChangedFlags),
|
||||
Online: bool(friend.Presence.Online),
|
||||
GameKey: gameKey,
|
||||
@@ -122,13 +126,15 @@ func (s *gRPCFriendsV2Server) GetUserFriendsDataWiiU(ctx context.Context, in *pb
|
||||
GatheringId: uint32(friend.Presence.GatheringID),
|
||||
ApplicationData: friend.Presence.ApplicationData,
|
||||
}
|
||||
var info = &pb.FriendInfoWiiU{
|
||||
|
||||
info := &pb.FriendInfoWiiU{
|
||||
NnaInfo: nnaInfo,
|
||||
Presence: presence,
|
||||
Status: comment,
|
||||
BecameFriend: timestamppb.New(time.Unix(int64(friend.BecameFriend.Second()), 0)),
|
||||
LastOnline: timestamppb.New(time.Unix(int64(friend.LastOnline.Second()), 0)),
|
||||
BecameFriend: timestamppb.New(friend.BecameFriend.Standard()),
|
||||
LastOnline: timestamppb.New(friend.LastOnline.Standard()),
|
||||
}
|
||||
|
||||
friends = append(friends, info)
|
||||
}
|
||||
|
||||
@@ -213,35 +219,40 @@ func (s *gRPCFriendsV2Server) GetUserFriendsData3DS(ctx context.Context, in *pb.
|
||||
}
|
||||
|
||||
for _, friend := range friendInfoList {
|
||||
// TODO: Is there a better way to do this? I really don't know what I'm doing here
|
||||
var gameKey = &pb.GameKey{
|
||||
gameKey := &pb.GameKey{
|
||||
TitleId: uint64(friend.GameKey.TitleID),
|
||||
TitleVersion: uint32(friend.GameKey.TitleVersion),
|
||||
}
|
||||
var miiIndex = -1
|
||||
|
||||
miiIndex := -1
|
||||
for index, mii := range miiList {
|
||||
if mii.PID == friend.PID {
|
||||
miiIndex = index
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if miiIndex == -1 {
|
||||
continue
|
||||
}
|
||||
var miiData = miiList[miiIndex]
|
||||
var mii = &pb.Mii{
|
||||
|
||||
miiData := miiList[miiIndex]
|
||||
mii := &pb.Mii{
|
||||
Name: string(miiData.Mii.Name),
|
||||
ProfanityFlag: bool(miiData.Mii.ProfanityFlag),
|
||||
CharacterSet: uint32(miiData.Mii.CharacterSet),
|
||||
MiiData: miiData.Mii.MiiData,
|
||||
}
|
||||
var friendMii = &pb.FriendMii{
|
||||
|
||||
friendMii := &pb.FriendMii{
|
||||
Pid: uint32(miiData.PID),
|
||||
Mii: mii,
|
||||
ModifiedAt: timestamppb.New(time.Unix(int64(miiData.ModifiedAt.Second()), 0)),
|
||||
}
|
||||
var presence = &pb.NintendoPresence{}
|
||||
|
||||
presence := &pb.NintendoPresence{}
|
||||
connectedUser, ok := globals.ConnectedUsers.Get(uint32(friend.PID))
|
||||
|
||||
if ok && connectedUser != nil {
|
||||
presence.ChangedFlags = uint32(connectedUser.Presence.ChangedFlags)
|
||||
presence.GameKey = &pb.GameKey{
|
||||
@@ -258,7 +269,7 @@ func (s *gRPCFriendsV2Server) GetUserFriendsData3DS(ctx context.Context, in *pb.
|
||||
presence.ApplicationArg = connectedUser.Presence.ApplicationArg
|
||||
}
|
||||
|
||||
var info = &pb.FriendInfo3DS{
|
||||
info := &pb.FriendInfo3DS{
|
||||
Pid: uint32(friend.PID),
|
||||
Region: uint32(friend.Region),
|
||||
Country: uint32(friend.Country),
|
||||
@@ -268,9 +279,9 @@ func (s *gRPCFriendsV2Server) GetUserFriendsData3DS(ctx context.Context, in *pb.
|
||||
Presence: presence,
|
||||
GameKey: gameKey,
|
||||
Message: string(friend.Message),
|
||||
MessageUpdatedAt: timestamppb.New(time.Unix(int64(friend.MessageUpdatedAt.Second()), 0)),
|
||||
MiiModifiedAt: timestamppb.New(time.Unix(int64(friend.MiiModifiedAt.Second()), 0)),
|
||||
LastOnline: timestamppb.New(time.Unix(int64(friend.LastOnline.Second()), 0)),
|
||||
MessageUpdatedAt: timestamppb.New(friend.MessageUpdatedAt.Standard()),
|
||||
MiiModifiedAt: timestamppb.New(friend.MiiModifiedAt.Standard()),
|
||||
LastOnline: timestamppb.New(friend.LastOnline.Standard()),
|
||||
Mii: friendMii,
|
||||
}
|
||||
friends = append(friends, info)
|
||||
|
||||
Reference in New Issue
Block a user