diff --git a/.github/workflows/build.yml b/.github/workflows/build-and-test.yml similarity index 92% rename from .github/workflows/build.yml rename to .github/workflows/build-and-test.yml index ae7501e8..1f4d0dca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-and-test.yml @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - build: + build-and-test: runs-on: ubuntu-latest @@ -20,6 +20,7 @@ jobs: with: configurePreset: 'default' buildPreset: 'default' + testPreset: 'default' - name: artifacts uses: actions/upload-artifact@v2 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index a8395c8a..85d2316a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.12) project(Darkflame) +include(CTest) # Read variables from file FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables) @@ -492,4 +493,8 @@ if(WIN32) add_dependencies(MasterServer WorldServer) add_dependencies(MasterServer AuthServer) add_dependencies(MasterServer ChatServer) -endif() \ No newline at end of file +endif() + +# Finally, add the tests +add_subdirectory(tests) + diff --git a/CMakePresets.json b/CMakePresets.json index 8b25452f..77d41205 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -36,5 +36,19 @@ "description": "Default Build", "jobs": 2 } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "displayName": "Default Tests", + "description": "Runs all tests", + "execution": { + "jobs": 2 + }, + "output": { + "outputOnFailure": true + } + } ] } diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 737bbba4..899fd355 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -354,7 +354,7 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) if (team->memberIDs.size() > 3) { // 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; } diff --git a/dCommon/NiPoint3.cpp b/dCommon/NiPoint3.cpp index d74be90b..4baefa13 100644 --- a/dCommon/NiPoint3.cpp +++ b/dCommon/NiPoint3.cpp @@ -93,14 +93,9 @@ Vector3 NiPoint3::CrossProduct(const Vector3& vec) const { //! Unitize the vector NiPoint3 NiPoint3::Unitize(void) const { - NiPoint3 unitVec; float length = this->Length(); - - unitVec.x = length != 0 ? this->x / length : 0; - unitVec.y = length != 0 ? this->y / length : 0; - unitVec.z = length != 0 ? this->z / length : 0; - - return unitVec; + + return length != 0 ? *this / length : NiPoint3::ZERO; } diff --git a/dCommon/dCommonVars.h b/dCommon/dCommonVars.h index 77570282..4920249d 100644 --- a/dCommon/dCommonVars.h +++ b/dCommon/dCommonVars.h @@ -469,6 +469,31 @@ enum eRebuildState : uint32_t { 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 { ACTIVITY_NONE, ACTIVITY_QUICKBUILDING, diff --git a/dDatabase/Database.cpp b/dDatabase/Database.cpp index 23fed182..cdadbbaa 100644 --- a/dDatabase/Database.cpp +++ b/dDatabase/Database.cpp @@ -28,7 +28,7 @@ void Database::Connect(const string& host, const string& database, const string& void Database::Destroy() { if (!con) return; - cout << "Destroying MySQL connection!" << endl; + Game::logger->Log("Database", "Destroying MySQL connection!\n"); con->close(); delete con; } //Destroy diff --git a/dGame/Character.cpp b/dGame/Character.cpp index 267e4577..4383ee46 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -527,7 +527,7 @@ void Character::OnZoneLoad() */ if (HasPermission(PermissionMap::Old)) { if (GetCoins() > 1000000) { - SetCoins(1000000); + SetCoins(1000000, LOOT_SOURCE_NONE); } } @@ -567,18 +567,15 @@ const NiPoint3& Character::GetRespawnPoint(LWOMAPID map) const return pair->second; } -void Character::SetCoins(int64_t newCoins, const bool message) { +void Character::SetCoins(int64_t newCoins, eLootSourceType lootSource) { if (newCoins < 0) { newCoins = 0; } m_Coins = newCoins; - - if (message) - { - GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true); - } + + GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootSource); } bool Character::HasBeenToWorld(LWOMAPID mapID) const diff --git a/dGame/Character.h b/dGame/Character.h index 57da8640..61017ccb 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -309,12 +309,11 @@ public: 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 - * as it's tracked by the client + * Updates the current amount of coins of the character by a specified amount * @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 diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 20af95e0..d0ec08d8 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -151,8 +151,8 @@ void Trade::Complete() if (inventoryA == nullptr || inventoryB == nullptr || characterA == nullptr || characterB == nullptr || missionsA == nullptr || missionsB == nullptr) return; - characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB); - characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA); + characterA->SetCoins(characterA->GetCoins() - m_CoinsA + m_CoinsB, LOOT_SOURCE_TRADE); + characterB->SetCoins(characterB->GetCoins() - m_CoinsB + m_CoinsA, LOOT_SOURCE_TRADE); for (const auto& tradeItem : m_ItemsA) { diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 5418e9f3..c01c5687 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -287,11 +287,11 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) std::stringstream xml; xml << ""; + xml << "\" hdc=\"0\" cd=\"" << shirtStyle << "\" lh=\"" << lh << "\" rh=\"" << rh << "\" es=\"" << eyebrows << "\" "; + xml << "ess=\"" << eyes << "\" ms=\"" << mouth << "\"/>"; xml << "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;\">"; xml << ""; xml << ""; diff --git a/dGame/dBehaviors/VerifyBehavior.cpp b/dGame/dBehaviors/VerifyBehavior.cpp index 71f75a18..f4edfece 100644 --- a/dGame/dBehaviors/VerifyBehavior.cpp +++ b/dGame/dBehaviors/VerifyBehavior.cpp @@ -23,7 +23,7 @@ void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS 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; } diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index 01beaa5f..fb4dfe61 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -825,7 +825,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose); } - character->SetCoins(coinsTotal); + character->SetCoins(coinsTotal, LOOT_SOURCE_PICKUP); Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity(); for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) { diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index fad5d7de..cd7910b4 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -706,7 +706,7 @@ void GameMessages::SendBroadcastTextToChatbox(Entity* entity, const SystemAddres 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 CMSGHEADER @@ -729,7 +729,6 @@ void GameMessages::SendSetCurrency(Entity* entity, int64_t currency, int lootTyp bitStream.Write(sourceTradeID != LWOOBJID_EMPTY); if (sourceTradeID != LWOOBJID_EMPTY) bitStream.Write(sourceTradeID); - int sourceType = 0; //For now. bitStream.Write(sourceType != LOOTTYPE_NONE); if (sourceType != LOOTTYPE_NONE) bitStream.Write(sourceType); @@ -4685,7 +4684,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream* inStream, Entity* enti inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost); } - character->SetCoins(character->GetCoins() - (coinCost)); + character->SetCoins(character->GetCoins() - (coinCost), LOOT_SOURCE_VENDOR); inv->AddItem(item, count); } @@ -4734,7 +4733,7 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit //inv->RemoveItem(count, -1, iObjID); 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 GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -4796,7 +4795,7 @@ void GameMessages::HandleBuybackFromVendor(RakNet::BitStream* inStream, Entity* //inv->RemoveItem(count, -1, iObjID); 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 GameMessages::SendVendorTransactionResult(entity, sysAddr); } @@ -5240,7 +5239,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent auto* ch = entity->GetCharacter(); 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; } - Game::logger->Log("GameMessages", "Build area found: %llu", buildArea->GetObjectID()); + Game::logger->Log("GameMessages", "Build area found: %llu\n", buildArea->GetObjectID()); GameMessages::SendStartArrangingWithItem( character, diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index e11f502a..0bc51c01 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -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 SendStopFXEffect(Entity* entity, bool killImmediate, std::string name); 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 SendEnableRebuild(Entity* entity, bool enable, bool fail, bool success, int failReason, float duration, const LWOOBJID& playerID); diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index 7f5104e6..8fadc49a 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -444,7 +444,7 @@ void Mission::YieldRewards() { 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) { count = 0; } @@ -453,7 +453,7 @@ void Mission::YieldRewards() { } 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; @@ -473,7 +473,7 @@ void Mission::YieldRewards() { 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) { count = 0; } @@ -482,7 +482,8 @@ void Mission::YieldRewards() { } 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) { diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 4ec056a5..635b2620 100644 --- a/dGame/dUtilities/Loot.cpp +++ b/dGame/dUtilities/Loot.cpp @@ -320,7 +320,7 @@ void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t ac 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) { diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index 2c3baf8c..302ba1cd 100644 --- a/dGame/dUtilities/Mail.cpp +++ b/dGame/dUtilities/Mail.cpp @@ -262,7 +262,7 @@ void Mail::HandleSendMail(RakNet::BitStream* packet, const SystemAddress& sysAdd } 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); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 5147cf16..6b1c932b 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -1338,7 +1338,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } 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) { @@ -1351,7 +1351,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } 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. diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index f16e791d..cb968169 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -645,7 +645,7 @@ void HandlePacket(Packet* packet) { } 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; break; } @@ -707,7 +707,7 @@ void ShutdownSequence() { auto* objIdManager = ObjectIDManager::TryInstance(); if (objIdManager != nullptr) { objIdManager->SaveToDatabase(); - printf("Saved objidtracker...\n"); + Game::logger->Log("MasterServer", "Saved ObjectIDTracker to DB\n"); } auto t = std::chrono::high_resolution_clock::now(); @@ -717,7 +717,8 @@ void ShutdownSequence() { 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) { auto done = true; diff --git a/dNet/dServer.cpp b/dNet/dServer.cpp index df366955..27b6df7c 100644 --- a/dNet/dServer.cpp +++ b/dNet/dServer.cpp @@ -104,13 +104,13 @@ Packet* dServer::ReceiveFromMaster() { if (packet->length < 1) { mMasterPeer->DeallocatePacket(packet); return nullptr; } 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; //ConnectToMaster(); //We'll just shut down now } 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; mMasterSystemAddress = packet->systemAddress; 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. default: + return packet; } } diff --git a/dScripts/NtAssemblyTubeServer.cpp b/dScripts/NtAssemblyTubeServer.cpp index 4653e1c7..5f05f54e 100644 --- a/dScripts/NtAssemblyTubeServer.cpp +++ b/dScripts/NtAssemblyTubeServer.cpp @@ -97,7 +97,7 @@ void NtAssemblyTubeServer::TeleportPlayer(Entity* self, Entity* player) GameMessages::SendPlayAnimation(player, u"tube-resurrect", 4.0f); - const auto animTime = 4; + const auto animTime = 2; const auto playerID = player->GetObjectID(); diff --git a/dScripts/NtParadoxTeleServer.cpp b/dScripts/NtParadoxTeleServer.cpp index dddd17e5..41d21cb7 100644 --- a/dScripts/NtParadoxTeleServer.cpp +++ b/dScripts/NtParadoxTeleServer.cpp @@ -88,7 +88,7 @@ void NtParadoxTeleServer::TeleportPlayer(Entity* self, Entity* player) GameMessages::SendPlayAnimation(player, u"paradox-teleport-in", 4.0f); - const auto animTime = 4; + const auto animTime = 2; const auto playerID = player->GetObjectID(); diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 520907ff..2a6cbaa5 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -475,7 +475,7 @@ int main(int argc, char** argv) { 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()); @@ -546,7 +546,7 @@ int main(int argc, char** argv) { if (Game::physicsWorld) Game::physicsWorld = nullptr; 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(); Database::Destroy(); @@ -573,13 +573,13 @@ dLogger * SetupLogger(int zoneID, int instanceID) { void HandlePacketChat(Packet* packet) { 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; } 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; chatConnected = true; @@ -863,7 +863,7 @@ void HandlePacket(Packet* packet) { case MSG_MASTER_SHUTDOWN: { 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; } @@ -1186,11 +1186,11 @@ void HandlePacket(Packet* packet) { } } 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); } } 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; } @@ -1296,7 +1296,7 @@ void WorldShutdownSequence() auto t = std::chrono::high_resolution_clock::now(); 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) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..eab4bbc9 --- /dev/null +++ b/tests/CMakeLists.txt @@ -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 () diff --git a/tests/CommonCxxTests.cpp b/tests/CommonCxxTests.cpp new file mode 100644 index 00000000..e69de29b diff --git a/tests/CommonCxxTests.h b/tests/CommonCxxTests.h new file mode 100644 index 00000000..f1894927 --- /dev/null +++ b/tests/CommonCxxTests.h @@ -0,0 +1,4 @@ +#include + +#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; }} diff --git a/tests/TestLDFFormat.cpp b/tests/TestLDFFormat.cpp new file mode 100644 index 00000000..276a8175 --- /dev/null +++ b/tests/TestLDFFormat.cpp @@ -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* )data)->GetValue(), u"VALUE"); + + // Check that the serialization is correct + ASSERT_EQ(data->GetString(), "KEY=0:VALUE"); + + // Cleanup the object + delete data; + + return 0; +} diff --git a/tests/TestNiPoint3.cpp b/tests/TestNiPoint3.cpp new file mode 100644 index 00000000..68da4571 --- /dev/null +++ b/tests/TestNiPoint3.cpp @@ -0,0 +1,13 @@ +#include + +#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; +}