Stephen McQuay
6fd4138740
unfortunately there is an issue with how these are calculated, and they don't decrease as things quiet down. Well, the bad numbers are their for your consumption, and should Just Work TM when appropriate changes in bitbucket.org/smcquay/bandwith land. And they will. But I'm tired now.
76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"math/rand"
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
"os"
|
|
"runtime/pprof"
|
|
"time"
|
|
|
|
"code.google.com/p/go.net/websocket"
|
|
)
|
|
|
|
var addr = flag.String("addr", ":8666", "http service address")
|
|
var profile = flag.String("pprof", "", "if specified will run with pprof")
|
|
var netprofile = flag.Bool("netprof", false, "if specified will run with net/http/pprof")
|
|
var verbose = flag.Bool("verbose", false, "")
|
|
var config = flag.String("config", "~/.config/hackerbots/config.json", "location of config file")
|
|
|
|
var delta float32
|
|
|
|
var idg *IdGenerator
|
|
var conf Config
|
|
|
|
// This is the main, global collection of games
|
|
var games MapLock
|
|
|
|
func main() {
|
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
log.Printf("Starting Server...")
|
|
var err error
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
flag.Parse()
|
|
if *profile != "" {
|
|
f, err := os.Create(*profile)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
pprof.StartCPUProfile(f)
|
|
}
|
|
if *netprofile {
|
|
go func() {
|
|
log.Println(http.ListenAndServe("localhost:8667", nil))
|
|
}()
|
|
}
|
|
|
|
games = MapLock{m: make(map[string]*game)}
|
|
idg = NewIdGenerator()
|
|
|
|
conf, err = loadConfig(*config)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
delta = (float32(conf.Tick) / 1000.0) * float32(conf.Timescale)
|
|
|
|
sm := http.NewServeMux()
|
|
|
|
sm.Handle("/", JsonHandler(index))
|
|
sm.Handle("/ws/", websocket.Handler(addPlayer))
|
|
sm.Handle("/game/start/", JsonHandler(startGame))
|
|
sm.Handle("/game/list/", JsonHandler(listGames))
|
|
sm.Handle("/game/stats/", JsonHandler(gameStats))
|
|
sm.Handle("/game/bw/", JsonHandler(bw))
|
|
sm.Handle("/game/stop/", JsonHandler(stopGame))
|
|
sm.HandleFunc("/fuck/shit/up/", killServer)
|
|
|
|
err = http.ListenAndServe(*addr, sm)
|
|
if err != nil {
|
|
log.Fatal("unable to start server")
|
|
}
|
|
}
|