Skip to content

Commit

Permalink
feat: Update to latest library versions
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniElectra committed Feb 11, 2025
1 parent e3ed1da commit 661568b
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 130 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ All configuration options are handled via environment variables

`.env` files are supported

| Name | Description | Required |
|------------------------------------------|--------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `PN_IRONFALL_KERBEROS_PASSWORD` | Password used as part of the internal server data in Kerberos tickets | No (Default password `password` will be used) |
| `PN_IRONFALL_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes |
| `PN_IRONFALL_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes |
| `PN_IRONFALL_SECURE_SERVER_PORT` | Port for the secure server | Yes |
| `PN_IRONFALL_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes |
| `PN_IRONFALL_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes |
| `PN_IRONFALL_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) |
| `PN_IRONFALL_FRIENDS_GRPC_HOST` | Host name for your friends server gRPC service | Yes |
| `PN_IRONFALL_FRIENDS_GRPC_PORT` | Port for your friends server gRPC service | Yes |
| `PN_IRONFALL_FRIENDS_GRPC_API_KEY` | API key for your friends server gRPC service | No (Assumed to be an open gRPC API) |
| Name | Description | Required |
|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|-------------------------------------|
| `PN_IRONFALL_POSTGRES_URI` | Fully qualified URI to your Postgres server (Example `postgres://username:password@localhost/ironfall?sslmode=disable`) | Yes |
| `PN_IRONFALL_AUTHENTICATION_SERVER_PORT` | Port for the authentication server | Yes |
| `PN_IRONFALL_SECURE_SERVER_HOST` | Host name for the secure server (should point to the same address as the authentication server) | Yes |
| `PN_IRONFALL_SECURE_SERVER_PORT` | Port for the secure server | Yes |
| `PN_IRONFALL_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes |
| `PN_IRONFALL_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes |
| `PN_IRONFALL_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) |
| `PN_IRONFALL_FRIENDS_GRPC_HOST` | Host name for your friends server gRPC service | Yes |
| `PN_IRONFALL_FRIENDS_GRPC_PORT` | Port for your friends server gRPC service | Yes |
| `PN_IRONFALL_FRIENDS_GRPC_API_KEY` | API key for your friends server gRPC service | No (Assumed to be an open gRPC API) |
23 changes: 23 additions & 0 deletions database/connect_postgres.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package database

import (
"database/sql"
"os"

_ "github.com/lib/pq"

"github.com/PretendoNetwork/ironfall-invasion/globals"
)

var Postgres *sql.DB

func ConnectPostgres() {
var err error

Postgres, err = sql.Open("postgres", os.Getenv("PN_IRONFALL_POSTGRES_URI"))
if err != nil {
globals.Logger.Critical(err.Error())
}

globals.Logger.Success("Connected to Postgres!")
}
56 changes: 56 additions & 0 deletions globals/accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 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)), 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 {
return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidUsername, "Invalid username")
}

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

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

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

return account, nil
}
2 changes: 1 addition & 1 deletion globals/get_user_friend_pids.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

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

Expand Down
8 changes: 5 additions & 3 deletions globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package globals
import (
pb_account "github.com/PretendoNetwork/grpc-go/account"
pb_friends "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 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_account.AccountClient
var GRPCAccountCommonMetadata metadata.MD
Expand Down
11 changes: 6 additions & 5 deletions globals/password_from_pid.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"context"

pb_account "github.com/PretendoNetwork/grpc-go/account"
"github.com/PretendoNetwork/nex-go"
"github.com/PretendoNetwork/nex-protocols-go/globals"
"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
"github.com/PretendoNetwork/nex-protocols-go/v2/globals"
"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_account.GetNEXPasswordRequest{Pid: pid})
response, err := GRPCAccountClient.GetNEXPassword(ctx, &pb_account.GetNEXPasswordRequest{Pid: uint32(pid)})
if err != nil {
globals.Logger.Error(err.Error())
return "", nex.Errors.RendezVous.InvalidUsername
return "", nex.ResultCodes.RendezVous.InvalidUsername
}

return response.Password, 0
Expand Down
40 changes: 24 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
module github.com/PretendoNetwork/ironfall-invasion

go 1.19
go 1.22.1

toolchain go1.23.5

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.29
github.com/PretendoNetwork/nex-protocols-go v1.0.55
github.com/PretendoNetwork/nex-go/v2 v2.1.1
github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.2.1
github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.0
github.com/PretendoNetwork/plogger-go v1.0.4
github.com/joho/godotenv v1.5.1
google.golang.org/grpc v1.59.0
github.com/lib/pq v1.10.9
google.golang.org/grpc v1.70.0
)

require (
github.com/fatih/color v1.15.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/PretendoNetwork/pq-extended v1.0.0 // indirect
github.com/dolthub/maphash v0.1.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/jwalton/go-supportscolor v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/lxzan/gws v1.8.8 // indirect
github.com/mattn/go-colorable v0.1.14 // 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-20250210185358-939b2ce775ac // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 // indirect
google.golang.org/protobuf v1.36.5 // indirect
)
Loading

0 comments on commit 661568b

Please sign in to comment.