本文整理汇总了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);
}
示例2: handlePrivateMessage
void ChatHandler::handlePrivateMessage(MessageIn &msg)
{
std::string userNick = msg.readString();
std::string chatMsg = msg.readString();
chatWindow->whisper(userNick, chatMsg);
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例9: readUpdateHost
void LoginHandler::readUpdateHost(MessageIn &msg)
{
// Set the update host when included in the message
if (msg.getUnreadLength() > 0)
{
mLoginData->updateHost = msg.readString();
}
}
示例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);
}
示例11: handleQuitChannelResponse
void ChatHandler::handleQuitChannelResponse(MessageIn &msg)
{
if(msg.readInt8() == ERRMSG_OK)
{
short channelId = msg.readInt16();
Channel *channel = channelManager->findById(channelId);
channelManager->removeChannel(channel);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}