Skip to content

Instantly share code, notes, and snippets.

@soccermitchy
Created February 10, 2013 02:03
Show Gist options
  • Save soccermitchy/4747995 to your computer and use it in GitHub Desktop.
Save soccermitchy/4747995 to your computer and use it in GitHub Desktop.
require "socket"
dofile("functions.lua")
dofile("http.lua")
JSON=require"libs.json"
server=socket.bind("*",8080)
while true do
connectData=acceptRequest(server)
if connectData.method=="GET" then
if string.find(connectData.page,"/Browse.json?") then
dofile("save-parser.lua")
page=string.match(connectData.page,".*%?.-=(.-)&.*")
amountperpage=string.match(connectData.page,".*%?.-=.-&.-=(.-)&.*")
jsontext=JSON:encode(getNeededSaves(page,amountperpage))
sendtext=[[HTTP/1.1 200 OK
Server: MitchTPT
Date: ]]..os.date()..[[
Content-Type: application\json
Connection: close
Content-Length: ]]..#jsontext..[[
X-Powered-By: lolcats
]]..jsontext
client:send(sendtext)
client:close()
elseif string.match(connectData.page,"/(.-).cps") then
saveid=string.match(connectData.page,"/(.-).cps")
if exists("saves/"..saveid..".cps") then
local savefile=io.open("saves/"..saveid..".cps")
local save=savefile:read'*a'
savefile:close()
sendtext=[[HTTP/1.1 200 OK
Server: MitchTPT
Content-Type: text/plain
X-Powered-By: lolcats
Content-Length: ]]..#save..[[
Accept-Ranges: bytes
Date: ]]..os.date()..[[
Age: 1
Connection: close
]]..save
client:send(sendtext)
client:close()
else
client:send([[HTTP/1.1 404 NOTFOUND
Server: MitchTPT
Content-Type: text/plain
X-Powered-By: lolcats
Content-Length: 10
Date: ]]..os.date()..[[
Connection: close
Not found.]])
client:close()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment