当前位置: 首页>>代码示例>>C++>>正文


C++ MessageIn类代码示例

本文整理汇总了C++中MessageIn的典型用法代码示例。如果您正苦于以下问题:C++ MessageIn类的具体用法?C++ MessageIn怎么用?C++ MessageIn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MessageIn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleMapChangeMessage

void PlayerHandler::handleMapChangeMessage(MessageIn &msg)
{
    const std::string mapName = msg.readString();
    const unsigned short x = msg.readInt16();
    const unsigned short y = msg.readInt16();

    Game *game = Game::instance();
    const bool sameMap = (game->getCurrentMapName() == mapName);

    logger->log("Changing map to %s (%d, %d)", mapName.c_str(), x, y);

    // Switch the actual map, deleting the previous one
    game->changeMap(mapName);

    const Vector &playerPos = local_player->getPosition();
    float scrollOffsetX = 0.0f;
    float scrollOffsetY = 0.0f;

    /* Scroll if neccessary */
    if (!sameMap
            || (abs(x - (int) playerPos.x) > MAP_TELEPORT_SCROLL_DISTANCE)
            || (abs(y - (int) playerPos.y) > MAP_TELEPORT_SCROLL_DISTANCE))
    {
        scrollOffsetX = x - (int) playerPos.x;
        scrollOffsetY = y - (int) playerPos.y;
    }

    local_player->setAction(Being::STAND);
    local_player->setPosition(x, y);
    local_player->setDestination(x, y);

    logger->log("Adjust scrolling by %d,%d", (int) scrollOffsetX,
                                             (int) scrollOffsetY);
    viewport->scrollBy(scrollOffsetX, scrollOffsetY);
}
开发者ID:jurkan,项目名称:mana,代码行数:35,代码来源:playerhandler.cpp

示例2: handlePrivateMessage

void ChatHandler::handlePrivateMessage(MessageIn &msg)
{
    std::string userNick = msg.readString();
    std::string chatMsg = msg.readString();

    chatWindow->whisper(userNick, chatMsg);
}
开发者ID:mekolat,项目名称:elektrogamesvn,代码行数:7,代码来源:chathandler.cpp

示例3: handleMessage

void ItemHandler::handleMessage(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;
    }
}
开发者ID:Ablu,项目名称:mana,代码行数:26,代码来源:itemhandler.cpp

示例4: handleNpc

void GameHandler::handleNpc(GameClient &client, MessageIn &message)
{
    int id = message.readInt16();
    Actor *actor = findActorNear(client.character, id);
    if (!actor || actor->getType() != OBJECT_NPC)
    {
        sendNpcError(client, id, "Not close enough to NPC\n");
        return;
    }

    Being *npc = static_cast<Being*>(actor);

    switch (message.getId())
    {
        case PGMSG_NPC_SELECT:
            Npc::integerReceived(client.character, message.readInt8());
            break;
        case PGMSG_NPC_NUMBER:
            Npc::integerReceived(client.character, message.readInt32());
            break;
        case PGMSG_NPC_STRING:
            Npc::stringReceived(client.character, message.readString());
            break;
        case PGMSG_NPC_TALK:
            Npc::start(npc, client.character);
            break;
        case PGMSG_NPC_TALK_NEXT:
        default:
            Npc::resume(client.character);
            break;
    }
}
开发者ID:hanwujunlc,项目名称:manaserv,代码行数:32,代码来源:gamehandler.cpp

示例5: handleChatMessage

void ChatHandler::handleChatMessage(ChatClient &client, MessageIn &msg)
{
    std::string text = msg.readString();

    // Pass it through the slang filter (false when it contains bad words)
    if (!stringFilter->filterContent(text))
    {
        warnPlayerAboutBadWords(client);
        return;
    }

    short channelId = msg.readShort();
    ChatChannel *channel = chatChannelManager->getChannel(channelId);

    if (channel)
    {
        LOG_DEBUG(client.characterName << " says in channel " << channelId
                  << ": " << text);

        MessageOut result(CPMSG_PUBMSG);
        result.writeShort(channelId);
        result.writeString(client.characterName);
        result.writeString(text);
        sendInChannel(channel, result);
    }

    // log transaction
    Transaction trans;
    trans.mCharacterId = client.characterId;
    trans.mAction = TRANS_MSG_PUBLIC;
    trans.mMessage = "User said " + text;
    storage->addTransaction(trans);
}
开发者ID:Ablu,项目名称:invertika,代码行数:33,代码来源:chathandler.cpp

示例6: handleMessage

void ItemHandler::handleMessage(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)
            {
                floorItemManager->create(id, itemId, x / 32, y / 32, engine->getCurrentMap());
            }
            else if (FloorItem *item = floorItemManager->findById(id))
            {
                floorItemManager->destroy(item);
            }
        }
    }
    break;
    }
}
开发者ID:kai62656,项目名称:manabot,代码行数:27,代码来源:itemhandler.cpp

