Skip to content

Commit

Permalink
Added /geolocate for ops.
Browse files Browse the repository at this point in the history
/geolocate <active user or ip address> to view country, region, and city
for an ip address.
  • Loading branch information
Jonathon Emerson committed Jul 25, 2013
1 parent 14b0436 commit 196d665
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
26 changes: 26 additions & 0 deletions rsc/default.dmf
Expand Up @@ -7993,6 +7993,32 @@ window "help"
keep-aspect = false
align = top
text-wrap = false
elem "label57"
type = LABEL
pos = 363,407
size = 343x20
anchor1 = none
anchor2 = none
font-family = "Trebuchet MS,Arial"
font-size = 10
font-style = ""
text-color = #000000
background-color = #e9e9e9
is-visible = true
is-disabled = false
is-transparent = false
is-default = false
border = none
drop-zone = false
right-click = false
saved-params = ""
on-size = ""
text = "/geolocate <user, ip>: geolocation"
image = ""
image-mode = center
keep-aspect = false
align = center
text-wrap = false
elem "label56"
type = LABEL
pos = 363,383
Expand Down
41 changes: 41 additions & 0 deletions src/struct/chatter.dm
Expand Up @@ -961,6 +961,47 @@ mob

server_manager.saveHome()

geolocate(target as text)
set hidden = 1

if(!target) return
if(!server_manager.home) return
if(!(ckey in server_manager.home.operators))
server_manager.bot.say("You do not have access to this command.", src)
return

var/mob/chatter/C
if(ismob(target)) C = target
else C = chatter_manager.getByKey(target)

if(C && C.client) target = client.address
target = copytext(target, 1, 16)

var/http[] = world.Export("http://freegeoip.net/json/[target]")
if(!http || !file2text(http["CONTENT"]))
server_manager.bot.say("Failed to geolocate [target].", src)
return

var
content = file2text(http["CONTENT"])
list/data

content = copytext(content, 2, length(content) - 1)
content = textutil.replaceText(content, ":", "=")
content = textutil.replaceText(content, ",", "&")
content = textutil.replaceText(content, "\"", "")

data = params2list(content)

if(data && (length(data) > 1) && (("ip" in data) && (data["ip"] == target)))
server_manager.bot.say("The following information was found for [target]:", src)
if(data["country_name"]) server_manager.bot.rawSay("<b>Country:</b> [data["country_name"]]", src)
if(data["region_name"]) server_manager.bot.rawSay("<b>Region:</b> [data["region_name"]]", src)
if(data["city"]) server_manager.bot.rawSay("<b>City:</b> [data["city"]]", src)
if(data["latitude"] && data["longitude"]) server_manager.bot.rawSay("<b>Click <a href=https://maps.google.com/maps?q=[data["latitude"]]+[data["longitude"]]>here</a> to view on Google Maps.</b>", src)

else server_manager.bot.say("Failed to geolocate [target].", src)

/* SETTINGS */

setDefaultMisc()
Expand Down

0 comments on commit 196d665

Please sign in to comment.