friends/nex/authentication.go
Daniel López Guimaraes 120776e197
fix: Better initialization of NEX server accounts
Initializing the server accounts in their own thread (e.g. the
authentication and secure servers) can cause a race condition where the
secure account hasn't been set up yet when authentication configures
`ticket-granting`, causing sometimes crashes on startup.

This has happened on production causing unnecesary restarts. To fix
this, initialize the accounts on the `init` function to ensure they will
always be accessible when needed.
2024-10-29 23:01:59 +00:00

31 lines
1.1 KiB
Go

package nex
import (
"os"
"strconv"
"github.com/PretendoNetwork/friends/globals"
"github.com/PretendoNetwork/nex-go/v2"
)
var serverBuildString string
func StartAuthenticationServer() {
port, _ := strconv.Atoi(os.Getenv("PN_FRIENDS_AUTHENTICATION_SERVER_PORT"))
globals.AuthenticationServer = nex.NewPRUDPServer()
globals.AuthenticationEndpoint = nex.NewPRUDPEndPoint(1)
globals.AuthenticationEndpoint.ServerAccount = globals.AuthenticationServerAccount
globals.AuthenticationEndpoint.AccountDetailsByPID = globals.AccountDetailsByPID
globals.AuthenticationEndpoint.AccountDetailsByUsername = globals.AccountDetailsByUsername
registerCommonAuthenticationServerProtocols()
globals.AuthenticationServer.SetFragmentSize(962)
globals.AuthenticationServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(1, 1, 0))
globals.AuthenticationServer.SessionKeyLength = 16
globals.AuthenticationServer.AccessKey = "ridfebb9"
globals.AuthenticationServer.BindPRUDPEndPoint(globals.AuthenticationEndpoint)
globals.AuthenticationServer.Listen(port)
}