[General] Cleanup Player packets

new-script-api
Koncord 7 years ago
parent 901fe72471
commit e44fcdc0b3

@ -40,7 +40,7 @@ void Books::addBook(const std::string &bookId)
std::string Books::getBookId(unsigned i) const
{
if (i >= player->bookChanges.count)
if (i >= player->bookChanges.books.size())
return "invalid";
return player->bookChanges.books.at(i).bookId;
@ -48,7 +48,7 @@ std::string Books::getBookId(unsigned i) const
unsigned Books::getChanges() const
{
return player->bookChanges.count;
return player->bookChanges.books.size();
}
void Books::reset()

@ -59,5 +59,5 @@ std::string Dialogue::getTopicId(unsigned int i) const
unsigned int Dialogue::getChanges() const
{
return player->topicChanges.count;
return player->topicChanges.topics.size();
}

@ -73,7 +73,7 @@ void Inventory::InitializeInventoryChanges()
int Inventory::getChangesSize() const
{
return netActor->getNetCreature()->inventoryChanges.count;
return netActor->getNetCreature()->inventoryChanges.items.size();
}
void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge)

@ -1091,7 +1091,6 @@ void LocalPlayer::sendInventory()
inventoryChanges.items.push_back(item);
}
inventoryChanges.count = (unsigned int) inventoryChanges.items.size();
inventoryChanges.action = InventoryChanges::SET;
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send();

