sol2-server-rewrite
David Cernat 6 years ago
commit 5cf71a4e67

@ -14,7 +14,6 @@ void Factions::Init(LuaState &lua)
{
lua.getState()->new_usertype<Factions>("Factions",
"addFaction", &Factions::addFaction,
"changesAction", sol::property(&Factions::getFactionChangesAction, &Factions::setFactionChangesAction),
"getFaction", &Factions::getFaction,
"setFaction", &Factions::setFaction,
"clear", &Factions::clear,
@ -40,20 +39,9 @@ void Factions::processUpdate()
clear();
}
mwmp::FactionChanges::Type Factions::getFactionChangesAction() const
void Factions::addFaction(const Faction &faction)
{
return player->factionChanges.action;
}
void Factions::setFactionChangesAction(mwmp::FactionChanges::Type action)
{
player->factionChanges.action = action;
setChanged();
}
void Factions::addFaction(Faction faction)
{
player->factionChanges.factions.push_back(faction.faction);
player->factionChanges.factions.emplace_back(faction.faction);
setChanged();
}
@ -63,7 +51,7 @@ Faction Factions::getFaction(int id) const
return Faction(player->factionChanges.factions.at(id));
}
void Factions::setFaction(int id, Faction faction)
void Factions::setFaction(int id, const Faction &faction)
{
player->factionChanges.factions.at(id) = faction.faction;
setChanged();
@ -112,6 +100,7 @@ int Faction::getFactionRank() const
void Faction::setFactionRank(unsigned int rank)
{
faction.rankChanged();
faction.rank = rank;
}
@ -122,6 +111,7 @@ bool Faction::getFactionExpulsionState() const
void Faction::setFactionExpulsionState(bool expulsionState)
{
faction.expulsionChanged();
faction.isExpelled = expulsionState;
}
@ -132,5 +122,6 @@ int Faction::getFactionReputation() const
void Faction::setFactionReputation(int reputation)
{
faction.reputationChanged();
faction.reputation = reputation;
}

@ -42,13 +42,9 @@ public:
explicit Factions(Player *player);
~Factions();
mwmp::FactionChanges::Type getFactionChangesAction() const;
void setFactionChangesAction(mwmp::FactionChanges::Type action);
void addFaction(Faction faction);
void addFaction(const Faction &faction);
Faction getFaction(int id) const;
void setFaction(int id, Faction faction);
void setFaction(int id, const Faction &faction);
size_t size() const;
void clear();

@ -33,7 +33,7 @@ void Inventory::Init(LuaState &lua)
);
}
Inventory::Inventory(NetActor *actor) : netActor(actor), equipmentChanged(false), inventoryChanged(mwmp::InventoryChanges::Type::None)
Inventory::Inventory(NetActor *actor) : netActor(actor), equipmentChanged(false), inventoryChanged(false)
{
printf("Inventory::Inventory()\n");
}
@ -85,19 +85,12 @@ void Inventory::update()
inventoryChanged = 0;*/
}
void Inventory::InitializeInventoryChanges()
{
netActor->getNetCreature()->inventoryChanges.items.clear();
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Set;
}
int Inventory::getChangesSize() const
{
return netActor->getNetCreature()->inventoryChanges.items.size();
}
void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, double enchantmentCharge)
void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, float enchantmentCharge)
{
netActor->getNetCreature()->equipmentItems[slot].refId = refId;
netActor->getNetCreature()->equipmentItems[slot].count = count;
@ -119,12 +112,10 @@ void Inventory::unequipItem( unsigned short slot)
}
void Inventory::addItem(const std::string &refId, unsigned int count, int charge, double enchantmentCharge)
void Inventory::addItem(const std::string &refId, unsigned int count, int charge, float enchantmentCharge)
{
if (inventoryChanged == mwmp::InventoryChanges::Type::Remove)
return;
if (inventoryChanged == mwmp::InventoryChanges::Type::None)
InitializeInventoryChanges();
if(!inventoryChanged)
resetInventoryFlag();
mwmp::Item item;
item.refId = refId;
@ -132,29 +123,24 @@ void Inventory::addItem(const std::string &refId, unsigned int count, int charge
item.charge = charge;
item.enchantmentCharge = enchantmentCharge;
netActor->getNetCreature()->inventoryChanges.items.push_back(item);
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Add;
if (inventoryChanged == mwmp::InventoryChanges::Type::None && netActor->isPlayer())
netActor->getNetCreature()->inventoryChanges.items.emplace_back(item, mwmp::InventoryChanges::Action::Add);
if (netActor->isPlayer())
netActor->toPlayer()->addToUpdateQueue();
inventoryChanged = netActor->getNetCreature()->inventoryChanges.action;
inventoryChanged = true;
}
void Inventory::removeItem(const std::string &refId, unsigned short count)
{
if (inventoryChanged == mwmp::InventoryChanges::Type::Add)
return;
if (inventoryChanged == mwmp::InventoryChanges::Type::None)
InitializeInventoryChanges();
if(!inventoryChanged)
resetInventoryFlag();
mwmp::Item item;
item.refId = refId;
item.count = count;
netActor->getNetCreature()->inventoryChanges.items.push_back(item);
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Remove;
if (inventoryChanged == mwmp::InventoryChanges::Type::None && netActor->isPlayer())
netActor->getNetCreature()->inventoryChanges.items.emplace_back(item, mwmp::InventoryChanges::Action::Remove);
if (netActor->isPlayer())
netActor->toPlayer()->addToUpdateQueue();
inventoryChanged = netActor->getNetCreature()->inventoryChanges.action;
inventoryChanged = true;
}
bool Inventory::hasItemEquipped(const std::string &refId) const
@ -173,7 +159,7 @@ std::tuple<std::string, int, int, double> Inventory::getEquipmentItem(unsigned s
std::tuple<std::string, int, int, double> Inventory::getInventoryItem(unsigned int slot) const
{
const auto &item = netActor->getNetCreature()->inventoryChanges.items.at(slot);
const auto &item = netActor->getNetCreature()->inventoryChanges.items.at(slot).first;
return make_tuple(item.refId, item.count, item.charge, item.enchantmentCharge);
}
@ -189,15 +175,14 @@ bool Inventory::isEquipmentChanged()
return equipmentChanged;
}
void Inventory::resetInventoryFlag()
{
inventoryChanged = mwmp::InventoryChanges::Type::None;
}
mwmp::InventoryChanges::Type Inventory::inventoryChangeType()
bool Inventory::isInventoryChanged()
{
return inventoryChanged;
}
void Inventory::resetInventoryFlag()
{
inventoryChanged = false;
netActor->getNetCreature()->inventoryChanges.items.clear();
}

@ -16,7 +16,7 @@ public:
static void Init(LuaState &lua);
bool isEquipmentChanged();
void resetEquipmentFlag();
mwmp::InventoryChanges::Type inventoryChangeType();
bool isInventoryChanged();
void resetInventoryFlag();
public:
explicit Inventory(NetActor *netActor);
@ -25,7 +25,7 @@ public:
//inventory
int getChangesSize() const;
void addItem(const std::string& refId, unsigned int count, int charge, double enchantmentCharge);
void addItem(const std::string& refId, unsigned int count, int charge, float enchantmentCharge);
void removeItem(const std::string& refId, unsigned short count);
/**
@ -37,7 +37,7 @@ public:
// equipment
void equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, double enchantmentCharge);
void equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, float enchantmentCharge);
void unequipItem(unsigned short slot);
bool hasItemEquipped(const std::string& refId) const;
@ -49,15 +49,11 @@ public:
*/
std::tuple<std::string,int, int, double> getEquipmentItem(unsigned short slot) const;
private:
void InitializeInventoryChanges();
private:
// not controlled pointer
NetActor *netActor;
bool equipmentChanged;
mwmp::InventoryChanges::Type inventoryChanged;
bool inventoryChanged;
};

