Anonymous avatar Anonymous committed 67511ee

Disconnected clients that didn't QUIT are now properly removed from channels, etc.

git-svn-id: https://svn.electricmonk.nl/svn/hircd/trunk@15 73c2b06a-06ba-454a-85af-d11de2e08ddc

Comments (0)

Files changed (1)

 # - Return erro 421 ERR_UNKNOWNCOMMAND on invalid command.
 # - Delete channel if last user leaves.
 # - [ERROR] <socket.error instance at 0x7f9f203dfb90> (better error msg required)
-# - Clients not removed from client list/channels, etc when connection is dropped without QUIT.
 # - Empty channels are left behind
 # - No Op assigned when new channel is created.
 # 
 
         while True:
             buf = ''
-            ready_to_read, ready_to_write, in_error = select.select([self.request], [], [], 0.1)
+            ready_to_read, ready_to_write, in_error = select.select([self.request], [], [], 1)
+            print ready_to_read, ready_to_write, in_error
 
             # Write any commands to the client
             while self.send_queue:
                             logging.debug('to %s: %s' % (self.client_ident(), response))
                             self.request.send(response + '\r\n')
 
-        logging.info('Client disconnected: %s' % (self.client_ident()))
+        self.disconnect()
         self.request.close()
 
     def handle_nick(self, params):
         """
         return('%s!%s@%s' % (self.nick, self.user, self.server.servername))
 
+    def disconnect(self):
+        """
+        Disconnect the client. This is called if the client suddenly
+        disconnected without properly saying goodbye (QUIT).
+        """
+        logging.info('Client disconnected: %s' % (self.client_ident()))
+
+        response = ':%s QUIT :EOF from client' % (self.client_ident())
+        # Send quit message to all clients in all channels user is in, and
+        # remove the user from the channels.
+        for channel in self.channels.values():
+            for client in channel.clients:
+                client.send_queue.append(response)
+            channel.clients.remove(self)
+        self.server.clients.pop(self.nick)
+
     def finish(self):
         """FINISH HIM!"""
         pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.