收拾掉旧的联网相关函数准备换新
This commit is contained in:
@@ -3,72 +3,6 @@ local tc=love.touch
|
|||||||
|
|
||||||
local max,min,sin=math.max,math.min,math.sin
|
local max,min,sin=math.max,math.min,math.sin
|
||||||
|
|
||||||
local function tick_httpREQ_launch(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
local res=json.decode(response.body)
|
|
||||||
if res.message=="OK"and response.code==200 then
|
|
||||||
LOG.print(res.notice,360,COLOR.sky)
|
|
||||||
if VERSION_CODE>=res.version_code then
|
|
||||||
LATEST_VERSION=true
|
|
||||||
else
|
|
||||||
LOG.print(string.gsub(text.oldVersion,"$1",res.version_name),"warn")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.getNoticeFail..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.getNoticeFail..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local function tick_httpREQ_autoLogin(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
local res=json.decode(response.body)
|
|
||||||
if response.code==200 and res.message=="OK"then
|
|
||||||
LOGIN=true
|
|
||||||
LOG.print(text.loginSuccessed)
|
|
||||||
httpRequest(
|
|
||||||
TICK_httpREQ_getUserInfo,
|
|
||||||
PATH.http..PATH.user,
|
|
||||||
"GET",
|
|
||||||
{["Content-Type"]="application/json"},
|
|
||||||
json.encode{
|
|
||||||
email=USER.email,
|
|
||||||
auth_token=USER.auth_token,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else
|
|
||||||
LOGIN=false
|
|
||||||
LOG.print(text.loginFailed..": "..text.httpCode..response.code.."-"..res.message,"warn")
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.loginFailed..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.loginFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local scene={}
|
local scene={}
|
||||||
|
|
||||||
local time--Animation timer
|
local time--Animation timer
|
||||||
|
|||||||
@@ -1,55 +1,3 @@
|
|||||||
local function tick_httpREQ_newLogin(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
local res=json.decode(response.body)
|
|
||||||
if response.code==200 and res.message=="OK"then
|
|
||||||
LOGIN=true
|
|
||||||
USER.email=res.email
|
|
||||||
USER.auth_token=res.auth_token
|
|
||||||
USER.id=res.id
|
|
||||||
FILE.save(USER,"conf/user","q")
|
|
||||||
LOG.print(text.loginSuccessed)
|
|
||||||
|
|
||||||
httpRequest(
|
|
||||||
TICK_httpREQ_getUserInfo,
|
|
||||||
PATH.http..PATH.user,
|
|
||||||
"GET",
|
|
||||||
{["Content-Type"]="application/json"},
|
|
||||||
json.encode{
|
|
||||||
email=USER.email,
|
|
||||||
auth_token=USER.auth_token,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
httpRequest(
|
|
||||||
TICK_httpREQ_getAccessToken,
|
|
||||||
PATH.http..PATH.access,
|
|
||||||
"POST",
|
|
||||||
{["Content-Type"]="application/json"},
|
|
||||||
json.encode{
|
|
||||||
email=USER.email,
|
|
||||||
auth_token=USER.auth_token,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else
|
|
||||||
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.loginFailed..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.loginFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function login()
|
local function login()
|
||||||
local email= WIDGET.active.email.value
|
local email= WIDGET.active.email.value
|
||||||
local password= WIDGET.active.password.value
|
local password= WIDGET.active.password.value
|
||||||
@@ -59,16 +7,10 @@ local function login()
|
|||||||
LOG.print(text.noPassword)return
|
LOG.print(text.noPassword)return
|
||||||
end
|
end
|
||||||
--[[TODO
|
--[[TODO
|
||||||
httpRequest(
|
|
||||||
tick_httpREQ_newLogin,
|
|
||||||
PATH.http..PATH.auth,
|
|
||||||
"POST",
|
|
||||||
{["Content-Type"]="application/json"},
|
|
||||||
json.encode{
|
json.encode{
|
||||||
email=email,
|
email=email,
|
||||||
password=password,
|
password=password,
|
||||||
}
|
}
|
||||||
)
|
|
||||||
]]
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +1,5 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
|
|
||||||
local function tick_httpREQ_manualAutoLogin(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
if response.code==200 then
|
|
||||||
LOG.print(text.accessSuccessed)
|
|
||||||
SCN.go("net_menu")
|
|
||||||
elseif response.code==403 or response.code==401 then
|
|
||||||
httpRequest(
|
|
||||||
TICK_httpREQ_getAccessToken,
|
|
||||||
PATH.http..PATH.access,
|
|
||||||
"POST",
|
|
||||||
{["Content-Type"]="application/json"},
|
|
||||||
json.encode{
|
|
||||||
email=USER.email,
|
|
||||||
auth_token=USER.auth_token,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else
|
|
||||||
local err=json.decode(response.body)
|
|
||||||
if err then
|
|
||||||
LOG.print(text.httpCode..response.code..": "..err.message,"warn")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.loginFailed..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.loginFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local scene={}
|
local scene={}
|
||||||
|
|
||||||
local tip=gc.newText(getFont(30),"")
|
local tip=gc.newText(getFont(30),"")
|
||||||
|
|||||||
@@ -1,25 +1,3 @@
|
|||||||
local function tick_goChatRoom(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local wsconn,connErr=client.poll(task)
|
|
||||||
if wsconn then
|
|
||||||
WSCONN=wsconn
|
|
||||||
SCN.go("net_chat")
|
|
||||||
LOG.print(text.wsSuccessed,"warn")
|
|
||||||
return
|
|
||||||
elseif connErr then
|
|
||||||
LOG.print(text.wsFailed..": "..connErr,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.wsFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local scene={}
|
local scene={}
|
||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
@@ -30,12 +8,12 @@ scene.widgetList={
|
|||||||
WIDGET.newButton{name="ffa", x=640, y=200,w=350,h=120,font=40,code=NULL},
|
WIDGET.newButton{name="ffa", x=640, y=200,w=350,h=120,font=40,code=NULL},
|
||||||
WIDGET.newButton{name="rooms", x=640, y=360,w=350,h=120,font=40,code=goScene"net_rooms"},
|
WIDGET.newButton{name="rooms", x=640, y=360,w=350,h=120,font=40,code=goScene"net_rooms"},
|
||||||
WIDGET.newButton{name="chat", x=640, y=540,w=350,h=120,font=40,code=function()
|
WIDGET.newButton{name="chat", x=640, y=540,w=350,h=120,font=40,code=function()
|
||||||
wsConnect(
|
--[[TODO
|
||||||
tick_goChatRoom,
|
wsConnect("chat","/chat",json.encode{
|
||||||
PATH.socket..PATH.onlineChat..
|
email=USER.email,
|
||||||
"?email="..urlEncode(USER.email)..
|
token=USER.access_token,
|
||||||
"&token="..urlEncode(USER.access_token)
|
})
|
||||||
)
|
]]
|
||||||
end},
|
end},
|
||||||
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene},
|
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,100 +6,26 @@ local scrollPos,selected
|
|||||||
local lastfreshTime
|
local lastfreshTime
|
||||||
local lastCreateRoomTime=0
|
local lastCreateRoomTime=0
|
||||||
|
|
||||||
local function task_enterRoom(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local wsconn,connErr=client.poll(task)
|
|
||||||
if wsconn then
|
|
||||||
WSCONN=wsconn
|
|
||||||
loadGame("netBattle",true,true)
|
|
||||||
LOG.print(text.wsSuccessed,"warn")
|
|
||||||
return
|
|
||||||
elseif connErr then
|
|
||||||
LOG.print(text.wsFailed..": "..connErr,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.wsFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local function enterRoom(roomID)
|
local function enterRoom(roomID)
|
||||||
wsConnect(
|
--[[TODO
|
||||||
task_enterRoom,
|
wsWrite("???",json.encode{
|
||||||
PATH.socket..PATH.onlinePlay..
|
email=USER.email,
|
||||||
"?email="..urlEncode(USER.email)..
|
token=USER.access_token,
|
||||||
"&token="..urlEncode(USER.access_token)..
|
id=roomID,
|
||||||
"&id="..urlEncode(roomID)..
|
conf=dumpBasicConfig(),
|
||||||
"&conf="..urlEncode(dumpBasicConfig())
|
-- password=password,
|
||||||
-- "&password="..urlEncode(password),
|
})
|
||||||
)
|
]]
|
||||||
end
|
|
||||||
local function task_fetchRooms(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
local res=json.decode(response.body)
|
|
||||||
if response.code==200 and res.message=="OK"then
|
|
||||||
rooms=res.room_list
|
|
||||||
else
|
|
||||||
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.roomsFetchFailed..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>210 then
|
|
||||||
LOG.print(text.roomsFetchFailed..": "..text.httpTimeout,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local function task_createRoom(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
local res=json.decode(response.body)
|
|
||||||
if response.code==200 and res.message=="OK"then
|
|
||||||
LOG.print(text.createRoomSuccessed)
|
|
||||||
enterRoom(res.room.id)
|
|
||||||
else
|
|
||||||
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.roomsCreateFailed..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>210 then
|
|
||||||
LOG.print(text.roomsCreateFailed..": "..text.httpTimeout,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local function fresh()
|
local function fresh()
|
||||||
lastfreshTime=TIME()
|
lastfreshTime=TIME()
|
||||||
rooms=nil
|
rooms=nil
|
||||||
httpRequest(
|
--[[TODO
|
||||||
task_fetchRooms,
|
wsWrite("???",json.encode{
|
||||||
PATH.http..PATH.onlinePlay,
|
email=USER.email,
|
||||||
"GET",
|
access_token=USER.access_token,
|
||||||
{["Content-Type"]="application/json"},
|
})
|
||||||
json.encode{
|
]]
|
||||||
email=USER.email,
|
|
||||||
access_token=USER.access_token,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local scene={}
|
local scene={}
|
||||||
@@ -121,18 +47,14 @@ function scene.keyDown(k)
|
|||||||
end
|
end
|
||||||
elseif k=="n"then
|
elseif k=="n"then
|
||||||
if TIME()-lastCreateRoomTime>26 then
|
if TIME()-lastCreateRoomTime>26 then
|
||||||
httpRequest(
|
--[[TODO
|
||||||
task_createRoom,
|
wsWrite("???",json.encode{
|
||||||
PATH.http..PATH.onlinePlay.."/classic",
|
email=USER.email,
|
||||||
"POST",
|
access_token=USER.access_token,
|
||||||
{["Content-Type"]="application/json"},
|
room_name=(USER.name or"???").."'s room",
|
||||||
json.encode{
|
room_password=nil,
|
||||||
email=USER.email,
|
})
|
||||||
access_token=USER.access_token,
|
]]
|
||||||
room_name=(USER.name or"???").."'s room",
|
|
||||||
room_password=nil,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
lastCreateRoomTime=TIME()
|
lastCreateRoomTime=TIME()
|
||||||
else
|
else
|
||||||
LOG.print(text.createRoomTooFast,"warn")
|
LOG.print(text.createRoomTooFast,"warn")
|
||||||
|
|||||||
@@ -1,34 +1,3 @@
|
|||||||
local function tick_httpREQ_register(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local response,request_error=client.poll(task)
|
|
||||||
if response then
|
|
||||||
local res=json.decode(response.body)
|
|
||||||
if response.code==200 and res.message=="OK"then
|
|
||||||
LOGIN=true
|
|
||||||
USER.name=res.name
|
|
||||||
USER.id=res.id
|
|
||||||
USER.motto=res.motto
|
|
||||||
USER.avatar=res.avatar
|
|
||||||
FILE.save(USER,"conf/user","q")
|
|
||||||
LOG.print(text.registerSuccessed..": "..res.message)
|
|
||||||
else
|
|
||||||
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif request_error then
|
|
||||||
LOG.print(text.loginFailed..": "..request_error,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.loginFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local scene={}
|
local scene={}
|
||||||
|
|
||||||
function scene.keyDown(key)
|
function scene.keyDown(key)
|
||||||
@@ -46,17 +15,13 @@ function scene.keyDown(key)
|
|||||||
elseif password~=password2 then
|
elseif password~=password2 then
|
||||||
LOG.print(text.diffPassword)return
|
LOG.print(text.diffPassword)return
|
||||||
end
|
end
|
||||||
httpRequest(
|
--[[
|
||||||
tick_httpREQ_register,
|
|
||||||
PATH.http..PATH.auth,
|
|
||||||
"POST",
|
|
||||||
{["Content-Type"]="application/json"},
|
|
||||||
json.encode{
|
json.encode{
|
||||||
username=username,
|
username=username,
|
||||||
email=email,
|
email=email,
|
||||||
password=password,
|
password=password,
|
||||||
}
|
}
|
||||||
)
|
]]
|
||||||
elseif key=="escape"then
|
elseif key=="escape"then
|
||||||
SCN.back()
|
SCN.back()
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user