@ -147,12 +147,12 @@ void Object::setCharge(int charge)
}
double Object::getEnchantmentCharge() const
float Object::getEnchantmentCharge() const
{
return object.enchantmentCharge;
}
void Object::setEnchantmentCharge(double enchantmentCharge)
void Object::setEnchantmentCharge(float enchantmentCharge)
{
changedObjectPlace = true;
object.enchantmentCharge = enchantmentCharge;
@ -251,7 +251,7 @@ tuple<string, int, int, double> Container::getItem(int i) const
return make_tuple(item.refId, item.count, item.charge, item.enchantmentCharge);
}
void Container::setItem(int i, const string &refId, int count, int charge, double enchantmentCharge)
void Container::setItem(int i, const string &refId, int count, int charge, float enchantmentCharge)
{
auto &item = object.containerItems.at(i);
item.refId = refId;
@ -261,7 +261,7 @@ void Container::setItem(int i, const string &refId, int count, int charge, doubl
changed = true;
}
void Container::addItem(const string &refId, int count, int charge, double enchantmentCharge)
void Container::addItem(const string &refId, int count, int charge, float enchantmentCharge)
{
mwmp::ContainerItem item;
item.refId = refId;
@ -296,6 +296,12 @@ void ObjectController::Init(LuaState &lua)
return lua.getObjectCtrl().sendContainers(player, objects, Utils::getCellFromDescription(cellDescription));
});
objectCtrl.set_function("sendConsoleCommand", [&lua](shared_ptr<Player> player, shared_ptr<vector<shared_ptr<Object>>> objects,
const std::string &cellDescription, const std::string &command,
bool broadcast) {
return lua.getObjectCtrl().sendConsoleCommand(player, objects, Utils::getCellFromDescription(cellDescription),
command, broadcast);
});
objectCtrl.set_function("requestContainers", [&lua](shared_ptr<Player> player) {
lua.getObjectCtrl().requestContainers(player);
});

