Merge branch 'DarkflameUniverse:main' into main

This commit is contained in:
Nils Bergmann 2022-01-05 16:33:13 +01:00 committed by GitHub
commit 0f3fafde4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 177 additions and 61 deletions

View File

@ -7,7 +7,7 @@ on:
branches: [ main ] branches: [ main ]
jobs: jobs:
build: build-and-test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -20,6 +20,7 @@ jobs:
with: with:
configurePreset: 'default' configurePreset: 'default'
buildPreset: 'default' buildPreset: 'default'
testPreset: 'default'
- name: artifacts - name: artifacts
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:

View File

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
project(Darkflame) project(Darkflame)
include(CTest)
# Read variables from file # Read variables from file
FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables) FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables)
@ -493,3 +494,7 @@ add_dependencies(MasterServer WorldServer)
add_dependencies(MasterServer AuthServer) add_dependencies(MasterServer AuthServer)
add_dependencies(MasterServer ChatServer) add_dependencies(MasterServer ChatServer)
endif() endif()
# Finally, add the tests
add_subdirectory(tests)

View File

@ -36,5 +36,19 @@
"description": "Default Build", "description": "Default Build",
"jobs": 2 "jobs": 2
} }
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"displayName": "Default Tests",
"description": "Runs all tests",
"execution": {
"jobs": 2
},
"output": {
"outputOnFailure": true
}
}
] ]
} }

View File

@ -49,6 +49,15 @@ Make sure packages like `gcc`, `cmake`, and `zlib` are installed. Depending on t
cmake must be version 3.12 or higher! cmake must be version 3.12 or higher!
**Build the repository** **Build the repository**
You can either run `build.sh` when in the root folder of the repository:
```bash
./build.sh
```
Or manually run the commands used in `build.sh`:
```bash ```bash
# Create the build directory, preserving it if it already exists # Create the build directory, preserving it if it already exists
mkdir -p build mkdir -p build

0
build.sh Normal file → Executable file
View File

View File

@ -354,7 +354,7 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet)
if (team->memberIDs.size() > 3) { if (team->memberIDs.size() > 3) {
// no more teams greater than 4 // no more teams greater than 4
Game::logger->Log("ChatPacketHandler", "Someone tried to invite a 5th player to a team"); Game::logger->Log("ChatPacketHandler", "Someone tried to invite a 5th player to a team\n");
return; return;
} }

View File

