实现玩家设置同步到服务器
实现玩家离开房间(各种途径) 修改云存读档代码(还未实现) 移除sid,准备之后用uid本地排序序号代替(排序还未实现) 整理代码,框架跟进
This commit is contained in:
Submodule Zframework updated: 98f0fff6b0...d86dba11ea
@@ -7,7 +7,7 @@ local function getRollGoal(P)
|
||||
if rem<=0 then return 0 end
|
||||
local goal=math.floor(rem)*4
|
||||
rem=rem%1
|
||||
return goal + (rem>0.3 and 4 or rem*10)
|
||||
return goal+(rem>0.3 and 4 or rem*10)
|
||||
end
|
||||
|
||||
return{
|
||||
|
||||
@@ -111,11 +111,11 @@ local function getRollGoal()
|
||||
if cools>8 then
|
||||
goal=math.floor(rem)*4
|
||||
rem=rem%1
|
||||
return goal + (rem>0.3 and 4 or rem*10)
|
||||
return goal+(rem>0.3 and 4 or rem*10)
|
||||
else
|
||||
goal=math.floor(rem/0.26)*4
|
||||
rem=rem%0.26
|
||||
return goal + (rem>0.12 and 4 or rem*25)
|
||||
return goal+(rem>0.12 and 4 or rem*25)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -100,8 +100,14 @@ function saveProgress()
|
||||
return saveFile(RANKS,'conf/unlock')
|
||||
end
|
||||
function saveSettings()
|
||||
if WS.status('game')=='running' then
|
||||
NET.player_updateConf()
|
||||
end
|
||||
return saveFile(SETTING,'conf/settings')
|
||||
end
|
||||
function saveUser()
|
||||
return saveFile(USER.__data,'conf/user')
|
||||
end
|
||||
do-- function applySettings()
|
||||
local saturateValues={
|
||||
normal={0,1},
|
||||
@@ -857,7 +863,7 @@ function drawOnlinePlayerCount()
|
||||
gc_setColor(1,1,1)
|
||||
gc_push('transform')
|
||||
gc_replaceTransform(SCR.xOy_ur)
|
||||
gc_printf(text.onlinePlayerCount..":"..NET.onlineCount,-600,80,594,'right')
|
||||
gc_printf(text.onlinePlayerCount:repD(NET.onlineCount),-600,80,594,'right')
|
||||
gc_pop()
|
||||
end
|
||||
function drawWarning()
|
||||
|
||||
@@ -576,6 +576,7 @@ end
|
||||
do-- Userdata tables
|
||||
USER=setmetatable({-- User infomation
|
||||
__data={
|
||||
uid=false,
|
||||
email=false,
|
||||
password=false,
|
||||
rToken=false,
|
||||
@@ -588,7 +589,6 @@ do-- Userdata tables
|
||||
__newindex=function(self,k,v)
|
||||
if self.__data[k]~=nil and v~=nil then
|
||||
self.__data[k]=v
|
||||
saveFile(USER.__data,'conf/user')
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -133,8 +133,9 @@ return{
|
||||
serverDown="Oops! Server is down",
|
||||
requestFailed="Request failed",
|
||||
|
||||
onlinePlayerCount="Online",
|
||||
onlinePlayerCount="Online: $1",
|
||||
createRoomSuccessed="Room created",
|
||||
playerKicked="[$1] removed [$2] from room",
|
||||
started="Playing",
|
||||
joinRoom="has entered the room.",
|
||||
leaveRoom="has left the room.",
|
||||
|
||||
@@ -132,8 +132,9 @@ return{
|
||||
-- serverDown="Oops! Server is down",
|
||||
-- requestFailed="Request failed",
|
||||
|
||||
onlinePlayerCount="En línea",
|
||||
onlinePlayerCount="En línea: $1",
|
||||
createRoomSuccessed="¡Sala creada con éxito!",
|
||||
-- playerKicked="[$1] removed [$2] from room",
|
||||
started="En juego",
|
||||
joinRoom="entró a la sala.",
|
||||
leaveRoom="salió de la sala.",
|
||||
|
||||
@@ -123,8 +123,9 @@ return{
|
||||
-- serverDown="Oops! Server is down",
|
||||
-- requestFailed="Request failed",
|
||||
|
||||
-- onlinePlayerCount="Online",
|
||||
-- onlinePlayerCount="Online: $1",
|
||||
createRoomSuccessed="Salon créé avec succès !",
|
||||
-- playerKicked="[$1] removed [$2] from room",
|
||||
-- started="Playing",
|
||||
joinRoom="a rejoint le salon.",
|
||||
leaveRoom="a quitté le salon.",
|
||||
|
||||
@@ -134,8 +134,9 @@ return{
|
||||
-- serverDown="Oops! Server is down",
|
||||
-- requestFailed="Request failed",
|
||||
|
||||
onlinePlayerCount="Online",
|
||||
onlinePlayerCount="Online: $1",
|
||||
createRoomSuccessed="Ruang terbuat",
|
||||
-- playerKicked="[$1] removed [$2] from room",
|
||||
started="Bermain",
|
||||
joinRoom="telah memasuki ruangan.",
|
||||
leaveRoom="telah keluar dari ruangan.",
|
||||
|
||||
@@ -134,8 +134,9 @@ return{
|
||||
-- serverDown="Oops! Server is down",
|
||||
-- requestFailed="Request failed",
|
||||
|
||||
onlinePlayerCount="オンライン人数",
|
||||
onlinePlayerCount="オンライン人数: $1",
|
||||
createRoomSuccessed="部屋を建てました",
|
||||
-- playerKicked="[$1] removed [$2] from room",
|
||||
started="プレイ中",
|
||||
joinRoom="が入室しました",
|
||||
leaveRoom="が退出しました",
|
||||
|
||||
@@ -121,8 +121,9 @@ return{
|
||||
-- serverDown="Oops! Server is down",
|
||||
-- requestFailed="Request failed",
|
||||
|
||||
-- onlinePlayerCount="Online",
|
||||
-- onlinePlayerCount="Online: $1",
|
||||
-- createRoomSuccessed="Room successfully created!",
|
||||
-- playerKicked="[$1] removed [$2] from room",
|
||||
-- started="Playing",
|
||||
joinRoom="Entrou a sala.",
|
||||
leaveRoom="Saiu da sala.",
|
||||
@@ -135,7 +136,7 @@ return{
|
||||
chatHistory="------Novas mensagens abaixo------",
|
||||
|
||||
|
||||
|
||||
|
||||
-- keySettingInstruction="Press to bind key\nescape: cancel\nbackspace: delete",
|
||||
-- customBGhelp="Drop image file here to apply custom background",
|
||||
-- customBGloadFailed="Unsupport image format for custom background",
|
||||
|
||||
@@ -133,8 +133,9 @@ return{
|
||||
serverDown="唉哟!服务器不在线",
|
||||
requestFailed="请求失败",
|
||||
|
||||
onlinePlayerCount="在线人数",
|
||||
onlinePlayerCount="在线人数: $1",
|
||||
createRoomSuccessed="创建房间成功!",
|
||||
playerKicked="<$1>把<$2>移出了房间",
|
||||
started="游戏中",
|
||||
joinRoom="进入房间",
|
||||
leaveRoom="离开房间",
|
||||
@@ -153,7 +154,7 @@ return{
|
||||
customBGloadFailed="自定义背景的图片文件格式不支持",
|
||||
|
||||
errorMsg="Techmino遭受了雷击,需要重新启动。\n我们已收集了一些错误信息,你可以向作者进行反馈。",
|
||||
tryAnotherBuild="[解码UTF-8错误] 如果你现在用的是Windows系统,请重新下载 Techmino-32位 或者 Techmino-64位 (和现在运行的不一样的那个)。",
|
||||
tryAnotherBuild="[解码UTF-8错误] 如果你现在用的是Windows系统,请重新下载 Techmino-32/64位 (和现在运行的不一样的那个)。",
|
||||
|
||||
modInstruction="选择你要使用的Mod!\n不同Mod会用不同的方式改变初始游戏规则(可能导致不能正常游玩)\n来开发新玩法或者挑战自我吧!\n提醒:开启一些Mod会让成绩无效,你也可以用键盘开关Mod,按住shift反向",
|
||||
modInfo={
|
||||
|
||||
@@ -133,8 +133,9 @@ return{
|
||||
serverDown="Error.ServerDown();",
|
||||
requestFailed="Error.RequestFailed();",
|
||||
|
||||
onlinePlayerCount="OnlinePlayerCount",
|
||||
onlinePlayerCount="OnlinePlayerCount=$1",
|
||||
createRoomSuccessed="CreateRoom.Successs=true",
|
||||
playerKicked="[$1]: roomKick([$2])",
|
||||
started="Room.Playing();",
|
||||
joinRoom="Room.Join();",
|
||||
leaveRoom="Room.Leave();",
|
||||
@@ -153,7 +154,7 @@ return{
|
||||
customBGloadFailed="Error.Ctm.BG(UnsupportFormat);",
|
||||
|
||||
errorMsg="Error.Fatal();\n//请检查语法错误或向作者进行反馈。",
|
||||
tryAnotherBuild="Error.DecodeUTF8(); //如果你现在用的是Windows系统,请重新下载 Techmino-32位 或者 Techmino-64位 (和现在运行的不一样的那个)。",
|
||||
tryAnotherBuild="Error.DecodeUTF8(); //如果你现在用的是Windows系统,请重新下载 Techmino-32/64位 (和现在运行的不一样的那个)。",
|
||||
|
||||
modInstruction="Mod.Instruction();\n/*选择你要使用的Mod\n不同Mod会用不同的方式改变初始游戏规则(可能导致不能正常游玩)\n提醒:开启一些Mod会让成绩无效,你也可以用键盘开关Mod,按住shift反向*/",
|
||||
modInfo={
|
||||
|
||||
@@ -133,8 +133,9 @@ return{
|
||||
serverDown="哎唷!服務器不在线",
|
||||
requestFailed="請求失敗",
|
||||
|
||||
onlinePlayerCount="在線用戶數",
|
||||
onlinePlayerCount="在線用戶數: $1",
|
||||
createRoomSuccessed="房間已創建!",
|
||||
playerKicked="<$1>把<$2>移出了房間",
|
||||
started="遊戲中",
|
||||
joinRoom="進入房間",
|
||||
leaveRoom="離開房間",
|
||||
@@ -153,7 +154,7 @@ return{
|
||||
customBGloadFailed="自定義背景的圖片檔案格式不支持",
|
||||
|
||||
errorMsg="Techmino遇到問題,需要重新啟動。\n我們已經收集了一些錯誤信息,你可以反饋給作者。",
|
||||
tryAnotherBuild="[無效的 UTF-8] 如果你使用的是Windows作業系統,請嘗試下載Techmino-win32或Techmino-win64(與你現在使用的不同的版本)。",
|
||||
tryAnotherBuild="[無效的UTF-8] 如果你使用的是Windows作業系統,請嘗試下載Techmino-win32或Techmino-win64(與你現在使用的不同的版本)。",
|
||||
|
||||
modInstruction="選擇你想使用的Mod!\n不同的Mod會以不同的方式改變遊戲規則(可能導致遊戲異常)\n快來開發新玩法或挑戰自我吧!\n提醒:開啟Mod會使成績無效,你可以使用鍵盤開關Mod,按下shift反向",
|
||||
modInfo={
|
||||
|
||||
@@ -24,7 +24,6 @@ return{
|
||||
if p.uid==USER.uid then
|
||||
if p.connected then
|
||||
PLY.newPlayer(1)
|
||||
PLAYERS[1].sid=NETPLY.getSID(USER.uid)
|
||||
N=2
|
||||
end
|
||||
table.remove(L,i)
|
||||
|
||||
213
parts/net.lua
213
parts/net.lua
@@ -1,9 +1,8 @@
|
||||
local WS=WS
|
||||
|
||||
local NET={
|
||||
allow_online=false,
|
||||
accessToken=false,
|
||||
cloudData={},
|
||||
uid=false,
|
||||
uid_sid={},
|
||||
|
||||
roomState={-- A copy of room structure on server
|
||||
info={
|
||||
@@ -17,8 +16,8 @@ local NET={
|
||||
private=false,
|
||||
start=false,
|
||||
},
|
||||
|
||||
spectate=false,-- If player is spectating
|
||||
specSRID=false,-- Cached SRID when enter playing room, for connect WS after scene swapped
|
||||
seed=false,
|
||||
|
||||
roomReadyState=false,
|
||||
@@ -26,7 +25,7 @@ local NET={
|
||||
onlineCount="_",
|
||||
|
||||
textBox=WIDGET.newTextBox{name='texts',x=340,y=80,w=600,h=560},
|
||||
inputBox=WIDGET.newInputBox{name='input',x=340,y=660,w=600,h=50,limit=256},
|
||||
inputBox=WIDGET.newInputBox{name='input',x=340,y=660,w=600,h=50,limit=256},
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +115,7 @@ function NET.getCode(email)
|
||||
if res then
|
||||
if res.code==200 then
|
||||
USER.email=email
|
||||
saveUser()
|
||||
SCN.fileDropped(2)
|
||||
MES.new('info',text.checkEmail,5)
|
||||
end
|
||||
@@ -148,6 +148,7 @@ function NET.codeLogin(code)
|
||||
if res.code==200 then
|
||||
USER.rToken=res.data.refreshToken
|
||||
USER.aToken=res.data.accessToken
|
||||
USER.uid=res.data.playerId
|
||||
NET.ws_connect()
|
||||
SCN.pop()SCN.go('net_menu')
|
||||
elseif res.code==201 then
|
||||
@@ -156,6 +157,7 @@ function NET.codeLogin(code)
|
||||
SCN.pop()SCN.push('net_menu')
|
||||
SCN.fileDropped(3)
|
||||
end
|
||||
saveUser()
|
||||
end
|
||||
|
||||
WAIT.interrupt()
|
||||
@@ -188,6 +190,7 @@ function NET.setPW(code,pw)
|
||||
if res then
|
||||
if res.code==200 then
|
||||
USER.password=pw
|
||||
saveUser()
|
||||
SCN.back()
|
||||
end
|
||||
end
|
||||
@@ -216,6 +219,8 @@ function NET.autoLogin()
|
||||
|
||||
if res then
|
||||
if res.code==200 then
|
||||
USER.uid=res.data.playerId
|
||||
saveUser()
|
||||
NET.ws_connect()
|
||||
SCN.go('net_menu')
|
||||
WAIT.interrupt()
|
||||
@@ -237,6 +242,8 @@ function NET.autoLogin()
|
||||
if res.code==200 then
|
||||
USER.rToken=res.data.refreshToken
|
||||
USER.aToken=res.data.accessToken
|
||||
USER.uid=res.data.playerId
|
||||
saveUser()
|
||||
NET.ws_connect()
|
||||
SCN.go('net_menu')
|
||||
WAIT.interrupt()
|
||||
@@ -260,6 +267,8 @@ function NET.autoLogin()
|
||||
if res.code==200 then
|
||||
USER.rToken=res.data.refreshToken
|
||||
USER.aToken=res.data.accessToken
|
||||
USER.uid=res.data.playerId
|
||||
saveUser()
|
||||
NET.ws_connect()
|
||||
SCN.go('net_menu')
|
||||
WAIT.interrupt()
|
||||
@@ -303,6 +312,8 @@ function NET.pwLogin(email,pw)
|
||||
USER.password=pw
|
||||
USER.rToken=res.data.refreshToken
|
||||
USER.aToken=res.data.accessToken
|
||||
USER.uid=res.data.playerId
|
||||
saveUser()
|
||||
NET.ws_connect()
|
||||
SCN.go('net_menu')
|
||||
end
|
||||
@@ -312,13 +323,11 @@ function NET.pwLogin(email,pw)
|
||||
end)
|
||||
end
|
||||
|
||||
--Remove player when leave
|
||||
local function _removePlayer(L,sid)
|
||||
for i=1,#L do
|
||||
if L[i].sid==sid then
|
||||
return table.remove(L,i)
|
||||
end
|
||||
end
|
||||
function NET.getUserInfo(uid)
|
||||
wsSend({
|
||||
uid=uid,
|
||||
hash=USERS.getHash(uid),
|
||||
})
|
||||
end
|
||||
|
||||
--------------------------<NEW WS API>
|
||||
@@ -351,13 +360,23 @@ local actMap={
|
||||
|
||||
local function wsSend(act,data)
|
||||
-- print(("Send: $1 -->"):repD(act))
|
||||
-- print(("Send: $1 -->"):repD(act)) print(TABLE.dump(data),"\n")
|
||||
-- print(("Send: $1 -->"):repD(act)) print(type(data)=='table' and TABLE.dump(data) or tostring(data),"\n")
|
||||
WS.send('game',JSON.encode{
|
||||
action=assert(act),
|
||||
data=data,
|
||||
})
|
||||
end
|
||||
|
||||
--Remove player when leave
|
||||
local function _playerLeaveRoom(uid)
|
||||
NETPLY.remove(uid)
|
||||
for i=1,#PLAYERS do if PLAYERS[i].uid==uid then table.remove(PLAYERS,i) break end end
|
||||
for i=1,#PLY_ALIVE do if PLY_ALIVE[i].uid==uid then table.remove(PLAYERS,i) break end end
|
||||
if uid==USER.uid and SCN.cur=='net_game' then
|
||||
SCN.back()
|
||||
end
|
||||
end
|
||||
|
||||
-- Global
|
||||
function NET.global_getOnlineCount()
|
||||
wsSend(actMap.global_getOnlineCount)
|
||||
@@ -479,6 +498,8 @@ function NET.player_setPlaying(playing)
|
||||
end
|
||||
|
||||
-- Match
|
||||
function NET.match_techminohaowan(arg)
|
||||
end
|
||||
|
||||
-- WS
|
||||
NET.wsCallBack={}
|
||||
@@ -497,6 +518,7 @@ function NET.wsCallBack.room_chat(body)
|
||||
end
|
||||
end
|
||||
function NET.wsCallBack.room_create(body)
|
||||
MES.new('check',text.createRoomSuccessed)
|
||||
NET.wsCallBack.room_enter(body)
|
||||
end
|
||||
function NET.wsCallBack.room_getData(body)
|
||||
@@ -522,30 +544,14 @@ function NET.wsCallBack.room_enter(body)-- TODO
|
||||
WAIT.interrupt()
|
||||
end
|
||||
function NET.wsCallBack.room_kick(body)
|
||||
if body.data then
|
||||
-- local eid=body.data.executorId
|
||||
local uid=body.data.targetId
|
||||
NETPLY.remove(uid)
|
||||
_removePlayer(PLAYERS,uid)
|
||||
_removePlayer(PLY_ALIVE,uid)
|
||||
end
|
||||
MES.new('info',text.playerKicked:repD(body.data.executorId,body.data.playerId))
|
||||
_playerLeaveRoom(body.data.playerId)
|
||||
end
|
||||
function NET.wsCallBack.room_leave(body)
|
||||
if body.data then
|
||||
if body.type=='Server' then
|
||||
if SCN.cur=='net_game' then
|
||||
if SCN.stack[#SCN.stack-1]=='net_newRoom' then
|
||||
SCN.pop()
|
||||
end
|
||||
SCN.back()
|
||||
end
|
||||
elseif body.type=='Client' then
|
||||
local uid=body.data.playerId
|
||||
NETPLY.remove(uid)
|
||||
_removePlayer(PLAYERS,uid)
|
||||
_removePlayer(PLY_ALIVE,uid)
|
||||
end
|
||||
if body.data.playerId~=USER.uid then
|
||||
MES.new('info',text.leaveRoom:repD(body.data.playerId))
|
||||
end
|
||||
_playerLeaveRoom(body.data.playerId)
|
||||
end
|
||||
function NET.wsCallBack.room_fetch(body)
|
||||
TASK.unlock('fetchRoom')
|
||||
@@ -554,8 +560,9 @@ end
|
||||
function NET.wsCallBack.room_setPW()
|
||||
MES.new(text.roomPasswordChanged)
|
||||
end
|
||||
function NET.wsCallBack.room_remove(body)
|
||||
NET.wsCallBack.room_leave(body)
|
||||
function NET.wsCallBack.room_remove()
|
||||
MES.new('info',text.roomRemoved)
|
||||
_playerLeaveRoom(USER.uid)
|
||||
end
|
||||
function NET.wsCallBack.player_updateConf(body)-- TODO
|
||||
end
|
||||
@@ -577,6 +584,7 @@ end
|
||||
function NET.ws_connect()
|
||||
if WS.status('game')=='dead' then
|
||||
WS.connect('game','',{['x-access-token']=USER.aToken},6)
|
||||
TASK.removeTask_code(NET.ws_update)
|
||||
TASK.new(NET.ws_update)
|
||||
end
|
||||
end
|
||||
@@ -584,56 +592,59 @@ function NET.ws_close()
|
||||
WS.close('game')
|
||||
end
|
||||
function NET.ws_update()
|
||||
local updateOnlineTimer=0
|
||||
while WS.status('game')~='dead' do
|
||||
local dt=coroutine.yield()
|
||||
|
||||
updateOnlineTimer=updateOnlineTimer+dt
|
||||
if updateOnlineTimer>6.26 then
|
||||
NET.global_getOnlineCount()
|
||||
updateOnlineTimer=0
|
||||
-- Wait until connected then initialize player setting
|
||||
while true do
|
||||
TEST.yieldT(1/26)
|
||||
if WS.status('game')=='dead' then
|
||||
return
|
||||
elseif WS.status('game')=='running' then
|
||||
NET.player_updateConf()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Websocket main loop
|
||||
local updateOnlineCD=0
|
||||
while true do
|
||||
TEST.yieldT(.01)-- Network messages, max 126 FPS is enough
|
||||
|
||||
if WS.status('game')=='dead' then return end
|
||||
|
||||
updateOnlineCD=updateOnlineCD%626+1
|
||||
if updateOnlineCD==0 then NET.global_getOnlineCount() end
|
||||
|
||||
local msg,op=WS.read('game')
|
||||
if msg then
|
||||
if op=='ping' then
|
||||
elseif op=='pong' then
|
||||
elseif op=='close' then
|
||||
local res=JSON.decode(msg)
|
||||
MES.new('info',text.wsClose:repD(res and res.message or msg))
|
||||
if res and res.message then LOG(res.message) end
|
||||
msg=JSON.decode(msg)
|
||||
if msg then
|
||||
MES.new('info',text.wsClose:repD(msg and msg.message or msg))
|
||||
if msg and msg.message then LOG(msg.message) end
|
||||
end
|
||||
TEST.yieldUntilNextScene()
|
||||
NET.connectLost()
|
||||
return
|
||||
else
|
||||
local body=JSON.decode(msg)
|
||||
if body then
|
||||
-- print(("Recv: <-- $1 ($2)"):repD(body.action,body.type))
|
||||
print(("Recv: <-- $1 ($2)"):repD(body.action,body.type)) print(TABLE.dump(body),"\n")
|
||||
if body.type=='Failed' then
|
||||
parseError(body.message~=nil and body.message or msg)
|
||||
else
|
||||
local f=NET.wsCallBack[actMap[body.action]]
|
||||
if f then f(body) end
|
||||
end
|
||||
elseif msg then
|
||||
msg=JSON.decode(msg)
|
||||
-- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno))
|
||||
-- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) print(TABLE.dump(msg),"\n")
|
||||
if msg.errno~=0 then
|
||||
parseError(msg.message~=nil and msg.message or msg)
|
||||
else
|
||||
MES.new('warn',"Wrong json: "..msg,5)
|
||||
WS.alert('user')
|
||||
local f=NET.wsCallBack[actMap[msg.action]]
|
||||
if f then f(msg) end
|
||||
end
|
||||
else
|
||||
MES.new('warn',"Wrong json: "..msg,5)
|
||||
WS.alert('user')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------<OLD ONLINE API>
|
||||
-- Account & User
|
||||
function NET.getUserInfo(uid)
|
||||
wsSend({
|
||||
uid=uid,
|
||||
hash=USERS.getHash(uid),
|
||||
})
|
||||
end
|
||||
|
||||
-- Save
|
||||
function NET.uploadSave()
|
||||
if not TASK.lock('uploadSave',8) then return end
|
||||
@@ -654,46 +665,48 @@ function NET.downloadSave()
|
||||
MES.new('info',"Downloading")
|
||||
end
|
||||
function NET.loadSavedData(sections)
|
||||
local cloudData={}
|
||||
local secNameList={'STAT','RANKS','SETTING','keyMap','VK_org','vkSave1','vkSave2'}
|
||||
for _,sec in next,sections do
|
||||
if sec.section==1 then
|
||||
NET.cloudData.STAT=STRING.unpackTable(sec.data)
|
||||
elseif sec.section==2 then
|
||||
NET.cloudData.RANKS=STRING.unpackTable(sec.data)
|
||||
elseif sec.section==3 then
|
||||
NET.cloudData.SETTING=STRING.unpackTable(sec.data)
|
||||
elseif sec.section==4 then
|
||||
NET.cloudData.keyMap=STRING.unpackTable(sec.data)
|
||||
elseif sec.section==5 then
|
||||
NET.cloudData.VK_org=STRING.unpackTable(sec.data)
|
||||
elseif sec.section==6 then
|
||||
NET.cloudData.vkSave1=STRING.unpackTable(sec.data)
|
||||
elseif sec.section==7 then
|
||||
NET.cloudData.vkSave2=STRING.unpackTable(sec.data)
|
||||
end
|
||||
cloudData[secNameList[sec.section]]=STRING.unpackTable(sec.data)
|
||||
end
|
||||
local success=true
|
||||
TABLE.cover(NET.cloudData.STAT,STAT)
|
||||
success=success and saveStats()
|
||||
|
||||
TABLE.cover(NET.cloudData.RANKS,RANKS)
|
||||
success=success and saveProgress()
|
||||
local fail
|
||||
repeat
|
||||
if cloudData.STAT then
|
||||
TABLE.cover(cloudData.STAT,STAT)
|
||||
if not saveStats() then fail=true end
|
||||
end
|
||||
|
||||
TABLE.cover(NET.cloudData.SETTING,SETTING)
|
||||
success=success and saveSettings()
|
||||
applySettings()
|
||||
if cloudData.RANKS then
|
||||
TABLE.cover(cloudData.RANKS,RANKS)
|
||||
if not saveProgress() then fail=true end
|
||||
end
|
||||
|
||||
TABLE.cover(NET.cloudData.keyMap,KEY_MAP)
|
||||
success=success and saveFile(KEY_MAP,'conf/key')
|
||||
if cloudData.SETTING then
|
||||
TABLE.cover(cloudData.SETTING,SETTING)
|
||||
if not saveSettings() then fail=true end
|
||||
end
|
||||
applySettings()
|
||||
|
||||
TABLE.cover(NET.cloudData.VK_org,VK_ORG)
|
||||
success=success and saveFile(VK_ORG,'conf/virtualkey')
|
||||
if cloudData.keyMap then
|
||||
TABLE.cover(cloudData.keyMap,KEY_MAP)
|
||||
if not saveFile(KEY_MAP,'conf/key') then fail=true end
|
||||
end
|
||||
|
||||
if #NET.cloudData.vkSave1[1] then success=success and saveFile(NET.cloudData.vkSave1,'conf/vkSave1') end
|
||||
if #NET.cloudData.vkSave2[1] then success=success and saveFile(NET.cloudData.vkSave2,'conf/vkSave2') end
|
||||
if success then
|
||||
MES.new('check',text.saveDone)
|
||||
if cloudData.VK_org then
|
||||
TABLE.cover(cloudData.VK_org,VK_ORG)
|
||||
if not saveFile(VK_ORG,'conf/virtualkey') then fail=true end
|
||||
end
|
||||
|
||||
if #cloudData.vkSave1[1] and not saveFile(cloudData.vkSave1,'conf/vkSave1') then fail=true end
|
||||
if #cloudData.vkSave2[1] and not saveFile(cloudData.vkSave2,'conf/vkSave2') then fail=true end
|
||||
until true
|
||||
|
||||
if fail then
|
||||
MES.new('error',text.dataCorrupted)
|
||||
else
|
||||
MES.new('warn',text.dataCorrupted)
|
||||
MES.new('check',text.saveDone)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ local nullIndex={
|
||||
NETPLY.add{
|
||||
uid=k,
|
||||
username="Stacker",
|
||||
sid=-1,
|
||||
mode=0,
|
||||
config="",
|
||||
}
|
||||
@@ -108,7 +107,6 @@ function NETPLY.add(d)
|
||||
local p={
|
||||
uid=d.uid,
|
||||
username=d.username,
|
||||
sid=d.sid,
|
||||
mode=d.mode,
|
||||
config=d.config,
|
||||
connected=false,
|
||||
@@ -122,9 +120,9 @@ function NETPLY.add(d)
|
||||
PLYmap[p.uid]=p
|
||||
_freshPos()
|
||||
end
|
||||
function NETPLY.remove(sid)
|
||||
function NETPLY.remove(uid)
|
||||
for i=1,#PLYlist do
|
||||
if PLYlist[i].sid==sid then
|
||||
if PLYlist[i].uid==uid then
|
||||
PLYmap[PLYlist[i].uid]=nil
|
||||
rem(PLYlist,i)
|
||||
_freshPos()
|
||||
@@ -134,7 +132,6 @@ function NETPLY.remove(sid)
|
||||
end
|
||||
|
||||
function NETPLY.getCount() return #PLYlist end
|
||||
function NETPLY.getSID(uid) return PLYmap[uid].sid end
|
||||
function NETPLY.getSelfJoinMode() return PLYmap[USER.uid].mode end
|
||||
function NETPLY.getSelfReady() return PLYmap[USER.uid].mode>0 end
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ local function _newEmptyPlayer(id,mini)
|
||||
-- User-related
|
||||
P.username=""
|
||||
P.uid=false
|
||||
P.sid=id
|
||||
P.sid=false
|
||||
|
||||
-- Block states
|
||||
--[[
|
||||
@@ -409,7 +409,7 @@ function PLY.newRemotePlayer(id,mini,ply)
|
||||
NETPLY.setPlayerObj(ply,P)
|
||||
P.uid=ply.uid
|
||||
P.username=ply.username
|
||||
P.sid=ply.sid
|
||||
P.sid=NET.uid_sid[ply.uid]
|
||||
|
||||
_loadRemoteEnv(P,ply.config)
|
||||
_applyGameEnv(P)
|
||||
@@ -430,8 +430,9 @@ function PLY.newPlayer(id,mini)
|
||||
P.type='human'
|
||||
P.sound=true
|
||||
|
||||
P.uid=USER.uid
|
||||
P.username=USERS.getUsername(USER.uid)
|
||||
P.uid=USER.uid
|
||||
P.sid=NET.uid_sid[USER.uid]
|
||||
|
||||
_loadGameEnv(P)
|
||||
_applyGameEnv(P)
|
||||
|
||||
@@ -77,9 +77,6 @@ function scene.sceneInit()
|
||||
BG.set(GAME.prevBG)
|
||||
GAME.prevBG=false
|
||||
end
|
||||
if NET.specSRID then
|
||||
NET.specSRID=false
|
||||
end
|
||||
end
|
||||
function scene.sceneBack()
|
||||
GAME.playing=false
|
||||
@@ -195,7 +192,7 @@ function scene.gamepadUp(key)
|
||||
end
|
||||
end
|
||||
|
||||
function scene.socketRead(cmd,d)
|
||||
function scene._(cmd,d)
|
||||
if cmd=='join' then
|
||||
textBox:push{
|
||||
COLOR.lR,d.username,
|
||||
@@ -209,12 +206,6 @@ function scene.socketRead(cmd,d)
|
||||
COLOR.dY,"#"..d.uid.." ",
|
||||
COLOR.Y,text.leaveRoom,
|
||||
}
|
||||
elseif cmd=='talk' then
|
||||
textBox:push{
|
||||
COLOR.Z,d.username,
|
||||
COLOR.dY,"#"..d.uid.." ",
|
||||
COLOR.N,d.message or "[_]",
|
||||
}
|
||||
elseif cmd=='go' then
|
||||
if not playing then
|
||||
playing=true
|
||||
@@ -222,8 +213,6 @@ function scene.socketRead(cmd,d)
|
||||
upstreamProgress=1
|
||||
resetGameData('n',NET.seed)
|
||||
NETPLY.mouseMove(0,0)
|
||||
else
|
||||
MES.new('warn',"Redundant [Go]")
|
||||
end
|
||||
elseif cmd=='finish' then
|
||||
playing=false
|
||||
@@ -315,7 +304,8 @@ function scene.draw()
|
||||
gc_draw(IMG.lock,30,668)
|
||||
end
|
||||
if NET.roomState.start then
|
||||
gc_setColor(0,1,0)gc_print(text.started,230,655)
|
||||
gc_setColor(0,1,0)
|
||||
gc_print(text.started,230,655)
|
||||
end
|
||||
|
||||
-- Profile
|
||||
|
||||
@@ -20,10 +20,12 @@ scene.widgetList={
|
||||
WIDGET.newButton{name='logout',x=880, y=40,w=180, h=60,color='dR',
|
||||
code=function()
|
||||
if tryBack() then
|
||||
USER.__data.uid=false
|
||||
USER.__data.email=false
|
||||
USER.__data.password=false
|
||||
USER.__data.rToken=false
|
||||
USER.__data.aToken=false
|
||||
love.filesystem.remove('conf/user')
|
||||
NET.ws_close()
|
||||
SCN.back()
|
||||
end
|
||||
|
||||
@@ -88,7 +88,7 @@ scene.widgetList={
|
||||
-- Capacity & Create & Back
|
||||
WIDGET.newSelector{name='capacity', x=1070,y=330,w=310,color='lY',list={2,3,4,5,7,10,17,31,49,99},disp=ROOMval('capacity'),code=ROOMsto('capacity')},
|
||||
WIDGET.newButton{name='create', x=1070,y=480,w=310,h=140,color='lN',font=40,code=_createRoom},
|
||||
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene},
|
||||
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=swapScene'net_rooms'},
|
||||
|
||||
-- Special rules
|
||||
WIDGET.newSwitch{name='ospin', x=850, y=850, lim=210,disp=ROOMval('ospin'), code=ROOMrev('ospin')},
|
||||
|
||||
@@ -147,7 +147,7 @@ scene.widgetList={
|
||||
WIDGET.newText{name='refreshing',x=450,y=240,font=45,hideF=function() return not TASK.getLock('fetchRoom') end},
|
||||
WIDGET.newText{name='noRoom', x=450,y=245,font=40,hideF=function() return roomList:getLen()>0 or TASK.getLock('fetchRoom') end},
|
||||
WIDGET.newKey{name='refresh', x=250,y=630,w=140,h=120,code=_fetchRoom,hideF=function() return fetchTimer>7 end},
|
||||
WIDGET.newKey{name='new', x=510,y=630,w=260,h=120,code=goScene'net_newRoom'},
|
||||
WIDGET.newKey{name='new', x=510,y=630,w=260,h=120,code=swapScene'net_newRoom'},
|
||||
WIDGET.newKey{name='join', x=780,y=630,w=140,h=120,code=pressKey'join',hideF=function() return roomList:getLen()==0 or TASK.getLock('enterRoom') end},
|
||||
WIDGET.newButton{name='back', x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=pressKey'escape'},
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ end
|
||||
function scene.keyDown(key,isRep)
|
||||
if isRep then return true end
|
||||
if key=='q' then
|
||||
SCN.back()
|
||||
GAME.playing=false
|
||||
SCN.back()
|
||||
elseif key=='escape' then
|
||||
SCN.swapTo(GAME.result and 'game' or 'depause','none')
|
||||
elseif key=='s' then
|
||||
|
||||
Reference in New Issue
Block a user