本文整理汇总了C++中MessageIn::getUnreadLength方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageIn::getUnreadLength方法的具体用法?C++ MessageIn::getUnreadLength怎么用?C++ MessageIn::getUnreadLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageIn
的用法示例。
在下文中一共展示了MessageIn::getUnreadLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: handleEnterChannelResponse
void ChatHandler::handleEnterChannelResponse(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 InventoryHandler::handleMessage(MessageIn &msg)
{
switch (msg.getId())
{
case GPMSG_INVENTORY_FULL:
player_node->clearInventory();
// no break!
case GPMSG_INVENTORY:
while (msg.getUnreadLength())
{
int slot = msg.readInt8();
if (slot == 255)
{
player_node->setMoney(msg.readInt32());
continue;
}
int id = msg.readInt16();
if (slot < EQUIPMENT_SIZE)
{
player_node->mEquipment->setEquipment(slot, id);
}
else if (slot >= 32 && slot < 32 + INVENTORY_SIZE)
{
int amount = id ? msg.readInt8() : 0;
player_node->setInvItem(slot - 32, id, amount);
}
};
break;
}
}
示例4: 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;
}
}
示例5: handleShake
void EffectHandler::handleShake(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());
}
}
示例6: readUpdateHost
void LoginHandler::readUpdateHost(MessageIn &msg)
{
// Set the update host when included in the message
if (msg.getUnreadLength() > 0)
{
mLoginData->updateHost = msg.readString();
}
}
示例7: handleMessage
void BuySellHandler::handleMessage(MessageIn &msg)
{
Being *being = beingManager->findBeing(msg.readInt16());
if (!being || being->getType() != Being::NPC)
{
return;
}
current_npc = being->getId();
switch (msg.getId())
{
case GPMSG_NPC_BUY:
buyDialog->reset();
buyDialog->setMoney(player_node->getMoney());
buyDialog->setVisible(true);
while (msg.getUnreadLength())
{
int itemId = msg.readInt16();
int amount = msg.readInt16();
int value = msg.readInt16();
buyDialog->addItem(itemId, amount, value);
}
break;
case GPMSG_NPC_SELL:
sellDialog->setMoney(player_node->getMoney());
sellDialog->reset();
sellDialog->setVisible(true);
while (msg.getUnreadLength())
{
int itemId = msg.readInt16();
int amount = msg.readInt16();
int value = msg.readInt16();
sellDialog->addItem(new Item(itemId, amount, false), value);
}
break;
}
}
示例8: syncDatabase
void GameServerHandler::syncDatabase(MessageIn &msg)
{
// It is safe to perform the following updates in a transaction
dal::PerformTransaction transaction(storage->database());
while (msg.getUnreadLength() > 0)
{
int msgType = msg.readInt8();
switch (msgType)
{
case SYNC_CHARACTER_POINTS:
{
LOG_DEBUG("received SYNC_CHARACTER_POINTS");
int charId = msg.readInt32();
int charPoints = msg.readInt32();
int corrPoints = msg.readInt32();
storage->updateCharacterPoints(charId, charPoints, corrPoints);
} break;
case SYNC_CHARACTER_ATTRIBUTE:
{
LOG_DEBUG("received SYNC_CHARACTER_ATTRIBUTE");
int charId = msg.readInt32();
int attrId = msg.readInt32();
double base = msg.readDouble();
double mod = msg.readDouble();
storage->updateAttribute(charId, attrId, base, mod);
} break;
case SYNC_CHARACTER_SKILL:
{
LOG_DEBUG("received SYNC_CHARACTER_SKILL");
int charId = msg.readInt32();
int skillId = msg.readInt8();
int skillValue = msg.readInt32();
storage->updateExperience(charId, skillId, skillValue);
} break;
case SYNC_ONLINE_STATUS:
{
LOG_DEBUG("received SYNC_ONLINE_STATUS");
int charId = msg.readInt32();
bool online = (msg.readInt8() == 1);
storage->setOnlineStatus(charId, online);
}
}
}
transaction.commit();
}
示例9: handleWhoResponse
void ChatHandler::handleWhoResponse(MessageIn &msg)
{
std::string userNick;
while(msg.getUnreadLength())
{
userNick = msg.readString();
if (userNick == "")
{
break;
}
localChatTab->chatLog(userNick, BY_SERVER);
}
}
示例10: handleListChannelsResponse
void ChatHandler::handleListChannelsResponse(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: sendPost
void AccountConnection::sendPost(Character *c, MessageIn &msg)
{
// send message to account server with id of sending player,
// the id of receiving player, the letter receiver and contents, and attachments
LOG_DEBUG("Sending GCMSG_STORE_POST.");
MessageOut out(GCMSG_STORE_POST);
out.writeInt32(c->getDatabaseID());
out.writeString(msg.readString()); // name of receiver
out.writeString(msg.readString()); // content of letter
while (msg.getUnreadLength()) // attachments
{
// write the item id and amount for each attachment
out.writeInt32(msg.readInt16());
out.writeInt32(msg.readInt16());
}
send(out);
}
示例12: handleListChannelUsersResponse
void ChatHandler::handleListChannelUsersResponse(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);
}
}
示例13: deserialize
void CharacterComponent::deserialize(Entity &entity, MessageIn &msg)
{
auto *beingComponent = entity.getComponent<BeingComponent>();
// general character properties
setAccountLevel(msg.readInt8());
beingComponent->setGender(ManaServ::getGender(msg.readInt8()));
setHairStyle(msg.readInt8());
setHairColor(msg.readInt8());
setAttributePoints(msg.readInt16());
setCorrectionPoints(msg.readInt16());
// character attributes
unsigned attrSize = msg.readInt16();
for (unsigned i = 0; i < attrSize; ++i)
{
unsigned id = msg.readInt16();
double base = msg.readDouble();
auto *attributeInfo = attributeManager->getAttributeInfo(id);
if (attributeInfo)
beingComponent->setAttribute(entity, attributeInfo, base);
}
// status effects currently affecting the character
int statusSize = msg.readInt16();
for (int i = 0; i < statusSize; i++)
{
int status = msg.readInt16();
int time = msg.readInt16();
beingComponent->applyStatusEffect(status, time);
}
// location
auto *map = MapManager::getMap(msg.readInt16());
entity.setMap(map);
Point temporaryPoint;
temporaryPoint.x = msg.readInt16();
temporaryPoint.y = msg.readInt16();
entity.getComponent<ActorComponent>()->setPosition(entity, temporaryPoint);
// kill count
int killSize = msg.readInt16();
for (int i = 0; i < killSize; i++)
{
int monsterId = msg.readInt16();
int kills = msg.readInt32();
setKillCount(monsterId, kills);
}
// character abilities
int abilitiesSize = msg.readInt16();
for (int i = 0; i < abilitiesSize; i++)
{
const int id = msg.readInt32();
entity.getComponent<AbilityComponent>()->giveAbility(id);
}
// questlog
int questlogSize = msg.readInt16();
for (int i = 0; i < questlogSize; ++i) {
unsigned id = msg.readInt16();
QuestState state = (QuestState) msg.readInt8();
std::string title = msg.readString();
std::string description = msg.readString();
setQuestlog(id, state, title, description);
}
Possessions &poss = getPossessions();
// Loads inventory - must be last because size isn't transmitted
InventoryData inventoryData;
EquipData equipmentData;
while (msg.getUnreadLength())
{
InventoryItem i;
i.slot = msg.readInt16();
i.itemId = msg.readInt16();
i.amount = msg.readInt16();
bool isEquipped = msg.readInt8() != 0;
inventoryData.insert(std::make_pair(i.slot, i));
if (isEquipped)
equipmentData.insert(i.slot);
}
poss.setInventory(inventoryData);
poss.setEquipment(equipmentData);
}
示例14: handleMessage
void PlayerHandler::handleMessage(MessageIn &msg)
{
switch (msg.getId())
{
case GPMSG_PLAYER_MAP_CHANGE:
handleMapChangeMessage(msg);
break;
case GPMSG_PLAYER_SERVER_CHANGE:
{ // TODO: Fix the servers to test this
netToken = msg.readString(32);
std::string address = msg.readString();
int port = msg.readInt16();
logger->log("Changing server to %s:%d", address.c_str(), port);
gameServer.hostname = address;
gameServer.port = port;
gameServerConnection->disconnect();
Client::setState(STATE_CHANGE_MAP);
local_player->setMap(0);
} break;
case GPMSG_PLAYER_ATTRIBUTE_CHANGE:
{
while (msg.getUnreadLength())
{
int attrId = msg.readInt16();
double base = msg.readInt32() / 256.0;
double value = msg.readInt32() / 256.0;
// Set the core player attribute the stat
// depending on attribute link.
int playerInfoId =
Attributes::getPlayerInfoIdFromAttrId(attrId);
if (playerInfoId > -1)
{
PlayerInfo::setAttribute(playerInfoId, value);
}
else
{
PlayerInfo::setStatBase(attrId, base);
PlayerInfo::setStatMod(attrId, value - base);
}
}
} break;
case GPMSG_PLAYER_EXP_CHANGE:
{
logger->log("EXP Update");
while (msg.getUnreadLength())
{
int skill = msg.readInt16();
int current = msg.readInt32();
int next = msg.readInt32();
int level = msg.readInt16();
PlayerInfo::setStatExperience(skill, current, next);
PlayerInfo::setStatBase(skill, level);
}
} break;
case GPMSG_LEVELUP:
{
PlayerInfo::setAttribute(LEVEL, msg.readInt16());
PlayerInfo::setAttribute(CHAR_POINTS, msg.readInt16());
PlayerInfo::setAttribute(CORR_POINTS, msg.readInt16());
Particle* effect = particleEngine->addEffect(
paths.getStringValue("particles")
+ paths.getStringValue("levelUpEffectFile")
,0, 0);
local_player->controlParticle(effect);
} break;
case GPMSG_LEVEL_PROGRESS:
{
PlayerInfo::setAttribute(EXP, msg.readInt8());
} break;
case GPMSG_RAISE_ATTRIBUTE_RESPONSE:
{
int errCode = msg.readInt8();
int attrNum = msg.readInt16();
switch (errCode)
{
case ATTRIBMOD_OK:
{
// feel(acknowledgment);
} break;
case ATTRIBMOD_INVALID_ATTRIBUTE:
{
logger->log("Warning: Server denied increase of attribute %d (unknown attribute) ", attrNum);
} break;
case ATTRIBMOD_NO_POINTS_LEFT:
{
// when the server says "you got no points" it
// has to be correct. The server is always right!
// undo attribute change and set points to 0
//.........这里部分代码省略.........
示例15: processMessage
void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg)
{
GameServer *server = static_cast<GameServer *>(comp);
switch (msg.getId())
{
case GAMSG_REGISTER:
{
LOG_DEBUG("GAMSG_REGISTER");
// TODO: check the credentials of the game server
server->address = msg.readString();
server->port = msg.readInt16();
const std::string password = msg.readString();
// checks the version of the remote item database with our local copy
unsigned int dbversion = msg.readInt32();
LOG_INFO("Game server uses itemsdatabase with version " << dbversion);
LOG_DEBUG("AGMSG_REGISTER_RESPONSE");
MessageOut outMsg(AGMSG_REGISTER_RESPONSE);
if (dbversion == storage->getItemDatabaseVersion())
{
LOG_DEBUG("Item databases between account server and "
"gameserver are in sync");
outMsg.writeInt16(DATA_VERSION_OK);
}
else
{
LOG_DEBUG("Item database of game server has a wrong version");
outMsg.writeInt16(DATA_VERSION_OUTDATED);
}
if (password == Configuration::getValue("net_password", "changeMe"))
{
outMsg.writeInt16(PASSWORD_OK);
// transmit global world state variables
std::map<std::string, std::string> variables;
variables = storage->getAllWorldStateVars(Storage::WorldMap);
for (std::map<std::string, std::string>::iterator i = variables.begin();
i != variables.end();
i++)
{
outMsg.writeString(i->first);
outMsg.writeString(i->second);
}
comp->send(outMsg);
}
else
{
LOG_INFO("The password given by " << server->address << ':' << server->port << " was bad.");
outMsg.writeInt16(PASSWORD_BAD);
comp->disconnect(outMsg);
break;
}
LOG_INFO("Game server " << server->address << ':' << server->port
<< " wants to register " << (msg.getUnreadLength() / 2)
<< " maps.");
while (msg.getUnreadLength())
{
int id = msg.readInt16();
LOG_INFO("Registering map " << id << '.');
if (GameServer *s = getGameServerFromMap(id))
{
LOG_ERROR("Server Handler: map is already registered by "
<< s->address << ':' << s->port << '.');
}
else
{
MessageOut outMsg(AGMSG_ACTIVE_MAP);
// Map variables
outMsg.writeInt16(id);
std::map<std::string, std::string> variables;
variables = storage->getAllWorldStateVars(id);
// Map vars number
outMsg.writeInt16(variables.size());
for (std::map<std::string, std::string>::iterator i = variables.begin();
i != variables.end();
i++)
{
outMsg.writeString(i->first);
outMsg.writeString(i->second);
}
// Persistent Floor Items
std::list<FloorItem> items;
items = storage->getFloorItemsFromMap(id);
outMsg.writeInt16(items.size()); //number of floor items
// Send each map item: item_id, amount, pos_x, pos_y
for (std::list<FloorItem>::iterator i = items.begin();
i != items.end(); ++i)
{
outMsg.writeInt32(i->getItemId());
//.........这里部分代码省略.........