Ejemplo n.º 1
0
void GameHandler::handleLowerAttribute(GameClient &client, MessageIn &message)
{
    const int attribute = message.readInt32();
    AttribmodResponseCode retCode;
    retCode = client.character->useCorrectionPoint(attribute);

    MessageOut result(GPMSG_LOWER_ATTRIBUTE_RESPONSE);
    result.writeInt8(retCode);
    result.writeInt16(attribute);
    client.send(result);

    if (retCode == ATTRIBMOD_OK)
    {
        accountHandler->updateCharacterPoints(
            client.character->getDatabaseID(),
            client.character->getCharacterPoints(),
            client.character->getCorrectionPoints());

        // log transaction
        std::stringstream str;
        str << "User decreased attribute " << attribute;
        accountHandler->sendTransaction(client.character->getDatabaseID(),
                                        TRANS_ATTR_DECREASE, str.str());
    }
}
Ejemplo n.º 2
0
void GameHandler::completeServerChange(int id, const std::string &token,
                                       const std::string &address, int port)
{
    for (NetComputers::const_iterator i = clients.begin(),
         i_end = clients.end(); i != i_end; ++i)
    {
        GameClient *c = static_cast< GameClient * >(*i);
        if (c->status == CLIENT_CHANGE_SERVER &&
            c->character->getComponent<CharacterComponent>()
                ->getDatabaseID() == id)
        {
            MessageOut msg(GPMSG_PLAYER_SERVER_CHANGE);
            msg.writeString(token, MAGIC_TOKEN_LENGTH);
            msg.writeString(address);
            msg.writeInt16(port);
            c->send(msg);
            c->character->getComponent<CharacterComponent>()->disconnected(
                    *c->character);
            delete c->character;
            c->character = nullptr;
            c->status = CLIENT_LOGIN;
            return;
        }
    }
}
Ejemplo n.º 3
0
void GameHandler::handleDisconnect(GameClient &client, MessageIn &message)
{
    const bool reconnectAccount = (bool) message.readInt8();

    MessageOut result(GPMSG_DISCONNECT_RESPONSE);
    result.writeInt8(ERRMSG_OK); // It is, when control reaches here

    if (reconnectAccount)
    {
        std::string magic_token(utils::getMagicToken());
        result.writeString(magic_token, MAGIC_TOKEN_LENGTH);
        // No accountserver data, the client should remember that
        accountHandler->playerReconnectAccount(
                    client.character->getDatabaseID(),
                    magic_token);
    }
    accountHandler->sendCharacterData(client.character);

    // Done with the character, also handle possible respawn case
    client.character->disconnected();
    delete client.character;
    client.character = 0;
    client.status = CLIENT_LOGIN;

    client.send(result);
}
Ejemplo n.º 4
0
void GameHandler::handleRaiseAttribute(GameClient &client, MessageIn &message)
{
    auto *characterComponent =
            client.character->getComponent<CharacterComponent>();

    const int attribute = message.readInt16();
    AttribmodResponseCode retCode;
    retCode = characterComponent->useCharacterPoint(*client.character,
                                                    attribute);

    MessageOut result(GPMSG_RAISE_ATTRIBUTE_RESPONSE);
    result.writeInt8(retCode);
    result.writeInt16(attribute);
    client.send(result);

    if (retCode == ATTRIBMOD_OK)
    {
        accountHandler->updateCharacterPoints(
                characterComponent->getDatabaseID(),
                characterComponent->getCharacterPoints(),
                characterComponent->getCorrectionPoints());

        // log transaction
        std::stringstream str;
        str << "User increased attribute " << attribute;
        accountHandler->sendTransaction(characterComponent->getDatabaseID(),
                                        TRANS_ATTR_INCREASE, str.str());
    }
}
Ejemplo n.º 5
0
void GameHandler::handleTradeRequest(GameClient &client, MessageIn &message)
{
    const int id = message.readInt16();

    auto *characterComponent =
            client.character->getComponent<CharacterComponent>();

    if (Trade *t = characterComponent->getTrading())
        if (t->request(client.character, id))
            return;

    Entity *q = findCharacterNear(client.character, id);
    if (!q || characterComponent->isBusy())
    {
        client.send(MessageOut(GPMSG_TRADE_CANCEL));
        return;
    }

    new Trade(client.character, q);

    // log transaction
    std::string str;
    str = "User requested trade with " + q->getComponent<BeingComponent>()
            ->getName();
    accountHandler->sendTransaction(characterComponent->getDatabaseID(),
                                    TRANS_TRADE_REQUEST, str);
}
Ejemplo n.º 6
0
void GameHandler::sendNpcError(GameClient &client, int id,
                               const std::string &errorMsg)
{
    MessageOut msg(GPMSG_NPC_ERROR);
    msg.writeInt16(id);
    msg.writeString(errorMsg, errorMsg.size());
    client.send(msg);
}
Ejemplo n.º 7
0
void GameHandler::handleUnequip(GameClient &client, MessageIn &message)
{
    const int itemInstance = message.readInt16();
    if (!Inventory(client.character).unequip(itemInstance))
    {
        MessageOut msg(GPMSG_SAY);
        msg.writeInt16(0); // From the server
        msg.writeString("Unable to unequip.");
        client.send(msg);
    }
}
Ejemplo n.º 8
0
void GameHandler::handlePartyInvite(GameClient &client, MessageIn &message)
{
    MapComposite *map = client.character->getMap();
    const int visualRange = Configuration::getValue("game_visualRange", 448);
    std::string invitee = message.readString();

    if (invitee == client.character->getComponent<BeingComponent>()->getName())
        return;

    for (CharacterIterator it(map->getWholeMapIterator()); it; ++it)
    {
        if ((*it)->getComponent<BeingComponent>()->getName() == invitee)
        {
            // calculate if the invitee is within the visual range
            auto *inviterComponent =
                    client.character->getComponent<ActorComponent>();
            auto *inviteeComponent = (*it)->getComponent<ActorComponent>();
            const Point &inviterPosition = inviterComponent->getPosition();
            const Point &inviteePosition = inviteeComponent->getPosition();
            const int dx = std::abs(inviterPosition.x - inviteePosition.x);
            const int dy = std::abs(inviterPosition.y - inviteePosition.y);
            if (visualRange > std::max(dx, dy))
            {
                MessageOut out(GCMSG_PARTY_INVITE);
                out.writeString(client.character
                                ->getComponent<BeingComponent>()->getName());
                out.writeString(invitee);
                accountHandler->send(out);
                return;
            }
            break;
        }
    }

    // Invitee was not found or is too far away
    MessageOut out(GPMSG_PARTY_INVITE_ERROR);
    out.writeString(invitee);
    client.send(out);
}
Ejemplo n.º 9
0
void GameHandler::sendTo(Character *beingPtr, MessageOut &msg)
{
    GameClient *client = beingPtr->getClient();
    assert(client && client->status == CLIENT_CONNECTED);
    client->send(msg);
}