mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 19:43:09 +00:00
add snax.gateserver snax.loginserver snax.msgserver
This commit is contained in:
@@ -7,21 +7,46 @@ skynet.register_protocol {
|
||||
}
|
||||
|
||||
local gate
|
||||
local userid, subid
|
||||
|
||||
local CMD = {}
|
||||
|
||||
function CMD.init(source , uid, server)
|
||||
function CMD.login(source, uid, sid, secret)
|
||||
-- you may use secret to make a encrypted data stream
|
||||
skynet.error(string.format("%s is login", uid))
|
||||
gate = source
|
||||
skynet.error(string.format("%s is coming", uid))
|
||||
userid = uid
|
||||
subid = sid
|
||||
-- you may load user data from database
|
||||
end
|
||||
|
||||
local function logout()
|
||||
if gate then
|
||||
skynet.call(gate, "lua", "logout", userid, subid)
|
||||
end
|
||||
skynet.exit()
|
||||
end
|
||||
|
||||
function CMD.logout(source)
|
||||
-- NOTICE: The logout MAY be reentry
|
||||
skynet.error(string.format("%s is logout", userid))
|
||||
logout()
|
||||
end
|
||||
|
||||
function CMD.afk(source)
|
||||
-- the connection is broken, but the user may back
|
||||
skynet.error(string.format("AFK"))
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua", function(_, source, command, ...)
|
||||
-- If you want to fork a work thread , you MUST do it in CMD.login
|
||||
skynet.dispatch("lua", function(session, source, command, ...)
|
||||
local f = assert(CMD[command])
|
||||
skynet.ret(skynet.pack(f(source, ...)))
|
||||
end)
|
||||
|
||||
skynet.dispatch("client", function(_,_, msg)
|
||||
-- the simple ehco service
|
||||
skynet.ret(msg)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user