bugfix for incorrect logic in game creation

This commit is contained in:
sm
2013-10-18 23:56:06 -07:00
parent c80acb478b
commit c074397c1f
3 changed files with 18 additions and 9 deletions
+9 -4
View File
@@ -44,7 +44,10 @@ type MapLock struct {
sync.RWMutex
}
func (ml *MapLock) getOrCreate(id string) (*game, error) {
// 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, force bool) (*game, error) {
ml.Lock()
g, ok := games.m[id]
ml.Unlock()
@@ -53,17 +56,19 @@ func (ml *MapLock) getOrCreate(id string) (*game, error) {
return g, nil
}
if !*debug {
if !force {
return nil, errors.New("game not found")
}
new_game_name := idg.Hash()
if id == "" {
id = idg.Hash()
}
_g := NewGame(id, *width, *height)
go _g.run()
ml.Lock()
ml.m[new_game_name] = _g
ml.m[id] = _g
ml.Unlock()
return _g, nil