@ -84,7 +84,6 @@ namespace mwmp
struct AttributeChanges
{
std::vector<int> attributeIndexes;
unsigned int count;
};
// Track only the indexes of the skills that have been changed,
@ -92,19 +91,16 @@ namespace mwmp
struct SkillChanges
{
std::vector<int> skillIndexes;
unsigned int count;
};
struct JournalChanges
{
std::vector<JournalItem> journalItems;
unsigned int count;
};
struct FactionChanges
{
std::vector<Faction> factions;
unsigned int count;
enum FACTION_ACTION
{
@ -119,31 +115,27 @@ namespace mwmp
struct TopicChanges
{
std::vector<Topic> topics;
unsigned int count;
};
struct KillChanges
{
std::vector<Kill> kills;
unsigned int count;
};
struct BookChanges
{
std::vector<Book> books;
unsigned int count;
};
struct MapChanges
{
std::vector<ESM::Cell> cellsExplored;
unsigned int count;
};
struct SpellbookChanges
{
std::vector<ESM::Spell> spells;
unsigned int count;
enum ACTION_TYPE
{
SET = 0,
@ -156,7 +148,6 @@ namespace mwmp
struct CellStateChanges
{
std::vector<CellState> cellStates;
unsigned int count;
};
enum RESURRECT_TYPE
@ -225,9 +216,7 @@ namespace mwmp
BasePlayer(RakNet::RakNetGUID guid) : guid(guid)
{
inventoryChanges.action = 0;
inventoryChanges.count = 0;
spellbookChanges.action = 0;
spellbookChanges.count = 0;
useCreatureName = false;
isWerewolf = false;
}

@ -22,7 +22,6 @@ namespace mwmp
struct InventoryChanges
{
std::vector<Item> items;
unsigned int count;
enum ACTION_TYPE
{
SET = 0,

@ -42,9 +42,9 @@ void BasePacket::SetSendStream(RakNet::BitStream *bitStream)
void BasePacket::SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream)
{
if (inStream != 0)
if (inStream != nullptr)
bsRead = inStream;
if (outStream != 0)
if (outStream != nullptr)
bsSend = outStream;
}

@ -76,7 +76,7 @@ namespace mwmp
bs->Read(data);
}
void RW(std::string &str, bool write, bool compress = 0)
void RW(std::string &str, bool write, bool compress = false)
{
if (write)
{
@ -101,10 +101,10 @@ namespace mwmp
}
protected:
unsigned char packetID;
uint8_t packetID;
PacketReliability reliability;
PacketPriority priority;
int orderChannel;
char orderChannel;
RakNet::BitStream *bsRead, *bsSend, *bs;
RakNet::RakPeerInterface *peer;
RakNet::RakNetGUID guid;

@ -24,7 +24,7 @@ void PacketGUIWindow::Packet(RakNet::BitStream *bs, bool send)
int32_t size;
if (send)
size = player->guiWindow.widgets.size();
size = static_cast<int32_t>(player->guiWindow.widgets.size());
RW(size, send);
if(!send)

@ -16,43 +16,40 @@ void PacketPlayerActiveSkills::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
unsigned long spells = 0;
uint32_t spellCount = 0;
if (send)
spells = player->activeSpells.mSpells.size();
spellCount = static_cast<uint32_t>(player->activeSpells.mSpells.size());
RW(spells, send);
RW(spellCount, send);
if (send)
for (ESM::ActiveSpells::TContainer::const_iterator spell = player->activeSpells.mSpells.begin();
spell != player->activeSpells.mSpells.end(); ++spell)
{
RW(spell->first, true);
RW(spell->second.mTimeStamp, true);
unsigned long effects = spell->second.mEffects.size();
RW(effects, true);
auto fnRWSpell = [this, &send](ESM::ActiveSpells::TContainer::value_type &spell) {
RW(spell.first, send);
RW(spell.second.mTimeStamp, send);
uint32_t effectsCount;
if(send)
effectsCount = static_cast<uint32_t>(spell.second.mEffects.size());
RW(effectsCount, send);
for (std::vector<ESM::ActiveEffect>::const_iterator effect = spell->second.mEffects.begin();
effect != spell->second.mEffects.end(); ++effect)
RW(effect, true);
if(!send)
spell.second.mEffects.resize(effectsCount);
for (auto &&effect : spell.second.mEffects)
RW(effect, send);
};
if (send)
for (auto && spell : player->activeSpells.mSpells)
{
fnRWSpell(spell);
}
else
for (unsigned int i = 0; i < spells; i++)
for (unsigned int i = 0; i < spellCount; i++)
{
ESM::ActiveSpells::TContainer::value_type spell;
RW(spell.first, false);
RW(spell.second.mTimeStamp, false);
unsigned long effects;
RW(effects, false);
ESM::ActiveEffect effect;
for (unsigned int j = 0; j < effects; j++)
{
RW(effect, false);
spell.second.mEffects.push_back(effect);
}
fnRWSpell(spell);
player->activeSpells.mSpells.insert(spell);
}
}

@ -13,23 +13,23 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
unsigned count;
if (send)
player->attributeChanges.count = (unsigned int)(player->attributeChanges.attributeIndexes.size());
else
player->attributeChanges.attributeIndexes.clear();
count = (unsigned int)(player->attributeChanges.attributeIndexes.size());
RW(player->attributeChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->attributeChanges.count; i++)
if(!send)
{
int attributeId;
if (send)
attributeId = player->attributeChanges.attributeIndexes.at(i);
player->attributeChanges.attributeIndexes.clear();
player->attributeChanges.attributeIndexes.resize(count);
}
RW(attributeId, send);
for (auto &&attributeIndex : player->attributeChanges.attributeIndexes)
{
RW(attributeIndex, send);
RW(player->creatureStats.mAttributes[attributeId], send);
RW(player->npcStats.mSkillIncrease[attributeId], send);
RW(player->creatureStats.mAttributes[attributeIndex], send);
RW(player->npcStats.mSkillIncrease[attributeIndex], send);
}
}

@ -13,23 +13,21 @@ void PacketPlayerBook::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->bookChanges.count = (unsigned int)(player->bookChanges.books.size());
else
player->bookChanges.books.clear();
count = static_cast<uint32_t>(player->bookChanges.books.size());
RW(player->bookChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->bookChanges.count; i++)
if(!send)
{
Book book;
if (send)
book = player->bookChanges.books.at(i);
RW(book.bookId, send, 1);
player->bookChanges.books.clear();
player->bookChanges.books.resize(count);
}
if (!send)
player->bookChanges.books.push_back(book);
for (auto &&book : player->bookChanges.books)
{
RW(book.bookId, send, true);
}
}

@ -13,25 +13,24 @@ void mwmp::PacketPlayerCellState::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->cellStateChanges.count = (unsigned int)(player->cellStateChanges.cellStates.size());
else
player->cellStateChanges.cellStates.clear();
count = static_cast<uint32_t>(player->cellStateChanges.cellStates.size());
RW(player->cellStateChanges.count, send);
for (unsigned int i = 0; i < player->cellStateChanges.count; i++)
RW(count, send);
if(!send)
{
CellState cellState;
player->cellStateChanges.cellStates.clear();
player->cellStateChanges.cellStates.resize(count);
}
if (send)
cellState = player->cellStateChanges.cellStates.at(i);
for (auto &&cellState : player->cellStateChanges.cellStates)
{
RW(cellState.type, send);
RW(cellState.cell.mData, send, 1);
RW(cellState.cell.mName, send, 1);
if (!send)
player->cellStateChanges.cellStates.push_back(cellState);
RW(cellState.cell.mData, send, true);
RW(cellState.cell.mName, send, true);
}
}

@ -18,8 +18,8 @@ void mwmp::PacketPlayerClass::Packet(RakNet::BitStream *bs, bool send)
if (player->charClass.mId.empty()) // custom class
{
RW(player->charClass.mName, send, 1);
RW(player->charClass.mDescription, send, 1);
RW(player->charClass.mData, send, 1);
RW(player->charClass.mName, send, true);
RW(player->charClass.mDescription, send, true);
RW(player->charClass.mData, send, true);
}
}

@ -22,7 +22,7 @@ namespace mwmp
{
PlayerPacket::Packet(bs, send);
RW(player->deathReason, send, 1);
RW(player->deathReason, send, true);
}
};
}

