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 v2 NEX libraries #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package database
import (
"database/sql"

ranking_types "github.com/PretendoNetwork/nex-protocols-go/ranking/types"
"github.com/PretendoNetwork/nex-go/v2/types"
ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types"
"github.com/PretendoNetwork/pikmin-3/globals"
)

func GetRankingsByCategoryAndRankingOrderParam(category uint32, rankingOrderParam *ranking_types.RankingOrderParam) (error, []*ranking_types.RankingRankData) {
rankings := make([]*ranking_types.RankingRankData, 0, rankingOrderParam.Length)
func GetRankingsAndCountByCategoryAndRankingOrderParam(category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error) {
rankings := types.NewList[*ranking_types.RankingRankData]()

rows, err := Postgres.Query(`
SELECT
Expand All @@ -23,14 +24,14 @@ func GetRankingsByCategoryAndRankingOrderParam(category uint32, rankingOrderPara
rankingOrderParam.Offset,
)
if err != nil {
return err, rankings
return nil, 0, err
}

row := 1
for rows.Next() {
rankingRankData := ranking_types.NewRankingRankData()
rankingRankData.UniqueID = 0
rankingRankData.Order = uint32(row)
rankingRankData.UniqueID.Value = 0
rankingRankData.Order.Value = uint32(row)
rankingRankData.Category = category

err := rows.Scan(
Expand All @@ -46,11 +47,11 @@ func GetRankingsByCategoryAndRankingOrderParam(category uint32, rankingOrderPara
}

if err == nil {
rankings = append(rankings, rankingRankData)
rankings.Append(rankingRankData)

row += 1
}
}

return nil, rankings
return rankings, uint32(rankings.Length()), nil
}
19 changes: 10 additions & 9 deletions database/insert_ranking_by_pid_and_ranking_score_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package database
import (
"time"

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

func InsertRankingByPIDAndRankingScoreData(pid uint32, rankingScoreData *ranking_types.RankingScoreData) error {
func InsertRankingByPIDAndRankingScoreData(pid *types.PID, rankingScoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) error {
now := time.Now().UnixNano()

_, err := Postgres.Exec(`
Expand All @@ -22,13 +23,13 @@ func InsertRankingByPIDAndRankingScoreData(pid uint32, rankingScoreData *ranking
created_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
pid,
rankingScoreData.Category,
rankingScoreData.Score,
rankingScoreData.OrderBy,
rankingScoreData.UpdateMode,
rankingScoreData.Groups,
rankingScoreData.Param,
pid.Value(),
rankingScoreData.Category.Value,
rankingScoreData.Score.Value,
rankingScoreData.OrderBy.Value,
rankingScoreData.UpdateMode.Value,
rankingScoreData.Groups.Value,
rankingScoreData.Param.Value,
make([]byte, 0),
now,
)
Expand Down
64 changes: 64 additions & 0 deletions globals/accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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
}
8 changes: 5 additions & 3 deletions globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package globals

import (
pb "github.com/PretendoNetwork/grpc-go/account"
"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.Logger
var KerberosPassword = "password" // * Default password
var AuthenticationServer *nex.Server
var SecureServer *nex.Server
var AuthenticationServer *nex.PRUDPServer
var AuthenticationEndpoint *nex.PRUDPEndPoint
var SecureServer *nex.PRUDPServer
var SecureEndpoint *nex.PRUDPEndPoint
var GRPCAccountClientConnection *grpc.ClientConn
var GRPCAccountClient pb.AccountClient
var GRPCAccountCommonMetadata metadata.MD
13 changes: 7 additions & 6 deletions globals/password_from_pid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package globals
import (
"context"

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

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

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

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

return response.Password, 0
Expand Down
27 changes: 19 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
module github.com/PretendoNetwork/pikmin-3

go 1.19
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.39
github.com/PretendoNetwork/plogger-go v1.0.3
github.com/PretendoNetwork/plogger-go v1.0.4
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
google.golang.org/grpc v1.56.2
)

require (
github.com/fatih/color v1.15.0 // indirect
github.com/PretendoNetwork/nex-go/v2 v2.0.5 // indirect
github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.5 // indirect
github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.3 // indirect
github.com/dolthub/maphash v0.1.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/golang/protobuf v1.5.3 // 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/mattn/go-isatty v0.0.20 // indirect
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect
github.com/superwhiskers/crunch/v3 v3.5.7 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.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/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/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
32 changes: 32 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@ github.com/PretendoNetwork/grpc-go v1.0.1 h1:3O0n4vnRX9rAZfrrjZydDjEOyWb4TbJcvwM
github.com/PretendoNetwork/grpc-go v1.0.1/go.mod h1:XZjEsij9lL7HJBNkH6JPbBIkUSq/1rjflvjGdv+DAj0=
github.com/PretendoNetwork/nex-go v1.0.28 h1:g3892srP1T7LaeY5JklMtLZ03gTxE8wpXqpPQpXpN74=
github.com/PretendoNetwork/nex-go v1.0.28/go.mod h1:tWfWhrC/DCJuS08jTk0ceOv2R1VtElvKSVv13To6miE=
github.com/PretendoNetwork/nex-go/v2 v2.0.5 h1:S/bYPb2SNUb9MSzai4wlqj/9J1JIiLuMtZcAAbBughM=
github.com/PretendoNetwork/nex-go/v2 v2.0.5/go.mod h1:iW1xjbg/vl2c3uheitUFxGcrt0sxaDxeXR5QqDcyLpI=
github.com/PretendoNetwork/nex-protocols-common-go v1.0.22 h1:oIKx3AsBApaKWl1f91q/Vt59YKJOjoUhzxs/F0UA1Vw=
github.com/PretendoNetwork/nex-protocols-common-go v1.0.22/go.mod h1:UwVHUdB1WFlzVn4yq8WLai0J+9OQXw4cg5qNjnJQ3RU=
github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.5 h1:17b7vA8wjWLW9JdJTHeOoX2g2e4S/EwA32m9AuPEA80=
github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.5/go.mod h1:0wDEYxDYbUOjsKjsTUjU0/f3pL1MT54h+tGn4UyeB+A=
github.com/PretendoNetwork/nex-protocols-go v1.0.39 h1:l0wezyS1s8WELcuiZBV726C/cYE0GHHnnks2GLP+33Q=
github.com/PretendoNetwork/nex-protocols-go v1.0.39/go.mod h1:jZSnoM2G4oc7tKXeUf2OkJ6VyfJc4nb7gR++2oNEh5A=
github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.3 h1:80CG7f9w/34MN1vAZ1XP3ec4LJ4mqKlkests+HQzrvc=
github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.3/go.mod h1:2UN8khoMDNaeJ4GcIG7ez7MqqmbLfLzbVS6hSa+kGnk=
github.com/PretendoNetwork/plogger-go v1.0.3 h1:KEnrUfPaCn0LFweg8OrhtiDhlN3pclWpNhlmAtmgfB0=
github.com/PretendoNetwork/plogger-go v1.0.3/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU=
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/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ=
github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
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=
Expand All @@ -19,28 +31,48 @@ 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/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lxzan/gws v1.8.3 h1:umX2VLhXj7oVV4Sd2gCuqzrzpVWtqkKMy0tjHBBxXg0=
github.com/lxzan/gws v1.8.3/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.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/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs=
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e/go.mod h1:9leZcVcItj6m9/CfHY5Em/iBrCz7js8LcRQGTKEEv2M=
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-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM=
Expand Down
5 changes: 5 additions & 0 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"

pb "github.com/PretendoNetwork/grpc-go/account"
"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
"github.com/PretendoNetwork/pikmin-3/database"
"github.com/PretendoNetwork/pikmin-3/globals"
"github.com/PretendoNetwork/plogger-go"
Expand Down Expand Up @@ -46,6 +48,9 @@ func init() {
globals.KerberosPassword = kerberosPassword
}

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

if strings.TrimSpace(authenticationServerPort) == "" {
globals.Logger.Error("PN_PIKMIN3_AUTHENTICATION_SERVER_PORT environment variable not set")
os.Exit(0)
Expand Down
35 changes: 19 additions & 16 deletions nex/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@ package nex
import (
"fmt"
"os"
"strconv"

nex "github.com/PretendoNetwork/nex-go"
nex "github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/pikmin-3/globals"
)

var serverBuildString string

func StartAuthenticationServer() {
globals.AuthenticationServer = nex.NewServer()
globals.AuthenticationServer.SetPRUDPVersion(1)
globals.AuthenticationServer.SetPRUDPProtocolMinorVersion(3)
globals.AuthenticationServer.SetDefaultNEXVersion(&nex.NEXVersion{
Major: 3,
Minor: 3,
Patch: 0,
})
globals.AuthenticationServer.SetKerberosPassword(globals.KerberosPassword)
globals.AuthenticationServer.SetAccessKey("f6accfc1")
globals.AuthenticationServer = nex.NewPRUDPServer()

globals.AuthenticationEndpoint = nex.NewPRUDPEndPoint(1)
globals.AuthenticationEndpoint.ServerAccount = globals.AuthenticationServerAccount
globals.AuthenticationEndpoint.AccountDetailsByPID = globals.AccountDetailsByPID
globals.AuthenticationEndpoint.AccountDetailsByUsername = globals.AccountDetailsByUsername
globals.AuthenticationServer.BindPRUDPEndPoint(globals.AuthenticationEndpoint)

globals.AuthenticationServer.On("Data", func(packet *nex.PacketV1) {
request := packet.RMCRequest()
globals.AuthenticationServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(3, 3, 0))
globals.AuthenticationServer.AccessKey = "f6accfc1"

globals.AuthenticationEndpoint.OnData(func(packet nex.PacketInterface) {
request := packet.RMCMessage()

fmt.Println("==PIKMIN 3 - Auth==")
fmt.Printf("Protocol ID: %#v\n", request.ProtocolID())
fmt.Printf("Method ID: %#v\n", request.MethodID())
fmt.Printf("Protocol ID: %#v\n", request.ProtocolID)
fmt.Printf("Method ID: %#v\n", request.MethodID)
fmt.Println("===============")
})

registerCommonAuthenticationServerProtocols()

globals.AuthenticationServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_PIKMIN3_AUTHENTICATION_SERVER_PORT")))
port, _ := strconv.Atoi(os.Getenv("PN_PIKMIN3_AUTHENTICATION_SERVER_PORT"))

globals.AuthenticationServer.Listen(port)
}
Loading
Loading