Advertisement
MudkipTheEpic

HTTP patch test

May 23rd, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. local tNativeP={}
  2. for k,v in pairs(peripheral) do
  3. tNativeP[k]=v
  4. end
  5. local tNativeCo={}
  6. for k,v in pairs(coroutine) do
  7. tNativeCo[k]=v
  8. end
  9. local nClock=os.clock()
  10. local nTimes=0
  11. local fClock=os.clock
  12. local nCo=-2
  13. local nativegetmetatable = getmetatable
  14. local nativetype = type
  15. local nativeerror = error
  16.  
  17. local httpban=300
  18. local nHClock=os.clock()
  19. local nBClock
  20. local oldRequest=http.request
  21. local nHTTP=0
  22. local isHTTPBanned=false
  23.  
  24. -- Install the lua part of the HTTP api (if enabled)
  25. if http then
  26. function http.request(...)
  27. if isHTTPBanned and fClock()-httpban>nBClock then
  28. isHTTPBanned=false
  29. nBClock=nil
  30. nHTTP=0
  31. nHClock-fClock()
  32. return oldRequest(...)
  33. elseif isHTTPBanned and fClock()-httpban<=nBClock then
  34. nativeerror("Banned from HTTP for "..nBClock-(nHClock()-httpban).."seconds.",2)
  35. return nil
  36. elseif nHTTP>=20 and fClock()-10 <= nHClock then
  37. isHTTPBanned=true
  38. nBClock=fClock()
  39. nativeerror("Spammed HTTP, banned for 5 minutes.",2)
  40. return nil
  41. elseif fClock()-10 >nHClock then
  42. nHClock=fClock()
  43. nHTTP=0
  44. return oldRequest(...)
  45. end
  46. return oldRequest(...)
  47. end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement