diff --git a/Zframework/task.lua b/Zframework/task.lua index 462e7164..3f4bee7d 100644 --- a/Zframework/task.lua +++ b/Zframework/task.lua @@ -45,13 +45,6 @@ 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 diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index df117645..d7202346 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -542,7 +542,7 @@ do--urlencode return out end end -do--httpRequest +do--httpRequest & wsConnect client=LOADLIB("NETlib") httpRequest= client and function(tick,path,method,header,body) diff --git a/Zframework/widget.lua b/Zframework/widget.lua index aabb8c8f..39ddb7c7 100644 --- a/Zframework/widget.lua +++ b/Zframework/widget.lua @@ -809,28 +809,26 @@ 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 + json.encode{ + email=ACCOUNT.email, + access_token=ACCOUNT.access_token, + } ) 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 + json.encode{ + email=ACCOUNT.email, + auth_token=ACCOUNT.auth_token, + } ) end else diff --git a/parts/globalTables.lua b/parts/globalTables.lua index 3db7d768..47222c07 100644 --- a/parts/globalTables.lua +++ b/parts/globalTables.lua @@ -283,7 +283,7 @@ SETTING={ } STAT={ - version=VERSION_NAME, + version=VERSION_CODE, run=0,game=0,time=0,frame=0, key=0,rotate=0,hold=0, extraPiece=0,finesseRate=0, diff --git a/parts/scenes/chat.lua b/parts/scenes/chat.lua index 457a40a3..5d713480 100644 --- a/parts/scenes/chat.lua +++ b/parts/scenes/chat.lua @@ -1,32 +1,40 @@ local function socketWrite(message) - if not WSCONN then + if WSCONN then + local writeErr=client.write(WSCONN,message) + if writeErr then print(writeErr,"warn")end + else LOG.print("尚未连接到服务器","warn") - return end - local writeErr = client.write(WSCONN, message) - if writeErr then - print(writeErr, "warn") - end - return true end -local function send() +local function sendMessage() local W=WIDGET.active.text - socketWrite(W.value) - W.value="" + if #W.value>0 then + socketWrite(W.value) + W.value="" + end end function sceneInit.chat() BG.set("none") wsConnect( TICK.wsCONN_connect, - PATH.socket..PATH.chat.."?email="..urlEncode(ACCOUNT.email).."&access_token="..urlEncode(ACCOUNT.access_token), - {} + PATH.socket..PATH.chat.."?email="..urlEncode(ACCOUNT.email).."&access_token="..urlEncode(ACCOUNT.access_token) ) end +function keyDown.chat(k) + if k=="return"then + sendMessage() + elseif k=="escape"then + SCN.back() + else + WIDGET.keyPressed(k) + end +end + WIDGET.init("chat",{ 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=sendMessage}, WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=WIDGET.lnk_BACK}, }) \ No newline at end of file diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index 5f448d43..c38672f6 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -118,19 +118,16 @@ function Tmr.load() VOC.play("welcome_voc") httpRequest(TICK.httpREQ_launch,PATH.api..PATH.appInfo) if ACCOUNT.auth_token and ACCOUNT.email then - local res=json.encode{ - email=ACCOUNT.email, - auth_token=ACCOUNT.auth_token, - } - if res then - httpRequest( - TICK.httpREQ_autoLogin, - PATH.api..PATH.auth, - "GET", - {["Content-Type"]="application/json"}, - res - ) - end + httpRequest( + TICK.httpREQ_autoLogin, + PATH.api..PATH.auth, + "GET", + {["Content-Type"]="application/json"}, + json.encode{ + email=ACCOUNT.email, + auth_token=ACCOUNT.auth_token, + } + ) end end if S.tar then diff --git a/parts/scenes/login.lua b/parts/scenes/login.lua index 0af34e34..6b8a2e63 100644 --- a/parts/scenes/login.lua +++ b/parts/scenes/login.lua @@ -7,19 +7,16 @@ function keyDown.login(key) elseif #password==0 then LOG.print(text.noPassword)return end - local res=json.encode{ - email=email, - password=password, - } - if res then - httpRequest( - TICK.httpREQ_newLogin, - PATH.api..PATH.auth, - "GET", - {["Content-Type"]="application/json"}, - res - ) - end + httpRequest( + TICK.httpREQ_newLogin, + PATH.api..PATH.auth, + "GET", + {["Content-Type"]="application/json"}, + json.encode{ + email=email, + password=password, + } + ) elseif key=="escape"then SCN.back() else diff --git a/parts/scenes/register.lua b/parts/scenes/register.lua index 8e711c4a..e9b6f70f 100644 --- a/parts/scenes/register.lua +++ b/parts/scenes/register.lua @@ -13,20 +13,17 @@ function keyDown.register(key) elseif password~=password2 then LOG.print(text.diffPassword)return end - local res=json.encode{ - username=username, - email=email, - password=password, - } - if res then - httpRequest( - TICK.httpREQ_register, - PATH.api..PATH.auth, - "POST", - {["Content-Type"]="application/json"}, - res - ) - end + httpRequest( + TICK.httpREQ_register, + PATH.api..PATH.auth, + "POST", + {["Content-Type"]="application/json"}, + json.encode{ + username=username, + email=email, + password=password, + } + ) elseif key=="escape"then SCN.back() else diff --git a/parts/tick.lua b/parts/tick.lua index 812f3a05..dca874ce 100644 --- a/parts/tick.lua +++ b/parts/tick.lua @@ -146,16 +146,15 @@ function Tick.httpREQ_newLogin(data) ACCOUNT.auth_token=res.auth_token FILE.save(ACCOUNT,"account","") - 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 + json.encode{ + email=ACCOUNT.email, + auth_token=ACCOUNT.auth_token, + } ) else LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") @@ -199,16 +198,15 @@ function Tick.httpREQ_checkAccessToken(data) SCN.pop() SCN.go("netgame") elseif response.code==403 or response.code==401 then - 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 + json.encode{ + email=ACCOUNT.email, + auth_token=ACCOUNT.auth_token, + } ) else local err=json.decode(response.body) @@ -264,7 +262,7 @@ function Tick.wsCONN_connect(data) local wsconn,connErr=client.poll(data.wsconntask) if wsconn then WSCONN = wsconn - TASK.new(Tick.wsCONN_read,{net=true}) + TASK.new(Tick.wsCONN_read) return true elseif connErr then LOG.print(text.wsFailed..": "..connErr,"warn") @@ -273,10 +271,7 @@ function Tick.wsCONN_connect(data) end return checkTimeout(data,360) end -function Tick.wsCONN_read(data) - if not data.net then - return true - end +function Tick.wsCONN_read() local messages,readErr=client.read(WSCONN) if messages then if messages[1] then