@ -66,8 +66,8 @@ public:
int getCharge() const;
void setCharge(int charge);
double getEnchantmentCharge() const;
void setEnchantmentCharge(double enchantmentCharge);
float getEnchantmentCharge() const;
void setEnchantmentCharge(float enchantmentCharge);
int getGoldValue() const;
void setGoldValue(int gold);
@ -99,9 +99,9 @@ public:
Container();
std::tuple<std::string, int, int, double> getItem(int i) const;
void addItem(const std::string &refId, int count, int charge, double enchantmentCharge);
void addItem(const std::string &refId, int count, int charge, float enchantmentCharge);
void setItem(int i, const std::string &refId, int count, int charge, double enchantmentCharge);
void setItem(int i, const std::string &refId, int count, int charge, float enchantmentCharge);
int getActionCount(int i) const;
size_t size() const;

@ -124,6 +124,7 @@ Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedM
storedData = mwmp::Networking::get().getState().getState()->create_table();
customData = mwmp::Networking::get().getState().getState()->create_table();
isActorPlayer = true;
inUpdateQueue = false;
}
Player::~Player()
@ -218,7 +219,7 @@ void Player::update()
inventory.resetEquipmentFlag();
}
if (inventory.inventoryChangeType() != mwmp::InventoryChanges::Type::None)
if (inventory.isInventoryChanged())
{
auto packet = plPCtrl->GetPacket(ID_PLAYER_INVENTORY);
packet->setPlayer(this);

@ -15,7 +15,7 @@ void GameSettings::Init(LuaState &lua)
lua.getState()->new_usertype<GameSettings>("Settings",
"setDifficulty", &GameSettings::setDifficulty,
"setConsoleAllowed", &GameSettings::setConsoleAllowed,
"setBedRestAllowed", &GameSettings::setConsoleAllowed,
"setBedRestAllowed", &GameSettings::setBedRestAllowed,
"setWildernessRestAllowed", &GameSettings::setWildernessRestAllowed,
"setWaitAllowed", &GameSettings::setWaitAllowed
);

@ -27,11 +27,6 @@ mwmp::Cell::Cell(MWWorld::CellStore* cellStore)
updateTimer = 0;
}
Cell::~Cell()
{
}
void Cell::updateLocal(bool forceUpdate)
{
if (localActors.empty())
@ -284,7 +279,7 @@ void Cell::readCellChange(ActorList& actorList)
std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor);
// Is a packet mistakenly moving the actor to the cell it's already in? If so, ignore it
if (Misc::StringUtils::ciEqual(getDescription(), baseActor.cell.getDescription()))
if (Misc::StringUtils::ciEqual(getDescription(), baseActor->cell.getDescription()))
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedActor %s moved to %s, but it was already there",
mapIndex.c_str(), getDescription().c_str());
@ -434,12 +429,12 @@ void Cell::uninitializeDedicatedActors()
dedicatedActors.clear();
}
LocalActor *Cell::getLocalActor(std::string actorIndex)
LocalActor *Cell::getLocalActor(const std::string &actorIndex)
{
return localActors.at(actorIndex);
}
DedicatedActor *Cell::getDedicatedActor(std::string actorIndex)
DedicatedActor *Cell::getDedicatedActor(const std::string &actorIndex)
{
return dedicatedActors.at(actorIndex);
}

