Beispiel #1
0
void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
    switch (msg.getId())
    {
        case GPMSG_INVENTORY_FULL:
            {
                PlayerInfo::clearInventory();
                PlayerInfo::getEquipment()->setBackend(&mEquips);
                int count = msg.readInt16();
                while (count--)
                {
                    unsigned int slot = msg.readInt16();
                    int id = msg.readInt16();
                    unsigned int amount = msg.readInt16();
                    PlayerInfo::setInventoryItem(slot, id, amount);
                }
                while (msg.getUnreadLength())
                {
                    unsigned int slot = msg.readInt8();
                    unsigned int ref = msg.readInt16();

                    mEquips.addEquipment(slot, ref);
                }
            }
            break;

        case GPMSG_INVENTORY:
            while (msg.getUnreadLength())
            {
                unsigned int slot = msg.readInt16();
                int id = msg.readInt16();
                unsigned int amount = id ? msg.readInt16() : 0;
                PlayerInfo::setInventoryItem(slot, id, amount);
            }
            break;

        case GPMSG_EQUIP:
            while (msg.getUnreadLength())
            {
                unsigned int ref = msg.readInt16();
                int count = msg.readInt8();
                while (count--)
                {
                    unsigned int slot = msg.readInt8();
                    unsigned int used = msg.readInt8();

                    mEquips.setEquipment(slot, used, ref);
                }
            }
            break;
    }
}
void ChatHandler::handleEnterChannelResponse(Net::MessageIn &msg)
{
    if(msg.readInt8() == ERRMSG_OK)
    {
        short channelId = msg.readInt16();
        std::string channelName = msg.readString();
        std::string announcement = msg.readString();
        Channel *channel = new Channel(channelId, channelName, announcement);
        channelManager->addChannel(channel);
        ChatTab *tab = channel->getTab();
        tab->chatLog(strprintf(_("Topic: %s"), announcement.c_str()), BY_CHANNEL);

        std::string user;
        std::string userModes;
        tab->chatLog(_("Players in this channel:"), BY_CHANNEL);
        while(msg.getUnreadLength())
        {
            user = msg.readString();
            if (user == "")
                return;
            userModes = msg.readString();
            if (userModes.find('o') != std::string::npos)
            {
                user = "******" + user;
            }
            tab->chatLog(user, BY_CHANNEL);
        }

    }
    else
    {
        localChatTab->chatLog(_("Error joining channel."), BY_SERVER);
    }
}
Beispiel #3
0
void ItemHandler::handleMessage(Net::MessageIn &msg)
{
    switch (msg.getId())
    {
        case GPMSG_ITEM_APPEAR:
        case GPMSG_ITEMS:
        {
            while (msg.getUnreadLength())
            {
                int itemId = msg.readInt16();
                int x = msg.readInt16();
                int y = msg.readInt16();
                int id = (x << 16) | y; // dummy id

                if (itemId)
                {
                    actorSpriteManager->createItem(id, itemId, Vector(x, y));
                }
                else if (FloorItem *item = actorSpriteManager->findItem(id))
                {
                    actorSpriteManager->destroy(item);
                }
            }
        } break;
    }
}
Beispiel #4
0
void EffectHandler::handleShake(Net::MessageIn &msg)
{
    int16_t intensityX = 0;
    int16_t intensityY = 0;
    float decay;
    int duration;

    switch (msg.getUnreadLength())
    {
        case 4:
            intensityX =  msg.readInt16();
            intensityY =  msg.readInt16();
            viewport->shakeScreen(intensityX, intensityY);
            break;
        case 6:
            intensityX =  msg.readInt16();
            intensityY =  msg.readInt16();
            decay =  msg.readInt16() / 10000.0f;
            viewport->shakeScreen(intensityX, intensityY, decay);
            break;
        case 8:
            intensityX =  msg.readInt16();
            intensityY =  msg.readInt16();
            decay =  msg.readInt16() / 10000.0f;
            duration =  msg.readInt16();
            viewport->shakeScreen(intensityX, intensityY, decay, duration);
            break;
        default:
            logger->log("Warning: Received GPMSG_SHAKE message with unexpected length of %d bytes", msg.getUnreadLength());
    }
}
void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
    switch (msg.getId())
    {
        case GPMSG_INVENTORY_FULL:
            player_node->clearInventory();
            player_node->mEquipment->setBackend(&mEqiups);
            // no break!

        case GPMSG_INVENTORY:
            while (msg.getUnreadLength())
            {
                unsigned int slot = msg.readInt8();
                if (slot == 255)
                {
                    player_node->setMoney(msg.readInt32());
                    continue;
                }

                int id = msg.readInt16();
                if (slot < EQUIPMENT_SIZE)
                {
                    mEqiups.setEquipment(slot, id);
                }
                else if (slot >= 32 && slot < 32 + getSize(INVENTORY))
                {
                    int amount = id ? msg.readInt8() : 0;
                    player_node->setInvItem(slot - 32, id, amount);
                }
            };
            break;
    }
}
Beispiel #6
0
void BuySellHandler::handleMessage(Net::MessageIn &msg)
{
    Being *being = actorSpriteManager->findBeing(msg.readInt16());
    if (!being || being->getType() != ActorSprite::NPC)
    {
        return;
    }

    int npcId = being->getId();

    switch (msg.getId())
    {
        case GPMSG_NPC_BUY:
        {
            BuyDialog* dialog = new BuyDialog(npcId);

            dialog->reset();
            dialog->setMoney(PlayerInfo::getAttribute(MONEY));

            while (msg.getUnreadLength())
            {
                int itemId = msg.readInt16();
                int amount = msg.readInt16();
                int value = msg.readInt16();
                dialog->addItem(itemId, amount, value);
            }
            break;
        }

        case GPMSG_NPC_SELL:
        {
            SellDialog* dialog = new SellDialog(npcId);

            dialog->reset();
            dialog->setMoney(PlayerInfo::getAttribute(MONEY));

            while (msg.getUnreadLength())
            {
                int itemId = msg.readInt16();
                int amount = msg.readInt16();
                int value = msg.readInt16();
                dialog->addItem(new Item(itemId, amount, false), value);
            }
            break;
        }
    }
}
Beispiel #7
0
void BeingHandler::handleBeingsDamageMessage(Net::MessageIn &msg)
{
    while (msg.getUnreadLength())
    {
        Being *being = actorSpriteManager->findBeing(msg.readInt16());
        int damage = msg.readInt16();
        if (being)
        {
            being->takeDamage(0, damage, Being::HIT);
        }
    }
}
Beispiel #8
0
void BeingHandler::handleBeingLooksChangeMessage(Net::MessageIn &msg)
{
    Being *being = actorSpriteManager->findBeing(msg.readInt16());
    if (!being || being->getType() != ActorSprite::PLAYER)
        return;
    handleLooks(being, msg);
    if (msg.getUnreadLength())
    {
        int style = msg.readInt16();
        int color = msg.readInt16();
        being->setSprite(SPRITE_HAIR, style * -1, ColorDB::get(color));
    }
}
void ChatHandler::handleWhoResponse(Net::MessageIn &msg)
{
    std::string userNick;

    while(msg.getUnreadLength())
    {
        userNick = msg.readString();
        if (userNick == "")
        {
            break;
        }
        localChatTab->chatLog(userNick, BY_SERVER);
    }
}
void ChatHandler::handleListChannelsResponse(Net::MessageIn &msg)
{
    localChatTab->chatLog(_("Listing channels."), BY_SERVER);
    while(msg.getUnreadLength())
    {
        std::string channelName = msg.readString();
        if (channelName == "")
            return;
        std::ostringstream numUsers;
        numUsers << msg.readInt16();
        channelName += " - ";
        channelName += numUsers.str();
        localChatTab->chatLog(channelName, BY_SERVER);
    }
    localChatTab->chatLog(_("End of channel list."), BY_SERVER);
}
void ChatHandler::handleListChannelUsersResponse(Net::MessageIn &msg)
{
    std::string channelName = msg.readString();
    std::string userNick;
    std::string userModes;
    Channel *channel = channelManager->findByName(channelName);
    channel->getTab()->chatLog(_("Players in this channel:"), BY_CHANNEL);
    while(msg.getUnreadLength())
    {
        userNick = msg.readString();
        if (userNick == "")
        {
            break;
        }
        userModes = msg.readString();
        if (userModes.find('o') != std::string::npos)
        {
            userNick = "@" + userNick;
        }
        localChatTab->chatLog(userNick, BY_CHANNEL, channel);
    }
}
Beispiel #12
0
void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg)
{
    while (msg.getUnreadLength())
    {
        int id = msg.readInt16();
        int flags = msg.readInt8();
        Being *being = actorSpriteManager->findBeing(id);
        int sx = 0, sy = 0, dx = 0, dy = 0, speed = 0;

        if ((!flags & (MOVING_POSITION | MOVING_DESTINATION)))
            continue;

        if (flags & MOVING_POSITION)
        {
            sx = msg.readInt16();
            sy = msg.readInt16();
        }

        if (flags & MOVING_DESTINATION)
        {
            dx = msg.readInt16();
            dy = msg.readInt16();
            speed = msg.readInt8();
        }

        if (!being)
            continue;

        if (speed)
        {
           /*
            * The being's speed is transfered in tiles per second * 10
            * to keep it transferable in a Byte.
            * We set it back to tiles per second and in a float.
            */
            float speedTilesSeconds = (float) speed / 10;
            being->setMoveSpeed(Vector(speedTilesSeconds, speedTilesSeconds,
                                       0));
        }

        // Ignore messages from the server for the local player
        if (being == player_node)
            continue;

        // If the position differs too much from the actual one, we resync
        // the being position
        if (flags & MOVING_POSITION)
        {
            if (!being->getMap()->containsPixel(sx, sy))
            {
                logger->log("Warning: Received GPMSG_BEINGS_MOVE for being id "
                            "%i with position outside the map boundaries "
                            "(x = %i, y = %i)", id, sx, sy);
                continue;
            }

            Vector serverPos(sx, sy);
            if (serverPos.length()
                - being->getPosition().length() > POSITION_DIFF_TOLERANCE)
                being->setPosition(serverPos);
        }

        if (flags & MOVING_DESTINATION)
        {
            if (!being->getMap()->containsPixel(dx, dy))
            {
                logger->log("Warning: Received GPMSG_BEINGS_MOVE for being id "
                            "%i with destination outside the map boundaries "
                            "(x = %i, y = %i)", id, dx, dy);
                continue;
            }

            being->setDestination(dx, dy);
        }
    }
}