Permalink
Browse files

find servers nearby

  • Loading branch information...
1 parent 98b8a2a commit 644ede0fc1b09c547815bd4ded31994000319849 @Arie committed Sep 10, 2016
@@ -49,7 +49,7 @@ def new_reservation
end
def free_servers
- @free_servers ||= free_server_finder.servers.ordered
+ @free_servers ||= free_server_finder.servers.near(current_user, 50000, order: "distance, position")
end
def free_server_finder
@@ -1,4 +1,4 @@
-- if !current_user.donator? && free_servers.count < 3
+- if !current_user.donator? && free_servers.size < 3
- free_donator_servers_count = Server.for_donators.active.count - used_donator_server_count
- if free_donator_servers_count > 0
.row
View
Oops, something went wrong.
View
@@ -10,22 +10,28 @@
fb1 = { :name => 'FakkelBrigade #1',
:path => '/home/tf2/tf2-1',
:ip => 'fakkelbrigade.eu',
- :port => '27015'
+ :port => '27015',
+ :latitude => 51,
+ :longitude => 9
}
fb2 = { :name => 'FakkelBrigade #2',
:path => '/home/tf2/tf2-2',
:ip => 'fakkelbrigade.eu',
- :port => '27025'
+ :port => '27025',
+ :latitude => 51,
+ :longitude => 9
}
fb4 = { :name => 'FakkelBrigade #4',
:path => '/home/tf2/tf2-4',
:ip => 'fakkelbrigade.eu',
- :port => '27045'
+ :port => '27045',
+ :latitude => 51,
+ :longitude => 9
}
servers = [fb1, fb2, fb4]
servers.each do |server|
- LocalServer.where(:name => server[:name], :path => server[:path], :ip => server[:ip], :port => server[:port]).first_or_create
+ LocalServer.where(:name => server[:name], :path => server[:path], :ip => server[:ip], :port => server[:port], :latitude => server[:latitude], :longitude => server[:longitude]).first_or_create
end
puts "Seeded servers #{servers.join(', ')}" unless Rails.env.test?
end
@@ -11,7 +11,7 @@ def results query
if query.to_s == '127.0.0.1'
[]
else
- [{:request=>"8.8.8.8", :ip=>"8.8.8.8", :country_code2=>"US", :country_code3=>"USA", :country_name=>"United States", :continent_code=>"NA", :region_name=>"CA", :city_name=>"Mountain View", :postal_code=>"94043", :latitude=>37.41919999999999, :longitude=>-122.0574, :dma_code=>807, :area_code=>650, :timezone=>"America/Los_Angeles"}]
+ [{:request=>"8.8.8.8", :ip=>"8.8.8.8", :country_code2=>"US", :country_code3=>"USA", :country_name=>"United States", :continent_code=>"NA", :region_name=>"CA", :city_name=>"Mountain View", :postal_code=>"94043", :latitude=>37.4191, :longitude=>-122.0574, :dma_code=>807, :area_code=>650, :timezone=>"America/Los_Angeles"}]
end
end
end
View
@@ -3,16 +3,20 @@
factory :server, :class => "LocalServer" do
name "TF2 1"
path "/home/tf2/tf2-1"
- ip "fakkelbrigade.eu"
+ ip "176.9.138.143"
port "27015"
location
+ latitude 51
+ longitude 9
end
factory :user do
uid "123456789"
nickname "Terminator"
name "Joe Sixpack"
provider "steam"
+ latitude 52.5
+ longitude 5.75
end
factory :admin, :class => "User" do
@@ -54,8 +54,8 @@
fallback_server_on_same_host = create :server, :ip => previous_reservation.server.ip, :port => 1337
new_reservation_taking_fallback_server = create :reservation, :server => fallback_server_on_same_host
- fallback_server_in_same_location = create(:server, :ip => "2.2.2.2", :location_id => previous_reservation.server.location_id)
- fallback_server_in_other_location = create(:server, :ip => "3.3.3.3", :location_id => create(:location))
+ fallback_server_in_same_location = create(:server, :ip => "176.9.138.144", :location_id => previous_reservation.server.location_id)
+ fallback_server_in_other_location = create(:server, :ip => "176.9.138.145", :location_id => create(:location))
reservation = subject.build_reservation

0 comments on commit 644ede0

Please sign in to comment.