Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to nex-go v2 #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion database/connect_mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func connectMongo() {
mongoContext, _ = context.WithTimeout(context.Background(), 10*time.Second)
_ = mongoClient.Connect(mongoContext)

accountDatabase = mongoClient.Database("pretendo")
accountDatabase = mongoClient.Database("pretendo_account")
ItzSwirlz marked this conversation as resolved.
Show resolved Hide resolved
pnidCollection = accountDatabase.Collection("pnids")
nexAccountsCollection = accountDatabase.Collection("nexaccounts")

Expand Down
4 changes: 2 additions & 2 deletions database/get_call_info_by_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

func GetCallInfoByTarget(target uint32) (uint32, uint32, bool) { // caller pid, target pid, ringing
func GetCallInfoByTarget(target uint64) (uint64, uint64, bool) { // caller pid, target pid, ringing
ItzSwirlz marked this conversation as resolved.
Show resolved Hide resolved
var result bson.M
filter := bson.D{
{"target_pid", target},
Expand All @@ -22,6 +22,6 @@ func GetCallInfoByTarget(target uint32) (uint32, uint32, bool) { // caller pid,
panic(err)
}
} else {
return uint32(result["caller_pid"].(int64)), uint32(result["target_pid"].(int64)), result["ringing"].(bool)
return uint64(result["caller_pid"].(int64)), uint64(result["target_pid"].(int64)), result["ringing"].(bool)
}
}
63 changes: 63 additions & 0 deletions globals/accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package globals

import (
"strconv"

"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
)

var AuthenticationServerAccount *nex.Account
var SecureServerAccount *nex.Account

func InitAccounts() {
AuthenticationServerAccount = nex.NewAccount(types.NewPID(1), "Quazal Authentication", KerberosPassword)
SecureServerAccount = nex.NewAccount(types.NewPID(2), "Quazal Rendez-Vous", KerberosPassword)
}

func AccountDetailsByPID(pid *types.PID) (*nex.Account, *nex.Error) {
if pid.Equals(AuthenticationServerAccount.PID) {
return AuthenticationServerAccount, nil
}

if pid.Equals(SecureServerAccount.PID) {
return SecureServerAccount, nil
}

password, errorCode := PasswordFromPID(pid)
if errorCode != 0 {
return nil, nex.NewError(errorCode, "Failed to get password from PID")
}

account := nex.NewAccount(pid, strconv.Itoa(int(pid.LegacyValue())), password)

return account, nil
}

func AccountDetailsByUsername(username string) (*nex.Account, *nex.Error) {
if username == AuthenticationServerAccount.Username {
return AuthenticationServerAccount, nil
}

if username == SecureServerAccount.Username {
return SecureServerAccount, nil
}

pidInt, err := strconv.Atoi(username)
if err != nil {
Logger.Error(err.Error())
return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidUsername, "Invalid username")
}

pid := types.NewPID(uint64(pidInt))

password, errorCode := PasswordFromPID(pid)
if errorCode != 0 {
Logger.Errorf("Password err: %v", errorCode)
return nil, nex.NewError(errorCode, "Failed to get password from PID")
}

account := nex.NewAccount(pid, username, password)

return account, nil
}
12 changes: 10 additions & 2 deletions globals/globals.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package globals

import (
pb_account "github.com/PretendoNetwork/grpc-go/account"
pb "github.com/PretendoNetwork/grpc-go/friends"
"github.com/PretendoNetwork/nex-go"
"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/plogger-go"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)

var Logger = plogger.NewLogger()
var NEXServer *nex.Server
var KerberosPassword = "password" // * Default password
var SecureServer *nex.PRUDPServer
var SecureEndpoint *nex.PRUDPEndPoint

var GRPCAccountClientConnection *grpc.ClientConn
var GRPCAccountClient pb_account.AccountClient
var GRPCAccountCommonMetadata metadata.MD

var GRPCFriendsClientConnection *grpc.ClientConn
var GRPCFriendsClient pb.FriendsClient
var GRPCFriendsCommonMetadata metadata.MD
23 changes: 23 additions & 0 deletions globals/password_from_pid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package globals

import (
"context"

"github.com/PretendoNetwork/nex-go/v2/types"

pb "github.com/PretendoNetwork/grpc-go/account"
"github.com/PretendoNetwork/nex-go/v2"
"google.golang.org/grpc/metadata"
)

func PasswordFromPID(pid *types.PID) (string, uint32) {
ctx := metadata.NewOutgoingContext(context.Background(), GRPCAccountCommonMetadata)

response, err := GRPCAccountClient.GetNEXPassword(ctx, &pb.GetNEXPasswordRequest{Pid: pid.LegacyValue()})
if err != nil {
Logger.Error(err.Error())
return "", nex.ResultCodes.RendezVous.InvalidUsername
}

return response.Password, 0
}
49 changes: 29 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
module github.com/PretendoNetwork/wiiu-chat-secure

go 1.18
go 1.21

toolchain go1.22.4

require (
github.com/PretendoNetwork/grpc-go v1.0.1
github.com/PretendoNetwork/nex-go v1.0.28
github.com/PretendoNetwork/nex-protocols-common-go v1.0.22
github.com/PretendoNetwork/nex-protocols-go v1.0.38
github.com/PretendoNetwork/plogger-go v1.0.3
github.com/PretendoNetwork/nex-go/v2 v2.0.5
github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.5
github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.3
github.com/PretendoNetwork/plogger-go v1.0.4
github.com/joho/godotenv v1.5.1
go.mongodb.org/mongo-driver v1.11.4
google.golang.org/grpc v1.48.0
go.mongodb.org/mongo-driver v1.16.0
google.golang.org/grpc v1.65.0
)

require (
github.com/fatih/color v1.15.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/PretendoNetwork/nex-go v1.0.41 // indirect
github.com/PretendoNetwork/nex-protocols-go v1.0.58 // indirect
github.com/dolthub/maphash v0.1.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/jwalton/go-supportscolor v1.1.0 // indirect
github.com/klauspost/compress v1.16.4 // indirect
github.com/jwalton/go-supportscolor v1.2.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/lxzan/gws v1.8.3 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/montanaflynn/stats v0.7.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect
github.com/superwhiskers/crunch/v3 v3.5.7 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)
Loading