From f326cb00b39b96cdc8e5f347c632c001e7739642 Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Fri, 19 Apr 2024 21:43:47 +1000 Subject: [PATCH 1/2] feat!(rewrite): Update to v2 libraries Updated nex libraries to their new v2 counterparts, and rewrite for the new API as appropriate. Removed a lot of dead code, notably NEX ranking, subscriptions, and the database connection for rankings - these are unused for Minecraft. --- .gitignore | 5 +- README.md | 1 - database/connect_postgres.go | 25 ------ ...ngs_by_category_and_ranking_order_param.go | 63 ------------- database/get_total_rankings_by_category.go | 12 --- database/init_postgres.go | 26 ------ ...t_ranking_by_pid_and_ranking_score_data.go | 38 -------- globals/accounts.go | 63 +++++++++++++ globals/globals.go | 11 ++- globals/password_from_pid.go | 12 +-- go.mod | 37 ++++---- go.sum | 88 ++++++++++--------- init.go | 11 +-- nex/authentication.go | 38 +++++--- nex/mm.go | 38 -------- nex/ranking/get_ranking.go | 65 -------------- nex/ranking/upload_score.go | 41 --------- ..._common_authentication_server_protocols.go | 36 ++++---- ...register_common_secure_server_protocols.go | 74 +++++++++------- nex/register_secure_server_nex_protocols.go | 11 --- nex/secure.go | 38 +++++--- .../create_my_subscription_data.go | 28 ------ .../get_active_player_subscription_data.go | 41 --------- .../get_friend_subscription_data.go | 33 ------- nex/subscription/get_privacy_levels.go | 27 ------ nex/subscription/get_subscription_data.go | 44 ---------- .../get_target_subscription_data.go | 33 ------- ...eplace_target_and_get_subscription_data.go | 33 ------- .../update_my_subscription_data.go | 29 ------ types/pq_uint8_array.go | 39 -------- 30 files changed, 260 insertions(+), 780 deletions(-) delete mode 100644 database/connect_postgres.go delete mode 100644 database/get_rankings_by_category_and_ranking_order_param.go delete mode 100644 database/get_total_rankings_by_category.go delete mode 100644 database/init_postgres.go delete mode 100644 database/insert_ranking_by_pid_and_ranking_score_data.go create mode 100644 globals/accounts.go delete mode 100644 nex/mm.go delete mode 100644 nex/ranking/get_ranking.go delete mode 100644 nex/ranking/upload_score.go delete mode 100644 nex/register_secure_server_nex_protocols.go delete mode 100644 nex/subscription/create_my_subscription_data.go delete mode 100644 nex/subscription/get_active_player_subscription_data.go delete mode 100644 nex/subscription/get_friend_subscription_data.go delete mode 100644 nex/subscription/get_privacy_levels.go delete mode 100644 nex/subscription/get_subscription_data.go delete mode 100644 nex/subscription/get_target_subscription_data.go delete mode 100644 nex/subscription/replace_target_and_get_subscription_data.go delete mode 100644 nex/subscription/update_my_subscription_data.go delete mode 100644 types/pq_uint8_array.go diff --git a/.gitignore b/.gitignore index c42ec53..70b6edb 100644 --- a/.gitignore +++ b/.gitignore @@ -23,8 +23,11 @@ go.work.sum # custom .vscode +.idea .env build log *.pem -*.key \ No newline at end of file +*.key +*.pcap +*.pcapng \ No newline at end of file diff --git a/README.md b/README.md index aba288b..df77e96 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ All configuration options are handled via environment variables | 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 | diff --git a/database/connect_postgres.go b/database/connect_postgres.go deleted file mode 100644 index d2823f6..0000000 --- a/database/connect_postgres.go +++ /dev/null @@ -1,25 +0,0 @@ -package database - -import ( - "database/sql" - "os" - - _ "github.com/lib/pq" - - "github.com/PretendoNetwork/minecraft-wiiu/globals" -) - -var Postgres *sql.DB - -func ConnectPostgres() { - var err error - - Postgres, err = sql.Open("postgres", os.Getenv("PN_MINECRAFT_POSTGRES_URI")) - if err != nil { - globals.Logger.Critical(err.Error()) - } - - globals.Logger.Success("Connected to Postgres!") - - initPostgres() -} diff --git a/database/get_rankings_by_category_and_ranking_order_param.go b/database/get_rankings_by_category_and_ranking_order_param.go deleted file mode 100644 index acd4805..0000000 --- a/database/get_rankings_by_category_and_ranking_order_param.go +++ /dev/null @@ -1,63 +0,0 @@ -package database - -import ( - "database/sql" - - ranking_types "github.com/PretendoNetwork/nex-protocols-go/ranking/types" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/minecraft-wiiu/types" -) - -func GetRankingsByCategoryAndRankingOrderParam(category uint32, rankingOrderParam *ranking_types.RankingOrderParam) (error, []*ranking_types.RankingRankData) { - rankings := make([]*ranking_types.RankingRankData, 0, rankingOrderParam.Length) - - rows, err := Postgres.Query(` - SELECT - owner_pid, - score, - groups, - param, - common_data - FROM rankings WHERE category=$1 ORDER BY score DESC LIMIT $2 OFFSET $3`, - category, - rankingOrderParam.Length, - rankingOrderParam.Offset, - ) - if err != nil { - return err, rankings - } - - row := 1 - for rows.Next() { - rankingRankData := ranking_types.NewRankingRankData() - rankingRankData.UniqueID = 0 - rankingRankData.Order = uint32(row) - rankingRankData.Category = category - - // * A custom type is needed because - // * Postgres doesn't support scanning - // * uint8 slices by default - var groups types.PQUInt8Array - - err := rows.Scan( - &rankingRankData.PrincipalID, - &rankingRankData.Score, - &groups, - &rankingRankData.Param, - &rankingRankData.CommonData, - ) - - if err != nil && err != sql.ErrNoRows { - globals.Logger.Critical(err.Error()) - } - - if err == nil { - rankingRankData.Groups = groups.Value - rankings = append(rankings, rankingRankData) - - row += 1 - } - } - - return nil, rankings -} diff --git a/database/get_total_rankings_by_category.go b/database/get_total_rankings_by_category.go deleted file mode 100644 index dc4415d..0000000 --- a/database/get_total_rankings_by_category.go +++ /dev/null @@ -1,12 +0,0 @@ -package database - -func GetTotalRankingsByCategory(category uint32) (error, uint32) { - var total uint32 - - err := Postgres.QueryRow(`SELECT COUNT(*) FROM rankings WHERE category=$1`, category).Scan(&total) - if err != nil { - return err, 0 - } - - return nil, total -} diff --git a/database/init_postgres.go b/database/init_postgres.go deleted file mode 100644 index a6d0748..0000000 --- a/database/init_postgres.go +++ /dev/null @@ -1,26 +0,0 @@ -package database - -import "github.com/PretendoNetwork/minecraft-wiiu/globals" - -func initPostgres() { - var err error - - _, err = Postgres.Exec(`CREATE TABLE IF NOT EXISTS rankings ( - id bigserial PRIMARY KEY, - owner_pid integer, - category integer, - score integer, - order_by integer, - update_mode integer, - groups integer[], - param bigint, - common_data bytea, - created_at bigint - )`) - if err != nil { - globals.Logger.Critical(err.Error()) - return - } - - globals.Logger.Success("Postgres tables created") -} diff --git a/database/insert_ranking_by_pid_and_ranking_score_data.go b/database/insert_ranking_by_pid_and_ranking_score_data.go deleted file mode 100644 index 7ae53a2..0000000 --- a/database/insert_ranking_by_pid_and_ranking_score_data.go +++ /dev/null @@ -1,38 +0,0 @@ -package database - -import ( - "time" - - ranking_types "github.com/PretendoNetwork/nex-protocols-go/ranking/types" - "github.com/lib/pq" -) - -func InsertRankingByPIDAndRankingScoreData(pid uint32, rankingScoreData *ranking_types.RankingScoreData) error { - now := time.Now().UnixNano() - - _, err := Postgres.Exec(` - INSERT INTO rankings ( - owner_pid, - category, - score, - order_by, - update_mode, - groups, - param, - common_data, - created_at - ) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, - pid, - rankingScoreData.Category, - rankingScoreData.Score, - rankingScoreData.OrderBy, - rankingScoreData.UpdateMode, - pq.Array(rankingScoreData.Groups), - rankingScoreData.Param, - make([]byte, 0), - now, - ) - - return err -} diff --git a/globals/accounts.go b/globals/accounts.go new file mode 100644 index 0000000..98b6949 --- /dev/null +++ b/globals/accounts.go @@ -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 +} diff --git a/globals/globals.go b/globals/globals.go index 61546bd..4fafd7c 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -2,7 +2,7 @@ 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" @@ -10,8 +10,13 @@ import ( 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 diff --git a/globals/password_from_pid.go b/globals/password_from_pid.go index f59823c..54a3b91 100644 --- a/globals/password_from_pid.go +++ b/globals/password_from_pid.go @@ -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 diff --git a/go.mod b/go.mod index 1a2c264..b8fec80 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index d1c428a..30a9673 100644 --- a/go.sum +++ b/go.sum @@ -1,62 +1,66 @@ github.com/PretendoNetwork/grpc-go v1.0.2 h1:9TvKmX7dCOANyoHEra1MMYqS1N/RGav66TRG4SHInvo= github.com/PretendoNetwork/grpc-go v1.0.2/go.mod h1:XZjEsij9lL7HJBNkH6JPbBIkUSq/1rjflvjGdv+DAj0= -github.com/PretendoNetwork/nex-go v1.0.41 h1:TcBb1Bpe2KAB+AXaGX1K9NVQBRtZJIoy4yCvRde2xbI= -github.com/PretendoNetwork/nex-go v1.0.41/go.mod h1:QwHEa165DeVd0xIuthrgc3j6NWXT8lyPSG6t5kC/Shk= -github.com/PretendoNetwork/nex-protocols-go v1.0.54 h1:nDbGnNpe7F/cwBZBvFFFPS1afZQ4OLpVHfF8t5xug/Y= -github.com/PretendoNetwork/nex-protocols-go v1.0.54/go.mod h1:136762CMIcAsTZDrt4W7gDE4ppiBuc9zN2QFOHESjS8= -github.com/PretendoNetwork/nex-protocols-go v1.0.55 h1:8QMeCNO2eZO4m7CRT/nv2WWm+gDh/REKR5jKTYQaaCs= -github.com/PretendoNetwork/nex-protocols-go v1.0.55/go.mod h1:136762CMIcAsTZDrt4W7gDE4ppiBuc9zN2QFOHESjS8= +github.com/PretendoNetwork/nex-go/v2 v2.0.2 h1:mPp27Ero3Rr28nekuKg4f0tdp28NzmCJXgupt2paT18= +github.com/PretendoNetwork/nex-go/v2 v2.0.2/go.mod h1:O5v200Ro8bdrmqSAmzV0cqQsG7cdmwLHAet5X7Jxz20= +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/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.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc= github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= -github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -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= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 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/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= -github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 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-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= -golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +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.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.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.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.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a h1:a2MQQVoTo96JC9PMGtGBymLp7+/RzpFc2yX/9WfFg1c= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:4cYg8o5yUbm77w8ZX00LhMVNl/YVBFJRYWDc0uYWMs0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc= -google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= -google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= -google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= -google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +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.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be h1:LG9vZxsWGOmUKieR8wPAUR3u3MpnYFQZROPIMaXh7/A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= +google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/init.go b/init.go index aac636b..e632f6a 100644 --- a/init.go +++ b/init.go @@ -7,7 +7,6 @@ import ( "strings" pb "github.com/PretendoNetwork/grpc-go/account" - "github.com/PretendoNetwork/minecraft-wiiu/database" "github.com/PretendoNetwork/minecraft-wiiu/globals" "github.com/PretendoNetwork/plogger-go" "github.com/joho/godotenv" @@ -26,7 +25,6 @@ func init() { globals.Logger.Warning("Error loading .env file") } - postgresURI := os.Getenv("PN_MINECRAFT_POSTGRES_URI") kerberosPassword := os.Getenv("PN_MINECRAFT_KERBEROS_PASSWORD") authenticationServerPort := os.Getenv("PN_MINECRAFT_AUTHENTICATION_SERVER_PORT") secureServerHost := os.Getenv("PN_MINECRAFT_SECURE_SERVER_HOST") @@ -35,17 +33,14 @@ func init() { accountGRPCPort := os.Getenv("PN_MINECRAFT_ACCOUNT_GRPC_PORT") accountGRPCAPIKey := os.Getenv("PN_MINECRAFT_ACCOUNT_GRPC_API_KEY") - if strings.TrimSpace(postgresURI) == "" { - globals.Logger.Error("PN_MINECRAFT_POSTGRES_URI environment variable not set") - os.Exit(0) - } - if strings.TrimSpace(kerberosPassword) == "" { globals.Logger.Warningf("PN_MINECRAFT_KERBEROS_PASSWORD environment variable not set. Using default password: %q", globals.KerberosPassword) } else { globals.KerberosPassword = kerberosPassword } + globals.InitAccounts() + if strings.TrimSpace(authenticationServerPort) == "" { globals.Logger.Error("PN_MINECRAFT_AUTHENTICATION_SERVER_PORT environment variable not set") os.Exit(0) @@ -109,6 +104,4 @@ func init() { globals.GRPCAccountCommonMetadata = metadata.Pairs( "X-API-Key", accountGRPCAPIKey, ) - - database.ConnectPostgres() } diff --git a/nex/authentication.go b/nex/authentication.go index 422040d..762270b 100644 --- a/nex/authentication.go +++ b/nex/authentication.go @@ -3,31 +3,41 @@ package nex import ( "fmt" "os" + "strconv" - nex "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/minecraft-wiiu/globals" + "github.com/PretendoNetwork/nex-go/v2" ) -var serverBuildString string - func StartAuthenticationServer() { - globals.AuthenticationServer = nex.NewServer() - globals.AuthenticationServer.SetPRUDPVersion(1) - globals.AuthenticationServer.SetPRUDPProtocolMinorVersion(2) - globals.AuthenticationServer.SetDefaultNEXVersion(nex.NewNEXVersion(3,10,0)) - globals.AuthenticationServer.SetKerberosPassword(globals.KerberosPassword) - globals.AuthenticationServer.SetAccessKey("f1b61c8e") + globals.AuthenticationServer = nex.NewPRUDPServer() + globals.AuthenticationServer.ByteStreamSettings.UseStructureHeader = true + + 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.LibraryVersions.SetDefault(nex.NewLibraryVersion(3, 10, 0)) + globals.AuthenticationServer.AccessKey = "f1b61c8e" - globals.AuthenticationServer.On("Data", func(packet *nex.PacketV1) { - request := packet.RMCRequest() + globals.AuthenticationEndpoint.OnData(func(packet nex.PacketInterface) { + request := packet.RMCMessage() fmt.Println("==Minecraft: Wii U Edition - 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("===============") }) + globals.AuthenticationEndpoint.OnError(func(err *nex.Error) { + globals.Logger.Errorf("Auth: %v", err) + }) + registerCommonAuthenticationServerProtocols() - globals.AuthenticationServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_MINECRAFT_AUTHENTICATION_SERVER_PORT"))) + port, _ := strconv.Atoi(os.Getenv("PN_MINECRAFT_AUTHENTICATION_SERVER_PORT")) + + globals.AuthenticationServer.Listen(port) } diff --git a/nex/mm.go b/nex/mm.go deleted file mode 100644 index 3793993..0000000 --- a/nex/mm.go +++ /dev/null @@ -1,38 +0,0 @@ -package nex - -import ( - "encoding/hex" - "fmt" - - nex "github.com/PretendoNetwork/nex-go" - matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - "github.com/PretendoNetwork/minecraft-wiiu/globals" -) - -func GetPlayingSession(err error, client *nex.Client, callID uint32, listPID []uint32) uint32 { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - rmcResponseStream.WriteUInt32LE(0) - - rmcResponseBody := rmcResponseStream.Bytes() - fmt.Println(hex.EncodeToString(rmcResponseBody)) - - rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) - rmcResponse.SetSuccess(matchmake_extension.MethodGetPlayingSession, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) - - return 0 -} \ No newline at end of file diff --git a/nex/ranking/get_ranking.go b/nex/ranking/get_ranking.go deleted file mode 100644 index 83c3930..0000000 --- a/nex/ranking/get_ranking.go +++ /dev/null @@ -1,65 +0,0 @@ -package nex_ranking - -import ( - "github.com/PretendoNetwork/nex-go" - ranking "github.com/PretendoNetwork/nex-protocols-go/ranking" - ranking_types "github.com/PretendoNetwork/nex-protocols-go/ranking/types" - "github.com/PretendoNetwork/minecraft-wiiu/database" - "github.com/PretendoNetwork/minecraft-wiiu/globals" -) - -func GetRanking(err error, client *nex.Client, callID uint32, rankingMode uint8, category uint32, orderParam *ranking_types.RankingOrderParam, uniqueID uint64, principalID uint32) { - rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID) - - if err != nil { - globals.Logger.Error(err.Error()) - rmcResponse.SetError(nex.Errors.Ranking.Unknown) - } - - rankDataListErr, rankDataList := database.GetRankingsByCategoryAndRankingOrderParam(category, orderParam) - if rankDataListErr != nil { - globals.Logger.Error(rankDataListErr.Error()) - rmcResponse.SetError(nex.Errors.Ranking.Unknown) - } - - totalCountErr, totalCount := database.GetTotalRankingsByCategory(category) - if totalCountErr != nil { - globals.Logger.Error(totalCountErr.Error()) - rmcResponse.SetError(nex.Errors.Ranking.Unknown) - } - - if totalCount == 0 || len(rankDataList) == 0 { - rmcResponse.SetError(nex.Errors.Ranking.NotFound) - } - - if rankDataListErr == nil && totalCountErr == nil && totalCount != 0 { - pResult := ranking_types.NewRankingResult() - - pResult.RankDataList = rankDataList - pResult.TotalCount = totalCount - pResult.SinceTime = nex.NewDateTime(0x1f40420000) // * 2000-01-01T00:00:00.000Z, this is what the real server sends back - - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - - rmcResponseStream.WriteStructure(pResult) - - rmcResponseBody := rmcResponseStream.Bytes() - - rmcResponse.SetSuccess(ranking.MethodGetRanking, rmcResponseBody) - } - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/ranking/upload_score.go b/nex/ranking/upload_score.go deleted file mode 100644 index f1dfc71..0000000 --- a/nex/ranking/upload_score.go +++ /dev/null @@ -1,41 +0,0 @@ -package nex_ranking - -import ( - "github.com/PretendoNetwork/nex-go" - ranking "github.com/PretendoNetwork/nex-protocols-go/ranking" - ranking_types "github.com/PretendoNetwork/nex-protocols-go/ranking/types" - "github.com/PretendoNetwork/minecraft-wiiu/database" - "github.com/PretendoNetwork/minecraft-wiiu/globals" -) - -func UploadScore(err error, client *nex.Client, callID uint32, scoreData *ranking_types.RankingScoreData, uniqueID uint64) { - rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID) - - if err != nil { - globals.Logger.Error(err.Error()) - rmcResponse.SetError(nex.Errors.Ranking.Unknown) - } - - insertErr := database.InsertRankingByPIDAndRankingScoreData(client.PID(), scoreData) - if insertErr != nil { - globals.Logger.Error(insertErr.Error()) - rmcResponse.SetError(nex.Errors.Ranking.Unknown) - } else { - rmcResponse.SetSuccess(ranking.MethodUploadScore, nil) - } - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/register_common_authentication_server_protocols.go b/nex/register_common_authentication_server_protocols.go index ca7ff01..3478933 100644 --- a/nex/register_common_authentication_server_protocols.go +++ b/nex/register_common_authentication_server_protocols.go @@ -1,31 +1,33 @@ package nex import ( + "github.com/PretendoNetwork/minecraft-wiiu/globals" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + commonticketgranting "github.com/PretendoNetwork/nex-protocols-common-go/v2/ticket-granting" + ticketgranting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" "os" "strconv" - - nex "github.com/PretendoNetwork/nex-go" - ticket_granting "github.com/PretendoNetwork/nex-protocols-common-go/ticket-granting" - "github.com/PretendoNetwork/minecraft-wiiu/globals" ) func registerCommonAuthenticationServerProtocols() { - ticketGrantingProtocol := ticket_granting.NewCommonTicketGrantingProtocol(globals.AuthenticationServer) + ticketGrantingProtocol := ticketgranting.NewProtocol() + globals.AuthenticationEndpoint.RegisterServiceProtocol(ticketGrantingProtocol) + commonTicketGrantingProtocol := commonticketgranting.NewCommonProtocol(ticketGrantingProtocol) port, _ := strconv.Atoi(os.Getenv("PN_MINECRAFT_SECURE_SERVER_PORT")) - secureStationURL := nex.NewStationURL("") - secureStationURL.SetScheme("prudps") + secureStationURL := types.NewStationURL("") + secureStationURL.SetURLType(constants.StationURLPRUDPS) secureStationURL.SetAddress(os.Getenv("PN_MINECRAFT_SECURE_SERVER_HOST")) - secureStationURL.SetPort(uint32(port)) - secureStationURL.SetCID(1) - secureStationURL.SetPID(2) - secureStationURL.SetSID(1) - secureStationURL.SetStream(10) - secureStationURL.SetType(2) - - ticketGrantingProtocol.SetSecureStationURL(secureStationURL) - //ticketGrantingProtocol.SetBuildName("branch:origin/project/ctr-egd build:3_10_22_2008_0") + secureStationURL.SetPortNumber(uint16(port)) + secureStationURL.SetConnectionID(1) + secureStationURL.SetPrincipalID(types.NewPID(2)) + secureStationURL.SetStreamID(1) + secureStationURL.SetStreamType(constants.StreamTypeRVSecure) + secureStationURL.SetType(uint8(constants.StationURLFlagPublic)) - globals.AuthenticationServer.SetPasswordFromPIDFunction(globals.PasswordFromPID) + commonTicketGrantingProtocol.SecureStationURL = secureStationURL + commonTicketGrantingProtocol.BuildName = types.NewString("branch:origin/release/ngs/3.10.x.200x build:3_10_22_2006_0") + commonTicketGrantingProtocol.SecureServerAccount = globals.SecureServerAccount } diff --git a/nex/register_common_secure_server_protocols.go b/nex/register_common_secure_server_protocols.go index 552e59d..cec9615 100644 --- a/nex/register_common_secure_server_protocols.go +++ b/nex/register_common_secure_server_protocols.go @@ -1,45 +1,57 @@ package nex import ( - secureconnection "github.com/PretendoNetwork/nex-protocols-common-go/secure-connection" - matchmaking "github.com/PretendoNetwork/nex-protocols-common-go/matchmaking" - matchmakingext "github.com/PretendoNetwork/nex-protocols-common-go/matchmaking-ext" - matchmakeextension "github.com/PretendoNetwork/nex-protocols-common-go/matchmake-extension" - nattraversal "github.com/PretendoNetwork/nex-protocols-common-go/nat-traversal" "github.com/PretendoNetwork/minecraft-wiiu/globals" - match_making_types "github.com/PretendoNetwork/nex-protocols-go/match-making/types" + "github.com/PretendoNetwork/nex-go/v2/types" + commonnattraversal "github.com/PretendoNetwork/nex-protocols-common-go/v2/nat-traversal" + commonsecure "github.com/PretendoNetwork/nex-protocols-common-go/v2/secure-connection" + nattraversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" + secure "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" - "fmt" -) - -func cleanupSearchMatchmakeSessionHandler(matchmakeSession *match_making_types.MatchmakeSession){ - //matchmakeSession.Attributes[2] = 0 - matchmakeSession.MatchmakeParam = match_making_types.NewMatchmakeParam() - matchmakeSession.ApplicationData = make([]byte, 0) - fmt.Println(matchmakeSession.String()) -} + commonmatchmaking "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making" + commonmatchmakingext "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making-ext" + commonmatchmakeextension "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension" + matchmaking "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + matchmakingext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext" + matchmakeextension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" -func cleanupMatchmakeSessionSearchCriteriaHandler(searchCriteria []*match_making_types.MatchmakeSessionSearchCriteria){ -} + matchmakingtypes "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) -func gameSpecificMatchmakeSessionSearchCriteriaChecksHandler(requestSearchCriteria, sessionSearchCriteria *match_making_types.MatchmakeSessionSearchCriteria) bool{ - return true; +// Is this needed? -Ash +func cleanupSearchMatchmakeSessionHandler(matchmakeSession *matchmakingtypes.MatchmakeSession) { + //_ = matchmakeSession.Attributes.SetIndex(2, types.NewPrimitiveU32(0)) + matchmakeSession.MatchmakeParam = matchmakingtypes.NewMatchmakeParam() + matchmakeSession.ApplicationBuffer = types.NewBuffer(make([]byte, 0)) + globals.Logger.Info(matchmakeSession.String()) } -func createReportDBRecordHandler(pid uint32, reportID uint32, reportData []byte) error { +func CreateReportDBRecord(_ *types.PID, _ *types.PrimitiveU32, _ *types.QBuffer) error { return nil } func registerCommonSecureServerProtocols() { - commonSecureconnectionProtocol := secureconnection.NewCommonSecureConnectionProtocol(globals.SecureServer) - commonSecureconnectionProtocol.CreateReportDBRecord(createReportDBRecordHandler) - matchmaking.NewCommonMatchMakingProtocol(globals.SecureServer) - matchmakingext.NewCommonMatchMakingExtProtocol(globals.SecureServer) - commonMatchmakeExtensionProtocol := matchmakeextension.NewCommonMatchmakeExtensionProtocol(globals.SecureServer) - commonMatchmakeExtensionProtocol.CleanupSearchMatchmakeSession(cleanupSearchMatchmakeSessionHandler) - commonMatchmakeExtensionProtocol.CleanupMatchmakeSessionSearchCriteria(cleanupMatchmakeSessionSearchCriteriaHandler) - commonMatchmakeExtensionProtocol.GameSpecificMatchmakeSessionSearchCriteriaChecks(gameSpecificMatchmakeSessionSearchCriteriaChecksHandler) - commonMatchmakeExtensionProtocol.DefaultProtocol.GetPlayingSession(GetPlayingSession) - //commonMatchmakeExtensionProtocol.DefaultProtocol.AutoMatchmakeWithParam_Postpone(autoMatchmakeWithParam_Postpone) - nattraversal.NewCommonNATTraversalProtocol(globals.SecureServer) + secureProtocol := secure.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(secureProtocol) + commonSecureProtocol := commonsecure.NewCommonProtocol(secureProtocol) + + commonSecureProtocol.CreateReportDBRecord = CreateReportDBRecord + + natTraversalProtocol := nattraversal.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(natTraversalProtocol) + commonnattraversal.NewCommonProtocol(natTraversalProtocol) + + matchMakingProtocol := matchmaking.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(matchMakingProtocol) + commonmatchmaking.NewCommonProtocol(matchMakingProtocol) + + matchMakingExtProtocol := matchmakingext.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(matchMakingExtProtocol) + commonmatchmakingext.NewCommonProtocol(matchMakingExtProtocol) + + matchmakeExtensionProtocol := matchmakeextension.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(matchmakeExtensionProtocol) + commonMatchmakeExtensionProtocol := commonmatchmakeextension.NewCommonProtocol(matchmakeExtensionProtocol) + + commonMatchmakeExtensionProtocol.CleanupSearchMatchmakeSession = cleanupSearchMatchmakeSessionHandler } diff --git a/nex/register_secure_server_nex_protocols.go b/nex/register_secure_server_nex_protocols.go deleted file mode 100644 index e85a51d..0000000 --- a/nex/register_secure_server_nex_protocols.go +++ /dev/null @@ -1,11 +0,0 @@ -package nex - -import ( - utility "github.com/PretendoNetwork/nex-protocols-go/utility" - "github.com/PretendoNetwork/minecraft-wiiu/globals" -) - -func registerSecureServerNEXProtocols() { - _ = utility.NewProtocol(globals.SecureServer) - -} diff --git a/nex/secure.go b/nex/secure.go index 41e9c6f..df26bf3 100644 --- a/nex/secure.go +++ b/nex/secure.go @@ -3,32 +3,44 @@ package nex import ( "fmt" "os" + "strconv" - nex "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/minecraft-wiiu/globals" + "github.com/PretendoNetwork/nex-go/v2" ) func StartSecureServer() { - globals.SecureServer = nex.NewServer() - globals.SecureServer.SetPRUDPVersion(1) - globals.SecureServer.SetPRUDPProtocolMinorVersion(3) - globals.SecureServer.SetDefaultNEXVersion(nex.NewNEXVersion(3,10,0)) - globals.SecureServer.SetKerberosPassword(globals.KerberosPassword) - globals.SecureServer.SetAccessKey("f1b61c8e") + globals.SecureServer = nex.NewPRUDPServer() + globals.SecureServer.ByteStreamSettings.UseStructureHeader = true + + globals.SecureEndpoint = nex.NewPRUDPEndPoint(1) + globals.SecureEndpoint.IsSecureEndPoint = true + globals.SecureEndpoint.ServerAccount = globals.SecureServerAccount + globals.SecureEndpoint.AccountDetailsByPID = globals.AccountDetailsByPID + globals.SecureEndpoint.AccountDetailsByUsername = globals.AccountDetailsByUsername + globals.SecureServer.BindPRUDPEndPoint(globals.SecureEndpoint) + + globals.SecureServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(3, 10, 0)) + globals.SecureServer.AccessKey = "f1b61c8e" globals.Timeline = make(map[uint32][]uint8) - globals.SecureServer.On("Data", func(packet *nex.PacketV1) { - request := packet.RMCRequest() + globals.SecureEndpoint.OnData(func(packet nex.PacketInterface) { + request := packet.RMCMessage() fmt.Println("==Minecraft: Wii U Edition - Secure==") - fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) - fmt.Printf("Method ID: %#v\n", request.MethodID()) + fmt.Printf("Protocol ID: %d\n", request.ProtocolID) + fmt.Printf("Method ID: %d\n", request.MethodID) fmt.Println("===============") }) + globals.SecureEndpoint.OnError(func(err *nex.Error) { + globals.Logger.Errorf("Secure: %v", err) + }) + registerCommonSecureServerProtocols() - registerSecureServerNEXProtocols() - globals.SecureServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_MINECRAFT_SECURE_SERVER_PORT"))) + port, _ := strconv.Atoi(os.Getenv("PN_MINECRAFT_SECURE_SERVER_PORT")) + + globals.SecureServer.Listen(port) } diff --git a/nex/subscription/create_my_subscription_data.go b/nex/subscription/create_my_subscription_data.go deleted file mode 100644 index 62ca17f..0000000 --- a/nex/subscription/create_my_subscription_data.go +++ /dev/null @@ -1,28 +0,0 @@ -package nex_subscription - -import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func CreateMySubscriptionData(err error, client *nex.Client, callID uint32, unk uint64, content []byte) { - globals.Timeline[client.PID()] = content - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodCreateMySubscriptionData, nil) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/subscription/get_active_player_subscription_data.go b/nex/subscription/get_active_player_subscription_data.go deleted file mode 100644 index ff86b33..0000000 --- a/nex/subscription/get_active_player_subscription_data.go +++ /dev/null @@ -1,41 +0,0 @@ -package nex_subscription - -import ( - "encoding/hex" - "fmt" - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func GetActivePlayerSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - - rmcResponseStream.WriteUInt32LE(uint32(len(globals.Timeline))) - for clientPID := range globals.Timeline { - for j := 0; j < len(globals.Timeline[clientPID]); j++ { - rmcResponseStream.WriteUInt8(globals.Timeline[clientPID][j]) - } - } - - rmcResponseBody := rmcResponseStream.Bytes() - fmt.Println(hex.EncodeToString(rmcResponseBody)) - - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodGetActivePlayerSubscriptionData, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/subscription/get_friend_subscription_data.go b/nex/subscription/get_friend_subscription_data.go deleted file mode 100644 index 3984bb5..0000000 --- a/nex/subscription/get_friend_subscription_data.go +++ /dev/null @@ -1,33 +0,0 @@ -package nex_subscription - -import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func GetFriendSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - - rmcResponseStream.WriteUInt32LE(0) - - rmcResponseBody := rmcResponseStream.Bytes() - - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodGetFriendSubscriptionData, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/subscription/get_privacy_levels.go b/nex/subscription/get_privacy_levels.go deleted file mode 100644 index 97f8dd0..0000000 --- a/nex/subscription/get_privacy_levels.go +++ /dev/null @@ -1,27 +0,0 @@ -package nex_subscription - -import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func GetPrivacyLevels(err error, client *nex.Client, callID uint32) { - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodGetPrivacyLevels, nil) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/subscription/get_subscription_data.go b/nex/subscription/get_subscription_data.go deleted file mode 100644 index 7097344..0000000 --- a/nex/subscription/get_subscription_data.go +++ /dev/null @@ -1,44 +0,0 @@ -package nex_subscription - -import ( - nex "github.com/PretendoNetwork/nex-go" - "encoding/hex" - "fmt" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func GetSubscriptionData(err error, client *nex.Client, callID uint32, pids []uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - - for _, pid := range pids { - fmt.Println(pid) - content := globals.Timeline[pid] - rmcResponseStream.WriteUInt32LE(1) - for i := 0; i < len(content); i++ { - rmcResponseStream.WriteUInt8(content[i]) - } - } - - rmcResponseBody := rmcResponseStream.Bytes() - _ = rmcResponseBody - fmt.Println(hex.EncodeToString(rmcResponseBody)) - - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodGetSubscriptionData, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/subscription/get_target_subscription_data.go b/nex/subscription/get_target_subscription_data.go deleted file mode 100644 index c2a514a..0000000 --- a/nex/subscription/get_target_subscription_data.go +++ /dev/null @@ -1,33 +0,0 @@ -package nex_subscription - -import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func GetTargetSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - - rmcResponseStream.WriteUInt32LE(0) - - rmcResponseBody := rmcResponseStream.Bytes() - - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodGetTargetSubscriptionData, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/subscription/replace_target_and_get_subscription_data.go b/nex/subscription/replace_target_and_get_subscription_data.go deleted file mode 100644 index 33248c6..0000000 --- a/nex/subscription/replace_target_and_get_subscription_data.go +++ /dev/null @@ -1,33 +0,0 @@ -package nex_subscription - -import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func ReplaceTargetAndGetSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - - rmcResponseStream.WriteUInt32LE(0) - - rmcResponseBody := rmcResponseStream.Bytes() - - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodReplaceTargetAndGetSubscriptionData, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/nex/subscription/update_my_subscription_data.go b/nex/subscription/update_my_subscription_data.go deleted file mode 100644 index acb6721..0000000 --- a/nex/subscription/update_my_subscription_data.go +++ /dev/null @@ -1,29 +0,0 @@ -package nex_subscription - -import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/minecraft-wiiu/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" -) - -func UpdateMySubscriptionData(err error, client *nex.Client, callID uint32, unk uint32, content []byte) { - globals.Timeline[client.PID()] = content - - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodUpdateMySubscriptionData, nil) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(responsePacket) -} diff --git a/types/pq_uint8_array.go b/types/pq_uint8_array.go deleted file mode 100644 index d296f69..0000000 --- a/types/pq_uint8_array.go +++ /dev/null @@ -1,39 +0,0 @@ -package types - -import ( - "fmt" - "strconv" - "strings" -) - -type PQUInt8Array struct { - Value []uint8 -} - -func (array *PQUInt8Array) Scan(src interface{}) error { - - switch src := src.(type) { - case []uint8: - // * Postgres stores uint8 slices as - // * a string in the format: - // * {1,2,3,4} - str := string(src) - str = strings.TrimSuffix(str, "}") - str = strings.TrimPrefix(str, "{") - strSlice := strings.Split(str, ",") - - for i := 0; i < len(strSlice); i++ { - number, err := strconv.Atoi(strSlice[i]) - - if err != nil { - return err - } - - array.Value = append(array.Value, uint8(number)) - } - - return nil - } - - return fmt.Errorf("Type %T does not have a path to convert to UInt8Array", src) -} From 9b9f3f503f821a9aa76333870dfdd07edb29fcfc Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Wed, 26 Jun 2024 13:32:51 +1000 Subject: [PATCH 2/2] feat!(secure): Disable public matchmaking by default Minecraft: Wii U Edition is the most exploitable game on the console. Add the option to restrict play to friend rooms only, mitigating this issue until a better solution can be found. --- README.md | 19 +++--- ...register_common_secure_server_protocols.go | 58 +++++++++++++++++++ 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index df77e96..5bf49c0 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,13 @@ All configuration options are handled via environment variables `.env` files are supported -| 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) | \ No newline at end of file +| 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) | \ No newline at end of file diff --git a/nex/register_common_secure_server_protocols.go b/nex/register_common_secure_server_protocols.go index cec9615..de53e30 100644 --- a/nex/register_common_secure_server_protocols.go +++ b/nex/register_common_secure_server_protocols.go @@ -2,11 +2,13 @@ package nex import ( "github.com/PretendoNetwork/minecraft-wiiu/globals" + "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/nex-go/v2/types" commonnattraversal "github.com/PretendoNetwork/nex-protocols-common-go/v2/nat-traversal" commonsecure "github.com/PretendoNetwork/nex-protocols-common-go/v2/secure-connection" nattraversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" secure "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" + "os" commonmatchmaking "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making" commonmatchmakingext "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making-ext" @@ -30,6 +32,43 @@ func CreateReportDBRecord(_ *types.PID, _ *types.PrimitiveU32, _ *types.QBuffer) return nil } +// * Minecraft WiiU edition isn't always safe to play on public matches. To mitigate this, just claim there are no +// * public matches. +func stubBrowseMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, _ *matchmakingtypes.MatchmakeSessionSearchCriteria, _ *types.ResultRange) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + lstGathering := types.NewList[*types.AnyDataHolder]() + lstGathering.Type = types.NewAnyDataHolder() + + // * Don't include any sessions! + //for _, session := range sessions { + // matchmakeSessionDataHolder := types.NewAnyDataHolder() + // matchmakeSessionDataHolder.TypeName = types.NewString("MatchmakeSession") + // matchmakeSessionDataHolder.ObjectData = session.GameMatchmakeSession.Copy() + // + // lstGathering.Append(matchmakeSessionDataHolder) + //} + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstGathering.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmakeextension.ProtocolID + rmcResponse.MethodID = matchmakeextension.MethodBrowseMatchmakeSession + rmcResponse.CallID = callID + + return rmcResponse, nil +} + func registerCommonSecureServerProtocols() { secureProtocol := secure.NewProtocol() globals.SecureEndpoint.RegisterServiceProtocol(secureProtocol) @@ -54,4 +93,23 @@ func registerCommonSecureServerProtocols() { commonMatchmakeExtensionProtocol := commonmatchmakeextension.NewCommonProtocol(matchmakeExtensionProtocol) commonMatchmakeExtensionProtocol.CleanupSearchMatchmakeSession = cleanupSearchMatchmakeSessionHandler + if os.Getenv("PN_MINECRAFT_ALLOW_PUBLIC_MATCHMAKING") != "1" { + globals.Logger.Warning("Public minigames are disabled for safety reasons.") + globals.Logger.Warning("To enable public matches, set PN_MINECRAFT_ALLOW_PUBLIC_MATCHMAKING=1.") + matchmakeExtensionProtocol.SetHandlerBrowseMatchmakeSession(stubBrowseMatchmakeSession) + + // * Make sure any unused MM protocols aren't able to show sessions + matchmakeExtensionProtocol.SetHandlerAutoMatchmakePostpone(nil) + matchmakeExtensionProtocol.SetHandlerAutoMatchmakeWithParamPostpone(nil) + matchmakeExtensionProtocol.SetHandlerAutoMatchmakeWithSearchCriteriaPostpone(nil) + matchMakingProtocol.SetHandlerFindByType(nil) + matchMakingProtocol.SetHandlerFindByDescription(nil) + matchMakingProtocol.SetHandlerFindByDescriptionRegex(nil) + matchMakingProtocol.SetHandlerFindByID(nil) + //matchMakingProtocol.SetHandlerFindBySingleID(nil) Used for friends matchmaking + matchMakingProtocol.SetHandlerFindByOwner(nil) + matchMakingProtocol.SetHandlerFindByParticipants(nil) + matchMakingProtocol.SetHandlerFindInvitations(nil) + matchMakingProtocol.SetHandlerFindBySQLQuery(nil) + } }