Fix the hack

I totally tested the previous hack
New hack! Allow us to travel backwards in time, as far as the computer
is concerned, that minute long request only took about ~0 seconds
This commit is contained in:
gamax92 2015-06-19 16:18:56 -06:00
parent b3494872f1
commit 744e640bea
3 changed files with 7 additions and 6 deletions

View File

@ -1,12 +1,12 @@
local env = ... local env = ...
local sok,socket = pcall(require,"socket") local sok,socket = pcall(require,"socket")
local gettime
if sok then if sok then
gettime = socket.gettime gettime = socket.gettime
else else
gettime = os.time gettime = os.time
end end
timeoffset = 0
local tmpaddr = "tmp-address" local tmpaddr = "tmp-address"
@ -21,7 +21,7 @@ env.computer = {}
function env.computer.realTime() function env.computer.realTime()
--TODO --TODO
--cprint("computer.realTime") -- Spammy --cprint("computer.realTime") -- Spammy
return gettime() return gettime()-timeoffset
end end
function env.computer.uptime() function env.computer.uptime()
--TODO --TODO

View File

@ -122,11 +122,11 @@ function obj.request(url, postData) -- Starts an HTTP request. If this returns t
end end
-- TODO: This works ... but is slow. -- TODO: This works ... but is slow.
-- TODO: Infact so slow, it can trigger the machine's sethook, so we have to work around that. -- TODO: Infact so slow, it can trigger the machine's sethook, so we have to work around that.
local hookf,hookm,hookc = debug.gethook() local starttime = gettime()
local co = coroutine.running()
debug.sethook(co)
local page, err, headers, status = http.request(url, postData) local page, err, headers, status = http.request(url, postData)
debug.sethook(co,hookf,hookm,hookc) local offset = gettime() - starttime
timeoffset = timeoffset + offset
cprint("(request.hack) Going back in time: " .. offset .. "s")
if not page then if not page then
cprint("(request) request failed",err) cprint("(request) request failed",err)
end end

View File

@ -271,6 +271,7 @@ boot_machine()
local resume_thread local resume_thread
function resume_thread(...) function resume_thread(...)
timeoffset = 0
if coroutine.status(machine.thread) ~= "dead" then if coroutine.status(machine.thread) ~= "dead" then
cprint("resume",...) cprint("resume",...)
local results = { coroutine.resume(machine.thread, ...) } local results = { coroutine.resume(machine.thread, ...) }