示例7: handleGuildMemberLevelChange

void ChatHandler::handleGuildMemberLevelChange(ChatClient &client,
                                               MessageIn &msg)
{
    // get the guild, the user to change the permissions, and the new permission
    // check theyre valid, and then change them
    MessageOut reply(CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE);
    short guildId = msg.readInt16();
    std::string user = msg.readString();
    short level = msg.readInt8();
    Guild *guild = guildManager->findById(guildId);
    CharacterData *c = storage->getCharacter(user);

    if (guild && c)
    {
        int rights = guild->getUserPermissions(c->getDatabaseID()) | level;
        if (guildManager->changeMemberLevel(&client, guild, c->getDatabaseID(),
                                            rights) == 0)
        {
            reply.writeInt8(ERRMSG_OK);
            client.send(reply);
        }
    }

    reply.writeInt8(ERRMSG_FAILURE);
    client.send(reply);
}
开发者ID:Ablu,项目名称:manaserv,代码行数:26,代码来源:guildhandler.cpp

示例8: handleCreateEffectPos

void EffectHandler::handleCreateEffectPos(MessageIn &msg)
{
    int id = msg.readInt16();
    uint16_t x = msg.readInt16();
    uint16_t y = msg.readInt16();
    effectManager->trigger(id, x, y);
}
开发者ID:Ablu,项目名称:mana,代码行数:7,代码来源:effecthandler.cpp

示例9: readUpdateHost

void LoginHandler::readUpdateHost(MessageIn &msg)
{
    // Set the update host when included in the message
    if (msg.getUnreadLength() > 0)
    {
        mLoginData->updateHost = msg.readString();
    }
}
开发者ID:kai62656,项目名称:manabot,代码行数:8,代码来源:loginhandler.cpp

示例10: handleGuildInvite

void ChatHandler::handleGuildInvite(ChatClient &client, MessageIn &msg)
{
    MessageOut reply(CPMSG_GUILD_INVITE_RESPONSE);
    MessageOut invite(CPMSG_GUILD_INVITED);

    // send an invitation from sender to character to join guild
    int guildId = msg.readInt16();
    std::string character = msg.readString();

    // get the chat client and the guild
    ChatClient *invitedClient = getClient(character);
    Guild *guild = guildManager->findById(guildId);

    if (invitedClient && guild)
    {
        // check permissions of inviter, and that they arent inviting themself,
        // and arent someone already in the guild
        if (guild->canInvite(client.characterId) &&
            client.characterName != character &&
            guild->checkInGuild(client.characterId))
        {
            if ((int)invitedClient->guilds.size() >=
                    Configuration::getValue("account_maxGuildsPerCharacter", 1))
            {
                reply.writeInt8(ERRMSG_LIMIT_REACHED);
            }
            else if (guild->checkInGuild(invitedClient->characterId))
            {
                reply.writeInt8(ERRMSG_ALREADY_MEMBER);
            }
            else
            {
                // send the name of the inviter and the name of the guild
                // that the character has been invited to join
                std::string senderName = client.characterName;
                std::string guildName = guild->getName();
                invite.writeString(senderName);
                invite.writeString(guildName);
                invite.writeInt16(guildId);
                invitedClient->send(invite);
                reply.writeInt8(ERRMSG_OK);

                // add member to list of invited members to the guild
                guild->addInvited(invitedClient->characterId);
            }
        }
        else
        {
            reply.writeInt8(ERRMSG_FAILURE);
        }
    }
    else
    {
        reply.writeInt8(ERRMSG_FAILURE);
    }

    client.send(reply);
}
开发者ID:Ablu,项目名称:manaserv,代码行数:58,代码来源:guildhandler.cpp

示例11: handleQuitChannelResponse

void ChatHandler::handleQuitChannelResponse(MessageIn &msg)
{
    if(msg.readInt8() == ERRMSG_OK)
    {
        short channelId = msg.readInt16();
        Channel *channel = channelManager->findById(channelId);
        channelManager->removeChannel(channel);
    }
}
开发者ID:mekolat,项目名称:elektrogamesvn,代码行数:9,代码来源:chathandler.cpp

示例12: handleChatMessage

void ChatHandler::handleChatMessage(MessageIn &msg)
{
    short channelId = msg.readInt16();
    std::string userNick = msg.readString();
    std::string chatMsg = msg.readString();

    Channel *channel = channelManager->findById(channelId);
    channel->getTab()->chatLog(userNick, chatMsg);
}
开发者ID:mekolat,项目名称:elektrogamesvn,代码行数:9,代码来源:chathandler.cpp

示例13: handleNpcBuySell

void GameHandler::handleNpcBuySell(GameClient &client, MessageIn &message)
{
    BuySell *t = client.character->getBuySell();
    if (!t)
        return;
    const int id = message.readInt16();
    const int amount = message.readInt16();
    t->perform(id, amount);
}
开发者ID:hanwujunlc,项目名称:manaserv,代码行数:9,代码来源:gamehandler.cpp

示例14: Being

Character::Character(MessageIn &msg):
    Being(OBJECT_CHARACTER),
    mClient(NULL),
    mConnected(true),
    mTransactionHandler(NULL),
    mSpecialUpdateNeeded(false),
    mDatabaseID(-1),
    mHairStyle(0),
    mHairColor(0),
    mLevel(1),
    mLevelProgress(0),
    mUpdateLevelProgress(false),
    mRecalculateLevel(true),
    mParty(0),
    mTransaction(TRANS_NONE),
    mTalkNpcId(0),
    mNpcThread(0),
    mKnuckleAttackInfo(0)
{
    const AttributeManager::AttributeScope &attr =
                           attributeManager->getAttributeScope(CharacterScope);
    LOG_DEBUG("Character creation: initialisation of "
              << attr.size() << " attributes.");
    for (AttributeManager::AttributeScope::const_iterator it1 = attr.begin(),
         it1_end = attr.end(); it1 != it1_end; ++it1)
        mAttributes.insert(std::make_pair(it1->first, Attribute(*it1->second)));

    setWalkMask(Map::BLOCKMASK_WALL);
    setBlockType(BLOCKTYPE_CHARACTER);

    // Get character data.
    mDatabaseID = msg.readInt32();
    setName(msg.readString());
    deserializeCharacterData(*this, msg);
    mOld = getPosition();
    Inventory(this).initialize();
    modifiedAllAttribute();
    setSize(16);

    // Default knuckle attack
    int damageBase = this->getModifiedAttribute(ATTR_STR);
    int damageDelta = damageBase / 2;
    Damage knuckleDamage;
    knuckleDamage.skill = skillManager->getDefaultSkillId();
    knuckleDamage.base = damageBase;
    knuckleDamage.delta = damageDelta;
    knuckleDamage.cth = 2;
    knuckleDamage.element = ELEMENT_NEUTRAL;
    knuckleDamage.type = DAMAGE_PHYSICAL;
    knuckleDamage.range = DEFAULT_TILE_LENGTH;

    mKnuckleAttackInfo = new AttackInfo(0, knuckleDamage, 7, 3, 0);
    addAttack(mKnuckleAttackInfo);
}
开发者ID:hanwujunlc,项目名称:manaserv,代码行数:54,代码来源:character.cpp

示例15: handleChannelEvent

void ChatHandler::handleChannelEvent(MessageIn &msg)
{
    short channelId = msg.readInt16();
    char eventId = msg.readInt8();
    std::string line = msg.readString();
    Channel *channel = channelManager->findById(channelId);

    if(channel)
    {
        switch(eventId)
        {
            case CHAT_EVENT_NEW_PLAYER:
                channel->getTab()->chatLog(strprintf(_("%s entered the "
                        "channel."), line.c_str()), BY_CHANNEL);
                break;

            case CHAT_EVENT_LEAVING_PLAYER:
                channel->getTab()->chatLog(strprintf(_("%s left the channel."),
                        line.c_str()), BY_CHANNEL);
                break;

            case CHAT_EVENT_TOPIC_CHANGE:
                channel->getTab()->chatLog(strprintf(_("Topic: %s"),
                        line.c_str()), BY_CHANNEL);
                break;

            case CHAT_EVENT_MODE_CHANGE:
            {
                int first = line.find(":");
                int second = line.find(":", first+1);
                std::string user1 = line.substr(0, first);
                std::string user2 = line.substr(first+1, second);
                std::string mode = line.substr(second+1, line.length());
                channel->getTab()->chatLog(strprintf(_("%s has set mode %s "
                        "on user %s."), user1.c_str(), mode.c_str(),
                        user2.c_str()), BY_CHANNEL);
            } break;

            case CHAT_EVENT_KICKED_PLAYER:
            {
                int first = line.find(":");
                std::string user1 = line.substr(0, first);
                std::string user2 = line.substr(first+1, line.length());
                channel->getTab()->chatLog(strprintf(_("%s has kicked %s."),
                        user1.c_str(), user2.c_str()), BY_CHANNEL);
            } break;

            default:
                channel->getTab()->chatLog(_("Unknown channel event."),
                                           BY_CHANNEL);
        }
    }
}
开发者ID:mekolat,项目名称:elektrogamesvn,代码行数:53,代码来源:chathandler.cpp


注:本文中的MessageIn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。