本文整理汇总了C++中net::MessageIn::getUnreadLength方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageIn::getUnreadLength方法的具体用法?C++ MessageIn::getUnreadLength怎么用?C++ MessageIn::getUnreadLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net::MessageIn
的用法示例。
在下文中一共展示了MessageIn::getUnreadLength方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleMessage
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;
}
}
示例2: handleEnterChannelResponse
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);
}
}
示例3: handleMessage
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;
}
}
示例4: handleShake
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());
}
}
示例5: handleMessage
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;
}
}
示例6: handleMessage
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;
}
}
}
示例7: handleBeingsDamageMessage
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);
}
}
}
示例8: handleBeingLooksChangeMessage
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));
}
}
示例9: handleWhoResponse
void ChatHandler::handleWhoResponse(Net::MessageIn &msg)
{
std::string userNick;
while(msg.getUnreadLength())
{
userNick = msg.readString();
if (userNick == "")
{
break;
}
localChatTab->chatLog(userNick, BY_SERVER);
}
}
示例10: handleListChannelsResponse
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);
}
示例11: handleListChannelUsersResponse
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);
}
}
示例12: handleBeingsMoveMessage
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);
}
}
}