Files
cheesy-arena-lite/main.go

46 lines
951 B
Go
Raw Normal View History

2014-05-24 00:39:22 -07:00
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
package main
import (
"log"
2014-05-25 17:21:42 -07:00
"math/rand"
"time"
2014-05-24 00:39:22 -07:00
)
2014-06-07 02:02:12 -07:00
const eventDbPath = "./event.db"
var db *Database
2014-06-06 21:26:55 -07:00
var eventSettings *EventSettings
// Main entry point for the application.
2014-05-24 00:39:22 -07:00
func main() {
2014-05-25 17:21:42 -07:00
rand.Seed(time.Now().UnixNano())
2014-06-07 02:02:12 -07:00
initDb()
// Run the webserver and DS packet listener in goroutines and use the main one for the arena state machine.
2014-07-04 16:55:29 -07:00
go ServeWebInterface()
go ListenForDriverStations()
2016-08-28 20:17:34 -07:00
go ListenForDsUdpPackets()
2015-06-20 23:54:14 -07:00
go MonitorBandwidth()
2014-07-04 16:55:29 -07:00
mainArena.Setup()
mainArena.Run()
2014-06-07 02:02:12 -07:00
}
// Opens the database and stores a handle to it in a global variable.
2014-06-07 02:02:12 -07:00
func initDb() {
2014-06-06 21:26:55 -07:00
var err error
2014-06-07 02:02:12 -07:00
db, err = OpenDatabase(eventDbPath)
2014-06-06 21:26:55 -07:00
checkErr(err)
eventSettings, err = db.GetEventSettings()
checkErr(err)
2014-05-24 00:39:22 -07:00
}
// Logs and exits the application if the given error is not nil.
2014-05-24 00:39:22 -07:00
func checkErr(err error) {
if err != nil {
log.Fatalln("Error: ", err)
}
}