CHICAGO — The city of Chicago, which has fought for decades to keep guns out of the hands of its residents, now must craft an ordinance within 180 days that will allow gun stores to open there, a federal judge ruled Tuesday.