@ -12,8 +12,8 @@ namespace mwmp
{
public:
Cell(MWWorld::CellStore* cellStore);
virtual ~Cell();
explicit Cell(MWWorld::CellStore* cellStore);
~Cell() = default;
void updateLocal(bool forceUpdate);
void updateDedicated(float dt);
@ -36,8 +36,8 @@ namespace mwmp
void uninitializeLocalActors();
void uninitializeDedicatedActors();
virtual LocalActor *getLocalActor(std::string actorIndex);
virtual DedicatedActor *getDedicatedActor(std::string actorIndex);
LocalActor *getLocalActor(const std::string &actorIndex);
DedicatedActor *getDedicatedActor(const std::string &actorIndex);
bool hasLocalAuthority();
void setAuthority(const RakNet::RakNetGUID& guid);

@ -177,15 +177,18 @@ void DedicatedActor::setEquipment()
const string &packetRefId = equipmentItems[slot].refId;
int packetCharge = equipmentItems[slot].charge;
std::string storeRefId = "";
bool equal = false;
if (it != invStore.end())
{
storeRefId = it->getCellRef().getRefId();
std::string storeRefId = it->getCellRef().getRefId();
int count = invStore.count(storeRefId);
if (!Misc::StringUtils::ciEqual(storeRefId, packetRefId)) // if other item equiped
if (!Misc::StringUtils::ciEqual(storeRefId, packetRefId)) // if other item equipped
{
invStore.unequipSlot(slot, ptr);
ptr.getClass().getContainerStore(ptr).remove(storeRefId, count, ptr);
}
else
equal = true;
}

@ -170,11 +170,10 @@ void DedicatedPlayer::setEquipment()
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
const string &dedicItem = equipmentItems[slot].refId;
std::string item = "";
bool equal = false;
if (it != invStore.end())
{
item = it->getCellRef().getRefId();
const std::string &item = it->getCellRef().getRefId();
if (!Misc::StringUtils::ciEqual(item, dedicItem)) // if other item equiped
{
MWWorld::ContainerStore &store = ptr.getClass().getContainerStore(ptr);

@ -457,11 +457,11 @@ void LocalPlayer::updateEquipment(bool forceUpdate)
item.refId = "";
item.count = 0;
item.charge = -1;
item.enchantmentCharge = -1;
item.enchantmentCharge = -1.0f;
}
}
if (equipmentIndexChanges.size() > 0)
if (!equipmentIndexChanges.empty())
{
getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->Send();
@ -500,7 +500,7 @@ void LocalPlayer::updateInventory(bool forceUpdate)
if (setItem(item, *result))
continue;
if (item == itemOld)
if (item == itemOld.first)
break;
}
if (result == ptrInventory.end())
@ -520,7 +520,9 @@ void LocalPlayer::updateInventory(bool forceUpdate)
auto items = inventoryChanges.items;
if (find(items.begin(), items.end(), item) == items.end())
if (find_if(items.begin(), items.end(), [&item](const std::pair<Item, InventoryChanges::Action> &a) {
return item == a.first;
}) == items.end())
{
invChanged = true;
break;
@ -650,27 +652,25 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
}
}
void LocalPlayer::addItems()
void LocalPlayer::addItem(const Item &item)
{
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
for (const auto &item : inventoryChanges.items)
try
{
try
{
MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer);
if (item.charge != -1)
itemPtr.getCellRef().setCharge(item.charge);
MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer);
if (item.charge != -1)
itemPtr.getCellRef().setCharge(item.charge);
if (item.enchantmentCharge != -1)
itemPtr.getCellRef().setEnchantmentCharge(item.enchantmentCharge);
}
catch (std::exception&)
{
LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid inventory item %s", item.refId.c_str());
}
if (item.enchantmentCharge != -1.0f)
itemPtr.getCellRef().setEnchantmentCharge(item.enchantmentCharge);
}
catch (std::exception&)
{
LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid inventory item %s", item.refId.c_str());
}
}
void LocalPlayer::addSpells()
@ -732,13 +732,12 @@ void LocalPlayer::addTopics()
}
}
void LocalPlayer::removeItems()
void LocalPlayer::removeItem(const Item &item)
{
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
for (const auto &item : inventoryChanges.items)
ptrStore.remove(item.refId, item.count, ptrPlayer);
ptrStore.remove(item.refId, item.count, ptrPlayer);
}
void LocalPlayer::removeSpells()
@ -1067,7 +1066,11 @@ void LocalPlayer::setInventory()
ptrStore.clear();
// Proceed by adding items
addItems();
for(const auto &item : inventoryChanges.items)
{
if(item.second == InventoryChanges::Action::Set)
addItem(item.first);
}
// Don't automatically setEquipment() here, or the player could end
// up getting a new set of their starting clothes, or other items
@ -1172,7 +1175,7 @@ void LocalPlayer::setFactions()
if (!ptrNpcStats.isInFaction(faction.factionId))
ptrNpcStats.joinFaction(faction.factionId);
if (factionChanges.action == mwmp::FactionChanges::Type::Rank)
if (faction.isRankChanged())
{
// While the faction rank is different in the packet than in the NpcStats,
// adjust the NpcStats accordingly
@ -1184,7 +1187,8 @@ void LocalPlayer::setFactions()
ptrNpcStats.lowerRank(faction.factionId);
}
}
else if (factionChanges.action == mwmp::FactionChanges::Type::Expulsion)
if (faction.isExpulsionChanged())
{
// If the expelled state is different in the packet than in the NpcStats,
// adjust the NpcStats accordingly
@ -1197,7 +1201,7 @@ void LocalPlayer::setFactions()
}
}
else if (factionChanges.action == mwmp::FactionChanges::Type::Reputation)
if (faction.isReputationChanged())
ptrNpcStats.setFactionReputation(faction.factionId, faction.reputation);
}
}
@ -1272,10 +1276,9 @@ void LocalPlayer::sendInventory()
item.charge = iter.getCellRef().getCharge();
item.enchantmentCharge = iter.getCellRef().getEnchantmentCharge();
inventoryChanges.items.push_back(item);
inventoryChanges.items.emplace_back(item, InventoryChanges::Action::Set);
}
inventoryChanges.action = InventoryChanges::Type::Set;
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send();
}
@ -1416,11 +1419,11 @@ void LocalPlayer::sendJournalIndex(const std::string& quest, int index)
void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
{
factionChanges.factions.clear();
factionChanges.action = FactionChanges::Type::Rank;
mwmp::Faction faction;
faction.factionId = factionId;
faction.rank = rank;
faction.rankChanged();
factionChanges.factions.push_back(faction);
@ -1431,11 +1434,11 @@ void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool isExpelled)
{
factionChanges.factions.clear();
factionChanges.action = FactionChanges::Type::Expulsion;
mwmp::Faction faction;
faction.factionId = factionId;
faction.isExpelled = isExpelled;
faction.expulsionChanged();
factionChanges.factions.push_back(faction);
@ -1446,11 +1449,11 @@ void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool i
void LocalPlayer::sendFactionReputation(const std::string& factionId, int reputation)
{
factionChanges.factions.clear();
factionChanges.action = FactionChanges::Type::Reputation;
mwmp::Faction faction;
faction.factionId = factionId;
faction.reputation = reputation;
faction.reputationChanged();
factionChanges.factions.push_back(faction);

@ -38,12 +38,12 @@ namespace mwmp
void updateDeadState(bool forceUpdate = false);
void updateAnimFlags(bool forceUpdate = false);
void addItems();
void addItem(const Item &item);
void addSpells();
void addJournalItems();
void addTopics();
void removeItems();
void removeItem(const Item &item);
void removeSpells();
void resurrect();

@ -90,7 +90,7 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore)
if (containerItem.charge > -1)
newPtr.getCellRef().setCharge(containerItem.charge);
if (containerItem.enchantmentCharge > -1)
if (containerItem.enchantmentCharge > -1.0f)
newPtr.getCellRef().setEnchantmentCharge(containerItem.enchantmentCharge);
containerStore.add(newPtr, containerItem.count, ownerPtr, true);
@ -173,7 +173,7 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore)
if (worldObject.charge > -1)
newPtr.getCellRef().setCharge(worldObject.charge);
if (worldObject.enchantmentCharge > -1)
if (worldObject.enchantmentCharge > -1.0f)
newPtr.getCellRef().setEnchantmentCharge(worldObject.enchantmentCharge);
newPtr.getCellRef().setGoldValue(worldObject.goldValue);

