Implemented chatting room (#17)

This commit is contained in:
Particle_G
2020-12-03 16:09:25 +08:00
committed by MrZ626
parent 325c544e17
commit 37d7dd5fe0
11 changed files with 189 additions and 66 deletions

View File

@@ -45,6 +45,13 @@ function TASK.removeTask_data(data)
end
end
end
function TASK.checkTask_code(code)
for i=#tasks,1,-1 do
if tasks[i].code==code then
return true
end
end
end
function TASK.clear()
local i=#tasks
while i>0 do

View File

@@ -166,44 +166,6 @@ do--dumpTable
return s..tabs[t-1].."}"
end
end
do--httpRequest
client=LOADLIB("NETlib")
httpRequest=
client and function(tick,path,method,header,body)
local task,err=client.httpraw{
url="http://krakens.tpddns.cn:10026"..path,
method=method or"GET",
header=header,
body=body,
}
if task then
TASK.new(tick,{task=task,time=0,net=true})
else
LOG.print("NETlib error: "..err,"warn")
end
TASK.netTaskCount=TASK.netTaskCount+1
end or
function()
LOG.print("[NO NETlib]",5,COLOR.yellow)
end
wsConnect=
client and function(tick,path,header)
local task,err=client.wsraw{
url="http://krakens.tpddns.cn:10026"..path,
header=header,
}
if task then
TASK.new(tick,{wsconntask=task,time=0,net=true})
else
LOG.print("NETlib error: "..err,"warn")
end
TASK.netTaskCount=TASK.netTaskCount+1
end or
function()
LOG.print("[NO NETlib]",5,COLOR.yellow)
end
end
do--json
--
-- json.lua
@@ -564,7 +526,6 @@ do--json
end
end
end
do--urlencode
local rshift=bit.rshift
local b16={[0]="0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}
@@ -581,6 +542,48 @@ do--urlencode
return out
end
end
do--httpRequest
client=LOADLIB("NETlib")
httpRequest=
client and function(tick,path,method,header,body)
local task,err=client.httpraw{
url="http://krakens.tpddns.cn:10026"..path,
-- url="http://127.0.0.1:10026"..path,
method=method or"GET",
header=header,
body=body,
}
if task then
TASK.new(tick,{task=task,time=0,net=true})
else
LOG.print("NETlib error: "..err,"warn")
end
TASK.netTaskCount=TASK.netTaskCount+1
end or
function()
LOG.print("[NO NETlib]",5,COLOR.yellow)
end
wsConnect=
client and function(tick,path,header)
local task,err=client.wsraw{
url="ws://krakens.tpddns.cn:10026"..path,
origin="krakens.tpddns.cn",
-- url="ws://127.0.0.1:10026"..path,
-- origin="127.0.0.1",
header=header,
}
if task then
TASK.new(tick,{wsconntask=task,time=0,net=true})
else
LOG.print("NETlib error: "..err,"warn")
end
TASK.netTaskCount=TASK.netTaskCount+1
end or
function()
LOG.print("[NO NETlib]",5,COLOR.yellow)
end
end
function copyList(org)
local L={}
for i=1,#org do

View File

@@ -806,6 +806,37 @@ function WIDGET.lnk_STPeq(k,v) return function() return sceneTemp[k]==v end e
function WIDGET.lnk_pressKey(k) return function() love.keypressed(k) end end
function WIDGET.lnk_goScene(t,s) return function() SCN.go(t,s) end end
function WIDGET.lnk_swapScene(t,s) return function() SCN.swapTo(t,s) end end
function WIDGET.lnk_goNetgame()
if LOGIN then
if ACCOUNT.access_token then
local res=json.encode{
email=ACCOUNT.email,
access_token=ACCOUNT.access_token,
}
httpRequest(
TICK.httpREQ_checkAccessToken,
PATH.api..PATH.access,
"GET",
{["Content-Type"]="application/json"},
res
)
else
local payload=json.encode{
email=ACCOUNT.email,
auth_token=ACCOUNT.auth_token,
}
httpRequest(
TICK.httpREQ_getAccessToken,
PATH.api..PATH.access,
"POST",
{["Content-Type"]="application/json"},
payload
)
end
else
SCN.go("login")
end
end
local indexMeta={
__index=function(L,k)