server without SafeWriting, is it possible?

Page:1 2 3 4 5 6 7 8 9  

  • golden_elite13

    Yes i think what i did is corrects, but i don't know why it don't works xD I can show you my code : (i didn't make the repeat of the updating function yet) Server = {}; local port = System.GetCVar("sv_port") or 64087 local name = System.GetCVar("sv_servername") local numPlayers = 0 local maxPlayers = tonumber(System.GetCVar("sv_maxplayers")) or 16 local mapPath = System.GetCVar("sv_map") or "" local mapDownloadLink = "" local desc = "Test_noSFW" local rank = System.GetCVar("sv_ranked") or 0 local pass = System.GetCVar("sv_password") or "" function Server:RequestHTTP(url) os.execute("curl.exe ""..url.."" > output.tmp") local f,err=io.open("output.tmp","r") if f then local content=f:read("*all") f:close() return content else return nil end end function urlencode(str) if type(str)=="string" then return str:gsub("[^a-zA-Z0-9]",function(chr) return string.format("%%%02X",chr:byte(1,1)) end) else return str end end function Server:Register(port, name, numPlayers, maxPlayers, mapPath, mapDownloadLink, timeLeft) mapDownloadLink=mapDownloadLink or "" -- http link to map download timeLeft=timeLeft or 0 --remaining round time in seconds pass = System.GetCVar("sv_password") or "" local result = Server:RequestHTTP("http://crymp.net/api/reg.php?ver=6156&port="..urlencode(port).."&name="..urlencode(name).."&desc="..desc.."&pass="..pass.."&numpl="..numPlayers.."&maxpl="..maxPlayers.."&map="..urlencode(mapPath).."&ranked="..rank.."&timel="..timeLeft.."&local=localhost"); local token=string.match(result,"<<Cookie>>([a-z0-9]-)<<") return token end local cookie = Server:Register(port, name, numPlayers, maxPlayers, mapPath, mapDownloadLink, g_gameRules.game:GetRemainingGameTime()) function Server:Update(token) local result = Server:RequestHTTP("http://crymp.net/api/up.php?&port="..urlencode(port).."&numpl="..numPlayers.."&name="..urlencode(name).."&desc="..desc.."&pass=".."&ver=6156".."&cookie="..token.."&map="..urlencode(mapPath).."&ranked="..rank.."&timel="..g_gameRules.game:GetRemainingGameTime().."&local=localhost") System.LogAlways("-----UPDATING------") --not finished but it should at least show max players number at startup.. end Server:Update(cookie)

    ❤️ 0
  • Zi;

    Hmm, this seems to work, you call :Update() every 45s, right? :D I would change a code little, so it remembers token for later use Server = {}; local port = System.GetCVar("sv_port") or 64087 local name = System.GetCVar("sv_servername") local numPlayers = 0 local maxPlayers = tonumber(System.GetCVar("sv_maxplayers")) or 16 local mapPath = System.GetCVar("sv_map") or "" local mapDownloadLink = "" local desc = "Test_noSFW" local rank = System.GetCVar("sv_ranked") or 0 local pass = System.GetCVar("sv_password") or "" function Server:RequestHTTP(url) os.execute("curl.exe \\""..url.."\\" > output.tmp") local f,err=io.open("output.tmp","r") if f then local content=f:read("*all") f:close() return content else return nil end end function urlencode(str) if type(str)=="string" then return str:gsub("[^a-zA-Z0-9]",function(chr) return string.format("%%%02X",chr:byte(1,1)) end) else return str end end function Server:Register(port, name, numPlayers, maxPlayers, mapPath, mapDownloadLink, timeLeft) mapDownloadLink=mapDownloadLink or "" -- http link to map download timeLeft=timeLeft or 0 --remaining round time in seconds pass = System.GetCVar("sv_password") or "" local result = Server:RequestHTTP("http://crymp.net/api/reg.php?ver=6156&port="..urlencode(port).."&name="..urlencode(name).."&desc="..desc.."&pass="..pass.."&numpl="..numPlayers.."&maxpl="..maxPlayers.."&map="..urlencode(mapPath).."&ranked="..rank.."&timel="..timeLeft.."&local=localhost"); local token=string.match(result,"<<Cookie>>([a-z0-9]-)<<") self.token=token; return token end local cookie = Server:Register(port, name, numPlayers, maxPlayers, mapPath, mapDownloadLink, g_gameRules.game:GetRemainingGameTime()) function Server:Update(token) token = token or self.token; local result = Server:RequestHTTP("http://crymp.net/api/up.php?port="..urlencode(port).."&numpl="..numPlayers.."&name="..urlencode(name).."&desc="..desc.."&pass=".."&ver=6156".."&cookie="..token.."&map="..urlencode(mapPath).."&ranked="..rank.."&timel="..g_gameRules.game:GetRemainingGameTime().."&local=localhost") System.LogAlways("-----UPDATING------") --not finished but it should at least show max players number at startup.. end Server:Update() Because if you don't call :Update() frequently, your server will disappear from serverlist after some short time Also &local shouldn't be localhost, but local IP of computer, like 192.168.1.56, but that doesn't matter so much, that's just in case you had more computers at home under same IP and wanted to connect server running on different one :D

    ❤️ 0
  • golden_elite13

    For now Update is called 1 time but i will change it Except this, it should work as you say but the max players number stays to 0 :'( And i haven't do the players score list yet. thank you for your help ^^

    ❤️ 0
  • Zi;

    Yeah, you must call it frequently, not just once, after that it will work 100% :D Ah, you need to pass &maxpl= also in Update call, you forgot to pass it! That's why there is problem. Anyways, it's strange, because there are several records on masterserver which show you successfuly had "32" as maxplayers on your server :D

    ❤️ 0
  • Zi;

    If you want to ease job of those params passing into HTTP, you can just use this function from my SSM function urlfmt(fmt,...) local args={}; for i,v in pairs({...}) do if type(v)=="string" then args[i]=v:gsub("[^a-zA-Z0-9]",function(c) return string.format("%%%02X",string.byte(c)); end); else args[i]=v; end end return string.format(fmt,unpack(args)); end And just use: urlfmt("http://crymp.net/api/up.php?numpl=%d&map=%s...",numPlayers,mapPath)

    ❤️ 0
  • golden_elite13

    32 maxplayers xDD i have set 16 xD yes it's a bit strange and yes i forgotten maxpl in update func, thank you ^^

    ❤️ 0
  • golden_elite13

    So I have to write : RequestHTTP(urlfmt("http://crymp.net/api/up.php?numpl=%d&map=%s...",numPlayers,mapPath)) right ?

    ❤️ 0
  • Zi;

    Maybe mistake is in tonumber(System.GetCVar("sv_maxplayers")) returning 0 for no reason :D Yes, isn't that easier than "..urlencode(...).."? u_u

    ❤️ 0
  • Zi;

    I think it's good idea to actually print full URL that is passed to RequestHTTP just for debug if something doesn't work as expected

    ❤️ 0
  • golden_elite13

    the full url of updating function : http://crymp.net/api/up.php?&port=64087&numpl=0&maxpl=16&name=%21Relax%20Gaming&desc=Test%5FnoSFW&pass=&ver=6156&cookie=e33660f03ba0b3d00509906b5c0207e5 &map=multiplayer%2Fia%2FPoolDay%5Fv2&ranked=0&timel=2502.29&local=192%2E168%2E1%2E18

    ❤️ 0
Page:1 2 3 4 5 6 7 8 9