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

View File

@ -122,11 +122,11 @@ function obj.request(url, postData) -- Starts an HTTP request. If this returns t
end
-- TODO: This works ... but is slow.
-- 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 co = coroutine.running()
debug.sethook(co)
local starttime = gettime()
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
cprint("(request) request failed",err)
end

View File

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