整理网络和用户相关代码
This commit is contained in:
@@ -223,9 +223,7 @@ USER=FILE.load("conf/user")or{--User infomation
|
|||||||
--Network infos
|
--Network infos
|
||||||
name=false,
|
name=false,
|
||||||
id=false,
|
id=false,
|
||||||
email=false,
|
|
||||||
authToken=false,
|
authToken=false,
|
||||||
accessToken=false,
|
|
||||||
|
|
||||||
--Local data
|
--Local data
|
||||||
xp=0,lv=1,
|
xp=0,lv=1,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ local NET={
|
|||||||
login=false,
|
login=false,
|
||||||
allow_online=false,
|
allow_online=false,
|
||||||
roomList=false,
|
roomList=false,
|
||||||
|
accessToken=false,
|
||||||
}
|
}
|
||||||
|
|
||||||
--Lock & Unlock submodule
|
--Lock & Unlock submodule
|
||||||
@@ -48,17 +49,25 @@ function NET.getUserInfo(id,ifDetail)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
function NET.storeUserInfo(res)
|
function NET.storeUserInfo(res)
|
||||||
local user
|
local user=USERS[res.id]
|
||||||
if not USERS[res.id]then
|
if not user then
|
||||||
user={}
|
user={}
|
||||||
user.email=res.email
|
user.email=res.email
|
||||||
user.name=res.username
|
user.name=res.username
|
||||||
USERS[res.id]=user
|
USERS[res.id]=user
|
||||||
else
|
else
|
||||||
user=USERS[res.id]
|
user.email=res.email
|
||||||
|
user.name=res.username
|
||||||
if not user.motto then user.motto=res.motto end
|
if not user.motto then user.motto=res.motto end
|
||||||
if not user.avatar then user.avatar=res.avatar end
|
if not user.avatar then user.avatar=res.avatar end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Get own name
|
||||||
|
if res.id==USER.id then
|
||||||
|
USER.name=res.name
|
||||||
|
FILE.save(USER,"conf/user")
|
||||||
|
end
|
||||||
|
|
||||||
-- FILE.save(USERS,"conf/users")
|
-- FILE.save(USERS,"conf/users")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -67,7 +76,7 @@ function NET.wsConnectPlay()
|
|||||||
if NET.lock("connectPlay")then
|
if NET.lock("connectPlay")then
|
||||||
WS.connect("play","/play",JSON.encode{
|
WS.connect("play","/play",JSON.encode{
|
||||||
id=USER.id,
|
id=USER.id,
|
||||||
accessToken=USER.accessToken,
|
accessToken=NET.accessToken,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -188,21 +197,20 @@ function NET.TICK_WS_user()
|
|||||||
if res.id then
|
if res.id then
|
||||||
USER.id=res.id
|
USER.id=res.id
|
||||||
USER.authToken=res.authToken
|
USER.authToken=res.authToken
|
||||||
|
FILE.save(USER,"conf/user","q")
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
end
|
||||||
FILE.save(USER,"conf/user","q")
|
|
||||||
LOG.print(text.loginSuccessed)
|
LOG.print(text.loginSuccessed)
|
||||||
|
|
||||||
--Get self infos
|
--Get self infos
|
||||||
NET.getUserInfo()
|
NET.getUserInfo(USER.id)
|
||||||
elseif res.action==0 then--Get accessToken
|
elseif res.action==0 then--Get accessToken
|
||||||
USER.accessToken=res.accessToken
|
NET.accessToken=res.accessToken
|
||||||
LOG.print(text.accessSuccessed)
|
LOG.print(text.accessSuccessed)
|
||||||
NET.wsConnectPlay()
|
NET.wsConnectPlay()
|
||||||
NET.unlock("accessToken")
|
NET.unlock("accessToken")
|
||||||
elseif res.action==1 then--Get userInfo
|
elseif res.action==1 then--Get userInfo
|
||||||
NET.storeUserInfo(res)
|
NET.storeUserInfo(res)
|
||||||
FILE.save(USER,"conf/user")
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WS.alert("user")
|
WS.alert("user")
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ local function login()
|
|||||||
elseif #password==0 then
|
elseif #password==0 then
|
||||||
LOG.print(text.noPassword)return
|
LOG.print(text.noPassword)return
|
||||||
end
|
end
|
||||||
USER.email=email
|
|
||||||
WS.connect("user","/user",JSON.encode{
|
WS.connect("user","/user",JSON.encode{
|
||||||
email=email,
|
email=email,
|
||||||
password=password,
|
password=password,
|
||||||
|
|||||||
Reference in New Issue
Block a user