aboutsummaryrefslogtreecommitdiff
path: root/gamemode/server/regtomaster.lua
blob: 9909fc8dd57da83c3e5e2616708ea515d53a3f26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
local function GetIP()
    	local hostip = GetConVar( "hostip" ):GetString()
    	hostip = tonumber( hostip )

    	local ip = {}
    	ip[ 1 ] = bit.rshift( bit.band( hostip, 0xFF000000 ), 24 )
    	ip[ 2 ] = bit.rshift( bit.band( hostip, 0x00FF0000 ), 16 )
    	ip[ 3 ] = bit.rshift( bit.band( hostip, 0x0000FF00 ), 8 )
    	ip[ 4 ] = bit.band( hostip, 0x000000FF )

    	return table.concat( ip, "." )
end

function GM:AddToMaster()
    if(!game.IsDedicated())then
        print("Listen or singleplayer, not registering with master server!")
        return
    end
    local data = {}
    data["hostname"] = GetHostName()
    data["ip"] = "" + GetIP() + ":" + (GetConVar("wss_serverurlport"):GetString() or 27015)
    data["online"] = "true"
    http.Post(GetConVar("wss_wss_masterserverurl"):GetString(),data)
end

function GM:RemoveFromMaster()
    local data = {}
    data["online"] = "false"
    http.Post(GAMEMODE.masterurl,data)
end