From c900263556354c36fdf3631886d43302d338d6f5 Mon Sep 17 00:00:00 2001
From: Matthew Wild <mwild1@gmail.com>
Date: Wed, 5 May 2010 17:12:32 +0100
Subject: net.server_select: Fix typo affecting connections with an onconnect
 listener that have data pending in the sendbuffer

---
 net/server_select.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/server_select.lua b/net/server_select.lua
index 68ac7091..e3a389a8 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -629,7 +629,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
 			listeners.onconnect(handler);
 			handler.sendbuffer = _sendbuffer;
 			if bufferqueuelen > 0 then
-				return _senddbuffer();
+				return _sendbuffer();
 			end
 		end
 	end
-- 
cgit v1.2.3


From 4af6813db9ffa6dcacd2eb20417ca4667159f9af Mon Sep 17 00:00:00 2001
From: Matthew Wild <mwild1@gmail.com>
Date: Wed, 5 May 2010 17:21:50 +0100
Subject: mod_console: Make use of the new onconnect callback to initialise
 session and send banner

---
 plugins/mod_console.lua | 124 ++++++++++++++++++++++++------------------------
 1 file changed, 62 insertions(+), 62 deletions(-)

diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua
index 8f574704..4457a2f3 100644
--- a/plugins/mod_console.lua
+++ b/plugins/mod_console.lua
@@ -53,76 +53,76 @@ end
 
 local sessions = {};
 
+function console_listener.onconnect(conn)
+	-- Handle new connection
+	local session = console:new_session(conn);
+	sessions[conn] = session;
+	printbanner(session);
+end
+
 function console_listener.onincoming(conn, data)
 	local session = sessions[conn];
-	
-	if not session then
-		-- Handle new connection
-		session = console:new_session(conn);
-		sessions[conn] = session;
-		printbanner(session);
-	end
-	if data then
-		-- Handle data
-		(function(session, data)
-			local useglobalenv;
-			
-			if data:match("^>") then
-				data = data:gsub("^>", "");
-				useglobalenv = true;
-			elseif data == "\004" then
-				commands["bye"](session, data);
+
+	-- Handle data
+	(function(session, data)
+		local useglobalenv;
+		
+		if data:match("^>") then
+			data = data:gsub("^>", "");
+			useglobalenv = true;
+		elseif data == "\004" then
+			commands["bye"](session, data);
+			return;
+		else
+			local command = data:lower();
+			command = data:match("^%w+") or data:match("%p");
+			if commands[command] then
+				commands[command](session, data);
 				return;
-			else
-				local command = data:lower();
-				command = data:match("^%w+") or data:match("%p");
-				if commands[command] then
-					commands[command](session, data);
-					return;
-				end
 			end
+		end
 
-			session.env._ = data;
-			
-			local chunk, err = loadstring("return "..data);
+		session.env._ = data;
+		
+		local chunk, err = loadstring("return "..data);
+		if not chunk then
+			chunk, err = loadstring(data);
 			if not chunk then
-				chunk, err = loadstring(data);
-				if not chunk then
-					err = err:gsub("^%[string .-%]:%d+: ", "");
-					err = err:gsub("^:%d+: ", "");
-					err = err:gsub("'<eof>'", "the end of the line");
-					session.print("Sorry, I couldn't understand that... "..err);
-					return;
-				end
-			end
-			
-			setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil);
-			
-			local ranok, taskok, message = pcall(chunk);
-			
-			if not (ranok or message or useglobalenv) and commands[data:lower()] then
-				commands[data:lower()](session, data);
+				err = err:gsub("^%[string .-%]:%d+: ", "");
+				err = err:gsub("^:%d+: ", "");
+				err = err:gsub("'<eof>'", "the end of the line");
+				session.print("Sorry, I couldn't understand that... "..err);
 				return;
 			end
-			
-			if not ranok then
-				session.print("Fatal error while running command, it did not complete");
-				session.print("Error: "..taskok);
-				return;
-			end
-			
-			if not message then
-				session.print("Result: "..tostring(taskok));
-				return;
-			elseif (not taskok) and message then
-				session.print("Command completed with a problem");
-				session.print("Message: "..tostring(message));
-				return;
-			end
-			
-			session.print("OK: "..tostring(message));
-		end)(session, data);
-	end
+		end
+		
+		setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil);
+		
+		local ranok, taskok, message = pcall(chunk);
+		
+		if not (ranok or message or useglobalenv) and commands[data:lower()] then
+			commands[data:lower()](session, data);
+			return;
+		end
+		
+		if not ranok then
+			session.print("Fatal error while running command, it did not complete");
+			session.print("Error: "..taskok);
+			return;
+		end
+		
+		if not message then
+			session.print("Result: "..tostring(taskok));
+			return;
+		elseif (not taskok) and message then
+			session.print("Command completed with a problem");
+			session.print("Message: "..tostring(message));
+			return;
+		end
+		
+		session.print("OK: "..tostring(message));
+	end)(session, data);
+	
 	session.send(string.char(0));
 end
 
-- 
cgit v1.2.3