func (r *Runner) joinGame(ctx context.Context, m message.Message, out chan<- message.Message) {
	games, ok := r.playerGames[m.PlayerName]
	switch {
	case !ok:
		games = make(map[game.ID]message.Addr, 1)
		r.playerGames[m.PlayerName] = games
	default:
		// remove other addr from the game
		addr2, ok := games[m.Game.ID]
		if ok {
			if m.Addr == addr2 {
				return // do not rejoin the game if already joined
			}
			m2 := message.Message{
				Type: message.LeaveGame,
				Info: "leaving game because it is being played on a different socket",
			}
			socketIn2 := r.playerSockets[m.PlayerName][addr2]
			message.Send(m2, socketIn2, r.Debug, r.log)
		}
		// remove the addr from its previously joined game if it is different
		for id, addr := range games {
			if addr == m.Addr {
				delete(games, id)
				break
			}
		}
	}
	games[m.Game.ID] = m.Addr
	message.Send(m, out, r.Debug, r.log)
}
// joinGame adds the socket to the game.
// If the socket is in a different game, that game is left.
// If a different socket is in the game for the player, that socket leaves the game.
joinGame adds the socket to the game.
If the socket is in a different game, that game is left.
If a different socket is in the game for the player, that socket leaves the game.
// joinGame adds the socket to the game . // If the socket is in a different game that game is left . // If a different socket is in the game for the player that socket leaves the game .
func (r *Runner) joinGame(ctx context.Context, m message.Message, out chan<- message.Message) {
	games, ok := r.playerGames[m.PlayerName]
	switch {
	case !ok:
		games = make(map[game.ID]message.Addr, 1)
		r.playerGames[m.PlayerName] = games
	default:
		addr2, ok := games[m.Game.ID]
		if ok {
			if m.Addr == addr2 {
				return 
			}
			m2 := message.Message{
				Type: message.LeaveGame,
				Info: "leaving game because it is being played on a different socket",
			}
			socketIn2 := r.playerSockets[m.PlayerName][addr2]
			message.Send(m2, socketIn2, r.Debug, r.log)
		}
		for id, addr := range games {
			if addr == m.Addr {
				delete(games, id)
				break
			}
		}
	}
	games[m.Game.ID] = m.Addr
	message.Send(m, out, r.Debug, r.log)
}
func ( r * Runner ) joinGame ( ctx context . Context , m message . Message , out chan <- message . Message ) { games , ok := r . playerGames [ m . PlayerName ] switch { case ! ok : games = make ( map [ game . ID ] message . Addr , 1 ) r . playerGames [ m . PlayerName ] = games default : addr2 , ok := games [ m . Game . ID ] if ok { if m . Addr == addr2 { return } m2 := message . Message { Type : message . LeaveGame , Info : " " , } socketIn2 := r . playerSockets [ m . PlayerName ] [ addr2 ] message . Send ( m2 , socketIn2 , r . Debug , r . log ) } for id , addr := range games { if addr == m . Addr { delete ( games , id ) break } } } games [ m . Game . ID ] = m . Addr message . Send ( m , out , r . Debug , r . log ) }
joinGame adds the socket to the game.
joinGame adds the socket to the game .
// remove other addr from the game // do not rejoin the game if already joined // remove the addr from its previously joined game if it is different