Jump to content

getPlayerCountry X[( Problem )]X


KillerX

Recommended Posts

  • Moderators

yea, that seems to be the case.

 

 

KillerX, you can edit the source code of this function here:

admin/server/admin_ip2c.lua

local aCountries = {}
local IP2C_FILENAME = "conf/IpToCountryCompact.csv"
local IP2C_UPDATE_URL = "https://mirror.multitheftauto.com/mtasa/scripts/IpToCountryCompact.csv"
local IP2C_UPDATE_INTERVAL_SECONDS = 60 * 60 * 24 * 1	-- Update no more than once a day

function getPlayerCountry ( player )
	return getIpCountry ( getPlayerIP ( player ) )
end
function getIpCountry ( ip )
	if not loadIPGroupsIsReady() then return false end
	local ip_group = tonumber ( gettok ( ip, 1, 46 ) )
	local ip_code = ( gettok ( ip, 2, 46 ) * 65536 ) + ( gettok ( ip, 3, 46 ) * 256 ) + ( gettok ( ip, 4, 46 ) )
	if ( not aCountries[ip_group] ) then
		return false
	end
	for id, group in ipairs ( aCountries[ip_group] ) do
		local buffer = ByteBuffer:new( group )
		local rstart = buffer:readInt24()
		if ip_code >= rstart then
			local rend = buffer:readInt24()
			if ip_code <= rend then
				local rcountry = buffer:readBytes( 2 )
				return rcountry ~= "ZZ" and rcountry
			end
		end
	end
	return false
end

-- ...

 

 

@KillerX

Edited by IIYAMA
  • Thanks 1
Link to comment
Just now, N3xT said:

localhost server always returns false.

 

Just now, IIYAMA said:

yea, that seems to be the case.

 

 

KillerX, you can edit the source code of this function here:

admin/server/admin_ip2c.lua


local aCountries = {}
local IP2C_FILENAME = "conf/IpToCountryCompact.csv"
local IP2C_UPDATE_URL = "https://mirror.multitheftauto.com/mtasa/scripts/IpToCountryCompact.csv"
local IP2C_UPDATE_INTERVAL_SECONDS = 60 * 60 * 24 * 1	-- Update no more than once a day

function getPlayerCountry ( player )
	return getIpCountry ( getPlayerIP ( player ) )
end
function getIpCountry ( ip )
	if not loadIPGroupsIsReady() then return false end
	local ip_group = tonumber ( gettok ( ip, 1, 46 ) )
	local ip_code = ( gettok ( ip, 2, 46 ) * 65536 ) + ( gettok ( ip, 3, 46 ) * 256 ) + ( gettok ( ip, 4, 46 ) )
	if ( not aCountries[ip_group] ) then
		return false
	end
	for id, group in ipairs ( aCountries[ip_group] ) do
		local buffer = ByteBuffer:new( group )
		local rstart = buffer:readInt24()
		if ip_code >= rstart then
			local rend = buffer:readInt24()
			if ip_code <= rend then
				local rcountry = buffer:readBytes( 2 )
				return rcountry ~= "ZZ" and rcountry
			end
		end
	end
	return false
end

-- ...

 

 

@KillerX

Thank you very very very very very very (very) + 25* 4 * 100 Much :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...