lewisclark / glua-steal

Retrieves client-sided Lua files from Garry's Mod game servers
GNU General Public License v3.0
151 stars 15 forks source link

[REQUEST] Add the ability to detect server IP for black/whitelisting #53

Closed synesthesium closed 1 year ago

synesthesium commented 1 year ago

Maybe something like gluasteal.SERVER so that something like this can be written?

if gluasteal.SERVER == "93.184.216.34" then -- this is the IP to example.com
    if gluasteal.SCRIPT == "includes/init.lua" then
        gluasteal.include("script1.lua")
    end
elseif gluasteal.SERVER == "172.67.183.168" then -- this is also the IP to something.com
    if gluasteal.SCRIPT == "includes/init.lua" then
        gluasteal.include("script2.lua")
    end
end
lewisclark commented 1 year ago

You can use Gmod's game.GetIPAddress function to retrieve the IP and port of the host you are connecting to. FYI, it's lua/includes/init.lua, not includes/init.lua (remember the prefix, e.g. lua, gamemode, etc).

print(gluasteal.SCRIPT)
if gluasteal.SCRIPT == "lua/includes/init.lua" then
    print("host ip", game.GetIPAddress())
end
Clientside Lua startup!
lua/includes/init.lua
host ip 45.88.1.1:27026
lua/includes/util.lua
lua/includes/util/color.lua
lua/includes/util/sql.lua
lua/includes/extensions/net.lua
lua/includes/modules/baseclass.lua
synesthesium commented 1 year ago

Huh. I read that game.GetIPAddress() reported wrong data occasionally. Anyways, as for including lua, that also solves #54, but I'm curious as to why the examples do not reflect that?

lewisclark commented 1 year ago

Woops! I'll update the readme now. Thanks. game.GetIPAddress() seems to work fine at the moment but if it does return wrong data I'll happily add something like gluasteal.SERVER.