取消USER的username域,USERS独立为模块用于管理所有用户信息缓存(还未测试)
This commit is contained in:
1
main.lua
1
main.lua
@@ -63,6 +63,7 @@ FIELD[1]=newBoard()--Initialize field[1]
|
|||||||
NET= require"parts.net"
|
NET= require"parts.net"
|
||||||
AIBUILDER= require"parts.AITemplate"
|
AIBUILDER= require"parts.AITemplate"
|
||||||
FREEROW= require"parts.freeRow"
|
FREEROW= require"parts.freeRow"
|
||||||
|
USERS= require"parts.users"
|
||||||
|
|
||||||
TEXTURE= require"parts.texture"
|
TEXTURE= require"parts.texture"
|
||||||
SKIN= require"parts.skin"
|
SKIN= require"parts.skin"
|
||||||
|
|||||||
@@ -973,7 +973,7 @@ do--function saveRecording()
|
|||||||
os.date("%Y/%m/%d %A %H:%M:%S\n")..
|
os.date("%Y/%m/%d %A %H:%M:%S\n")..
|
||||||
GAME.curModeName.."\n"..
|
GAME.curModeName.."\n"..
|
||||||
VERSION.string.."\n"..
|
VERSION.string.."\n"..
|
||||||
(USER.username or"Player")
|
"Local Player"
|
||||||
local fileBody=
|
local fileBody=
|
||||||
GAME.seed.."\n"..
|
GAME.seed.."\n"..
|
||||||
JSON.encode(GAME.setting).."\n"..
|
JSON.encode(GAME.setting).."\n"..
|
||||||
@@ -1021,7 +1021,7 @@ do--function drawFWM()
|
|||||||
local t=TIME()
|
local t=TIME()
|
||||||
setFont(25)
|
setFont(25)
|
||||||
gc_setColor(1,1,1,.2+.1*(sin(3*t)+sin(2.6*t)))
|
gc_setColor(1,1,1,.2+.1*(sin(3*t)+sin(2.6*t)))
|
||||||
mStr(m[SETTING.lang]or m[1],240,60+26*sin(t))
|
mStr(m[_G["\83\69\84\84\73\78\71"]["\108\97\110\103"]or m[1]],240,60+26*sin(t))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function drawWarning()
|
function drawWarning()
|
||||||
|
|||||||
@@ -222,14 +222,12 @@ GAME={--Global game data
|
|||||||
RANKS=FILE.load("conf/unlock")or{sprint_10l=0}--Ranks of modes
|
RANKS=FILE.load("conf/unlock")or{sprint_10l=0}--Ranks of modes
|
||||||
USER=FILE.load("conf/user")or{--User infomation
|
USER=FILE.load("conf/user")or{--User infomation
|
||||||
--Network infos
|
--Network infos
|
||||||
username=false,
|
|
||||||
uid=false,
|
uid=false,
|
||||||
authToken=false,
|
authToken=false,
|
||||||
|
|
||||||
--Local data
|
--Local data
|
||||||
xp=0,lv=1,
|
xp=0,lv=1,
|
||||||
}
|
}
|
||||||
USERS=FILE.load("conf/users")or{}
|
|
||||||
SETTING={--Settings
|
SETTING={--Settings
|
||||||
--Tuning
|
--Tuning
|
||||||
das=10,arr=2,dascut=0,
|
das=10,arr=2,dascut=0,
|
||||||
|
|||||||
@@ -145,30 +145,11 @@ function NET.getUserInfo(id,ifDetail)
|
|||||||
WS.send("user",JSON.encode{
|
WS.send("user",JSON.encode{
|
||||||
action=1,
|
action=1,
|
||||||
data={
|
data={
|
||||||
id=id or USER.uid,
|
id=id,
|
||||||
detailed=ifDetail or false,
|
detailed=ifDetail or false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
function NET.storeUserInfo(d)
|
|
||||||
local user=USERS[d.uid]
|
|
||||||
if not user then
|
|
||||||
user={}
|
|
||||||
USERS[d.uid]=user
|
|
||||||
end
|
|
||||||
user.uid=d.uid
|
|
||||||
user.username=d.username
|
|
||||||
user.motto=d.motto
|
|
||||||
user.avatar=d.avatar
|
|
||||||
|
|
||||||
--Get own name
|
|
||||||
if d.uid==USER.uid then
|
|
||||||
USER.username=d.username
|
|
||||||
FILE.save(USER,"conf/user","q")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- FILE.save(USERS,"conf/users")
|
|
||||||
end
|
|
||||||
|
|
||||||
--Room
|
--Room
|
||||||
function NET.fetchRoom()
|
function NET.fetchRoom()
|
||||||
@@ -316,14 +297,14 @@ function NET.updateWS_user()
|
|||||||
LOG.print(text.loginSuccessed)
|
LOG.print(text.loginSuccessed)
|
||||||
|
|
||||||
--Get self infos
|
--Get self infos
|
||||||
NET.getUserInfo(USER.uid)
|
NET.getUserInfo()
|
||||||
NET.unlock("wsc_user")
|
NET.unlock("wsc_user")
|
||||||
elseif res.action==0 then--Get accessToken
|
elseif res.action==0 then--Get accessToken
|
||||||
NET.accessToken=res.accessToken
|
NET.accessToken=res.accessToken
|
||||||
LOG.print(text.accessSuccessed)
|
LOG.print(text.accessSuccessed)
|
||||||
NET.wsconn_play()
|
NET.wsconn_play()
|
||||||
elseif res.action==1 then--Get userInfo
|
elseif res.action==1 then--Get userInfo
|
||||||
NET.storeUserInfo(res.data)
|
USERS.updateUserData(res.data)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WS.alert("user")
|
WS.alert("user")
|
||||||
@@ -490,9 +471,8 @@ function NET.updateWS_stream()
|
|||||||
elseif res.action==3 then--Player leave
|
elseif res.action==3 then--Player leave
|
||||||
--?
|
--?
|
||||||
elseif res.action==4 then--Player died
|
elseif res.action==4 then--Player died
|
||||||
local uid=res.data.uid
|
|
||||||
for _,P in next,PLY_ALIVE do
|
for _,P in next,PLY_ALIVE do
|
||||||
if P.uid==uid then
|
if P.uid==d.uid then
|
||||||
P:lose(true)
|
P:lose(true)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ scene.widgetList={
|
|||||||
if USER.uid then
|
if USER.uid then
|
||||||
NET.wsclose_play()
|
NET.wsclose_play()
|
||||||
NET.wsclose_user()
|
NET.wsclose_user()
|
||||||
USER.username=false
|
|
||||||
USER.uid=false
|
USER.uid=false
|
||||||
USER.authToken=false
|
USER.authToken=false
|
||||||
FILE.save(USER,"conf/user","q")
|
FILE.save(USER,"conf/user","q")
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ function scene.keyDown(k)
|
|||||||
kb.isDown("4")and"r99"or
|
kb.isDown("4")and"r99"or
|
||||||
kb.isDown("5")and"unlimited"
|
kb.isDown("5")and"unlimited"
|
||||||
)or"solo",
|
)or"solo",
|
||||||
(USER.username or"???").."'s room"
|
(USERS.getName(USER.uid)or"???").."'s room"
|
||||||
)
|
)
|
||||||
lastCreateRoomTime=TIME()
|
lastCreateRoomTime=TIME()
|
||||||
else
|
else
|
||||||
|
|||||||
81
parts/users.lua
Normal file
81
parts/users.lua
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
local loadImage=love.graphics.newImage
|
||||||
|
local fs=love.filesystem
|
||||||
|
|
||||||
|
local ins=table.insert
|
||||||
|
|
||||||
|
local texture_noImage=DOGC{32,32,
|
||||||
|
{"rgb",0,0,0},
|
||||||
|
{"rect","fill",0,0,32,32},
|
||||||
|
{"rgb",1,1,1},
|
||||||
|
{"wid",3},
|
||||||
|
{"line",0,0,31,31},
|
||||||
|
{"line",0,31,31,0},
|
||||||
|
}
|
||||||
|
|
||||||
|
local function _getEmptyUser()
|
||||||
|
return{
|
||||||
|
uid=-1,
|
||||||
|
username="[X]",
|
||||||
|
motto="Techmino haowan",
|
||||||
|
hash=false,
|
||||||
|
new=false,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local imgReqSeq={}
|
||||||
|
local db_img={}
|
||||||
|
local db=setmetatable({},{__index=function(self,k)
|
||||||
|
local file="cache/user"..k..".dat"
|
||||||
|
if fs.getInfo(file)then
|
||||||
|
rawset(self,k,JSON.decode(fs.read(file)))
|
||||||
|
if fs.getInfo(self[k].hash)then
|
||||||
|
db_img[k].avatar=loadImage(self[k].hash)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
rawset(self,k,_getEmptyUser())
|
||||||
|
end
|
||||||
|
return self[k]
|
||||||
|
end})
|
||||||
|
|
||||||
|
local USERS={}
|
||||||
|
|
||||||
|
function USERS.updateUserData(data)
|
||||||
|
local uid=data.uid
|
||||||
|
db[uid].username=data.username
|
||||||
|
db[uid].motto=data.motto
|
||||||
|
fs.write("cache/user"..uid..".dat",JSON.encode{
|
||||||
|
username=data.username,
|
||||||
|
motto=data.motto,
|
||||||
|
hash=data.hash,
|
||||||
|
})
|
||||||
|
if data.avatar then
|
||||||
|
fs.write("cache/"..data.hash,data.avatar:sub(data.avatar:find","+1))
|
||||||
|
db_img[uid].avatar=loadImage("cache/"..data.hash)
|
||||||
|
db[uid].hash=data.hash
|
||||||
|
db[uid].new=true
|
||||||
|
end
|
||||||
|
needSave=true
|
||||||
|
end
|
||||||
|
|
||||||
|
function USERS.getUsername(uid)return db[uid].username end
|
||||||
|
function USERS.getMotto(uid)return db[uid].motto end
|
||||||
|
function USERS.getAvatar(uid)
|
||||||
|
if db_img[uid]then
|
||||||
|
return db_img[uid]
|
||||||
|
else
|
||||||
|
if not db[uid].new then
|
||||||
|
ins(imgReqSeq,uid)
|
||||||
|
db[uid].new=true
|
||||||
|
end
|
||||||
|
return texture_noImage
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function USERS.update()
|
||||||
|
if #imgReqSeq>0 and WS.status("user")=="running"then
|
||||||
|
NET.getUserInfo(imgReqSeq[#imgReqSeq],true)
|
||||||
|
imgReqSeq[#imgReqSeq]=nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return USERS
|
||||||
Reference in New Issue
Block a user