func (i *GameController) Clear() { gmech := i.server.mechanics gmech.gMutex.Lock() var mech *mechanics.GameMechanics if getMech, ok := gmech.games[i.gameID]; ok { mech = getMech } gmech.gMutex.Unlock() if mech != nil { mech.RemoveOutput(i.player) } }
func (i *GameController) processGamePlay(message *protocol.GamePlayMessage) { players := message.Data.Players find := false for _, b := range players { if b == i.player { find = true break } } if find == false { i.logicError = true return } ID := CalcGameID(players) gmech := i.server.mechanics gmech.gMutex.Lock() var create bool var mech *mechanics.GameMechanics if getMech, ok := gmech.games[ID]; ok { mech = getMech } else { create = true createMech := mechanics.NewGameMechanics(players, i.server.complete) gmech.games[ID] = createMech mech = createMech } gmech.gMutex.Unlock() i.gameID = ID i.input = mech.GetInput() mech.AddOutput(i.player, i.output) if create { go mech.Run() } }