add snax.gateserver snax.loginserver snax.msgserver

This commit is contained in:
Cloud Wu
2014-07-15 12:05:58 +08:00
parent 43719de101
commit dbf492b761
13 changed files with 562 additions and 268 deletions

View File

@@ -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)