server/main.go
Stephen McQuay 56c965add7 some clean up
Mainly adding some comments, and some function renaming
2013-09-28 12:59:17 -07:00

50 lines
1014 B
Go

package main
import (
"code.google.com/p/go.net/websocket"
"flag"
"log"
"math/rand"
"net/http"
"sync"
"time"
)
var addr = flag.String("addr", ":8666", "http service address")
var tick = flag.Int("tick", 33, "")
var verbose = flag.Bool("verbose", false, "")
var width = flag.Float64("width", 800, "width of field")
var height = flag.Float64("height", 550, "height of field")
var delta float64
var idg *IdGenerator
type MapLock struct {
m map[string]*game
sync.RWMutex
}
// This is the main, global collection of games
var games MapLock
func main() {
rand.Seed(time.Now().UnixNano())
flag.Parse()
games = MapLock{m: make(map[string]*game)}
idg = NewIdGenerator()
delta = float64(*tick) / 1000
http.Handle("/ws/", websocket.Handler(addPlayer))
http.Handle("/game/start/", JsonHandler(startGame))
http.Handle("/game/list/", JsonHandler(listGames))
http.HandleFunc("/game/stop/", stopGame)
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("unable to start server")
}
}