LOC-7 - Implemented ability to close a room
LOC-7 - Implemented ability to close a room

The room owner can now close the room with

/room close [roompass]

The pass is only required to prevent additional triggering and isn't used for any form of validation.

--- a/client/LocalChatClient.py
+++ b/client/LocalChatClient.py
@@ -225,6 +225,25 @@
         return resp['name']
     
 
+    def closeRoom(self):
+        if not self.room:
+            return False
+
+        payload = {"roomName": self.room, 
+                   "user": self.user,
+                   }
+        
+        request = {"action":"closeRoom",
+                   "payload": json.dumps(payload)
+                   }        
+
+        resp = self.sendRequest(request)
+        if resp == "BROKENLINK" or resp['status'] != "ok":
+            return False
+        
+        return True
+        
+        
 
     def inviteUser(self,user):
         ''' Invite a user into a room
@@ -408,6 +427,18 @@
                 return
         
             if cmd == "room":
+                
+                # /room close [roompass]
+                if args[0] == "close":
+                    if len(args) < 2:
+                        raise InvalidCommand('/room close [pass]')
+                    
+                    if not msg.closeRoom():
+                        raise UnableTo('Close Room','')
+                                        
+                    return
+                
+                
                 # /room create [roomname] [roompass] [[user]]
                 if args[0] == "create":
                     
@@ -469,6 +500,7 @@
             
             /kick [user]                                                Kick a user out of the room (they can return)
             /ban [user]                                                 Kick a user out and disinvite them (they cannot return)
+            /room close [roompass]                                      Kick all users out and close the room
             
             Once in a room, to send a message, just type it.
             

--- a/server/LocalChat.py
+++ b/server/LocalChat.py
@@ -116,6 +116,9 @@
         if reqjson['action'] == "createRoom":
             return self.createRoom(reqjson)
         
+        if reqjson['action'] == "closeRoom":
+            return self.closeRoom(reqjson)
+        
         elif reqjson['action'] == "joinRoom":
             return self.processjoinRoom(reqjson)
         
@@ -195,6 +198,50 @@
             }
         
     
+
+    def closeRoom(self,reqjson):
+        ''' Close a room.
+        
+        Means we need to
+        
+        - Ban all the users
+        - Scrub the message queue
+        - Remove the room record
+        '''
+        
+        if "roomName" not in reqjson['payload'] or "user" not in reqjson['payload']:
+            return 400
+        
+        room = self.getRoomID(reqjson['payload']["roomName"])
+        
+        if not room:
+            return 400
+        
+        
+        # Check the requesting user is the admin
+        self.cursor.execute("SELECT * from rooms where id=? and owner=?",(room,reqjson["payload"]["user"]))
+        n = self.cursor.fetchone()
+        
+        if not n:
+            return 403
+        
+        m = {
+            "user":"SYSTEM",
+            "text":"Room has been closed. Buh-Bye"
+        }
+        self.cursor.execute("INSERT INTO messages (ts,room,msg) VALUES (?,?,?)",(time.time(),room,json.dumps(m))) 
+        self.conn.commit()
+        
+        self.cursor.execute("DELETE FROM users where room=?",(room,))
+        self.cursor.execute("DELETE FROM rooms where id=?",(room,))
+        self.cursor.execute("DELETE FROM messages where room=?",(room,))
+        self.conn.commit()
+        
+        return { "status" : "ok" }
+    
+        
+           
+        
 
 
     def inviteUser(self,reqjson):