예제 #1
0
 def process(self):
     if not self._client_connection.character.waiting_for_name:
         return True
     self._client_connection.send('Please enter your name')
     name = self._client_connection.recv(64) or ''
     if not re.match(r'^[a-zA-Z]{3,12}$', name):
         return False
     self._client_connection.character.name = name.capitalize()
     LOGGER.debug(
         '%s:%s - %s connected' % (
             self._client_connection.remote_ip,
             self._client_connection.remote_port,
             self._client_connection.character.name,
         )
     )
     self._client_connection.send('Welcome %s!' % self._client_connection.character.name)
     matching_client_connections = ClientConnectionManager.instance.get_all_except(
         [self._client_connection],
         exclude_waiting_for_name=True
     )
     for matching_client_connection in matching_client_connections:
         matching_client_connection.send(
             '%s just arrived' % self._client_connection.character.name,
             num_leading_new_lines=1
         )
     return not self._client_connection.character.waiting_for_name
예제 #2
0
 def process(self):
     command = self._client_connection.recv(256) or ''
     if not command:
         return True
     LOGGER.debug(
         '%s:%s - %s [fromclient]' % (
             self._client_connection.remote_ip,
             self._client_connection.remote_port,
             command,
         )
     )
     if command[0:1] == "'":
         command = 'say ' + command[1:]
     LOGGER.debug(
         '%s:%s - %s [translated]' % (
             self._client_connection.remote_ip,
             self._client_connection.remote_port,
             command,
         )
     )
     args = command.split(' ')
     args0_lc = args[0].lower()
     if args0_lc in self.__exit_commands:
         return False
     command_handler = self.__get_command_handler(args0_lc)
     if not command_handler:
         self._client_connection.send(
             'I could not find what you were referring to'
         )
     else:
         command_handler.handle(
             self._client_connection,
             args[1:]
         )
     return True
예제 #3
0
 def finish(self):
     ClientConnectionManager.instance.remove(self.__client_connection)
     LOGGER.debug(
         '%s:%s - %s disconnected' % (
             self.__client_connection.remote_ip,
             self.__client_connection.remote_port,
             self.__client_connection.character.name,
         )
     )
예제 #4
0
 def handle(self):
     try:
         while not self.__login_processor.process():
             continue
         while self.__command_processor.process():
             continue
     except:
         LOGGER.error(
             sys.exc_info()[1],
             sys.exc_info()[2]
         )
예제 #5
0
 def handle(self):
     try:
         while not self._login_processor.process():
             continue
         while self._command_processor.process():
             continue
     except Exception as e:
         if isinstance(e, NotImplementedError):
             return
         if isinstance(e, IOError) and e.errno == 32:
             return
         LOGGER.error(sys.exc_info()[1], sys.exc_info()[2])
예제 #6
0
 def __import_command_handler(self, module_name):
     if module_name in sys.modules:
         if self.__has_source_file_changed(module_name):
             LOGGER.debug('reloading module: "%s"' % module_name)
             reload(sys.modules[module_name])
             LOGGER.debug('reloaded module: "%s"' % module_name)
     else:
         try:
             LOGGER.debug('importing module: "%s"' % module_name)
             __import__(module_name)
             LOGGER.debug('imported module: "%s"' % module_name)
         except ImportError:
             LOGGER.error('module: "%s" does not exist' % module_name)