func (r *Runner) validateSocketMessage(m message.Message) error {
	if len(m.PlayerName) == 0 {
		return fmt.Errorf("no player name, cannot send message back")
	}
	if len(m.Addr) == 0 {
		return fmt.Errorf("no player address, cannot send message back")
	}
	socketAddrs, ok := r.playerSockets[m.PlayerName]
	if !ok {
		return fmt.Errorf("unknown player (%v), cannot send message back", m.PlayerName)
	}
	_, ok = socketAddrs[m.Addr]
	if !ok {
		return fmt.Errorf("unknown address: %v, cannot send message back", m.Addr)
	}
	if m.Game == nil && m.Type != message.SocketClose {
		return fmt.Errorf("received message without game")
	}
	switch m.Type {
	case message.CreateGame, message.JoinGame, message.SocketClose, message.LeaveGame:
		// NOOP
	default:
		games, ok := r.playerGames[m.PlayerName]
		switch {
		case !ok:
			return fmt.Errorf("player %v at %v not playing any game,", m.PlayerName, m.Addr)
		default:
			addr, ok := games[m.Game.ID]
			if !ok {
				return fmt.Errorf("player %v at %v not in game %v", m.PlayerName, m.Addr, m.Game.ID)
			}
			if addr != m.Addr {
				return fmt.Errorf("player %v at %v playing game %v on a different socket (%v)", m.PlayerName, m.Addr, m.Game.ID, addr)
			}
		}
	}
	return nil
}
// validateSocketMessage returns an error if the message from a socket is invalid
validateSocketMessage returns an error if the message from a socket is invalid
// validateSocketMessage returns an error if the message from a socket is invalid
func (r *Runner) validateSocketMessage(m message.Message) error {
	if len(m.PlayerName) == 0 {
		return fmt.Errorf("no player name, cannot send message back")
	}
	if len(m.Addr) == 0 {
		return fmt.Errorf("no player address, cannot send message back")
	}
	socketAddrs, ok := r.playerSockets[m.PlayerName]
	if !ok {
		return fmt.Errorf("unknown player (%v), cannot send message back", m.PlayerName)
	}
	_, ok = socketAddrs[m.Addr]
	if !ok {
		return fmt.Errorf("unknown address: %v, cannot send message back", m.Addr)
	}
	if m.Game == nil && m.Type != message.SocketClose {
		return fmt.Errorf("received message without game")
	}
	switch m.Type {
	case message.CreateGame, message.JoinGame, message.SocketClose, message.LeaveGame:
	default:
		games, ok := r.playerGames[m.PlayerName]
		switch {
		case !ok:
			return fmt.Errorf("player %v at %v not playing any game,", m.PlayerName, m.Addr)
		default:
			addr, ok := games[m.Game.ID]
			if !ok {
				return fmt.Errorf("player %v at %v not in game %v", m.PlayerName, m.Addr, m.Game.ID)
			}
			if addr != m.Addr {
				return fmt.Errorf("player %v at %v playing game %v on a different socket (%v)", m.PlayerName, m.Addr, m.Game.ID, addr)
			}
		}
	}
	return nil
}
func ( r * Runner ) validateSocketMessage ( m message . Message ) error { if len ( m . PlayerName ) == 0 { return fmt . Errorf ( " " ) } if len ( m . Addr ) == 0 { return fmt . Errorf ( " " ) } socketAddrs , ok := r . playerSockets [ m . PlayerName ] if ! ok { return fmt . Errorf ( " " , m . PlayerName ) } _ , ok = socketAddrs [ m . Addr ] if ! ok { return fmt . Errorf ( " " , m . Addr ) } if m . Game == nil && m . Type != message . SocketClose { return fmt . Errorf ( " " ) } switch m . Type { case message . CreateGame , message . JoinGame , message . SocketClose , message . LeaveGame : default : games , ok := r . playerGames [ m . PlayerName ] switch { case ! ok : return fmt . Errorf ( " " , m . PlayerName , m . Addr ) default : addr , ok := games [ m . Game . ID ] if ! ok { return fmt . Errorf ( " " , m . PlayerName , m . Addr , m . Game . ID ) } if addr != m . Addr { return fmt . Errorf ( " " , m . PlayerName , m . Addr , m . Game . ID , addr ) } } } return nil }
validateSocketMessage returns an error if the message from a socket is invalid
validateSocketMessage returns an error if the message from a socket is invalid
// NOOP