bugfix for incorrect logic in game creation
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user