Update api path, add global table (#16)
This commit is contained in:
@@ -171,7 +171,6 @@ do--httpRequest
|
|||||||
httpRequest=
|
httpRequest=
|
||||||
client and function(tick,path,method,header,body)
|
client and function(tick,path,method,header,body)
|
||||||
local task,err=client.httpraw{
|
local task,err=client.httpraw{
|
||||||
-- url="http://47.103.200.40/"..path,
|
|
||||||
url="http://krakens.tpddns.cn:10026"..path,
|
url="http://krakens.tpddns.cn:10026"..path,
|
||||||
method=method or"GET",
|
method=method or"GET",
|
||||||
header=header,
|
header=header,
|
||||||
@@ -187,6 +186,25 @@ do--httpRequest
|
|||||||
function()
|
function()
|
||||||
LOG.print("[NO NETlib]",5,COLOR.yellow)
|
LOG.print("[NO NETlib]",5,COLOR.yellow)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
wsConnect=
|
||||||
|
client and function(tick,path,header)
|
||||||
|
local task,err=client.wsraw{
|
||||||
|
-- url="http://krakens.tpddns.cn:10026"..path,
|
||||||
|
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
|
end
|
||||||
do--json
|
do--json
|
||||||
--
|
--
|
||||||
|
|||||||
1
main.lua
1
main.lua
@@ -23,6 +23,7 @@ LOADED=false
|
|||||||
NOGAME=false
|
NOGAME=false
|
||||||
LOGIN=false
|
LOGIN=false
|
||||||
EDITING=""
|
EDITING=""
|
||||||
|
WSCONN=nil
|
||||||
|
|
||||||
math.randomseed(os.time()*626)
|
math.randomseed(os.time()*626)
|
||||||
love.keyboard.setKeyRepeat(true)
|
love.keyboard.setKeyRepeat(true)
|
||||||
|
|||||||
@@ -309,6 +309,15 @@ ACCOUNT={
|
|||||||
avatar=nil,
|
avatar=nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PATH={
|
||||||
|
api="/tech/api/v1",
|
||||||
|
appInfo="/app/info",
|
||||||
|
users="/users",
|
||||||
|
auth="/auth",
|
||||||
|
access="/auth/access",
|
||||||
|
versus="/online/versus"
|
||||||
|
}
|
||||||
|
|
||||||
keyMap={
|
keyMap={
|
||||||
{"left","right","x","z","c","up","down","space","tab","r"},{},
|
{"left","right","x","z","c","up","down","space","tab","r"},{},
|
||||||
--Keyboard
|
--Keyboard
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ return{
|
|||||||
registerFailed="Registration failed",
|
registerFailed="Registration failed",
|
||||||
loginSuccessed="Successfully logged in!",
|
loginSuccessed="Successfully logged in!",
|
||||||
loginFailed="Login failed",
|
loginFailed="Login failed",
|
||||||
|
wsSuccessed="Websocket connected!",
|
||||||
|
wsFailed="Websocket failed to connect",
|
||||||
|
|
||||||
errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.",
|
errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.",
|
||||||
|
|
||||||
@@ -483,6 +485,10 @@ return{
|
|||||||
password="Password",
|
password="Password",
|
||||||
password2="Reenter password",
|
password2="Reenter password",
|
||||||
},
|
},
|
||||||
|
netgame={
|
||||||
|
title="Online game",
|
||||||
|
test="Test",
|
||||||
|
},
|
||||||
account={
|
account={
|
||||||
title="Account",
|
title="Account",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ return{
|
|||||||
registerFailed="Erreur d'enregistrement",
|
registerFailed="Erreur d'enregistrement",
|
||||||
-- loginSuccessed="Successfully logged in!",
|
-- loginSuccessed="Successfully logged in!",
|
||||||
-- loginFailed="Login failed",
|
-- loginFailed="Login failed",
|
||||||
|
-- wsSuccessed="Websocket connected!",
|
||||||
|
-- wsFailed="Websocket failed to connect",
|
||||||
|
|
||||||
errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.",
|
errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.",
|
||||||
|
|
||||||
@@ -480,6 +482,10 @@ return{
|
|||||||
password="Mot de passe",
|
password="Mot de passe",
|
||||||
password2="Confirmer le mot de passe",
|
password2="Confirmer le mot de passe",
|
||||||
},
|
},
|
||||||
|
netgame={ -- TODO: translation
|
||||||
|
title="Online game",
|
||||||
|
test="Test",
|
||||||
|
},
|
||||||
account={
|
account={
|
||||||
title="Compte",
|
title="Compte",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ return{
|
|||||||
registerFailed="Registro fallido.",
|
registerFailed="Registro fallido.",
|
||||||
-- loginSuccessed="Successfully logged in!",
|
-- loginSuccessed="Successfully logged in!",
|
||||||
-- loginFailed="Login failed",
|
-- loginFailed="Login failed",
|
||||||
|
-- wsSuccessed="Websocket connected!",
|
||||||
|
-- wsFailed="Websocket failed to connect",
|
||||||
|
|
||||||
errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.",
|
errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.",
|
||||||
|
|
||||||
@@ -485,6 +487,10 @@ return{
|
|||||||
password="Contraseña",
|
password="Contraseña",
|
||||||
password2="Repetir Contr.",
|
password2="Repetir Contr.",
|
||||||
},
|
},
|
||||||
|
netgame={ -- TODO: translation
|
||||||
|
title="Online game",
|
||||||
|
test="Test",
|
||||||
|
},
|
||||||
account={
|
account={
|
||||||
title="Cuenta",
|
title="Cuenta",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -407,6 +407,10 @@ return{
|
|||||||
password="*",
|
password="*",
|
||||||
password2="*",
|
password2="*",
|
||||||
},
|
},
|
||||||
|
netgame={
|
||||||
|
title="Online game",
|
||||||
|
test="Test",
|
||||||
|
},
|
||||||
account={
|
account={
|
||||||
title="@_@",
|
title="@_@",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ return{
|
|||||||
registerFailed="注册失败",
|
registerFailed="注册失败",
|
||||||
loginSuccessed="登录成功!",
|
loginSuccessed="登录成功!",
|
||||||
loginFailed="登录失败",
|
loginFailed="登录失败",
|
||||||
|
wsSuccessed="连接成功!",
|
||||||
|
wsFailed="连接失败",
|
||||||
|
|
||||||
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
|
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
|
||||||
|
|
||||||
@@ -506,6 +508,10 @@ return{
|
|||||||
password="密码",
|
password="密码",
|
||||||
password2="确认密码",
|
password2="确认密码",
|
||||||
},
|
},
|
||||||
|
netgame={
|
||||||
|
title="在线游戏",
|
||||||
|
test="测试",
|
||||||
|
},
|
||||||
account={
|
account={
|
||||||
title="账户",
|
title="账户",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,6 +8,27 @@ function sceneInit.chat()
|
|||||||
BG.set("none")
|
BG.set("none")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function socketConnect()
|
||||||
|
wsConnect(
|
||||||
|
TICK.wsCONN_connect,
|
||||||
|
"/solo?room_id=114",
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
local function socketWrite()
|
||||||
|
if not WSCONN then
|
||||||
|
LOG.print("尚未连接到服务器","warn")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local message = WIDGET.active.message.value
|
||||||
|
print("TextBox: "..message)
|
||||||
|
local writeErr = client.write(WSCONN, message)
|
||||||
|
if writeErr then
|
||||||
|
print(writeErr, "warn")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
WIDGET.init("chat",{
|
WIDGET.init("chat",{
|
||||||
WIDGET.newTextBox{name="text", x=40, y=500,w=980,h=180,font=40},
|
WIDGET.newTextBox{name="text", x=40, y=500,w=980,h=180,font=40},
|
||||||
WIDGET.newButton{name="send", x=1140, y=540,w=170,h=80,font=40,code=send},
|
WIDGET.newButton{name="send", x=1140, y=540,w=170,h=80,font=40,code=send},
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ function Tmr.load()
|
|||||||
LOADED=true
|
LOADED=true
|
||||||
SFX.play("welcome_sfx")
|
SFX.play("welcome_sfx")
|
||||||
VOC.play("welcome_voc")
|
VOC.play("welcome_voc")
|
||||||
httpRequest(TICK.httpREQ_launch,"/tech/api/v1/app/info")
|
httpRequest(TICK.httpREQ_launch,PATH.api..PATH.appInfo)
|
||||||
if ACCOUNT.auth_token then
|
if ACCOUNT.auth_token and ACCOUNT.email then
|
||||||
local res=json.encode{
|
local res=json.encode{
|
||||||
email=ACCOUNT.email,
|
email=ACCOUNT.email,
|
||||||
auth_token=ACCOUNT.auth_token,
|
auth_token=ACCOUNT.auth_token,
|
||||||
@@ -125,7 +125,7 @@ function Tmr.load()
|
|||||||
if res then
|
if res then
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_autoLogin,
|
TICK.httpREQ_autoLogin,
|
||||||
"/tech/api/v1/users",
|
PATH.api..PATH.auth,
|
||||||
"GET",
|
"GET",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ function keyDown.login(key)
|
|||||||
if res then
|
if res then
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_newLogin,
|
TICK.httpREQ_newLogin,
|
||||||
"/tech/api/v1/users",
|
PATH.api..PATH.auth,
|
||||||
"GET",
|
"GET",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function keyDown.register(key)
|
|||||||
if res then
|
if res then
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_register,
|
TICK.httpREQ_register,
|
||||||
"/tech/api/v1/users",
|
PATH.api..PATH.auth,
|
||||||
"POST",
|
"POST",
|
||||||
{["Content-Type"]="application/json"},
|
{["Content-Type"]="application/json"},
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ function Tick.httpREQ_register(data)
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
LOG.print(text.registerFailed..": "..request_error,"warn")
|
LOG.print(text.loginFailed..": "..request_error,"warn")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return checkTimeout(data,360)
|
return checkTimeout(data,360)
|
||||||
@@ -151,7 +151,7 @@ function Tick.httpREQ_newLogin(data)
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
LOG.print(text.registerFailed..": "..request_error,"warn")
|
LOG.print(text.loginFailed..": "..request_error,"warn")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return checkTimeout(data,360)
|
return checkTimeout(data,360)
|
||||||
@@ -163,7 +163,7 @@ function Tick.httpREQ_autoLogin(data)
|
|||||||
LOGIN=true
|
LOGIN=true
|
||||||
local res=json.decode(response.body)
|
local res=json.decode(response.body)
|
||||||
if res then
|
if res then
|
||||||
LOG.print(text.loginSuccessed..": "..res.message)
|
LOG.print(text.loginSuccessed)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
LOGIN=false
|
LOGIN=false
|
||||||
@@ -174,9 +174,54 @@ function Tick.httpREQ_autoLogin(data)
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
elseif request_error then
|
elseif request_error then
|
||||||
LOG.print(text.registerFailed..": "..request_error,"warn")
|
LOG.print(text.loginFailed..": "..request_error,"warn")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return checkTimeout(data,360)
|
return checkTimeout(data,360)
|
||||||
end
|
end
|
||||||
|
function Tick.wsCONN_connect(data)
|
||||||
|
print("Running wsconntask...")
|
||||||
|
if data.wsconntask then
|
||||||
|
local wsconn,connErr=client.poll(data.wsconntask)
|
||||||
|
if wsconn then
|
||||||
|
WSCONN = wsconn
|
||||||
|
TASK.new(Tick.wsCONN_read,{net=true})
|
||||||
|
return true
|
||||||
|
elseif connErr then
|
||||||
|
LOG.print(text.wsFailed..": "..connErr,"warn")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return checkTimeout(data,360)
|
||||||
|
end
|
||||||
|
function Tick.wsCONN_read(data)
|
||||||
|
if not data.net then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local messages,readErr=client.read(WSCONN)
|
||||||
|
if messages then
|
||||||
|
if messages[1] then
|
||||||
|
print(messages[1])
|
||||||
|
LOG.print("Message: "..messages[1])
|
||||||
|
end
|
||||||
|
elseif readErr then
|
||||||
|
print("Read error: "..readErr)
|
||||||
|
if readErr == "EOF" then
|
||||||
|
LOG.print("Socket closed!","warn")
|
||||||
|
end
|
||||||
|
WSCONN = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- function Tick.wsCONN_write(data)
|
||||||
|
-- if not data.net then
|
||||||
|
-- return true
|
||||||
|
-- end
|
||||||
|
-- local writeErr=client.write(WSCONN,data.message)
|
||||||
|
-- if writeErr then
|
||||||
|
-- print(writeErr, "warn")
|
||||||
|
-- end
|
||||||
|
-- return true
|
||||||
|
-- end
|
||||||
|
|
||||||
return Tick
|
return Tick
|
||||||
Reference in New Issue
Block a user