diff --git a/bserv/main.go b/bserv/main.go index b8066a4..2b0fdc2 100644 --- a/bserv/main.go +++ b/bserv/main.go @@ -21,8 +21,6 @@ var netprofile = flag.Bool("netprof", false, "if specified will run with net/htt var verbose = flag.Bool("verbose", false, "") var config = flag.String("config", "~/.config/hackerbots/config.json", "location of config file") -var delta float32 - func main() { log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) log.Printf("Starting Server...") @@ -49,8 +47,6 @@ func main() { log.Fatal(err) } - delta = (float32(conf.Tick) / 1000.0) * float32(conf.Timescale) - sm := http.NewServeMux() c := botserv.Controller{ diff --git a/control.go b/control.go index 4f0280e..1b2794b 100644 --- a/control.go +++ b/control.go @@ -64,7 +64,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) { mode = cfg.Mode } - g := c.Games.get(requested_game_name) + g := c.Games.Get(requested_game_name) if g == nil { log.Printf("Game '%s' non-existant; making it now", requested_game_name) var err error @@ -76,7 +76,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) { return } go g.run() - c.Games.add(g) + c.Games.Add(g) } else { log.Printf("Game '%s' already exists: %p", requested_game_name, g) b, _ := json.Marshal(NewFailure("game already exists")) @@ -254,6 +254,7 @@ func (c *Controller) getGameId(path string) (string, error) { return key, err } +// MapLock is simply a map and a RWMutex type MapLock struct { M map[string]*Game sync.RWMutex @@ -262,14 +263,15 @@ type MapLock struct { // get is a function that returns a game if found, and creates one if // not found and force is true. In order to get a hash (rather than use // the string you pass) send "" for id. -func (ml *MapLock) get(id string) *Game { +func (ml *MapLock) Get(id string) *Game { ml.Lock() g, _ := ml.M[id] ml.Unlock() return g } -func (ml *MapLock) add(g *Game) { +// add is used to insert a new game into this MapLock +func (ml *MapLock) Add(g *Game) { ml.Lock() ml.M[g.id] = g ml.Unlock() diff --git a/protocol.go b/protocol.go index 61cf014..62cfdd9 100644 --- a/protocol.go +++ b/protocol.go @@ -151,7 +151,7 @@ func (c *Controller) AddPlayer(ws *websocket.Conn) { return } - game := c.Games.get(gid.Id) + game := c.Games.Get(gid.Id) if game == nil { var err error game, err = NewGame( @@ -169,7 +169,7 @@ func (c *Controller) AddPlayer(ws *websocket.Conn) { return } go game.run() - c.Games.add(game) + c.Games.Add(game) } player_id := c.Idg.Hash()