|
1 pcall(function () |
|
2 local city_db_path = os.getenv("GEOIP_CITY_DB"); |
|
3 if not city_db_path then return; end |
|
4 |
|
5 local city_db = assert(require "geoip.city".open(city_db_path)); |
|
6 |
|
7 events.add_handler("new-client", function (info) |
|
8 local ip = info.conn:ip(); |
|
9 local location = city_db:query_by_addr(ip); |
|
10 if location then |
|
11 local l = {}; |
|
12 if location.city_name then |
|
13 table.insert(l, location.city_name); |
|
14 end |
|
15 if location.region then |
|
16 table.insert(l, location.region); |
|
17 end |
|
18 if location.country_name then |
|
19 table.insert(l, location.country_name); |
|
20 end |
|
21 conn.location = table.concat(l, ", "); |
|
22 end |
|
23 end); |
|
24 end) |