From b76494e5a520782c5f63283ef04ce1823f364043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Tue, 29 Aug 2023 16:10:46 +0100 Subject: [PATCH] Add more error handling --- ...store_prepare_post_param_with_owner_pid.go | 7 +++---- globals/globals.go | 2 +- go.mod | 10 +++++----- go.sum | 20 +++++++++---------- nex/authentication.go | 4 ++-- nex/datastore/post_meta_binary.go | 6 +++++- ..._common_authentication_server_protocols.go | 15 ++++++++------ nex/secure.go | 4 ++-- 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/database/insert_meta_binary_by_datastore_prepare_post_param_with_owner_pid.go b/database/insert_meta_binary_by_datastore_prepare_post_param_with_owner_pid.go index 09a79f4..fef6bac 100644 --- a/database/insert_meta_binary_by_datastore_prepare_post_param_with_owner_pid.go +++ b/database/insert_meta_binary_by_datastore_prepare_post_param_with_owner_pid.go @@ -4,11 +4,10 @@ import ( "time" datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types" - "github.com/PretendoNetwork/team-kirby-clash-deluxe/globals" "github.com/lib/pq" ) -func InsertMetaBinaryByDataStorePreparePostParamWithOwnerPID(dataStorePreparePostParam *datastore_types.DataStorePreparePostParam, pid uint32) uint32 { +func InsertMetaBinaryByDataStorePreparePostParamWithOwnerPID(dataStorePreparePostParam *datastore_types.DataStorePreparePostParam, pid uint32) (uint32, error) { var dataID uint32 now := time.Now().Unix() @@ -50,8 +49,8 @@ func InsertMetaBinaryByDataStorePreparePostParamWithOwnerPID(dataStorePreparePos expireTime, ).Scan(&dataID) if err != nil { - globals.Logger.Critical(err.Error()) + return 0, err } - return dataID + return dataID, nil } diff --git a/globals/globals.go b/globals/globals.go index f880d5f..61546bd 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -8,7 +8,7 @@ import ( "google.golang.org/grpc/metadata" ) -var Logger = plogger.NewLogger() +var Logger *plogger.Logger var KerberosPassword = "password" // * Default password var AuthenticationServer *nex.Server var SecureServer *nex.Server diff --git a/go.mod b/go.mod index 145a980..26a5593 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.19 require ( github.com/PretendoNetwork/grpc-go v1.0.2 - github.com/PretendoNetwork/nex-go v1.0.35 - github.com/PretendoNetwork/nex-protocols-common-go v1.0.25 - github.com/PretendoNetwork/nex-protocols-go v1.0.49 + github.com/PretendoNetwork/nex-go v1.0.36 + github.com/PretendoNetwork/nex-protocols-common-go v1.0.26 + github.com/PretendoNetwork/nex-protocols-go v1.0.50 github.com/PretendoNetwork/plogger-go v1.0.4 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.9 @@ -20,11 +20,11 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/superwhiskers/crunch/v3 v3.5.7 // indirect - golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect + golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/term v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index 8021b75..bff54cf 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,11 @@ 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.35 h1:2oZxb4YUlMgFcT2tSRETrjsrS/9Wxf3BVr45+bMvjRM= -github.com/PretendoNetwork/nex-go v1.0.35/go.mod h1:v3dYsytdk7VvZOqplKwVqQOPa9heaq2V4DOAzCwyYNE= -github.com/PretendoNetwork/nex-protocols-common-go v1.0.25 h1:mMvmzrqwwBk6iFq8mCd8jn0XcxwFrhSc3jFITpprsZs= -github.com/PretendoNetwork/nex-protocols-common-go v1.0.25/go.mod h1:yLskCITByVXqxxuBd7389wW1xOhzSw4nmPNpA86CHzk= -github.com/PretendoNetwork/nex-protocols-go v1.0.49 h1:CIAjb9H11uTLj4JT2/4eedX1NsnQbBEFAJsSSEE2zR8= -github.com/PretendoNetwork/nex-protocols-go v1.0.49/go.mod h1:ztsrVFHaJc5MDBpL1rv4PgriLsTjl3R8u5XVxJHUzCk= +github.com/PretendoNetwork/nex-go v1.0.36 h1:eOJM80ytFZgMwyq63pxjfjZrFdtaIJXbM1B2ESvvKhE= +github.com/PretendoNetwork/nex-go v1.0.36/go.mod h1:v3dYsytdk7VvZOqplKwVqQOPa9heaq2V4DOAzCwyYNE= +github.com/PretendoNetwork/nex-protocols-common-go v1.0.26 h1:lddBn6khciXt4rEnRhrwzX9vtc0GvNQ8JLfxzMwTUKo= +github.com/PretendoNetwork/nex-protocols-common-go v1.0.26/go.mod h1:wrA+ueFqXMBxfF8p25Q72kPuopDbdjw/MvtnOqvWICY= +github.com/PretendoNetwork/nex-protocols-go v1.0.50 h1:ZTAXWjCw5rAsQgWtHp6qklRcmVd/y6KRdBYmR3hS/Xw= +github.com/PretendoNetwork/nex-protocols-go v1.0.50/go.mod h1:ztsrVFHaJc5MDBpL1rv4PgriLsTjl3R8u5XVxJHUzCk= 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= @@ -28,8 +28,8 @@ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APP github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 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-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U= -golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -44,8 +44,8 @@ golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.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-20230807174057-1744710a1577 h1:wukfNtZmZUurLN/atp2hiIeTKn7QJWIQdHzqmsOnAOk= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/nex/authentication.go b/nex/authentication.go index 1e3d7e6..177307a 100644 --- a/nex/authentication.go +++ b/nex/authentication.go @@ -25,10 +25,10 @@ func StartAuthenticationServer() { globals.AuthenticationServer.On("Data", func(packet *nex.PacketV1) { request := packet.RMCRequest() - fmt.Println("==TKCD - Auth==") + fmt.Println("=== TKCD - Auth ===") fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) fmt.Printf("Method ID: %#v\n", request.MethodID()) - fmt.Println("===============") + fmt.Println("===================") }) registerCommonAuthenticationServerProtocols() diff --git a/nex/datastore/post_meta_binary.go b/nex/datastore/post_meta_binary.go index 262ab22..8665de0 100644 --- a/nex/datastore/post_meta_binary.go +++ b/nex/datastore/post_meta_binary.go @@ -27,7 +27,11 @@ func PostMetaBinary(err error, client *nex.Client, callID uint32, param *datasto } } - dataID := database.InsertMetaBinaryByDataStorePreparePostParamWithOwnerPID(param, client.PID()) + dataID, err := database.InsertMetaBinaryByDataStorePreparePostParamWithOwnerPID(param, client.PID()) + if err != nil { + globals.Logger.Critical(err.Error()) + return nex.Errors.DataStore.Unknown + } rmcResponseStream := nex.NewStreamOut(globals.SecureServer) diff --git a/nex/register_common_authentication_server_protocols.go b/nex/register_common_authentication_server_protocols.go index 86ae75c..2fc2f34 100644 --- a/nex/register_common_authentication_server_protocols.go +++ b/nex/register_common_authentication_server_protocols.go @@ -2,6 +2,7 @@ package nex import ( "os" + "strconv" nex "github.com/PretendoNetwork/nex-go" ticket_granting "github.com/PretendoNetwork/nex-protocols-common-go/ticket-granting" @@ -11,15 +12,17 @@ import ( func registerCommonAuthenticationServerProtocols() { ticketGrantingProtocol := ticket_granting.NewCommonTicketGrantingProtocol(globals.AuthenticationServer) + port, _ := strconv.Atoi(os.Getenv("PN_TKCD_SECURE_SERVER_PORT")) + secureStationURL := nex.NewStationURL("") secureStationURL.SetScheme("prudps") secureStationURL.SetAddress(os.Getenv("PN_TKCD_SECURE_SERVER_HOST")) - secureStationURL.SetPort(os.Getenv("PN_TKCD_SECURE_SERVER_PORT")) - secureStationURL.SetCID("1") - secureStationURL.SetPID("2") - secureStationURL.SetSID("1") - secureStationURL.SetStream("10") - secureStationURL.SetType("2") + secureStationURL.SetPort(uint32(port)) + secureStationURL.SetCID(1) + secureStationURL.SetPID(2) + secureStationURL.SetSID(1) + secureStationURL.SetStream(10) + secureStationURL.SetType(2) ticketGrantingProtocol.SetSecureStationURL(secureStationURL) ticketGrantingProtocol.SetBuildName(serverBuildString) diff --git a/nex/secure.go b/nex/secure.go index ea16831..29901b6 100644 --- a/nex/secure.go +++ b/nex/secure.go @@ -24,10 +24,10 @@ func StartSecureServer() { globals.SecureServer.On("Data", func(packet *nex.PacketV1) { request := packet.RMCRequest() - fmt.Println("== TKCD - Secure ==") + fmt.Println("=== TKCD - Secure ===") fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) fmt.Printf("Method ID: %#v\n", request.MethodID()) - fmt.Println("======================") + fmt.Println("=====================") }) registerCommonSecureServerProtocols()