@ -29,12 +29,19 @@ namespace mwmp
{
LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
if (localPlayer.inventoryChanges.action == InventoryChanges::Type::Add)
localPlayer.addItems();
else if (localPlayer.inventoryChanges.action == InventoryChanges::Type::Remove)
localPlayer.removeItems();
else // InventoryChanges::SET
localPlayer.setInventory();
for (const auto &item : localPlayer.inventoryChanges.items)
{
if (item.second == InventoryChanges::Action::Add)
localPlayer.addItem(item.first);
else if (item.second == InventoryChanges::Action::Remove)
localPlayer.removeItem(item.first);
else // InventoryChanges::SET
{
// found set flag, clear and reset inventory
localPlayer.setInventory();
break;
}
}
}
}
};

@ -50,7 +50,7 @@ namespace mwmp
{
Set = 0,
Add,
Remsove,
Remove,
Request
};

@ -12,7 +12,7 @@ namespace mwmp
std::string refId;
int count;
int charge;
double enchantmentCharge;
float enchantmentCharge;
int actionCount;
@ -29,7 +29,7 @@ namespace mwmp
unsigned mpNum;
int count;
int charge;
double enchantmentCharge;
float enchantmentCharge;
int goldValue;
ESM::Position position;

@ -59,10 +59,26 @@ namespace mwmp
struct Faction
{
enum ChangesMask
{
Rank = 1,
Expulsion = 2,
Reputation = 4
};
inline bool isRankChanged() const { return (changes & ChangesMask::Rank) > 0; }
inline bool isExpulsionChanged() const { return (changes & ChangesMask::Expulsion) > 0; }
inline bool isReputationChanged() const { return (changes & ChangesMask::Reputation) > 0; }
inline void rankChanged() { changes |= ChangesMask::Rank; };
inline void expulsionChanged() { changes |= ChangesMask::Expulsion; };
inline void reputationChanged() { changes |= ChangesMask::Reputation; };
std::string factionId;
int rank;
int reputation;
bool isExpelled;
uint8_t changes = 0;
};
struct Topic
@ -118,15 +134,6 @@ namespace mwmp
struct FactionChanges
{
std::vector<Faction> factions;
enum class Type: uint8_t
{
Rank = 0,
Expulsion,
Reputation
};
Type action;
};
struct TopicChanges
@ -240,7 +247,6 @@ namespace mwmp
BasePlayer(RakNet::RakNetGUID guid) : guid(guid)
{
inventoryChanges.action = InventoryChanges::Type::None;
spellbookChanges.action = SpellbookChanges::Type::None;
useCreatureName = false;
isWerewolf = false;

@ -12,7 +12,7 @@ namespace mwmp
std::string refId;
int count;
int charge;
double enchantmentCharge;
float enchantmentCharge;
inline bool operator==(const Item& rhs)
{
@ -22,15 +22,14 @@ namespace mwmp
struct InventoryChanges
{
std::vector<Item> items;
enum class Type: int8_t
enum class Action: int8_t
{
None = -1,
Set = 0,
Add,
Remove
};
Type action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item
std::vector<std::pair<Item, Action>> items;
};
struct Target

@ -20,7 +20,8 @@ inline void AddPacket(mwmp::ActorPacketController::packets_t *packets, RakNet::R
{
T *packet = new T(peer);
typedef mwmp::ActorPacketController::packets_t::value_type value_t;
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(std::move(packet))));
unsigned char packetId = packet->GetPacketID();
packets->insert(value_t(packetId, value_t::second_type(std::move(packet))));
}
mwmp::ActorPacketController::ActorPacketController(RakNet::RakPeerInterface *peer)

@ -47,7 +47,8 @@ inline void AddPacket(mwmp::PlayerPacketController::packets_t *packets, RakNet::
{
T *packet = new T(peer);
typedef mwmp::PlayerPacketController::packets_t::value_type value_t;
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(std::move(packet))));
unsigned char packetId = packet->GetPacketID();
packets->insert(value_t(packetId, value_t::second_type(std::move(packet))));
}
mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *peer)

