Example #1
0
// Start initalizes all scoreboard subsystems and starts up a webserver on port
func Start(port uint16) {
	l := openLog()
	if l != nil {
		defer l.Close()
	}
	mux := http.NewServeMux()
	var savers []*statemanager.Saver

	// Initialize statemanager and load Settings.*
	statemanager.Initialize()
	savers = append(savers, initSettings("config/settings"))

	// Initialize leagues and load Leagues.*
	leagues.Initialize()
	savers = append(savers, statemanager.NewSaver("config/leagues", "Leagues", time.Duration(5)*time.Second, true, true))

	// Initialize scoreboard and load Scoreboard.*
	statemanager.Lock()
	scoreboard.New()
	statemanager.Unlock()
	savers = append(savers, statemanager.NewSaver("config/scoreboard", "Scoreboard", time.Duration(5)*time.Second, true, true))

	// Initialize websocket interface
	websocket.Initialize(mux)

	addFileWatcher("TeamLogos", "html", "/images/teamlogo")
	addFileWatcher("Sponsors", "html", "/images/sponsor_banner")
	addFileWatcher("Image", "html", "/images/fullscreen")
	addFileWatcher("Video", "html", "/videos")
	addFileWatcher("CustomHtml", "html", "/customhtml")

	printStartup(port)
	mux.Handle("/", http.FileServer(http.Dir(filepath.Join(statemanager.BaseFilePath(), "html"))))

	c := make(chan os.Signal, 1)
	go func() {
		err := http.ListenAndServe(fmt.Sprintf(":%d", port), setDefaultHeaders(mux))
		if err != nil {
			log.Print(err)
		}
		c <- os.Kill
	}()

	mux.Handle("/version", http.HandlerFunc(versionHandler))
	mux.Handle("/urls", http.HandlerFunc(urlsHandler))

	signal.Notify(c, os.Interrupt, os.Kill)
	s := <-c
	log.Printf("Server received signal: %v.  Shutting down", s)

	for _, saver := range savers {
		saver.Close()
	}
}
Example #2
0
// setup default settings
func initSettings(saveFile string) *statemanager.Saver {
	defaults := []struct{ name, value string }{
		{"BackgroundStyle", "bg_blacktowhite"},
		{"BoxStyle", "box_flat"},
		{"CurrentView", "scoreboard"},
		{"HideJamTotals", "false"},
		{"SwapTeams", "false"},
		{"Image", "/images/fullscreen/American Flag.jpg"},
		{"Video", "/videos/American Flag.webm"},
		{"CustomHtml", "/customhtml/example"},
	}
	views := []string{"View", "Preview"}
	statemanager.Lock()
	for _, v := range views {
		for _, d := range defaults {
			statemanager.StateUpdateString(fmt.Sprintf("Settings.%v.%v", v, d.name), d.value)
		}
	}
	statemanager.RegisterPatternUpdaterString("Settings", 0, setSettings)
	statemanager.Unlock()
	return statemanager.NewSaver(saveFile, "Settings", time.Duration(5)*time.Second, true, true)
}