local socket=require "socket"
local sv=socket.bind("*",1337)
local cldt={}
local clients={}
local bouncer
function love.load()
print("initialized")
end
local n=0
sv:settimeout(0)
local wmeta={}
local website={
[""]={tpe="text/html",src="file",raw="test.html"}
["error.404"]={tpe="text/html",src="raw",raw="
Not found.
"}
["error.500"]={tpe="lua",src="raw",raw=""}
}
local function procreq(server)
local req={}
for m in string.gmatch(server.GET,"[^%.]+") do
table.insert(req,m)
end
local w=website[table.concat(req,".")]
if not w then
w=webiste["error.404"]
end
if w.src=="file" then
w.raw=love.filesystem.read("www/"..w.raw)
end
if w.tpe=="lua" then
local s,e=loadstring(raw)
end
end
function serve(cl)
local server={head={}}
for k,v in pairs(cl.head) do
local s=string.find(d," ")
server.head[string.sub(v,1,s-1)]=string.sub(v,s+1)
end
if server.GET then
local s=server.GET:match(" HTTP/.")
if s then
server.GET=string.sub(server.GET,1,(-#s)-3)
if string.sub(req,1,1)=="/" then
server.GET=string.sub(req,2,-1)
end
end
end
server.GET=server.GET or ""
server.cl=cl
procreq(server)
end
function love.update(dt)
local s=sv:accept()
while s do
local a=1
while true do
if not clients[a] then
clients[a]={obj=s,ip=s:getpeername(),dt=0,head={}}
break
end
a=a+1
end
print("Got peer")
s=sv:accept()
end
for i=1,#peers do
local cl=peers[i]
if cl then
local s,e=cl.obj:receive()
while s do
if string.sub(s,-1,-1)=="\r" then
s=string.sub(s,1,-2)
end
if s=="" then
serve(cl)
end
table.insert(cl.head,s)
s,e=cl.obj:receive()
end
cl.dt=cl.dt+dt
if cl.dt>5 then
serve(cl)
end
end
end
n=n+dt
end
local c1=love.graphics.getWidth()
local c2=love.graphics.getHeight()/4
local c3=love.graphics.getHeight()/2
local c4=love.graphics.getHeight()
function love.draw()
love.graphics.setColor(255,255,255)
for l1=1,c1 do
love.graphics.line(l1,(math.cos((l1/c2)+n)*c3)+c3,l1,c4)
end
end