@ -16,10 +16,10 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
for (int i = 0; i < 19; i++)
for (auto &equipedItem : player->equipedItems)
{
RW(player->equipedItems[i].refId, send, 1);
RW(player->equipedItems[i].count, send);
RW(player->equipedItems[i].charge, send);
RW(equipedItem.refId, send, true);
RW(equipedItem.count, send);
RW(equipedItem.charge, send);
}
}

@ -15,21 +15,22 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
RW(player->factionChanges.action, send);
uint32_t count;
if (send)
player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size());
else
player->factionChanges.factions.clear();
count = static_cast<uint32_t>(player->factionChanges.factions.size());
RW(player->factionChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->factionChanges.count; i++)
if(!send)
{
Faction faction;
if (send)
faction = player->factionChanges.factions.at(i);
player->factionChanges.factions.clear();
player->factionChanges.factions.resize(count);
}
RW(faction.factionId, send, 1);
for (auto &&faction : player->factionChanges.factions)
{
RW(faction.factionId, send, true);
if (player->factionChanges.action == FactionChanges::RANK)
RW(faction.rank, send);
@ -39,8 +40,5 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
if (player->factionChanges.action == FactionChanges::REPUTATION)
RW(faction.reputation, send);
if (!send)
player->factionChanges.factions.push_back(faction);
}
}

@ -19,25 +19,23 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send)
RW(player->inventoryChanges.action, send);
uint32_t count;
if (send)
player->inventoryChanges.count = (unsigned int) (player->inventoryChanges.items.size());
else
player->inventoryChanges.items.clear();
count = static_cast<uint32_t>(player->inventoryChanges.items.size());
RW(player->inventoryChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->inventoryChanges.count; i++)
if(!send)
{
Item item;
if (send)
item = player->inventoryChanges.items.at(i);
player->inventoryChanges.items.clear();
player->inventoryChanges.items.resize(count);
}
RW(item.refId, send, 1);
for (auto &&item : player->inventoryChanges.items)
{
RW(item.refId, send, true);
RW(item.count, send);
RW(item.charge, send);
if (!send)
player->inventoryChanges.items.push_back(item);
}
}

