func NewServer(motd *string, maxPlayers *uint16, authenticate *bool, router Router, localizer Localizer, connect *connect.ProxyConnect) (server *Server, err error) { privateKey, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { return } server = &Server{ sessionRegistry: NewSessionRegistry(), motd: motd, maxPlayers: maxPlayers, authenticate: authenticate, router: router, localizer: localizer, connect: connect, privateKey: privateKey, } connect.OnRedirect(func(serverName string, player string) { session := server.SessionRegistry().GetByName(player) if session == nil { return } server := connect.Server(serverName) if server == nil { return } session.Redirect(server) }) return }
func NewServer(motd *string, maxPlayers *uint16, syncMaxPlayers *bool, authenticate *bool, router Router, localizer Localizer, connect *connect.ProxyConnect) (this *Server, err error) { this = new(Server) this.SessionRegistry = NewSessionRegistry() this.motd = motd this.maxPlayers = maxPlayers this.syncMaxPlayers = syncMaxPlayers this.authenticate = authenticate this.router = router this.localizer = localizer this.connect = connect this.privateKey, err = rsa.GenerateKey(cryptoRand.Reader, 2048) if err != nil { return } this.publicKey, err = x509.MarshalPKIXPublicKey(&this.privateKey.PublicKey) if err != nil { return } connect.OnRedirect(func(serverName string, player string) { session := this.SessionRegistry.GetByName(player) if session == nil { return } server := connect.Server(serverName) if server == nil { return } session.Redirect(server) }) return }