Jump to content

[HELP] getServerIP Server requested own IP.


PlayAkoya

Recommended Posts

Hi,

unfortunately my MTA request was refused and I still have not found a solution here hope someone can help me ?

https://bugs.multitheftauto.com/view.php?id=8992

Here's a test:

function getServerIp() 
    callRemote("http://box.houkouonchi.jp/ip.php", 
    function(value) 
        value = tostring(value) 
    end) 
    return value 
end 
  
function getServerPutWithIP() 
     
    outputChatBox("The server ip is: "..getServerIp().."", root, 200, 200, 0) 
end 
setTimer(getServerPutWithIP, 30000, -1) 

I always get an error message = nil

It's not working :(

Please Please help me ..

Link to comment

ehh

serverIP = false 
  
fetchRemote ( "http://ip4.telize.com/", function(r,e) if e == 0 then serverIP = r else print ( "error "..e.." when getting serverip !" ) end end ) 
  
function getServerIP ( ) 
    return serverIP; 
end 

obs: setTimer need a number higher than -1 in the third parameter also make sure you're using this code in server side.

Link to comment

Thx, it works well.

There are still a problem, when I use the command frequently then the port will always be added?

dc4176-1439293470.png

And that's not good. :wink:

serverIP = false 
  
fetchRemote("http://ip4.telize.com/", function(r,e) if e == 0 then serverIP = r else print("error "..e.." when getting serverip !" ) end end) 
  
function getServerIP () 
    serverIP = tostring(""..serverIP..":"..getServerPort().."") 
    serverIP = string.gsub(serverIP, "%s+", "") 
    return serverIP; 
end 
  
function getServerPutWithIP() 
    
    outputChatBox("The server ip is: "..getServerIP().."", root, 200, 200, 0) 
end 
addCommandHandler("serverip", getServerPutWithIP) 

Link to comment

The port is duplicated because "serverIP" is set as IP:PORT, and everytime you call that function with /serverip, you still ask for the port again. You can avoid it by adding two variables instead of one.

  
serverIP = false  
  
fetchRemote("http://ip4.telize.com/", function(r,e) if e == 0 then serverIP = r else print("error "..e.." when getting serverip !" ) end end)  
  
function getServerIP () 
    serverIP = string.gsub(serverIP, "%s+", "") 
    local formattedString = serverIP..":"..getServerPort() 
    return formattedString; 
end 
  
function getServerPutWithIP() 
    outputChatBox("The server ip is: "..getServerIP().."", root, 200, 200, 0) 
end 
addCommandHandler("serverip", getServerPutWithIP) 

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...