processMsg :: Connection -> Client -> MessageFromClient -> IO [MessageFromServer]

processMsg conn _ (ListActiveRooms (swlat,swlng) (nelat,nelng)) = do
  -- make a polygon box from PostGIS; 5 points to make a box

 
  let q = "select rooms.room_id from rooms \
        \inner join clients using (room_id) \
        \where ST_Intersects(  \
        \   ST_Transform(ST_MakePolygon(ST_GeomFromText('LINESTRING(' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ')', 4269)), 2163), \
        \   rooms.geom)  \
        \group by rooms.room_id order by rooms.created desc "
      variables = (swlng,swlat,nelng,swlat,nelng,nelat,swlng,nelat,swlng,swlat) 

  -- formatQuery conn q variables >>= C.putStrLn  -- uncomment to debug
  xs :: [Only Int] <- query conn q variables -- go around the 4 corners and end at start
  forM xs (\x -> do 
    room <- findRoom conn (fromOnly x) 
    return $ makeUpdatedRoom room InitRoom)
processMsg :: Connection -> Client -> MessageFromClient -> IO [MessageFromServer]
processMsg conn _ (ListActiveRooms (swlat,swlng) (nelat,nelng)) = do
  -- make a polygon box from PostGIS; 5 points to make a box

 
  let q = "select rooms.room_id from rooms \
        \inner join clients using (room_id) \
        \where ST_Intersects(  \
        \   ST_Transform(ST_MakePolygon(ST_GeomFromText('LINESTRING(' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ')', 4269)), 2163), \
        \   rooms.geom)  \
        \group by rooms.room_id order by rooms.created desc "
      variables = (swlng,swlat,nelng,swlat,nelng,nelat,swlng,nelat,swlng,swlat) 

  -- formatQuery conn q variables >>= C.putStrLn  -- uncomment to debug
  xs :: [Only Int] <- query conn q variables -- go around the 4 corners and end at start
  forM xs (\x -> do 
    room <- findRoom conn (fromOnly x) 
    return $ makeUpdatedRoom room InitRoom)
processMsg conn _ (ListActiveRooms (swlat,swlng) (nelat,nelng)) = do
  -- make a polygon box from PostGIS; 5 points to make a box

 
  let q = "select rooms.room_id from rooms \
        \inner join clients using (room_id) \
        \where ST_Intersects(  \
        \   ST_Transform(ST_MakePolygon(ST_GeomFromText('LINESTRING(' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ',' || ? || ' ' || ? || ')', 4269)), 2163), \
        \   rooms.geom)  \
        \group by rooms.room_id order by rooms.created desc "
      variables = (swlng,swlat,nelng,swlat,nelng,nelat,swlng,nelat,swlng,swlat) 

  -- formatQuery conn q variables >>= C.putStrLn  -- uncomment to debug
  xs :: [Only Int] <- query conn q variables -- go around the 4 corners and end at start
  forM xs (\x -> do 
    room <- findRoom conn (fromOnly x) 
    return $ makeUpdatedRoom room InitRoom)