• Connect To And Run External PHP Script On Server Start
    11 replies, posted
I'm not quite sure where this goes, but I suppose the Lua questions forum is probably the best place, since this is probably achieved through some Lua. My gaming community has a central box where we host our forums, our gameservers, and our Fast Download. However, we also have several external gameservers that have been donated by members of our community. One such server, a Garrysmod server, uses Fast Download files that are hosted on our central box (two different servers). I've written some PHP code to automatically download the Dua cache through FTP and upload it to our Fast Download server. I normally do this whenever I change any Lua (as should rightly be done), but occasionally the Lua changes without me being told or I forget. Hence, I would like to have the server connect to this PHP code (via an http address), and run the script every time the server starts up. If this can be accomplished through command line, please let me know. Otherwise, if someone could explain how this is done or point me in the right direction, it'd be greatly appreciated. I don't really know any Lua, so please try to elaborate. Thanks for the help.
[b][url=http://wiki.garrysmod.com/?title=Http.Get]Http.Get [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] This is what your looking for
Something like this would probably work. [lua] -- Replace this with the address to your script. local url = "http://www.youtube.com/"; hook.Add("Initialize", "Run PHP-script on initialize", function() http.Get(url, "", function(content, size) MsgN("Script ran at \"" .. url .. "\". Server returned:\n\n" .. content .. "\n(" .. size .. " bytes)"); end); end); [/lua]
Put that in autorun I presume?
If you want it to run when you connect to a game, then yes.
Hm, no I only want it to run when the server starts. Is there any hook to do this?
Then put it in autorun/server.
There's no way to tell if the server has just started, or has just changelevel'd. Initialize is called when the server loads a map (Which happens on map change and when it's first booted up)
[b][url=http://wiki.garrysmod.com/?title=G.CurTime]G.CurTime [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] maybe ? according to the wiki it runs from server start and not level start. [lua] function ServerStart() if CurTime() < 5 then dosomething() hook.Remove( "Think", "ServerStart" ) end end hook.Add("Think", "ServerStart", ServerStart) [/lua]
[QUOTE=ColdFusion;23998054][b][url=http://wiki.garrysmod.com/?title=G.CurTime]G.CurTime [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] maybe ?[/QUOTE] That's relative to when the server initialised, not when it first booted.
[QUOTE=|FlapJack|;23998059]That's relative to when the server initialised, not when it first booted.[/QUOTE] [quote] Gets the current time in seconds [B]since server start[/B]. Mainly used for timers. Only runs while players are connected.[/quote] But i suppose the wiki is incorrect. EDIT: you were right But also RealTime() does run from server start and not map change :smug: [quote] 02:47:06 > print(RealTime())... 446.48989868164 02:47:12 changelevel gm_construct 02:47:14 HLSW NOTE: Disconnected 02:47:23 HLSW NOTE: Connecting to XXX.XXX.XXX.XX:270XX ... 02:47:23 lua_run print(RealTime()) 02:47:23 > print(RealTime())... 463.43695068359 [/quote] So this [lua] function ServerStart() if RealTime() < 5 then local url = "http://www.youtube.com/" http.Get(url, "", function(content, size) MsgN("Script ran at \"" .. url .. "\". Server returned:\n\n" .. content .. "\n(" .. size .. " bytes)"); hook.Remove( "Think", "ServerStart" ) end end hook.Add("Think", "ServerStart", ServerStart) [/lua] This would be were you are looking for place in the lua/autorun folder
Sorry to bump this, I've been on vacation. I'll try the script and let you know if it works.
Sorry, you need to Log In to post a reply to this thread.