Add "uuid" library and make sessionmanager use this.

Sat, 04 Oct 2008 02:12:54 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 04 Oct 2008 02:12:54 +0100
changeset 44
80d2ade0fd69
parent 43
03dc9df59368
child 45
363c0af290bc

Add "uuid" library and make sessionmanager use this.
...and yes, the uuid generation needs work :P

core/sessionmanager.lua file | annotate | diff | comparison | revisions
util/uuid.lua file | annotate | diff | comparison | revisions
--- a/core/sessionmanager.lua	Sat Oct 04 02:10:14 2008 +0100
+++ b/core/sessionmanager.lua	Sat Oct 04 02:12:54 2008 +0100
@@ -12,7 +12,7 @@
 local modulemanager = require "core.modulemanager";
 local log = require "util.logger".init("sessionmanager");
 local error = error;
-
+local uuid_generate = require "util.uuid".uuid_generate;
 module "sessionmanager"
 
 function new_session(conn)
@@ -41,7 +41,7 @@
 function bind_resource(session, resource)
 	if not session.username then return false, "auth"; end
 	if session.resource then return false, "constraint"; end -- We don't support binding multiple resources
-	resource = resource or math.random(100000, 99999999); -- FIXME: Clearly we have issues :)
+	resource = resource or uuid_generate();
 	--FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing
 	
 	if not hosts[session.host].sessions[session.username] then
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util/uuid.lua	Sat Oct 04 02:12:54 2008 +0100
@@ -0,0 +1,9 @@
+
+local m_random = math.random;
+module "uuid"
+
+function uuid_generate()
+	return m_random(0, 99999999);
+end
+
+return _M;
\ No newline at end of file

mercurial