@ -16,6 +16,6 @@ void PacketPlayerJail::Packet(RakNet::BitStream *bs, bool send)
RW(player->jailDays, send);
RW(player->ignoreJailTeleportation, send);
RW(player->ignoreJailSkillIncreases, send);
RW(player->jailProgressText, send, 1);
RW(player->jailEndText, send, 1);
RW(player->jailProgressText, send, true);
RW(player->jailEndText, send, true);
}

@ -13,30 +13,26 @@ void PacketPlayerJournal::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->journalChanges.count = (unsigned int)(player->journalChanges.journalItems.size());
else
player->journalChanges.journalItems.clear();
count = static_cast<uint32_t>(player->journalChanges.journalItems.size());
RW(player->journalChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->journalChanges.count; i++)
if(!send)
{
JournalItem journalItem;
if (send)
journalItem = player->journalChanges.journalItems.at(i);
player->journalChanges.journalItems.clear();
player->journalChanges.journalItems.resize(count);
}
for (auto &&journalItem : player->journalChanges.journalItems)
{
RW(journalItem.type, send);
RW(journalItem.quest, send, 1);
RW(journalItem.quest, send, true);
RW(journalItem.index, send);
if (journalItem.type == JournalItem::ENTRY)
{
RW(journalItem.actorRefId, send, 1);
}
if (!send)
player->journalChanges.journalItems.push_back(journalItem);
RW(journalItem.actorRefId, send, true);
}
}

@ -9,25 +9,23 @@ mwmp::PacketPlayerKillCount::PacketPlayerKillCount(RakNet::RakPeerInterface *pee
void mwmp::PacketPlayerKillCount::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->killChanges.count = (unsigned int)(player->killChanges.kills.size());
else
player->killChanges.kills.clear();
count = static_cast<uint32_t>(player->killChanges.kills.size());
RW(player->killChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->killChanges.count; i++)
if(!send)
{
Kill kill;
if (send)
kill = player->killChanges.kills.at(i);
player->killChanges.kills.clear();
player->killChanges.kills.resize(count);
}
RW(kill.refId, send, 1);
for (auto &&kill : player->killChanges.kills)
{
RW(kill.refId, send, true);
RW(kill.number, send);
if (!send)
player->killChanges.kills.push_back(kill);
}
}

@ -12,25 +12,23 @@ PacketPlayerMap::PacketPlayerMap(RakNet::RakPeerInterface *peer) : PlayerPacket(
void PacketPlayerMap::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->mapChanges.count = (unsigned int)(player->mapChanges.cellsExplored.size());
else
player->mapChanges.cellsExplored.clear();
count = static_cast<uint32_t>(player->mapChanges.cellsExplored.size());
RW(player->mapChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->mapChanges.count; i++)
if(!send)
{
ESM::Cell cellExplored;
if (send)
cellExplored = player->mapChanges.cellsExplored.at(i);
RW(cellExplored.mData, send, 1);
RW(cellExplored.mName, send, 1);
player->mapChanges.cellsExplored.clear();
player->mapChanges.cellsExplored.resize(count);
}
if (!send)
player->mapChanges.cellsExplored.push_back(cellExplored);
for (auto &&cellExplored : player->mapChanges.cellsExplored)
{
RW(cellExplored.mData, send, true);
RW(cellExplored.mName, send, true);
}
}

@ -29,10 +29,10 @@ void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send)
dir = (player->direction.pos[0] >= 0 ? (unsigned char)(player->direction.pos[0]) : (unsigned char) 0x3) << 2; // pack direction
dir += (player->direction.pos[1] >= 0 ? (unsigned char)(player->direction.pos[1]) : (unsigned char) 0x3);
}
RW(rot[0], send, 1);
RW(rot[1], send, 1);
RW(rot[0], send, true);
RW(rot[1], send, true);
RW(player->position.pos, send, 1);
RW(player->position.pos, send, true);
RW(dir, send);
if (!send)

