Exemplo n.º 1
0
    def handle(world_session, socket, reader):
        if len(reader.data) < 8:  # Avoid handling wrong player login packet
            return -1

        guid = unpack('<Q', reader.data[:8])[0]

        world_session.player_mgr = PlayerManager(
            RealmDatabaseManager.character_get_by_guid(guid), world_session)
        world_session.player_mgr.session = world_session
        if not world_session.player_mgr.player:
            Logger.anticheat('Character with wrong guid (%u) tried to login.' % guid)
            return -1

        socket.sendall(PacketWriter.get_packet(OpCode.SMSG_LOGIN_SETTIMESPEED,
                                               PlayerLoginHandler._get_login_timespeed()))

        world_session.player_mgr.load_skills()
        world_session.player_mgr.load_spells()

        socket.sendall(world_session.player_mgr.get_tutorial_packet())
        socket.sendall(world_session.player_mgr.get_initial_spells())
        socket.sendall(world_session.player_mgr.get_action_buttons())

        # MotD
        ChatManager.send_system_message(world_session, config.Server.General.motd)

        # Clear Who list on login, otherwise the last search will appear
        PlayerLoginHandler._clear_who_list(socket)

        world_session.player_mgr.inventory.load_items()

        update_packet = UpdatePacketFactory.compress_if_needed(PacketWriter.get_packet(
            OpCode.SMSG_UPDATE_OBJECT,
            world_session.player_mgr.get_update_packet(update_type=UpdateTypes.UPDATE_FULL)))
        socket.sendall(update_packet)

        PlayerLoginHandler._send_cinematic(world_session, world_session.player_mgr.player, socket)
        world_session.player_mgr.complete_login()

        return 0
Exemplo n.º 2
0
    def handle(world_session, socket, reader):
        chat_type, lang = unpack('<2I', reader.data[:8])
        message = ''
        guid = 0
        chat_flags = 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
        # 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

        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
Exemplo n.º 3
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
Exemplo n.º 4
0
    def handle_command(world_session, command_msg):
        terminator_index = command_msg.find(' ') if ' ' in command_msg else len(command_msg)

        command = command_msg[1:terminator_index].strip()
        args = command_msg[terminator_index:].strip()

        if command in PLAYER_COMMAND_DEFINITIONS:
            command_func = PLAYER_COMMAND_DEFINITIONS.get(command)
        elif command in GM_COMMAND_DEFINITIONS and world_session.player_mgr.is_gm:
            command_func = GM_COMMAND_DEFINITIONS.get(command)
        else:
            ChatManager.send_system_message(world_session, 'Command not found, type .help for help.')
            return

        if command_func:
            code, res = command_func(world_session, args)
            if code != 0:
                ChatManager.send_system_message(world_session, 'Wrong arguments for <%s> command: %s' % (command, res))
            elif res:
                ChatManager.send_system_message(world_session, res)
Exemplo n.º 5
0
    def handle(world_session, socket, reader):
        if len(reader.data) < 8:  # Avoid handling wrong player login packet
            return -1

        guid = unpack('<Q', reader.data[:8])[0]

        world_session.player_mgr = PlayerManager(
            RealmDatabaseManager.character_get_by_guid(guid), world_session)
        world_session.player_mgr.session = world_session
        if not world_session.player_mgr.player:
            Logger.anticheat('Character with wrong guid (%u) tried to login.' %
                             guid)
            return -1

        # Disabled race & class checks (only if not a GM)
        if not world_session.player_mgr.is_gm:
            disabled_race_mask = config.Server.General.disabled_race_mask
            disabled = disabled_race_mask & world_session.player_mgr.race_mask == world_session.player_mgr.race_mask

            if not disabled:
                disabled_class_mask = config.Server.General.disabled_class_mask
                disabled = disabled_class_mask & world_session.player_mgr.class_mask == world_session.player_mgr.class_mask

            if disabled:
                # Not 100% sure if CHAR_LOGIN_DISABLED matters here, but I don't know where else to send it
                data = pack('<B', CharLogin.CHAR_LOGIN_DISABLED)
                socket.sendall(
                    PacketWriter.get_packet(OpCode.SMSG_CHARACTER_LOGIN_FAILED,
                                            data))
                return 0

        # Class & race allowed, continue with the login process

        socket.sendall(
            PacketWriter.get_packet(OpCode.SMSG_LOGIN_SETTIMESPEED,
                                    PlayerLoginHandler._get_login_timespeed()))

        world_session.player_mgr.load_skills()
        world_session.player_mgr.load_spells()

        world_session.player_mgr.deathbind = RealmDatabaseManager.character_get_deathbind(
            world_session.player_mgr.guid)

        socket.sendall(world_session.player_mgr.get_deathbind_packet())
        #  Tutorials aren't implemented in 0.5.3
        #  socket.sendall(world_session.player_mgr.get_tutorial_packet())
        socket.sendall(world_session.player_mgr.get_initial_spells())
        socket.sendall(world_session.player_mgr.get_action_buttons())

        # MotD
        ChatManager.send_system_message(world_session,
                                        config.Server.General.motd)

        world_session.player_mgr.inventory.load_items()
        world_session.player_mgr.stat_manager.init_stats()
        world_session.player_mgr.stat_manager.apply_bonuses()
        world_session.player_mgr.send_update_self(create=True)
        world_session.player_mgr.reset_fields()

        PlayerLoginHandler._send_cinematic(world_session,
                                           world_session.player_mgr.player,
                                           socket)
        world_session.player_mgr.complete_login()

        return 0