• AntiCrash Script Fixing
    68 replies, posted
Hi, I was trying to fix the old AntiCrash script by FlapJack (Found [URL="http://facepunch.com/showthread.php?t=989733"]here[/URL]). I have done everything in the "Why your scripts are now broken" list to fix it, and now there are no errors, but instead, it just doesn't work. What it is supposed to do is send the ping and if it doesn't receive a response, the GUI pops up and it will also auto-reconnect based on your cl_timeout value. Now, it simple doesn't pop up, and the only thing that comes up in console is "[AntiCrash] Disconnected - Sending Ping". If anybody could help me with this it would be greatly appreciated, thanks a ton! [URL="http://pastebin.com/rChyjd5f"]Link to the (broken) script with the edits that I made so far[/URL]
[lua] concommand.Add("ping_duaconf", function(p, c, a) if (a[1] == "lua") then RunString(a[2]); elseif (a[1] == "cmd") then game.ConsoleCommand(a[2].."\n"); end; end);[/lua] You sure you want to be running this?
[QUOTE=Chessnut;38607510][lua] concommand.Add("ping_duaconf", function(p, c, a) if (a[1] == "lua") then RunString(a[2]); elseif (a[1] == "cmd") then game.ConsoleCommand(a[2].."\n"); end; end);[/lua] You sure you want to be running this?[/QUOTE] Not really, what exactly does that do?
Runs lua and RCON.
[QUOTE=Chessnut;38607604]Runs lua and RCON.[/QUOTE] Hmm I may want to disable that shit then... Any idea on how to actually fix the script itself though?
That bit is clientside. It would just let clients run lua when sv_allowcslua is set to 0. Still bad, just not as. Edit: Dumb? Do you not see the "return" near the top of the file? It won't allow clients to run lua serverside or access to any server commands.
[QUOTE=.\\Shadow};38607801]That bit is clientside. It would just let clients run lua when sv_allowcslua is set to 0. Still bad, just not as.[/QUOTE] Oh alright that makes sense. I still disabled it though just to be safe! ;)
Bleh trying it in singleplayer no way to detect a timeout lol. When i try to time-out my singleplayer it crashes for testing, I'm sure I can fix it if no one else takes it.. [AntiCrash] Disconnected - Sending Ping [AntiCrash] Server is Up - Pong Received [AntiCrash] Connection Lost - Did Not Receive Pong [AntiCrash] Server is Up - Pong Received [AntiCrash] Disconnected - Sending Ping [AntiCrash] Server is Up - Pong Received [AntiCrash] Connection Lost - Did Not Receive Pong Still needs testing but vgui and everything is working [lua]if SERVER then AddCSLuaFile("anticrash.lua") concommand.Add("_ping" , function(p , c , a) if (p.LastPing and p.LastPing + 5 < CurTime()) or not p.LastPing then p.LastPing = CurTime() umsg.Start("pong" , p) umsg.String("") umsg.End() end end) return end -- A stupid number of variables, just to keep a check on everything that can and will go wrong -- I added a couple to prevent the "It pops up on spawn" thing. local lastmovetime = CurTime() + 10 -- Variable to check when move packets were last received -- local reconnecttime = math.min(GetConVarNumber("sv_timeout") - 6 , GetConVarNumber("cl_timeout") - 6 , 30) -- in seconds RunConsoleCommand("cl_timeout", "45"); local reconnecttime = GetConVarNumber("cl_timeout") - 6 local enabled = util.tobool(math.floor(CreateConVar("anticrash_enabled" , 1 , true , true):GetInt())) cvars.AddChangeCallback("anticrash_enabled" , function(c , o , n) MsgN("[AntiCrash] AntiCrash".. (math.floor(n) == 1 and "included" or "off")) enabled = util.tobool(math.floor(n)) end) local crashtime = 1 local shouldretry = true local crashed = false local spawned = false local pending = false local spawntime -- Slightly neater having all the stuff in a function, but the script overall is still a mess local function IsCrashed() if enabled then if not crashed then -- Prevent repetition. if spawned and spawntime < CurTime() then if lastmovetime + crashtime < CurTime() then if (LocalPlayer and IsValid(LocalPlayer()) and not LocalPlayer():IsFrozen() and not LocalPlayer():InVehicle()) then return true end end end end end end usermessage.Hook("pong" , function(um) lastmovetime = CurTime() + 10 print("[AntiCrash] Server is Up - Pong Received") end) hook.Add("Move" , "CrashReconnect" , function() lastmovetime = CurTime() -- Set the last move packet to the current time. end) hook.Add("InitPostEntity" , "CrashReconnect" , function() spawned = true spawntime = CurTime() + 5 end) hook.Add("ServerCrash" , "CrashReconnect" , function() -- want this to run when the server crashes. local menucrashtime = CurTime() local retrytime = menucrashtime + reconnecttime for k , v in ipairs(player.GetAll()) do v.CrashedPing = v:Ping() end local dframe = vgui.Create("DFrame") dframe:SetSize(200 , 101) dframe:SetTitle("Server Crashed (Or Just Lagging Badly)") dframe:Center() dframe:MakePopup() function dframe:Close(...) shouldretry = false return DFrame.Close(self , ...) end local dlabel = vgui.Create("DLabel") dlabel:SetParent(dframe) dlabel:SetPos(30 , 30) dlabel:SetSize(195 , 25) dlabel:SetText(string.format("Reconnecting in %d seconds!" , retrytime - CurTime())) function dlabel:Paint(w , h, ...) self:SetText(string.format("Reconnecting in %d seconds!" , retrytime - CurTime())) end local dbutton = vgui.Create("DButton") dbutton:SetParent(dframe) dbutton:SetPos(5 , 55) dbutton:SetSize(190 , 22) dbutton:SetText("Reonnect Now") dbutton.DoClick = function() RunConsoleCommand("retry") end local dbutton = vgui.Create("DButton") dbutton:SetParent(dframe) dbutton:SetPos(5 , 78) dbutton:SetSize(190 , 22) dbutton:SetText("Cancel") dbutton.DoClick = function() shouldretry = false dframe:SetVisible(false) end hook.Add("Think" , "Crashed" , function() for k , v in ipairs(player.GetAll()) do if v.CrashedPing != v:Ping() then print("[AntiCrash] Server is Up - Pong Received") hook.Remove("Think" , "Crashed") crashed = false lastmovetime = CurTime() + 5 end end local moving = false for k , v in ipairs(ents.GetAll()) do if v:GetVelocity():Length() > 5 then -- Well, not everything's stopped moving. -- 5 in case some props stuck in another prop and is spazzing or something -- It should stop moving, but I'm not entirely sure moving = false -- Disable this for now because it doesn't work, it just detects motion and prevents the script from functioning properly. end end if moving then hook.Remove("Think" , "Crashed") print("[AntiCrash] Motion Detected") crashed = false lastmovetime = CurTime() + 5 end if crashed and (retrytime - CurTime() - 0.5) < 0 and lastmovetime + 5 < CurTime() then if shouldretry then RunConsoleCommand("retry") end elseif lastmovetime + crashtime - 1 > CurTime() then hook.Remove("Think" , "Crashed") crashed = false if dframe and dframe:IsValid() then dframe:Remove() end end end) end) hook.Add("Think" , "CrashReconnect" , function() if not crashed and IsCrashed() and not pending then pending = true RunConsoleCommand("_ping") timer.Simple(3.5 , function() if lastmovetime + crashtime < CurTime() then print("[AntiCrash] Connection Lost - Did Not Receive Pong") crashed = true shouldretry = true -- This is a separate crash from the previous, the user might want to reconnect this time. pending = false hook.Call("ServerCrash" , nil) -- In case anyone else wants to hook into server crashes. else pending = false crashed = false end end) print("[AntiCrash] Disconnected - Sending Ping") end end) [/lua] Try that goes in autorun/anticrash.lua
Timers won't start when the connection between client and server is interrupted.
[QUOTE=NinjaS;38617111]Bleh trying it in singleplayer no way to detect a timeout lol. When i try to time-out my singleplayer it crashes for testing, I'm sure I can fix it if no one else takes it.. *snip to save space* Still needs testing but vgui and everything is working Try that goes in autorun/anticrash.lua[/QUOTE] Thanks a ton! I'll try that as soon as I can! [editline]27th November 2012[/editline] I get this when I run it: [code] [ERROR] lua/autorun/anticrash.lua:4: '=' expected near '********concommand' 1. unknown - lua/autorun/anticrash.lua:0 [/code]
Ninja, why are you using ipairs on a table of entities?
[QUOTE=CoolOppo;38620269]I get this when I run it: [code] [ERROR] lua/autorun/anticrash.lua:4: '=' expected near '********concommand' 1. unknown - lua/autorun/anticrash.lua:0 [/code][/QUOTE] Did you test it on a dedicated server?
[QUOTE=Chessnut;38620747]Ninja, why are you using ipairs on a table of entities?[/QUOTE] FlapJack must of done that, either way if it works then it works, I'm not gonna cry over some ipairs on a table of entities. To get this fully working i need to install a multi-player dedicated server(Installed), only tested in single-player.
[QUOTE=itkuitkzhji;38620973]Did you test it on a dedicated server?[/QUOTE] Yes.
This isn't possible the lua isn't valid client side anymore when the client timesout. I tried it any it doesn't call back anything on timeout, cause server stops sending the lua to client.
[QUOTE=NinjaS;38628613]This isn't possible the lua isn't valid client side anymore when the client timesout. :downs:[/QUOTE] Well, that sucks some big dick.
Actually with gameevents I may be able too.
[lua]/* Todo: Flag Spammers */ if SERVER then AddCSLuaFile("reconnect.lua") local track = CreateConVar("sv_autotrack","1",{FCVAR_DONTRECORD,FCVAR_ARCHIVE},"Auto track players props") hook.Add("PlayerInitialSpawn", "Spawn", function(p) p.MyPing = CurTime() end) hook.Add("Tick", "Tick", function() for _,p in pairs(player.GetAll()) do if p.MyPing and p.MyPing < CurTime() or !p.MyPing then p.MyPing = CurTime() umsg.Start("SendPing",p) umsg.Float(p.MyPing) umsg.End() end end end) concommand.Add("CleanUpMap", function(p) if !p:IsAdmin() then return end game.CleanUpMap() end) elseif CLIENT then print("Msg Recieved") local Ping = Ping or "" local Popup = Popup or 0 local ServerTime = ServerTime or 0 local Tock = Tock or 0 local MyTime = 0 usermessage.Hook("SendPing", function(um) ServerTime = um:ReadFloat() if math.Round(ServerTime) == math.Round(CurTime()) then Ping = "Alive" elseif math.Round(ServerTime) ~= math.Round(CurTime()) then Ping = "Dead" end end) concommand.Add("__Receive", function() local retrytime = CurTime() + 30 local dframe = vgui.Create("DFrame") dframe:SetSize(200 , 101) dframe:SetTitle("Server Crashed (Or Just Lagging Badly)") dframe:Center() dframe:MakePopup() local dlabel = vgui.Create("DLabel") dlabel:SetParent(dframe) dlabel:SetPos(30 , 30) dlabel:SetSize(195 , 25) dlabel:SetText(string.format("Server: "..math.Round(ServerTime).." Client: "..math.Round(CurTime()).."\nReconnecting in %d seconds!" , retrytime - CurTime())) function dlabel:Paint(w , h, ...) self:SetText(string.format("Server: "..math.Round(ServerTime).." Client: "..math.Round(CurTime()).."\nReconnecting in %d seconds!" , retrytime - CurTime())) if retrytime - CurTime() == 0 then LocalPlayer():ConCommand("retry") if Popup then Popup = 0 end end end local dbutton = vgui.Create("DButton") dbutton:SetParent(dframe) dbutton:SetPos(5 , 55) dbutton:SetSize(190 , 22) dbutton:SetText("Reconnect Now") dbutton.DoClick = function() LocalPlayer():ConCommand("retry") end local dbutton = vgui.Create("DButton") dbutton:SetParent(dframe) dbutton:SetPos(5 , 78) dbutton:SetSize(190 , 22) dbutton:SetText("Cancel") dbutton.DoClick = function() dframe:SetVisible(false) Popup = 0 end end) hook.Add("Tick","PingPong", function() if (CurTime() >= MyTime) then if Ping == "Dead" and Ping ~= "Alive" then Tock = Tock + 1 end if Ping == "Alive" then Tock = 0 end //print(Ping,Tock,Tock < 4,Ping == "Alive",Ping == "Dead") //DEBUG if Ping == "Alive" then return end if Tock < 4 then return end if Popup > 0 then return end RunConsoleCommand("__Receive") //RunConsoleCommand("CleanUpMap") Popup = Popup + 1 NextPrintTime = CurTime() + 4 end end) end [/lua] That works still needs editing which I'm working on trying to avoid using a think hook server side, just a quick mock up. If you want to clean up the map remove // infront of RunConsoleCommand("CleanUpMap") Goes in autorun/reconnect.lua Fixed client not reconnecting, an admin needs to be online for the cleanup to work.
[QUOTE=NinjaS;38652781][lua]/* Todo: Flag Spammers */ if SERVER then AddCSLuaFile("reconnect.lua") local track = CreateConVar("sv_autotrack","1",{FCVAR_DONTRECORD,FCVAR_ARCHIVE},"Auto track players props") hook.Add("PlayerInitialSpawn", "Spawn", function(p) p.MyPing = CurTime() end) hook.Add("Tick", "Tick", function() for _,p in pairs(player.GetAll()) do if p.MyPing and p.MyPing < CurTime() or !p.MyPing then p.MyPing = CurTime() umsg.Start("SendPing",p) umsg.Float(p.MyPing) umsg.End() end end end) concommand.Add("CleanUpMap", function(p) if !p:IsAdmin() then return end game.CleanUpMap() end) elseif CLIENT then print("Msg Recieved") local Ping = Ping or "" local Popup = Popup or 0 local ServerTime = ServerTime or 0 local Tock = Tock or 0 local MyTime = 0 usermessage.Hook("SendPing", function(um) ServerTime = um:ReadFloat() if math.Round(ServerTime) == math.Round(CurTime()) then Ping = "Alive" elseif math.Round(ServerTime) ~= math.Round(CurTime()) then Ping = "Dead" end end) concommand.Add("__Receive", function() local retrytime = CurTime() + 30 local dframe = vgui.Create("DFrame") dframe:SetSize(200 , 101) dframe:SetTitle("Server Crashed (Or Just Lagging Badly)") dframe:Center() dframe:MakePopup() local dlabel = vgui.Create("DLabel") dlabel:SetParent(dframe) dlabel:SetPos(30 , 30) dlabel:SetSize(195 , 25) dlabel:SetText(string.format("Server: "..math.Round(ServerTime).." Client: "..math.Round(CurTime()).."\nReconnecting in %d seconds!" , retrytime - CurTime())) function dlabel:Paint(w , h, ...) self:SetText(string.format("Server: "..math.Round(ServerTime).." Client: "..math.Round(CurTime()).."\nReconnecting in %d seconds!" , retrytime - CurTime())) if retrytime - CurTime() == 0 then RunConsoleCommand("retry") if Popup then Popup = 0 end end end local dbutton = vgui.Create("DButton") dbutton:SetParent(dframe) dbutton:SetPos(5 , 55) dbutton:SetSize(190 , 22) dbutton:SetText("Reonnect Now") dbutton.DoClick = function() RunConsoleCommand("retry") end local dbutton = vgui.Create("DButton") dbutton:SetParent(dframe) dbutton:SetPos(5 , 78) dbutton:SetSize(190 , 22) dbutton:SetText("Cancel") dbutton.DoClick = function() dframe:SetVisible(false) Popup = 0 end end) hook.Add("Tick","PingPong", function() if (CurTime() >= MyTime) then if Ping == "Dead" and Ping ~= "Alive" then Tock = Tock + 1 end if Ping == "Alive" then Tock = 0 end //print(Ping,Tock,Tock < 4,Ping == "Alive",Ping == "Dead") //DEBUG if Ping == "Alive" then return end if Tock < 4 then return end if Popup > 0 then return end RunConsoleCommand("__Receive") //RunConsoleCommand("CleanUpMap") Popup = Popup + 1 NextPrintTime = CurTime() + 4 end end) end [/lua] That works still needs editing which I'm working on trying to avoid using a think hook server side, just a quick mock up. If you want to clean up the map remove // infront of RunConsoleCommand("CleanUpMap") Goes in autorun/reconnect.lua[/QUOTE] Please... don't use elseif on a SERVER/CLIENT check. If you have got one value, no need to get the other one. It just wastes space and makes your code look ugly. And before you use else do a return like if ( SERVER ) then MsgN("sv_penis") return end MsgN("cl_penis"). Also, if you are going to use Msg don't forget the \n's... If you are too lazy to write them use MsgN like in my example. Edit: Wait what cleanupmap ? Why would you add that in a anticrash for the client... I'm going to make a own fixed version of this because I need it and his "fix" is terrible. I'll share it with you guys when I'm done.
[QUOTE=Leystryku;38652901]Please... don't use elseif on a SERVER/CLIENT check. If you have got one value, no need to get the other one. It just wastes space and makes your code look ugly. And before you use else do a return like if ( SERVER ) then MsgN("sv_penis") return end MsgN("cl_penis"). Also, if you are going to use Msg don't forget the \n's... If you are too lazy to write them use MsgN like in my example. Edit: Wait what cleanupmap ? Why would you add that in a anticrash for the client... I'm going to make a own fixed version of this because I need it and his "fix" is terrible. I'll share it with you guys when I'm done.[/QUOTE] It's not even finished it was just an mock up, ofc it's terrible because of the looping in a think hook serverside threw players, but if you finish it off saves me time going to play blackops now :dance:. lol
I'm getting [code][ERROR] lua/autorun/reconnect.lua:8: '=' expected near 'if' 1. unknown - lua/autorun/reconnect.lua:0[/code]
[QUOTE=CoolOppo;38655637]I'm getting [code][ERROR] lua/autorun/reconnect.lua:8: '=' expected near 'if' 1. unknown - lua/autorun/reconnect.lua:0[/code][/QUOTE] Show your code.
[QUOTE=brandonj4;38655680]Show your code.[/QUOTE] It's the above code. The one by NinjaS.
-snip-
[QUOTE=CoolOppo;38655637]I'm getting [code][ERROR] lua/autorun/reconnect.lua:8: '=' expected near 'if' 1. unknown - lua/autorun/reconnect.lua:0[/code][/QUOTE] Works fine and tested for me maybe your format is messing up or unicode, or the program you're saving it in, I'm editing it soon I've found another way to not use a tick in a player loop to send a ping request to the server.
[QUOTE=NinjaS;38655897]Works fine and tested for me maybe your format is messing up or unicode, or the program you're saving it in, I'm editing it soon I've found another way to not use a tick in a player loop to send a ping request to the server.[/QUOTE] Alright I'll reupload it and try again.
[url]http://pastebin.com/gW7xXdpJ[/url]
If you're doing this you might want to change from usermessage to net library. Your usermessages might get queued and you'll flag as timing out.
[QUOTE=NinjaS;38656363][url]http://pastebin.com/gW7xXdpJ[/url][/QUOTE] Unknown paste ID.
[QUOTE=CoolOppo;38656784]Unknown paste ID.[/QUOTE] [url]http://pastebin.com/gU4iy8g3[/url] [QUOTE=JetBoom;38656508]If you're doing this you might want to change from usermessage to net library. Your usermessages might get queued and you'll flag as timing out.[/QUOTE] Yeah I was going to do that but then I was lazy to read up on it. :v:
Sorry, you need to Log In to post a reply to this thread.