@ -93,14 +93,9 @@ Vector3 NiPoint3::CrossProduct(const Vector3& vec) const {
//! Unitize the vector //! Unitize the vector
NiPoint3 NiPoint3::Unitize(void) const { NiPoint3 NiPoint3::Unitize(void) const {
NiPoint3 unitVec;
float length = this->Length(); float length = this->Length();
unitVec.x = length != 0 ? this->x / length : 0; return length != 0 ? *this / length : NiPoint3::ZERO;
unitVec.y = length != 0 ? this->y / length : 0;
unitVec.z = length != 0 ? this->z / length : 0;
return unitVec;
} }

View File

@ -469,6 +469,31 @@ enum eRebuildState : uint32_t {
REBUILD_INCOMPLETE REBUILD_INCOMPLETE
}; };
enum eLootSourceType : int32_t {
LOOT_SOURCE_NONE = 0,
LOOT_SOURCE_CHEST,
LOOT_SOURCE_MISSION,
LOOT_SOURCE_MAIL,
LOOT_SOURCE_CURRENCY,
LOOT_SOURCE_ACHIEVEMENT,
LOOT_SOURCE_TRADE,
LOOT_SOURCE_QUICKBUILD,
LOOT_SOURCE_DELETION,
LOOT_SOURCE_VENDOR,
LOOT_SOURCE_ACTIVITY,
LOOT_SOURCE_PICKUP,
LOOT_SOURCE_BRICK,
LOOT_SOURCE_PROPERTY,
LOOT_SOURCE_MODERATION,
LOOT_SOURCE_EXHIBIT,
LOOT_SOURCE_INVENTORY,
LOOT_SOURCE_CLAIMCODE,
LOOT_SOURCE_CONSUMPTION,
LOOT_SOURCE_CRAFTING,
LOOT_SOURCE_LEVELREWARD,
LOOT_SOURCE_RELOCATE
};
enum eGameActivities : uint32_t { enum eGameActivities : uint32_t {
ACTIVITY_NONE, ACTIVITY_NONE,
ACTIVITY_QUICKBUILDING, ACTIVITY_QUICKBUILDING,

View File

@ -28,7 +28,7 @@ void Database::Connect(const string& host, const string& database, const string&
void Database::Destroy() { void Database::Destroy() {
if (!con) return; if (!con) return;
cout << "Destroying MySQL connection!" << endl; Game::logger->Log("Database", "Destroying MySQL connection!\n");
con->close(); con->close();
delete con; delete con;
} //Destroy } //Destroy

View File

@ -527,7 +527,7 @@ void Character::OnZoneLoad()
*/ */
if (HasPermission(PermissionMap::Old)) { if (HasPermission(PermissionMap::Old)) {
if (GetCoins() > 1000000) { if (GetCoins() > 1000000) {
SetCoins(1000000); SetCoins(1000000, LOOT_SOURCE_NONE);
} }
} }
@ -567,7 +567,7 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const
return pair->second; return pair->second;
} }
void Character::SetCoins(int64_t newCoins, const bool message) { void Character::SetCoins(int64_t newCoins, eLootSourceType lootSource) {
if (newCoins < 0) if (newCoins < 0)
{ {
newCoins = 0; newCoins = 0;
@ -575,10 +575,7 @@ void Character::SetCoins(int64_t newCoins, const bool message) {
m_Coins = newCoins; m_Coins = newCoins;
if (message) GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootSource);
{
GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true);
}
} }
bool Character::HasBeenToWorld(LWOMAPID mapID) const bool Character::HasBeenToWorld(LWOMAPID mapID) const

View File

@ -309,12 +309,11 @@ public:
const int64_t GetCoins() const { return m_Coins; } const int64_t GetCoins() const { return m_Coins; }
/** /**
* Updates the current amount of coins of the character by a specified amount, for achievements this is not sent * Updates the current amount of coins of the character by a specified amount
* as it's tracked by the client
* @param newCoins the amount of coins to update by * @param newCoins the amount of coins to update by
* @param message whether to notify the client of the change * @param coinSource The source of the loot
*/ */
void SetCoins(int64_t newCoins, bool message = true); void SetCoins(int64_t newCoins, eLootSourceType coinSource);
/** /**
* Get the entity this character belongs to * Get the entity this character belongs to

View File

@ -151,8 +151,8 @@ void Trade::Complete()
if (inventoryA == nullptr || inventoryB == nullptr || characterA == nullptr || characterB == nullptr || missionsA == nullptr || missionsB == nullptr) return; if (inventoryA == nullptr || inventoryB == nullptr || characterA == nullptr || characterB == nullptr || missionsA == nullptr || missionsB == nullptr) return;
characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB); characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, LOOT_SOURCE_TRADE);
characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA); characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, LOOT_SOURCE_TRADE);
for (const auto& tradeItem : m_ItemsA) for (const auto& tradeItem : m_ItemsA)
{ {

View File

@ -287,11 +287,11 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
std::stringstream xml; std::stringstream xml;
xml << "<obj v=\"1\"><mf hc=\"" << hairColor << "\" hs=\"" << hairStyle << "\" hd=\"0\" t=\"" << shirtColor << "\" l=\"" << pantsColor; xml << "<obj v=\"1\"><mf hc=\"" << hairColor << "\" hs=\"" << hairStyle << "\" hd=\"0\" t=\"" << shirtColor << "\" l=\"" << pantsColor;
xml << "\" hdc=\"0\" cd=\"" << shirtStyle << "\" lh=\"" << lh << "\" rh=\"" << rh << "\" es=\"" << eyebrows << "\""; xml << "\" hdc=\"0\" cd=\"" << shirtStyle << "\" lh=\"" << lh << "\" rh=\"" << rh << "\" es=\"" << eyebrows << "\" ";
xml << " ess=\"" << eyes << "\" ms=\"" << mouth << "\"/>"; xml << "ess=\"" << eyes << "\" ms=\"" << mouth << "\"/>";
xml << "<char acct=\"" << u->GetAccountID() << "\" cc=\"0\" gm=\"0\" ft=\"0\" llog=\"" << time(NULL) << "\" "; xml << "<char acct=\"" << u->GetAccountID() << "\" cc=\"0\" gm=\"0\" ft=\"0\" llog=\"" << time(NULL) << "\" ";
xml << "ls=\"0\" lzx=\"-626.5847\" lzy=\"613.3515\" lzz=\"-28.6374\" lzrx=\"0.0\" lzry=\"0.7015\" lzrz=\"0.0\" lzrw=\"0.7126\""; xml << "ls=\"0\" lzx=\"-626.5847\" lzy=\"613.3515\" lzz=\"-28.6374\" lzrx=\"0.0\" lzry=\"0.7015\" lzrz=\"0.0\" lzrw=\"0.7126\" ";
xml << "stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\"></char>"; xml << "stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\"></char>";
xml << "<dest hm=\"4\" hc=\"4\" im=\"0\" ic=\"0\" am=\"0\" ac=\"0\" d=\"0\"/>"; xml << "<dest hm=\"4\" hc=\"4\" im=\"0\" ic=\"0\" am=\"0\" ac=\"0\" d=\"0\"/>";
xml << "<inv><bag><b t=\"0\" m=\"20\"/><b t=\"1\" m=\"240\"/><b t=\"2\" m=\"240\"/><b t=\"3\" m=\"240\"/></bag><items><in t=\"0\">"; xml << "<inv><bag><b t=\"0\" m=\"20\"/><b t=\"1\" m=\"240\"/><b t=\"2\" m=\"240\"/><b t=\"3\" m=\"240\"/></bag><items><in t=\"0\">";

View File

@ -23,7 +23,7 @@ void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
if (self == nullptr) if (self == nullptr)
{ {
Game::logger->Log("VerifyBehavior", "Invalid self for (%llu)", context->originator); Game::logger->Log("VerifyBehavior", "Invalid self for (%llu)\n", context->originator);
return; return;
} }

View File

@ -825,7 +825,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose); LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose);
} }
character->SetCoins(coinsTotal); character->SetCoins(coinsTotal, LOOT_SOURCE_PICKUP);
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity(); Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) { for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {

View File

@ -706,7 +706,7 @@ void GameMessages::SendBroadcastTextToChatbox(Entity* entity, const SystemAddres
SEND_PACKET_BROADCAST SEND_PACKET_BROADCAST
} }
void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent) { void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, eLootSourceType sourceType) {
CBITSTREAM CBITSTREAM
CMSGHEADER CMSGHEADER
@ -729,7 +729,6 @@ void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootTyp
bitStream.Write(sourceTradeID != LWOOBJID_EMPTY); bitStream.Write(sourceTradeID != LWOOBJID_EMPTY);
if (sourceTradeID != LWOOBJID_EMPTY) bitStream.Write(sourceTradeID); if (sourceTradeID != LWOOBJID_EMPTY) bitStream.Write(sourceTradeID);
int sourceType = 0; //For now.
bitStream.Write(sourceType != LOOTTYPE_NONE); bitStream.Write(sourceType != LOOTTYPE_NONE);
if (sourceType != LOOTTYPE_NONE) bitStream.Write(sourceType); if (sourceType != LOOTTYPE_NONE) bitStream.Write(sourceType);
@ -4685,7 +4684,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti
inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost); inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost);
} }
character->SetCoins(character->GetCoins() - (coinCost)); character->SetCoins(character->GetCoins() - (coinCost), LOOT_SOURCE_VENDOR);
inv->AddItem(item, count); inv->AddItem(item, count);
} }
@ -4734,7 +4733,7 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit
//inv->RemoveItem(count, -1, iObjID); //inv->RemoveItem(count, -1, iObjID);
inv->MoveItemToInventory(item, VENDOR_BUYBACK, count, true, false, true); inv->MoveItemToInventory(item, VENDOR_BUYBACK, count, true, false, true);
character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count))); character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar)*count)), LOOT_SOURCE_VENDOR);
//EntityManager::Instance()->SerializeEntity(player); // so inventory updates //EntityManager::Instance()->SerializeEntity(player); // so inventory updates
GameMessages::SendVendorTransactionResult(entity, sysAddr); GameMessages::SendVendorTransactionResult(entity, sysAddr);
} }
@ -4796,7 +4795,7 @@ void GameMessages::HandleBuybackFromVendor(RakNet::BitStream* inStream, Entity*
//inv->RemoveItem(count, -1, iObjID); //inv->RemoveItem(count, -1, iObjID);
inv->MoveItemToInventory(item, Inventory::FindInventoryTypeForLot(item->GetLot()), count, true, false); inv->MoveItemToInventory(item, Inventory::FindInventoryTypeForLot(item->GetLot()), count, true, false);
character->SetCoins(character->GetCoins() - cost); character->SetCoins(character->GetCoins() - cost, LOOT_SOURCE_VENDOR);
//EntityManager::Instance()->SerializeEntity(player); // so inventory updates //EntityManager::Instance()->SerializeEntity(player); // so inventory updates
GameMessages::SendVendorTransactionResult(entity, sysAddr); GameMessages::SendVendorTransactionResult(entity, sysAddr);
} }
@ -5240,7 +5239,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent
auto* ch = entity->GetCharacter(); auto* ch = entity->GetCharacter();
if (entity->CanPickupCoins(currency)) { if (entity->CanPickupCoins(currency)) {
ch->SetCoins(ch->GetCoins() + currency); ch->SetCoins(ch->GetCoins() + currency, LOOT_SOURCE_PICKUP);
} }
} }
@ -5673,7 +5672,7 @@ void GameMessages::HandleDoneArrangingWithItem(RakNet::BitStream* inStream, Enti
return; return;
} }
Game::logger->Log("GameMessages", "Build area found: %llu", buildArea->GetObjectID()); Game::logger->Log("GameMessages", "Build area found: %llu\n", buildArea->GetObjectID());
GameMessages::SendStartArrangingWithItem( GameMessages::SendStartArrangingWithItem(
character, character,

View File

@ -78,7 +78,7 @@ namespace GameMessages {
void SendPlayFXEffect(const LWOOBJID& entity, int32_t effectID, const std::u16string& effectType, const std::string& name, LWOOBJID secondary = LWOOBJID_EMPTY, float priority = 1, float scale = 1, bool serialize = true); void SendPlayFXEffect(const LWOOBJID& entity, int32_t effectID, const std::u16string& effectType, const std::string& name, LWOOBJID secondary = LWOOBJID_EMPTY, float priority = 1, float scale = 1, bool serialize = true);
void SendStopFXEffect(Entity* entity, bool killImmediate, std::string name); void SendStopFXEffect(Entity* entity, bool killImmediate, std::string name);
void SendBroadcastTextToChatbox(Entity* entity, const SystemAddress& sysAddr, const std::u16string& attrs, const std::u16string& wsText); void SendBroadcastTextToChatbox(Entity* entity, const SystemAddress& sysAddr, const std::u16string& attrs, const std::u16string& wsText);
void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent); void SendSetCurrency(Entity* entity, int64_t currency, int lootType, const LWOOBJID& sourceID, const LOT& sourceLOT, int sourceTradeID, bool overrideCurrent, eLootSourceType sourceType);
void SendRebuildNotifyState(Entity* entity, int prevState, int state, const LWOOBJID& playerID); void SendRebuildNotifyState(Entity* entity, int prevState, int state, const LWOOBJID& playerID);
void SendEnableRebuild(Entity* entity, bool enable, bool fail, bool success, int failReason, float duration, const LWOOBJID& playerID); void SendEnableRebuild(Entity* entity, bool enable, bool fail, bool success, int failReason, float duration, const LWOOBJID& playerID);

View File

@ -444,7 +444,7 @@ void Mission::YieldRewards() {
auto count = pair.second > 0 ? pair.second : 1; auto count = pair.second > 0 ? pair.second : 1;
// Sanitfy check, 6 is the max any mission yields // Sanity check, 6 is the max any mission yields
if (count > 6) { if (count > 6) {
count = 0; count = 0;
} }
@ -453,7 +453,7 @@ void Mission::YieldRewards() {
} }
if (info->reward_currency_repeatable > 0) { if (info->reward_currency_repeatable > 0) {
character->SetCoins(character->GetCoins() + info->reward_currency_repeatable); character->SetCoins(character->GetCoins() + info->reward_currency_repeatable, LOOT_SOURCE_MISSION);
} }
return; return;
@ -473,7 +473,7 @@ void Mission::YieldRewards() {
auto count = pair.second > 0 ? pair.second : 1; auto count = pair.second > 0 ? pair.second : 1;
// Sanitfy check, 6 is the max any mission yields // Sanity check, 6 is the max any mission yields
if (count > 6) { if (count > 6) {
count = 0; count = 0;
} }
@ -482,7 +482,8 @@ void Mission::YieldRewards() {
} }
if (info->reward_currency > 0) { if (info->reward_currency > 0) {
character->SetCoins(character->GetCoins() + info->reward_currency, info->isMission); eLootSourceType lootSource = info->isMission ? LOOT_SOURCE_MISSION : LOOT_SOURCE_ACHIEVEMENT;
character->SetCoins(character->GetCoins() + info->reward_currency, lootSource);
} }
if (info->reward_maxinventory > 0) { if (info->reward_maxinventory > 0) {

View File

@ -320,7 +320,7 @@ void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t ac
auto* character = player->GetCharacter(); auto* character = player->GetCharacter();
character->SetCoins(character->GetCoins() + coins); character->SetCoins(character->GetCoins() + coins, LOOT_SOURCE_ACTIVITY);
} }
void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) { void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) {

View File

@ -262,7 +262,7 @@ void Mail::HandleSendMail(RakNet::BitStream* packet, const SystemAddress& sysAdd
} }
Mail::SendSendResponse(sysAddr, Mail::MailSendResponse::Success); Mail::SendSendResponse(sysAddr, Mail::MailSendResponse::Success);
entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost); entity->GetCharacter()->SetCoins(entity->GetCharacter()->GetCoins() - mailCost, LOOT_SOURCE_MAIL);
Game::logger->Log("Mail", "Seeing if we need to remove item with ID/count/LOT: %i %i %i\n", itemID, attachmentCount, itemLOT); Game::logger->Log("Mail", "Seeing if we need to remove item with ID/count/LOT: %i %i %i\n", itemID, attachmentCount, itemLOT);

View File

@ -1334,7 +1334,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
} }
auto* ch = entity->GetCharacter(); auto* ch = entity->GetCharacter();
ch->SetCoins(ch->GetCoins() + money); ch->SetCoins(ch->GetCoins() + money, LOOT_SOURCE_MODERATION);
} }
if ((chatCommand == "setcurrency") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { if ((chatCommand == "setcurrency") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
@ -1347,7 +1347,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
} }
auto* ch = entity->GetCharacter(); auto* ch = entity->GetCharacter();
ch->SetCoins(money); ch->SetCoins(money, LOOT_SOURCE_MODERATION);
} }
// Allow for this on even while not a GM, as it sometimes toggles incorrrectly. // Allow for this on even while not a GM, as it sometimes toggles incorrrectly.

View File

@ -651,7 +651,7 @@ void HandlePacket(Packet* packet) {
} }
case MSG_MASTER_SHUTDOWN_UNIVERSE: { case MSG_MASTER_SHUTDOWN_UNIVERSE: {
Game::logger->Log("MasterServer","Received shutdown universe command, ""shutting down in 10 minutes.\n"); Game::logger->Log("MasterServer","Received shutdown universe command, shutting down in 10 minutes.\n");
shouldShutdown = true; shouldShutdown = true;
break; break;
} }
@ -713,7 +713,7 @@ void ShutdownSequence() {
auto* objIdManager = ObjectIDManager::TryInstance(); auto* objIdManager = ObjectIDManager::TryInstance();
if (objIdManager != nullptr) { if (objIdManager != nullptr) {
objIdManager->SaveToDatabase(); objIdManager->SaveToDatabase();
printf("Saved objidtracker...\n"); Game::logger->Log("MasterServer", "Saved ObjectIDTracker to DB\n");
} }
auto t = std::chrono::high_resolution_clock::now(); auto t = std::chrono::high_resolution_clock::now();
@ -723,7 +723,8 @@ void ShutdownSequence() {
exit(0); exit(0);
} }
printf("Attempting to shutdown instances, max 60 seconds...\n"); Game::logger->Log("MasterServer", "Attempting to shutdown instances, max 60 seconds...\n");
while (true) { while (true) {
auto done = true; auto done = true;

View File

@ -104,13 +104,13 @@ Packet* dServer::ReceiveFromMaster() {
if (packet->length < 1) { mMasterPeer->DeallocatePacket(packet); return nullptr; } if (packet->length < 1) { mMasterPeer->DeallocatePacket(packet); return nullptr; }
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) { if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
mLogger->Log("Server", "Lost our connection to master, shutting DOWN!\n"); mLogger->Log("dServer", "Lost our connection to master, shutting DOWN!\n");
mMasterConnectionActive = false; mMasterConnectionActive = false;
//ConnectToMaster(); //We'll just shut down now //ConnectToMaster(); //We'll just shut down now
} }
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) { if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
mLogger->Log("Server", "Established connection to master\n"); mLogger->Log("dServer", "Established connection to master, zone (%i), instance (%i)\n",this->GetZoneID(), this->GetInstanceID());
mMasterConnectionActive = true; mMasterConnectionActive = true;
mMasterSystemAddress = packet->systemAddress; mMasterSystemAddress = packet->systemAddress;
MasterPackets::SendServerInfo(this, packet); MasterPackets::SendServerInfo(this, packet);
@ -127,6 +127,7 @@ Packet* dServer::ReceiveFromMaster() {
//When we handle these packets in World instead dServer, we just return the packet's pointer. //When we handle these packets in World instead dServer, we just return the packet's pointer.
default: default:
return packet; return packet;
} }
} }

View File

@ -97,7 +97,7 @@ void NtAssemblyTubeServer::TeleportPlayer(Entity* self, Entity* player)
GameMessages::SendPlayAnimation(player, u"tube-resurrect", 4.0f); GameMessages::SendPlayAnimation(player, u"tube-resurrect", 4.0f);
const auto animTime = 4; const auto animTime = 2;
const auto playerID = player->GetObjectID(); const auto playerID = player->GetObjectID();

View File

@ -88,7 +88,7 @@ void NtParadoxTeleServer::TeleportPlayer(Entity* self, Entity* player)
GameMessages::SendPlayAnimation(player, u"paradox-teleport-in", 4.0f); GameMessages::SendPlayAnimation(player, u"paradox-teleport-in", 4.0f);
const auto animTime = 4; const auto animTime = 2;
const auto playerID = player->GetObjectID(); const auto playerID = player->GetObjectID();

View File

@ -475,7 +475,7 @@ int main(int argc, char** argv) {
if (framesSinceMasterStatus >= 200) if (framesSinceMasterStatus >= 200)
{ {
Game::logger->Log("WorldServer", "Finished loading world, ready up!\n"); Game::logger->Log("WorldServer", "Finished loading world with zone (%i), ready up!\n", Game::server->GetZoneID());
MasterPackets::SendWorldReady(Game::server, Game::server->GetZoneID(), Game::server->GetInstanceID()); MasterPackets::SendWorldReady(Game::server, Game::server->GetZoneID(), Game::server->GetInstanceID());
@ -546,7 +546,7 @@ int main(int argc, char** argv) {
if (Game::physicsWorld) Game::physicsWorld = nullptr; if (Game::physicsWorld) Game::physicsWorld = nullptr;
if (Game::zoneManager) delete Game::zoneManager; if (Game::zoneManager) delete Game::zoneManager;
Game::logger->Log("Test", "Quitting\n"); Game::logger->Log("WorldServer", "Shutdown complete, zone (%i), instance (%i)\n", Game::server->GetZoneID(), instanceID);
Metrics::Clear(); Metrics::Clear();
Database::Destroy(); Database::Destroy();
@ -573,13 +573,13 @@ dLogger * SetupLogger(int zoneID, int instanceID) {
void HandlePacketChat(Packet* packet) { void HandlePacketChat(Packet* packet) {
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) { if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
Game::logger->Log("WorldServer", "Lost our connection to chat.\n"); Game::logger->Log("WorldServer", "Lost our connection to chat, zone(%i), instance(%i)\n", Game::server->GetZoneID(), Game::server->GetInstanceID());
chatConnected = false; chatConnected = false;
} }
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) { if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
Game::logger->Log("WorldServer", "Established connection to chat\n"); Game::logger->Log("WorldServer", "Established connection to chat, zone(%i), instance (%i)\n",Game::server -> GetZoneID(), Game::server -> GetInstanceID());
Game::chatSysAddr = packet->systemAddress; Game::chatSysAddr = packet->systemAddress;
chatConnected = true; chatConnected = true;
@ -863,7 +863,7 @@ void HandlePacket(Packet* packet) {
case MSG_MASTER_SHUTDOWN: { case MSG_MASTER_SHUTDOWN: {
worldShutdownSequenceStarted = true; worldShutdownSequenceStarted = true;
Game::logger->Log("WorldServer", "Got shutdown request\n"); Game::logger->Log("WorldServer", "Got shutdown request from master, zone (%i), instance (%i)\n", Game::server->GetZoneID(), Game::server->GetInstanceID());
break; break;
} }
@ -1186,11 +1186,11 @@ void HandlePacket(Packet* packet) {
} }
} }
else { else {
Game::logger->Log("WorldMain", "Couldn't find character to log in with for user %s (%i)!\n", user->GetUsername().c_str(), user->GetAccountID()); Game::logger->Log("WorldServer", "Couldn't find character to log in with for user %s (%i)!\n", user->GetUsername().c_str(), user->GetAccountID());
Game::server->Disconnect(packet->systemAddress, SERVER_DISCON_CHARACTER_NOT_FOUND); Game::server->Disconnect(packet->systemAddress, SERVER_DISCON_CHARACTER_NOT_FOUND);
} }
} else { } else {
Game::logger->Log("WorldMain", "Couldn't get user for level load complete!\n"); Game::logger->Log("WorldServer", "Couldn't get user for level load complete!\n");
} }
break; break;
} }
@ -1296,7 +1296,7 @@ void WorldShutdownSequence()
auto t = std::chrono::high_resolution_clock::now(); auto t = std::chrono::high_resolution_clock::now();
auto ticks = 0; auto ticks = 0;
printf("Attempting to shutdown world, max 10 seconds...");; Game::logger->Log("WorldServer", "Attempting to shutdown world, zone (%i), instance (%i), max 10 seconds...\n", Game::server->GetZoneID(), instanceID);
while (true) while (true)
{ {

21
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,21 @@
# create the testing file and list of tests
create_test_sourcelist (Tests
CommonCxxTests.cpp
TestNiPoint3.cpp
TestLDFFormat.cpp
)
# add the executable
add_executable (CommonCxxTests ${Tests})
target_link_libraries(CommonCxxTests dCommon raknet)
# remove the test driver source file
set (TestsToRun ${Tests})
remove (TestsToRun CommonCxxTests.cpp)
# Add all the ADD_TEST for each test
foreach (test ${TestsToRun})
get_filename_component (TName ${test} NAME_WE)
add_test (NAME ${TName} COMMAND CommonCxxTests ${TName})
set_property(TEST ${TName} PROPERTY ENVIRONMENT CTEST_OUTPUT_ON_FAILURE=1)
endforeach ()

0
tests/CommonCxxTests.cpp Normal file
View File

4
tests/CommonCxxTests.h Normal file
View File

@ -0,0 +1,4 @@
#include <cstdio>
#define ASSERT_EQ(a,b) { if (!(a == b)) { printf("Failed assertion: " #a " == " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }}
#define ASSERT_NE(a,b) { if (!(a != b)) { printf("Failed assertion: " #a " != " #b " \n in %s:%d\n", __FILE__, __LINE__); return 1; }}

31
tests/TestLDFFormat.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "LDFFormat.h"
#include "CommonCxxTests.h"
/**
* @brief Test parsing an LDF value
*
* @param argc Number of command line arguments for this test
* @param argv Command line arguments
* @return 0 on success, non-zero on failure
*/
int TestLDFFormat(int argc, char** argv) {
// Create
auto* data = LDFBaseData::DataFromString("KEY=0:VALUE");
// Check that the data type is correct
ASSERT_EQ(data->GetValueType(), eLDFType::LDF_TYPE_UTF_16);
// Check that the key is correct
ASSERT_EQ(data->GetKey(), u"KEY");
// Check that the value is correct
ASSERT_EQ(((LDFData<std::u16string>* )data)->GetValue(), u"VALUE");
// Check that the serialization is correct
ASSERT_EQ(data->GetString(), "KEY=0:VALUE");
// Cleanup the object
delete data;
return 0;
}

13
tests/TestNiPoint3.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <stdexcept>
#include "NiPoint3.h"
#include "CommonCxxTests.h"
int TestNiPoint3(int argc, char** argv) {
// Check that Unitize works
ASSERT_EQ(NiPoint3(3,0,0).Unitize(), NiPoint3::UNIT_X);
// Check what unitize does to a vector of length 0
ASSERT_EQ(NiPoint3::ZERO.Unitize(), NiPoint3::ZERO);
// If we get here, all was successful
return 0;
}