@ -27,7 +27,8 @@ inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::R
{
T *packet = new T(peer);
typedef mwmp::WorldPacketController::packets_t::value_type value_t;
packets->insert(value_t(packet->GetPacketID(), value_t::second_type(std::move(packet))));
unsigned char packetId = packet->GetPacketID();
packets->insert(value_t(packetId, value_t::second_type(std::move(packet))));
}
mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer)

@ -12,9 +12,6 @@ PacketPlayerFaction::PacketPlayerFaction(RakNet::RakPeerInterface *peer) : Playe
void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->factionChanges.action, send);
uint32_t count;
if (send)
@ -30,15 +27,17 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
for (auto &&faction : player->factionChanges.factions)
{
RW(faction.changes, send, true);
RW(faction.factionId, send, true);
if (player->factionChanges.action == FactionChanges::Type::Rank)
if (faction.isRankChanged())
RW(faction.rank, send);
if (player->factionChanges.action == FactionChanges::Type::Expulsion)
if (faction.isExpulsionChanged())
RW(faction.isExpelled, send);
if (player->factionChanges.action == FactionChanges::Type::Reputation)
if (faction.isReputationChanged())
RW(faction.reputation, send);
}
}

@ -17,8 +17,6 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->inventoryChanges.action, send);
uint32_t count;
if (send)
@ -34,9 +32,10 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send)
for (auto &&item : player->inventoryChanges.items)
{
RW(item.refId, send, true);
RW(item.count, send);
RW(item.charge, send);
RW(item.enchantmentCharge, send);
RW(item.first.refId, send, true);
RW(item.first.count, send);
RW(item.first.charge, send);
RW(item.first.enchantmentCharge, send);
RW(item.second, send, true); // compress byte to bits
}
}

@ -12,7 +12,6 @@ PacketPlayerPosition::PacketPlayerPosition(RakNet::RakPeerInterface *peer) : Pla
{
packetID = ID_PLAYER_POSITION;
priority = MEDIUM_PRIORITY;
//reliability = UNRELIABLE_SEQUENCED;
}
void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send)
@ -23,6 +22,11 @@ void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send)
unsigned char dir;
if (send)
{
if((player->movementFlags & /*Flag_ForceJump*/16) != 0)
reliability = RELIABLE_ORDERED;
else
reliability = UNRELIABLE_SEQUENCED;
rot[0] = player->position.rot[0] * 0.1f;
rot[1] = player->position.rot[2] * 0.1f;

Loading…
Cancel
Save