diff --git a/main.go b/main.go index e1b661d..c010e93 100644 --- a/main.go +++ b/main.go @@ -9,10 +9,11 @@ import ( var wg sync.WaitGroup func main() { - wg.Add(1) + wg.Add(2) // TODO - Add gRPC server - go nex.StartNEXServer() + go nex.StartAuthenticationServer() + go nex.StartSecureServer() wg.Wait() } diff --git a/nex/authentication.go b/nex/authentication.go new file mode 100644 index 0000000..10d913f --- /dev/null +++ b/nex/authentication.go @@ -0,0 +1,35 @@ +package nex + +import ( + "fmt" + "os" + + nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/super-mario-maker-secure/globals" +) + +var serverBuildString string + +func StartAuthenticationServer() { + globals.AuthenticationServer = nex.NewServer() + globals.AuthenticationServer.SetPRUDPVersion(1) + globals.AuthenticationServer.SetPRUDPProtocolMinorVersion(2) + globals.AuthenticationServer.SetDefaultNEXVersion(nex.NewNEXVersion(3, 8, 3)) + globals.AuthenticationServer.SetKerberosPassword(globals.KerberosPassword) + globals.AuthenticationServer.SetAccessKey("9f2b4678") + + globals.AuthenticationServer.On("Data", func(packet *nex.PacketV1) { + request := packet.RMCRequest() + + fmt.Println("==SMM1 - Auth==") + fmt.Printf("Protocol ID: %d\n", request.ProtocolID()) + fmt.Printf("Method ID: %d\n", request.MethodID()) + fmt.Println("===============") + }) + + serverBuildString = "build:3_8_29_3022_0" + + registerCommonAuthenticationServerProtocols() + + globals.AuthenticationServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_SMM_AUTHENTICATION_SERVER_PORT"))) +} diff --git a/nex/register_common_authentication_server_protocols.go b/nex/register_common_authentication_server_protocols.go new file mode 100755 index 0000000..709d025 --- /dev/null +++ b/nex/register_common_authentication_server_protocols.go @@ -0,0 +1,30 @@ +package nex + +import ( + "os" + "strconv" + + nex "github.com/PretendoNetwork/nex-go" + ticket_granting "github.com/PretendoNetwork/nex-protocols-common-go/ticket-granting" + "github.com/PretendoNetwork/super-mario-maker-secure/globals" +) + +func registerCommonAuthenticationServerProtocols() { + ticketGrantingProtocol := ticket_granting.NewCommonTicketGrantingProtocol(globals.AuthenticationServer) + + secureStationURL := nex.NewStationURL("") + secureStationURL.SetScheme("prudps") + secureStationURL.SetAddress(os.Getenv("PN_SMM_SECURE_SERVER_HOST")) + port, _ := strconv.ParseUint(os.Getenv("PN_SMM_SECURE_SERVER_PORT"), 10, 32) + 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) + + globals.AuthenticationServer.SetPasswordFromPIDFunction(globals.PasswordFromPID) +} diff --git a/nex/register_common_protocols.go b/nex/register_common_secure_server_protocols.go similarity index 61% rename from nex/register_common_protocols.go rename to nex/register_common_secure_server_protocols.go index 7e36a43..1f78067 100644 --- a/nex/register_common_protocols.go +++ b/nex/register_common_secure_server_protocols.go @@ -5,6 +5,6 @@ import ( "github.com/PretendoNetwork/super-mario-maker-secure/globals" ) -func registerCommonProtocols() { - secureconnection.NewCommonSecureConnectionProtocol(globals.NEXServer) +func registerCommonSecureProtocols() { + secureconnection.NewCommonSecureConnectionProtocol(globals.SecureServer) } diff --git a/nex/secure.go b/nex/secure.go new file mode 100644 index 0000000..9ffd66d --- /dev/null +++ b/nex/secure.go @@ -0,0 +1,33 @@ +package nex + +import ( + "fmt" + "os" + + "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/super-mario-maker-secure/globals" +) + +func StartSecureServer() { + globals.SecureServer = nex.NewServer() + globals.SecureServer.SetPRUDPVersion(1) + globals.SecureServer.SetPRUDPProtocolMinorVersion(2) + globals.SecureServer.SetDefaultNEXVersion(nex.NewNEXVersion(3, 8, 3)) + globals.SecureServer.SetKerberosPassword(globals.KerberosPassword) + globals.SecureServer.SetAccessKey("9f2b4678") + + globals.SecureServer.On("Data", func(packet *nex.PacketV1) { + request := packet.RMCRequest() + + fmt.Println("==SMM1 - Secure==") + fmt.Printf("Protocol ID: %d\n", request.ProtocolID()) + fmt.Printf("Method ID: %d\n", request.MethodID()) + fmt.Println("===============") + }) + + // * Register the common handlers first so that they can be overridden if needed + registerCommonSecureProtocols() + registerNEXProtocols() + + globals.SecureServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_SMM_SECURE_SERVER_PORT"))) +} diff --git a/nex/server.go b/nex/server.go deleted file mode 100644 index 18ded65..0000000 --- a/nex/server.go +++ /dev/null @@ -1,33 +0,0 @@ -package nex - -import ( - "fmt" - "os" - - "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/super-mario-maker-secure/globals" -) - -func StartNEXServer() { - globals.NEXServer = nex.NewServer() - globals.NEXServer.SetPRUDPVersion(1) - globals.NEXServer.SetPRUDPProtocolMinorVersion(2) - globals.NEXServer.SetDefaultNEXVersion(nex.NewNEXVersion(3, 8, 3)) - globals.NEXServer.SetKerberosPassword(os.Getenv("KERBEROS_PASSWORD")) - globals.NEXServer.SetAccessKey("9f2b4678") - - globals.NEXServer.On("Data", func(packet *nex.PacketV1) { - request := packet.RMCRequest() - - fmt.Println("==SMM1 - Secure==") - fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) - fmt.Printf("Method ID: %#v\n", request.MethodID()) - fmt.Println("===============") - }) - - // * Register the common handlers first so that they can be overridden if needed - registerCommonProtocols() - registerNEXProtocols() - - globals.NEXServer.Listen(":60003") -}