@ -17,21 +17,22 @@ PacketPlayerSkill::PacketPlayerSkill(RakNet::RakPeerInterface *peer) : PlayerPac
void PacketPlayerSkill::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->skillChanges.count = (unsigned int)(player->skillChanges.skillIndexes.size());
else
player->skillChanges.skillIndexes.clear();
count = static_cast<uint32_t>(player->skillChanges.skillIndexes.size());
RW(player->skillChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->skillChanges.count; i++)
if(!send)
{
int skillId;
if (send)
skillId = player->skillChanges.skillIndexes.at(i);
player->skillChanges.skillIndexes.clear();
player->skillChanges.skillIndexes.resize(count);
}
for (auto && skillId : player->skillChanges.skillIndexes)
{
RW(skillId, send);
RW(player->npcStats.mSkills[skillId], send);
}

@ -15,58 +15,56 @@ void PacketPlayerSpellbook::Packet(RakNet::BitStream *bs, bool send)
RW(player->spellbookChanges.action, send);
uint32_t changesCount;
if (send)
player->spellbookChanges.count = (unsigned int) (player->spellbookChanges.spells.size());
else
player->spellbookChanges.spells.clear();
changesCount = static_cast<uint32_t>(player->spellbookChanges.spells.size());
RW(player->spellbookChanges.count, send);
RW(changesCount, send);
for (unsigned int i = 0; i < player->spellbookChanges.count; i++)
if(!send)
{
ESM::Spell spell;
player->spellbookChanges.spells.clear();
player->spellbookChanges.spells.resize(changesCount);
}
if (send)
spell = player->spellbookChanges.spells.at(i);
for (auto &&spell : player->spellbookChanges.spells)
{
RW(spell.mId, send, 1);
RW(spell.mId, send, true);
if(spell.mId.find("$dynamic") != string::npos)
{
RW(spell.mName, send, 1);
RW(spell.mName, send, true);
RW(spell.mData.mType, send, 1);
RW(spell.mData.mCost, send, 1);
RW(spell.mData.mFlags, send, 1);
RW(spell.mData.mType, send, true);
RW(spell.mData.mCost, send, true);
RW(spell.mData.mFlags, send, true);
int effectCount = 0;
uint32_t effectCount;
if (send)
effectCount = spell.mEffects.mList.size();
effectCount = static_cast<uint32_t>(spell.mEffects.mList.size());
RW(effectCount, send, 1);
RW(effectCount, send, true);
if (!send)
{
spell.mEffects.mList.resize(effectCount);
}
for (unsigned int j = 0; j < effectCount; j++)
for (auto &&effect : spell.mEffects.mList)
{
ESM::ENAMstruct effect;
if (send)
effect = spell.mEffects.mList.at(j);
RW(effect.mEffectID, send, 1);
RW(effect.mSkill, send, 1);
RW(effect.mAttribute, send, 1);
RW(effect.mRange, send, 1);
RW(effect.mArea, send, 1);
RW(effect.mDuration, send, 1);
RW(effect.mMagnMin, send, 1);
RW(effect.mMagnMax, send, 1);
if(!send)
spell.mEffects.mList.push_back(effect);
RW(effect.mEffectID, send, true);
RW(effect.mSkill, send, true);
RW(effect.mAttribute, send, true);
RW(effect.mRange, send, true);
RW(effect.mArea, send, true);
RW(effect.mDuration, send, true);
RW(effect.mMagnMin, send, true);
RW(effect.mMagnMax, send, true);
}
}
if (!send)
player->spellbookChanges.spells.push_back(spell);
}
}

@ -12,24 +12,16 @@ PacketPlayerTopic::PacketPlayerTopic(RakNet::RakPeerInterface *peer) : PlayerPac
void PacketPlayerTopic::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->topicChanges.count = (unsigned int)(player->topicChanges.topics.size());
else
player->topicChanges.topics.clear();
count = static_cast<uint32_t>(player->topicChanges.topics.size());
RW(player->topicChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->topicChanges.count; i++)
for (auto &&topic : player->topicChanges.topics)
{
Topic topic;
if (send)
topic = player->topicChanges.topics.at(i);
RW(topic.topicId, send, 1);
if (!send)
player->topicChanges.topics.push_back(topic);
RW(topic.topicId, send, true);
}
}

Loading…
Cancel
Save