实现自动请求没见过的用户信息和自动获取用户头像
This commit is contained in:
@@ -834,7 +834,6 @@ do-- function drawSelfProfile()
|
||||
local name
|
||||
local textObj,scaleK,width,offY
|
||||
function drawSelfProfile()
|
||||
local selfAvatar=USERS.getAvatar(USER.uid)
|
||||
gc_push('transform')
|
||||
gc_replaceTransform(SCR.xOy_ur)
|
||||
|
||||
@@ -843,7 +842,7 @@ do-- function drawSelfProfile()
|
||||
gc_setColor(COLOR.X)gc_rectangle('fill',0,0,-300,80)
|
||||
gc_setColor(1,1,1)gc_rectangle('line',-300,0,300,80,5)
|
||||
gc_rectangle('line',-73,7,66,66,2)
|
||||
gc_draw(selfAvatar,-72,8,nil,.5)
|
||||
gc_draw(USERS.getAvatar(USER.uid),-72,8,nil,.5)
|
||||
|
||||
-- Draw username
|
||||
if name~=USERS.getUsername(USER.uid) then
|
||||
|
||||
@@ -148,16 +148,16 @@ function NET.codeLogin(code)
|
||||
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.pop()SCN.go('net_menu')
|
||||
elseif res.code==201 then
|
||||
USER.rToken=res.data.refreshToken
|
||||
USER.aToken=res.data.accessToken
|
||||
saveUser()
|
||||
SCN.pop()SCN.push('net_menu')
|
||||
SCN.fileDropped(3)
|
||||
end
|
||||
saveUser()
|
||||
end
|
||||
|
||||
WAIT.interrupt()
|
||||
@@ -219,7 +219,7 @@ function NET.autoLogin()
|
||||
|
||||
if res then
|
||||
if res.code==200 then
|
||||
USER.uid=res.data.playerId
|
||||
USER.uid=res.data
|
||||
saveUser()
|
||||
NET.ws_connect()
|
||||
SCN.go('net_menu')
|
||||
@@ -242,7 +242,6 @@ 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')
|
||||
@@ -267,7 +266,6 @@ 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')
|
||||
@@ -312,7 +310,6 @@ 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')
|
||||
@@ -322,14 +319,30 @@ function NET.pwLogin(email,pw)
|
||||
WAIT.interrupt()
|
||||
end)
|
||||
end
|
||||
|
||||
function NET.getUserInfo(uid)
|
||||
wsSend({
|
||||
uid=uid,
|
||||
hash=USERS.getHash(uid),
|
||||
})
|
||||
end
|
||||
TASK.new(function()
|
||||
local res=getMsg({
|
||||
pool='getInfo',
|
||||
path='/techmino/api/v1/player/info?playerId='..uid,
|
||||
},6.26)
|
||||
|
||||
if res and res.code==200 then
|
||||
USERS.updateUserData(res.data)
|
||||
end
|
||||
end)
|
||||
end
|
||||
function NET.getAvatar(uid)
|
||||
TASK.new(function()
|
||||
local res=getMsg({
|
||||
pool='getInfo',
|
||||
path='/techmino/api/v1/player/avatar?playerId='..uid,
|
||||
},6.26)
|
||||
|
||||
if res and res.code==200 then
|
||||
USERS.updateAvatar(uid,res.data)
|
||||
end
|
||||
end)
|
||||
end
|
||||
--------------------------<NEW WS API>
|
||||
local actMap={
|
||||
global_getOnlineCount= 1000,
|
||||
@@ -592,17 +605,35 @@ function NET.ws_close()
|
||||
WS.close('game')
|
||||
end
|
||||
function NET.ws_update()
|
||||
-- Wait until connected then initialize player setting
|
||||
-- Wait until connected
|
||||
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
|
||||
|
||||
do-- Get UID
|
||||
local res=getMsg({
|
||||
pool='getUID',
|
||||
path='/techmino/api/v1/auth/check',
|
||||
headers={["x-access-token"]=USER.aToken},
|
||||
},6.26)
|
||||
|
||||
if res and res.code==200 then
|
||||
USER.uid=res.data
|
||||
else
|
||||
TEST.yieldUntilNextScene()
|
||||
NET.connectLost()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Initialize player setting
|
||||
NET.player_updateConf()
|
||||
|
||||
-- Websocket main loop
|
||||
local updateOnlineCD=0
|
||||
while true do
|
||||
|
||||
@@ -52,20 +52,33 @@ end})
|
||||
|
||||
local USERS={}
|
||||
|
||||
--[[userdata={
|
||||
username="MrZ",
|
||||
motto="Techmino 好玩",
|
||||
id=26,
|
||||
permission="Admin",
|
||||
region=0,
|
||||
avatar_hash=XXX,
|
||||
avatar_frame=0,
|
||||
}]]
|
||||
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{
|
||||
local id=data.id
|
||||
db[id].username=data.username
|
||||
db[id].motto=data.motto
|
||||
if type(data.avatar_hash)=='string' and (db[id].hash~=data.avatar_hash or not fs.getInfo("cache/"..data.avatar_hash)) then
|
||||
db[id].hash=data.avatar_hash
|
||||
NET.getAvatar(id)
|
||||
end
|
||||
fs.write("cache/user"..id..".dat",JSON.encode{
|
||||
username=data.username,
|
||||
motto=data.motto,
|
||||
hash=data.hash or db[uid].hash,
|
||||
hash=db[id].hash,
|
||||
})
|
||||
if data.avatar then
|
||||
fs.write("cache/"..data.hash,love.data.decode('string','base64',data.avatar:sub(data.avatar:find(",")+1)))
|
||||
db_img[uid]=_loadAvatar("cache/"..data.hash)
|
||||
db[uid].hash=type(data.hash)=='string' and #data.hash>0 and data.hash
|
||||
end
|
||||
end
|
||||
function USERS.updateAvatar(id,imgData)
|
||||
local hash=db[id].hash
|
||||
fs.write("cache/"..hash,love.data.decode('string','base64',imgData:sub(imgData:find(",")+1)))
|
||||
db_img[id]=_loadAvatar("cache/"..hash)
|
||||
end
|
||||
|
||||
function USERS.getUsername(uid) return db[uid].username end
|
||||
|
||||
Reference in New Issue
Block a user