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