Beispiel #1
0
 def from_client(self, json):
     # Check if the message is valid
     message = TcpMessage.from_json(json)
     if not message.is_valid():
         print("Invalid message")
         return
     print("Message: {0}".format(message.get_body()))
     # Check if it is an new user
     if message.get_identity() not in self.users.keys():
         self.create_user(message.get_identity(), "")
         return
     user = self.users[message.get_identity()]
     # Check if the user has a valid login
     if len(user.get_login()) == 0:
         result = re.search(self.configure[0], message.get_body())
         if result:
             self.configure[1](self, message.get_identity(),
                               result.groups())
         return
     # Check the commands
     for command in self.commands.keys():
         result = re.search(command, message.get_body())
         if result:
             self.commands[command](self, message.get_identity(),
                                    result.groups())
             return
     # Check if the user is in a room and is chatting
     if user.get_room() != "":
         result = re.search(self.broadcast[0], message.get_body())
         if result:
             self.broadcast[1](self, message.get_identity(),
                               result.groups())
             return
     # Send an error if the command isn't recognized
     internal = InternalMessage(message.get_identity(),
                                Proxy.Commands.send.name, Text.HELP_MESSAGE)
     self.proxy_pusher.send_json(internal.to_json())
Beispiel #2
0
 def configure_user(self, identity, arguments):
     print("Configure user")
     message = InternalMessage(identity, Users.Commands.configure.name,
                               arguments[0])
     self.users_pusher.send_json(message.to_json())
Beispiel #3
0
 def create_user(self, identity, arguments):
     print("Create user")
     message = InternalMessage(identity, Users.Commands.create.name)
     self.users_pusher.send_json(message.to_json())
Beispiel #4
0
 def chat_broadcast(self, identity, arguments):
     print("Broadcast")
     message = InternalMessage(identity, Chat.Commands.broadcast.name,
                               arguments[0])
     self.chat_pusher.send_json(message.to_json())
Beispiel #5
0
 def list_rooms(self, identity, arguments):
     print("List rooms")
     message = InternalMessage(identity, Rooms.Commands.list.name)
     self.rooms_pusher.send_json(message.to_json())
Beispiel #6
0
 def create_room(self, identity, arguments):
     print("Create room")
     message = InternalMessage(identity, Rooms.Commands.create.name,
                               arguments[0])
     self.rooms_pusher.send_json(message.to_json())
Beispiel #7
0
 def brutaly_quit(self, identity, arguments):
     print("Brutaly quit")
     message = InternalMessage(identity, Users.Commands.hard_quit.name)
     self.users_pusher.send_json(message.to_json())
Beispiel #8
0
 def leave_room(self, identity, arguments):
     print("Leave room")
     message = InternalMessage(identity, Users.Commands.leave.name)
     self.users_pusher.send_json(message.to_json())
Beispiel #9
0
 def join_room(self, identity, arguments):
     print("Join room")
     message = InternalMessage(identity, Users.Commands.join.name,
                               arguments[0])
     self.users_pusher.send_json(message.to_json())