server/main.go

44 lines
928 B
Go
Raw Normal View History

2013-08-19 20:43:26 -07:00
package main
import (
"code.google.com/p/go.net/websocket"
"flag"
"log"
"math/rand"
"net/http"
2013-09-01 22:04:10 -07:00
"sync"
2013-08-19 20:43:26 -07:00
"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
2013-08-28 23:46:12 -07:00
var games map[string]*game
var idg *IdGenerator
2013-09-01 22:04:10 -07:00
var gameLock sync.RWMutex
2013-08-28 23:46:12 -07:00
2013-08-19 20:43:26 -07:00
func main() {
rand.Seed(time.Now().UnixNano())
flag.Parse()
2013-08-28 23:46:12 -07:00
games = make(map[string]*game)
idg = NewIdGenerator()
2013-08-19 20:43:26 -07:00
delta = float64(*tick) / 1000
http.Handle("/ws/", websocket.Handler(addPlayer))
2013-08-28 23:46:12 -07:00
http.Handle("/game/start/", JsonHandler(startGame))
2013-09-01 22:04:10 -07:00
http.Handle("/game/list/", JsonHandler(listGames))
2013-08-28 23:46:12 -07:00
// http.Handle("/game/stop/", stopGame)
2013-08-19 20:43:26 -07:00
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("unable to start server")
}
}