本文整理汇总了C++中MessageIn::getId方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageIn::getId方法的具体用法?C++ MessageIn::getId怎么用?C++ MessageIn::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageIn
的用法示例。
在下文中一共展示了MessageIn::getId方法的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)
{
actorSpriteManager->createItem(id, itemId, Vector(x, y));
}
else if (FloorItem *item = actorSpriteManager->findItem(id))
{
actorSpriteManager->destroy(item);
}
}
} break;
}
}
示例2: 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;
}
}
示例3: handleMessage
void ItemHandler::handleMessage(MessageIn &msg)
{
Uint32 id;
Uint16 x, y;
int itemId;
switch (msg.getId())
{
case SMSG_ITEM_VISIBLE:
case SMSG_ITEM_DROPPED:
id = msg.readInt32();
itemId = msg.readInt16();
msg.readInt8(); // identify flag
x = msg.readInt16();
y = msg.readInt16();
msg.skip(4); // amount,subX,subY / subX,subY,amount
floorItemManager->create(id, itemId, x, y, engine->getCurrentMap());
break;
case SMSG_ITEM_REMOVE:
FloorItem *item;
item = floorItemManager->findById(msg.readInt32());
if (item)
floorItemManager->destroy(item);
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)
{
floorItemManager->create(id, itemId, x / 32, y / 32, engine->getCurrentMap());
}
else if (FloorItem *item = floorItemManager->findById(id))
{
floorItemManager->destroy(item);
}
}
}
break;
}
}
示例5: handleMessage
void ItemHandler::handleMessage(MessageIn &msg)
{
switch (msg.getId())
{
case SMSG_ITEM_VISIBLE:
case SMSG_ITEM_DROPPED:
{
int id = msg.readInt32();
int itemId = msg.readInt16();
msg.readInt8(); // identify flag
int x = msg.readInt16();
int y = msg.readInt16();
msg.skip(4); // amount,subX,subY / subX,subY,amount
Game *game = Game::instance();
if (!game)
break;
if (Map *map = game->getCurrentMap())
actorSpriteManager->createItem(id, itemId,
map->getTileCenter(x, y));
}
break;
case SMSG_ITEM_REMOVE:
if (FloorItem *item = actorSpriteManager->findItem(msg.readInt32()))
actorSpriteManager->destroyActor(item);
break;
}
}
示例6: 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;
}
}
示例7: dispatchMessages
void Network::dispatchMessages()
{
while (messageReady())
{
MessageIn msg = getNextMessage();
MessageHandlerIterator iter = mMessageHandlers.find(msg.getId());
if (msg.getLength() == 0)
logger->error("Zero length packet received. Exiting.");
if (iter != mMessageHandlers.end())
{
iter->second->handleMessage(msg);
}
else
{
logger->log("Unhandled packet: %x", msg.getId());
}
skip(msg.getLength());
}
}
示例8: handleTrade
void GameHandler::handleTrade(GameClient &client, MessageIn &message)
{
auto *characterComponent =
client.character->getComponent<CharacterComponent>();
int databaseId = characterComponent->getDatabaseID();
std::stringstream str;
Trade *t = characterComponent->getTrading();
if (!t)
return;
switch (message.getId())
{
case PGMSG_TRADE_CANCEL:
t->cancel();
break;
case PGMSG_TRADE_CONFIRM:
t->confirm(client.character);
break;
case PGMSG_TRADE_AGREED:
t->agree(client.character);
// log transaction
accountHandler->sendTransaction(databaseId,
TRANS_TRADE_END,
"User finished trading");
break;
case PGMSG_TRADE_SET_MONEY:
{
int money = message.readInt32();
t->setMoney(client.character, money);
// log transaction
str << "User added " << money << " money to trade.";
accountHandler->sendTransaction(databaseId,
TRANS_TRADE_MONEY, str.str());
} break;
case PGMSG_TRADE_ADD_ITEM:
{
int slot = message.readInt8();
t->addItem(client.character, slot, message.readInt8());
// log transaction
str << "User add item from slot " << slot;
accountHandler->sendTransaction(databaseId,
TRANS_TRADE_ITEM, str.str());
} break;
}
}
示例9: handleMessage
void ChatHandler::handleMessage(MessageIn &msg)
{
switch (msg.getId())
{
case GPMSG_SAY:
handleGameChatMessage(msg);
break;
case CPMSG_ENTER_CHANNEL_RESPONSE:
handleEnterChannelResponse(msg);
break;
case CPMSG_LIST_CHANNELS_RESPONSE:
handleListChannelsResponse(msg);
break;
case CPMSG_PRIVMSG:
handlePrivateMessage(msg);
break;
case CPMSG_ANNOUNCEMENT:
handleAnnouncement(msg);
break;
case CPMSG_PUBMSG:
handleChatMessage(msg);
break;
case CPMSG_QUIT_CHANNEL_RESPONSE:
handleQuitChannelResponse(msg);
break;
case CPMSG_LIST_CHANNELUSERS_RESPONSE:
handleListChannelUsersResponse(msg);
break;
case CPMSG_CHANNEL_EVENT:
handleChannelEvent(msg);
break;
case CPMSG_WHO_RESPONSE:
handleWhoResponse(msg);
break;
}
}
示例10: handleMessage
void EffectHandler::handleMessage(MessageIn &msg)
{
switch (msg.getId())
{
case GPMSG_CREATE_EFFECT_POS:
handleCreateEffectPos(msg);
break;
case GPMSG_CREATE_EFFECT_BEING:
handleCreateEffectBeing(msg);
break;
case GPMSG_CREATE_TEXT_PARTICLE:
handleCreateTextParticle(msg);
break;
case GPMSG_SHAKE:
handleShake(msg);
break;
default:
break;
}
}
示例11: 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;
}
}
示例12: 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());
//.........这里部分代码省略.........
示例13: handleMessage
void CharServerHandler::handleMessage(MessageIn &msg)
{
int slot;
LocalPlayer *tempPlayer;
switch (msg.getId())
{
case APMSG_CHAR_CREATE_RESPONSE:
handleCharCreateResponse(msg);
break;
case APMSG_CHAR_DELETE_RESPONSE:
{
int errMsg = msg.readInt8();
// Character deletion successful
if (errMsg == ERRMSG_OK)
{
delete mCharInfo->getEntry();
mCharInfo->setEntry(0);
mCharInfo->unlock();
new OkDialog("Info", "Player deleted");
}
// Character deletion failed
else
{
std::string message = "";
switch (errMsg)
{
case ERRMSG_NO_LOGIN:
message = "Not logged in";
break;
case ERRMSG_INVALID_ARGUMENT:
message = "Selection out of range";
break;
default:
message = "Unknown error";
}
mCharInfo->unlock();
new OkDialog("Error", message);
}
}
break;
case APMSG_CHAR_INFO:
tempPlayer = readPlayerData(msg, slot);
mCharInfo->unlock();
mCharInfo->select(slot);
mCharInfo->setEntry(tempPlayer);
// Close the character create dialog
if (mCharCreateDialog)
{
mCharCreateDialog->scheduleDelete();
mCharCreateDialog = 0;
}
break;
case APMSG_CHAR_SELECT_RESPONSE:
handleCharSelectResponse(msg);
break;
}
}
示例14: handleMessage
void PlayerHandler::handleMessage(MessageIn &msg)
{
switch (msg.getId())
{
case SMSG_WALK_RESPONSE:
/*
* This client assumes that all walk messages succeed,
* and that the server will send a correction notice
* otherwise.
*/
break;
case SMSG_PLAYER_WARP:
{
std::string mapPath = msg.readString(16);
bool nearby;
Uint16 x = msg.readInt16();
Uint16 y = msg.readInt16();
logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y);
/*
* We must clear the local player's target *before* the call
* to changeMap, as it deletes all beings.
*/
player_node->stopAttack();
nearby = (engine->getCurrentMapName() == mapPath);
// Switch the actual map, deleting the previous one if necessary
mapPath = mapPath.substr(0, mapPath.rfind("."));
engine->changeMap(mapPath);
float scrollOffsetX = 0.0f;
float scrollOffsetY = 0.0f;
/* Scroll if neccessary */
if (!nearby
|| (abs(x - player_node->getTileX()) > MAP_TELEPORT_SCROLL_DISTANCE)
|| (abs(y - player_node->getTileY()) > MAP_TELEPORT_SCROLL_DISTANCE))
{
scrollOffsetX = (x - player_node->getTileX()) * 32;
scrollOffsetY = (y - player_node->getTileY()) * 32;
}
player_node->setAction(Being::STAND);
player_node->mFrame = 0;
player_node->setTileCoords(x, y);
logger->log("Adjust scrolling by %d:%d", (int) scrollOffsetX,
(int) scrollOffsetY);
viewport->scrollBy(scrollOffsetX, scrollOffsetY);
}
break;
case SMSG_PLAYER_STAT_UPDATE_1:
{
int type = msg.readInt16();
int value = msg.readInt32();
switch (type)
{
case 0x0000:
player_node->setWalkSpeed(value);
break;
case 0x0004:
break; // manner
case 0x0005:
player_node->setHp(value);
break;
case 0x0006:
player_node->setMaxHp(value);
break;
case 0x0007:
player_node->setMP(value);
break;
case 0x0008:
player_node->setMaxMP(value);
break;
case 0x0009:
player_node->setCharacterPoints(value);
break;
case 0x000b:
player_node->setLevel(value);
break;
case 0x000c:
player_node->setSkillPoints(value);
break;
case 0x0018:
if (value >= player_node->getMaxWeight() / 2 &&
player_node->getTotalWeight() <
player_node->getMaxWeight() / 2)
{
weightNotice = new OkDialog(_("Message"),
_("You are carrying more than "
"half your weight. You are "
"unable to regain health."));
weightNotice->addActionListener(
&weightListener);
//.........这里部分代码省略.........
示例15: processMessage
void AccountHandler::processMessage(NetComputer *comp, MessageIn &message)
{
AccountClient &client = *static_cast< AccountClient * >(comp);
switch (message.getId())
{
case PAMSG_LOGIN_RNDTRGR:
LOG_DEBUG("Received msg ... PAMSG_LOGIN_RANDTRIGGER");
handleLoginRandTriggerMessage(client, message);
break;
case PAMSG_LOGIN:
LOG_DEBUG("Received msg ... PAMSG_LOGIN");
handleLoginMessage(client, message);
break;
case PAMSG_LOGOUT:
LOG_DEBUG("Received msg ... PAMSG_LOGOUT");
handleLogoutMessage(client);
break;
case PAMSG_RECONNECT:
LOG_DEBUG("Received msg ... PAMSG_RECONNECT");
handleReconnectMessage(client, message);
break;
case PAMSG_REGISTER:
LOG_DEBUG("Received msg ... PAMSG_REGISTER");
handleRegisterMessage(client, message);
break;
case PAMSG_UNREGISTER:
LOG_DEBUG("Received msg ... PAMSG_UNREGISTER");
handleUnregisterMessage(client, message);
break;
case PAMSG_REQUEST_REGISTER_INFO :
LOG_DEBUG("Received msg ... REQUEST_REGISTER_INFO");
handleRequestRegisterInfoMessage(client, message);
break;
case PAMSG_EMAIL_CHANGE:
LOG_DEBUG("Received msg ... PAMSG_EMAIL_CHANGE");
handleEmailChangeMessage(client, message);
break;
case PAMSG_PASSWORD_CHANGE:
LOG_DEBUG("Received msg ... PAMSG_PASSWORD_CHANGE");
handlePasswordChangeMessage(client, message);
break;
case PAMSG_CHAR_CREATE:
LOG_DEBUG("Received msg ... PAMSG_CHAR_CREATE");
handleCharacterCreateMessage(client, message);
break;
case PAMSG_CHAR_SELECT:
LOG_DEBUG("Received msg ... PAMSG_CHAR_SELECT");
handleCharacterSelectMessage(client, message);
break;
case PAMSG_CHAR_DELETE:
LOG_DEBUG("Received msg ... PAMSG_CHAR_DELETE");
handleCharacterDeleteMessage(client, message);
break;
default:
LOG_WARN("AccountHandler::processMessage, Invalid message type "
<< message.getId());
MessageOut result(XXMSG_INVALID);
client.send(result);
break;
}
}