core/sessionmanager.lua

changeset 44
80d2ade0fd69
parent 41
68297fef35ff
child 49
1cd2a8db392d
equal deleted inserted replaced
43:03dc9df59368 44:80d2ade0fd69
10 local hosts = hosts; 10 local hosts = hosts;
11 11
12 local modulemanager = require "core.modulemanager"; 12 local modulemanager = require "core.modulemanager";
13 local log = require "util.logger".init("sessionmanager"); 13 local log = require "util.logger".init("sessionmanager");
14 local error = error; 14 local error = error;
15 15 local uuid_generate = require "util.uuid".uuid_generate;
16 module "sessionmanager" 16 module "sessionmanager"
17 17
18 function new_session(conn) 18 function new_session(conn)
19 local session = { conn = conn, notopen = true, priority = 0, type = "c2s_unauthed" }; 19 local session = { conn = conn, notopen = true, priority = 0, type = "c2s_unauthed" };
20 local w = conn.write; 20 local w = conn.write;
39 end 39 end
40 40
41 function bind_resource(session, resource) 41 function bind_resource(session, resource)
42 if not session.username then return false, "auth"; end 42 if not session.username then return false, "auth"; end
43 if session.resource then return false, "constraint"; end -- We don't support binding multiple resources 43 if session.resource then return false, "constraint"; end -- We don't support binding multiple resources
44 resource = resource or math.random(100000, 99999999); -- FIXME: Clearly we have issues :) 44 resource = resource or uuid_generate();
45 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing 45 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing
46 46
47 if not hosts[session.host].sessions[session.username] then 47 if not hosts[session.host].sessions[session.username] then
48 hosts[session.host].sessions[session.username] = { sessions = {} }; 48 hosts[session.host].sessions[session.username] = { sessions = {} };
49 else 49 else

mercurial