Esempio n. 1
0
    def handle(world_session, socket, reader):
        chat_type, lang = unpack('<2I', reader.data[:8])
        message = ''
        guid = 0
        chat_flags = 0

        # Return if no player
        if not world_session.player_mgr:
            return 0

        # Override language to universal for GMs
        if world_session.player_mgr.is_gm:
            lang = Languages.LANG_UNIVERSAL

        # Say, Yell, Emote
        if chat_type == ChatMsgs.CHAT_MSG_SAY \
                or chat_type == ChatMsgs.CHAT_MSG_EMOTE \
                or chat_type == ChatMsgs.CHAT_MSG_YELL:
            message = PacketReader.read_string(reader.data, 8)
            guid = world_session.player_mgr.guid
            chat_flags = world_session.player_mgr.chat_flags

            # Only send message if it's not a command
            if not ChatHandler.check_if_command(world_session, message):
                ChatManager.send_chat_message(
                    world_session, guid, chat_flags, message, chat_type, lang,
                    ChatHandler.get_range_by_type(chat_type))
        # Whisper
        elif chat_type == ChatMsgs.CHAT_MSG_WHISPER:
            target_name = PacketReader.read_string(reader.data, 8).strip()
            target_player_mgr = WorldSessionStateHandler.find_player_by_name(
                target_name)
            if not target_player_mgr:
                ChatManager.send_system_message(
                    world_session,
                    'No player named \'%s\' is currently playing.' %
                    target_name.capitalize())
                return 0
            message = PacketReader.read_string(reader.data,
                                               8 + len(target_name) + 1)
            if not ChatHandler.check_if_command(world_session, message):
                # Always whisper in universal language when speaking with a GM
                if target_player_mgr.is_gm:
                    lang = Languages.LANG_UNIVERSAL

                ChatManager.send_whisper(world_session.player_mgr,
                                         target_player_mgr, message, lang)
            return 0
        # Party
        elif chat_type == ChatMsgs.CHAT_MSG_PARTY:
            message = PacketReader.read_string(reader.data, 8)
            ChatManager.send_party(world_session.player_mgr, message, lang)
            return 0
        # Guild
        elif chat_type == ChatMsgs.CHAT_MSG_GUILD:
            # TODO: Implement
            return 0

        return 0
Esempio n. 2
0
    def handle(world_session, socket, reader):
        chat_type, lang = unpack('<2I', reader.data[:8])
        message = ''
        guid = 0
        chat_flags = 0

        # Say, Yell, Emote
        if chat_type == ChatMsgs.CHAT_MSG_SAY \
                or chat_type == ChatMsgs.CHAT_MSG_EMOTE \
                or chat_type == ChatMsgs.CHAT_MSG_YELL:
            message = PacketReader.read_string(reader.data, 8)
            guid = world_session.player_mgr.guid
            chat_flags = world_session.player_mgr.chat_flags
        # Whisper
        elif chat_type == ChatMsgs.CHAT_MSG_WHISPER:
            target_name = PacketReader.read_string(reader.data, 8).strip()
            target_player_mgr = WorldSessionStateHandler.find_player_by_name(
                target_name)
            if not target_player_mgr:
                ChatManager.send_system_message(
                    world_session,
                    'No player named \'%s\' is currently playing.' %
                    target_name.capitalize())
                return 0
            message = PacketReader.read_string(reader.data,
                                               8 + len(target_name) + 1)
            if not ChatHandler.check_if_command(world_session, message):
                ChatManager.send_whisper(world_session.player_mgr,
                                         target_player_mgr, message,
                                         0)  # TODO: handle lang
            return 0

        if not ChatHandler.check_if_command(world_session, message):
            ChatManager.send_chat_message(
                world_session, guid, chat_flags, message, chat_type, lang,
                ChatHandler.get_range_by_type(chat_type))

        return 0