Esempio n. 1
0
func startBeacon() {
	for _, server := range allServers {
		handler.SetStatus(server.Hostnames, &(server.PingStatus))
		handler.Handle(server.Hostnames, server.ResponseHandler)
	}

	log.Fatal(handler.Listen("25565"))
}
Esempio n. 2
0
func (s *Server) setStateRaw(st state) {
	if s.State == stateStarted || s.State == stateOff {
		handler.Handle(s.Hostnames, s.ResponseHandler)
	}

	switch st {
	case stateInitializing:
		s.ConnectMessage = "Sorry, the server is not ready take requests " +
			"yet!\nTry connecting again in a few seconds."
		s.PingStatus.Message = chat.Format(s.Messages.ServerInfoPrefix) +
			chat.Yellow + "Initializing..."
		s.PingStatus.ShowConnection = false
	case stateShutdown, stateSnapshot, stateDestroy:
		s.ConnectMessage = "Sorry, the server is currently shutting down.\n" +
			"You may start it again when it is completely powered off."
		s.PingStatus.Message = chat.Format(s.Messages.ServerInfoPrefix) +
			chat.Yellow + "Shutting down..."
		s.PingStatus.ShowConnection = false
	case stateOff:
		handler.Handle(s.Hostnames, s.StartServerHandler)
		s.PingStatus.Message = chat.Format(s.Messages.ServerInfoPrefix) +
			chat.Gold + "Powered off. Connect to start."
		s.PingStatus.ShowConnection = true
	case stateStarting:
		s.ConnectMessage = "Sorry, the server is still starting up.\n" +
			"Try connecting again in a few minutes."
		s.PingStatus.Message = chat.Format(s.Messages.ServerInfoPrefix) +
			chat.LightGreen + "Starting up..."
		s.PingStatus.ShowConnection = false
	case stateUnavailable:
		s.ConnectMessage = "The server isn't available right now.\n" +
			"Contact " + s.Messages.Owner + " for help."
		s.PingStatus.Message = chat.Format(s.Messages.ServerInfoPrefix) +
			chat.Red + "Unavailable."
		s.PingStatus.ShowConnection = false
	case stateStarted:
		s.LastConnectionTime = time.Now()
		handler.Forward(s.Hostnames, s.IPAddress+":25565")
	}

	s.State = st
}
Esempio n. 3
0
func liveLoadConfig() {
	time.Sleep(time.Second * 3)
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		Log("config", "Could not resolve filepath:", err)
		return
	}

	data, err := ioutil.ReadFile(dir + "/config.json")
	if err != nil {
		Log("config", "Failed to read configuration:", err)
		return
	}

	var newConfig Config
	err = json.Unmarshal(data, &newConfig)
	if err != nil {
		Log("config", "Failed to decode configuration:", err)
		return
	}

	if len(newConfig.Servers) != len(allServers) {
		Log("config", "Number of servers have changed. "+
			"You must restart the reverse proxy for changes to take place.")
		return
	}

	if newConfig.APIToken != globalConfig.APIToken {
		Log("config", "The API key has changed. You must restart "+
			"the server to use the new API key.")
	}

	if newConfig.CommunicationsPort != globalConfig.CommunicationsPort {
		Log("config", "The communications port has changed. You must restart "+
			"the server to use the new communications port.")
	}

	for i, newServer := range newConfig.Servers {
		currentServer := allServers[i]

		if currentServer.Name != newServer.Name {
			Log("config", "The servers have been reordered or renamed."+
				"You must restart the reverse proxy for changes to take place.")
			continue
		}

		currentServer.Messages = newServer.Messages
		currentServer.Whitelist = newServer.Whitelist
		currentServer.Hostnames = newServer.Hostnames
		currentServer.MaxPlayers = newServer.MaxPlayers
		currentServer.ProtocolNumber = newServer.ProtocolNumber
		currentServer.Droplet = newServer.Droplet
		currentServer.AutoShutdownMinutes = newServer.AutoShutdownMinutes

		currentServer.PingStatus.MaxPlayers = currentServer.MaxPlayers
		currentServer.PingStatus.ProtocolNumber = currentServer.ProtocolNumber

		if newServer.Available {
			currentServer.Available = true
			currentServer.setStateRaw(currentServer.State)

			if currentServer.State != stateStarted &&
				currentServer.State != stateOff {
				handler.Handle(currentServer.Hostnames,
					currentServer.ResponseHandler)
			}
		} else {
			currentServer.Available = false
			currentServer.SetState(stateUnavailable)
		}
	}

	Log("config", "Reloaded configuration.")
}