mirror of
https://github.com/Squareville/wonderland-server.git
synced 2025-12-16 12:33:52 -06:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
@@ -1669,11 +1669,9 @@ void Entity::PickupItem(const LWOOBJID& objectID) const {
|
||||
auto* const skillsTable = CDClientManager::GetTable<CDObjectSkillsTable>();
|
||||
const auto skills = skillsTable->Query([&info](CDObjectSkills entry) {return (entry.objectTemplate == info.lot); });
|
||||
for (const auto& skill : skills) {
|
||||
auto* skillComponent = GetComponent<SkillComponent>();
|
||||
const auto [skillComponent, missionComponent] = GetComponentsMut<SkillComponent, MissionComponent>();
|
||||
if (skillComponent) skillComponent->CastSkill(skill.skillID, GetObjectID(), GetObjectID(), skill.castOnType, NiQuaternion(0, 0, 0, 0));
|
||||
|
||||
auto* missionComponent = GetComponent<MissionComponent>();
|
||||
|
||||
if (missionComponent != nullptr) {
|
||||
missionComponent->Progress(eMissionTaskType::POWERUP, skill.skillID);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <typeinfo>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
@@ -161,6 +162,12 @@ public:
|
||||
template<typename T>
|
||||
T* GetComponent() const;
|
||||
|
||||
template<typename... T>
|
||||
auto GetComponents() const;
|
||||
|
||||
template<typename... T>
|
||||
auto GetComponentsMut() const;
|
||||
|
||||
template<typename T>
|
||||
bool TryGetComponent(eReplicaComponentType componentId, T*& component) const;
|
||||
|
||||
@@ -580,3 +587,13 @@ inline ComponentType* Entity::AddComponent(VaArgs... args) {
|
||||
// To allow a static cast here instead of a dynamic one.
|
||||
return dynamic_cast<ComponentType*>(componentToReturn);
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
auto Entity::GetComponents() const {
|
||||
return GetComponentsMut<const T...>();
|
||||
}
|
||||
|
||||
template<typename... T>
|
||||
auto Entity::GetComponentsMut() const {
|
||||
return std::tuple{GetComponent<T>()...};
|
||||
}
|
||||
|
||||
@@ -610,3 +610,14 @@ void EntityManager::FireEventServerSide(Entity* origin, std::string args) {
|
||||
bool EntityManager::IsExcludedFromGhosting(LOT lot) {
|
||||
return std::find(m_GhostingExcludedLOTs.begin(), m_GhostingExcludedLOTs.end(), lot) != m_GhostingExcludedLOTs.end();
|
||||
}
|
||||
|
||||
bool EntityManager::SendMessage(GameMessages::GameMsg& msg) const {
|
||||
bool handled = false;
|
||||
const auto entityItr = m_Entities.find(msg.target);
|
||||
if (entityItr != m_Entities.end()) {
|
||||
auto* const entity = entityItr->second;
|
||||
if (entity) handled = entity->HandleMsg(msg);
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ class Player;
|
||||
class User;
|
||||
enum class eReplicaComponentType : uint32_t;
|
||||
|
||||
namespace GameMessages {
|
||||
struct GameMsg;
|
||||
}
|
||||
|
||||
struct SystemAddress;
|
||||
|
||||
class EntityManager {
|
||||
@@ -70,6 +74,9 @@ public:
|
||||
const bool GetHardcoreDropinventoryOnDeath() { return m_HardcoreDropinventoryOnDeath; };
|
||||
const uint32_t GetHardcoreUscoreEnemiesMultiplier() { return m_HardcoreUscoreEnemiesMultiplier; };
|
||||
|
||||
// Messaging
|
||||
bool SendMessage(GameMessages::GameMsg& msg) const;
|
||||
|
||||
private:
|
||||
void SerializeEntities();
|
||||
void KillEntities();
|
||||
|
||||
@@ -575,7 +575,7 @@ void ActivityInstance::RewardParticipant(Entity* participant) {
|
||||
maxCoins = currencyTable[0].maxvalue;
|
||||
}
|
||||
|
||||
Loot::DropLoot(participant, m_Parent, activityRewards[0].LootMatrixIndex, minCoins, maxCoins);
|
||||
Loot::DropLoot(participant, m_Parent->GetObjectID(), activityRewards[0].LootMatrixIndex, minCoins, maxCoins);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -755,18 +755,18 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
|
||||
auto* member = Game::entityManager->GetEntity(specificOwner);
|
||||
|
||||
if (member) Loot::DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
if (member) Loot::DropLoot(member, m_Parent->GetObjectID(), lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
} else {
|
||||
for (const auto memberId : team->members) { // Free for all
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
|
||||
Loot::DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
Loot::DropLoot(member, m_Parent->GetObjectID(), lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
}
|
||||
} else { // drop loot for non team user
|
||||
Loot::DropLoot(owner, m_Parent, GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
Loot::DropLoot(owner, m_Parent->GetObjectID(), GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -784,7 +784,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
|
||||
coinsTotal -= coinsToLose;
|
||||
|
||||
Loot::DropLoot(m_Parent, m_Parent, -1, coinsToLose, coinsToLose);
|
||||
Loot::DropLoot(m_Parent, m_Parent->GetObjectID(), -1, coinsToLose, coinsToLose);
|
||||
character->SetCoins(coinsTotal, eLootSourceType::PICKUP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,12 @@ void ModelComponent::Update(float deltaTime) {
|
||||
for (auto& behavior : m_Behaviors) {
|
||||
behavior.Update(deltaTime, *this);
|
||||
}
|
||||
|
||||
if (!m_RestartAtEndOfFrame) return;
|
||||
|
||||
GameMessages::ResetModelToDefaults reset{};
|
||||
OnResetModelToDefaults(reset);
|
||||
m_RestartAtEndOfFrame = false;
|
||||
}
|
||||
|
||||
void ModelComponent::LoadBehaviors() {
|
||||
|
||||
@@ -146,7 +146,11 @@ public:
|
||||
|
||||
void OnChatMessageReceived(const std::string& sMessage);
|
||||
|
||||
// Sets the speed of the model
|
||||
void SetSpeed(const float newSpeed) { m_Speed = newSpeed; }
|
||||
|
||||
// Whether or not to restart at the end of the frame
|
||||
void RestartAtEndOfFrame() { m_RestartAtEndOfFrame = true; }
|
||||
private:
|
||||
|
||||
// Loads a behavior from the database.
|
||||
@@ -190,4 +194,7 @@ private:
|
||||
|
||||
// The speed at which this model moves
|
||||
float m_Speed{ 3.0f };
|
||||
|
||||
// Whether or not to restart at the end of the frame.
|
||||
bool m_RestartAtEndOfFrame{ false };
|
||||
};
|
||||
|
||||
@@ -460,7 +460,7 @@ void QuickBuildComponent::CompleteQuickBuild(Entity* const user) {
|
||||
auto* missionComponent = builder->GetComponent<MissionComponent>();
|
||||
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
||||
}
|
||||
Loot::DropActivityLoot(builder, m_Parent, m_ActivityId, 1);
|
||||
Loot::DropActivityLoot(builder, m_Parent->GetObjectID(), m_ActivityId, 1);
|
||||
}
|
||||
|
||||
// Notify scripts
|
||||
|
||||
@@ -389,7 +389,7 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity* player, int32_t bu
|
||||
// Calculate the score, different loot depending on player count
|
||||
auto playersRating = m_LoadedPlayers;
|
||||
const auto score = playersRating * 10 + data->finished;
|
||||
Loot::GiveActivityLoot(player, m_Parent, m_ActivityID, score);
|
||||
Loot::GiveActivityLoot(player, m_Parent->GetObjectID(), m_ActivityID, score);
|
||||
|
||||
// Giving rewards
|
||||
GameMessages::SendNotifyRacingClient(
|
||||
|
||||
@@ -6250,12 +6250,9 @@ void GameMessages::HandleRemoveDonationItem(RakNet::BitStream& inStream, Entity*
|
||||
}
|
||||
|
||||
void GameMessages::HandleConfirmDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity) {
|
||||
auto* inventoryComponent = entity->GetComponent<InventoryComponent>();
|
||||
if (!inventoryComponent) return;
|
||||
auto* missionComponent = entity->GetComponent<MissionComponent>();
|
||||
if (!missionComponent) return;
|
||||
auto* characterComponent = entity->GetComponent<CharacterComponent>();
|
||||
if (!characterComponent || !characterComponent->GetCurrentInteracting()) return;
|
||||
const auto [inventoryComponent, missionComponent, characterComponent] = entity->GetComponentsMut<InventoryComponent, MissionComponent, CharacterComponent>();
|
||||
if (!inventoryComponent || !missionComponent || !characterComponent || !characterComponent->GetCurrentInteracting()) return;
|
||||
|
||||
auto* donationEntity = Game::entityManager->GetEntity(characterComponent->GetCurrentInteracting());
|
||||
if (!donationEntity) return;
|
||||
auto* donationVendorComponent = donationEntity->GetComponent<DonationVendorComponent>();
|
||||
@@ -6397,6 +6394,10 @@ void GameMessages::SendUpdateInventoryUi(LWOOBJID objectId, const SystemAddress&
|
||||
}
|
||||
|
||||
namespace GameMessages {
|
||||
bool GameMsg::Send() {
|
||||
return Game::entityManager->SendMessage(*this);
|
||||
}
|
||||
|
||||
void GameMsg::Send(const SystemAddress& sysAddr) const {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
@@ -54,6 +54,12 @@ namespace GameMessages {
|
||||
GameMsg(MessageType::Game gmId, eGameMasterLevel lvl) : msgId{ gmId }, requiredGmLevel{ lvl } {}
|
||||
GameMsg(MessageType::Game gmId) : GameMsg(gmId, eGameMasterLevel::CIVILIAN) {}
|
||||
virtual ~GameMsg() = default;
|
||||
|
||||
// Sends a message to the entity manager to route to the target
|
||||
bool Send();
|
||||
|
||||
// Sends the message to the specified client or
|
||||
// all clients if UNASSIGNED_SYSTEM_ADDRESS is specified
|
||||
void Send(const SystemAddress& sysAddr) const;
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const {}
|
||||
virtual bool Deserialize(RakNet::BitStream& bitStream) { return true; }
|
||||
|
||||
@@ -97,20 +97,18 @@ void Mission::LoadFromXmlCur(const tinyxml2::XMLElement& element) {
|
||||
if (index >= m_Tasks.size()) {
|
||||
break;
|
||||
}
|
||||
auto* const curTask = m_Tasks[index];
|
||||
|
||||
const auto type = m_Tasks[index]->GetType();
|
||||
const auto type = curTask->GetType();
|
||||
|
||||
if (type == eMissionTaskType::COLLECTION ||
|
||||
type == eMissionTaskType::VISIT_PROPERTY) {
|
||||
auto value = std::stoul(task->Attribute("v"));
|
||||
curTask->SetProgress(value, false);
|
||||
task = task->NextSiblingElement();
|
||||
|
||||
// Collection tasks and visit property tasks store each of the collected/visited targets after the progress value
|
||||
if (type == eMissionTaskType::COLLECTION || type == eMissionTaskType::VISIT_PROPERTY) {
|
||||
std::vector<uint32_t> uniques;
|
||||
|
||||
const auto value = std::stoul(task->Attribute("v"));
|
||||
|
||||
m_Tasks[index]->SetProgress(value, false);
|
||||
|
||||
task = task->NextSiblingElement();
|
||||
|
||||
while (task != nullptr) {
|
||||
while (task != nullptr && value > 0) {
|
||||
const auto unique = std::stoul(task->Attribute("v"));
|
||||
|
||||
uniques.push_back(unique);
|
||||
@@ -120,19 +118,10 @@ void Mission::LoadFromXmlCur(const tinyxml2::XMLElement& element) {
|
||||
}
|
||||
|
||||
task = task->NextSiblingElement();
|
||||
value--;
|
||||
}
|
||||
|
||||
m_Tasks[index]->SetUnique(uniques);
|
||||
|
||||
m_Tasks[index]->SetProgress(uniques.size(), false);
|
||||
|
||||
break;
|
||||
} else {
|
||||
const auto value = std::stoul(task->Attribute("v"));
|
||||
|
||||
m_Tasks[index]->SetProgress(value, false);
|
||||
|
||||
task = task->NextSiblingElement();
|
||||
curTask->SetUnique(uniques);
|
||||
}
|
||||
|
||||
index++;
|
||||
@@ -164,31 +153,19 @@ void Mission::UpdateXmlCur(tinyxml2::XMLElement& element) {
|
||||
|
||||
if (IsComplete()) return;
|
||||
|
||||
for (auto* task : m_Tasks) {
|
||||
if (task->GetType() == eMissionTaskType::COLLECTION ||
|
||||
task->GetType() == eMissionTaskType::VISIT_PROPERTY) {
|
||||
|
||||
auto* child = element.GetDocument()->NewElement("sv");
|
||||
|
||||
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
||||
|
||||
element.LinkEndChild(child);
|
||||
|
||||
for (auto unique : task->GetUnique()) {
|
||||
auto* uniqueElement = element.GetDocument()->NewElement("sv");
|
||||
|
||||
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
|
||||
|
||||
element.LinkEndChild(uniqueElement);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
auto* child = element.GetDocument()->NewElement("sv");
|
||||
|
||||
for (const auto* const task : m_Tasks) {
|
||||
auto* const child = element.InsertNewChildElement("sv");
|
||||
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
||||
|
||||
element.LinkEndChild(child);
|
||||
// Collection and visit property tasks then need to store the collected/visited items after the progress
|
||||
const auto taskType = task->GetType();
|
||||
if (taskType == eMissionTaskType::COLLECTION || taskType == eMissionTaskType::VISIT_PROPERTY) {
|
||||
for (const auto unique : task->GetUnique()) {
|
||||
auto* uniqueElement = element.InsertNewChildElement("sv");
|
||||
|
||||
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,6 +221,8 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
|
||||
sound.target = modelComponent.GetParent()->GetObjectID();
|
||||
sound.soundID = numberAsInt;
|
||||
sound.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
} else if (nextActionType == "Restart") {
|
||||
modelComponent.RestartAtEndOfFrame();
|
||||
}
|
||||
/* END Action */
|
||||
/* BEGIN Gameplay */
|
||||
|
||||
@@ -65,6 +65,8 @@ private:
|
||||
|
||||
// The position of the parent model on the previous frame
|
||||
NiPoint3 m_PreviousFramePosition{};
|
||||
|
||||
NiPoint3 m_SavedVelocity{};
|
||||
};
|
||||
|
||||
#endif //!__STRIP__H__
|
||||
|
||||
@@ -214,7 +214,7 @@ void Loot::GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result, eL
|
||||
}
|
||||
}
|
||||
|
||||
void Loot::GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) {
|
||||
void Loot::GiveActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating) {
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::GetTable<CDActivityRewardsTable>();
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
||||
|
||||
@@ -248,7 +248,7 @@ void Loot::GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID,
|
||||
character->SetCoins(character->GetCoins() + coins, eLootSourceType::ACTIVITY);
|
||||
}
|
||||
|
||||
void Loot::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) {
|
||||
void Loot::DropLoot(Entity* player, const LWOOBJID source, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
|
||||
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
@@ -258,10 +258,10 @@ void Loot::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex,
|
||||
|
||||
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
||||
|
||||
DropLoot(player, killedObject, result, minCoins, maxCoins);
|
||||
DropLoot(player, source, result, minCoins, maxCoins);
|
||||
}
|
||||
|
||||
void Loot::DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins) {
|
||||
void Loot::DropLoot(Entity* player, const LWOOBJID source, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
|
||||
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
@@ -269,9 +269,11 @@ void Loot::DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT
|
||||
if (!inventoryComponent)
|
||||
return;
|
||||
|
||||
const auto spawnPosition = killedObject->GetPosition();
|
||||
GameMessages::GetPosition posMsg;
|
||||
posMsg.target = source;
|
||||
posMsg.Send();
|
||||
|
||||
const auto source = killedObject->GetObjectID();
|
||||
const auto spawnPosition = posMsg.pos;
|
||||
|
||||
for (const auto& pair : result) {
|
||||
for (int i = 0; i < pair.second; ++i) {
|
||||
@@ -284,7 +286,7 @@ void Loot::DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT
|
||||
GameMessages::SendDropClientLoot(player, source, LOT_NULL, coins, spawnPosition);
|
||||
}
|
||||
|
||||
void Loot::DropActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) {
|
||||
void Loot::DropActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating) {
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::GetTable<CDActivityRewardsTable>();
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace Loot {
|
||||
void CacheMatrix(const uint32_t matrixIndex);
|
||||
void GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType = eLootSourceType::NONE);
|
||||
void GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result, eLootSourceType lootSourceType = eLootSourceType::NONE);
|
||||
void GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating = 0);
|
||||
void DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating = 0);
|
||||
void DropCoins(Entity* player, Entity* source, int32_t currencyIndex, int32_t npcMinLevel = 1);
|
||||
void GiveActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating = 0);
|
||||
void DropLoot(Entity* player, const LWOOBJID source, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropLoot(Entity* player, const LWOOBJID source, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating = 0);
|
||||
void DropCoins(Entity* player, const LWOOBJID source, int32_t currencyIndex, int32_t npcMinLevel = 1);
|
||||
};
|
||||
|
||||
@@ -1463,12 +1463,21 @@ void SlashCommandHandler::Startup() {
|
||||
.requiredLevel = eGameMasterLevel::CIVILIAN
|
||||
};
|
||||
RegisterCommand(notifyzonecontrolCommand);
|
||||
Command shutdownCommand{
|
||||
|
||||
Command command{
|
||||
.help = "Shuts this world down",
|
||||
.info = "Shuts this world down",
|
||||
.aliases = {"shutdown"},
|
||||
.handle = DEVGMCommands::Shutdown,
|
||||
.requiredLevel = eGameMasterLevel::DEVELOPER
|
||||
};
|
||||
RegisterCommand(shutdownCommand);
|
||||
RegisterCommand(command);
|
||||
|
||||
RegisterCommand({
|
||||
.help = "Turns all players' pvp mode on",
|
||||
.info = "Turns all players' pvp mode on",
|
||||
.aliases = {"barfight"},
|
||||
.handle = DEVGMCommands::Barfight,
|
||||
.requiredLevel = eGameMasterLevel::DEVELOPER
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1635,4 +1635,17 @@ namespace DEVGMCommands {
|
||||
if (character) LOG("Mythran (%s) has shutdown the world", character->GetName().c_str());
|
||||
Game::OnSignal(-1);
|
||||
}
|
||||
|
||||
void Barfight(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
auto* const characterComponent = entity->GetComponent<CharacterComponent>();
|
||||
if (!characterComponent) return;
|
||||
|
||||
for (auto* const player : PlayerManager::GetAllPlayers()) {
|
||||
auto* const pCharacterComponent = player->GetComponent<CharacterComponent>();
|
||||
if (pCharacterComponent) pCharacterComponent->SetPvpEnabled(true);
|
||||
Game::entityManager->SerializeEntity(player);
|
||||
}
|
||||
const auto msg = u"Pvp has been turned on for all players by " + GeneralUtils::ASCIIToUTF16(characterComponent->GetName());
|
||||
ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, msg, true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace DEVGMCommands {
|
||||
void CastSkill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Shutdown(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Barfight(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
}
|
||||
|
||||
#endif //!DEVGMCOMMANDS_H
|
||||
|
||||
@@ -14,24 +14,21 @@
|
||||
|
||||
#include "Start.h"
|
||||
|
||||
InstanceManager::InstanceManager(Logger* logger, const std::string& externalIP) {
|
||||
mLogger = logger;
|
||||
mExternalIP = externalIP;
|
||||
using std::make_unique;
|
||||
|
||||
namespace {
|
||||
const InstancePtr g_Empty{ nullptr };
|
||||
}
|
||||
|
||||
InstanceManager::InstanceManager(const std::string& externalIP) : mExternalIP{ externalIP } {
|
||||
m_LastPort =
|
||||
GeneralUtils::TryParse<uint16_t>(Game::config->GetValue("world_port_start")).value_or(m_LastPort);
|
||||
m_LastInstanceID = LWOINSTANCEID_INVALID;
|
||||
}
|
||||
|
||||
InstanceManager::~InstanceManager() {
|
||||
for (Instance* i : m_Instances) {
|
||||
delete i;
|
||||
i = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID) {
|
||||
const InstancePtr& InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID) {
|
||||
LOG("Searching for an instance for mapID %i/%i", mapID, cloneID);
|
||||
Instance* instance = FindInstance(mapID, isFriendTransfer, cloneID);
|
||||
auto& instance = FindInstance(mapID, isFriendTransfer, cloneID);
|
||||
if (instance) return instance;
|
||||
|
||||
// If we are shutting down, return a nullptr so a new instance is not created.
|
||||
@@ -40,7 +37,7 @@ Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LW
|
||||
mapID,
|
||||
m_LastInstanceID + 1,
|
||||
cloneID);
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
//TODO: Update this so that the IP is read from a configuration file instead
|
||||
|
||||
@@ -56,23 +53,23 @@ Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LW
|
||||
}
|
||||
|
||||
uint32_t port = GetFreePort();
|
||||
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, softCap, maxPlayers);
|
||||
auto newInstance = make_unique<Instance>(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, softCap, maxPlayers);
|
||||
|
||||
//Start the actual process:
|
||||
StartWorldServer(mapID, port, m_LastInstanceID, maxPlayers, cloneID);
|
||||
|
||||
m_Instances.push_back(instance);
|
||||
m_Instances.push_back(std::move(newInstance));
|
||||
|
||||
if (instance) {
|
||||
if (m_Instances.back()) {
|
||||
LOG("Created new instance: %i/%i/%i with min/max %i/%i", mapID, m_LastInstanceID, cloneID, softCap, maxPlayers);
|
||||
return instance;
|
||||
return m_Instances.back();
|
||||
} else LOG("Failed to create a new instance!");
|
||||
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
bool InstanceManager::IsPortInUse(uint32_t port) {
|
||||
for (Instance* i : m_Instances) {
|
||||
for (const auto& i : m_Instances) {
|
||||
if (i && i->GetPort() == port) {
|
||||
return true;
|
||||
}
|
||||
@@ -84,7 +81,7 @@ bool InstanceManager::IsPortInUse(uint32_t port) {
|
||||
uint32_t InstanceManager::GetFreePort() {
|
||||
uint32_t port = m_LastPort;
|
||||
std::vector<uint32_t> usedPorts;
|
||||
for (Instance* i : m_Instances) {
|
||||
for (const auto& i : m_Instances) {
|
||||
usedPorts.push_back(i->GetPort());
|
||||
}
|
||||
|
||||
@@ -101,7 +98,7 @@ uint32_t InstanceManager::GetFreePort() {
|
||||
}
|
||||
|
||||
void InstanceManager::AddPlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
||||
Instance* inst = FindInstance(mapID, instanceID);
|
||||
const auto& inst = FindInstance(mapID, instanceID);
|
||||
if (inst) {
|
||||
Player player;
|
||||
player.addr = systemAddr;
|
||||
@@ -111,7 +108,7 @@ void InstanceManager::AddPlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINS
|
||||
}
|
||||
|
||||
void InstanceManager::RemovePlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
||||
Instance* inst = FindInstance(mapID, instanceID);
|
||||
const auto& inst = FindInstance(mapID, instanceID);
|
||||
if (inst) {
|
||||
Player player;
|
||||
player.addr = systemAddr;
|
||||
@@ -120,25 +117,23 @@ void InstanceManager::RemovePlayer(SystemAddress systemAddr, LWOMAPID mapID, LWO
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Instance*> InstanceManager::GetInstances() const {
|
||||
const std::vector<InstancePtr>& InstanceManager::GetInstances() const {
|
||||
return m_Instances;
|
||||
}
|
||||
|
||||
void InstanceManager::AddInstance(Instance* instance) {
|
||||
void InstanceManager::AddInstance(InstancePtr& instance) {
|
||||
if (instance == nullptr) return;
|
||||
|
||||
m_Instances.push_back(instance);
|
||||
m_Instances.push_back(std::move(instance));
|
||||
}
|
||||
|
||||
void InstanceManager::RemoveInstance(Instance* instance) {
|
||||
void InstanceManager::RemoveInstance(const InstancePtr& instance) {
|
||||
for (uint32_t i = 0; i < m_Instances.size(); ++i) {
|
||||
if (m_Instances[i] == instance) {
|
||||
instance->SetShutdownComplete(true);
|
||||
|
||||
if (!Game::ShouldShutdown()) RedirectPendingRequests(instance);
|
||||
|
||||
delete m_Instances[i];
|
||||
|
||||
m_Instances.erase(m_Instances.begin() + i);
|
||||
|
||||
break;
|
||||
@@ -146,7 +141,7 @@ void InstanceManager::RemoveInstance(Instance* instance) {
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceManager::ReadyInstance(Instance* instance) {
|
||||
void InstanceManager::ReadyInstance(const InstancePtr& instance) {
|
||||
instance->SetIsReady(true);
|
||||
|
||||
auto& pending = instance->GetPendingRequests();
|
||||
@@ -172,7 +167,7 @@ void InstanceManager::ReadyInstance(Instance* instance) {
|
||||
pending.clear();
|
||||
}
|
||||
|
||||
void InstanceManager::RequestAffirmation(Instance* instance, const PendingInstanceRequest& request) {
|
||||
void InstanceManager::RequestAffirmation(const InstancePtr& instance, const PendingInstanceRequest& request) {
|
||||
instance->GetPendingAffirmations().push_back(request);
|
||||
|
||||
CBITSTREAM;
|
||||
@@ -189,7 +184,7 @@ void InstanceManager::RequestAffirmation(Instance* instance, const PendingInstan
|
||||
);
|
||||
}
|
||||
|
||||
void InstanceManager::AffirmTransfer(Instance* instance, const uint64_t transferID) {
|
||||
void InstanceManager::AffirmTransfer(const InstancePtr& instance, const uint64_t transferID) {
|
||||
auto& pending = instance->GetPendingAffirmations();
|
||||
|
||||
for (auto i = 0u; i < pending.size(); ++i) {
|
||||
@@ -217,11 +212,11 @@ void InstanceManager::AffirmTransfer(Instance* instance, const uint64_t transfer
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceManager::RedirectPendingRequests(Instance* instance) {
|
||||
void InstanceManager::RedirectPendingRequests(const InstancePtr& instance) {
|
||||
const auto& zoneId = instance->GetZoneID();
|
||||
|
||||
for (const auto& request : instance->GetPendingAffirmations()) {
|
||||
auto* in = Game::im->GetInstance(zoneId.GetMapID(), false, zoneId.GetCloneID());
|
||||
const auto& in = Game::im->GetInstance(zoneId.GetMapID(), false, zoneId.GetCloneID());
|
||||
|
||||
if (in && !in->GetIsReady()) // Instance not ready, make a pending request
|
||||
{
|
||||
@@ -234,68 +229,48 @@ void InstanceManager::RedirectPendingRequests(Instance* instance) {
|
||||
}
|
||||
}
|
||||
|
||||
Instance* InstanceManager::GetInstanceBySysAddr(SystemAddress& sysAddr) {
|
||||
for (uint32_t i = 0; i < m_Instances.size(); ++i) {
|
||||
if (m_Instances[i] && m_Instances[i]->GetSysAddr() == sysAddr) {
|
||||
return m_Instances[i];
|
||||
const InstancePtr& InstanceManager::GetInstanceBySysAddr(SystemAddress& sysAddr) {
|
||||
for (const auto& instance : m_Instances) {
|
||||
if (instance && instance->GetSysAddr() == sysAddr) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
bool InstanceManager::IsInstanceFull(Instance* instance, bool isFriendTransfer) {
|
||||
if (!isFriendTransfer && instance->GetSoftCap() > instance->GetCurrentClientCount())
|
||||
return false;
|
||||
else if (isFriendTransfer && instance->GetHardCap() > instance->GetCurrentClientCount())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Instance* InstanceManager::FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId) {
|
||||
for (Instance* i : m_Instances) {
|
||||
if (i && i->GetMapID() == mapID && i->GetCloneID() == cloneId && !IsInstanceFull(i, isFriendTransfer) && !i->GetIsPrivate() && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
|
||||
const InstancePtr& InstanceManager::FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId) {
|
||||
for (const auto& i : m_Instances) {
|
||||
if (i && i->GetMapID() == mapID && i->GetCloneID() == cloneId && !i->IsFull(isFriendTransfer) && !i->GetIsPrivate() && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
Instance* InstanceManager::FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
||||
for (Instance* i : m_Instances) {
|
||||
const InstancePtr& InstanceManager::FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
||||
for (const auto& i : m_Instances) {
|
||||
if (i && i->GetMapID() == mapID && i->GetInstanceID() == instanceID && !i->GetIsPrivate() && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
std::vector<Instance*> InstanceManager::FindInstancesByMapID(LWOMAPID mapID) {
|
||||
std::vector<Instance*> instances;
|
||||
for (Instance* instance : m_Instances) {
|
||||
if (instance && instance->GetMapID() == mapID) {
|
||||
instances.push_back(instance);
|
||||
}
|
||||
}
|
||||
|
||||
return instances;
|
||||
}
|
||||
|
||||
Instance* InstanceManager::FindInstanceWithPrivate(LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
||||
for (Instance* i : m_Instances) {
|
||||
const InstancePtr& InstanceManager::FindInstanceWithPrivate(LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
||||
for (const auto& i : m_Instances) {
|
||||
if (i && i->GetMapID() == mapID && i->GetInstanceID() == instanceID && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password) {
|
||||
auto* instance = FindPrivateInstance(password);
|
||||
const InstancePtr& InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password) {
|
||||
const auto& instance = FindPrivateInstance(password);
|
||||
|
||||
if (instance != nullptr) {
|
||||
return instance;
|
||||
@@ -306,27 +281,27 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon
|
||||
mapID,
|
||||
m_LastInstanceID + 1,
|
||||
cloneID);
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
int maxPlayers = 999;
|
||||
|
||||
uint32_t port = GetFreePort();
|
||||
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);
|
||||
auto newInstance = make_unique<Instance>(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);
|
||||
|
||||
//Start the actual process:
|
||||
StartWorldServer(mapID, port, m_LastInstanceID, maxPlayers, cloneID);
|
||||
|
||||
m_Instances.push_back(instance);
|
||||
m_Instances.push_back(std::move(newInstance));
|
||||
|
||||
if (instance) return instance;
|
||||
if (m_Instances.back()) return m_Instances.back();
|
||||
else LOG("Failed to create a new instance!");
|
||||
|
||||
return instance;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
Instance* InstanceManager::FindPrivateInstance(const std::string& password) {
|
||||
for (auto* instance : m_Instances) {
|
||||
const InstancePtr& InstanceManager::FindPrivateInstance(const std::string& password) {
|
||||
for (const auto& instance : m_Instances) {
|
||||
if (!instance) continue;
|
||||
|
||||
if (!instance->GetIsPrivate()) {
|
||||
@@ -340,7 +315,7 @@ Instance* InstanceManager::FindPrivateInstance(const std::string& password) {
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return g_Empty;
|
||||
}
|
||||
|
||||
int InstanceManager::GetSoftCap(LWOMAPID mapID) {
|
||||
@@ -374,3 +349,14 @@ void Instance::Shutdown() {
|
||||
|
||||
LOG("Triggered world shutdown for zone/clone/instance %i/%i/%i", GetMapID(), GetCloneID(), GetInstanceID());
|
||||
}
|
||||
|
||||
|
||||
bool Instance::IsFull(bool isFriendTransfer) const {
|
||||
if (!isFriendTransfer && GetSoftCap() > GetCurrentClientCount())
|
||||
return false;
|
||||
else if (isFriendTransfer && GetHardCap() > GetCurrentClientCount())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,8 @@ public:
|
||||
|
||||
void Shutdown();
|
||||
|
||||
bool IsFull(bool isFriendTransfer) const;
|
||||
|
||||
private:
|
||||
std::string m_IP{};
|
||||
uint32_t m_Port{};
|
||||
@@ -99,43 +101,43 @@ private:
|
||||
//Private functions:
|
||||
};
|
||||
|
||||
using InstancePtr = std::unique_ptr<Instance>;
|
||||
|
||||
class InstanceManager {
|
||||
public:
|
||||
InstanceManager(Logger* logger, const std::string& externalIP);
|
||||
~InstanceManager();
|
||||
InstanceManager(const std::string& externalIP);
|
||||
|
||||
Instance* GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID); //Creates an instance if none found
|
||||
const InstancePtr& GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID); //Creates an instance if none found
|
||||
bool IsPortInUse(uint32_t port);
|
||||
uint32_t GetFreePort();
|
||||
|
||||
void AddPlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
void RemovePlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
|
||||
std::vector<Instance*> GetInstances() const;
|
||||
void AddInstance(Instance* instance);
|
||||
void RemoveInstance(Instance* instance);
|
||||
const std::vector<InstancePtr>& GetInstances() const;
|
||||
void AddInstance(InstancePtr& instance);
|
||||
void RemoveInstance(const InstancePtr& instance);
|
||||
|
||||
void ReadyInstance(Instance* instance);
|
||||
void RequestAffirmation(Instance* instance, const PendingInstanceRequest& request);
|
||||
void AffirmTransfer(Instance* instance, uint64_t transferID);
|
||||
void ReadyInstance(const InstancePtr& instance);
|
||||
void RequestAffirmation(const InstancePtr& instance, const PendingInstanceRequest& request);
|
||||
void AffirmTransfer(const InstancePtr& instance, uint64_t transferID);
|
||||
|
||||
void RedirectPendingRequests(Instance* instance);
|
||||
void RedirectPendingRequests(const InstancePtr& instance);
|
||||
|
||||
Instance* GetInstanceBySysAddr(SystemAddress& sysAddr);
|
||||
const InstancePtr& GetInstanceBySysAddr(SystemAddress& sysAddr);
|
||||
|
||||
Instance* FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId = 0);
|
||||
Instance* FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
const InstancePtr& FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId = 0);
|
||||
const InstancePtr& FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
std::vector<Instance*> FindInstancesByMapID(LWOMAPID mapID);
|
||||
Instance* FindInstanceWithPrivate(LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
const InstancePtr& FindInstanceWithPrivate(LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
|
||||
Instance* CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password);
|
||||
Instance* FindPrivateInstance(const std::string& password);
|
||||
const InstancePtr& CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password);
|
||||
const InstancePtr& FindPrivateInstance(const std::string& password);
|
||||
void SetIsShuttingDown(bool value) { this->m_IsShuttingDown = value; };
|
||||
|
||||
private:
|
||||
Logger* mLogger;
|
||||
std::string mExternalIP;
|
||||
std::vector<Instance*> m_Instances;
|
||||
std::vector<std::unique_ptr<Instance>> m_Instances;
|
||||
uint16_t m_LastPort = 3000;
|
||||
LWOINSTANCEID m_LastInstanceID;
|
||||
|
||||
@@ -145,7 +147,6 @@ private:
|
||||
bool m_IsShuttingDown = false;
|
||||
|
||||
//Private functions:
|
||||
bool IsInstanceFull(Instance* instance, bool isFriendTransfer);
|
||||
int GetSoftCap(LWOMAPID mapID);
|
||||
int GetHardCap(LWOMAPID mapID);
|
||||
};
|
||||
|
||||
@@ -359,7 +359,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
//Create additional objects here:
|
||||
PersistentIDManager::Initialize();
|
||||
Game::im = new InstanceManager(Game::logger, Game::server->GetIP());
|
||||
Game::im = new InstanceManager(Game::server->GetIP());
|
||||
|
||||
//Get CDClient initial information
|
||||
try {
|
||||
@@ -434,9 +434,9 @@ int main(int argc, char** argv) {
|
||||
framesSinceKillUniverseCommand++;
|
||||
}
|
||||
|
||||
const auto instances = Game::im->GetInstances();
|
||||
const auto& instances = Game::im->GetInstances();
|
||||
|
||||
for (auto* instance : instances) {
|
||||
for (const auto& instance : instances) {
|
||||
if (instance == nullptr) {
|
||||
break;
|
||||
}
|
||||
@@ -460,7 +460,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
//Remove dead instances
|
||||
for (auto* instance : instances) {
|
||||
for (const auto& instance : instances) {
|
||||
if (instance == nullptr) {
|
||||
break;
|
||||
}
|
||||
@@ -489,7 +489,7 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
//Since this disconnection is intentional, we'll just delete it as
|
||||
//we'll start a new one anyway if needed:
|
||||
Instance* instance =
|
||||
const auto& instance =
|
||||
Game::im->GetInstanceBySysAddr(packet->systemAddress);
|
||||
if (instance) {
|
||||
LOG("Actually disconnected from zone %i clone %i instance %i port %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
|
||||
@@ -510,7 +510,7 @@ void HandlePacket(Packet* packet) {
|
||||
if (packet->data[0] == ID_CONNECTION_LOST) {
|
||||
LOG("A server has lost the connection");
|
||||
|
||||
Instance* instance =
|
||||
const auto& instance =
|
||||
Game::im->GetInstanceBySysAddr(packet->systemAddress);
|
||||
if (instance) {
|
||||
LWOZONEID zoneID = instance->GetZoneID(); //Get the zoneID so we can recreate a server
|
||||
@@ -561,9 +561,9 @@ void HandlePacket(Packet* packet) {
|
||||
LOG("Shutdown sequence has been started. Not creating a new zone.");
|
||||
break;
|
||||
}
|
||||
Instance* in = Game::im->GetInstance(zoneID, false, zoneClone);
|
||||
const auto& in = Game::im->GetInstance(zoneID, false, zoneClone);
|
||||
|
||||
for (auto* instance : Game::im->GetInstances()) {
|
||||
for (const auto& instance : Game::im->GetInstances()) {
|
||||
LOG("Instance: %i/%i/%i -> %i %s", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance == in, instance->GetSysAddr().ToString());
|
||||
}
|
||||
|
||||
@@ -603,12 +603,12 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
if (theirServerType == ServerType::World) {
|
||||
if (!Game::im->IsPortInUse(theirPort)) {
|
||||
Instance* in = new Instance(theirIP.string, theirPort, theirZoneID, theirInstanceID, 0, 12, 12);
|
||||
auto in = std::make_unique<Instance>(theirIP.string, theirPort, theirZoneID, theirInstanceID, 0, 12, 12);
|
||||
|
||||
in->SetSysAddr(packet->systemAddress);
|
||||
Game::im->AddInstance(in);
|
||||
} else {
|
||||
auto* instance = Game::im->FindInstanceWithPrivate(theirZoneID, static_cast<LWOINSTANCEID>(theirInstanceID));
|
||||
const auto& instance = Game::im->FindInstanceWithPrivate(theirZoneID, static_cast<LWOINSTANCEID>(theirInstanceID));
|
||||
if (instance) {
|
||||
instance->SetSysAddr(packet->systemAddress);
|
||||
}
|
||||
@@ -682,7 +682,7 @@ void HandlePacket(Packet* packet) {
|
||||
inStream.Read(theirZoneID);
|
||||
inStream.Read(theirInstanceID);
|
||||
|
||||
auto instance =
|
||||
const auto& instance =
|
||||
Game::im->FindInstance(theirZoneID, theirInstanceID);
|
||||
if (instance) {
|
||||
instance->AddPlayer(Player());
|
||||
@@ -702,7 +702,7 @@ void HandlePacket(Packet* packet) {
|
||||
inStream.Read(theirZoneID);
|
||||
inStream.Read(theirInstanceID);
|
||||
|
||||
auto instance =
|
||||
const auto& instance =
|
||||
Game::im->FindInstance(theirZoneID, theirInstanceID);
|
||||
if (instance) {
|
||||
instance->RemovePlayer(Player());
|
||||
@@ -728,7 +728,7 @@ void HandlePacket(Packet* packet) {
|
||||
inStream.Read<char>(character);
|
||||
password += character;
|
||||
}
|
||||
auto* newInst = Game::im->CreatePrivateInstance(mapId, cloneId, password.c_str());
|
||||
const auto& newInst = Game::im->CreatePrivateInstance(mapId, cloneId, password.c_str());
|
||||
LOG("Creating private zone %i/%i/%i with password %s", newInst->GetMapID(), newInst->GetCloneID(), newInst->GetInstanceID(), password.c_str());
|
||||
|
||||
break;
|
||||
@@ -754,9 +754,9 @@ void HandlePacket(Packet* packet) {
|
||||
password += character;
|
||||
}
|
||||
|
||||
auto* instance = Game::im->FindPrivateInstance(password.c_str());
|
||||
const auto& instance = Game::im->FindPrivateInstance(password.c_str());
|
||||
|
||||
LOG("Join private zone: %llu %d %s %p", requestID, mythranShift, password.c_str(), instance);
|
||||
LOG("Join private zone: %llu %d %s %p", requestID, mythranShift, password.c_str(), instance.get());
|
||||
|
||||
if (instance == nullptr) {
|
||||
return;
|
||||
@@ -781,7 +781,7 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
LOG("Got world ready %i %i", zoneID, instanceID);
|
||||
|
||||
auto* instance = Game::im->FindInstance(zoneID, instanceID);
|
||||
const auto& instance = Game::im->FindInstance(zoneID, instanceID);
|
||||
|
||||
if (instance == nullptr) {
|
||||
LOG("Failed to find zone to ready");
|
||||
@@ -819,7 +819,7 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
LOG("Got affirmation of transfer %llu", requestID);
|
||||
|
||||
auto* instance = Game::im->GetInstanceBySysAddr(packet->systemAddress);
|
||||
const auto& instance = Game::im->GetInstanceBySysAddr(packet->systemAddress);
|
||||
|
||||
if (instance == nullptr)
|
||||
return;
|
||||
@@ -832,7 +832,7 @@ void HandlePacket(Packet* packet) {
|
||||
case MessageType::Master::SHUTDOWN_RESPONSE: {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
|
||||
auto* instance = Game::im->GetInstanceBySysAddr(packet->systemAddress);
|
||||
const auto& instance = Game::im->GetInstanceBySysAddr(packet->systemAddress);
|
||||
LOG("Got shutdown response from %s", packet->systemAddress.ToString());
|
||||
if (instance == nullptr) {
|
||||
return;
|
||||
@@ -948,13 +948,13 @@ int ShutdownSequence(int32_t signal) {
|
||||
LOG("Saved ObjectIDTracker to DB");
|
||||
|
||||
// A server might not be finished spinning up yet, remove all of those here.
|
||||
for (auto* instance : Game::im->GetInstances()) {
|
||||
for (const auto& instance : Game::im->GetInstances()) {
|
||||
if (!instance) continue;
|
||||
|
||||
if (!instance->GetIsReady()) {
|
||||
Game::im->RemoveInstance(instance);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* instance : Game::im->GetInstances()) {
|
||||
|
||||
instance->SetIsShuttingDown(true);
|
||||
}
|
||||
|
||||
@@ -975,7 +975,7 @@ int ShutdownSequence(int32_t signal) {
|
||||
|
||||
allInstancesShutdown = true;
|
||||
|
||||
for (auto* instance : Game::im->GetInstances()) {
|
||||
for (const auto& instance : Game::im->GetInstances()) {
|
||||
if (instance == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ void TreasureChestDragonServer::OnUse(Entity* self, Entity* user) {
|
||||
|
||||
if (memberObject == nullptr) continue;
|
||||
|
||||
Loot::DropActivityLoot(memberObject, self, scriptedActivityComponent->GetActivityID(), rating);
|
||||
Loot::DropActivityLoot(memberObject, self->GetObjectID(), scriptedActivityComponent->GetActivityID(), rating);
|
||||
}
|
||||
} else {
|
||||
Loot::DropActivityLoot(user, self, scriptedActivityComponent->GetActivityID(), rating);
|
||||
Loot::DropActivityLoot(user, self->GetObjectID(), scriptedActivityComponent->GetActivityID(), rating);
|
||||
}
|
||||
|
||||
self->Smash(self->GetObjectID());
|
||||
|
||||
@@ -45,7 +45,7 @@ BootyDigServer::OnFireEventServerSide(Entity* self, Entity* sender, std::string
|
||||
if (renderComponent != nullptr)
|
||||
renderComponent->PlayEffect(7730, u"cast", "bootyshine");
|
||||
|
||||
Loot::DropLoot(player, self, 231, 75, 75);
|
||||
Loot::DropLoot(player, self->GetObjectID(), 231, 75, 75);
|
||||
}
|
||||
}
|
||||
} else if (args == "ChestDead") {
|
||||
|
||||
@@ -22,7 +22,7 @@ void BaseInteractDropLootServer::BaseUse(Entity* self, Entity* user) {
|
||||
|
||||
self->SetNetworkVar(u"bInUse", true);
|
||||
|
||||
Loot::DropLoot(user, self, lootMatrix, 0, 0);
|
||||
Loot::DropLoot(user, self->GetObjectID(), lootMatrix, 0, 0);
|
||||
|
||||
self->AddCallbackTimer(cooldownTime, [this, self]() {
|
||||
self->SetNetworkVar(u"bInUse", false);
|
||||
|
||||
@@ -13,7 +13,7 @@ void GrowingFlower::OnSkillEventFired(Entity* self, Entity* target, const std::s
|
||||
const auto mission1 = self->GetVar<int32_t>(u"missionID");
|
||||
const auto mission2 = self->GetVar<int32_t>(u"missionID2");
|
||||
|
||||
Loot::DropActivityLoot(target, self, self->GetLOT(), 0);
|
||||
Loot::DropActivityLoot(target, self->GetObjectID(), self->GetLOT(), 0);
|
||||
|
||||
auto* missionComponent = target->GetComponent<MissionComponent>();
|
||||
if (missionComponent != nullptr) {
|
||||
|
||||
@@ -23,7 +23,7 @@ void WishingWellServer::OnUse(Entity* self, Entity* user) {
|
||||
|
||||
Loot::DropActivityLoot(
|
||||
user,
|
||||
self,
|
||||
self->GetObjectID(),
|
||||
static_cast<uint32_t>(scriptedActivity->GetActivityID()),
|
||||
GeneralUtils::GenerateRandomNumber<int32_t>(1, 1000)
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "eTerminateType.h"
|
||||
|
||||
void VeMissionConsole::OnUse(Entity* self, Entity* user) {
|
||||
Loot::DropActivityLoot(user, self, 12551);
|
||||
Loot::DropActivityLoot(user, self->GetObjectID(), 12551);
|
||||
|
||||
auto* inventoryComponent = user->GetComponent<InventoryComponent>();
|
||||
if (inventoryComponent != nullptr) {
|
||||
|
||||
@@ -14,6 +14,6 @@ void NjDragonEmblemChestServer::OnUse(Entity* self, Entity* user) {
|
||||
|
||||
auto* destroyable = self->GetComponent<DestroyableComponent>();
|
||||
if (destroyable != nullptr) {
|
||||
Loot::DropLoot(user, self, destroyable->GetLootMatrixID(), 0, 0);
|
||||
Loot::DropLoot(user, self->GetObjectID(), destroyable->GetLootMatrixID(), 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void MinigameTreasureChestServer::OnUse(Entity* self, Entity* user) {
|
||||
if (self->GetLOT() == frakjawChestId || Game::server->GetZoneID() == 1204)
|
||||
activityRating = team->members.size();
|
||||
|
||||
Loot::DropActivityLoot(teamMember, self, sac->GetActivityID(), activityRating);
|
||||
Loot::DropActivityLoot(teamMember, self->GetObjectID(), sac->GetActivityID(), activityRating);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -38,7 +38,7 @@ void MinigameTreasureChestServer::OnUse(Entity* self, Entity* user) {
|
||||
if (self->GetLOT() == frakjawChestId || Game::server->GetZoneID() == 1204)
|
||||
activityRating = 1;
|
||||
|
||||
Loot::DropActivityLoot(user, self, sac->GetActivityID(), activityRating);
|
||||
Loot::DropActivityLoot(user, self->GetObjectID(), sac->GetActivityID(), activityRating);
|
||||
}
|
||||
|
||||
sac->PlayerRemove(user->GetObjectID());
|
||||
|
||||
@@ -72,7 +72,8 @@ void ActivityManager::StopActivity(Entity* self, const LWOOBJID playerID, const
|
||||
SetActivityValue(self, playerID, 1, value1);
|
||||
SetActivityValue(self, playerID, 2, value2);
|
||||
|
||||
if (givingLoot) Loot::GiveActivityLoot(player, self, gameID, CalculateActivityRating(self, playerID));
|
||||
if (givingLoot) Loot::GiveActivityLoot(player, self->GetObjectID(), gameID, CalculateActivityRating(self, playerID));
|
||||
|
||||
if (sac != nullptr) {
|
||||
sac->PlayerRemove(player->GetObjectID());
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void ScriptedPowerupSpawner::OnTimerDone(Entity* self, std::string message) {
|
||||
renderComponent->PlayEffect(0, u"cast", "N_cast");
|
||||
}
|
||||
|
||||
Loot::DropLoot(owner, self, drops, 0, 0);
|
||||
Loot::DropLoot(owner, self->GetObjectID(), drops, 0, 0);
|
||||
}
|
||||
|
||||
// Increment the current cycle
|
||||
|
||||
@@ -11,7 +11,7 @@ void AgPicnicBlanket::OnUse(Entity* self, Entity* user) {
|
||||
self->SetVar<bool>(u"active", true);
|
||||
|
||||
auto lootTable = std::unordered_map<LOT, int32_t>{ {935, 3} };
|
||||
Loot::DropLoot(user, self, lootTable, 0, 0);
|
||||
Loot::DropLoot(user, self->GetObjectID(), lootTable, 0, 0);
|
||||
|
||||
self->AddCallbackTimer(5.0f, [self]() {
|
||||
self->SetVar<bool>(u"active", false);
|
||||
|
||||
@@ -572,7 +572,7 @@ void SGCannon::StopGame(Entity* self, bool cancel) {
|
||||
missionComponent->Progress(eMissionTaskType::ACTIVITY, m_CannonLot, 0, "", self->GetVar<int32_t>(TotalScoreVariable));
|
||||
}
|
||||
|
||||
Loot::GiveActivityLoot(player, self, GetGameID(self), self->GetVar<int32_t>(TotalScoreVariable));
|
||||
Loot::GiveActivityLoot(player, self->GetObjectID(), GetGameID(self), self->GetVar<int32_t>(TotalScoreVariable));
|
||||
|
||||
SaveScore(self, player->GetObjectID(),
|
||||
static_cast<float>(self->GetVar<int32_t>(TotalScoreVariable)), static_cast<float>(self->GetVar<uint32_t>(MaxStreakVariable)), percentage);
|
||||
|
||||
@@ -114,6 +114,7 @@ These commands are primarily for development and testing. The usage of many of t
|
||||
|addfaction|`/addfaction <faction id>`|Add the faction to the users list of factions|8|
|
||||
|getfactions|`/getfactions`|Shows the player's factions|8|
|
||||
|setrewardcode|`/setrewardcode <code>`|Sets the rewardcode for the account you are logged into if it's a valid rewardcode, See cdclient table `RewardCodes`|8|
|
||||
|barfight|`/barfight start`|Starts a barfight (turns everyones pvp on)|8|
|
||||
|crash|`/crash`|Crashes the server.|9|
|
||||
|rollloot|`/rollloot <loot matrix index> <item id> <amount>`|Given a `loot matrix index`, look for `item id` in that matrix `amount` times and print to the chat box statistics of rolling that loot matrix.|9|
|
||||
|castskill|`/castskill <skill id>`|Casts the skill as the player|9|
|
||||
|
||||
Reference in New Issue
Block a user