Skip to content

Commit

Permalink
Merge pull request #2 from ashquarky/v2-update
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow authored Jun 30, 2024
2 parents 0501905 + 9b9f3f5 commit 1ca59de
Show file tree
Hide file tree
Showing 30 changed files with 326 additions and 787 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ go.work.sum

# custom
.vscode
.idea
.env
build
log
*.pem
*.key
*.key
*.pcap
*.pcapng
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ All configuration options are handled via environment variables

`.env` files are supported

| Name | Description | Required |
|-----------------------------------------|------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `PN_MINECRAFT_POSTGRES_URI` | Fully qualified URI to your Postgres server (Example `postgres://username:password@localhost/minecraft?sslmode=disable`) | Yes |
| `PN_MINECRAFT_KERBEROS_PASSWORD` | Password used as part of the internal server data in Kerberos tickets | No (Default password `password` will be used) |
| `PN_MINECRAFT_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes |
| `PN_MINECRAFT_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes |
| `PN_MINECRAFT_SECURE_SERVER_PORT` | Port for the secure server | Yes |
| `PN_MINECRAFT_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes |
| `PN_MINECRAFT_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes |
| `PN_MINECRAFT_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) |
| Name | Description | Required |
|-------------------------------------------|-------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `PN_MINECRAFT_KERBEROS_PASSWORD` | Password used as part of the internal server data in Kerberos tickets | No (Default password `password` will be used) |
| `PN_MINECRAFT_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes |
| `PN_MINECRAFT_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes |
| `PN_MINECRAFT_SECURE_SERVER_PORT` | Port for the secure server | Yes |
| `PN_MINECRAFT_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes |
| `PN_MINECRAFT_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes |
| `PN_MINECRAFT_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) |
| `PN_MINECRAFT_ALLOW_PUBLIC_MATCHMAKING` | Set to "1" to enable public matchmaking (unsafe - game has 0 anticheat) | No (Assumed 0) |
25 changes: 0 additions & 25 deletions database/connect_postgres.go

This file was deleted.

63 changes: 0 additions & 63 deletions database/get_rankings_by_category_and_ranking_order_param.go

This file was deleted.

12 changes: 0 additions & 12 deletions database/get_total_rankings_by_category.go

This file was deleted.

26 changes: 0 additions & 26 deletions database/init_postgres.go

This file was deleted.

38 changes: 0 additions & 38 deletions database/insert_ranking_by_pid_and_ranking_score_data.go

This file was deleted.

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 (
"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
"strconv"
)

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
}
11 changes: 8 additions & 3 deletions globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ 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
12 changes: 6 additions & 6 deletions globals/password_from_pid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,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
37 changes: 20 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
module github.com/PretendoNetwork/minecraft-wiiu

go 1.19
go 1.21

replace github.com/PretendoNetwork/nex-protocols-common-go => ./nex-protocols-common-go
toolchain go1.21.9

require (
github.com/PretendoNetwork/grpc-go v1.0.2
github.com/PretendoNetwork/nex-go v1.0.41
github.com/PretendoNetwork/nex-protocols-common-go v1.0.28
github.com/PretendoNetwork/nex-protocols-go v1.0.55
github.com/PretendoNetwork/nex-go/v2 v2.0.2
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
github.com/lib/pq v1.10.9
google.golang.org/grpc v1.59.0
google.golang.org/grpc v1.63.2
)

require (
github.com/fatih/color v1.15.0 // indirect
github.com/golang/protobuf v1.5.3 // 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/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.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/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/protobuf v1.31.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-20240415180920-8c6c420018be // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading

0 comments on commit 1ca59de

Please sign in to comment.