diff --git a/game/server/application/CMakeLists.txt b/game/server/application/CMakeLists.txt index 014c8492..a134e113 100644 --- a/game/server/application/CMakeLists.txt +++ b/game/server/application/CMakeLists.txt @@ -1,2 +1,3 @@ +add_subdirectory(SwgDatabaseServer) add_subdirectory(SwgGameServer) diff --git a/game/server/application/SwgDatabaseServer/CMakeLists.txt b/game/server/application/SwgDatabaseServer/CMakeLists.txt new file mode 100644 index 00000000..2ee18a3a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 2.8) + +project(SwgDatabaseServer) + +if(WIN32) + add_definitions(/D_CRT_SECURE_NO_WARNINGS) +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public) + +add_subdirectory(src) diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/AuctionLocationsBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/AuctionLocationsBuffer.h new file mode 100644 index 00000000..d285d76a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/AuctionLocationsBuffer.h @@ -0,0 +1 @@ +#include "../../../src/shared/buffers/AuctionLocationsBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BattlefieldParticipantBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BattlefieldParticipantBuffer.h new file mode 100644 index 00000000..b39feeab --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BattlefieldParticipantBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/BattlefieldParticipantBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BattlefieldParticipantQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BattlefieldParticipantQuery.h new file mode 100644 index 00000000..79d83c2a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BattlefieldParticipantQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/BattlefieldParticipantQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BountyHunterTargetBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BountyHunterTargetBuffer.h new file mode 100644 index 00000000..045e146c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BountyHunterTargetBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/BountyHunterTargetBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BountyHunterTargetQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BountyHunterTargetQuery.h new file mode 100644 index 00000000..37afc497 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/BountyHunterTargetQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/BountyHunterTargetQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CMLoader.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CMLoader.h new file mode 100644 index 00000000..7a3ebf6f --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CMLoader.h @@ -0,0 +1 @@ +#include "../../src/shared/core/CMLoader.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesQuery.h new file mode 100644 index 00000000..b261c0d4 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesQuery.h @@ -0,0 +1 @@ +#include "../../../src/shared/queries/CommoditiesQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesSchema.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesSchema.h new file mode 100644 index 00000000..45ba51e7 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesSchema.h @@ -0,0 +1 @@ +#include "../../../src/shared/queries/CommoditiesSchema.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesSnapshot.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesSnapshot.h new file mode 100644 index 00000000..695209d2 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CommoditiesSnapshot.h @@ -0,0 +1 @@ +#include "../../src/shared/core/CommoditiesSnapshot.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CreatureObjectBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CreatureObjectBuffer.h new file mode 100644 index 00000000..a367c06b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/CreatureObjectBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/CreatureObjectBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/DataCleanupManager.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/DataCleanupManager.h new file mode 100644 index 00000000..709a2282 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/DataCleanupManager.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/DataCleanupManager.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/DeleteDemandLoadedContainerQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/DeleteDemandLoadedContainerQuery.h new file mode 100644 index 00000000..c73095f5 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/DeleteDemandLoadedContainerQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/DeleteDemandLoadedContainerQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ExperienceBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ExperienceBuffer.h new file mode 100644 index 00000000..31aea544 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ExperienceBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/ExperienceBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ExperienceQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ExperienceQuery.h new file mode 100644 index 00000000..706d2234 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ExperienceQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/ExperienceQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/FirstSwgDatabaseServer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/FirstSwgDatabaseServer.h new file mode 100644 index 00000000..31c794a5 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/FirstSwgDatabaseServer.h @@ -0,0 +1 @@ +#include "../../src/shared/core/FirstSwgDatabaseServer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/IndexedNetworkTableBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/IndexedNetworkTableBuffer.h new file mode 100644 index 00000000..99603f15 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/IndexedNetworkTableBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/IndexedNetworkTableBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/IndexedTableBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/IndexedTableBuffer.h new file mode 100644 index 00000000..350f50d6 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/IndexedTableBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/IndexedTableBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/LocationBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/LocationBuffer.h new file mode 100644 index 00000000..181bfea1 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/LocationBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/LocationBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/LocationQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/LocationQuery.h new file mode 100644 index 00000000..6fed9d2d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/LocationQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/LocationQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ManufactureSchematicAttributeBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ManufactureSchematicAttributeBuffer.h new file mode 100644 index 00000000..baa80956 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ManufactureSchematicAttributeBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/ManufactureSchematicAttributeBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ManufactureSchematicAttributeQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ManufactureSchematicAttributeQuery.h new file mode 100644 index 00000000..0b5403c6 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ManufactureSchematicAttributeQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/ManufactureSchematicAttributeQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MarketAuctionBidsBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MarketAuctionBidsBuffer.h new file mode 100644 index 00000000..49f94464 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MarketAuctionBidsBuffer.h @@ -0,0 +1 @@ +#include "../../../src/shared/buffers/MarketAuctionBidsBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MarketAuctionsBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MarketAuctionsBuffer.h new file mode 100644 index 00000000..2137702d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MarketAuctionsBuffer.h @@ -0,0 +1 @@ +#include "../../../src/shared/buffers/MarketAuctionsBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MessageBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MessageBuffer.h new file mode 100644 index 00000000..efa2595b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MessageBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/MessageBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MessageQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MessageQuery.h new file mode 100644 index 00000000..025513ee --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/MessageQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/MessageQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectQueries.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectQueries.h new file mode 100644 index 00000000..1cc32dda --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectQueries.h @@ -0,0 +1 @@ +#include "../../src/shared/generated/ObjectQueries.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectTableBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectTableBuffer.h new file mode 100644 index 00000000..0a20cf7d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectTableBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/ObjectTableBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectVariableQueries.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectVariableQueries.h new file mode 100644 index 00000000..3e2c0f02 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectVariableQueries.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/ObjectVariableQueries.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectsTableQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectsTableQuery.h new file mode 100644 index 00000000..bb530475 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjectsTableQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/ObjectsTableQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjvarBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjvarBuffer.h new file mode 100644 index 00000000..ff1c9b04 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjvarBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/ObjvarBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjvarNameManager.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjvarNameManager.h new file mode 100644 index 00000000..700e4557 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ObjvarNameManager.h @@ -0,0 +1 @@ +#include "../../src/shared/core/ObjvarNameManager.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/OfflineMoneyCustomPersistStep.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/OfflineMoneyCustomPersistStep.h new file mode 100644 index 00000000..f6ae431a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/OfflineMoneyCustomPersistStep.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/OfflineMoneyCustomPersistStep.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PersistableMatchMakingId.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PersistableMatchMakingId.h new file mode 100644 index 00000000..e69de29b diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PersistableWaypoint.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PersistableWaypoint.h new file mode 100644 index 00000000..525c86f7 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PersistableWaypoint.h @@ -0,0 +1 @@ +#include "../../src/shared/persistable/PersistableWaypoint.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PropertyListBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PropertyListBuffer.h new file mode 100644 index 00000000..d79064aa --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PropertyListBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/PropertyListBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PropertyListQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PropertyListQuery.h new file mode 100644 index 00000000..d6fb6ab2 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/PropertyListQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/PropertyListQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ResourceTypeBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ResourceTypeBuffer.h new file mode 100644 index 00000000..7bac1b0d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ResourceTypeBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/ResourceTypeBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ResourceTypeQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ResourceTypeQuery.h new file mode 100644 index 00000000..f854f6db --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ResourceTypeQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/ResourceTypeQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/Schema.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/Schema.h new file mode 100644 index 00000000..72e23cb0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/Schema.h @@ -0,0 +1 @@ +#include "../../src/shared/generated/Schema.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ScriptBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ScriptBuffer.h new file mode 100644 index 00000000..a37929a6 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/ScriptBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/ScriptBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SkillQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SkillQuery.h new file mode 100644 index 00000000..da39ab13 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SkillQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/SkillQuery.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgDatabaseServer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgDatabaseServer.h new file mode 100644 index 00000000..1ff2ced7 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgDatabaseServer.h @@ -0,0 +1 @@ +#include "../../src/shared/core/SwgDatabaseServer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgLoader.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgLoader.h new file mode 100644 index 00000000..0e5fe0a6 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgLoader.h @@ -0,0 +1 @@ +#include "../../src/shared/core/SwgLoader.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgLoaderSnapshotGroup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgLoaderSnapshotGroup.h new file mode 100644 index 00000000..230b507e --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgLoaderSnapshotGroup.h @@ -0,0 +1 @@ +#include "../../src/shared/core/SwgLoaderSnapshotGroup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgPersister.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgPersister.h new file mode 100644 index 00000000..4adf2189 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgPersister.h @@ -0,0 +1 @@ +#include "../../src/shared/core/SwgPersister.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgSnapshot.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgSnapshot.h new file mode 100644 index 00000000..a338db0d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/SwgSnapshot.h @@ -0,0 +1 @@ +#include "../../src/shared/core/SwgSnapshot.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskAnySQL.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskAnySQL.h new file mode 100644 index 00000000..23561c54 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskAnySQL.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskAnySQL.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskBrokenObjectCleanup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskBrokenObjectCleanup.h new file mode 100644 index 00000000..1d47515e --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskBrokenObjectCleanup.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskBrokenObjectCleanup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskConsolidateExperience.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskConsolidateExperience.h new file mode 100644 index 00000000..b633b51b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskConsolidateExperience.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskConsolidateExperience.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskDailyCleanup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskDailyCleanup.h new file mode 100644 index 00000000..ddc21bcb --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskDailyCleanup.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskDailyCleanup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskFixBadCells.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskFixBadCells.h new file mode 100644 index 00000000..15dce91b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskFixBadCells.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskFixBadCells.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskGetCharacters.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskGetCharacters.h new file mode 100644 index 00000000..57d48cd1 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskGetCharacters.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskGetCharacters.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskLoadObjvarNames.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskLoadObjvarNames.h new file mode 100644 index 00000000..61f799d9 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskLoadObjvarNames.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskLoadObjvarNames.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskLocateStructure.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskLocateStructure.h new file mode 100644 index 00000000..e0c789d1 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskLocateStructure.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskLocateStructure.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMarketAttributesCleanup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMarketAttributesCleanup.h new file mode 100644 index 00000000..a7ed7f78 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMarketAttributesCleanup.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskMarketAttributesCleanup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMessagesCleanup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMessagesCleanup.h new file mode 100644 index 00000000..7dcc4b85 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMessagesCleanup.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskMessagesCleanup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMoveToPlayer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMoveToPlayer.h new file mode 100644 index 00000000..e2d02f53 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskMoveToPlayer.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskMoveToPlayer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskObjectTemplateListUpdater.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskObjectTemplateListUpdater.h new file mode 100644 index 00000000..83247c3f --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskObjectTemplateListUpdater.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskObjectTemplateListUpdater.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskObjvarNameCleanup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskObjvarNameCleanup.h new file mode 100644 index 00000000..30c0a94b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskObjvarNameCleanup.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskObjvarNameCleanup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskOrphanedObjectCleanup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskOrphanedObjectCleanup.h new file mode 100644 index 00000000..3fcfa049 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskOrphanedObjectCleanup.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskOrphanedObjectCleanup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskRestoreCharacter.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskRestoreCharacter.h new file mode 100644 index 00000000..e9952b35 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskRestoreCharacter.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskRestoreCharacter.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskRestoreHouse.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskRestoreHouse.h new file mode 100644 index 00000000..1db46be6 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskRestoreHouse.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskRestoreHouse.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskSaveObjvarNames.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskSaveObjvarNames.h new file mode 100644 index 00000000..1de364b6 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskSaveObjvarNames.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskSaveObjvarNames.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskUndeleteItem.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskUndeleteItem.h new file mode 100644 index 00000000..5cea0c33 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskUndeleteItem.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskUndeleteItem.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskVendorObjectCleanup.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskVendorObjectCleanup.h new file mode 100644 index 00000000..c15ce834 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskVendorObjectCleanup.h @@ -0,0 +1 @@ +#include "../../src/shared/cleanup/TaskVendorObjectCleanup.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskVerifyCharacter.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskVerifyCharacter.h new file mode 100644 index 00000000..54202432 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/TaskVerifyCharacter.h @@ -0,0 +1 @@ +#include "../../src/shared/tasks/TaskVerifyCharacter.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/WaypointBuffer.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/WaypointBuffer.h new file mode 100644 index 00000000..f8cdaa6d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/WaypointBuffer.h @@ -0,0 +1 @@ +#include "../../src/shared/buffers/WaypointBuffer.h" diff --git a/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/WaypointQuery.h b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/WaypointQuery.h new file mode 100644 index 00000000..58bd02eb --- /dev/null +++ b/game/server/application/SwgDatabaseServer/include/public/SwgDatabaseServer/WaypointQuery.h @@ -0,0 +1 @@ +#include "../../src/shared/queries/WaypointQuery.h" diff --git a/game/server/application/SwgDatabaseServer/src/CMakeLists.txt b/game/server/application/SwgDatabaseServer/src/CMakeLists.txt new file mode 100644 index 00000000..37de5935 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/CMakeLists.txt @@ -0,0 +1,265 @@ + +set(SHARED_SOURCES + shared/buffers/AuctionLocationsBuffer.cpp + shared/buffers/AuctionLocationsBuffer.h + shared/buffers/BattlefieldParticipantBuffer.cpp + shared/buffers/BattlefieldParticipantBuffer.h + shared/buffers/BountyHunterTargetBuffer.cpp + shared/buffers/BountyHunterTargetBuffer.h + shared/buffers/CreatureObjectBuffer.cpp + shared/buffers/CreatureObjectBuffer.h + shared/buffers/ExperienceBuffer.cpp + shared/buffers/ExperienceBuffer.h + shared/buffers/IndexedNetworkTableBuffer.cpp + shared/buffers/IndexedNetworkTableBuffer.h + shared/buffers/IndexedTableBuffer.h + shared/buffers/LocationBuffer.cpp + shared/buffers/LocationBuffer.h + shared/buffers/ManufactureSchematicAttributeBuffer.cpp + shared/buffers/ManufactureSchematicAttributeBuffer.h + shared/buffers/MarketAuctionBidsBuffer.cpp + shared/buffers/MarketAuctionBidsBuffer.h + shared/buffers/MarketAuctionsBuffer.cpp + shared/buffers/MarketAuctionsBuffer.h + shared/buffers/MessageBuffer.cpp + shared/buffers/MessageBuffer.h + shared/buffers/ObjectTableBuffer.cpp + shared/buffers/ObjectTableBuffer.h + shared/buffers/ObjvarBuffer.cpp + shared/buffers/ObjvarBuffer.h + shared/buffers/PropertyListBuffer.cpp + shared/buffers/PropertyListBuffer.h + shared/buffers/ResourceTypeBuffer.cpp + shared/buffers/ResourceTypeBuffer.h + shared/buffers/ScriptBuffer.cpp + shared/buffers/ScriptBuffer.h + shared/buffers/WaypointBuffer.cpp + shared/buffers/WaypointBuffer.h + + shared/cleanup/DataCleanupManager.cpp + shared/cleanup/DataCleanupManager.h + shared/cleanup/TaskConsolidateExperience.cpp + shared/cleanup/TaskConsolidateExperience.h + shared/cleanup/TaskDailyCleanup.cpp + shared/cleanup/TaskDailyCleanup.h + shared/cleanup/TaskAnySQL.cpp + shared/cleanup/TaskAnySQL.h + shared/cleanup/TaskObjvarNameCleanup.cpp + shared/cleanup/TaskObjvarNameCleanup.h + shared/cleanup/TaskOrphanedObjectCleanup.cpp + shared/cleanup/TaskOrphanedObjectCleanup.h + shared/cleanup/TaskMarketAttributesCleanup.cpp + shared/cleanup/TaskMarketAttributesCleanup.h + shared/cleanup/TaskMessagesCleanup.cpp + shared/cleanup/TaskMessagesCleanup.h + shared/cleanup/TaskBrokenObjectCleanup.cpp + shared/cleanup/TaskBrokenObjectCleanup.h + shared/cleanup/TaskVendorObjectCleanup.cpp + shared/cleanup/TaskVendorObjectCleanup.h + shared/cleanup/TaskFixBadCells.cpp + shared/cleanup/TaskFixBadCells.h + shared/cleanup/TaskObjectTemplateListUpdater.cpp + shared/cleanup/TaskObjectTemplateListUpdater.h + + shared/core/CMLoader.cpp + shared/core/CMLoader.h + shared/core/FirstSwgDatabaseServer.h + shared/core/MiscPack.cpp + shared/core/ObjvarNameManager.cpp + shared/core/ObjvarNameManager.h + shared/core/CommoditiesSnapshot.cpp + shared/core/CommoditiesSnapshot.h + shared/core/SwgDatabaseServer.cpp + shared/core/SwgDatabaseServer.h + shared/core/SwgLoader.cpp + shared/core/SwgLoader.h + shared/core/SwgLoaderSnapshotGroup.cpp + shared/core/SwgLoaderSnapshotGroup.h + shared/core/SwgPersister.cpp + shared/core/SwgPersister.h + shared/core/SwgSnapshot.cpp + shared/core/SwgSnapshot.h + + shared/persistable/PersistableWaypoint.cpp + shared/persistable/PersistableWaypoint.h + + shared/queries/BattlefieldParticipantQuery.cpp + shared/queries/BattlefieldParticipantQuery.h + shared/queries/BountyHunterTargetQuery.cpp + shared/queries/BountyHunterTargetQuery.h + shared/queries/CommoditiesQuery.cpp + shared/queries/CommoditiesQuery.h + shared/queries/DeleteDemandLoadedContainerQuery.cpp + shared/queries/DeleteDemandLoadedContainerQuery.h + shared/queries/ExperienceQuery.cpp + shared/queries/ExperienceQuery.h + shared/queries/LocationQuery.cpp + shared/queries/LocationQuery.h + shared/queries/ManufactureSchematicAttributeQuery.cpp + shared/queries/ManufactureSchematicAttributeQuery.h + shared/queries/MessageQuery.cpp + shared/queries/MessageQuery.h + shared/queries/ObjectVariableQueries.cpp + shared/queries/ObjectVariableQueries.h + shared/queries/ObjectsTableQuery.cpp + shared/queries/ObjectsTableQuery.h + shared/queries/OfflineMoneyCustomPersistStep.cpp + shared/queries/OfflineMoneyCustomPersistStep.h + shared/queries/PropertyListQuery.cpp + shared/queries/PropertyListQuery.h + shared/queries/ResourceTypeQuery.cpp + shared/queries/ResourceTypeQuery.h + shared/queries/SkillQuery.cpp + shared/queries/SkillQuery.h + shared/queries/WaypointQuery.cpp + shared/queries/WaypointQuery.h + + shared/tasks/TaskGetAuctionAttributeList.cpp + shared/tasks/TaskGetAuctionAttributeList.h + shared/tasks/TaskGetAuctionList.cpp + shared/tasks/TaskGetAuctionList.h + shared/tasks/TaskGetBidList.cpp + shared/tasks/TaskGetBidList.h + shared/tasks/TaskGetCharacters.cpp + shared/tasks/TaskGetCharacters.h + shared/tasks/TaskGetLocationList.cpp + shared/tasks/TaskGetLocationList.h + shared/tasks/TaskLoadObjvarNames.cpp + shared/tasks/TaskLoadObjvarNames.h + shared/tasks/TaskLocateStructure.cpp + shared/tasks/TaskLocateStructure.h + shared/tasks/TaskMoveToPlayer.cpp + shared/tasks/TaskMoveToPlayer.h + shared/tasks/TaskRestoreCharacter.cpp + shared/tasks/TaskRestoreCharacter.h + shared/tasks/TaskRestoreHouse.cpp + shared/tasks/TaskRestoreHouse.h + shared/tasks/TaskSaveObjvarNames.cpp + shared/tasks/TaskSaveObjvarNames.h + shared/tasks/TaskUndeleteItem.cpp + shared/tasks/TaskUndeleteItem.h + shared/tasks/TaskVerifyCharacter.cpp + shared/tasks/TaskVerifyCharacter.h +) + +if(WIN32) + set(PLATFORM_SOURCES + win32/FirstSwgDatabaseServer.cpp + win32/WinMain.cpp + ) + + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/win32) +else() + set(PLATFORM_SOURCES + linux/main.cpp + ) + + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/linux) +endif() + +include_directories( + #${CMAKE_CURRENT_SOURCE_DIR}/shared/combat + #${CMAKE_CURRENT_SOURCE_DIR}/shared/core + #${CMAKE_CURRENT_SOURCE_DIR}/shared/lint + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCollision/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCommandParser/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedGame/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedImage/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedLog/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMathArchive/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMessageDispatch/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetwork/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetworkMessages/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedObject/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedPathfinding/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRandom/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRegex/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRemoteDebugServer/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedSkillSystem/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedTerrain/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedThread/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedUtility/include/public + #${SWG_ENGINE_SOURCE_DIR}/server/library/serverGame/include/public + #${SWG_ENGINE_SOURCE_DIR}/server/library/serverNetworkMessages/include/public + #${SWG_ENGINE_SOURCE_DIR}/server/library/serverPathfinding/include/public + #${SWG_ENGINE_SOURCE_DIR}/server/library/serverScript/include/public + #${SWG_ENGINE_SOURCE_DIR}/server/library/serverUtility/include/public + #${SWG_GAME_SOURCE_DIR}/shared/library/swgSharedNetworkMessages/include/public + #${SWG_GAME_SOURCE_DIR}/shared/library/swgSharedUtility/include/public + #${SWG_GAME_SOURCE_DIR}/server/library/swgServerNetworkMessages/include/public + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/fileInterface/include/public + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localization/include + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localizationArchive/include/public + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/singleton/include + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicodeArchive/include/public + #${Boost_INCLUDE_DIR} + #${JNI_INCLUDE_DIRS} +) + +link_directories(${STLPORT_LIBDIR}) + +add_executable(SwgDatabaseServer + ${SHARED_SOURCES} + ${PLATFORM_SOURCES} +) + +target_link_libraries(SwgDatabaseServer + #sharedCollision + #sharedCommandParser + #sharedCompression + #sharedDebug + #sharedFile + #sharedFractal + #sharedFoundation + #sharedGame + #sharedImage + #sharedLog + #sharedMath + #sharedMemoryManager + #sharedMessageDispatch + #sharedNetwork + #sharedNetworkMessages + #sharedObject + #sharedPathfinding + #sharedRandom + #sharedRegex + #sharedRemoteDebugServer + #sharedSkillSystem + #sharedSynchronization + #sharedTerrain + #sharedThread + #sharedUtility + #sharedXml + #serverGame + #serverMetrics + #serverNetworkMessages + #serverPathfinding + #serverScript + #serverUtility + #swgSharedNetworkMessages + #swgSharedUtility + #swgServerNetworkMessages + #archive + #fileInterface + #localization + #localizationArchive + #unicode + #unicodeArchive + #Base + #udplibrary + #${PCRE_LIBRARY} + #${LIBXML2_LIBRARY} + #${ZLIB_LIBRARY} +) + +if(WIN32) + target_link_libraries(SwgDatabaseServer mswsock ws2_32) +endif() diff --git a/game/server/application/SwgDatabaseServer/src/linux/main.cpp b/game/server/application/SwgDatabaseServer/src/linux/main.cpp new file mode 100644 index 00000000..9878eed1 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/linux/main.cpp @@ -0,0 +1,76 @@ +#include "FirstSwgDatabaseServer.h" + +#include "SwgDatabaseServer/SwgDatabaseServer.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFile/TreeFile.h" +#include "sharedFoundation/Os.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedLog/LogManager.h" +#include "sharedLog/SetupSharedLog.h" +#include "sharedNetwork/NetworkHandler.h" +#include "sharedNetwork/SetupSharedNetwork.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" + +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "swgSharedNetworkMessages/SetupSwgSharedNetworkMessages.h" +#include "swgServerNetworkMessages/SetupSwgServerNetworkMessages.h" + +// ====================================================================== + +void dumpPid(const char * argv) +{ + pid_t p = getpid(); + char fileName[1024]; + sprintf(fileName, "%s.%d", argv, p); + FILE * f = fopen(fileName, "w+"); + fclose(f); +} + +int main(int argc, char ** argv) +{ +// dumpPid(argv[0]); + + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + //-- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + setupFoundationData.lpCmdLine = ConvertCommandLine(argc,argv); + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedFile::install(false); + SetupSharedRandom::install(time(NULL)); + SetupSharedNetwork::SetupData networkSetupData; + SetupSharedNetwork::getDefaultServerSetupData(networkSetupData); + SetupSharedNetwork::install(networkSetupData); + + SetupSharedNetworkMessages::install(); + SetupSwgSharedNetworkMessages::install(); + SetupSwgServerNetworkMessages::install(); + + SetupSharedLog::install("SwgDatabaseServer"); + + TreeFile::addSearchAbsolute(0); + TreeFile::addSearchPath(".",0); + + //-- setup server + ConfigServerDatabase::install (); + + NetworkHandler::install(); + Os::setProgramName("SwgDatabaseServer"); + SwgDatabaseServer::install(); + + //-- run server + SwgDatabaseServer::getInstance().run(); + NetworkHandler::remove(); + SetupSharedLog::remove(); + + SetupSharedFoundation::remove(); + SetupSharedThread::remove(); + + return 0; +} diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/AuctionLocationsBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/AuctionLocationsBuffer.cpp new file mode 100644 index 00000000..c0baa227 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/AuctionLocationsBuffer.cpp @@ -0,0 +1,180 @@ +// ====================================================================== +// +// AuctionLocationsBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/AuctionLocationsBuffer.h" +#include "SwgDatabaseServer/CommoditiesQuery.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include + +// ====================================================================== + +AuctionLocationsBuffer::AuctionLocationsBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer(), + m_mode(mode), + m_rows() +{ +} + +// ---------------------------------------------------------------------- + +AuctionLocationsBuffer::~AuctionLocationsBuffer(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +bool AuctionLocationsBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + return true; +} + +// ---------------------------------------------------------------------- + +void AuctionLocationsBuffer::removeObject(const NetworkId &object) +{ + removeAuctionLocations(object); +} + +// ---------------------------------------------------------------------- + +void AuctionLocationsBuffer::removeAuctionLocations(const NetworkId &locationId) +{ + IndexType::iterator i=m_rows.find(locationId); + if (i!=m_rows.end()) + { + delete i->second; + i->second=NULL; + m_rows.erase(i); + } +} + +// ---------------------------------------------------------------------- + +void AuctionLocationsBuffer::setAuctionLocations(const NetworkId &locationId) +{ + DBSchema::AuctionLocationsRow *row=findRowByIndex(locationId); + if (!row) + { + row=new DBSchema::AuctionLocationsRow; + addRowToIndex(locationId, row); + } + row->location_id = locationId; +} + +// ---------------------------------------------------------------------- + +void AuctionLocationsBuffer::setAuctionLocations(const NetworkId &locationId, const std::string &locationName, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge) +{ + DBSchema::AuctionLocationsRow *row=findRowByIndex(locationId); + if (!row) + { + row=new DBSchema::AuctionLocationsRow; + addRowToIndex(locationId, row); + } + row->location_id = locationId; + row->location_name = locationName; + row->sales_tax = salesTax; + row->sales_tax_bank_id = salesTaxBankId; + row->empty_date = emptyDate; + row->last_access_date = lastAccessDate; + row->inactive_date = inactiveDate; + row->status = status; + row->search_enabled = searchEnabled; + row->entrance_charge = entranceCharge; +} + +// ---------------------------------------------------------------------- + +void AuctionLocationsBuffer::setAuctionLocations(const NetworkId &locationId, const std::string &locationName, const NetworkId &ownerId, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge) +{ + DBSchema::AuctionLocationsRow *row=findRowByIndex(locationId); + if (!row) + { + row=new DBSchema::AuctionLocationsRow; + addRowToIndex(locationId, row); + } + row->location_id = locationId; + row->location_name = locationName; + row->owner_id = ownerId; + row->sales_tax = salesTax; + row->sales_tax_bank_id = salesTaxBankId; + row->empty_date = emptyDate; + row->last_access_date = lastAccessDate; + row->inactive_date = inactiveDate; + row->status = status; + row->search_enabled = searchEnabled; + row->entrance_charge = entranceCharge; +} + +// ---------------------------------------------------------------------- + +DBSchema::AuctionLocationsRow * AuctionLocationsBuffer::findRowByIndex(const NetworkId &locationId) +{ + IndexType::iterator i=m_rows.find(locationId); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void AuctionLocationsBuffer::addRowToIndex (const NetworkId &locationId, DBSchema::AuctionLocationsRow *row) +{ + m_rows[locationId]=row; +} + +// ---------------------------------------------------------------------- + +bool AuctionLocationsBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("AuctionLocations: %i saved to db",m_rows.size())); + DEBUG_REPORT_LOG(true, ("Saving Auctions Locations Buffer. mode:%d rowcount:%d\n", m_mode, m_rows.size())); + + DBQuery::AuctionLocationsQuery qry; + + if (m_mode==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else if (m_mode == DB::ModeQuery::mode_UPDATE) + qry.updateMode(); + else + qry.deleteMode(); + if (!qry.setupData(session)) + return false; + + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + if (!qry.addData(i->second)) + return false; + if (qry.getNumItems() >= AuctionLocationsTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + return true; + +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/AuctionLocationsBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/AuctionLocationsBuffer.h new file mode 100644 index 00000000..6f2f8e16 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/AuctionLocationsBuffer.h @@ -0,0 +1,65 @@ +// ====================================================================== +// +// AuctionLocationsBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_AuctionLocationsBuffer_H +#define INCLUDED_AuctionLocationsBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/CommoditiesQuery.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" +#include "serverDatabase/AbstractTableBuffer.h" +#include +#include + +// ====================================================================== + +namespace AuctionLocationsTableBufferNamespace +{ + const int ms_maxItemsPerExec = 10000; +} + +using namespace AuctionLocationsTableBufferNamespace; + +// ====================================================================== + +class AuctionLocationsBuffer : public AbstractTableBuffer +{ +public: + explicit AuctionLocationsBuffer (DB::ModeQuery::Mode mode); + virtual ~AuctionLocationsBuffer (); + + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + + DBSchema::AuctionLocationsRow * findRowByIndex (const NetworkId &locationId); + + void setAuctionLocations (const NetworkId &locationId); + void setAuctionLocations (const NetworkId &locationId, const std::string &locationName, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge); + void setAuctionLocations (const NetworkId &locationId, const std::string &locationName, const NetworkId &ownerId, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge); + void removeAuctionLocations (const NetworkId &locationId); + virtual void removeObject (const NetworkId &object); + + private: + void addRowToIndex (const NetworkId &locationId, DBSchema::AuctionLocationsRow *row); + + private: + + typedef std::map IndexType; + + DB::ModeQuery::Mode m_mode; + IndexType m_rows; + + private: + AuctionLocationsBuffer(); //disable + AuctionLocationsBuffer(const AuctionLocationsBuffer&); //disable + AuctionLocationsBuffer & operator=(const AuctionLocationsBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/BattlefieldParticipantBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/BattlefieldParticipantBuffer.cpp new file mode 100644 index 00000000..7abc8164 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/BattlefieldParticipantBuffer.cpp @@ -0,0 +1,165 @@ +// ====================================================================== +// +// BattlefieldParticipantBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/BattlefieldParticipantBuffer.h" + +#include "SwgDatabaseServer/BattlefieldParticipantQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +BattlefieldParticipantBuffer::BattlefieldParticipantBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer(), + m_rows(), + m_mode(mode) +{ +} + +// ---------------------------------------------------------------------- + +BattlefieldParticipantBuffer::~BattlefieldParticipantBuffer(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +void BattlefieldParticipantBuffer::setParticipantForRegion(const NetworkId ®ionObjectId, const NetworkId &characterObjectId, uint32 factionId) +{ + DBSchema::BattlefieldParticipantRow *row=findRowByIndex(regionObjectId,characterObjectId); + if (!row) + { + row=new DBSchema::BattlefieldParticipantRow; + addRowToIndex(regionObjectId,characterObjectId,row); + } + row->region_object_id = regionObjectId; + row->character_object_id = characterObjectId; + row->faction_id = static_cast(factionId); +} + +// ---------------------------------------------------------------------- + +bool BattlefieldParticipantBuffer::getParticipantsForRegion(const NetworkId &objectId, std::vector > &values) const +{ + DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getBattlefieldParticipantForRegion()\n")); + IndexType::const_iterator i ( m_rows.lower_bound(IndexKey(objectId,NetworkId::cms_invalid)) ); + if (i==m_rows.end()) + return false; + for (; (i!=m_rows.end()) && (((*i).second)->region_object_id.getValue()==objectId); ++i) + { + NetworkId temp; + (*i).second->character_object_id.getValue(temp); + values.push_back(std::pair(temp, static_cast((*i).second->faction_id.getValue()))); + } + return true; +} + +// ---------------------------------------------------------------------- + +DBSchema::BattlefieldParticipantRow * BattlefieldParticipantBuffer::findRowByIndex(const NetworkId ®ionObjectId, const NetworkId &characterObjectId) +{ + IndexType::iterator i=m_rows.find(IndexKey(regionObjectId,characterObjectId)); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void BattlefieldParticipantBuffer::addRowToIndex (const NetworkId ®ionObjectId, const NetworkId &characterObjectId, DBSchema::BattlefieldParticipantRow *row) +{ + m_rows[IndexKey(regionObjectId,characterObjectId)]=row; +} + +// ---------------------------------------------------------------------- + +/** + * Load the attributes for all the remembered objectId's. + */ +bool BattlefieldParticipantBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched = 0; + if (tags.find(static_cast(ServerBattlefieldMarkerObjectTemplate::ServerBattlefieldMarkerObjectTemplate_tag)) != tags.end()) + { + DBQuery::GetAllBattlefieldParticipant qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + DBSchema::BattlefieldParticipantRow *row=new DBSchema::BattlefieldParticipantRow(*i); + NOT_NULL(row); + NetworkId temp; + row->character_object_id.getValue(temp); + addRowToIndex(row->region_object_id.getValue(),temp,row); + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +bool BattlefieldParticipantBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("BattlefieldParticipants: %i saved to db",m_rows.size())); + + DBQuery::BattlefieldParticipantQuery qry; + + if (m_mode==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else + qry.updateMode(); + + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + qry.setData(*(i->second)); + if (! (session->exec(&qry))) + return false; + } + qry.done(); + return true; +} + +// ---------------------------------------------------------------------- + +void BattlefieldParticipantBuffer::removeObject(const NetworkId &object) +{ + IndexType::iterator i=m_rows.lower_bound(IndexKey(object,NetworkId::cms_invalid)); + while (i!=m_rows.end() && i->first.m_regionObjectId==object) + { + IndexType::iterator next=i; + ++next; + delete i->second; + i->second=NULL; + m_rows.erase(i); + i=next; + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/BattlefieldParticipantBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/BattlefieldParticipantBuffer.h new file mode 100644 index 00000000..8f17e14d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/BattlefieldParticipantBuffer.h @@ -0,0 +1,102 @@ +// ====================================================================== +// +// BattlefieldParticipantBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_BattlefieldParticipantBuffer_H +#define INCLUDED_BattlefieldParticipantBuffer_H + +// ====================================================================== + +#include +#include +#include "serverDatabase/TableBuffer.h" +#include "SwgDatabaseServer/BattlefieldParticipantQuery.h" +#include "SwgDatabaseServer/Schema.h" + +// ====================================================================== + +class BattlefieldParticipantBuffer : public AbstractTableBuffer +{ +public: + explicit BattlefieldParticipantBuffer (DB::ModeQuery::Mode mode); + virtual ~BattlefieldParticipantBuffer (); + + virtual bool load (DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save (DB::Session *session); + virtual void removeObject (const NetworkId &object); + + DBSchema::BattlefieldParticipantRow * findRowByIndex (const NetworkId ®ionObjectId, const NetworkId &characterObjectId); + + void setParticipantForRegion (const NetworkId ®ionObjectId, const NetworkId &characterObjectId, uint32 factionId); + void removeParticipantForRegion (const NetworkId ®ionObjectId, const NetworkId &characterObjectId); + bool getParticipantsForRegion (const NetworkId ®ionObjectId, std::vector > &values) const; + +private: + void addRowToIndex (const NetworkId ®ionObjectId, const NetworkId &characterObjectId, DBSchema::BattlefieldParticipantRow *row); + +private: + struct IndexKey + { + NetworkId m_regionObjectId; + NetworkId m_characterObjectId; + + IndexKey(const NetworkId ®ionObjectId, const NetworkId &characterObjectId); + bool operator==(const IndexKey &rhs) const; + }; + struct IndexSorter + { + bool operator() (const IndexKey &left, const IndexKey &right) const; + }; + + typedef std::map IndexType; + IndexType m_rows; + DB::ModeQuery::Mode m_mode; + + private: + BattlefieldParticipantBuffer(); //disable + BattlefieldParticipantBuffer(const BattlefieldParticipantBuffer&); //disable + BattlefieldParticipantBuffer & operator=(const BattlefieldParticipantBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +inline BattlefieldParticipantBuffer::IndexKey::IndexKey(const NetworkId ®ionObjectId, const NetworkId &characterObjectId) : + m_regionObjectId(regionObjectId), + m_characterObjectId(characterObjectId) +{ +} + +// ---------------------------------------------------------------------- + +inline bool BattlefieldParticipantBuffer::IndexKey::operator==(const IndexKey &rhs) const +{ + return ((m_regionObjectId == rhs.m_regionObjectId) && (m_characterObjectId == rhs.m_characterObjectId)); +} + +// ---------------------------------------------------------------------- + +inline bool BattlefieldParticipantBuffer::IndexSorter::operator() (const IndexKey &left, const IndexKey &right) const +{ + if (left.m_regionObjectId == right.m_regionObjectId) + return (left.m_characterObjectId < right.m_characterObjectId); + else + return (left.m_regionObjectId < right.m_regionObjectId); +} + +// ---------------------------------------------------------------------- + +/** + * Removing a battlefield participant is the same as setting it to 0. (The database package + * will delete the row if faction_id == 0.) + */ +inline void BattlefieldParticipantBuffer::removeParticipantForRegion(const NetworkId ®ionObjectId, const NetworkId &characterObjectId) +{ + setParticipantForRegion(regionObjectId,characterObjectId,0); +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/BountyHunterTargetBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/BountyHunterTargetBuffer.cpp new file mode 100644 index 00000000..4098e2c3 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/BountyHunterTargetBuffer.cpp @@ -0,0 +1,184 @@ +// ====================================================================== +// +// BountyHunterTargetBuffer.cpp +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/BountyHunterTargetBuffer.h" + +#include "SwgDatabaseServer/BountyHunterTargetQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/GameServerConnection.h" +#include "serverGame/ServerPlanetObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +BountyHunterTargetBuffer::BountyHunterTargetBuffer() : + AbstractTableBuffer(), + m_data() +{ +} + +// ---------------------------------------------------------------------- + +BountyHunterTargetBuffer::~BountyHunterTargetBuffer() +{ + for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetBuffer::setBountyHunterTarget(const NetworkId &objectId, const NetworkId &targetId) +{ + DBSchema::BountyHunterTargetRow *row=findRowByIndex(objectId); + if (!row) + { + row=new DBSchema::BountyHunterTargetRow; + addRowToIndex(objectId, row); + } + row->object_id = objectId; + row->target_id = targetId; +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetBuffer::sendBountyHunterTargetMessage(GameServerConnection & conn) const +{ + if (m_data.empty()) + return; + + std::vector< std::pair< NetworkId, NetworkId > > targetList; + + for (DataType::const_iterator row = m_data.begin(); row != m_data.end(); ++row) + { + NOT_NULL(row->second); + + NetworkId objectId; + NetworkId targetId; + row->second->object_id.getValue(objectId); + row->second->target_id.getValue(targetId); + targetList.push_back(std::make_pair(objectId, targetId)); + } + + DEBUG_REPORT_LOG(true,("Sending BountyHunterTargetsList\n")); + BountyHunterTargetListMessage msg(targetList); + conn.send(msg,true); +} + +// ---------------------------------------------------------------------- + +DBSchema::BountyHunterTargetRow * BountyHunterTargetBuffer::findRowByIndex(const NetworkId &objectId) +{ + DataType::iterator i=m_data.find(objectId); + if (i==m_data.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetBuffer::addRowToIndex (const NetworkId &objectId, DBSchema::BountyHunterTargetRow *row) +{ + m_data[objectId]=row; +} + +// ---------------------------------------------------------------------- + +bool BountyHunterTargetBuffer::save(DB::Session *session) +{ + bool rval = true; + if (m_data.empty()) + return true; + + int actualSaves=0; + DBQuery::BountyHunterTargetQuery qry; + if (!qry.setupData(session)) + return false; + + for (DataType::const_iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + ++actualSaves; + NOT_NULL(i->second); + if (!qry.addData(*(i->second))) + return false; + + if (qry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize()) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + + if (qry.getNumItems() != 0) + rval = session->exec(&qry); + + qry.done(); + qry.freeData(); + + LOG("SaveCounts",("BountyHunterTargets: %i saved in db",actualSaves)); + return rval; +} + +// ---------------------------------------------------------------------- + +bool BountyHunterTargetBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + int rowsFetched = 0; + // Only load Bounty Hunter Target data if the planets are being loaded + if (tags.find(ServerPlanetObjectTemplate::ServerPlanetObjectTemplate_tag)!=tags.end()) + { + DEBUG_REPORT_LOG(true,("Loading BountyHunterTargets\n")); + DBQuery::BountyHunterTargetQuerySelect qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t const numRows = qry.getNumRowsFetched(); + size_t count = 0; + std::vector const & data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + DBSchema::BountyHunterTargetRow *row=new DBSchema::BountyHunterTargetRow(*i); + NOT_NULL(row); + NetworkId temp; + row->object_id.getValue(temp); + m_data.insert(std::make_pair(row->object_id.getValue(), row)); + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetBuffer::removeObject(const NetworkId &object) +{ + DBSchema::BountyHunterTargetRow *row=findRowByIndex(object); + if (row) + { + const NetworkId zeroNetworkId(static_cast(0)); + row->object_id = object; + row->target_id = zeroNetworkId; + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/BountyHunterTargetBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/BountyHunterTargetBuffer.h new file mode 100644 index 00000000..f84a25b3 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/BountyHunterTargetBuffer.h @@ -0,0 +1,59 @@ +// ====================================================================== +// +// BountyHunterTargetBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_BountyHunterTargetBuffer_H +#define INCLUDED_BountyHunterTargetBuffer_H + +// ====================================================================== + +#include "serverDatabase/AbstractTableBuffer.h" +#include "serverNetworkMessages/BountyHunterTargetListMessage.h" +#include "serverNetworkMessages/BountyHunterTargetMessage.h" + +// ====================================================================== + +namespace DB +{ + class Session; +} + +namespace DBSchema +{ + struct BountyHunterTargetRow; +} + +class GameServerConnection; + +// ====================================================================== + +/** + * A buffer to hold bounty hunter target data. + */ +class BountyHunterTargetBuffer : public AbstractTableBuffer +{ + public: + void setBountyHunterTarget (const NetworkId &objectId, const NetworkId &targetId); + void sendBountyHunterTargetMessage (GameServerConnection & conn) const; + + virtual bool save(DB::Session *session); + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual void removeObject(const NetworkId &object); + DBSchema::BountyHunterTargetRow * findRowByIndex (const NetworkId &objectId); + + public: + BountyHunterTargetBuffer(); + virtual ~BountyHunterTargetBuffer(); + + private: + void addRowToIndex (const NetworkId &objectId, DBSchema::BountyHunterTargetRow *row); + typedef std::map DataType; + DataType m_data; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/CreatureObjectBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/CreatureObjectBuffer.cpp new file mode 100644 index 00000000..10556590 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/CreatureObjectBuffer.cpp @@ -0,0 +1,249 @@ +// ====================================================================== +// +// CreatureObjectBuffer.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/CreatureObjectBuffer.h" +#include "serverNetworkMessages/UpdateObjectPositionMessage.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +CreatureObjectBuffer::CreatureObjectBuffer(DB::ModeQuery::Mode mode) : + IndexedNetworkTableBuffer(mode) +{ +} + + +// ---------------------------------------------------------------------- + +bool CreatureObjectBuffer::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message) +{ + + DBSchema::CreatureObjectBufferRow *row=dynamic_cast(findRowByIndex(message.getNetworkId())); + if (row==0) + { + row=addEmptyRow(message.getNetworkId()); + } + + Vector v = message.getWorldspaceTransform().getPosition_p(); + row->ws_x = static_cast(v.x); + row->ws_y = static_cast(v.y); + row->ws_z = static_cast(v.z); + + return true; +} + + +// ---------------------------------------------------------------------- + +void CreatureObjectBuffer::setAttribute(const NetworkId &objectId, Attributes::Enumerator type, Attributes::Value value) +{ + DBSchema::CreatureObjectBufferRow *row=dynamic_cast(findRowByIndex(objectId)); + if (row==0) + { + row=addEmptyRow(objectId); + } + + switch (type) + { + case 0: + row->attribute_0=value; + break; + case 1: + row->attribute_1=value; + break; + case 2: + row->attribute_2=value; + break; + case 3: + row->attribute_3=value; + break; + case 4: + row->attribute_4=value; + break; + case 5: + row->attribute_5=value; + break; + case 6: + row->attribute_6=value; + break; + case 7: + row->attribute_7=value; + break; + case 8: + row->attribute_8=value; + break; + case 9: + row->attribute_9=value; + break; + case 10: + row->attribute_10=value; + break; + case 11: + row->attribute_11=value; + break; + case 12: + row->attribute_12=value; + break; + case 13: + row->attribute_13=value; + break; + case 14: + row->attribute_14=value; + break; + case 15: + row->attribute_15=value; + break; + case 16: + row->attribute_16=value; + break; + case 17: + row->attribute_17=value; + break; + case 18: + row->attribute_18=value; + break; + case 19: + row->attribute_19=value; + break; + case 20: + row->attribute_20=value; + break; + case 21: + row->attribute_21=value; + break; + case 22: + row->attribute_22=value; + break; + case 23: + row->attribute_23=value; + break; + case 24: + row->attribute_24=value; + break; + case 25: + row->attribute_25=value; + break; + case 26: + row->attribute_26=value; + break; + + default: + WARNING_STRICT_FATAL(true,("Programmer bug: setAttribute(%s, %i, %i): %i is not a valid attribute identifier",objectId.getValueString().c_str(), type, value, type)); + } +} + +// ---------------------------------------------------------------------- + +/** + * Retreive a range of attributes for an object + */ +void CreatureObjectBuffer::getAttributesForObject(const NetworkId &objectId, std::vector &values, int offset, int howMany) const +{ + const DBSchema::CreatureObjectBufferRow *row=dynamic_cast(findConstRowByIndex(objectId)); + + for (int position=offset; positionattribute_0.getValue(value); + break; + case 1: + row->attribute_1.getValue(value); + break; + case 2: + row->attribute_2.getValue(value); + break; + case 3: + row->attribute_3.getValue(value); + break; + case 4: + row->attribute_4.getValue(value); + break; + case 5: + row->attribute_5.getValue(value); + break; + case 6: + row->attribute_6.getValue(value); + break; + case 7: + row->attribute_7.getValue(value); + break; + case 8: + row->attribute_8.getValue(value); + break; + case 9: + row->attribute_9.getValue(value); + break; + case 10: + row->attribute_10.getValue(value); + break; + case 11: + row->attribute_11.getValue(value); + break; + case 12: + row->attribute_12.getValue(value); + break; + case 13: + row->attribute_13.getValue(value); + break; + case 14: + row->attribute_14.getValue(value); + break; + case 15: + row->attribute_15.getValue(value); + break; + case 16: + row->attribute_16.getValue(value); + break; + case 17: + row->attribute_17.getValue(value); + break; + case 18: + row->attribute_18.getValue(value); + break; + case 19: + row->attribute_19.getValue(value); + break; + case 20: + row->attribute_20.getValue(value); + break; + case 21: + row->attribute_21.getValue(value); + break; + case 22: + row->attribute_22.getValue(value); + break; + case 23: + row->attribute_23.getValue(value); + break; + case 24: + row->attribute_24.getValue(value); + break; + case 25: + row->attribute_25.getValue(value); + break; + case 26: + row->attribute_26.getValue(value); + break; + + default: + FATAL(true,("Programmer bug: getAttributesForObject(%s, &values, %i, %i): attempted to read attribute %i, which is out of range",objectId.getValueString().c_str(),offset, howMany, position)); + } + if (value == -999) + { + WARNING(true,("Object %s had null attribute %i, defaulting to 100",objectId.getValueString().c_str(), position)); + value = 100; + } + + values.push_back(static_cast(value)); + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/CreatureObjectBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/CreatureObjectBuffer.h new file mode 100644 index 00000000..ac8e786d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/CreatureObjectBuffer.h @@ -0,0 +1,35 @@ +// ====================================================================== +// +// CreatureObjectBuffer.h +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_CreatureObjectBuffer_H +#define INCLUDED_CreatureObjectBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/IndexedNetworkTableBuffer.h" +#include "SwgDatabaseServer/ObjectQueries.h" +#include "SwgDatabaseServer/Schema.h" +#include "swgSharedUtility/Attributes.def" + +class UpdateObjectPositionMessage; + +// ====================================================================== + +class CreatureObjectBuffer : public IndexedNetworkTableBuffer +{ + public: + CreatureObjectBuffer(DB::ModeQuery::Mode mode); + + void setAttribute(const NetworkId &objectId, Attributes::Enumerator type, Attributes::Value value); + void getAttributesForObject (const NetworkId &objectId, std::vector &values, int offset, int howMany) const; + + virtual bool handleUpdateObjectPosition(const UpdateObjectPositionMessage &message); +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ExperienceBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ExperienceBuffer.cpp new file mode 100644 index 00000000..5c361b16 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ExperienceBuffer.cpp @@ -0,0 +1,166 @@ +// ====================================================================== +// +// ExperienceBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/ExperienceBuffer.h" + +#include "SwgDatabaseServer/ExperienceQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include + +// ====================================================================== + +ExperienceBuffer::ExperienceBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer(), + m_mode(mode), + m_rows() +{ +} + +// ---------------------------------------------------------------------- + +ExperienceBuffer::~ExperienceBuffer(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +void ExperienceBuffer::setExperience(const NetworkId &objectId, const std::string &experienceType, int value) +{ + DBSchema::ExperiencePointRow *row=findRowByIndex(objectId,experienceType); + if (!row) + { + row=new DBSchema::ExperiencePointRow; + addRowToIndex(objectId,experienceType,row); + } + row->object_id = objectId; + row->experience_type=experienceType; + row->points = value; +} + +// ---------------------------------------------------------------------- + +bool ExperienceBuffer::getExperienceForObject(const NetworkId &objectId, std::vector > &values) const +{ + DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getExperienceForObject()\n")); + IndexType::const_iterator i ( m_rows.lower_bound(IndexKey(objectId,"")) ); + if (i==m_rows.end()) + return false; + for (; (i!=m_rows.end()) && (((*i).second)->object_id.getValue()==objectId); ++i) + { + std::string temp; + (*i).second->experience_type.getValue(temp); + values.push_back(std::pair(temp, (*i).second->points.getValue())); + } + return true; +} + +// ---------------------------------------------------------------------- + +DBSchema::ExperiencePointRow * ExperienceBuffer::findRowByIndex(const NetworkId &objectId, const std::string &experienceType) +{ + IndexType::iterator i=m_rows.find(IndexKey(objectId,experienceType)); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void ExperienceBuffer::addRowToIndex (const NetworkId &objectId, const std::string &experienceType, DBSchema::ExperiencePointRow *row) +{ + m_rows[IndexKey(objectId,experienceType)]=row; +} + +// ---------------------------------------------------------------------- + +/** + * Load the attributes for all the remembered objectId's. + */ +bool ExperienceBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched = 0; + if (tags.find(static_cast(ServerPlayerObjectTemplate::ServerPlayerObjectTemplate_tag)) != tags.end()) + { + DBQuery::GetAllExperience qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + DBSchema::ExperiencePointRow *row=new DBSchema::ExperiencePointRow(*i); + NOT_NULL(row); + std::string temp; + row->experience_type.getValue(temp); + addRowToIndex(row->object_id.getValue(),temp,row); + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +bool ExperienceBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("Experience: %i saved to db",m_rows.size())); + + DBQuery::ExperienceQuery qry; + + if (m_mode==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else + qry.updateMode(); + + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + qry.setData(*(i->second)); + if (! (session->exec(&qry))) + return false; + } + qry.done(); + return true; +} + +// ---------------------------------------------------------------------- + +void ExperienceBuffer::removeObject(const NetworkId &object) +{ + IndexType::iterator i=m_rows.lower_bound(IndexKey(object,"")); + while (i!=m_rows.end() && i->first.m_objectId==object) + { + IndexType::iterator next=i; + ++next; + delete i->second; + i->second=NULL; + m_rows.erase(i); + i=next; + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ExperienceBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ExperienceBuffer.h new file mode 100644 index 00000000..855f1ee5 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ExperienceBuffer.h @@ -0,0 +1,102 @@ +// ====================================================================== +// +// ExperienceBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ExperienceBuffer_H +#define INCLUDED_ExperienceBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/ExperienceQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/AbstractTableBuffer.h" +#include +#include + +// ====================================================================== + +class ExperienceBuffer : public AbstractTableBuffer +{ +public: + explicit ExperienceBuffer (DB::ModeQuery::Mode mode); + virtual ~ExperienceBuffer (); + + virtual bool load (DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save (DB::Session *session); + virtual void removeObject (const NetworkId &object); + + DBSchema::ExperiencePointRow * findRowByIndex (const NetworkId &objectId, const std::string &experienceType); + + void setExperience (const NetworkId &objectId, const std::string &experienceType, int value); + void removeExperience (const NetworkId &objectId, std::string experienceType); + bool getExperienceForObject (const NetworkId &objectId, stdvector >::fwd &values) const; + + private: + void addRowToIndex (const NetworkId &objectId, const std::string &experienceType, DBSchema::ExperiencePointRow *row); + + private: + struct IndexKey + { + NetworkId m_objectId; + std::string m_experienceType; + + IndexKey(NetworkId objectId, std::string experienceType); + bool operator==(const IndexKey &rhs) const; + }; + struct IndexSorter + { + bool operator() (const IndexKey &left, const IndexKey &right) const; + }; + typedef std::map IndexType; + + DB::ModeQuery::Mode m_mode; + IndexType m_rows; + + private: + ExperienceBuffer(); //disable + ExperienceBuffer(const ExperienceBuffer&); //disable + ExperienceBuffer & operator=(const ExperienceBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +inline ExperienceBuffer::IndexKey::IndexKey(NetworkId objectId, std::string experienceType) : + m_objectId(objectId), + m_experienceType(experienceType) +{ +} + +// ---------------------------------------------------------------------- + +inline bool ExperienceBuffer::IndexKey::operator==(const IndexKey &rhs) const +{ + return ((m_objectId == rhs.m_objectId) && (m_experienceType == rhs.m_experienceType)); +} + +// ---------------------------------------------------------------------- + +inline bool ExperienceBuffer::IndexSorter::operator() (const IndexKey &left, const IndexKey &right) const +{ + if (left.m_objectId == right.m_objectId) + return (left.m_experienceType < right.m_experienceType); + else + return (left.m_objectId < right.m_objectId); +} + +// ---------------------------------------------------------------------- + +/** + * Removing experience is the same as setting it to 0. (The database package + * will delete the row if points == 0.) + */ +inline void ExperienceBuffer::removeExperience(const NetworkId &objectId, std::string experienceType) +{ + setExperience(objectId,experienceType,0); +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedNetworkTableBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedNetworkTableBuffer.cpp new file mode 100644 index 00000000..aa82669a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedNetworkTableBuffer.cpp @@ -0,0 +1,11 @@ +// ====================================================================== +// +// IndexedNetworkTableBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "IndexedNetworkTableBuffer.h" + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedNetworkTableBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedNetworkTableBuffer.h new file mode 100644 index 00000000..5180b92a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedNetworkTableBuffer.h @@ -0,0 +1,270 @@ +// ====================================================================== +// +// IndexedNetworkTableBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_IndexedNetworkTableBuffer_H +#define INCLUDED_IndexedNetworkTableBuffer_H + +// ====================================================================== + +#include "serverDatabase/AbstractTableBuffer.h" +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedFoundation/NetworkId.h" +#include +#include +#include + +// ====================================================================== + +namespace IndexedNetworkTableBufferNamespace +{ + const int ms_maxItemsPerExec = 10000; +} + +using namespace IndexedNetworkTableBufferNamespace; + + +/** + * A TableBuffer organized to track data by objects, one row per object. + * + * @todo: Rename the class. Name makes no sense anymore. Un-templatize. + */ + +template +class IndexedNetworkTableBuffer : public AbstractTableBuffer +{ + public: + explicit IndexedNetworkTableBuffer(DB::ModeQuery::Mode mode); + ~IndexedNetworkTableBuffer(); + + public: + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + + BUFFERROW *findRowByIndex(const NetworkId &indexValue); + const BUFFERROW *findConstRowByIndex(const NetworkId &indexValue) const; + + BUFFERROW *addEmptyRow(const NetworkId &indexValue); + virtual void removeObject(const NetworkId &object); + DB::ModeQuery::Mode getMode(void) const; + + void addTag(Tag tag); + + static int getRowsCreated() { return m_sRowsCreated; } + static int getRowsDeleted() { return m_sRowsDeleted; } + static int getRowsActive() + { + int i_retval = m_sRowsCreated - m_sRowsDeleted; + if ( i_retval < 0 ) + return 0; + return i_retval; + } + + protected: + typedef std::map IndexType; + IndexType m_rows; + + private: + DB::ModeQuery::Mode m_mode; + DB::TagSet m_relevantTags; + + private: + void addRow(const NetworkId &indexValue,BUFFERROW *row); + static volatile int m_sRowsCreated; + static volatile int m_sRowsDeleted; + + private: + IndexedNetworkTableBuffer(); // disable +}; + +template volatile int IndexedNetworkTableBuffer::m_sRowsCreated = 0; +template volatile int IndexedNetworkTableBuffer::m_sRowsDeleted = 0; + +// ====================================================================== + +template +IndexedNetworkTableBuffer::IndexedNetworkTableBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer(), + m_rows(), + m_mode(mode) +{ +} + +// ---------------------------------------------------------------------- + +template +IndexedNetworkTableBuffer::~IndexedNetworkTableBuffer() +{ + for (typename IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + ++m_sRowsDeleted; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +template +void IndexedNetworkTableBuffer::addRow(const NetworkId &indexValue,BUFFERROW *row) +{ + m_rows[indexValue]=row; + ++m_sRowsCreated; +} + +// ---------------------------------------------------------------------- + +template +BUFFERROW *IndexedNetworkTableBuffer::findRowByIndex(const NetworkId &indexValue) +{ + typename IndexType::iterator i=m_rows.find(indexValue); + if (i==m_rows.end()) + return 0; + else + return i->second; +} + +// ---------------------------------------------------------------------- + +template +const BUFFERROW *IndexedNetworkTableBuffer::findConstRowByIndex(const NetworkId &indexValue) const +{ + typename IndexType::const_iterator i=m_rows.find(indexValue); + if (i==m_rows.end()) + return 0; + else + return i->second; +} + +// ---------------------------------------------------------------------- + +template +BUFFERROW *IndexedNetworkTableBuffer::addEmptyRow(const NetworkId &indexValue) +{ + BUFFERROW *row=new BUFFERROW; + row->setPrimaryKey(indexValue); + addRow(indexValue,row); + return row; +} + +// ---------------------------------------------------------------------- + +template +void IndexedNetworkTableBuffer::removeObject(const NetworkId &object) +{ + typename IndexType::iterator i=m_rows.find(object); + if (i!=m_rows.end()) + { + delete i->second; + ++m_sRowsDeleted; + i->second=NULL; + m_rows.erase(i); + } +} + +// ---------------------------------------------------------------------- + +template +DB::ModeQuery::Mode IndexedNetworkTableBuffer::getMode(void) const +{ + return m_mode; +} + +// ---------------------------------------------------------------------- + +template +bool IndexedNetworkTableBuffer::save(DB::Session *session) +{ + QUERY qry; + + if (getMode()==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else + qry.updateMode(); + + if (!qry.setupData(session)) + return false; + + for (typename IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + if (!qry.addData((i->second))) + return false; + if (qry.getNumItems() == IndexedNetworkTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + qry.done(); + qry.freeData(); + return true; +} + +// ---------------------------------------------------------------------- + +/** + * Load rows into the buffer from the database. + * + * The query is assumed to return 0 or more rows, which will be placed + * in the buffer. The virtual addRow function is used to make sure indexes, + * etc., are updated as needed. + */ +template +bool IndexedNetworkTableBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched = 0; + if (m_relevantTags.empty() || hasCommonTags(m_relevantTags, tags)) + { + SELECTQUERY qry(schema); + + FATAL (getMode()!=DB::ModeQuery::mode_SELECT,("load() was invoked on a TableBuffer that was not in tbm_select mode.")); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + int numRows = qry.getNumRowsFetched(); + int count = 0; + + const std::vector &data = qry.getData(); + + for (typename std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + BUFFERROW *newRow=new BUFFERROW(*i); + addRow(newRow->getPrimaryKey(),newRow); + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +/** + * Add a tag to the list we are interested in. If the current snapshot + * contains no objects with tags in this list, this buffer will skip its + * load. (Exception: If no tags are registered at all, the load will + * always happen.) + */ +template +void IndexedNetworkTableBuffer::addTag(Tag tag) +{ + m_relevantTags.insert(tag); +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedTableBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedTableBuffer.h new file mode 100644 index 00000000..f22b5754 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/IndexedTableBuffer.h @@ -0,0 +1,54 @@ +#if 0 //@todo code reorg +// ====================================================================== +// +// IndexedNetworkTableBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_IndexedNetworkTableBuffer_H +#define INCLUDED_IndexedNetworkTableBuffer_H + +// ====================================================================== + +#include +#include "serverDatabase/TableBuffer.h" + +// ====================================================================== + +/** + * Adds to NetworkTableBuffer the ability to retrieve rows based on an + * integer index. + * @todo Remove "Network" from the name because it no longer has anything to + * do with the network. + * @todo If we have time someday :) Play with the idea of making this be a + * class that's attached to a TableBuffer, much the same way a real DB index + * is attached to a table. The TableBuffer could have a list of pointers + * to indexes, and it would invoke addRow, etc., as needed. + */ + +class IndexedNetworkTableBuffer : public TableBuffer +{ + public: + void addRowToIndex(int indexValue, DB::Row *row); + DB::Row *findRowByIndex(int indexValue); + + protected: + IndexedNetworkTableBuffer(TableBufferMode mode, DB::ModeQuery *query); + + private: + typedef std::hash_map IndexType; + /** + * Index to locate rows. + * + * Note that the rows are owned by the TableBuffer base class. This + * is just an index to find a specific row quickly. Therefore, this + * class does not create or delete the rows. + */ + IndexType m_index; +}; + +// ====================================================================== + +#endif +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/LocationBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/LocationBuffer.cpp new file mode 100644 index 00000000..f10d32a5 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/LocationBuffer.cpp @@ -0,0 +1,165 @@ +// ====================================================================== +// +// LocationBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "LocationBuffer.h" + +#include "SwgDatabaseServer/LocationQuery.h" +#include "serverGame/ServerCreatureObjectTemplate.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +LocationBuffer::LocationBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer() +{ + UNREF(mode); +} + +// ---------------------------------------------------------------------- + +LocationBuffer::~LocationBuffer() +{ +} + +// ---------------------------------------------------------------------- + +bool LocationBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("Locations: %i saved to db",m_saveData.size())); + + DBQuery::SaveLocationQuery qry; + for (SaveDataType::const_iterator i=m_saveData.begin(); i!=m_saveData.end(); ++i) + { + NetworkId networkId=i->first; + const std::vector &data=i->second; + for (std::vector::const_iterator j=data.begin(); j!=data.end(); ++j) + { + qry.setData(networkId, j->m_listId, j->m_action, j->m_index, j->m_data); + if (! (session->exec(&qry))) + return false; + } + } + + qry.done(); + return true; +} + +// ---------------------------------------------------------------------- + +bool LocationBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched = 0; + if (tags.find(static_cast(ServerCreatureObjectTemplate::ServerCreatureObjectTemplate_tag)) != tags.end()) + { + DBQuery::LoadLocationQuery qry(schema); + LocationData temp; + + if (! (session->exec(&qry))) + return false; + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + i->name.getValue(temp.name); + i->scene.getValue(temp.scene); + temp.location.setCenter(static_cast(i->x.getValue()),static_cast(i->y.getValue()),static_cast(i->z.getValue())); + temp.location.setRadius(static_cast(i->radius.getValue())); + + m_loadData[IndexKey(i->object_id.getValue(),i->list_id.getValue(),i->index.getValue())]=temp; + } + } + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +void LocationBuffer::removeObject(const NetworkId &object) +{ + m_saveData.erase(object); +} + +// ---------------------------------------------------------------------- + +void LocationBuffer::addAction(BufferEntry::Action action, const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value) +{ + m_saveData[objectId].push_back(BufferEntry(listId, action, sequenceNumber, value)); +} + +// ---------------------------------------------------------------------- + +void LocationBuffer::getLocationList(const NetworkId &objectId, size_t listId, std::vector &values) const +{ +#ifdef _DEBUG + size_t expectedIndex = 0; +#endif + + for (LoadDataType::const_iterator i=m_loadData.find(IndexKey(objectId, listId, 0)); (i!=m_loadData.end()) && (i->first.m_objectId == objectId) && (i->first.m_listId == listId); ++i) + { + DEBUG_FATAL(i->first.m_index != expectedIndex++,("Programmer bug: location list was not sorted or had gaps in the sequence. Object id %s, list id %i, sequence %i\n",objectId.getValueString().c_str(), listId, i->first.m_index)); + + values.push_back(i->second); + } +} + +// ====================================================================== + +LocationBuffer::BufferEntry::BufferEntry(size_t listId, Action action, size_t index, const LocationData &data) : + m_listId(listId), + m_action(action), + m_index(index), + m_data(data) +{ +} + +// ====================================================================== + +LocationBuffer::IndexKey::IndexKey() +{ +} + +// ---------------------------------------------------------------------- + +LocationBuffer::IndexKey::IndexKey(const NetworkId &objectId, size_t listId, size_t index) : + m_objectId(objectId), + m_listId(listId), + m_index(index) +{ +} + +// ---------------------------------------------------------------------- + +LocationBuffer::IndexKey::IndexKey(const IndexKey &rhs) : + m_objectId(rhs.m_objectId), + m_listId(rhs.m_listId), + m_index(rhs.m_index) +{ +} + +// ---------------------------------------------------------------------- + +bool LocationBuffer::IndexKey::operator<(const IndexKey &rhs) const +{ + if (m_objectId == rhs.m_objectId) + if (m_listId == rhs.m_listId) + return (m_index < rhs.m_index); + else + return (m_listId < rhs.m_listId); + else + return (m_objectId < rhs.m_objectId); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/LocationBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/LocationBuffer.h new file mode 100644 index 00000000..6d31adbf --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/LocationBuffer.h @@ -0,0 +1,114 @@ +// ====================================================================== +// +// LocationBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_LocationBuffer_H +#define INCLUDED_LocationBuffer_H + +// ====================================================================== + +#include +#include +#include "serverDatabase/TableBuffer.h" +#include "serverUtility/LocationData.h" +#include "sharedFoundation/NetworkId.h" + +namespace DBSchema +{ + struct LocationRow; +} + +// ====================================================================== + +/** + * LocationBuffer is a table buffer customized to the job of loading and + * saving locations for OnArrivedAt() targets, etc. + * + * Locations are keyed by object id, a list number, and a sequence number. (Thus + * each object can have multiple lists of locations.) + * + * Unlike most other buffer classes, this class does not maintain a list of rows. + * Instead, it has a map of vectors of actions to be applied in the database. + */ + +class LocationBuffer : public AbstractTableBuffer +{ + public: + explicit LocationBuffer(DB::ModeQuery::Mode mode); + virtual ~LocationBuffer(void); + + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + virtual void removeObject(const NetworkId &object); + + void set (const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value); + void insert (const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value); + void erase (const NetworkId &objectId, size_t listId, size_t sequenceNumber); + void getLocationList(const NetworkId &objectId, size_t listId, std::vector &values) const; + + private: + struct BufferEntry + { + enum Action {be_INSERT, be_ERASE, be_SET}; + size_t m_listId; + Action m_action; + size_t m_index; + LocationData m_data; + + BufferEntry(size_t listId, Action action, size_t index, const LocationData &data); + }; + + struct IndexKey + { + NetworkId m_objectId; + size_t m_listId; + size_t m_index; + + IndexKey(); + IndexKey(const NetworkId &objectId, size_t listId, size_t index); + IndexKey(const IndexKey &rhs); + bool operator < (const IndexKey &rhs) const; + }; + + typedef std::map > SaveDataType; + SaveDataType m_saveData; + + typedef std::map LoadDataType; + LoadDataType m_loadData; + + private: + void addAction(BufferEntry::Action action, const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value); + + private: + LocationBuffer(); //disable + LocationBuffer(const LocationBuffer&); //disable + LocationBuffer & operator=(const LocationBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +inline void LocationBuffer::set(const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value) +{ + addAction(BufferEntry::be_SET, objectId, listId, sequenceNumber, value); +} + +// ---------------------------------------------------------------------- + +inline void LocationBuffer::insert(const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value) +{ + addAction(BufferEntry::be_INSERT, objectId, listId, sequenceNumber, value); +} + +// ---------------------------------------------------------------------- + +inline void LocationBuffer::erase(const NetworkId &objectId, size_t listId, size_t sequenceNumber) +{ + addAction(BufferEntry::be_ERASE, objectId, listId, sequenceNumber, LocationData()); +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ManufactureSchematicAttributeBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ManufactureSchematicAttributeBuffer.cpp new file mode 100644 index 00000000..12c4e790 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ManufactureSchematicAttributeBuffer.cpp @@ -0,0 +1,183 @@ +// ====================================================================== +// +// ManufactureSchematicAttributeBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/ManufactureSchematicAttributeBuffer.h" + +#include "SwgDatabaseServer/ManufactureSchematicAttributeQuery.h" +#include "serverGame/ServerManufactureSchematicObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +#include + +// ====================================================================== + +ManufactureSchematicAttributeBuffer::ManufactureSchematicAttributeBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer(), + m_mode(mode), + m_rows() +{ +} + +// ---------------------------------------------------------------------- + +ManufactureSchematicAttributeBuffer::~ManufactureSchematicAttributeBuffer(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +void ManufactureSchematicAttributeBuffer::setManufactureSchematicAttribute(const NetworkId &objectId, std::string attributeType, float value) +{ + DBSchema::ManufactureSchematicAttributeRow *row=findRowByIndex(objectId,attributeType); + if (!row) + { + row=new DBSchema::ManufactureSchematicAttributeRow; + addRowToIndex(objectId,attributeType,row); + } + + row->action = 1; //TODO: enum somewhere + row->object_id = objectId; + row->attribute_type=attributeType; + row->value = value; +} + +// ---------------------------------------------------------------------- + +void ManufactureSchematicAttributeBuffer::removeManufactureSchematicAttribute(const NetworkId &objectId, std::string attributeType) +{ + DBSchema::ManufactureSchematicAttributeRow *row=findRowByIndex(objectId,attributeType); + if (!row) + { + row=new DBSchema::ManufactureSchematicAttributeRow; + addRowToIndex(objectId,attributeType,row); + } + + row->action = 0; //TODO: enum somewhere +} + +// ---------------------------------------------------------------------- + +bool ManufactureSchematicAttributeBuffer::getDataForObject(const NetworkId &objectId, std::vector > &values) const +{ + DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getExperienceForObject()\n")); + IndexType::const_iterator i ( m_rows.lower_bound(IndexKey(objectId,"")) ); + if (i==m_rows.end()) + return false; + for (; (i!=m_rows.end()) && (((*i).second)->object_id.getValue()==objectId); ++i) + { + std::string temp; + (*i).second->attribute_type.getValue(temp); + values.push_back(std::pair(temp, static_cast((*i).second->value.getValue()))); + } + return true; +} + +// ---------------------------------------------------------------------- + +DBSchema::ManufactureSchematicAttributeRow * ManufactureSchematicAttributeBuffer::findRowByIndex(NetworkId objectId, std::string experienceType) +{ + IndexType::iterator i=m_rows.find(IndexKey(objectId,experienceType)); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void ManufactureSchematicAttributeBuffer::addRowToIndex(NetworkId objectId, std::string attributeType, DBSchema::ManufactureSchematicAttributeRow *row) +{ + m_rows[IndexKey(objectId,attributeType)]=row; +} + +// ---------------------------------------------------------------------- + +/** + * Load the attributes for all the remembered objectId's. + */ +bool ManufactureSchematicAttributeBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched = 0; + if (tags.find(static_cast(ServerManufactureSchematicObjectTemplate::ServerManufactureSchematicObjectTemplate_tag)) != tags.end()) + { + DBQuery::GetAllManufactureSchematicAttributes qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + DBSchema::ManufactureSchematicAttributeRow *row=new DBSchema::ManufactureSchematicAttributeRow(*i); + NOT_NULL(row); + std::string temp; + row->attribute_type.getValue(temp); + addRowToIndex(row->object_id.getValue(),temp,row); + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +bool ManufactureSchematicAttributeBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("ManufactureSchematicAttributeBuffer: %i saved to db",m_rows.size())); + + DBQuery::ManufactureSchematicAttributeQuery qry; + + if (m_mode==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else + qry.updateMode(); + + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + qry.setData(*(i->second)); + if (! (session->exec(&qry))) + return false; + } + qry.done(); + return true; +} + + +// ---------------------------------------------------------------------- + +void ManufactureSchematicAttributeBuffer::removeObject(const NetworkId &object) +{ + IndexType::iterator i=m_rows.lower_bound(IndexKey(object,"")); + while (i!=m_rows.end() && i->first.m_objectId==object) + { + IndexType::iterator next=i; + ++next; + delete i->second; + i->second=NULL; + m_rows.erase(i); + i=next; + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ManufactureSchematicAttributeBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ManufactureSchematicAttributeBuffer.h new file mode 100644 index 00000000..79f570e8 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ManufactureSchematicAttributeBuffer.h @@ -0,0 +1,97 @@ +// ====================================================================== +// +// ManufactureSchematicAttributeBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ManufactureSchematicAttributeBuffer_H +#define INCLUDED_ManufactureSchematicAttributeBuffer_H + +// ====================================================================== + +#include +#include +#include "serverDatabase/AbstractTableBuffer.h" +#include "SwgDatabaseServer/ManufactureSchematicAttributeQuery.h" + +namespace DBSchema +{ + struct ManufactureSchematicAttributeRow; +} + +// ====================================================================== + +class ManufactureSchematicAttributeBuffer : public AbstractTableBuffer // +{ +public: + explicit ManufactureSchematicAttributeBuffer (DB::ModeQuery::Mode mode); + virtual ~ManufactureSchematicAttributeBuffer (); + + virtual bool load (DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save (DB::Session *session); + virtual void removeObject (const NetworkId &object); + + + DBSchema::ManufactureSchematicAttributeRow * findRowByIndex (NetworkId objectId, std::string attributeType); + + void setManufactureSchematicAttribute (const NetworkId &objectId, std::string attributeType, float value); + void removeManufactureSchematicAttribute (const NetworkId &objectId, std::string attributeType); + bool getDataForObject (const NetworkId &objectId, stdvector >::fwd &values) const; + + private: + void addRowToIndex (NetworkId objectId, std::string attributeType, DBSchema::ManufactureSchematicAttributeRow *row); + + private: + struct IndexKey + { + NetworkId m_objectId; + std::string m_attributeType; + + IndexKey(NetworkId objectId, std::string attributeType); + bool operator==(const IndexKey &rhs) const; + }; + struct IndexSorter + { + bool operator() (const IndexKey &left, const IndexKey &right) const; + }; + + typedef std::map IndexType; + + DB::ModeQuery::Mode m_mode; + IndexType m_rows; + + private: + ManufactureSchematicAttributeBuffer(); //disable + ManufactureSchematicAttributeBuffer(const ManufactureSchematicAttributeBuffer&); //disable + ManufactureSchematicAttributeBuffer & operator=(const ManufactureSchematicAttributeBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +inline ManufactureSchematicAttributeBuffer::IndexKey::IndexKey(NetworkId objectId, std::string attributeType) : + m_objectId(objectId), + m_attributeType(attributeType) +{ +} + +// ---------------------------------------------------------------------- + +inline bool ManufactureSchematicAttributeBuffer::IndexKey::operator==(const IndexKey &rhs) const +{ + return ((m_objectId == rhs.m_objectId) && (m_attributeType == rhs.m_attributeType)); +} + +// ---------------------------------------------------------------------- + +inline bool ManufactureSchematicAttributeBuffer::IndexSorter::operator() (const IndexKey &left, const IndexKey &right) const +{ + if (left.m_objectId == right.m_objectId) + return (left.m_attributeType < right.m_attributeType); + else + return (left.m_objectId < right.m_objectId); +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionBidsBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionBidsBuffer.cpp new file mode 100644 index 00000000..3a024651 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionBidsBuffer.cpp @@ -0,0 +1,138 @@ +// ====================================================================== +// +// MarketAuctionBidsBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/MarketAuctionBidsBuffer.h" + +#include "SwgDatabaseServer/CommoditiesQuery.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include + +// ====================================================================== + +MarketAuctionBidsBuffer::MarketAuctionBidsBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer(), + m_mode(mode), + m_rows() +{ +} + +// ---------------------------------------------------------------------- + +MarketAuctionBidsBuffer::~MarketAuctionBidsBuffer(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionBidsBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + return true; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionBidsBuffer::removeObject(const NetworkId &object) +{ + removeMarketAuctionBids(object); +} + +// ---------------------------------------------------------------------- + +void MarketAuctionBidsBuffer::removeMarketAuctionBids(const NetworkId &itemId) +{ + IndexType::iterator i=m_rows.find(itemId); + if (i!=m_rows.end()) + { + delete i->second; + i->second=NULL; + m_rows.erase(i); + } +} + +// ---------------------------------------------------------------------- + +void MarketAuctionBidsBuffer::setMarketAuctionBids(const NetworkId &itemId, const NetworkId &bidderId, const int bid, const int maxProxyBid) +{ + DBSchema::MarketAuctionBidsRow *row=findRowByIndex(itemId); + if (!row) + { + row=new DBSchema::MarketAuctionBidsRow; + addRowToIndex(itemId, row); + } + row->item_id = itemId; + row->bidder_id = bidderId; + row->bid = bid; + row->max_proxy_bid = maxProxyBid; +} + +// ---------------------------------------------------------------------- + +DBSchema::MarketAuctionBidsRow * MarketAuctionBidsBuffer::findRowByIndex(const NetworkId &itemId) +{ + IndexType::iterator i=m_rows.find(itemId); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionBidsBuffer::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionBidsRow *row) +{ + m_rows[itemId]=row; +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionBidsBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("MarketAuctionBids: %i saved to db",m_rows.size())); + DEBUG_REPORT_LOG(true, ("Saving Market Auction Bids Buffer. mode:%d rowcount:%d\n", m_mode, m_rows.size())); + + DBQuery::MarketAuctionBidsQuery qry; + + if (m_mode==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else if (m_mode == DB::ModeQuery::mode_UPDATE) + qry.updateMode(); + else + qry.deleteMode(); + if (!qry.setupData(session)) + return false; + + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + if (!qry.addData(i->second)) + return false; + if (qry.getNumItems() >= MarketAuctionBidsTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + return true; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionBidsBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionBidsBuffer.h new file mode 100644 index 00000000..83ef7355 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionBidsBuffer.h @@ -0,0 +1,63 @@ +// ====================================================================== +// +// MarketAuctionBidsBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_MarketAuctionBidsBuffer_H +#define INCLUDED_MarketAuctionBidsBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/CommoditiesQuery.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" +#include "serverDatabase/AbstractTableBuffer.h" +#include +#include + +// ====================================================================== + +namespace MarketAuctionBidsTableBufferNamespace +{ + const int ms_maxItemsPerExec = 10000; +} + +using namespace MarketAuctionBidsTableBufferNamespace; + +// ====================================================================== + +class MarketAuctionBidsBuffer : public AbstractTableBuffer +{ +public: + explicit MarketAuctionBidsBuffer (DB::ModeQuery::Mode mode); + virtual ~MarketAuctionBidsBuffer (); + + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + + DBSchema::MarketAuctionBidsRow * findRowByIndex (const NetworkId &itemId); + + void setMarketAuctionBids (const NetworkId &itemId, const NetworkId &bidderId, const int bid, const int maxProxyBid); + void removeMarketAuctionBids(const NetworkId &itemId); + virtual void removeObject (const NetworkId &object); + + private: + void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionBidsRow *row); + + private: + + typedef std::map IndexType; + + DB::ModeQuery::Mode m_mode; + IndexType m_rows; + + private: + MarketAuctionBidsBuffer(); //disable + MarketAuctionBidsBuffer(const MarketAuctionBidsBuffer&); //disable + MarketAuctionBidsBuffer & operator=(const MarketAuctionBidsBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionsBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionsBuffer.cpp new file mode 100644 index 00000000..24a0ac51 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionsBuffer.cpp @@ -0,0 +1,433 @@ +// ====================================================================== +// +// MarketAuctionsBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/MarketAuctionsBuffer.h" + +#include "SwgDatabaseServer/CommoditiesQuery.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include + +// ====================================================================== + +MarketAuctionsBufferCreate::MarketAuctionsBufferCreate() : + AbstractTableBuffer(), + m_rows(), + m_attributes() +{ +} + +// ---------------------------------------------------------------------- + +MarketAuctionsBufferCreate::~MarketAuctionsBufferCreate(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsBufferCreate::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + return true; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferCreate::removeObject(const NetworkId &object) +{ + removeMarketAuctions(object); +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferCreate::removeMarketAuctions(const NetworkId &itemId) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size())); + DBSchema::MarketAuctionsRow *row=findRowByIndex(itemId); + if (row) + { + delete row; + IGNORE_RETURN(m_rows.erase(itemId)); + IGNORE_RETURN(m_attributes.erase(itemId)); + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size())); + } +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferCreate::setMarketAuctions(const NetworkId &itemId, const NetworkId &ownerId, const int active) +{ + DBSchema::MarketAuctionsRow *row=findRowByIndex(itemId); + if (!row) + { + row=new DBSchema::MarketAuctionsRow; + addRowToIndex(itemId, row); + } + row->item_id = itemId; + row->owner_id = ownerId; + row->active = active; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferCreate::setMarketAuctions(const NetworkId &itemId, const NetworkId &ownerId, const NetworkId &creatorId, const NetworkId &locationId, const int minBid, const int buyNowPrice, const int auctionTimer, std::vector > const & attributes, const Unicode::String userDescription, const int category, const int itemTemplateId, const Unicode::String itemName, const int itemTimer, const int active, const int itemSize) +{ + DBSchema::MarketAuctionsRow *row=findRowByIndex(itemId); + if (!row) + { + row=new DBSchema::MarketAuctionsRow; + addRowToIndex(itemId, row); + } + row->item_id = itemId; + row->owner_id = ownerId; + row->creator_id = creatorId; + row->location_id = locationId; + row->min_bid = minBid; + row->buy_now_price = buyNowPrice; + row->auction_timer = auctionTimer; +// row->oob = oob; + row->user_description = userDescription; + row->category = category; + row->item_name = itemName; + row->item_timer = itemTimer; + row->active = active; + row->item_size = itemSize; + row->object_template_id = itemTemplateId; + LOG("CommoditiesServer", ("MarketAuctionsBufferCreate Added MarketAuctionsBuffer row for item %s", row->item_id.getValueASCII().c_str())); + + m_attributes[itemId] = attributes; +} + +// ---------------------------------------------------------------------- + +DBSchema::MarketAuctionsRow * MarketAuctionsBufferCreate::findRowByIndex(const NetworkId &itemId) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Finding row by Index. ItemId : %s.\n", itemId.getValueString().c_str())); + IndexType::iterator i=m_rows.find(itemId); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferCreate::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRow *row) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Adding row to Index. ItemId : %s.\n", itemId.getValueString().c_str())); + m_rows[itemId]=row; +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsBufferCreate::save(DB::Session *session) +{ + { + // count how many attributes we're saving + size_t numAttributes = 0; + + for (AttributesType::const_iterator i=m_attributes.begin(); i!=m_attributes.end(); ++i) + numAttributes += i->second.size(); + + LOG("SaveCounts",("MarketAuctionsBufferCreate: %i auctions, %i auction attributes saved to db",m_rows.size(), numAttributes)); + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Saving Market Auctions Buffer. rowcount:%d auctions, %d auction attributes\n", m_rows.size(), numAttributes)); + } + + { + DBQuery::MarketAuctionsQuery qry; + qry.insertMode(); + + if (!qry.setupData(session)) + return false; + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + if (!qry.addData(i->second)) + return false; + LOG("CommoditiesServer", ("MarketAuctionsBufferCreate Added row to MarketAuctionsQuery VARRAY for item %s", (i->second)->item_id.getValueASCII().c_str())); + if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + } + + + { + DBQuery::MarketAuctionsAttributesQuery qry; + qry.insertMode(); + + if (!qry.setupData(session)) + return false; + for (AttributesType::const_iterator i=m_attributes.begin(); i!=m_attributes.end(); ++i) + { + for (std::vector >::const_iterator j=i->second.begin(); j!=i->second.end(); ++j) + { + if (!qry.addData(i->first, j->first, j->second)) + return false; + if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + } + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + } + + return true; +} + +// ====================================================================== + +MarketAuctionsBufferDelete::MarketAuctionsBufferDelete() : + AbstractTableBuffer(), + m_rows() +{ +} + +// ---------------------------------------------------------------------- + +MarketAuctionsBufferDelete::~MarketAuctionsBufferDelete(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsBufferDelete::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + return true; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferDelete::removeObject(const NetworkId &object) +{ + removeMarketAuctions(object); +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferDelete::removeMarketAuctions(const NetworkId &itemId) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size())); + DBSchema::MarketAuctionsRowDelete *row=findRowByIndex(itemId); + if (row) + { + delete row; + IGNORE_RETURN(m_rows.erase(itemId)); + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size())); + } +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferDelete::setMarketAuctions(const NetworkId &itemId) +{ + DBSchema::MarketAuctionsRowDelete *row=findRowByIndex(itemId); + if (!row) + { + row=new DBSchema::MarketAuctionsRowDelete; + addRowToIndex(itemId, row); + } + row->item_id = itemId; +} + +// ---------------------------------------------------------------------- + +DBSchema::MarketAuctionsRowDelete * MarketAuctionsBufferDelete::findRowByIndex(const NetworkId &itemId) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Finding row by Index. ItemId : %s.\n", itemId.getValueString().c_str())); + IndexType::iterator i=m_rows.find(itemId); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferDelete::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowDelete *row) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Adding row to Index. ItemId : %s.\n", itemId.getValueString().c_str())); + m_rows[itemId]=row; +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsBufferDelete::save(DB::Session *session) +{ + LOG("SaveCounts",("MarketAuctionsBufferDelete: %i saved to db",m_rows.size())); + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Saving Market Auctions Buffer. rowcount:%d\n", m_rows.size())); + + DBQuery::MarketAuctionsQuery qry; + qry.deleteMode(); + + if (!qry.setupData(session)) + return false; + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + if (!qry.addData(i->second)) + return false; + LOG("CommoditiesServer", ("MarketAuctionsBufferDelete Added row to MarketAuctionsQuery VARRAY for item %s", (i->second)->item_id.getValueASCII().c_str())); + if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + return true; +} + +// ====================================================================== + +MarketAuctionsBufferUpdate::MarketAuctionsBufferUpdate() : + AbstractTableBuffer(), + m_rows() +{ +} + +// ---------------------------------------------------------------------- + +MarketAuctionsBufferUpdate::~MarketAuctionsBufferUpdate(void) +{ + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsBufferUpdate::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + return true; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferUpdate::removeObject(const NetworkId &object) +{ + removeMarketAuctions(object); +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferUpdate::removeMarketAuctions(const NetworkId &itemId) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size())); + DBSchema::MarketAuctionsRowUpdate *row=findRowByIndex(itemId); + if (row) + { + delete row; + IGNORE_RETURN(m_rows.erase(itemId)); + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size())); + } +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferUpdate::setMarketAuctions(const NetworkId &itemId, const NetworkId &ownerId, const int active) +{ + DBSchema::MarketAuctionsRowUpdate *row=findRowByIndex(itemId); + if (!row) + { + row=new DBSchema::MarketAuctionsRowUpdate; + addRowToIndex(itemId, row); + } + row->item_id = itemId; + row->owner_id = ownerId; + row->active = active; +} + +// ---------------------------------------------------------------------- + +DBSchema::MarketAuctionsRowUpdate * MarketAuctionsBufferUpdate::findRowByIndex(const NetworkId &itemId) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Finding row by Index. ItemId : %s.\n", itemId.getValueString().c_str())); + IndexType::iterator i=m_rows.find(itemId); + if (i==m_rows.end()) + return 0; + else + return (*i).second; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsBufferUpdate::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowUpdate *row) +{ + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Adding row to Index. ItemId : %s.\n", itemId.getValueString().c_str())); + m_rows[itemId]=row; +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsBufferUpdate::save(DB::Session *session) +{ + LOG("SaveCounts",("MarketAuctionsBufferUpdate: %i saved to db",m_rows.size())); + DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Saving Market Auctions Buffer. rowcount:%d\n", m_rows.size())); + + DBQuery::MarketAuctionsQuery qry; + qry.updateMode(); + + if (!qry.setupData(session)) + return false; + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + if (!qry.addData(i->second)) + return false; + LOG("CommoditiesServer", ("MarketAuctionsBufferUpdate Added row to MarketAuctionsQuery VARRAY for item %s", (i->second)->item_id.getValueASCII().c_str())); + if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + return true; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionsBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionsBuffer.h new file mode 100644 index 00000000..269731d8 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/MarketAuctionsBuffer.h @@ -0,0 +1,121 @@ +// ====================================================================== +// +// MarketAuctionsBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_MarketAuctionsBuffer_H +#define INCLUDED_MarketAuctionsBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/CommoditiesQuery.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" +#include "serverDatabase/AbstractTableBuffer.h" +#include +#include + +// ====================================================================== + +namespace MarketAuctionsTableBufferNamespace +{ + const int ms_maxItemsPerExec = 10000; +} + +using namespace MarketAuctionsTableBufferNamespace; + +// ====================================================================== + +class MarketAuctionsBufferCreate : public AbstractTableBuffer +{ +public: + MarketAuctionsBufferCreate(); + virtual ~MarketAuctionsBufferCreate(); + + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + + DBSchema::MarketAuctionsRow * findRowByIndex (const NetworkId &itemId); + + void setMarketAuctions (const NetworkId &itemId, const NetworkId &ownerId, const int active); + void setMarketAuctions (const NetworkId &itemId, const NetworkId &ownerId, const NetworkId &creatorId, const NetworkId &locationId, const int minBid, const int buyNowPrice, const int auctionTimer, std::vector > const & attributes, const Unicode::String userDescription, const int category, const int itemTemplateId, const Unicode::String itemName, const int itemTimer, const int active, const int itemSize); + void removeMarketAuctions (const NetworkId &itemId); + virtual void removeObject (const NetworkId &object); + +private: + void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRow *row); + +private: + typedef std::hash_map IndexType; + IndexType m_rows; + + typedef std::hash_map > > AttributesType; + AttributesType m_attributes; + +private: + MarketAuctionsBufferCreate(const MarketAuctionsBufferCreate&); //disable + MarketAuctionsBufferCreate & operator=(const MarketAuctionsBufferCreate&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +class MarketAuctionsBufferDelete : public AbstractTableBuffer +{ +public: + explicit MarketAuctionsBufferDelete(); + virtual ~MarketAuctionsBufferDelete(); + + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + + DBSchema::MarketAuctionsRowDelete * findRowByIndex(const NetworkId &itemId); + + void setMarketAuctions (const NetworkId &itemId); + void removeMarketAuctions (const NetworkId &itemId); + virtual void removeObject (const NetworkId &object); + +private: + void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowDelete *row); + +private: + typedef std::hash_map IndexType; + IndexType m_rows; + +private: + MarketAuctionsBufferDelete(const MarketAuctionsBufferDelete&); //disable + MarketAuctionsBufferDelete & operator=(const MarketAuctionsBufferDelete&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +class MarketAuctionsBufferUpdate : public AbstractTableBuffer +{ +public: + explicit MarketAuctionsBufferUpdate(); + virtual ~MarketAuctionsBufferUpdate(); + + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + + DBSchema::MarketAuctionsRowUpdate * findRowByIndex(const NetworkId &itemId); + + void setMarketAuctions (const NetworkId &itemId, const NetworkId &ownerId, const int active); + void removeMarketAuctions (const NetworkId &itemId); + virtual void removeObject (const NetworkId &object); + +private: + void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowUpdate *row); + +private: + typedef std::hash_map IndexType; + IndexType m_rows; + +private: + MarketAuctionsBufferUpdate(const MarketAuctionsBufferUpdate&); //disable + MarketAuctionsBufferUpdate & operator=(const MarketAuctionsBufferUpdate&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/MessageBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/MessageBuffer.cpp new file mode 100644 index 00000000..c835b487 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/MessageBuffer.cpp @@ -0,0 +1,205 @@ +// ====================================================================== +// +// MessageBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/MessageBuffer.h" + +#include "SwgDatabaseServer/MessageQuery.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/GameServerConnection.h" +#include "serverDatabase/Loader.h" +#include "serverDatabase/MessageToManager.h" +#include "serverNetworkMessages/MessageToMessage.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +MessageBuffer::~MessageBuffer() +{ +} + +// ---------------------------------------------------------------------- + +void MessageBuffer::handleMessageTo(const MessageToPayload &message) +{ + DEBUG_FATAL(m_data.find(message.getMessageId())!=m_data.end(),("Received duplicate messageTo, id %s.\n",message.getMessageId().getValueString().c_str())); + + if (message.getNetworkId().getValue() <= static_cast(0)) + DEBUG_WARNING(true,("Ignored persisted messageTo sent to invalid object id %s, method %s",message.getNetworkId().getValueString().c_str(), message.getMethod().c_str())); + else + m_data[message.getMessageId()]=message; +} + +// ---------------------------------------------------------------------- + +void MessageBuffer::handleMessageToAck(const MessageToId &messageId) +{ + MessageMap::iterator i=m_data.find(messageId); + if (i!=m_data.end()) + { + // we have the message in the buffer, so we can just delete it without involving the database + m_data.erase(i); + } + else + { + // we don't have the message, so it must have already been persisted to the database + // set a flag to remove it from the DB + m_ackedMessages.push_back(messageId); + } +} + +// ---------------------------------------------------------------------- + +bool MessageBuffer::save(DB::Session *session) +{ + int actualSaves=0; + DBQuery::SaveMessageQuery qry; + if (!qry.setupData(session)) + return false; + + for (MessageMap::const_iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + if (m_cancelledObjects.find(i->second.getNetworkId())==m_cancelledObjects.end()) + { + ++actualSaves; + if (!qry.addData((*i).second)) + return false; + + if (qry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize()) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + } + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + + DBQuery::AckMessageQuery ackqry; + if (!ackqry.setupData(session)) + return false; + + for (AckedMessagesType::const_iterator j=m_ackedMessages.begin(); j!=m_ackedMessages.end(); ++j) + { + if (!ackqry.addData(*j)) + return false; + + if (ackqry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize()) + { + if (! (session->exec(&ackqry))) + return false; + ackqry.clearData(); + } + } + if (ackqry.getNumItems() != 0) + if (! (session->exec(&ackqry))) + return false;; + + ackqry.done(); + ackqry.freeData(); + + + LOG("SaveCounts",("Messages: %i out of %i saved in db, %i acks sent to db",actualSaves,m_data.size(),m_ackedMessages.size())); + return true; +} + +// ---------------------------------------------------------------------- + +bool MessageBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched; + UNREF(tags); // any object can have messages + + DBQuery::LoadMessagesQuery qry(schema); + + if (! (session->exec(&qry))) + return false; + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + + const std::vector &data =qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + std::string utf8data; + i->packed_data.getValue(utf8data); + std::vector packedDataVector; + qry.convertUTF8ToMessage(utf8data, packedDataVector); + + MessageToPayload messageData(i->object_id.getValue(), + i->message_id.getValue(), + Unicode::wideToNarrow(i->method.getValue()), + packedDataVector, + i->call_time.getValue(), + i->guaranteed.getValue(), + static_cast(i->delivery_type.getValue()), + NetworkId::cms_invalid, + std::string(), + 0); + messageData.setPersisted(true); + m_data[i->message_id.getValue()]=messageData; + } + } + qry.done(); + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +/** + * Send all the messages in the buffer to the GameServer, which will enqueue + * them and handle them when their timers expire. + * Note: This requires that all the objects loaded have already been + * sent to the game server. + */ +void MessageBuffer::sendMessages(GameServerConnection &conn) const +{ + for (MessageMap::const_iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + if (!MessageToManager::getInstance().hasMessage(i->second.getMessageId())) + { + MessageToMessage const msg((*i).second, DatabaseProcess::getInstance().getProcessId()); + conn.send(msg, true); + } + } +} + +// ---------------------------------------------------------------------- + +void MessageBuffer::removeObject(const NetworkId &object) +{ + // Too slow to hunt down all the messages & acks for this object, so easier to make + // a set of objects and skip any new messages for these objects + m_cancelledObjects.insert(object); +} + +// ---------------------------------------------------------------------- + +/** + * Called by the main thread after persistence is complete. + * Remove all the saved messages from the MessageToManager, since + * they will be reloaded from the DB if needed. + */ +void MessageBuffer::removeSavedMessagesFromMemory () const +{ + for (MessageMap::const_iterator i=m_data.begin(); i!=m_data.end(); ++i) + MessageToManager::getInstance().onMessagePersisted(i->second.getMessageId()); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/MessageBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/MessageBuffer.h new file mode 100644 index 00000000..f4f3fafc --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/MessageBuffer.h @@ -0,0 +1,62 @@ +// ====================================================================== +// +// MessageBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_MessageBuffer_H +#define INCLUDED_MessageBuffer_H + +// ====================================================================== + +#include "serverDatabase/AbstractTableBuffer.h" +#include "serverNetworkMessages/MessageToPayload.h" + +#include +#include +#include + +// ====================================================================== + +namespace DB +{ + class Session; +} + +class GameServerConnection; + +// ====================================================================== + +/** + * A buffer to hold messageTo commands. + */ +class MessageBuffer : public AbstractTableBuffer +{ + public: + void handleMessageTo (const MessageToPayload &message); + void handleMessageToAck (const MessageToId &messageId); + void sendMessages (GameServerConnection &conn) const; + void removeSavedMessagesFromMemory () const; + + virtual bool save(DB::Session *session); + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual void removeObject(const NetworkId &object); + + public: + virtual ~MessageBuffer(); + + private: + typedef std::map MessageMap; + typedef std::vector AckedMessagesType; + typedef std::set OIDList; + + private: + MessageMap m_data; + AckedMessagesType m_ackedMessages; + OIDList m_cancelledObjects; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjectTableBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjectTableBuffer.cpp new file mode 100644 index 00000000..4491b654 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjectTableBuffer.cpp @@ -0,0 +1,819 @@ +// ====================================================================== +// +// ObjectTableBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "ObjectTableBuffer.h" + +#include +#include +#include + +#include "SwgDatabaseServer/DeleteDemandLoadedContainerQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/GetContentsList.h" +#include "serverNetworkMessages/GetMoneyFromOfflineObjectMessage.h" +#include "serverNetworkMessages/UpdateObjectPositionMessage.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include "sharedMath/Quaternion.h" +#include "sharedNetworkMessages/MessageQueueDataTransform.h" +#include "sharedNetworkMessages/ObjectChannelMessages.h" + +// ====================================================================== + +namespace ObjectTableBufferNamespace +{ + static const int s_numPositions = 20; + static const int s_positionMasks[20] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288}; + static const int s_allPositionsSet = 1048575; +} +using namespace ObjectTableBufferNamespace; + +// ====================================================================== + +ObjectTableBuffer::ObjectTableBuffer(DB::ModeQuery::Mode mode) : + IndexedNetworkTableBuffer(mode) +{ +} + +// ====================================================================== + +ObjectTableBuffer::~ObjectTableBuffer() +{ +} + +// ---------------------------------------------------------------------- + + + +/** + * Called when a new object is created. + * + * Sets up the data for the object in the Objects table. + */ + +void ObjectTableBuffer::newObject(const NetworkId &objectId, int templateId, Tag typeId) +{ + DBSchema::ObjectBufferRow *row=addEmptyRow(objectId); + row->object_template_id.setValue(templateId); + row->type_id.setValue(static_cast(typeId)); // cast because tags are unsigned + row->deleted.setValue(0); + row->controller_type.setValue(0); +} + +// ---------------------------------------------------------------------- + +bool ObjectTableBuffer::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message) +{ + DBSchema::ObjectBufferRow *row=dynamic_cast(findRowByIndex(message.getNetworkId())); + if (row==0) + { + row=addEmptyRow(message.getNetworkId()); + } + + Vector v = message.getTransform().getPosition_p(); + row->x = static_cast(v.x); + row->y = static_cast(v.y); + row->z = static_cast(v.z); + + Quaternion q(message.getTransform()); + + Transform t; + q.getTransform(&t); + + row->quaternion_w = static_cast(q.w); + row->quaternion_x = static_cast(q.x); + row->quaternion_y = static_cast(q.y); + row->quaternion_z = static_cast(q.z); + + row->node_x=roundToNode(v.x); + row->node_y=roundToNode(v.y); + row->node_z=roundToNode(v.z); + + row->contained_by = message.getContainerId(); + row->slot_arrangement = message.getSlotArrangement(); + row->load_with = message.getLoadWith(); + + return true; +} + +// ---------------------------------------------------------------------- + +/** + * Process a delete message for an object. + * + * Sets the "deleted" column to "true". + * + * Note: even if the object is a new object, leaves it in the buffer + * (but filters it out in save().) This is to avoid a possible bug + * where some delta comes to the object after it is deleted, and we end + * up creating a new row that doesn't have "deleted" set. + */ + +void ObjectTableBuffer::handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool demandLoadedContainer, bool cascadeDeleteReason) +{ + DEBUG_FATAL(reasonCode==0,("Programmer bug: The gameserver sent 0 as the reason code when deleting object %s, but 0 indicates the object is not deleted.\n",objectId.getValueString().c_str())); + + DBSchema::ObjectBufferRow *row=dynamic_cast(findRowByIndex(objectId)); + if (row==0) + row=addEmptyRow(objectId); + + row->deleted.setValue(reasonCode); + + if (demandLoadedContainer) + { + if (cascadeDeleteReason) + m_demandLoadedContainersToDelete.push_back(std::make_pair(objectId, reasonCode)); + else + m_demandLoadedContainersToDelete.push_back(std::make_pair(objectId, 0)); + } +} + +// ---------------------------------------------------------------------- + +int ObjectTableBuffer::roundToNode(real coordinate) +{ + int c=static_cast(coordinate); + // (c/chunksize)*chunksize : ... blah + return (c >= 0) ? (c/100)*100 : (((c-100)+1)/100)*100; +} + +// ---------------------------------------------------------------------- + +// Topological sort +struct DFSNode +{ + NetworkId m_oid; + NetworkId m_containedBy; + bool m_visited; +}; + +// ---------------------------------------------------------------------- + +void ObjectTableBuffer::getTags(DB::TagSet &tags) const +{ + for (IndexType::const_iterator r=m_rows.begin(); r!=m_rows.end(); ++r) + tags.insert(r->second->type_id.getValue()); +} + +// ---------------------------------------------------------------------- + +void ObjectTableBuffer::getObjectList(stdvector::fwd &theList) const +{ + typedef std::map NodesType; + NodesType nodes; + std::vector nodeStack; + + // Copy the rows to our temporary space for sorting + for (IndexType::const_iterator r=m_rows.begin(); r!=m_rows.end(); ++r) + { + DFSNode &newNode = nodes[r->second->object_id.getValue()]; + newNode.m_oid = r->second->object_id.getValue(); + newNode.m_containedBy = r->second->contained_by.getValue(); + newNode.m_visited = false; + } + + // Depth-first search, outputting the nodes as we recurse *out* of them + for (NodesType::iterator i=nodes.begin(); i!=nodes.end(); ++i) + { + if (!i->second.m_visited) + { + nodeStack.push_back(&i->second); + i->second.m_visited = true; + while (!nodeStack.empty()) + { + DFSNode *theNode = nodeStack.back(); + bool noContainer = true; + if (theNode->m_containedBy!=NetworkId::cms_invalid) + { + NodesType::iterator j=nodes.find(theNode->m_containedBy); + if (j!=nodes.end() && !(j->second.m_visited)) + { + nodeStack.push_back(&(j->second)); + j->second.m_visited = true; + noContainer=false; + } + } + + if (noContainer) + { + nodeStack.pop_back(); + theList.push_back(theNode->m_oid); + } + } + } + } +} + +// ---------------------------------------------------------------------- + + +bool ObjectTableBuffer::save(DB::Session *session) +{ + int updates=0; + int deletes=0; + int onlyPositionOrDeletes=0; + + DBQuery::ObjectsTableQuery qry; + + if (getMode()==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else + qry.updateMode(); + + if (!qry.setupData(session)) + return false; + + for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i) + { + if (i->second->object_template_id.isNull() && + i->second->type_id.isNull() && + i->second->scene_id.isNull() && + i->second->controller_type.isNull() && + i->second->object_name.isNull() && + i->second->volume.isNull() && + i->second->slot_arrangement.isNull() && + i->second->player_controlled.isNull() && + i->second->cache_version.isNull() && + i->second->load_contents.isNull() && + i->second->cash_balance.isNull() && + i->second->bank_balance.isNull() && + i->second->complexity.isNull() && + i->second->name_string_table.isNull() && + i->second->name_string_text.isNull()) + { + ++onlyPositionOrDeletes; + } + + if (!i->second->deleted.isNull() && i->second->deleted.getValue()!=0) + ++deletes; + + + if (getMode()==DB::ModeQuery::mode_INSERT && !i->second->deleted.isNull() && i->second->deleted.getValue()!=0) + { +// DEBUG_REPORT_LOG(true,("Skipped saving deleted object %s\n",i->second->object_id.getValue().getValueString().c_str())); + } + else + { + ++updates; + qry.setData(*(i->second)); +#if 0 // Enable this to debug load_with problems + DEBUG_REPORT_LOG(true,("Save object %s ",i->second->object_id.getValue().getValueString().c_str())); + if (i->second->contained_by.isNull()) + DEBUG_REPORT_LOG(true, ("contained_by NULL ")); + else + DEBUG_REPORT_LOG(true, ("contained_by %s ",i->second->contained_by.getValue().getValueString().c_str())); + if (i->second->load_with.isNull()) + DEBUG_REPORT_LOG(true,("load_with NULL\n")); + else + DEBUG_REPORT_LOG(true,("load_with %s\n",i->second->load_with.getValue().getValueString().c_str())); +#endif + + if (!qry.addData((i->second))) + return false; + + if (qry.getNumItems() == ObjectTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + + + } + } + + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + + if (!m_demandLoadedContainersToDelete.empty()) + { + DBQuery::DeleteDemandLoadedContainerQuery ddlcq; + if (!ddlcq.setupData(*session)) + return false; + + for (std::vector >::const_iterator i=m_demandLoadedContainersToDelete.begin(); i!=m_demandLoadedContainersToDelete.end(); ++i) + { + if (!ddlcq.addData(i->first, i->second)) + return false; + if (ddlcq.getCount() == ObjectTableBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&ddlcq))) + return false; + ddlcq.clearData(); + } + } + if (ddlcq.getCount() != 0) + { + if (! (session->exec(&ddlcq))) + return false; + ddlcq.clearData(); + } + ddlcq.done(); + ddlcq.freeData(); + } + + if (getMode()==DB::ModeQuery::mode_INSERT) + LOG("SaveCounts",("Object table new objects: %i (out of %i) total, %i only position or delete, %i delete\n",updates,m_rows.size(),onlyPositionOrDeletes,deletes)); + else + LOG("SaveCounts",("Object table updates: %i total, %i only position or delete, %i delete\n",updates,onlyPositionOrDeletes,deletes)); + return true; +} + +// ---------------------------------------------------------------------- + +void ObjectTableBuffer::decodeObjVarFreeFlags(const NetworkId &objectId, int freePositions) +{ +// DEBUG_REPORT_LOG(true,("OBJVAR_DEBUG: decodeObjVarFreeFlags(%s,%i)\n",objectId.getValueString().c_str(),freePositions)); + + DBSchema::ObjectBufferRow *row=dynamic_cast(findRowByIndex(objectId)); + if (row==0) + row=addEmptyRow(objectId); + + for (int i=0; iobjvar_0_type = -1; + break; + case 1: + row->objvar_1_type = -1; + break; + case 2: + row->objvar_2_type = -1; + break; + case 3: + row->objvar_3_type = -1; + break; + case 4: + row->objvar_4_type = -1; + break; + case 5: + row->objvar_5_type = -1; + break; + case 6: + row->objvar_6_type = -1; + break; + case 7: + row->objvar_7_type = -1; + break; + case 8: + row->objvar_8_type = -1; + break; + case 9: + row->objvar_9_type = -1; + break; + case 10: + row->objvar_10_type = -1; + break; + case 11: + row->objvar_11_type = -1; + break; + case 12: + row->objvar_12_type = -1; + break; + case 13: + row->objvar_13_type = -1; + break; + case 14: + row->objvar_14_type = -1; + break; + case 15: + row->objvar_15_type = -1; + break; + case 16: + row->objvar_16_type = -1; + break; + case 17: + row->objvar_17_type = -1; + break; + case 18: + row->objvar_18_type = -1; + break; + case 19: + row->objvar_19_type = -1; + break; + default: + DEBUG_FATAL(true,("ObjectId %s had freePositions flag %i, which is not valid.",objectId.getValueString().c_str(),freePositions)); + } + } + } +} + +// ---------------------------------------------------------------------- + +void ObjectTableBuffer::handlePackedObjvar(const NetworkId &objectId, int position, const std::string &objvarName, int typeId, const std::string &packedValue) +{ +// DEBUG_REPORT_LOG(true,("OBJVAR_DEBUG: handlePackedObjvar(%s,%i,%s,%i,%s)\n",objectId.getValueString().c_str(),position,objvarName.c_str(), typeId, packedValue.c_str())); + + DBSchema::ObjectBufferRow *row=dynamic_cast(findRowByIndex(objectId)); + if (row==0) + row=addEmptyRow(objectId); + + switch(position) + { + case 0: + row->objvar_0_name = objvarName; + row->objvar_0_type = typeId; + row->objvar_0_value = packedValue; + break; + case 1: + row->objvar_1_name = objvarName; + row->objvar_1_type = typeId; + row->objvar_1_value = packedValue; + break; + case 2: + row->objvar_2_name = objvarName; + row->objvar_2_type = typeId; + row->objvar_2_value = packedValue; + break; + case 3: + row->objvar_3_name = objvarName; + row->objvar_3_type = typeId; + row->objvar_3_value = packedValue; + break; + case 4: + row->objvar_4_name = objvarName; + row->objvar_4_type = typeId; + row->objvar_4_value = packedValue; + break; + case 5: + row->objvar_5_name = objvarName; + row->objvar_5_type = typeId; + row->objvar_5_value = packedValue; + break; + case 6: + row->objvar_6_name = objvarName; + row->objvar_6_type = typeId; + row->objvar_6_value = packedValue; + break; + case 7: + row->objvar_7_name = objvarName; + row->objvar_7_type = typeId; + row->objvar_7_value = packedValue; + break; + case 8: + row->objvar_8_name = objvarName; + row->objvar_8_type = typeId; + row->objvar_8_value = packedValue; + break; + case 9: + row->objvar_9_name = objvarName; + row->objvar_9_type = typeId; + row->objvar_9_value = packedValue; + break; + case 10: + row->objvar_10_name = objvarName; + row->objvar_10_type = typeId; + row->objvar_10_value = packedValue; + break; + case 11: + row->objvar_11_name = objvarName; + row->objvar_11_type = typeId; + row->objvar_11_value = packedValue; + break; + case 12: + row->objvar_12_name = objvarName; + row->objvar_12_type = typeId; + row->objvar_12_value = packedValue; + break; + case 13: + row->objvar_13_name = objvarName; + row->objvar_13_type = typeId; + row->objvar_13_value = packedValue; + break; + case 14: + row->objvar_14_name = objvarName; + row->objvar_14_type = typeId; + row->objvar_14_value = packedValue; + break; + case 15: + row->objvar_15_name = objvarName; + row->objvar_15_type = typeId; + row->objvar_15_value = packedValue; + break; + case 16: + row->objvar_16_name = objvarName; + row->objvar_16_type = typeId; + row->objvar_16_value = packedValue; + break; + case 17: + row->objvar_17_name = objvarName; + row->objvar_17_type = typeId; + row->objvar_17_value = packedValue; + break; + case 18: + row->objvar_18_name = objvarName; + row->objvar_18_type = typeId; + row->objvar_18_value = packedValue; + break; + case 19: + row->objvar_19_name = objvarName; + row->objvar_19_type = typeId; + row->objvar_19_value = packedValue; + break; + default: + WARNING_STRICT_FATAL(true,("ObjectId %s had objvar %s with postion %i, which is not a valid position.",objectId.getValueString().c_str(),objvarName.c_str(), position)); + } +} + +// ---------------------------------------------------------------------- + +void ObjectTableBuffer::getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const +{ + const DBSchema::ObjectBufferRow *row=safe_cast(findConstRowByIndex(objectId)); + if (row==0) + { + WARNING_STRICT_FATAL(true,("Loaded OBJECT_VARIABLES for %s, but had no OBJECTS row.",objectId.getValueString().c_str())); + return; + } + + DynamicVariableList::MapType::Command c; + c.cmd = DynamicVariableList::MapType::Command::ADD; + + if (row->objvar_0_type.getValue() >= 0) + { + row->objvar_0_name.getValue(c.key); + c.value.load(0, row->objvar_0_type.getValue(), row->objvar_0_value.getValue()); + commands.push_back(c); + } + if (row->objvar_1_type.getValue() >= 0) + { + row->objvar_1_name.getValue(c.key); + c.value.load(1, row->objvar_1_type.getValue(), row->objvar_1_value.getValue()); + commands.push_back(c); + } + if (row->objvar_2_type.getValue() >= 0) + { + row->objvar_2_name.getValue(c.key); + c.value.load(2, row->objvar_2_type.getValue(), row->objvar_2_value.getValue()); + commands.push_back(c); + } + if (row->objvar_3_type.getValue() >= 0) + { + row->objvar_3_name.getValue(c.key); + c.value.load(3, row->objvar_3_type.getValue(), row->objvar_3_value.getValue()); + commands.push_back(c); + } + if (row->objvar_4_type.getValue() >= 0) + { + row->objvar_4_name.getValue(c.key); + c.value.load(4, row->objvar_4_type.getValue(), row->objvar_4_value.getValue()); + commands.push_back(c); + } + if (row->objvar_5_type.getValue() >= 0) + { + row->objvar_5_name.getValue(c.key); + c.value.load(5, row->objvar_5_type.getValue(), row->objvar_5_value.getValue()); + commands.push_back(c); + } + if (row->objvar_6_type.getValue() >= 0) + { + row->objvar_6_name.getValue(c.key); + c.value.load(6, row->objvar_6_type.getValue(), row->objvar_6_value.getValue()); + commands.push_back(c); + } + if (row->objvar_7_type.getValue() >= 0) + { + row->objvar_7_name.getValue(c.key); + c.value.load(7, row->objvar_7_type.getValue(), row->objvar_7_value.getValue()); + commands.push_back(c); + } + if (row->objvar_8_type.getValue() >= 0) + { + row->objvar_8_name.getValue(c.key); + c.value.load(8, row->objvar_8_type.getValue(), row->objvar_8_value.getValue()); + commands.push_back(c); + } + if (row->objvar_9_type.getValue() >= 0) + { + row->objvar_9_name.getValue(c.key); + c.value.load(9, row->objvar_9_type.getValue(), row->objvar_9_value.getValue()); + commands.push_back(c); + } + if (row->objvar_10_type.getValue() >= 0) + { + row->objvar_10_name.getValue(c.key); + c.value.load(10, row->objvar_10_type.getValue(), row->objvar_10_value.getValue()); + commands.push_back(c); + } + if (row->objvar_11_type.getValue() >= 0) + { + row->objvar_11_name.getValue(c.key); + c.value.load(11, row->objvar_11_type.getValue(), row->objvar_11_value.getValue()); + commands.push_back(c); + } + if (row->objvar_12_type.getValue() >= 0) + { + row->objvar_12_name.getValue(c.key); + c.value.load(12, row->objvar_12_type.getValue(), row->objvar_12_value.getValue()); + commands.push_back(c); + } + if (row->objvar_13_type.getValue() >= 0) + { + row->objvar_13_name.getValue(c.key); + c.value.load(13, row->objvar_13_type.getValue(), row->objvar_13_value.getValue()); + commands.push_back(c); + } + if (row->objvar_14_type.getValue() >= 0) + { + row->objvar_14_name.getValue(c.key); + c.value.load(14, row->objvar_14_type.getValue(), row->objvar_14_value.getValue()); + commands.push_back(c); + } + if (row->objvar_15_type.getValue() >= 0) + { + row->objvar_15_name.getValue(c.key); + c.value.load(15, row->objvar_15_type.getValue(), row->objvar_15_value.getValue()); + commands.push_back(c); + } + if (row->objvar_16_type.getValue() >= 0) + { + row->objvar_16_name.getValue(c.key); + c.value.load(16, row->objvar_16_type.getValue(), row->objvar_16_value.getValue()); + commands.push_back(c); + } + if (row->objvar_17_type.getValue() >= 0) + { + row->objvar_17_name.getValue(c.key); + c.value.load(17, row->objvar_17_type.getValue(), row->objvar_17_value.getValue()); + commands.push_back(c); + } + if (row->objvar_18_type.getValue() >= 0) + { + row->objvar_18_name.getValue(c.key); + c.value.load(18, row->objvar_18_type.getValue(), row->objvar_18_value.getValue()); + commands.push_back(c); + } + if (row->objvar_19_type.getValue() >= 0) + { + row->objvar_19_name.getValue(c.key); + c.value.load(19, row->objvar_19_type.getValue(), row->objvar_19_value.getValue()); + commands.push_back(c); + } +} + +// ---------------------------------------------------------------------- + +int ObjectTableBuffer::encodeObjVarFreeFlags(const NetworkId & objectId) const +{ + const DBSchema::ObjectBufferRow *row=findConstRowByIndex(objectId); + WARNING_STRICT_FATAL(row==NULL,("Loading object %s, no ObjectRow in the buffer\n",objectId.getValueString().c_str())); + if (!row) + return 0; + + int positionFlags=0; + + for (int i=0; iobjvar_0_type.getValue() < 0); + break; + case 1: + free = (row->objvar_1_type.getValue() < 0); + break; + case 2: + free = (row->objvar_2_type.getValue() < 0); + break; + case 3: + free = (row->objvar_3_type.getValue() < 0); + break; + case 4: + free = (row->objvar_4_type.getValue() < 0); + break; + case 5: + free = (row->objvar_5_type.getValue() < 0); + break; + case 6: + free = (row->objvar_6_type.getValue() < 0); + break; + case 7: + free = (row->objvar_7_type.getValue() < 0); + break; + case 8: + free = (row->objvar_8_type.getValue() < 0); + break; + case 9: + free = (row->objvar_9_type.getValue() < 0); + break; + case 10: + free = (row->objvar_10_type.getValue() < 0); + break; + case 11: + free = (row->objvar_11_type.getValue() < 0); + break; + case 12: + free = (row->objvar_12_type.getValue() < 0); + break; + case 13: + free = (row->objvar_13_type.getValue() < 0); + break; + case 14: + free = (row->objvar_14_type.getValue() < 0); + break; + case 15: + free = (row->objvar_15_type.getValue() < 0); + break; + case 16: + free = (row->objvar_16_type.getValue() < 0); + break; + case 17: + free = (row->objvar_17_type.getValue() < 0); + break; + case 18: + free = (row->objvar_18_type.getValue() < 0); + break; + case 19: + free = (row->objvar_19_type.getValue() < 0); + break; + default: + DEBUG_FATAL(true,("Iterated through too many positions. WTF?")); + } + + if (free) + positionFlags += s_positionMasks[i]; + } + + return positionFlags; +} + +// ---------------------------------------------------------------------- + +void ObjectTableBuffer::getWorldContainers(std::vector &containers) const +{ + for (IndexType::const_iterator r=m_rows.begin(); r!=m_rows.end(); ++r) + { + if ((r->second->contained_by.getValue()==NetworkId::cms_invalid) && (r->second->load_contents.getValue())) + containers.push_back(r->second->object_id.getValue()); + } +} + +// ---------------------------------------------------------------------- + +bool ObjectTableBuffer::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary) +{ + DBSchema::ObjectBufferRow * const row=findRowByIndex(sourceObject); + if (!row) + return false; + + // We might have buffered values for bank balance, cash balance, both, or neither + // We can only change the ones for which we have a value. + bool const definiteBankBalance = !row->bank_balance.isNull(); + bool const definiteCashBalance = !row->cash_balance.isNull(); + + int const previousBankBalance = definiteBankBalance ? row->bank_balance.getValue() : 0; + int const previousCashBalance = definiteCashBalance ? row->cash_balance.getValue() : 0; + + if (previousBankBalance + previousCashBalance < amount) + { + if (definiteBankBalance && definiteCashBalance) + { + // send failure message + GetMoneyFromOfflineObjectMessage replyMessage(sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary, false); + DatabaseProcess::getInstance().sendToGameServer(replyServer, replyMessage); + } + else + return false; // can't be handled in memory, but there's a possibility it could be handled in the DB + } + + // Has enough money to handle this in memory + + int newBankBalance = previousBankBalance - amount; + int newCashBalance = previousCashBalance; + if (newBankBalance < 0) + { + int const remainingAmount = -newBankBalance; + newBankBalance = 0; + newCashBalance -= remainingAmount; + DEBUG_FATAL(newCashBalance < 0,("Programmer bug: newCashBalance ended up negative, which should not be possible. Indicates bad logic in getMoneyFromOfflineObject()")); + } + + if (definiteBankBalance) + row->bank_balance=newBankBalance; + if (definiteCashBalance) + row->cash_balance=newCashBalance; + + // Send success message + GetMoneyFromOfflineObjectMessage replyMessage(sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary, true); + DatabaseProcess::getInstance().sendToGameServer(replyServer, replyMessage); + + return true; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjectTableBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjectTableBuffer.h new file mode 100644 index 00000000..372da7e0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjectTableBuffer.h @@ -0,0 +1,78 @@ +// ====================================================================== +// +// ObjectTableBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ObjectTableBuffer_H +#define INCLUDED_ObjectTableBuffer_H + +// ====================================================================== + +#include "IndexedNetworkTableBuffer.h" + +#include "SwgDatabaseServer/ObjectsTableQuery.h" +#include "sharedFoundation/DynamicVariableList.h" +#include "sharedFoundation/Tag.h" + +// ====================================================================== + +class NetworkId; +class UpdateObjectPositionMessage; + +namespace DB +{ + class Session; +} +namespace DBSchema +{ + struct ObjectRow; +} +namespace ObjectTableBufferNamespace +{ + const int ms_maxItemsPerExec = 10000; +} + +using namespace ObjectTableBufferNamespace; + + +// ====================================================================== + +class ObjectTableBuffer : public IndexedNetworkTableBuffer +{ +public: + explicit ObjectTableBuffer(DB::ModeQuery::Mode mode); + virtual ~ObjectTableBuffer(); + +// virtual void loadRow(DB::Session *session, const NetworkId &primaryKey); + + virtual bool handleUpdateObjectPosition(const UpdateObjectPositionMessage &message); + void handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool demandLoadedContainer, bool cascadeDeleteReason); + void decodeObjVarFreeFlags(const NetworkId &objectId, int freePositions); + int encodeObjVarFreeFlags(const NetworkId & objectId) const; + void handlePackedObjvar(const NetworkId &objectId, int position, const std::string &objvarName, int typeId, const std::string &packedValue); + void getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const; + bool getMoneyFromOfflineObject(uint32 replyServer,NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary); + + void newObject(const NetworkId &objectId, int templateId, Tag typeId); + +// std::vector queueForLoadWithContents(const stdvector::fwd &oidList, DB::Session *session); + + void getObjectList(stdvector::fwd &theList) const; + void getWorldContainers(stdvector::fwd &containers) const; + void getTags(DB::TagSet &tags) const; + + virtual bool save(DB::Session *session); + + private: + static int roundToNode(real coordinate); + std::vector > m_demandLoadedContainersToDelete; + + private: + ObjectTableBuffer(); // disable +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp new file mode 100644 index 00000000..bf736c7c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.cpp @@ -0,0 +1,348 @@ +// ====================================================================== +// +// ObjvarBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "ObjvarBuffer.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +namespace ObjvarBufferNamespace +{ + const int ms_maxItemsPerExec = 10000; +} + +using namespace ObjvarBufferNamespace; + +// ====================================================================== + +ObjvarBuffer::ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames) : + AbstractTableBuffer(), + m_mode(mode), + m_data(), + m_objectTableBuffer(objectTableBuffer), + m_useGoldNames(useGoldNames) +{ +} + +// ---------------------------------------------------------------------- + +ObjvarBuffer::~ObjvarBuffer() +{ +} + +// ---------------------------------------------------------------------- + +/** + * Loads all the object variables for the remembered objectId's + */ + +bool ObjvarBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + int rowsFetched; + UNREF(tags); // all objects have objvars + + DBQuery::GetAllObjectVariables qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator row=data.begin(); row!=data.end(); ++row) + { + if (++count > numRows) + { + break; + } + + IndexKey key(row->object_id.getValue(), row->name_id.getValue()); + ObjvarValue value; + value.m_type=row->type.getValue(); + + // The string is stored in the database as utf8, so a wide-to-narrow is appropriate + value.m_value=Unicode::wideToNarrow(row->value.getValue()); + + value.m_detached=false; + + m_data.insert(std::make_pair(key,value)); + } + } + + qry.done(); + if (rowsFetched < 0) + return false; + + if (usingGoldDatabase) + { + // Check for local overrides to the gold data + DBQuery::GetObjectVariableOverrides qry(DatabaseProcess::getInstance().getSchemaQualifier(), schema); + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator row=data.begin(); row!=data.end(); ++row) + { + if (++count > numRows) + { + break; + } + + IndexKey key(row->object_id.getValue(), row->name_id.getValue()); + ObjvarValue value; + value.m_type=row->type.getValue(); + + // The string is stored in the database as utf8, so a wide-to-narrow is appropriate + value.m_value=Unicode::wideToNarrow(row->value.getValue()); + + value.m_detached=false; + + m_overrides.insert(std::make_pair(key,value)); + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +bool ObjvarBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("Objvars: %i saved to db",m_data.size())); + + { + DBQuery::AddObjectVariableQuery addQuery; + if (!addQuery.setupData(session)) + return false; + for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + if (!i->second.m_detached && !i->second.m_inDatabase) + if (!addQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value)) + return false; + if (addQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&addQuery))) + return false; + addQuery.clearData(); + } + } + if (addQuery.getNumItems() != 0) + if (! (session->exec(&addQuery))) + return false; + addQuery.done(); + addQuery.freeData(); + } + + { + DBQuery::UpdateObjectVariableQuery updateQuery; + if (!updateQuery.setupData(session)) + return false; + for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + if (!i->second.m_detached && i->second.m_inDatabase) + if (!updateQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value)) + return false; + if (updateQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&updateQuery))) + return false; + updateQuery.clearData(); + } + } + if (updateQuery.getNumItems() != 0) + if (! (session->exec(&updateQuery))) + return false; + updateQuery.done(); + updateQuery.freeData(); + } + + { + DBQuery::RemoveObjectVariableQuery removeQuery; + if (!removeQuery.setupData(session)) + return false; + for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + if (i->second.m_detached && i->second.m_inDatabase) + if (!removeQuery.addData(i->first.m_objectId, i->first.m_nameId)) + return false; + if (removeQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&removeQuery))) + return false; + removeQuery.clearData(); + } + } + if (removeQuery.getNumItems() != 0) + if (! (session->exec(&removeQuery))) + return false; + removeQuery.done(); + removeQuery.freeData(); + } + return true; +} + +// ---------------------------------------------------------------------- + +void ObjvarBuffer::getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const +{ + DynamicVariableList::MapType::Command c; + + // unpacked object variables + + { + for (DataType::const_iterator i= m_data.lower_bound(IndexKey(objectId,0)); (i!=m_data.end()) && (i->first.m_objectId==objectId); ++i) + { + std::string name; + bool foundName = false; + if (m_useGoldNames) + foundName=ObjvarNameManager::getGoldInstance().getName(i->first.m_nameId, name); + else + foundName=ObjvarNameManager::getInstance().getName(i->first.m_nameId, name); + + if (foundName) + { + c.cmd = DynamicVariableList::MapType::Command::ADD; + c.key = name; + c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value)); + + commands.push_back(c); + } + else + WARNING_STRICT_FATAL(true,("Object %s has an objvar with name_id %i, which was not in the list of names.",objectId.getValueString().c_str(), i->first.m_nameId)); + } + } + + //packed object variables + + m_objectTableBuffer->getObjvarsForObject(objectId, commands); + + // Apply overrides, if any. + // The last objvar sent to the game takes precedence, so we want to send the overrides after the values read in through the regular process + + { + for (DataType::const_iterator i= m_overrides.lower_bound(IndexKey(objectId,0)); (i!=m_overrides.end()) && (i->first.m_objectId==objectId); ++i) + { + std::string name; + bool foundName = false; + foundName=ObjvarNameManager::getInstance().getName(i->first.m_nameId, name); // overrides always use the live names, not the gold names. + + if (foundName) + { + c.cmd = DynamicVariableList::MapType::Command::ADD; + c.key = name; + c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value)); + + commands.push_back(c); + } + else + WARNING_STRICT_FATAL(true,("Object %s has an objvar with name_id %i, which was not in the list of names.",objectId.getValueString().c_str(), i->first.m_nameId)); + } + } +} + +// ---------------------------------------------------------------------- + +void ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vector &commands) +{ + bool override=false; // flag that we're dealing with the gold data override case (storing an objvar change in the live database, on an object that came from the gold database) + if (ConfigServerDatabase::getEnableGoldDatabase() && objectId < ConfigServerDatabase::getMaxGoldNetworkId()) + override=true; + + for (std::vector::const_iterator i=commands.begin(); i!=commands.end(); ++i) + { + switch(i->cmd) + { + case DynamicVariableList::MapType::Command::ADD : + case DynamicVariableList::MapType::Command::SET : + { + std::string packedValue(Unicode::wideToUTF8(i->value.getPackedValueString())); + + if (i->value.getPosition() !=-1 && ConfigServerDatabase::getEnableObjvarPacking() && !override) + { + m_objectTableBuffer->handlePackedObjvar(objectId, i->value.getPosition(), i->key, i->value.getType(), packedValue); + } + else + { + int nameId = ObjvarNameManager::getInstance().getOrAddNameId(i->key); + + DataType::iterator row=m_data.find(IndexKey(objectId, nameId)); + if (row==m_data.end()) + { + row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first; + if (i->cmd==DynamicVariableList::MapType::Command::ADD || override) + row->second.m_inDatabase=false; // new variable + else + row->second.m_inDatabase=true; // update to existing variable + } + row->second.m_type = i->value.getType(); + row->second.m_value = packedValue; + row->second.m_detached = false; + } + break; + } + + case DynamicVariableList::MapType::Command::ERASE : + { + int nameId = ObjvarNameManager::getInstance().getNameId(i->key); + if (nameId != 0) // It's possible to get an ERASE for a packed objvar where the name was never used in the OBJECT_VARIABLES table. We can safely ignore these. + { + DataType::iterator row=m_data.find(IndexKey(objectId, nameId)); + if (row==m_data.end()) + { + if (i->value.getPosition() == -1 || override) + { + row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first; + row->second.m_inDatabase=true; // deleting existing variable + } + // else it was a packed objvar, and no update is necessary + } + + row->second.m_type = i->value.getType(); + row->second.m_detached = true; + } + break; + } + + default: + WARNING_STRICT_FATAL(true,("Unknown command %i unpacked in object variables for object %s.",i->cmd,objectId.getValueString().c_str())); + } + } + + DEBUG_WARNING(commands.size() > 100,("Object %s has a suspicious number of objvar updates (%i updates).",objectId.getValueString().c_str(),commands.size())); +} + +// ---------------------------------------------------------------------- + +void ObjvarBuffer::removeObject(const NetworkId &object) +{ + DataType::iterator i=m_data.lower_bound(IndexKey(object,0)); + while (i!=m_data.end() && i->first.m_objectId==object) + { + DataType::iterator next=i; + ++next; + m_data.erase(i); + i=next; + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h new file mode 100644 index 00000000..61ff386b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ObjvarBuffer.h @@ -0,0 +1,122 @@ +// ====================================================================== +// +// ObjvarBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ObjvarBuffer_H +#define INCLUDED_ObjvarBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/ObjectTableBuffer.h" +#include "SwgDatabaseServer/ObjectVariableQueries.h" +#include "serverDatabase/AbstractTableBuffer.h" +#include "sharedFoundation/DynamicVariableList.h" +#include +#include + +// ====================================================================== + +class ObjectTableBuffer; +namespace DBSchema +{ + struct ObjvarRow; +} + +// ====================================================================== + +/** + * ObjvarBuffer is a table buffer customized to the job of loading and + * saving object variables. + * + * Differences from standard table buffers: + * + * 1) Objvars are keyed by object_id and name + * + * 2) When loading, only the object_id is specified, and all objvars + * are loaded for that object. + */ + +class ObjvarBuffer : public AbstractTableBuffer +{ +public: + explicit ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames); + virtual ~ObjvarBuffer(void); + + virtual bool load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + virtual void removeObject(const NetworkId &object); + + DBSchema::ObjectVariableRow *findRowByIndex(const NetworkId &objectId, const std::string &name); + + void updateObjvars(const NetworkId &objectId, const std::vector &commands); + void getObjvarsForObject(const NetworkId &objectId, std::vector &commands) const; + + private: + struct IndexKey + { + NetworkId m_objectId; + int m_nameId; + + IndexKey(const NetworkId &objectId, int nameId); + bool operator==(const IndexKey &rhs) const; + bool operator<(const IndexKey &rhs) const; + }; + + struct ObjvarValue + { + int m_type; + std::string m_value; + bool m_detached; + bool m_inDatabase; + }; + + typedef std::map DataType; + + DB::ModeQuery::Mode m_mode; + DataType m_data; + DataType m_overrides; + ObjectTableBuffer *m_objectTableBuffer; + bool m_useGoldNames; + +// typedef std::map > LoadIndexType; +// LoadIndexType m_loadIndex; + + private: + ObjvarBuffer(); //disable + ObjvarBuffer(const ObjvarBuffer&); //disable + ObjvarBuffer & operator=(const ObjvarBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +inline ObjvarBuffer::IndexKey::IndexKey(const NetworkId &objectId, int nameId) : + m_objectId(objectId), + m_nameId(nameId) +{ +} + +// ---------------------------------------------------------------------- + +inline bool ObjvarBuffer::IndexKey::operator==(const IndexKey &rhs) const +{ + return ((m_objectId == rhs.m_objectId) && (m_nameId == rhs.m_nameId)); +} + +// ---------------------------------------------------------------------- + +inline bool ObjvarBuffer::IndexKey::operator<(const IndexKey &rhs) const +{ + if (m_objectId < rhs.m_objectId) + return true; + else if (m_objectId == rhs.m_objectId) + return (m_nameId < rhs.m_nameId); + else + return false; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/PropertyListBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/PropertyListBuffer.cpp new file mode 100644 index 00000000..e60b08b0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/PropertyListBuffer.cpp @@ -0,0 +1,263 @@ +// ====================================================================== +// +// PropertyListBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "PropertyListBuffer.h" + +#include "SwgDatabaseServer/PropertyListQuery.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +using namespace PropertyListBufferNamespace; + +// ====================================================================== + +PropertyListBuffer::PropertyListBuffer(DB::ModeQuery::Mode mode) : + TableBuffer(mode), + m_loadData() +{ +} + +// ---------------------------------------------------------------------- + +PropertyListBuffer::~PropertyListBuffer(void) +{ +} + +// ---------------------------------------------------------------------- + +void PropertyListBuffer::insertProperty(const NetworkId &objectId, int listId, const std::string &value) +{ + PropertyListEntry entry(objectId, listId, value); + m_adds.insert(entry); + m_deletes.erase(entry); // if this add cancels out a previous delete, don't save the delete +} + +// ---------------------------------------------------------------------- + +void PropertyListBuffer::deleteProperty(const NetworkId &objectId, int listId, const std::string &value) +{ + PropertyListEntry entry(objectId, listId, value); + m_deletes.insert(entry); + m_adds.erase(entry); // if this delete cancels out a previous add, don't save the add +} + +// ---------------------------------------------------------------------- + +void PropertyListBuffer::clearProperties(const NetworkId &objectId, int listId) +{ + static const std::string emptyString; + PropertyListEntry entry(objectId, listId, emptyString); + + // erase any changes we saved for this object & list previously. For each set, find the range + // of entries corresponding to this object & list, then erase them + PropertyListSet::iterator startOfRange = m_deletes.lower_bound(entry); + PropertyListSet::iterator endOfRange; + for (endOfRange = startOfRange; + endOfRange!=m_deletes.end() && endOfRange->m_objectId == objectId && endOfRange->m_listId == listId; + ++endOfRange) + ; + m_deletes.erase(startOfRange, endOfRange); + + startOfRange = m_adds.lower_bound(entry); + for (endOfRange = startOfRange; + endOfRange!=m_adds.end() && endOfRange->m_objectId == objectId && endOfRange->m_listId == listId; + ++endOfRange) + ; + m_adds.erase(startOfRange, endOfRange); + + m_clears.insert(entry); +} + +// ---------------------------------------------------------------------- + +/** + * Get all the commands for a particular object and value type. + */ + +bool PropertyListBuffer::getPropertyListForObject(const NetworkId &objectId, int listId, std::set &values) const +{ + static const std::string emptyString; + + DEBUG_FATAL(!values.empty(),("Values vector should be empty on call to getPropertyListsForObject()\n")); + + // The data is ordered by object id then by list id, so start with the first entry matching the object id and list id. + // Return all the entries in sequence until we move to the next list or the next object + for (PropertyListSet::const_iterator i = m_loadData.lower_bound(PropertyListEntry(objectId, listId, emptyString)); + i!=m_loadData.end() && i->m_objectId == objectId && i->m_listId == listId; + ++i) + { + values.insert(i->m_value); + } + + return true; +} + +// ---------------------------------------------------------------------- + +bool PropertyListBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched; + UNREF(tags); + + DBQuery::GetAllPropertyLists qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + const DBSchema::PropertyListQueryData &row=*i; + m_loadData.insert(PropertyListEntry(row.object_id.getValue(), row.list_id.getValue(), row.value.getValueASCII())); + } + } + + qry.done(); + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +bool PropertyListBuffer::save(DB::Session *session) +{ + DBQuery::PropertyListQuery qry_ot_CLEAR; + DBQuery::PropertyListQuery qry_ot_DELETE; + DBQuery::PropertyListQuery qry_ot_INSERT; + int actualSaves=0; + + if (!qry_ot_DELETE.setupData(session)) return false; + if (!qry_ot_INSERT.setupData(session)) return false; + if (!qry_ot_CLEAR.setupData(session)) return false; + + // Clears must be done first, so that we don't clear something we were trying to add + { + for (PropertyListSet::const_iterator i=m_clears.begin(); i!=m_clears.end(); ++i) + { + if (m_cancelledObjects.find(i->m_objectId) == m_cancelledObjects.end()) + { + ++actualSaves; + if (!qry_ot_CLEAR.addData(i->m_objectId, i->m_listId, i->m_value, DBSchema::PropertyListQueryData::ot_CLEAR)) + return false; + if (qry_ot_CLEAR.getNumItems() == PropertyListBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry_ot_CLEAR))) + return false; + qry_ot_CLEAR.clearData(); + } + } + } + if (qry_ot_CLEAR.getNumItems() != 0) + { + if (! (session->exec(&qry_ot_CLEAR))) + return false; + } + qry_ot_CLEAR.done(); + qry_ot_CLEAR.freeData(); + } + + { + for (PropertyListSet::const_iterator i=m_adds.begin(); i!=m_adds.end(); ++i) + { + if (m_cancelledObjects.find(i->m_objectId) == m_cancelledObjects.end()) + { + ++actualSaves; + if (!qry_ot_INSERT.addData(i->m_objectId, i->m_listId, i->m_value, DBSchema::PropertyListQueryData::ot_INSERT)) + return false; + if (qry_ot_INSERT.getNumItems() == PropertyListBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry_ot_INSERT))) + return false; + qry_ot_INSERT.clearData(); + } + } + } + if (qry_ot_INSERT.getNumItems() != 0) + { + if (! (session->exec(&qry_ot_INSERT))) + return false; + } + qry_ot_INSERT.done(); + qry_ot_INSERT.freeData(); + } + + { + for (PropertyListSet::const_iterator i=m_deletes.begin(); i!=m_deletes.end(); ++i) + { + if (m_cancelledObjects.find(i->m_objectId) == m_cancelledObjects.end()) + { + ++actualSaves; + if (!qry_ot_DELETE.addData(i->m_objectId, i->m_listId, i->m_value, DBSchema::PropertyListQueryData::ot_DELETE)) + return false; + if (qry_ot_DELETE.getNumItems() == PropertyListBufferNamespace::ms_maxItemsPerExec) + { + if (! (session->exec(&qry_ot_DELETE))) + return false; + qry_ot_DELETE.clearData(); + } + } + } + if (qry_ot_DELETE.getNumItems() != 0) + { + if (! (session->exec(&qry_ot_DELETE))) + return false; + } + qry_ot_DELETE.done(); + qry_ot_DELETE.freeData(); + } + + LOG("SaveCounts",("PropertyList updates: %i (out of %i) saved to db",actualSaves, m_rows.size())); + return true; +} + +// ---------------------------------------------------------------------- + +void PropertyListBuffer::removeObject(const NetworkId &object) +{ + m_cancelledObjects.insert(object); +} + +// ====================================================================== + +PropertyListBuffer::PropertyListEntry::PropertyListEntry() : + m_objectId(), + m_listId(0), + m_value() +{ +} + +// ---------------------------------------------------------------------- + +PropertyListBuffer::PropertyListEntry::PropertyListEntry(const PropertyListBuffer::PropertyListEntry & rhs) : + m_objectId(rhs.m_objectId), + m_listId(rhs.m_listId), + m_value(rhs.m_value) +{ +} + +// ---------------------------------------------------------------------- + +PropertyListBuffer::PropertyListEntry & PropertyListBuffer::PropertyListEntry::operator=(const PropertyListBuffer::PropertyListEntry & rhs) +{ + m_objectId=rhs.m_objectId; + m_listId=rhs.m_listId; + m_value=rhs.m_value; + + return *this; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/PropertyListBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/PropertyListBuffer.h new file mode 100644 index 00000000..c610dd9a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/PropertyListBuffer.h @@ -0,0 +1,135 @@ +// ====================================================================== +// +// PropertyListBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_PropertyListBuffer_H +#define INCLUDED_PropertyListBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/PropertyListQuery.h" +#include "serverDatabase/TableBuffer.h" +#include "sharedFoundation/NetworkId.h" + +#include +#include + +// ====================================================================== + +namespace PropertyListBufferNamespace +{ + const int ms_maxItemsPerExec = 10000; +} + +using namespace PropertyListBufferNamespace; + +// ====================================================================== + +/** + * PropertyListBuffer is a buffer customized to the job of loading and + * saving lists of sets. + * + * This buffer does not combine changes. All operations given to it are + * sent to the database. + */ + +class PropertyListBuffer : public TableBuffer +{ + public: + // WARNING: Do not renumber anything in this list. You will break objects that are already persisted. + // If you remove something from the list, leave the numbers of other items unchanged + enum ListIds + { + LI_Commands=0, + LI_DraftSchematics=1, + // removed: LI_PvpEnemies=2, + LI_Allowed=3, + LI_Banned=4, + LI_GuildNames=5, + LI_GuildAbbrevs=6, + LI_GuildMembers=7, + LI_GuildEnemies=8, + LI_GuildLeaders=10, + LI_Skills=11, + LI_Cities=12, + LI_Citizens=13, + LI_CityStructures=14 + }; + +public: + explicit PropertyListBuffer(DB::ModeQuery::Mode mode); + virtual ~PropertyListBuffer(void); + + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save(DB::Session *session); + virtual void removeObject(const NetworkId &object); + + bool getPropertyListForObject(const NetworkId &objectId, int listId, std::set &values) const; + + void insertProperty (const NetworkId &objectId, int listId, const std::string &value); + void deleteProperty (const NetworkId &objectId, int listId, const std::string &value); + void clearProperties(const NetworkId &objectId, int listId); + + private: + struct PropertyListEntry + { + NetworkId m_objectId; + int m_listId; + std::string m_value; + + PropertyListEntry(const NetworkId &objectId, int listId, const std::string &value); + bool operator<(const PropertyListEntry &rhs) const; + + PropertyListEntry(); + PropertyListEntry(const PropertyListEntry & rhs); + PropertyListEntry & operator=(const PropertyListEntry & rhs); + }; + + typedef std::set PropertyListSet; + PropertyListSet m_loadData; + + PropertyListSet m_adds; + PropertyListSet m_deletes; + PropertyListSet m_clears; + + typedef std::set OIDList; + OIDList m_cancelledObjects; + + private: + PropertyListBuffer(); //disable + PropertyListBuffer(const PropertyListBuffer&); //disable + PropertyListBuffer & operator=(const PropertyListBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +inline PropertyListBuffer::PropertyListEntry::PropertyListEntry(const NetworkId &objectId, int listId, const std::string &value) : + m_objectId(objectId), + m_listId(listId), + m_value(value) +{ +} + +// ---------------------------------------------------------------------- + +inline bool PropertyListBuffer::PropertyListEntry::operator<(const PropertyListEntry &right) const +{ + if (m_objectId < right.m_objectId) + return true; + if (m_objectId == right.m_objectId) + { + if (m_listId < right.m_listId) + return true; + if (m_listId == right.m_listId) + return m_value < right.m_value; + } + return false; +} + +// ====================================================================== + +#endif + diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ResourceTypeBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ResourceTypeBuffer.cpp new file mode 100644 index 00000000..0784be9b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ResourceTypeBuffer.cpp @@ -0,0 +1,266 @@ +// ====================================================================== +// +// ResourceTypeBuffer.cpp +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/ResourceTypeBuffer.h" + +#include "SwgDatabaseServer/ResourceTypeQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/GameServerConnection.h" +#include "serverGame/ServerPlanetObjectTemplate.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +ResourceTypeBuffer::ResourceTypeBuffer() : + AbstractTableBuffer(), + m_data() +{ +} + +// ---------------------------------------------------------------------- + +ResourceTypeBuffer::~ResourceTypeBuffer() +{ + for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + delete i->second; + i->second=NULL; + } +} + +// ---------------------------------------------------------------------- + +void ResourceTypeBuffer::handleAddResourceTypeMessage(AddResourceTypeMessage const & message) +{ + for (std::vector::const_iterator typeData = message.getData().begin(); typeData != message.getData().end(); ++typeData) + { + DBSchema::ResourceTypeRow * row = NULL; + DataType::iterator rowIter = m_data.find(typeData->m_networkId); + if (rowIter == m_data.end()) + { + row = new DBSchema::ResourceTypeRow; + row->resource_id = typeData->m_networkId; + m_data.insert(std::make_pair(typeData->m_networkId, row)); + } + else + row=rowIter->second; + + row->resource_name = typeData->m_name; + row->resource_class = typeData->m_parentClass; + row->depleted_timestamp = typeData->m_depletedTimestamp; + + // Pack attributes: + { + std::string packedAttributes; + for (std::vector >::const_iterator i=typeData->m_attributes.begin(); i!=typeData->m_attributes.end(); ++i) + { + char buffer[256]; + snprintf(buffer, 256, "%s %i:", i->first.c_str(), i->second); + buffer[255]='\0'; + packedAttributes+=buffer; + } + if (packedAttributes.size()==0) + packedAttributes=" "; + row->attributes = packedAttributes; + } + + // Pack fractal seeds: + { + std::string packedSeeds; + for (std::vector >::const_iterator i=typeData->m_fractalSeeds.begin(); i!=typeData->m_fractalSeeds.end(); ++i) + { + char buffer[256]; + snprintf(buffer, 256, "%s %i:", i->first.getValueString().c_str(), i->second); + buffer[255]='\0'; + packedSeeds+=buffer; + } + if (packedSeeds.size()==0) + packedSeeds=" "; + row->fractal_seeds = packedSeeds; + } + } +} + +// ---------------------------------------------------------------------- + +void ResourceTypeBuffer::sendResourceTypeObjects(GameServerConnection & conn) const +{ + if (m_data.empty()) + return; + + std::vector resourceTypeDataVector; + for (DataType::const_iterator row = m_data.begin(); row != m_data.end(); ++row) + { + AddResourceTypeMessageNamespace::ResourceTypeData typeData; + + NOT_NULL(row->second); + + row->second->resource_id.getValue(typeData.m_networkId); + row->second->resource_name.getValue(typeData.m_name); + row->second->resource_class.getValue(typeData.m_parentClass); + row->second->depleted_timestamp.getValue(typeData.m_depletedTimestamp); + + // unpack attributes: + { + std::string packedAttributes; + row->second->attributes.getValue(packedAttributes); + static const int BUFSIZE = 256; + char buffer[BUFSIZE]; + char *bufpos = buffer; + std::string currentAttributeName; + for (std::string::iterator i = packedAttributes.begin(); i != packedAttributes.end() && bufpos < buffer + BUFSIZE; ++i) + { + if ((*i) == ' ') + { + *bufpos = '\0'; + currentAttributeName = buffer; + + // remove double quotes around some double quoted resource name + if (currentAttributeName.find_first_of('"') == 0) + { + std::string::size_type const closingQuote = currentAttributeName.find_last_of('"'); + if ((closingQuote >= 2) && (closingQuote == (currentAttributeName.size() - 1))) + currentAttributeName = currentAttributeName.substr(1, (closingQuote - 1)); + } + + bufpos = buffer; + } + else if ((*i) == ':') + { + *bufpos = '\0'; + typeData.m_attributes.push_back(std::make_pair(currentAttributeName, atoi(buffer))); + bufpos = buffer; + } + else + { + *(bufpos++) = *i; + } + } + } + + // unpack fractal seeds: + { + std::string packedSeeds; + row->second->fractal_seeds.getValue(packedSeeds); + static const int BUFSIZE = 256; + char buffer[BUFSIZE]; + char *bufpos = buffer; + NetworkId currentPlanetId; + for (std::string::iterator i = packedSeeds.begin(); i != packedSeeds.end() && bufpos < buffer + BUFSIZE; ++i) + { + if ((*i) == ' ') + { + *bufpos = '\0'; + currentPlanetId = NetworkId(std::string(buffer)); + bufpos = buffer; + } + else if ((*i) == ':') + { + *bufpos = '\0'; + typeData.m_fractalSeeds.push_back(std::make_pair(currentPlanetId, atoi(buffer))); + bufpos = buffer; + } + else + { + *(bufpos++) = *i; + } + } + } + + resourceTypeDataVector.push_back(typeData); + } + + AddResourceTypeMessage msg(resourceTypeDataVector); + conn.send(msg,true); +} + +// ---------------------------------------------------------------------- + +bool ResourceTypeBuffer::save(DB::Session *session) +{ + if (m_data.empty()) + return true; + + int actualSaves=0; + DBQuery::ResourceTypeQuery qry; + if (!qry.setupData(session)) + return false; + + for (DataType::const_iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + ++actualSaves; + NOT_NULL(i->second); + if (!qry.addData(*(i->second))) + return false; + + if (qry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize()) + { + if (! (session->exec(&qry))) + return false; + qry.clearData(); + } + } + + if (qry.getNumItems() != 0) + if (! (session->exec(&qry))) + return false; + + qry.done(); + qry.freeData(); + + LOG("SaveCounts",("Resource types: %i saved in db",actualSaves)); + return true; +} + +// ---------------------------------------------------------------------- + +bool ResourceTypeBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase) +{ + int rowsFetched = 0; + // Resource data is associated with PlanetObjects, so load it if the planets are being loaded + if (tags.find(ServerPlanetObjectTemplate::ServerPlanetObjectTemplate_tag)!=tags.end()) + { + DEBUG_REPORT_LOG(true,("Loading resource types\n")); + DBQuery::ResourceTypeQuerySelect qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t const numRows = qry.getNumRowsFetched(); + size_t count = 0; + std::vector const & data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + DBSchema::ResourceTypeRow *row=new DBSchema::ResourceTypeRow(*i); + NOT_NULL(row); + NetworkId temp; + row->resource_id.getValue(temp); + m_data.insert(std::make_pair(row->resource_id.getValue(), row)); + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +void ResourceTypeBuffer::removeObject(const NetworkId &object) +{ +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ResourceTypeBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ResourceTypeBuffer.h new file mode 100644 index 00000000..40829d95 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ResourceTypeBuffer.h @@ -0,0 +1,58 @@ +// ====================================================================== +// +// ResourceTypeBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ResourceTypeBuffer_H +#define INCLUDED_ResourceTypeBuffer_H + +// ====================================================================== + +#include "serverDatabase/AbstractTableBuffer.h" +#include "serverNetworkMessages/AddResourceTypeMessage.h" + +// ====================================================================== + +namespace DB +{ + class Session; +} + +namespace DBSchema +{ + struct ResourceTypeRow; +} + +class GameServerConnection; + +// ====================================================================== + +/** + * A buffer to hold resource type data. + */ +class ResourceTypeBuffer : public AbstractTableBuffer +{ + public: + void handleAddResourceTypeMessage (AddResourceTypeMessage const & message); + void sendResourceTypeObjects (GameServerConnection & conn) const; + + virtual bool save(DB::Session *session); + virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual void removeObject(const NetworkId &object); + + public: + ResourceTypeBuffer(); + virtual ~ResourceTypeBuffer(); + + private: + typedef std::map DataType; + + private: + DataType m_data; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ScriptBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/ScriptBuffer.cpp new file mode 100644 index 00000000..e9959565 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ScriptBuffer.cpp @@ -0,0 +1,131 @@ +// ====================================================================== +// +// ScriptBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "ScriptBuffer.h" + +#include "serverDatabase/ScriptQueries.h" +#include "sharedDatabaseInterface/DbSession.h" +#include +#include +#include + +// ====================================================================== + +ScriptBuffer::ScriptBuffer() : + m_loadedData(new LoadedDataType) +{ +} + +// ---------------------------------------------------------------------- + +ScriptBuffer::~ScriptBuffer() +{ + delete m_loadedData; + m_loadedData=0; +} + +// ---------------------------------------------------------------------- + +void ScriptBuffer::clearScripts(const NetworkId &objectId) +{ + m_objectsToClear.insert(objectId); +} + +// ---------------------------------------------------------------------- + +bool ScriptBuffer::save(DB::Session *session) +{ + DBQuery::ScriptClearQuery clearQry; + + for (std::set::const_iterator i=m_objectsToClear.begin(); i!=m_objectsToClear.end(); ++i) + { + clearQry.setNetworkId(*i); + if (! (session->exec(&clearQry))) + return false; + } + + clearQry.done(); + return true; +} + +// ---------------------------------------------------------------------- + +bool ScriptBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched; + UNREF(tags); // any object can have scripts + + DBQuery::GetScripts qry(schema); + + if (! (session->exec(&qry))) + return false; + + std::string scriptName; + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + i->script_name.getValue(scriptName); + (*m_loadedData)[IndexKey(i->object_id.getValue(),i->index.getValue())]=scriptName; + } + } + + qry.done(); + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +void ScriptBuffer::getScriptsForObject(const NetworkId &objectId, std::vector &scripts) const +{ + scripts.clear(); + +#ifdef _DEBUG + int expectedIndex = 0; +#endif + + for (LoadedDataType::const_iterator i=m_loadedData->find(IndexKey(objectId,0)); (i!=m_loadedData->end()) && (i->first.m_objectId==objectId); ++i) + { + DEBUG_WARNING((i->first.m_index != expectedIndex++), ("Programmer bug: Script buffer was not sorted, or there were gaps in the sequence. ObjectId %s, sequence number %i\n",objectId.getValueString().c_str(),i->first.m_index)); + scripts.push_back(i->second); + } +} + +// ---------------------------------------------------------------------- + +void ScriptBuffer::removeObject(const NetworkId &object) +{ + m_objectsToClear.erase(object); +} + +// ====================================================================== + +ScriptBuffer::IndexKey::IndexKey(const NetworkId &objectId, int index) : + m_objectId(objectId), + m_index(index) +{ +} + +// ---------------------------------------------------------------------- + +bool ScriptBuffer::IndexKey::operator<(const IndexKey &rhs) const +{ + if (m_objectId == rhs.m_objectId) + return (m_index < rhs.m_index); + else + return (m_objectId < rhs.m_objectId); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/ScriptBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/ScriptBuffer.h new file mode 100644 index 00000000..a848d712 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/ScriptBuffer.h @@ -0,0 +1,74 @@ +// ====================================================================== +// +// ScriptBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ScriptBuffer_H +#define INCLUDED_ScriptBuffer_H + +// ====================================================================== + +#include +#include +#include +#include +#include +#include "serverDatabase/AbstractTableBuffer.h" +#include "sharedFoundation/NetworkId.h" +#include "sharedLog/Log.h" + +namespace DB +{ + class Session; +} + +// ====================================================================== + +/** + * A buffer to hold script attach & detach commands. + * Unlike many of the other buffers, this does not attempt to combine + * operations (e.g. match up a detach with an attach already in the buffer, + * and so skip sending either to the database). Instead, it just keeps a + * list of everything to do. + */ +class ScriptBuffer : public AbstractTableBuffer +{ + public: + void clearScripts(const NetworkId &objectId); + + virtual bool save(DB::Session *session); + virtual bool load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual void removeObject(const NetworkId &object); + + void addObject(const NetworkId &objectId); + + void getScriptsForObject(const NetworkId &objectId, std::vector &scripts) const; + + ScriptBuffer(); + virtual ~ScriptBuffer(); + + private: + class IndexKey + { + public: + NetworkId m_objectId; + int m_index; + + public: + IndexKey(const NetworkId &objectId, int index); + + public: + bool operator<(const IndexKey &rhs) const; + }; + + std::set m_objectsToClear; + + typedef stdmap::fwd LoadedDataType; + LoadedDataType *m_loadedData; // data loaded from the database +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/WaypointBuffer.cpp b/game/server/application/SwgDatabaseServer/src/shared/buffers/WaypointBuffer.cpp new file mode 100644 index 00000000..67a1cc32 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/WaypointBuffer.cpp @@ -0,0 +1,158 @@ +// ====================================================================== +// +// WaypointBuffer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/WaypointBuffer.h" + +#include "SwgDatabaseServer/Schema.h" +#include "SwgDatabaseServer/WaypointQuery.h" +#include "serverGame/ServerMissionObjectTemplate.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "sharedDatabaseInterface/DbException.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedUtility/Location.h" +#include "sharedLog/Log.h" +#include + + +// ====================================================================== + +WaypointBuffer::WaypointBuffer(DB::ModeQuery::Mode mode) : + AbstractTableBuffer(), + m_mode(mode), + m_data() +{ +} + +// ---------------------------------------------------------------------- + +WaypointBuffer::~WaypointBuffer(void) +{ +} + +// ---------------------------------------------------------------------- + +void WaypointBuffer::setWaypoint(const NetworkId &objectId, const NetworkId &waypointId, const PersistableWaypoint &value) +{ + m_data[IndexKey(objectId,waypointId)] = value; +} + +// ---------------------------------------------------------------------- + +bool WaypointBuffer::getWaypointsForObject(const NetworkId &objectId, stdvector::fwd &values) const +{ + DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getWaypointForObject()\n")); + IndexType::const_iterator i ( m_data.lower_bound(IndexKey(objectId,NetworkId::cms_invalid)) ); + if (i==m_data.end()) + return false; + for (; (i!=m_data.end()) && (i->first.m_objectId==objectId); ++i) + { + std::string temp; + values.push_back(i->second); + } + return true; +} + +// ---------------------------------------------------------------------- + +bool WaypointBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool) +{ + int rowsFetched = 0; + if ( tags.find(static_cast(ServerPlayerObjectTemplate::ServerPlayerObjectTemplate_tag)) != tags.end() + || tags.find(static_cast(ServerMissionObjectTemplate::ServerMissionObjectTemplate_tag)) != tags.end()) + { + DBQuery::GetAllWaypoints qry(schema); + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + const DBSchema::WaypointRow &row=*i; + PersistableWaypoint temp; + temp.m_appearanceNameCrc = row.appearance_name_crc.getValue(); + temp.m_location = Location(Vector(static_cast(row.location_x.getValue()), + static_cast(row.location_y.getValue()), + static_cast(row.location_z.getValue())), + row.location_cell.getValue(),row.location_scene.getValue()); + temp.m_name = row.name.getValue(); + temp.m_networkId = row.waypoint_id.getValue(); + temp.m_color = static_cast(row.color.getValue()); + temp.m_active = row.active.getValue(); + temp.m_detached = false; + + m_data[IndexKey(row.object_id.getValue(),temp.m_networkId)]=temp; + } + } + + qry.done(); + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +bool WaypointBuffer::save(DB::Session *session) +{ + LOG("SaveCounts",("Waypoint: %i saved to db",m_data.size())); + + DBQuery::WaypointQuery qry; + + if (m_mode==DB::ModeQuery::mode_INSERT) + qry.insertMode(); + else + qry.updateMode(); + + for (IndexType::iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + DBSchema::WaypointRow row; + + row.object_id = i->first.m_objectId; + row.waypoint_id = i->first.m_waypointId; + row.appearance_name_crc = i->second.m_appearanceNameCrc; + row.location_x = i->second.m_location.getCoordinates().x; + row.location_y = i->second.m_location.getCoordinates().y; + row.location_z = i->second.m_location.getCoordinates().z; + row.location_cell = i->second.m_location.getCell(); + row.location_scene = i->second.m_location.getSceneIdCrc(); + row.name = i->second.m_name; + row.color = i->second.m_color; + row.active = i->second.m_active; + row.detached = i->second.m_detached; + + qry.setData(row); + if (! (session->exec(&qry))) + return false; + } + qry.done(); + return true; +} + +// ---------------------------------------------------------------------- + +void WaypointBuffer::removeObject(const NetworkId &object) +{ + IndexType::iterator i=m_data.lower_bound(IndexKey(object,NetworkId::cms_invalid)); + while (i!=m_data.end() && i->first.m_objectId==object) + { + IndexType::iterator next=i; + ++next; + m_data.erase(i); + i=next; + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/buffers/WaypointBuffer.h b/game/server/application/SwgDatabaseServer/src/shared/buffers/WaypointBuffer.h new file mode 100644 index 00000000..94b3c9c9 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/buffers/WaypointBuffer.h @@ -0,0 +1,98 @@ +// ====================================================================== +// +// WaypointBuffer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_WaypointBuffer_H +#define INCLUDED_WaypointBuffer_H + +// ====================================================================== + +#include "SwgDatabaseServer/PersistableWaypoint.h" +#include "SwgDatabaseServer/Schema.h" +#include "SwgDatabaseServer/WaypointQuery.h" +#include "serverDatabase/AbstractTableBuffer.h" + +#include +#include + +// ====================================================================== + +class WaypointBuffer : public AbstractTableBuffer +{ +public: + explicit WaypointBuffer (DB::ModeQuery::Mode mode); + virtual ~WaypointBuffer (); + + virtual bool load (DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase); + virtual bool save (DB::Session *session); + virtual void removeObject (const NetworkId &object); + + void setWaypoint (const NetworkId &objectId, const NetworkId &waypointId, const PersistableWaypoint &value); + void removeWaypoint (const NetworkId &objectId, const NetworkId &waypointId); + bool getWaypointsForObject(const NetworkId &objectId, stdvector::fwd &values) const; + + private: + struct IndexKey + { + NetworkId m_objectId; + NetworkId m_waypointId; + + IndexKey(const NetworkId &objectId, const NetworkId &waypointId); + bool operator==(const IndexKey &rhs) const; + bool operator<(const IndexKey &rhs) const; + }; + typedef std::map IndexType; + + DB::ModeQuery::Mode m_mode; + IndexType m_data; + + private: + WaypointBuffer(); //disable + WaypointBuffer(const WaypointBuffer&); //disable + WaypointBuffer & operator=(const WaypointBuffer&); //disable +}; //lint !e1712 // IndexKey has no default constructor + +// ====================================================================== + +inline WaypointBuffer::IndexKey::IndexKey(const NetworkId &objectId, const NetworkId &waypointId) : + m_objectId(objectId), + m_waypointId(waypointId) +{ +} + +// ---------------------------------------------------------------------- + +inline bool WaypointBuffer::IndexKey::operator==(const IndexKey &rhs) const +{ + return ((m_objectId == rhs.m_objectId) && (m_waypointId == rhs.m_waypointId)); +} + +// ---------------------------------------------------------------------- + +inline bool WaypointBuffer::IndexKey::operator< (const IndexKey &rhs) const +{ + if (m_objectId == rhs.m_objectId) + return (m_waypointId < rhs.m_waypointId); + else + return (m_objectId < rhs.m_objectId); +} + +// ---------------------------------------------------------------------- + +/** + * + */ +inline void WaypointBuffer::removeWaypoint(const NetworkId &objectId, const NetworkId &waypointId) +{ + PersistableWaypoint temp; + temp.m_networkId=waypointId; + temp.m_detached=true; + setWaypoint(objectId,waypointId,temp); +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/DataCleanupManager.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/DataCleanupManager.cpp new file mode 100644 index 00000000..d5fbc9d5 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/DataCleanupManager.cpp @@ -0,0 +1,157 @@ +// ====================================================================== +// +// DataCleanupManager.cpp +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "DataCleanupManager.h" + +#include "SwgDatabaseServer/TaskConsolidateExperience.h" +#include "SwgDatabaseServer/TaskDailyCleanup.h" +#include "SwgDatabaseServer/TaskAnySQL.h" +#include "SwgDatabaseServer/TaskObjvarNameCleanup.h" +#include "SwgDatabaseServer/TaskOrphanedObjectCleanup.h" +#include "SwgDatabaseServer/TaskMarketAttributesCleanup.h" +#include "SwgDatabaseServer/TaskMessagesCleanup.h" +#include "SwgDatabaseServer/TaskBrokenObjectCleanup.h" +#include "SwgDatabaseServer/TaskVendorObjectCleanup.h" +#include "SwgDatabaseServer/TaskFixBadCells.h" +#include "SwgDatabaseServer/TaskObjectTemplateListUpdater.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbTaskQueue.h" +#include "sharedLog/Log.h" +#include "sharedLog/LogManager.h" +#include "sharedFoundation/Os.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverMetrics/MetricsManager.h" +#include "sharedNetwork/NetworkHandler.h" + +// ====================================================================== + +DataCleanupManager::DataCleanupManager() : + m_taskQueue(new DB::TaskQueue(1, DatabaseProcess::getInstance().getDBServer(), 0)) +{ +} + +// ---------------------------------------------------------------------- + +DataCleanupManager::~DataCleanupManager() +{ + delete m_taskQueue; // Note: The destructor of TaskQueue waits for all the tasks to be finished +} + +// ---------------------------------------------------------------------- + +void DataCleanupManager::runDailyCleanup( void ) +{ + if ( ConfigServerDatabase::getEnableFixBadCells() ) // do this first... + { + TaskFixBadCells *task = new TaskFixBadCells; + m_taskQueue->asyncRequest(task); + } + + if ( ConfigServerDatabase::getObjectTemplateListUpdateFilename() != 0) + { + TaskObjectTemplateListUpdater *task = new TaskObjectTemplateListUpdater( ConfigServerDatabase::getObjectTemplateListUpdateFilename() ); + m_taskQueue->asyncRequest(task); + } + + if ( ConfigServerDatabase::getEnableDataCleanup() ) + { + if ( ConfigServerDatabase::getExperienceConsolidationTime() != 0) + { + TaskConsolidateExperience *task = new TaskConsolidateExperience( ConfigServerDatabase::getExperienceConsolidationTime() ); + m_taskQueue->asyncRequest(task); + } + + if ( ConfigServerDatabase::getObjvarNameCleanupTime() != 0) + { + TaskObjvarNameCleanup *task = new TaskObjvarNameCleanup( ConfigServerDatabase::getObjvarNameCleanupTime() ); + m_taskQueue->asyncRequest(task); + } + + if ( ConfigServerDatabase::getOrphanedObjectCleanupTime() != 0) + { + TaskOrphanedObjectCleanup *task = new TaskOrphanedObjectCleanup( ConfigServerDatabase::getOrphanedObjectCleanupTime() ); + m_taskQueue->asyncRequest(task); + } + + LOG("Cleanup:attributes:",("%d", ConfigServerDatabase::getMarketAttributesCleanupTime() )); + if ( ConfigServerDatabase::getMarketAttributesCleanupTime() != 0) + { + TaskMarketAttributesCleanup *task = new TaskMarketAttributesCleanup( ConfigServerDatabase::getMarketAttributesCleanupTime() ); + m_taskQueue->asyncRequest(task); + } + + LOG("Cleanup:messages:",("%d", ConfigServerDatabase::getMarketAttributesCleanupTime() )); + if ( ConfigServerDatabase::getMessagesCleanupTime() != 0) + { + TaskMessagesCleanup *task = new TaskMessagesCleanup( ConfigServerDatabase::getMessagesCleanupTime() ); + m_taskQueue->asyncRequest(task); + } + + LOG("Cleanup:brokenobj:",("%d", ConfigServerDatabase::getBrokenObjectCleanupTime() )); + if ( ConfigServerDatabase::getBrokenObjectCleanupTime() != 0) + { + TaskBrokenObjectCleanup *task = new TaskBrokenObjectCleanup( ConfigServerDatabase::getBrokenObjectCleanupTime() ); + m_taskQueue->asyncRequest(task); + } + + if ( ConfigServerDatabase::getVendorObjectCleanupTime() != 0) + { + TaskVendorObjectCleanup *task = new TaskVendorObjectCleanup( ConfigServerDatabase::getVendorObjectCleanupTime() ); + m_taskQueue->asyncRequest(task); + } + } + + + // + // Open custom sql file and execute everything in there (in queries folder) + // + std::string s_filename( ConfigServerDatabase::getCustomSQLFilename() ); + if ( s_filename.length() ) + { + std::string s_path( "../../src/game/server/database/queries/" ); + s_path += s_filename; + FILE* in = fopen(s_path.c_str(), "r"); + if ( in ) + { + char line[4096]; + std::string s_sql; + while( fgets(line, 4096, in ) ) + { + if ( line[0] != '#' ) + s_sql+=line; + if ( s_sql.find(';') != std::string::npos ) + { + TaskAnySQL *task = new TaskAnySQL( s_sql.c_str() ); + m_taskQueue->asyncRequest( task ); + s_sql.clear(); + } + } + fclose( in ); + } + else + { + LOG("Cleanup:AnySQL:",("Couldn't open: %s",s_path.c_str())); + } + } + + + // Sleep until all the cleanup is done.... + while( m_taskQueue->isIdle() == false ) + { + const int ki_sleeptime = 100; + Os::sleep(ki_sleeptime); + m_taskQueue->update(float(ki_sleeptime) / float(1000.0)); + MetricsManager::update(float(ki_sleeptime) / float(1000.0)); + NetworkHandler::update(); + NetworkHandler::dispatch(); + NetworkHandler::clearBytesThisFrame(); + } +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/DataCleanupManager.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/DataCleanupManager.h new file mode 100644 index 00000000..9f5eeae4 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/DataCleanupManager.h @@ -0,0 +1,39 @@ +// ====================================================================== +// +// DataCleanupManager.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_DataCleanupManager_H +#define INCLUDED_DataCleanupManager_H + +// ====================================================================== + +namespace DB +{ + class TaskQueue; +} + +// ====================================================================== + +/** + * Class to run cleanup scripts on the database before starting + * the cluster. This class can be deleted when its work is complete. + */ +class DataCleanupManager +{ + public: + DataCleanupManager(); + ~DataCleanupManager(); + + public: + void runDailyCleanup( ); + + private: + DB::TaskQueue * m_taskQueue; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskAnySQL.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskAnySQL.cpp new file mode 100644 index 00000000..57cb9cec --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskAnySQL.cpp @@ -0,0 +1,71 @@ +// ====================================================================== +// +// TaskAnySQL.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskAnySQL.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +bool TaskAnySQL::process(DB::Session *session) +{ + LOG("TaskANYSQL",("%s", m_sSQL.c_str() )); + AnyQuery qry( m_sSQL.c_str() ); + return (session->exec(&qry)); +} + +// ---------------------------------------------------------------------- + +void TaskAnySQL::onComplete() +{ +} + +// ====================================================================== + +TaskAnySQL::AnyQuery::AnyQuery( const char* pSQL ) : m_sSQL(pSQL) +{ + // Erase trailing semicolon from each line + size_t pos = m_sSQL.rfind(';'); + if ( pos != std::string::npos ) + m_sSQL.erase( pos ); +} + +// ---------------------------------------------------------------------- + +void TaskAnySQL::AnyQuery::getSQL(std::string &sql) +{ + sql=m_sSQL; +} + +// ---------------------------------------------------------------------- + +bool TaskAnySQL::AnyQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskAnySQL::AnyQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskAnySQL::AnyQuery::getExecutionMode() const +{ + return MODE_DML; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskAnySQL.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskAnySQL.h new file mode 100644 index 00000000..0547e2ba --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskAnySQL.h @@ -0,0 +1,52 @@ +// ====================================================================== +// +// TaskAnySQL.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskAnySQL_H +#define INCLUDED_TaskAnySQL_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include + +// ====================================================================== + +/** + * Run arbitrary cleanup SQL (doesn't support any input or output) + */ +class TaskAnySQL : public DB::TaskRequest +{ + public: + TaskAnySQL( const char* pSQL ) : m_sSQL(pSQL) {} + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class AnyQuery : public DB::Query + { + public: + AnyQuery( const char* pSQL ); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: + AnyQuery(const AnyQuery&); + AnyQuery& operator=(const AnyQuery&); + + + std::string m_sSQL; + }; + std::string m_sSQL; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskBrokenObjectCleanup.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskBrokenObjectCleanup.cpp new file mode 100644 index 00000000..38275fc4 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskBrokenObjectCleanup.cpp @@ -0,0 +1,80 @@ +// ====================================================================== +// +// TaskBrokenObjectCleanup.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskBrokenObjectCleanup.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +bool TaskBrokenObjectCleanup::process(DB::Session *session) +{ + time_t t_start = time(0); + while( (time(0) - t_start) < m_tSeconds ) // limit the run time + { + DataCleanupQuery qry; + if ( session->exec(&qry) == false ) + { + LOG("TaskBrokenObjectCleanup::process",( "returned false!" )); + return false; + } + LOG("TaskBrokenObjectCleanup::process",("ROWS = %d", qry.result.getValue() )); + if( qry.result.getValue() == 0 ) // cleanup done + break; + } + LOG("TaskBrokenObjectCleanup",("TIME = %d", time(0)-t_start )); + return true; +} + +// ---------------------------------------------------------------------- + +void TaskBrokenObjectCleanup::onComplete() +{ +} + +// ====================================================================== + +TaskBrokenObjectCleanup::DataCleanupQuery::DataCleanupQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskBrokenObjectCleanup::DataCleanupQuery::getSQL(std::string &sql) +{ + sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.broken_object_cleanup(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskBrokenObjectCleanup::DataCleanupQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskBrokenObjectCleanup::DataCleanupQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskBrokenObjectCleanup::DataCleanupQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskBrokenObjectCleanup.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskBrokenObjectCleanup.h new file mode 100644 index 00000000..ff96a9f0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskBrokenObjectCleanup.h @@ -0,0 +1,55 @@ +// ====================================================================== +// +// TaskBrokenObjectCleanup.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskBrokenObjectCleanup_H +#define INCLUDED_TaskBrokenObjectCleanup_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/Bindable.h" +#include + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskBrokenObjectCleanup : public DB::TaskRequest +{ + public: + TaskBrokenObjectCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; } + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + time_t m_tSeconds; + + class DataCleanupQuery : public DB::Query + { + public: + DataCleanupQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + DB::BindableLong result; + + private: + DataCleanupQuery(const DataCleanupQuery&); + DataCleanupQuery& operator=(const DataCleanupQuery&); + + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskConsolidateExperience.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskConsolidateExperience.cpp new file mode 100644 index 00000000..fc2bba45 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskConsolidateExperience.cpp @@ -0,0 +1,311 @@ +// ====================================================================== +// +// TaskConsolidateExperience.cpp +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/TaskConsolidateExperience.h" + +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedDebug/PerformanceTimer.h" +#include "sharedFoundation/NetworkId.h" +#include +#include +#include + +// ====================================================================== + +TaskConsolidateExperience::TaskConsolidateExperience(float timeLimit) : + m_timeLimit(timeLimit) +{ +} + +// ---------------------------------------------------------------------- + +TaskConsolidateExperience::~TaskConsolidateExperience() +{ +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::process(DB::Session *session) +{ + int rowsFetched = 0; + NOT_NULL(session); + + session->setAutoCommitMode(false); + + PerformanceTimer timer; + timer.start(); + + std::vector objectQueue; + { + // Make an ordered list of objects with lots of messages pending + FindLotsOfMessagesQuery qry; + if (! (session->exec(&qry))) + return false; + while ((rowsFetched = qry.fetch()) > 0) + { + objectQueue.push_back(qry.getNetworkId()); + } + } + if (rowsFetched < 0) + return false; + + for (std::vector::const_iterator objectToClean=objectQueue.begin(); objectToClean!=objectQueue.end() && timer.getSplitTime() < m_timeLimit; ++objectToClean) + { + bool bail=false; + std::map experiencePoints; + { + // Total up the experience grants for the object + GetExperienceQuery qry(*objectToClean); + if (! (session->exec(&qry))) + return false; + while ((rowsFetched = qry.fetch()) > 0 && !bail) + { + std::string type; + int amount; + if (splitExperience(qry.getData(), type, amount)) + { + experiencePoints[type]+=amount; + } + else + { + WARNING(true,("Unrecognized experience string \"%s\" for object %s. Bailing out of experience consolidation for this object.\n", + qry.getData().c_str(), objectToClean->getValueString().c_str())); + bail=true; + } + } + } + if (rowsFetched < 0) + return false; + + if (!bail) + { + { + // delete all xp grants + DeleteExperienceQuery qry(*objectToClean); + if (! (session->exec(&qry))) + return false; + } + + { + // replace with simplified grants + GrantExperienceQuery qry; + + for (std::map::const_iterator i=experiencePoints.begin(); i!=experiencePoints.end(); ++i) + { + qry.setData(*objectToClean, makeExperienceString(i->first, i->second)); + if (! (session->exec(&qry))) + return false; + } + } + + session->commitTransaction(); + } + bail=false; + } + return true; +} + +// ---------------------------------------------------------------------- + +void TaskConsolidateExperience::onComplete() +{ +} + +// ---------------------------------------------------------------------- + +/** + * Convert packed experience data into the type name and the amount. + */ +bool TaskConsolidateExperience::splitExperience(const std::string &packedData, std::string &type, int &amount) const +{ + size_t spacePos=packedData.find(' '); + if (spacePos==std::string::npos) return false; + type=std::string(packedData,0,spacePos); + std::string amountString(packedData,spacePos+1,static_cast(std::string::npos)); + amount=atoi(amountString.c_str()); + if (amount <= 0) return false; // string is probably badly-formed or parsed wrong + return true; +} + +// ---------------------------------------------------------------------- + +std::string TaskConsolidateExperience::makeExperienceString(const std::string &type, int amount) +{ + char buffer[1000]; + snprintf(buffer,1000,"%s %i",type.c_str(), amount); + return std::string(buffer); +} + +// ====================================================================== + +TaskConsolidateExperience::FindLotsOfMessagesQuery::FindLotsOfMessagesQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskConsolidateExperience::FindLotsOfMessagesQuery::getSQL(std::string &sql) +{ + sql="begin :rc := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.getObjectsWithExpMessages(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::FindLotsOfMessagesQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::FindLotsOfMessagesQuery::bindColumns() +{ + if (!bindCol(object_id)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskConsolidateExperience::FindLotsOfMessagesQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ---------------------------------------------------------------------- + +NetworkId TaskConsolidateExperience::FindLotsOfMessagesQuery::getNetworkId() const +{ + return object_id.getValue(); +} + +// ====================================================================== + +TaskConsolidateExperience::GetExperienceQuery::GetExperienceQuery(const NetworkId &objectId) : + object_id(objectId) +{ +} + +// ---------------------------------------------------------------------- + +void TaskConsolidateExperience::GetExperienceQuery::getSQL(std::string &sql) +{ + sql="begin :rc := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.getExperienceGrants(:object_id); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::GetExperienceQuery::bindParameters() +{ + if (!bindParameter(object_id)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::GetExperienceQuery::bindColumns() +{ + if (!bindCol(grant_data)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskConsolidateExperience::GetExperienceQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ---------------------------------------------------------------------- + +const std::string TaskConsolidateExperience::GetExperienceQuery::getData() const +{ + return grant_data.getValueASCII(); +} + +// ====================================================================== + +TaskConsolidateExperience::DeleteExperienceQuery::DeleteExperienceQuery(const NetworkId &objectId) : + object_id(objectId) +{ +} + +// ---------------------------------------------------------------------- + +void TaskConsolidateExperience::DeleteExperienceQuery::getSQL(std::string &sql) +{ + sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.delete_experience(:object_id); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::DeleteExperienceQuery::bindParameters() +{ + if (!bindParameter(object_id)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::DeleteExperienceQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskConsolidateExperience::DeleteExperienceQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ====================================================================== + +TaskConsolidateExperience::GrantExperienceQuery::GrantExperienceQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskConsolidateExperience::GrantExperienceQuery::getSQL(std::string &sql) +{ + sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.grant_experience(:object_id, :experience_data); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::GrantExperienceQuery::bindParameters() +{ + if (!bindParameter(object_id)) return false; + if (!bindParameter(experience_data)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskConsolidateExperience::GrantExperienceQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskConsolidateExperience::GrantExperienceQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +void TaskConsolidateExperience::GrantExperienceQuery::setData(const NetworkId &objectId, const std::string &data) +{ + object_id=objectId; + experience_data=data; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskConsolidateExperience.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskConsolidateExperience.h new file mode 100644 index 00000000..671d50d7 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskConsolidateExperience.h @@ -0,0 +1,128 @@ +// ====================================================================== +// +// TaskConsolidateExperience.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskConsolidateExperience_H +#define INCLUDED_TaskConsolidateExperience_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" + +// ====================================================================== + +/** + * Look for players with lots of pending experience grants, combine them + * into a single grant with the sum of the experience. + * + * A time limit can be specified, in which case this task will do as much + * as it can before the time limit expires. + */ +class TaskConsolidateExperience : public DB::TaskRequest +{ + public: + TaskConsolidateExperience(float timeLimit); + ~TaskConsolidateExperience(); + + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class FindLotsOfMessagesQuery : public DB::Query + { + public: + FindLotsOfMessagesQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + NetworkId getNetworkId() const; + + private: + DB::BindableNetworkId object_id; + + private: + FindLotsOfMessagesQuery(const FindLotsOfMessagesQuery&); + FindLotsOfMessagesQuery& operator=(const FindLotsOfMessagesQuery&); + }; + + class GetExperienceQuery : public DB::Query + { + public: + GetExperienceQuery(const NetworkId &objectId); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + const std::string getData() const; + + private: + DB::BindableNetworkId object_id; + DB::BindableString<1000> grant_data; + + private: + GetExperienceQuery(const GetExperienceQuery&); + GetExperienceQuery& operator=(const GetExperienceQuery&); + }; + + class DeleteExperienceQuery : public DB::Query + { + public: + DeleteExperienceQuery(const NetworkId &targetObject); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: + DB::BindableNetworkId object_id; + + private: + DeleteExperienceQuery(const DeleteExperienceQuery&); + DeleteExperienceQuery& operator=(const DeleteExperienceQuery&); + }; + + class GrantExperienceQuery : public DB::Query + { + public: + GrantExperienceQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + void setData(const NetworkId &objectId, const std::string &data); + + private: + DB::BindableNetworkId object_id; + DB::BindableString<1000> experience_data; + + private: + GrantExperienceQuery(const GrantExperienceQuery&); + GrantExperienceQuery& operator=(const GrantExperienceQuery&); + }; + + private: + bool splitExperience(const std::string &packedData, std::string &type, int &amount) const; + std::string makeExperienceString(const std::string &type, int amount); + + private: + float m_timeLimit; +}; + + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskDailyCleanup.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskDailyCleanup.cpp new file mode 100644 index 00000000..13229093 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskDailyCleanup.cpp @@ -0,0 +1,66 @@ +// ====================================================================== +// +// TaskDailyCleanup.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskDailyCleanup.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" + +// ====================================================================== + +bool TaskDailyCleanup::process(DB::Session *session) +{ + DataCleanupQuery qry; + return (session->exec(&qry)); +} + +// ---------------------------------------------------------------------- + +void TaskDailyCleanup::onComplete() +{ + DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : TaskDailyCleanup::onComplete().\n")); +} + +// ====================================================================== + +TaskDailyCleanup::DataCleanupQuery::DataCleanupQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskDailyCleanup::DataCleanupQuery::getSQL(std::string &sql) +{ + sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.run_cleanup(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskDailyCleanup::DataCleanupQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskDailyCleanup::DataCleanupQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskDailyCleanup::DataCleanupQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskDailyCleanup.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskDailyCleanup.h new file mode 100644 index 00000000..5be5e4bc --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskDailyCleanup.h @@ -0,0 +1,46 @@ +// ====================================================================== +// +// TaskDailyCleanup.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskDailyCleanup_H +#define INCLUDED_TaskDailyCleanup_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskDailyCleanup : public DB::TaskRequest +{ + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class DataCleanupQuery : public DB::Query + { + public: + DataCleanupQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: + DataCleanupQuery(const DataCleanupQuery&); + DataCleanupQuery& operator=(const DataCleanupQuery&); + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskFixBadCells.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskFixBadCells.cpp new file mode 100644 index 00000000..ea5da243 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskFixBadCells.cpp @@ -0,0 +1,68 @@ +// ====================================================================== +// +// TaskFixBadCells.cpp +// copyright (c) 2005 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskFixBadCells.h" + +#include "serverDatabase/DatabaseProcess.h" +//#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" + +// ====================================================================== + +bool TaskFixBadCells::process(DB::Session *session) +{ + FixBadCellsQuery qry; + DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : Processing Bad Cells Query.\n")); + return (session->exec(&qry)); +} + +// ---------------------------------------------------------------------- + +void TaskFixBadCells::onComplete() +{ + DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : TaskFixBadCells::onComplete().\n")); +} + +// ====================================================================== + +TaskFixBadCells::FixBadCellsQuery::FixBadCellsQuery() +{ + DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : TaskFixBadCells::FixBadCellsQuery::FixBadCellsQuery().\n")); +} + +// ---------------------------------------------------------------------- + +void TaskFixBadCells::FixBadCellsQuery::getSQL(std::string &sql) +{ + sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.run_fix_bad_cells(); end;"; + DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : Query : %s.\n", sql.c_str())); +} + +// ---------------------------------------------------------------------- + +bool TaskFixBadCells::FixBadCellsQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskFixBadCells::FixBadCellsQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskFixBadCells::FixBadCellsQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskFixBadCells.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskFixBadCells.h new file mode 100644 index 00000000..6cbeb4e0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskFixBadCells.h @@ -0,0 +1,46 @@ +// ====================================================================== +// +// TaskFixBadCells.h +// copyright (c) 2005 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskFixBadCells_H +#define INCLUDED_TaskFixBadCells_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" + +// ====================================================================== + +/** + * Fixes cells that have the wrong load_with. + */ +class TaskFixBadCells : public DB::TaskRequest +{ + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class FixBadCellsQuery : public DB::Query + { + public: + FixBadCellsQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: + FixBadCellsQuery(const FixBadCellsQuery&); + FixBadCellsQuery& operator=(const FixBadCellsQuery&); + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMarketAttributesCleanup.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMarketAttributesCleanup.cpp new file mode 100644 index 00000000..8d241926 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMarketAttributesCleanup.cpp @@ -0,0 +1,80 @@ +// ====================================================================== +// +// TaskMarketAttributesCleanup.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskMarketAttributesCleanup.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +bool TaskMarketAttributesCleanup::process(DB::Session *session) +{ + time_t t_start = time(0); + while( (time(0) - t_start) < m_tSeconds ) // limit the run time + { + DataCleanupQuery qry; + if ( session->exec(&qry) == false ) + { + LOG("TaskMarketAttributesCleanup::process",( "returned false!" )); + return false; + } + LOG("TaskMarketAttributesCleanup::process",("ROWS = %d", qry.result.getValue() )); + if( qry.result.getValue() == 0 ) // cleanup done + break; + } + LOG("TaskMarketAttributesCleanup",("TIME = %d", time(0)-t_start )); + return true; +} + +// ---------------------------------------------------------------------- + +void TaskMarketAttributesCleanup::onComplete() +{ +} + +// ====================================================================== + +TaskMarketAttributesCleanup::DataCleanupQuery::DataCleanupQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskMarketAttributesCleanup::DataCleanupQuery::getSQL(std::string &sql) +{ + sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.market_attributes_cleanup(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskMarketAttributesCleanup::DataCleanupQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskMarketAttributesCleanup::DataCleanupQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskMarketAttributesCleanup::DataCleanupQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMarketAttributesCleanup.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMarketAttributesCleanup.h new file mode 100644 index 00000000..2d35ab60 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMarketAttributesCleanup.h @@ -0,0 +1,55 @@ +// ====================================================================== +// +// TaskMarketAttributesCleanup.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskMarketAttributesCleanup_H +#define INCLUDED_TaskMarketAttributesCleanup_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/Bindable.h" +#include + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskMarketAttributesCleanup : public DB::TaskRequest +{ + public: + TaskMarketAttributesCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; } + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + time_t m_tSeconds; + + class DataCleanupQuery : public DB::Query + { + public: + DataCleanupQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + DB::BindableLong result; + + private: + DataCleanupQuery(const DataCleanupQuery&); + DataCleanupQuery& operator=(const DataCleanupQuery&); + + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMessagesCleanup.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMessagesCleanup.cpp new file mode 100644 index 00000000..b1409cdc --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMessagesCleanup.cpp @@ -0,0 +1,80 @@ +// ====================================================================== +// +// TaskMessagesCleanup.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskMessagesCleanup.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +bool TaskMessagesCleanup::process(DB::Session *session) +{ + time_t t_start = time(0); + while( (time(0) - t_start) < m_tSeconds ) // limit the run time + { + DataCleanupQuery qry; + if ( session->exec(&qry) == false ) + { + LOG("TaskMessagesCleanup::process",( "returned false!" )); + return false; + } + LOG("TaskMessagesCleanup::process",("ROWS = %d", qry.result.getValue() )); + if( qry.result.getValue() == 0 ) // cleanup done + break; + } + LOG("TaskMessagesCleanup",("TIME = %d", time(0)-t_start )); + return true; +} + +// ---------------------------------------------------------------------- + +void TaskMessagesCleanup::onComplete() +{ +} + +// ====================================================================== + +TaskMessagesCleanup::DataCleanupQuery::DataCleanupQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskMessagesCleanup::DataCleanupQuery::getSQL(std::string &sql) +{ + sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.messages_cleanup(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskMessagesCleanup::DataCleanupQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskMessagesCleanup::DataCleanupQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskMessagesCleanup::DataCleanupQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMessagesCleanup.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMessagesCleanup.h new file mode 100644 index 00000000..0efeb860 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskMessagesCleanup.h @@ -0,0 +1,55 @@ +// ====================================================================== +// +// TaskMessagesCleanup.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskMessagesCleanup_H +#define INCLUDED_TaskMessagesCleanup_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/Bindable.h" +#include + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskMessagesCleanup : public DB::TaskRequest +{ + public: + TaskMessagesCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; } + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + time_t m_tSeconds; + + class DataCleanupQuery : public DB::Query + { + public: + DataCleanupQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + DB::BindableLong result; + + private: + DataCleanupQuery(const DataCleanupQuery&); + DataCleanupQuery& operator=(const DataCleanupQuery&); + + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjectTemplateListUpdater.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjectTemplateListUpdater.cpp new file mode 100644 index 00000000..7b73fc9b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjectTemplateListUpdater.cpp @@ -0,0 +1,122 @@ +// ====================================================================== +// +// TaskObjectTemplateListUpdater.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskObjectTemplateListUpdater.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== +// Update the object_templates table based on the contents of the crc string table file +// This file can be found in: +// ../../dsrc/sku.0/sys.server/built/game/misc/object_template_crc_string_table.tab +// +bool TaskObjectTemplateListUpdater::process(DB::Session *session) +{ + if ( m_sPath.empty() ) + return true; + FILE *in = fopen(m_sPath.c_str(),"r"); + if ( in ) + { + LOG("TaskObjectTemplateListUpdater",("File open OK" )); + + char s_sql[4096]; + int i_lines = 0; + while(1) + { + int i_id; + char s_name[4096]; + int i_retval = 0; + + if ( i_lines++ == 0 ) // do the delete first + strcpy(s_sql,"delete object_templates"); + else // read a line + { + i_retval = fscanf(in,"0x%X\t%s\n", &i_id, s_name ); // format = ID(hex) Name(string) + if ( EOF == i_retval ) // commit after final one + strcpy(s_sql,"commit"); + else if ( i_retval == 2 ) // got ID & Name + { + s_name[256]=0; // null term to make sure it fits + sprintf(s_sql,"insert into object_templates values (%d,'%s')",i_id,s_name); + } + else + continue; + } + if ( i_lines % 1000 == 0 ) // periodic log + { + LOG("TaskObjectTemplateListUpdater",("(%d) = %s", time(0), s_sql )); + } + AnyQuery qry( s_sql ); + session->exec(&qry); + if ( EOF == i_retval ) // done + break; + } + fclose(in); + } + +#ifndef WIN32 + else + { + char cwdbuf[4096]; + LOG("TaskObjectTemplateListUpdater",("Couldn't open %s from %s", m_sPath.c_str(), getcwd(cwdbuf,4096) )); + } +#endif + + return true; +} + +// ---------------------------------------------------------------------- + +void TaskObjectTemplateListUpdater::onComplete() +{ +} + +// ====================================================================== + +TaskObjectTemplateListUpdater::AnyQuery::AnyQuery( const char* pSQL ) : m_sSQL(pSQL) +{ + // Erase trailing semicolon from each line + size_t pos = m_sSQL.rfind(';'); + if ( pos != std::string::npos ) + m_sSQL.erase( pos ); +} + +// ---------------------------------------------------------------------- + +void TaskObjectTemplateListUpdater::AnyQuery::getSQL(std::string &sql) +{ + sql=m_sSQL; +} + +// ---------------------------------------------------------------------- + +bool TaskObjectTemplateListUpdater::AnyQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskObjectTemplateListUpdater::AnyQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskObjectTemplateListUpdater::AnyQuery::getExecutionMode() const +{ + return MODE_DML; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjectTemplateListUpdater.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjectTemplateListUpdater.h new file mode 100644 index 00000000..6a50b642 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjectTemplateListUpdater.h @@ -0,0 +1,57 @@ +// ====================================================================== +// +// TaskObjectTemplateListUpdater.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskObjectTemplateListUpdater_H +#define INCLUDED_TaskObjectTemplateListUpdater_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/Bindable.h" +#include + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskObjectTemplateListUpdater : public DB::TaskRequest +{ + public: + TaskObjectTemplateListUpdater( const char* sPath ) { m_sPath = sPath; } + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + std::string m_sPath; + + + + class AnyQuery : public DB::Query + { + public: + AnyQuery( const char* pSQL ); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: + AnyQuery(const AnyQuery&); + AnyQuery& operator=(const AnyQuery&); + + + std::string m_sSQL; + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjvarNameCleanup.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjvarNameCleanup.cpp new file mode 100644 index 00000000..f4b11075 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjvarNameCleanup.cpp @@ -0,0 +1,80 @@ +// ====================================================================== +// +// TaskObjvarNameCleanup.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskObjvarNameCleanup.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +bool TaskObjvarNameCleanup::process(DB::Session *session) +{ + time_t t_start = time(0); + while( (time(0) - t_start) < m_tSeconds ) // limit the run time + { + DataCleanupQuery qry; + if ( session->exec(&qry) == false ) + { + LOG("TaskObjvarNameCleanup::process",( "returned false!" )); + return false; + } + LOG("TaskObjvarNameCleanup::process",("ROWS = %d", qry.result.getValue() )); + if( qry.result.getValue() == 0 ) // cleanup done + break; + } + LOG("TaskObjvarNameCleanup",("TIME = %d", time(0)-t_start )); + return true; +} + +// ---------------------------------------------------------------------- + +void TaskObjvarNameCleanup::onComplete() +{ +} + +// ====================================================================== + +TaskObjvarNameCleanup::DataCleanupQuery::DataCleanupQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskObjvarNameCleanup::DataCleanupQuery::getSQL(std::string &sql) +{ + sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.object_variable_name_cleanup(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskObjvarNameCleanup::DataCleanupQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskObjvarNameCleanup::DataCleanupQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskObjvarNameCleanup::DataCleanupQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjvarNameCleanup.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjvarNameCleanup.h new file mode 100644 index 00000000..fd324d45 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskObjvarNameCleanup.h @@ -0,0 +1,55 @@ +// ====================================================================== +// +// TaskObjvarNameCleanup.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskObjvarNameCleanup_H +#define INCLUDED_TaskObjvarNameCleanup_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/Bindable.h" +#include + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskObjvarNameCleanup : public DB::TaskRequest +{ + public: + TaskObjvarNameCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; } + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + time_t m_tSeconds; + + class DataCleanupQuery : public DB::Query + { + public: + DataCleanupQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + DB::BindableLong result; + + private: + DataCleanupQuery(const DataCleanupQuery&); + DataCleanupQuery& operator=(const DataCleanupQuery&); + + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskOrphanedObjectCleanup.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskOrphanedObjectCleanup.cpp new file mode 100644 index 00000000..fa4cf116 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskOrphanedObjectCleanup.cpp @@ -0,0 +1,80 @@ +// ====================================================================== +// +// TaskOrphanedObjectCleanup.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskOrphanedObjectCleanup.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +bool TaskOrphanedObjectCleanup::process(DB::Session *session) +{ + time_t t_start = time(0); + while( (time(0) - t_start) < m_tSeconds ) // limit the run time + { + DataCleanupQuery qry; + if ( session->exec(&qry) == false ) + { + LOG("TaskOrphanedObjectCleanup::process",( "returned false!" )); + return false; + } + LOG("TaskOrphanedObjectCleanup::process",("ROWS = %d", qry.result.getValue() )); + if( qry.result.getValue() == 0 ) // cleanup done + break; + } + LOG("TaskOrphanedObjectCleanup",("TIME = %d", time(0)-t_start )); + return true; +} + +// ---------------------------------------------------------------------- + +void TaskOrphanedObjectCleanup::onComplete() +{ +} + +// ====================================================================== + +TaskOrphanedObjectCleanup::DataCleanupQuery::DataCleanupQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskOrphanedObjectCleanup::DataCleanupQuery::getSQL(std::string &sql) +{ + sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.orphaned_object_cleanup(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskOrphanedObjectCleanup::DataCleanupQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskOrphanedObjectCleanup::DataCleanupQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskOrphanedObjectCleanup::DataCleanupQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskOrphanedObjectCleanup.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskOrphanedObjectCleanup.h new file mode 100644 index 00000000..baafd4c2 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskOrphanedObjectCleanup.h @@ -0,0 +1,55 @@ +// ====================================================================== +// +// TaskOrphanedObjectCleanup.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskOrphanedObjectCleanup_H +#define INCLUDED_TaskOrphanedObjectCleanup_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/Bindable.h" +#include + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskOrphanedObjectCleanup : public DB::TaskRequest +{ + public: + TaskOrphanedObjectCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; } + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + time_t m_tSeconds; + + class DataCleanupQuery : public DB::Query + { + public: + DataCleanupQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + DB::BindableLong result; + + private: + DataCleanupQuery(const DataCleanupQuery&); + DataCleanupQuery& operator=(const DataCleanupQuery&); + + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskVendorObjectCleanup.cpp b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskVendorObjectCleanup.cpp new file mode 100644 index 00000000..f9b9f37b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskVendorObjectCleanup.cpp @@ -0,0 +1,80 @@ +// ====================================================================== +// +// TaskVendorObjectCleanup.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskVendorObjectCleanup.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" + +// ====================================================================== + +bool TaskVendorObjectCleanup::process(DB::Session *session) +{ + time_t t_start = time(0); + while( (time(0) - t_start) < m_tSeconds ) // limit the run time + { + DataCleanupQuery qry; + if ( session->exec(&qry) == false ) + { + LOG("TaskVendorObjectCleanup::process",( "returned false!" )); + return false; + } + LOG("TaskVendorObjectCleanup::process",("ROWS = %d", qry.result.getValue() )); + if( qry.result.getValue() == 0 ) // cleanup done + break; + } + LOG("TaskVendorObjectCleanup",("TIME = %d", time(0)-t_start )); + return true; +} + +// ---------------------------------------------------------------------- + +void TaskVendorObjectCleanup::onComplete() +{ +} + +// ====================================================================== + +TaskVendorObjectCleanup::DataCleanupQuery::DataCleanupQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskVendorObjectCleanup::DataCleanupQuery::getSQL(std::string &sql) +{ + sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.vendor_object_cleanup(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskVendorObjectCleanup::DataCleanupQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskVendorObjectCleanup::DataCleanupQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskVendorObjectCleanup::DataCleanupQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskVendorObjectCleanup.h b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskVendorObjectCleanup.h new file mode 100644 index 00000000..e715be43 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/cleanup/TaskVendorObjectCleanup.h @@ -0,0 +1,55 @@ +// ====================================================================== +// +// TaskVendorObjectCleanup.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskVendorObjectCleanup_H +#define INCLUDED_TaskVendorObjectCleanup_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/Bindable.h" +#include + +// ====================================================================== + +/** + * Runs scripts to do regular daily cleanup in the database. + */ +class TaskVendorObjectCleanup : public DB::TaskRequest +{ + public: + TaskVendorObjectCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; } + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + time_t m_tSeconds; + + class DataCleanupQuery : public DB::Query + { + public: + DataCleanupQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + DB::BindableLong result; + + private: + DataCleanupQuery(const DataCleanupQuery&); + DataCleanupQuery& operator=(const DataCleanupQuery&); + + }; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/CMLoader.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/CMLoader.cpp new file mode 100644 index 00000000..405d6a80 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/CMLoader.cpp @@ -0,0 +1,269 @@ +// ====================================================================== +// +// CMLoader.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "CMLoader.h" + +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverNetworkMessages/CommoditiesLoadDoneMessage.h" +#include "serverNetworkMessages/LoadCommoditiesMessage.h" +#include "serverNetworkMessages/GetAuctionLocationsMessage.h" +#include "serverNetworkMessages/GetMarketAuctionAttributesMessage.h" +#include "serverNetworkMessages/GetMarketAuctionBidsMessage.h" +#include "serverNetworkMessages/GetMarketAuctionsMessage.h" +#include "sharedDatabaseInterface/DbTaskQueue.h" +#include "sharedFoundation/ExitChain.h" +#include "sharedFoundation/Os.h" +#include "sharedLog/Log.h" +#include "TaskGetAuctionAttributeList.h" +#include "TaskGetAuctionList.h" +#include "TaskGetLocationList.h" +#include "TaskGetBidList.h" + +CMLoader *CMLoader::ms_instance = NULL; + +// ====================================================================== + +void CMLoader::install() +{ + DEBUG_FATAL(ms_instance, ("Installed CMLoader twice.\n")); + ms_instance = new CMLoader; + ExitChain::add(&remove, "Loader::remove"); +} + +// ---------------------------------------------------------------------- + +void CMLoader::remove() +{ + NOT_NULL(ms_instance); + delete ms_instance; + ms_instance = NULL; +} + +// ---------------------------------------------------------------------- + +CMLoader::CMLoader() : + m_tablesLoaded(0), + m_auctionLocationsCount(0), + m_marketAuctionsCount(0), + m_marketAuctionAttributesCount(0), + m_marketAuctionBidsCount(0), + m_mutex(), + m_taskQ(new DB::TaskQueue(static_cast(ConfigServerDatabase::getLoaderThreads()),DatabaseProcess::getInstance().getDBServer(),0)), + m_locationList(), + m_auctionList(), + m_auctionAttributeList(), + m_bidList(), + m_timeLoadStarted(0), // 0 means load hasn't started yet + m_loadTime(-1) // -1 means load hasn't completed yet +{ + ; +} + +// ---------------------------------------------------------------------- + +CMLoader:: ~CMLoader() +{ +} + +// ---------------------------------------------------------------------- +// It is important that commodity tables are loaded in the following order: +// AUCTION_LOCATIONS, MARKET_AUCTIONS, MARKET_AUCTION_ATTRIBUTES, and MARKET_AUCTION_BIDS. +// To make sure commodity tables are loaded in this order, TaskGetLocationList is put +// into taskQ first. When onLoadComplete for AUCTION_LOCATIONS finishes, +// TaskGetAuctionList is put into taskQ, and so on. + +void CMLoader::loadCommoditiesData() +{ + m_timeLoadStarted = time(0); // mark when the load started + m_loadTime = -1; // -1 means load hasn't completed yet + m_tablesLoaded = 0; + m_taskQ->asyncRequest(new TaskGetLocationList); + LOG("SwgDatabaseServer", ("start CommoditiesLoad")); +} + +void CMLoader::onLoadComplete(const std::string & tableName, const int count) +{ + m_tablesLoaded++; + if (tableName == "AUCTION_LOCATIONS") + { + m_auctionLocationsCount = count; + m_taskQ->asyncRequest(new TaskGetAuctionList); + LOG("SwgDatabaseServer", ("finish loading AUCTION_LOCATIONS, start loading MARKET_AUCTIONS")); + } + else if (tableName == "MARKET_AUCTIONS") + { + m_marketAuctionsCount = count; + m_taskQ->asyncRequest(new TaskGetAuctionAttributeList); + LOG("SwgDatabaseServer", ("finish loading MARKET_AUCTIONS, start loading MARKET_AUCTION_ATTRIBUTES")); + } + else if (tableName == "MARKET_AUCTION_ATTRIBUTES") + { + m_marketAuctionAttributesCount = count; + m_taskQ->asyncRequest(new TaskGetBidList); + LOG("SwgDatabaseServer", ("finish loading MARKET_AUCTION_ATTRIBUTES, start loading MARKET_AUCTION_BIDS")); + } + else if (tableName == "MARKET_AUCTION_BIDS") + { + m_marketAuctionBidsCount = count; + LOG("SwgDatabaseServer", ("finish loading MARKET_AUCTION_BIDS")); + } + else + FATAL(true, ("Unknown table %s loaded for commodities.\n", tableName.c_str())); +} + +// ---------------------------------------------------------------------- + +void CMLoader::update() +{ + volatile int i; + NOT_NULL(m_taskQ); + m_taskQ->update(0); + m_mutex.enter(); + if (! m_locationList.empty()) + { + GetAuctionLocationsMessage msg; + int numLocations = 0; + std::list::iterator locationIterator = m_locationList.begin(); + while (locationIterator != m_locationList.end()) + { + msg.addAuctionLocation( + locationIterator->m_locationId, + locationIterator->m_locationString.length(), + locationIterator->m_locationString, + locationIterator->m_ownerId, + locationIterator->m_salesTax, + locationIterator->m_salesTaxBankId, + locationIterator->m_emptyDate, + locationIterator->m_lastAccessDate, + locationIterator->m_inactiveDate, + locationIterator->m_status, + locationIterator->m_searchEnabled, + locationIterator->m_entranceCharge + ); + + if (++numLocations >= ConfigServerDatabase::getAuctionLocationLoadBatchSize()) + { + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + numLocations = 0; + msg.clearAllAuctionLocations(); + } + ++locationIterator; + } + + if (!msg.getAuctionLocations().empty()) + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + + m_locationList.clear(); + } + if (! m_auctionList.empty()) + { + GetMarketAuctionsMessage msg; + int numAuctions = 0; + std::list::iterator auctionIterator = m_auctionList.begin(); + while (auctionIterator != m_auctionList.end()) + { + msg.addAuction(auctionIterator->m_itemId, auctionIterator->m_ownerId, auctionIterator->m_creatorId, auctionIterator->m_locationId, auctionIterator->m_minBid, auctionIterator->m_buyNowPrice, auctionIterator->m_auctionTimer, auctionIterator->m_oob.length(), auctionIterator->m_oob, auctionIterator->m_userDescription.length(), auctionIterator->m_userDescription, auctionIterator->m_category, auctionIterator->m_itemTemplateId, auctionIterator->m_itemName.length(), auctionIterator->m_itemName, auctionIterator->m_itemTimer, auctionIterator->m_active, auctionIterator->m_itemSize); + if (++numAuctions >= ConfigServerDatabase::getAuctionLoadBatchSize()) + { + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + numAuctions = 0; + msg.clearAllAuctions(); + } + ++auctionIterator; + } + + if (!msg.getAuctions().empty()) + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + + m_auctionList.clear(); + } + if (! m_auctionAttributeList.empty()) + { + GetMarketAuctionAttributesMessage msg; + int numAttributes = 0; + std::list > >::iterator auctionAttributeIterator = m_auctionAttributeList.begin(); + while (auctionAttributeIterator != m_auctionAttributeList.end()) + { + msg.addAttribute(auctionAttributeIterator->first, auctionAttributeIterator->second.first, auctionAttributeIterator->second.second); + if (++numAttributes >= ConfigServerDatabase::getAuctionAttributeLoadBatchSize()) + { + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + numAttributes = 0; + msg.clearAllAttributes(); + } + ++auctionAttributeIterator; + } + + if (!msg.getAttributes().empty()) + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + + m_auctionAttributeList.clear(); + } + if (! m_bidList.empty()) + { + GetMarketAuctionBidsMessage msg; + int numBids = 0; + std::list::iterator bidIterator = m_bidList.begin(); + while (bidIterator != m_bidList.end()) + { + msg.addMarketAuctionBid(bidIterator->m_itemId, bidIterator->m_bidderId, bidIterator->m_bid, bidIterator->m_maxProxyBid); + if (++numBids >= ConfigServerDatabase::getAuctionBidLoadBatchSize()) + { + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + numBids = 0; + msg.clearAllMarketAuctionBids(); + } + ++bidIterator; + } + + if (!msg.getMarketAuctionBids().empty()) + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + + m_bidList.clear(); + } + i = m_tablesLoaded; + if (i == 4) + { + m_tablesLoaded = 0; + + // record how long it took to load + if ((m_loadTime == -1) && (m_timeLoadStarted != 0)) + m_loadTime = int((time(0) - m_timeLoadStarted) / 60); + + // commodity loading finished, send message back to CommoditiesServer + DEBUG_REPORT_LOG(true, ("Sending CommoditiesLoadDoneMessage to CommoditesServer. Auction_Locations = %d, Market_Auctions = %d, Market_Auction_Attributes = %d, Market_Auction_Bids = %d\n", + m_auctionLocationsCount, m_marketAuctionsCount, m_marketAuctionAttributesCount, m_marketAuctionBidsCount)); + LOG("SwgDatabaseServer", ("Sending CommoditiesLoadDoneMessage to CommoditesServer. Auction_Locations = %d, Market_Auctions = %d, Market_Auction_Attributes = %d, Market_Auction_Bids = %d\n", + m_auctionLocationsCount, m_marketAuctionsCount, m_marketAuctionAttributesCount, m_marketAuctionBidsCount)); + CommoditiesLoadDoneMessage msg(m_auctionLocationsCount, m_marketAuctionsCount, m_marketAuctionAttributesCount, m_marketAuctionBidsCount); + DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true); + } + m_mutex.leave(); +} + +// ---------------------------------------------------------------------- + +int CMLoader::getLoadTime() const +{ + if (m_timeLoadStarted == 0) + { + // load hasn't started yet + return 0; + } + else + { + if (m_loadTime != -1) + return m_loadTime; + else + // return how long we have been loading + return int((time(0) - m_timeLoadStarted) / 60); + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/CMLoader.h b/game/server/application/SwgDatabaseServer/src/shared/core/CMLoader.h new file mode 100644 index 00000000..bb073683 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/CMLoader.h @@ -0,0 +1,85 @@ +// ====================================================================== +// +// CMLoader.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_CMLoader_H +#define INCLUDED_CMLoader_H + +#include "serverDatabase/dBAuctionRecord.h" +#include "serverDatabase/dBBidRecord.h" +#include "serverDatabase/dBLocationRecord.h" +#include "sharedFoundation/FirstSharedFoundation.h" +#include "sharedSynchronization/Mutex.h" +#include + +// ====================================================================== + +namespace DB +{ + class TaskQueue; + class Server; +} + +/** + * Singleton that organizes and queues requests to load objects from the database. + */ +class CMLoader +{ + public: + static void install(); + static CMLoader &getInstance(); + void update(); + void onLoadComplete(const std::string & tableName, const int count); + void loadCommoditiesData(); + void addAuctionLocation(const LocationRecord & data) {m_mutex.enter(); m_locationList.push_back(data); m_mutex.leave();}; + void addAuctionLocationNoLockMutex(const LocationRecord & data) {m_locationList.push_back(data);}; + void addMarketAuctions(const AuctionRecord & data) {m_mutex.enter(); m_auctionList.push_back(data); m_mutex.leave();}; + void addMarketAuctionsNoLockMutex(const AuctionRecord & data) {m_auctionList.push_back(data);}; + void addMarketAuctionAttributes(const NetworkId & itemId, const std::string & attributeName, const Unicode::String & attributeValue) {m_mutex.enter(); m_auctionAttributeList.push_back(std::make_pair(itemId, std::make_pair(attributeName, attributeValue))); m_mutex.leave();}; + void addMarketAuctionAttributesNoLockMutex(const NetworkId & itemId, const std::string & attributeName, const Unicode::String & attributeValue) {m_auctionAttributeList.push_back(std::make_pair(itemId, std::make_pair(attributeName, attributeValue)));}; + void addMarketAuctionBid(const BidRecord & data) {m_mutex.enter(); m_bidList.push_back(data); m_mutex.leave();}; + void addMarketAuctionBidNoLockMutex(const BidRecord & data) {m_bidList.push_back(data);}; + void lockMutex() {m_mutex.enter();}; + void unlockMutex() {m_mutex.leave();}; + int getLoadTime() const; + + private: + CMLoader(); + virtual ~CMLoader(); + CMLoader(const CMLoader &); + CMLoader & operator = (const CMLoader &); + + static void remove(); + static CMLoader *ms_instance; + + int m_tablesLoaded; + int m_auctionLocationsCount; + int m_marketAuctionsCount; + int m_marketAuctionAttributesCount; + int m_marketAuctionBidsCount; + Mutex m_mutex; + + DB::TaskQueue *m_taskQ; + std::list m_locationList; + std::list m_auctionList; + std::list > > m_auctionAttributeList; + std::list m_bidList; + + time_t m_timeLoadStarted; + int m_loadTime; +}; + +// ---------------------------------------------------------------------- + +inline CMLoader &CMLoader::getInstance() +{ + NOT_NULL(ms_instance); + return *ms_instance; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/CommoditiesSnapshot.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/CommoditiesSnapshot.cpp new file mode 100644 index 00000000..8de382a0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/CommoditiesSnapshot.cpp @@ -0,0 +1,427 @@ +// ====================================================================== +// +// SwgSnapshot.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/CommoditiesSnapshot.h" + +#include "Archive/AutoDeltaSet.h" +#include "Archive/AutoDeltaVector.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" //TODO: remove after cleaning up authority transfer stuff +#include "serverDatabase/GameServerConnection.h" +#include "serverDatabase/ImmediateDeleteCustomPersistStep.h" +#include "serverDatabase/MessageToManager.h" +#include "serverDatabase/ObjectLocator.h" +#include "serverDatabase/Persister.h" +#include "serverNetworkMessages/CMCreateAuctionMessage.h" +#include "serverNetworkMessages/CMCreateAuctionBidMessage.h" +#include "serverNetworkMessages/CMCreateLocationMessage.h" +#include "serverNetworkMessages/CMDeleteAuctionMessage.h" +#include "serverNetworkMessages/CMDeleteLocationMessage.h" +#include "serverNetworkMessages/CMUpdateAuctionMessage.h" +#include "serverNetworkMessages/CMUpdateLocationMessage.h" +#include "serverUtility/MissionLocation.h" +#include "sharedFoundation/DynamicVariableList.h" +#include "sharedFoundation/GameControllerMessage.h" +#include "sharedFoundation/NetworkIdArchive.h" +#include "sharedFoundation/Os.h" +#include "sharedUtility/Location.h" +#include "sharedGame/MatchMakingId.h" +#include "sharedLog/Log.h" +#include "sharedMath/Quaternion.h" +#include "sharedMathArchive/TransformArchive.h" +#include "sharedMathArchive/VectorArchive.h" +#include "swgSharedUtility/Attributes.def" +#include "SwgDatabaseServer/ObjectTableBuffer.h" +#include "unicodeArchive/UnicodeArchive.h" + +// ====================================================================== + +/** + * Construct a snapshot. + * + * This and the header file should be the only places that the entire + * list of buffers is hard-coded. Every other place where you want to refer + * to all the buffers should use m_bufferList. This will reduce the number + * of places the code needs to be changed if new buffers are added. + * (Referring to a _specific_ buffer when you know you need that buffer + * is kosher.) + */ +CommoditiesSnapshot::CommoditiesSnapshot(DB::ModeQuery::Mode mode) : + Snapshot(mode, false), + m_deleteMarketAuctionsBuffer(), + m_deleteAuctionLocationsBuffer(DB::ModeQuery::mode_DELETE), + m_createMarketAuctionsBuffer(), + m_createAuctionLocationsBuffer(DB::ModeQuery::mode_INSERT), + m_createMarketAuctionBidsBuffer(DB::ModeQuery::mode_INSERT), + m_updateMarketAuctionsBuffer(), + m_updateAuctionLocationsBuffer(DB::ModeQuery::mode_UPDATE), + doLoadAfterSaveComplete(false) +{ + ; +} + +// ---------------------------------------------------------------------- + +CommoditiesSnapshot::~CommoditiesSnapshot() +{ +} + +// ---------------------------------------------------------------------- + +/** + * Called by a worker thread. Saves the snapshot to the database + * @todo: would it be better to have SwgSnapshot add a CustomStep for + * the objectTableBuffer and not override this function? + */ + +bool CommoditiesSnapshot::saveToDB(DB::Session *session) +{ + if (Snapshot::getTimeStamp()!=0) + { + if (! (Snapshot::saveTimestamp(session))) + return false; + } + + LOG("CommoditiesServer", ("start save CommoditiesSnapshot")); + // artificial delay can be added here to help debug timing issues + if (ConfigServerDatabase::getWriteDelay() > 0) + { + LOG("CommoditiesSnapshot::saveToDB",("Delaying writing of snapshot for %i seconds",ConfigServerDatabase::getWriteDelay())); + Os::sleep(ConfigServerDatabase::getWriteDelay()*1000); + } + DEBUG_REPORT_LOG(true, ("Snapshot calling MarketAuctionsBuffer.save().\n")); + + session->setAutoCommitMode(false); + + // If we want to use database rferential integrity (and we do), + // then these must be executed in order! + if (! (m_deleteAuctionLocationsBuffer.save(session))) + return false; + if (! (m_deleteMarketAuctionsBuffer.save(session))) + return false; + + if (! (m_createAuctionLocationsBuffer.save(session))) + return false; + if (! (m_createMarketAuctionsBuffer.save(session))) + return false; + if (! (m_createMarketAuctionBidsBuffer.save(session))) + return false; + + if (! (m_updateAuctionLocationsBuffer.save(session))) + return false; + if (! (m_updateMarketAuctionsBuffer.save(session))) + return false; + + session->commitTransaction(); + LOG("CommoditiesServer", ("finish save CommoditiesSnapshot")); + return true; +} + +/** + * Called when a message is received to update an object's transform and container. + * + * Identifies what the message changes, and puts it in the appropriate + * table buffer. + */ + +void CommoditiesSnapshot::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message) +{ + ; +} + +// ---------------------------------------------------------------------- + +/** + * Called when a message is received to delete an object. + * + * Tells the objectTableBuffer to set the deleted column to true. + */ + +void CommoditiesSnapshot::handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason) +{ + ; +} + +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::handleMessageTo(const MessageToPayload &data) +{ + ; +} + +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::handleMessageToAck(const MessageToId &messageId) +{ + ; +} + +// ---------------------------------------------------------------------- + +/** + * Load the objects. + * + * This function will load all the objects listed in m_oidList. + */ +bool CommoditiesSnapshot::load(DB::Session *session) +{ + return true; +} + +// ---------------------------------------------------------------------- + +/** + * Send the snapshot to the appropriate server. + * + * This function will send messages to the appropriate gameServer to + * create a proxy for the objects in the snapshot, then it will send a + * message to central to relinquish authority for the objects. + * + * @return true if the objects were sent, false if they were not. + */ +bool CommoditiesSnapshot::send(GameServerConnection *connection) const +{ + return true; +} + +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::saveCompleted() +{ + Snapshot::saveCompleted(); + if (doLoadAfterSaveComplete) + Persister::getInstance().startLoadCommodities(); +} + +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::newObject(NetworkId const & objectId, int templateId, Tag typeId) +{ + WARNING(true,("Attempt to create object %s. It has unknown type %i.",objectId.getValueString().c_str(),typeId)); +} + +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message) +{ + if (message.isType("CMCreateAuctionMessage")) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + CMCreateAuctionMessage msg(ri); + handleCreateAuctionMessage(msg); + } + else if (message.isType("CMCreateLocationMessage")) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + CMCreateLocationMessage msg(ri); + handleCreateLocationMessage(msg); + } + else if (message.isType("CMCreateAuctionBidMessage")) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + CMCreateAuctionBidMessage msg(ri); + handleCreateAuctionBidMessage(msg); + } + else if (message.isType("CMUpdateAuctionMessage")) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + CMUpdateAuctionMessage msg(ri); + handleUpdateAuctionMessage(msg); + } + else if (message.isType("CMUpdateLocationMessage")) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + CMUpdateLocationMessage msg(ri); + handleUpdateLocationMessage(msg); + } + else if (message.isType("CMDeleteAuctionMessage")) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + CMDeleteAuctionMessage msg(ri); + handleDeleteAuctionMessage(msg); + } + else if (message.isType("CMDeleteLocationMessage")) + { + Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); + CMDeleteLocationMessage msg(ri); + handleDeleteLocationMessage(msg); + } +} + +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::startLoadAfterSaveComplete() +{ + doLoadAfterSaveComplete = true; +} + +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::handleCreateAuctionMessage(CMCreateAuctionMessage &msg) +{ + DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMCreateAuctionMessage\n")); + LOG("CommoditiesServer", ("Handling CMCreateAuctionMessage for item %s", msg.GetItemId().getValueString().c_str())); + m_createMarketAuctionsBuffer.setMarketAuctions( + msg.GetItemId(), + msg.GetOwnerId(), + msg.GetCreatorId(), + msg.GetLocationId(), + msg.GetMinimumBid(), + msg.GetBuyNowPrice(), + msg.GetAuctionTimer(), + msg.GetAttributes(), + msg.GetUserDescription(), + msg.GetItemType(), + msg.GetItemTemplateId(), + msg.GetItemName(), + msg.GetExpireTimer(), + msg.GetFlags(), + msg.GetItemSize()); +} + +void CommoditiesSnapshot::handleCreateAuctionBidMessage(CMCreateAuctionBidMessage &msg) +{ + DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMCreateAuctionBidMessage\n")); + m_createMarketAuctionBidsBuffer.setMarketAuctionBids( + msg.GetItemId(), + msg.GetBidderId(), + msg.GetBid(), + msg.GetMaxProxyBid()); +} + +void CommoditiesSnapshot::handleCreateLocationMessage(CMCreateLocationMessage &msg) +{ + DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMCreateLocationMessage\n")); + m_createAuctionLocationsBuffer.setAuctionLocations( + msg.GetLocationId(), + msg.GetLocationString(), + msg.GetOwnerId(), + msg.GetSalesTax(), + msg.GetBankId(), + msg.GetEmptyDate(), + msg.GetLastAccessDate(), + msg.GetInactiveDate(), + msg.GetStatus(), + msg.GetSearchEnabled(), + msg.GetEntranceCharge()); +} + +void CommoditiesSnapshot::handleUpdateAuctionMessage(CMUpdateAuctionMessage &msg) +{ + DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMUpdateAuctionMessage\n")); + DBSchema::MarketAuctionsRow *row = m_createMarketAuctionsBuffer.findRowByIndex(msg.GetItemId()); + if (row) + { + m_createMarketAuctionsBuffer.setMarketAuctions(msg.GetItemId(), msg.GetOwnerId(), msg.GetFlags()); + } + else + { + m_updateMarketAuctionsBuffer.setMarketAuctions(msg.GetItemId(), msg.GetOwnerId(), msg.GetFlags()); + } +} + +void CommoditiesSnapshot::handleUpdateLocationMessage(CMUpdateLocationMessage &msg) +{ + DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMUpdateLocationMessage\n")); + DBSchema::AuctionLocationsRow *row = m_createAuctionLocationsBuffer.findRowByIndex(msg.GetLocationId()); + if (row) + { + m_createAuctionLocationsBuffer.setAuctionLocations( + msg.GetLocationId(), + msg.GetLocationString(), + msg.GetOwnerId(), + msg.GetSalesTax(), + msg.GetBankId(), + msg.GetEmptyDate(), + msg.GetLastAccessDate(), + msg.GetInactiveDate(), + msg.GetStatus(), + msg.GetSearchEnabled(), + msg.GetEntranceCharge()); + } + else + { + m_updateAuctionLocationsBuffer.setAuctionLocations( + msg.GetLocationId(), + msg.GetLocationString(), + msg.GetOwnerId(), + msg.GetSalesTax(), + msg.GetBankId(), + msg.GetEmptyDate(), + msg.GetLastAccessDate(), + msg.GetInactiveDate(), + msg.GetStatus(), + msg.GetSearchEnabled(), + msg.GetEntranceCharge()); + } +} + +void CommoditiesSnapshot::handleDeleteAuctionMessage(CMDeleteAuctionMessage &msg) +{ + DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMDeleteAuctionMessage\n")); + m_createMarketAuctionsBuffer.removeMarketAuctions(msg.GetItemId()); + m_updateMarketAuctionsBuffer.removeMarketAuctions(msg.GetItemId()); + m_createMarketAuctionBidsBuffer.removeMarketAuctionBids(msg.GetItemId()); + m_deleteMarketAuctionsBuffer.setMarketAuctions(msg.GetItemId()); +} + +void CommoditiesSnapshot::handleDeleteLocationMessage(CMDeleteLocationMessage &msg) +{ + DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMDeleteLocationMessage\n")); + m_createAuctionLocationsBuffer.removeAuctionLocations(msg.GetLocationId()); + m_updateAuctionLocationsBuffer.removeAuctionLocations(msg.GetLocationId()); + m_deleteAuctionLocationsBuffer.setAuctionLocations(msg.GetLocationId()); +} + +// ---------------------------------------------------------------------- +/** + * For gold mode, return a list of all the objects in the world that may be + * ordinary (non-demand-load) containers. The live database will be checked + * for objects inside these objects. + */ +void CommoditiesSnapshot::getWorldContainers(stdvector::fwd &containers) const +{ +} +// ---------------------------------------------------------------------- + +void CommoditiesSnapshot::decodeServerData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) +{ +} + +void CommoditiesSnapshot::decodeSharedData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) +{ +} + +void CommoditiesSnapshot::decodeClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) +{ +} + +void CommoditiesSnapshot::decodeParentClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) +{ +} + +bool CommoditiesSnapshot::encodeSharedData(NetworkId const & objectId, Tag typeId, std::vector &baselines) const +{ + return false; +} + +bool CommoditiesSnapshot::encodeServerData(NetworkId const & objectId, Tag typeId, std::vector &baselines) const +{ + return false; +} + +bool CommoditiesSnapshot::encodeClientData(NetworkId const & objectId, Tag typeId, std::vector &baselines) const +{ + return false; +} + +bool CommoditiesSnapshot::encodeParentClientData(NetworkId const & objectId, Tag typeId, std::vector &baselines) const +{ + return false; +} + diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/CommoditiesSnapshot.h b/game/server/application/SwgDatabaseServer/src/shared/core/CommoditiesSnapshot.h new file mode 100644 index 00000000..a577e61e --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/CommoditiesSnapshot.h @@ -0,0 +1,104 @@ +// ====================================================================== +// +// CommoditiesSnapshot.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_CommoditiesSnapshot_H +#define INCLUDED_CommoditiesSnapshot_H + +// ====================================================================== + +#include "Archive/ByteStream.h" +#include "serverDatabase/Snapshot.h" +#include "serverDatabase/TableBuffer.h" +#include "sharedFoundation/Tag.h" +#include "SwgDatabaseServer/AuctionLocationsBuffer.h" +#include "SwgDatabaseServer/MarketAuctionsBuffer.h" +#include "SwgDatabaseServer/MarketAuctionBidsBuffer.h" + +class CMCreateAuctionMessage; +class CMCreateAuctionBidMessage; +class CMCreateLocationMessage; +class CMDeleteAuctionMessage; +class CMDeleteLocationMessage; +class CMUpdateAuctionMessage; +class CMUpdateLocationMessage; + +namespace DB +{ + class Session; +} + +// ====================================================================== + +/** + * A Snapshot customized to Star Wars Galaxies Commodities Server. + * + * @todo: there are a lot of public functions that could be made private + */ +class CommoditiesSnapshot : public Snapshot +{ +public: + CommoditiesSnapshot(DB::ModeQuery::Mode mode); + ~CommoditiesSnapshot(); + + // Network Functions: + virtual void handleUpdateObjectPosition(const UpdateObjectPositionMessage &message); + virtual void handleDeleteMessage (const NetworkId &objectID, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason); + virtual void handleMessageTo (const MessageToPayload &data); + virtual void handleMessageToAck (const MessageToId &messageId); + virtual void handleAddResourceTypeMessage (const AddResourceTypeMessage &) { ;} + virtual void handleBountyHunterTargetMessage (const BountyHunterTargetMessage &) { ;} + virtual bool send (GameServerConnection *connection) const; + + // Saving and Loading: + virtual bool saveToDB (DB::Session *session); + virtual bool load (DB::Session *session); + virtual void saveCompleted (); + virtual void getWorldContainers (stdvector::fwd &containers) const; + + virtual void handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message); + virtual void startLoadAfterSaveComplete(); + + // Functions for object creation: + virtual void newObject(NetworkId const & objectId, int templateId, Tag typeId); + +protected: + MarketAuctionsBufferDelete m_deleteMarketAuctionsBuffer; + AuctionLocationsBuffer m_deleteAuctionLocationsBuffer; + MarketAuctionsBufferCreate m_createMarketAuctionsBuffer; + AuctionLocationsBuffer m_createAuctionLocationsBuffer; + MarketAuctionBidsBuffer m_createMarketAuctionBidsBuffer; + MarketAuctionsBufferUpdate m_updateMarketAuctionsBuffer; + AuctionLocationsBuffer m_updateAuctionLocationsBuffer; + + bool doLoadAfterSaveComplete; + +private: + void handleCreateAuctionMessage(CMCreateAuctionMessage &msg); + void handleCreateAuctionBidMessage(CMCreateAuctionBidMessage &msg); + void handleCreateLocationMessage(CMCreateLocationMessage &msg); + void handleUpdateAuctionMessage(CMUpdateAuctionMessage &msg); + void handleUpdateLocationMessage(CMUpdateLocationMessage &msg); + void handleDeleteAuctionMessage(CMDeleteAuctionMessage &msg); + void handleDeleteLocationMessage(CMDeleteLocationMessage &msg); + + virtual void decodeServerData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + virtual void decodeSharedData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + virtual void decodeClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + virtual void decodeParentClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + + virtual bool encodeParentClientData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + virtual bool encodeClientData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + virtual bool encodeServerData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + virtual bool encodeSharedData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + +private: + CommoditiesSnapshot(const CommoditiesSnapshot&); //disable + CommoditiesSnapshot &operator=(const CommoditiesSnapshot&); //disable +}; + +// ====================================================================== +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/FirstSwgDatabaseServer.h b/game/server/application/SwgDatabaseServer/src/shared/core/FirstSwgDatabaseServer.h new file mode 100644 index 00000000..00bb7175 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/FirstSwgDatabaseServer.h @@ -0,0 +1,25 @@ +// ====================================================================== +// +// FirstSwgDatabaseServer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_FirstSwgDatabaseServer_H +#define INCLUDED_FirstSwgDatabaseServer_H + +// ====================================================================== + +#include "sharedFoundation/FirstSharedFoundation.h" +#include "sharedDebug/FirstSharedDebug.h" +#include "sharedMemoryManager/FirstSharedMemoryManager.h" + +#include "sharedFoundation/NetworkIdArchive.h" + +#ifdef _WIN32 +#pragma warning(disable: 4100) // unreferenced formal parameter +#endif +// ====================================================================== + +#endif + diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/MiscPack.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/MiscPack.cpp new file mode 100644 index 00000000..b407a1b3 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/MiscPack.cpp @@ -0,0 +1,57 @@ +// ====================================================================== +// +// MiscPack.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// Defines various packing and unpacking functions needed for SwgDatabaseServer +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" + +#include "serverUtility/MissionLocation.h" +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/BufferString.h" + +// ====================================================================== + +void MissionLocation::unpackFromDatabase(const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableString<500> &planet, const DB::BindableString<500> ®ion_name, const DB::BindableNetworkId &cellId) +{ + x.getValue(coordinates.x); + y.getValue(coordinates.y); + z.getValue(coordinates.z); + planet.getValue(planetName); + region_name.getValue(regionName); + cellId.getValue(cell); +} + +// ---------------------------------------------------------------------- + +void MissionLocation::packToDatabase(DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableString<500> &planet, DB::BindableString<500> ®ion_name, DB::BindableNetworkId &cellId) const +{ + x.setValue(coordinates.x); + y.setValue(coordinates.y); + z.setValue(coordinates.z); + planet.setValue(planetName); + region_name.setValue(regionName); + cellId.setValue(cell); +} + +// ---------------------------------------------------------------------- + +void StringId::unpackFromDatabase(const DB::BufferString &table, const DB::BufferString &text) +{ + table.getValue(m_table); + text.getValue(m_text); +} + +// ---------------------------------------------------------------------- + +void StringId::packToDatabase(DB::BufferString &table, DB::BufferString &text) const +{ + table.setValue(m_table); + text.setValue(m_text); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/ObjvarNameManager.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/ObjvarNameManager.cpp new file mode 100644 index 00000000..0226690b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/ObjvarNameManager.cpp @@ -0,0 +1,174 @@ +// ====================================================================== +// +// ObjvarNameManager.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "ObjvarNameManager.h" + +#include "SwgDatabaseServer/TaskSaveObjvarNames.h" +#include "sharedFoundation/ExitChain.h" +#include +#include +#include + +// ====================================================================== + +ObjvarNameManager * ObjvarNameManager::ms_instance = NULL; +ObjvarNameManager * ObjvarNameManager::ms_goldInstance = NULL; + +// ====================================================================== + +void ObjvarNameManager::install() +{ + DEBUG_FATAL(ms_instance,("Installed ObjvarNameManager twice.\n")); + ExitChain::add(remove,"ObjvarNameManager::remove"); + + ms_instance = new ObjvarNameManager; + ms_goldInstance = new ObjvarNameManager; +} + +// ---------------------------------------------------------------------- + +void ObjvarNameManager::remove() +{ + NOT_NULL(ms_instance); + delete ms_instance; + ms_instance = NULL; + + NOT_NULL(ms_goldInstance); + delete ms_goldInstance; + ms_goldInstance = NULL; +} + +// ---------------------------------------------------------------------- + +ObjvarNameManager::ObjvarNameManager() : + m_nameToIdMap(new NameToIdMapType), + m_idToNameMap(new IdToNameMapType), + m_newNames(new NewNamesType), + m_nextAvailableId(0), + m_namesLoaded(false) +{ +} + +// ---------------------------------------------------------------------- + +ObjvarNameManager::~ObjvarNameManager() +{ + DEBUG_FATAL(!m_newNames->empty(),("Database server was shut down without allowing all object variable names to be saved.")); + + delete m_nameToIdMap; + delete m_idToNameMap; + delete m_newNames; + m_nameToIdMap=NULL; + m_idToNameMap=NULL; + m_newNames=NULL; +} + +// ---------------------------------------------------------------------- + +int ObjvarNameManager::getNameId(const std::string &name) const +{ + DEBUG_FATAL(!m_namesLoaded,("Programmer bug: Attempted to look up object variable names before all were loaded.")); + + NameToIdMapType::const_iterator i=m_nameToIdMap->find(name); + if (i!=m_nameToIdMap->end()) + return i->second; + else + return 0; +} + +// ---------------------------------------------------------------------- + +/** + * Lookup a name in the map. Add the name if it isn't already in use. + */ +int ObjvarNameManager::getOrAddNameId (const std::string &name) +{ + DEBUG_FATAL(!m_namesLoaded,("Programmer bug: Attempted to look up object variable names before all were loaded.")); + + int id=getNameId(name); + if (id!=0) + return id; + else + { + id = m_nextAvailableId++; + (*m_nameToIdMap)[name]=id; + (*m_idToNameMap)[id]=name; + m_newNames->push_back(std::make_pair(id, name)); + return id; + } +} + +// ---------------------------------------------------------------------- + +/** + * Lookup a name in the map. + */ +bool ObjvarNameManager::getName(int id, std::string &name) const +{ + DEBUG_FATAL(!m_namesLoaded,("Programmer bug: Attempted to look up object variable names before all were loaded.")); + + IdToNameMapType::const_iterator i=m_idToNameMap->find(id); + if (i!=m_idToNameMap->end()) + { + name = i->second; + return true; + } + else + return false; +} + +// ---------------------------------------------------------------------- + +/** + * Add a name to the map, e.g. when loaded from the database + */ +void ObjvarNameManager::addNameMapping (int id, const std::string &name) +{ + NameToIdMapType::iterator i=m_nameToIdMap->find(name); + if (i!=m_nameToIdMap->end()) + { + int lower=std::min(id, i->second); + DEBUG_REPORT_LOG(true,("Objvar name %s is duplicated in the database. Ids are %i and %i. Using %i for this name\n", name.c_str(), id, i->second, lower)); + i->second = lower; + } + else + (*m_nameToIdMap)[name]=id; + + (*m_idToNameMap)[id]=name; + + if (id >= m_nextAvailableId) + m_nextAvailableId = id+1; +} + +// ---------------------------------------------------------------------- + +void ObjvarNameManager::allNamesLoaded() +{ + m_namesLoaded=true; + if (m_nextAvailableId==0) + m_nextAvailableId=1; // start with 1 if there are no names in the database. 0 is reserved for "invalid name" +} + +// ---------------------------------------------------------------------- + +/** + * Make a CustomPersistStep to save all the new names to the database. + */ +DB::TaskRequest *ObjvarNameManager::saveNewNames() +{ + if (!m_newNames->empty()) + { + DB::TaskRequest *task = new TaskSaveObjvarNames(*m_newNames); + m_newNames->clear(); + return task; + } + else + return NULL; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/ObjvarNameManager.h b/game/server/application/SwgDatabaseServer/src/shared/core/ObjvarNameManager.h new file mode 100644 index 00000000..5c3c3531 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/ObjvarNameManager.h @@ -0,0 +1,77 @@ +// ====================================================================== +// +// ObjvarNameManager.h +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ObjvarNameManager_H +#define INCLUDED_ObjvarNameManager_H + +// ====================================================================== + +namespace DB +{ + class TaskRequest; +} + +// ====================================================================== + +class ObjvarNameManager +{ + public: + static void install(); + static ObjvarNameManager &getInstance(); + static ObjvarNameManager &getGoldInstance(); + + public: + int getOrAddNameId(const std::string &name); + int getNameId(const std::string &name) const; + bool getName(int id, std::string &name) const; + void addNameMapping(int id, const std::string &name); + void allNamesLoaded(); + + DB::TaskRequest *saveNewNames(); + + private: + typedef stdhash_map::fwd NameToIdMapType; + NameToIdMapType *m_nameToIdMap; + + typedef stdhash_map::fwd IdToNameMapType; + IdToNameMapType *m_idToNameMap; + + typedef stdvector >::fwd NewNamesType; + NewNamesType *m_newNames; + + int m_nextAvailableId; + bool m_namesLoaded; + + private: + static void remove(); + ObjvarNameManager(); + ~ObjvarNameManager(); + + private: + static ObjvarNameManager *ms_instance; + static ObjvarNameManager *ms_goldInstance; +}; + +// ====================================================================== + +inline ObjvarNameManager &ObjvarNameManager::getInstance() +{ + NOT_NULL(ms_instance); + return *ms_instance; +} + +// ---------------------------------------------------------------------- + +inline ObjvarNameManager &ObjvarNameManager::getGoldInstance() +{ + NOT_NULL(ms_goldInstance); + return *ms_goldInstance; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgDatabaseServer.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/SwgDatabaseServer.cpp new file mode 100644 index 00000000..0e331f8c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgDatabaseServer.cpp @@ -0,0 +1,290 @@ +// ====================================================================== +// +// SwgDatabaseServer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer.h" + +#include "SwgDatabaseServer/DataCleanupManager.h" +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "SwgDatabaseServer/SwgLoader.h" +#include "SwgDatabaseServer/SwgPersister.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DataLookup.h" +#include "serverDatabase/LazyDeleter.h" +#include "serverDatabase/MessageToManager.h" +#include "SwgDatabaseServer/CMLoader.h" +#include "serverMetrics/MetricsData.h" +#include "sharedLog/Log.h" +#include "SwgSnapshot.h" +#include "../queries/CommoditiesSchema.h" +#include "../tasks/TaskLoadObjvarNames.h" +#include "sharedFoundation/Os.h" + + +// ====================================================================== + +void SwgDatabaseServer::install() +{ + DatabaseProcess::installDerived(new SwgDatabaseServer); +} + +// ---------------------------------------------------------------------- + +SwgDatabaseServer::SwgDatabaseServer() : + DatabaseProcess() +{ +} + +// ---------------------------------------------------------------------- + +SwgDatabaseServer::~SwgDatabaseServer() +{ +} + +// ---------------------------------------------------------------------- + +void SwgDatabaseServer::run() +{ + SwgPersister::install(); + SwgLoader::install(); + DataLookup::install(); + LazyDeleter::install(); + ObjvarNameManager::install(); + MessageToManager::install(); + CMLoader::install(); + + setupSwgMetrics(); // Game specific metrics + + DataCleanupManager cleanupManager; + cleanupManager.runDailyCleanup(); + + + + DatabaseProcess::run(); +} + + +// ---------------------------------------------------------------------- +void SwgDatabaseServer::frameTick() +{ + tickSwgMetrics(); +} + + +// ---------------------------------------------------------------------- + +/** + * This function is needed to be able to use callbackWithExceptionHandling() + */ +void SwgDatabaseServer::runStatic() +{ + getInstance().run(); +} + + +// ---------------------------------------------------------------------- +void SwgDatabaseServer::setupSwgMetrics() +{ + MetricsData* p_met = MetricsData::getInstance(); + if ( p_met ) + { + m_metricTableBufferBattlefieldMarkerObjectBufferCreated = p_met->addMetric("Buffers.Created.BattlefieldMarkerObjectBuffer"); + m_metricTableBufferBattlefieldMarkerObjectBufferActive = p_met->addMetric("Buffers.Active.BattlefieldMarkerObjectBuffer"); + + m_metricTableBufferBuildingObjectBufferCreated = p_met->addMetric("Buffers.Created.BuildingObjectBuffer"); + m_metricTableBufferBuildingObjectBufferActive = p_met->addMetric("Buffers.Active.BuildingObjectBuffer"); + + m_metricTableBufferCellObjectBufferCreated = p_met->addMetric("Buffers.Created.CellObjectBuffer"); + m_metricTableBufferCellObjectBufferActive = p_met->addMetric("Buffers.Active.CellObjectBuffer"); + + m_metricTableBufferCityObjectBufferCreated = p_met->addMetric("Buffers.Created.CityObjectBuffer"); + m_metricTableBufferCityObjectBufferActive = p_met->addMetric("Buffers.Active.CityObjectBuffer"); + + m_metricTableBufferCreatureObjectBufferCreated = p_met->addMetric("Buffers.Created.CreatureObjectBuffer"); + m_metricTableBufferCreatureObjectBufferActive = p_met->addMetric("Buffers.Active.CreatureObjectBuffer"); + + m_metricTableBufferFactoryObjectBufferCreated = p_met->addMetric("Buffers.Created.FactoryObjectBuffer"); + m_metricTableBufferFactoryObjectBufferActive = p_met->addMetric("Buffers.Active.FactoryObjectBuffer"); + + m_metricTableBufferGuildObjectBufferCreated = p_met->addMetric("Buffers.Created.GuildObjectBuffer"); + m_metricTableBufferGuildObjectBufferActive = p_met->addMetric("Buffers.Active.GuildObjectBuffer"); + + m_metricTableBufferHarvesterInstallationObjectBufferCreated = p_met->addMetric("Buffers.Created.HarvesterInstallationObjectBuffer"); + m_metricTableBufferHarvesterInstallationObjectBufferActive = p_met->addMetric("Buffers.Active.HarvesterInstallationObjectBuffer"); + + m_metricTableBufferInstallationObjectBufferCreated = p_met->addMetric("Buffers.Created.InstallationObjectBuffer"); + m_metricTableBufferInstallationObjectBufferActive = p_met->addMetric("Buffers.Active.InstallationObjectBuffer"); + + m_metricTableBufferIntangibleObjectBufferCreated = p_met->addMetric("Buffers.Created.IntangibleObjectBuffer"); + m_metricTableBufferIntangibleObjectBufferActive = p_met->addMetric("Buffers.Active.IntangibleObjectBuffer"); + + m_metricTableBufferManufactureInstallationObjectBufferCreated = p_met->addMetric("Buffers.Created.ManufactureInstallationObjectBuffer"); + m_metricTableBufferManufactureInstallationObjectBufferActive = p_met->addMetric("Buffers.Active.ManufactureInstallationObjectBuffer"); + + m_metricTableBufferManufactureSchematicObjectBufferCreated = p_met->addMetric("Buffers.Created.ManufactureSchematicObjectBuffer"); + m_metricTableBufferManufactureSchematicObjectBufferActive = p_met->addMetric("Buffers.Active.ManufactureSchematicObjectBuffer"); + + m_metricTableBufferMissionObjectBufferCreated = p_met->addMetric("Buffers.Created.MissionObjectBuffer"); + m_metricTableBufferMissionObjectBufferActive = p_met->addMetric("Buffers.Active.MissionObjectBuffer"); + + m_metricTableBufferObjectTableBufferCreated = p_met->addMetric("Buffers.Created.ObjectTableBuffer"); + m_metricTableBufferObjectTableBufferActive = p_met->addMetric("Buffers.Active.ObjectTableBuffer"); + + m_metricTableBufferPlanetObjectBufferCreated = p_met->addMetric("Buffers.Created.PlanetObjectBuffer"); + m_metricTableBufferPlanetObjectBufferActive = p_met->addMetric("Buffers.Active.PlanetObjectBuffer"); + + m_metricTableBufferPlayerObjectBufferCreated = p_met->addMetric("Buffers.Created.PlayerObjectBuffer"); + m_metricTableBufferPlayerObjectBufferActive = p_met->addMetric("Buffers.Active.PlayerObjectBuffer"); + + m_metricTableBufferResourceContainerObjectBufferCreated = p_met->addMetric("Buffers.Created.ResourceContainerObjectBuffer"); + m_metricTableBufferResourceContainerObjectBufferActive = p_met->addMetric("Buffers.Active.ResourceContainerObjectBuffer"); + + m_metricTableBufferShipObjectBufferCreated = p_met->addMetric("Buffers.Created.ShipObjectBuffer"); + m_metricTableBufferShipObjectBufferActive = p_met->addMetric("Buffers.Active.ShipObjectBuffer"); + + m_metricTableBufferStaticObjectBufferCreated = p_met->addMetric("Buffers.Created.StaticObjectBuffer"); + m_metricTableBufferStaticObjectBufferActive = p_met->addMetric("Buffers.Active.StaticObjectBuffer"); + + m_metricTableBufferTangibleObjectBufferCreated = p_met->addMetric("Buffers.Created.TangibleObjectBuffer"); + m_metricTableBufferTangibleObjectBufferActive = p_met->addMetric("Buffers.Active.TangibleObjectBuffer"); + + m_metricTableBufferUniverseObjectBufferCreated = p_met->addMetric("Buffers.Created.UniverseObjectBuffer"); + m_metricTableBufferUniverseObjectBufferActive = p_met->addMetric("Buffers.Active.UniverseObjectBuffer"); + + m_metricTableBufferVehicleObjectBufferCreated = p_met->addMetric("Buffers.Created.VehicleObjectBuffer"); + m_metricTableBufferVehicleObjectBufferActive = p_met->addMetric("Buffers.Active.VehicleObjectBuffer"); + + m_metricTableBufferWeaponObjectBufferCreated = p_met->addMetric("Buffers.Created.WeaponObjectBuffer"); + m_metricTableBufferWeaponObjectBufferActive = p_met->addMetric("Buffers.Active.WeaponObjectBuffer"); + + // Auction Metrics + m_metricAuctionLocationsRowCreated = p_met->addMetric("CBuffers.Created.AuctionLocationsRow"); + m_metricAuctionLocationsRowActive = p_met->addMetric("CBuffers.Active.AuctionLocationsRow"); + + m_metricMarketAuctionsRowCreated = p_met->addMetric("CBuffers.Created.MarketAuctionsRow"); + m_metricMarketAuctionsRowActive = p_met->addMetric("CBuffers.Active.MarketAuctionsRow"); + + m_metricMarketAuctionBidsRowCreated = p_met->addMetric("CBuffers.Created.MarketAuctionBidsRow"); + m_metricMarketAuctionBidsRowActive = p_met->addMetric("CBuffers.Active.MarketAuctionBidsRow"); + + m_metricObjvarNameRowsActive = p_met->addMetric("ObjvarRowsActive" ); + m_metricGoldObjvarNameRowsActive = p_met->addMetric("ObjvarGoldRowsActive" ); + } + else + { + LOG("SwgDatabaseServer::setupSwgMetrics", ("Metrics create FAILED!" )); + } +} + + +// ---------------------------------------------------------------------- +void SwgDatabaseServer::tickSwgMetrics() +{ + //return; + + static time_t st_lastTime = 0; + if ( time(0) == st_lastTime ) + return; + st_lastTime=time(0); + + MetricsData* p_met = MetricsData::getInstance(); + if ( p_met == 0 ) + return; + + + p_met->updateMetric( m_metricTableBufferBattlefieldMarkerObjectBufferCreated, BattlefieldMarkerObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferBattlefieldMarkerObjectBufferActive, BattlefieldMarkerObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferBuildingObjectBufferCreated, BuildingObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferBuildingObjectBufferActive, BuildingObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferCellObjectBufferCreated, CellObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferCellObjectBufferActive, CellObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferCityObjectBufferCreated, CityObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferCityObjectBufferActive, CityObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferCreatureObjectBufferCreated, CreatureObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferCreatureObjectBufferActive, CreatureObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferFactoryObjectBufferCreated, FactoryObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferFactoryObjectBufferActive, FactoryObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferGuildObjectBufferCreated, GuildObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferGuildObjectBufferActive, GuildObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferHarvesterInstallationObjectBufferCreated, HarvesterInstallationObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferHarvesterInstallationObjectBufferActive, HarvesterInstallationObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferInstallationObjectBufferCreated, InstallationObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferInstallationObjectBufferActive, InstallationObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferIntangibleObjectBufferCreated, IntangibleObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferIntangibleObjectBufferActive, IntangibleObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferManufactureInstallationObjectBufferCreated, ManufactureInstallationObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferManufactureInstallationObjectBufferActive, ManufactureInstallationObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferManufactureSchematicObjectBufferCreated, ManufactureSchematicObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferManufactureSchematicObjectBufferActive, ManufactureSchematicObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferMissionObjectBufferCreated, MissionObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferMissionObjectBufferActive, MissionObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferObjectTableBufferCreated, ObjectTableBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferObjectTableBufferActive, ObjectTableBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferPlanetObjectBufferCreated, PlanetObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferPlanetObjectBufferActive, PlanetObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferPlayerObjectBufferCreated, PlayerObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferPlayerObjectBufferActive, PlayerObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferResourceContainerObjectBufferCreated, ResourceContainerObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferResourceContainerObjectBufferActive, ResourceContainerObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferShipObjectBufferCreated, ShipObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferShipObjectBufferActive, ShipObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferStaticObjectBufferCreated, StaticObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferStaticObjectBufferActive, StaticObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferTangibleObjectBufferCreated, TangibleObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferTangibleObjectBufferActive, TangibleObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferUniverseObjectBufferCreated, UniverseObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferUniverseObjectBufferActive, UniverseObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferVehicleObjectBufferCreated, VehicleObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferVehicleObjectBufferActive, VehicleObjectBuffer::getRowsActive() ); + + p_met->updateMetric( m_metricTableBufferWeaponObjectBufferCreated, WeaponObjectBuffer::getRowsCreated() ); + p_met->updateMetric( m_metricTableBufferWeaponObjectBufferActive, WeaponObjectBuffer::getRowsActive() ); + + + // Auction metrics + p_met->updateMetric( m_metricAuctionLocationsRowCreated, DBSchema::AuctionLocationsRow::getRowsCreated() ); + p_met->updateMetric( m_metricAuctionLocationsRowActive, DBSchema::AuctionLocationsRow::getRowsActive() ); + + p_met->updateMetric( m_metricMarketAuctionsRowCreated, DBSchema::MarketAuctionsRow::getRowsCreated() ); + p_met->updateMetric( m_metricMarketAuctionsRowActive, DBSchema::MarketAuctionsRow::getRowsActive() ); + + p_met->updateMetric( m_metricMarketAuctionBidsRowCreated, DBSchema::MarketAuctionBidsRow::getRowsCreated() ); + p_met->updateMetric( m_metricMarketAuctionBidsRowActive, DBSchema::MarketAuctionBidsRow::getRowsActive() ); + + + // Objvars + p_met->updateMetric( m_metricObjvarNameRowsActive, TaskLoadObjvarNames::getObjvarNamesCount() ); + p_met->updateMetric( m_metricGoldObjvarNameRowsActive, TaskLoadObjvarNames::getGoldObjvarNamesCount() ); + +} + + + + +// ====================================================================== + diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgDatabaseServer.h b/game/server/application/SwgDatabaseServer/src/shared/core/SwgDatabaseServer.h new file mode 100644 index 00000000..587d38f4 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgDatabaseServer.h @@ -0,0 +1,119 @@ +// ====================================================================== +// +// SwgDatabaseServer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SwgDatabaseServer_H +#define INCLUDED_SwgDatabaseServer_H + +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +class SwgDatabaseServer : public DatabaseProcess +{ + public: + static void install(); + + virtual void run(); + static void runStatic(); + + virtual void frameTick(); + + void setupSwgMetrics(); + void tickSwgMetrics(); + + private: + SwgDatabaseServer(); + virtual ~SwgDatabaseServer(); + + public: + int m_metricTableBufferBattlefieldMarkerObjectBufferCreated; + int m_metricTableBufferBattlefieldMarkerObjectBufferActive; + + int m_metricTableBufferBuildingObjectBufferCreated; + int m_metricTableBufferBuildingObjectBufferActive; + + int m_metricTableBufferCellObjectBufferCreated; + int m_metricTableBufferCellObjectBufferActive; + + int m_metricTableBufferCityObjectBufferCreated; + int m_metricTableBufferCityObjectBufferActive; + + int m_metricTableBufferCreatureObjectBufferCreated; + int m_metricTableBufferCreatureObjectBufferActive; + + int m_metricTableBufferFactoryObjectBufferCreated; + int m_metricTableBufferFactoryObjectBufferActive; + + int m_metricTableBufferGuildObjectBufferCreated; + int m_metricTableBufferGuildObjectBufferActive; + + int m_metricTableBufferHarvesterInstallationObjectBufferCreated; + int m_metricTableBufferHarvesterInstallationObjectBufferActive; + + int m_metricTableBufferInstallationObjectBufferCreated; + int m_metricTableBufferInstallationObjectBufferActive; + + int m_metricTableBufferIntangibleObjectBufferCreated; + int m_metricTableBufferIntangibleObjectBufferActive; + + int m_metricTableBufferManufactureInstallationObjectBufferCreated; + int m_metricTableBufferManufactureInstallationObjectBufferActive; + + int m_metricTableBufferManufactureSchematicObjectBufferCreated; + int m_metricTableBufferManufactureSchematicObjectBufferActive; + + int m_metricTableBufferMissionObjectBufferCreated; + int m_metricTableBufferMissionObjectBufferActive; + + int m_metricTableBufferObjectTableBufferCreated; + int m_metricTableBufferObjectTableBufferActive; + + int m_metricTableBufferPlanetObjectBufferCreated; + int m_metricTableBufferPlanetObjectBufferActive; + + int m_metricTableBufferPlayerObjectBufferCreated; + int m_metricTableBufferPlayerObjectBufferActive; + + int m_metricTableBufferResourceContainerObjectBufferCreated; + int m_metricTableBufferResourceContainerObjectBufferActive; + + int m_metricTableBufferShipObjectBufferCreated; + int m_metricTableBufferShipObjectBufferActive; + + int m_metricTableBufferStaticObjectBufferCreated; + int m_metricTableBufferStaticObjectBufferActive; + + int m_metricTableBufferTangibleObjectBufferCreated; + int m_metricTableBufferTangibleObjectBufferActive; + + int m_metricTableBufferUniverseObjectBufferCreated; + int m_metricTableBufferUniverseObjectBufferActive; + + int m_metricTableBufferVehicleObjectBufferCreated; + int m_metricTableBufferVehicleObjectBufferActive; + + int m_metricTableBufferWeaponObjectBufferCreated; + int m_metricTableBufferWeaponObjectBufferActive; + + // Auction metrics + int m_metricAuctionLocationsRowCreated; + int m_metricAuctionLocationsRowActive; + + int m_metricMarketAuctionsRowCreated; + int m_metricMarketAuctionsRowActive; + + int m_metricMarketAuctionBidsRowCreated; + int m_metricMarketAuctionBidsRowActive; + + // Objvar + int m_metricObjvarNameRowsActive; + int m_metricGoldObjvarNameRowsActive; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoader.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoader.cpp new file mode 100644 index 00000000..206cd1ee --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoader.cpp @@ -0,0 +1,130 @@ +// ====================================================================== +// +// SwgLoader.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgLoader.h" + +#include "SwgDatabaseServer/SwgLoaderSnapshotGroup.h" +#include "SwgDatabaseServer/TaskGetCharacters.h" +#include "SwgDatabaseServer/TaskLoadObjvarNames.h" +#include "SwgDatabaseServer/TaskLocateStructure.h" +#include "SwgDatabaseServer/TaskVerifyCharacter.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbTaskQueue.h" +#include "sharedDebug/Profiler.h" + +// ====================================================================== + +void SwgLoader::install() +{ + Loader::installDerived(new SwgLoader); +} + +// ---------------------------------------------------------------------- + +SwgLoader::SwgLoader() : + Loader(), + m_pendingTaskVerifyCharacter(NULL), + m_loadingTaskVerifyCharacter(NULL), + m_verifyCharacterTaskQ(NULL) +{ + m_verifyCharacterTaskQ = new DB::TaskQueue(1,DatabaseProcess::getInstance().getDBServer(),4); +} + +// ---------------------------------------------------------------------- + +SwgLoader:: ~SwgLoader() +{ + m_verifyCharacterTaskQ->cancel(); + delete m_verifyCharacterTaskQ; + delete m_pendingTaskVerifyCharacter; + m_loadingTaskVerifyCharacter = 0; // owned by a db task queue, freed elsewhere + m_verifyCharacterTaskQ = 0; +} + +// ---------------------------------------------------------------------- + +LoaderSnapshotGroup *SwgLoader::makeLoaderSnapshotGroup(uint32 processId) +{ + PROFILER_AUTO_BLOCK_DEFINE("SwgLoader::makeLoaderSnapshotGroup"); + return new SwgLoaderSnapshotGroup(processId); +} + +// ---------------------------------------------------------------------- + +// /** +// * Called to request that the Loader get the list of characters for +// * an account and send them to central. +// */ +// void SwgLoader::getCharacters(uint32 accountNumber) +// { +// TaskGetCharacters *task=new TaskGetCharacters(accountNumber); +// taskQ->asyncRequest(task); +// } + +// ---------------------------------------------------------------------- + +/** + * Called to verify that a player can use a particular character, + * and to get location data needed for login. + */ +void SwgLoader::verifyCharacter(StationId suid, const NetworkId &characterId, const TransferCharacterData * transferCharacterData) +{ + if (!m_pendingTaskVerifyCharacter) + { + if (ConfigServerDatabase::getEnableGoldDatabase()) + m_pendingTaskVerifyCharacter = new TaskVerifyCharacter(DatabaseProcess::getInstance().getGoldSchemaQualifier()); + else + { + static std::string nullSchema; + m_pendingTaskVerifyCharacter = new TaskVerifyCharacter(nullSchema); + } + } + m_pendingTaskVerifyCharacter->addCharacter(suid,characterId, transferCharacterData); +} + +// ---------------------------------------------------------------------- + +void SwgLoader::update(real updateTime) +{ + if (m_pendingTaskVerifyCharacter && !m_loadingTaskVerifyCharacter) + { + m_loadingTaskVerifyCharacter = m_pendingTaskVerifyCharacter; + m_pendingTaskVerifyCharacter = NULL; + m_verifyCharacterTaskQ->asyncRequest(m_loadingTaskVerifyCharacter); + } + + m_verifyCharacterTaskQ->update(ConfigServerDatabase::getDefaultQueueUpdateTimeLimit()); + Loader::update(updateTime); +} + +// ---------------------------------------------------------------------- + +void SwgLoader::verifyCharacterFinished (TaskVerifyCharacter *task) +{ + UNREF(task); + DEBUG_FATAL(task!=m_loadingTaskVerifyCharacter,("Programmer bug: wrong TaskVerifyCharacter finished.\n")); + m_loadingTaskVerifyCharacter = NULL; +} + +// ---------------------------------------------------------------------- + +void SwgLoader::locateStructure(const NetworkId &structureId, const std::string whoRequested) +{ + TaskLocateStructure *task = new TaskLocateStructure(structureId, whoRequested); + taskQ->asyncRequest(task); +} + +// ---------------------------------------------------------------------- + +void SwgLoader::loadStartupData() +{ + taskQ->asyncRequest(new TaskLoadObjvarNames); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoader.h b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoader.h new file mode 100644 index 00000000..daecba41 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoader.h @@ -0,0 +1,57 @@ +// ====================================================================== +// +// SwgLoader.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SwgLoader_H +#define INCLUDED_SwgLoader_H + +// ====================================================================== + +#include "serverDatabase/Loader.h" + +// ====================================================================== + +class TaskVerifyCharacter; +class TransferCharacterData; + +// ====================================================================== + +/** + * Singleton that organizes and queues requests to load objects from the database. + */ +class SwgLoader : public Loader +{ + public: + static void install(); + + public: +// virtual void getCharacters(uint32 accountNumber); + virtual void verifyCharacter(StationId suid, const NetworkId &id, const TransferCharacterData *); + virtual void update(real updateTime); + void verifyCharacterFinished (TaskVerifyCharacter *task); + virtual void locateStructure(const NetworkId &structureId, const std::string whoRequested); + + private: + virtual LoaderSnapshotGroup *makeLoaderSnapshotGroup(uint32 processId); + virtual void loadStartupData(); + + private: + SwgLoader(); + virtual ~SwgLoader(); + SwgLoader(const SwgLoader &); + SwgLoader & operator = (const SwgLoader &); + + private: + TaskVerifyCharacter *m_pendingTaskVerifyCharacter; + TaskVerifyCharacter *m_loadingTaskVerifyCharacter; + + DB::TaskQueue *m_verifyCharacterTaskQ; +}; + + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoaderSnapshotGroup.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoaderSnapshotGroup.cpp new file mode 100644 index 00000000..4e3f0d7f --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoaderSnapshotGroup.cpp @@ -0,0 +1,33 @@ +// ====================================================================== +// +// SwgLoaderSnapshotGroup.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgLoaderSnapshotGroup.h" + +#include "SwgDatabaseServer/SwgSnapshot.h" + +// ====================================================================== + +SwgLoaderSnapshotGroup::SwgLoaderSnapshotGroup(uint32 requestingProcess) : + LoaderSnapshotGroup(requestingProcess, new SwgSnapshot(DB::ModeQuery::mode_SELECT, false)) +{ +} + +// ---------------------------------------------------------------------- + +SwgLoaderSnapshotGroup::~SwgLoaderSnapshotGroup() +{ +} + +// ---------------------------------------------------------------------- + +Snapshot *SwgLoaderSnapshotGroup::makeGoldSnapshot() +{ + return new SwgSnapshot(DB::ModeQuery::mode_SELECT, true); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoaderSnapshotGroup.h b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoaderSnapshotGroup.h new file mode 100644 index 00000000..bdc72326 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgLoaderSnapshotGroup.h @@ -0,0 +1,35 @@ +// ====================================================================== +// +// SwgLoaderSnapshotGroup.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SwgLoaderSnapshotGroup_H +#define INCLUDED_SwgLoaderSnapshotGroup_H + +// ====================================================================== + +#include "serverDatabase/LoaderSnapshotGroup.h" + +namespace DB +{ + class Session; +} +class SwgSnapshot; + +// ====================================================================== + +class SwgLoaderSnapshotGroup : public LoaderSnapshotGroup +{ + public: + SwgLoaderSnapshotGroup(uint32 requestingProcess); + virtual ~SwgLoaderSnapshotGroup(); + + private: + virtual Snapshot *makeGoldSnapshot(); +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgPersister.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/SwgPersister.cpp new file mode 100644 index 00000000..216a6aec --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgPersister.cpp @@ -0,0 +1,123 @@ +// ====================================================================== +// +// SwgPersister.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgPersister.h" + +#include "sharedDatabaseInterface/DbTaskQueue.h" +#include "serverDatabase/CMLoader.h" +#include "SwgDatabaseServer/CommoditiesSnapshot.h" +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "SwgDatabaseServer/SwgSnapshot.h" +#include "SwgDatabaseServer/TaskRestoreCharacter.h" +#include "SwgDatabaseServer/TaskRestoreHouse.h" +#include "SwgDatabaseServer/TaskUndeleteItem.h" +#include "SwgDatabaseServer/TaskMoveToPlayer.h" + +// ====================================================================== + +void SwgPersister::install() +{ + Persister::installDerived(new SwgPersister); +} + +// ---------------------------------------------------------------------- + +SwgPersister::SwgPersister() : + Persister() +{ +} + +// ---------------------------------------------------------------------- + +SwgPersister::~SwgPersister() +{ +} + +// ---------------------------------------------------------------------- + +Snapshot *SwgPersister::makeSnapshot(DB::ModeQuery::Mode mode) const +{ + return new SwgSnapshot(mode, false); +} + +// ---------------------------------------------------------------------- + +Snapshot *SwgPersister::makeCommoditiesSnapshot(DB::ModeQuery::Mode mode) const +{ + return new CommoditiesSnapshot(mode); +} + +// ---------------------------------------------------------------------- + +void SwgPersister::startLoadCommodities() +{ + CMLoader::getInstance().loadCommoditiesData(); +} + +// ---------------------------------------------------------------------- + +/** + * Save new object variable names, if necessary, then call the base class' + * startSave function. + */ +void SwgPersister::startSave() +{ + DB::TaskRequest *req = ObjvarNameManager::getInstance().saveNewNames(); + if (req) + taskQueue->asyncRequest(req); + + Persister::startSave(); +} + +// ---------------------------------------------------------------------- + +void SwgPersister::restoreHouse(const NetworkId &houseId, const std::string &whoRequested) +{ + TaskRestoreHouse *task = new TaskRestoreHouse (houseId, whoRequested); + taskQueue->asyncRequest(task); +} + +// ---------------------------------------------------------------------- + +void SwgPersister::restoreCharacter(const NetworkId &characterId, const std::string &whoRequested) +{ + TaskRestoreCharacter *task = new TaskRestoreCharacter (characterId, whoRequested); + taskQueue->asyncRequest(task); +} + +// ---------------------------------------------------------------------- + +void SwgPersister::undeleteItem(const NetworkId &itemId, const std::string &whoRequested) +{ + TaskUndeleteItem *task = new TaskUndeleteItem (itemId, whoRequested); + taskQueue->asyncRequest(task); +} + +// ---------------------------------------------------------------------- + +void SwgPersister::moveToPlayer(const NetworkId &oid, const NetworkId &player, const std::string &whoRequested) +{ + TaskMoveToPlayer *task = new TaskMoveToPlayer (oid, player, whoRequested); + taskQueue->asyncRequest(task); +} + +// ---------------------------------------------------------------------- + +void SwgPersister::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary) +{ + SwgSnapshot * snapshot=NULL; + + if (hasDataForObject(sourceObject)) + snapshot=safe_cast(&getSnapshotForObject(sourceObject, 0)); + else + snapshot=safe_cast(&getSnapshotForServer(0)); + + snapshot->getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgPersister.h b/game/server/application/SwgDatabaseServer/src/shared/core/SwgPersister.h new file mode 100644 index 00000000..a4a72023 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgPersister.h @@ -0,0 +1,40 @@ +// ====================================================================== +// +// SwgPersister.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SwgPersister_H +#define INCLUDED_SwgPersister_H + +#include "serverDatabase/Persister.h" + +// ====================================================================== + +class SwgPersister : public Persister +{ + public: + static void install(); + + private: + virtual Snapshot * makeSnapshot (DB::ModeQuery::Mode mode) const; + virtual Snapshot * makeCommoditiesSnapshot(DB::ModeQuery::Mode mode) const; + virtual void startLoadCommodities(); + virtual void startSave(); + virtual void restoreHouse(const NetworkId &houseId, const std::string &whoRequested); + virtual void restoreCharacter(const NetworkId &playerId, const std::string &whoRequested); + virtual void undeleteItem(const NetworkId &itemId, const std::string &whoRequested); + virtual void moveToPlayer(const NetworkId &oid, const NetworkId &player, const std::string &whoRequested); + virtual void getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary); + + private: + SwgPersister(); + virtual ~SwgPersister(); + SwgPersister(const SwgPersister &); + SwgPersister & operator = (const SwgPersister &); +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.cpp b/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.cpp new file mode 100644 index 00000000..b5e7e461 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.cpp @@ -0,0 +1,1524 @@ +// ====================================================================== +// +// SwgSnapshot.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/SwgSnapshot.h" + +#include "Archive/AutoDeltaPackedMap.h" +#include "Archive/AutoDeltaSet.h" +#include "Archive/AutoDeltaVector.h" +#include "SwgDatabaseServer/ObjectTableBuffer.h" +#include "SwgDatabaseServer/OfflineMoneyCustomPersistStep.h" +#include "SwgDatabaseServer/PersistableWaypoint.h" +#include "localizationArchive/StringIdArchive.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/GameServerConnection.h" +#include "serverDatabase/ImmediateDeleteCustomPersistStep.h" +#include "serverDatabase/MessageToManager.h" +#include "serverDatabase/ObjectLocator.h" +#include "serverNetworkMessages/CreateObjectMessage.h" +#include "serverNetworkMessages/EndBaselinesMessage.h" +#include "serverNetworkMessages/MessageToPayload.h" +#include "serverNetworkMessages/SetAuthoritativeMessage.h" +#include "serverNetworkMessages/UpdateObjectPositionMessage.h" +#include "serverUtility/MissionLocation.h" +#include "sharedDebug/Profiler.h" +#include "sharedFoundation/DynamicVariableList.h" +#include "sharedFoundation/FormattedString.h" +#include "sharedFoundation/GameControllerMessage.h" +#include "sharedFoundation/NetworkIdArchive.h" +#include "sharedFoundation/Os.h" +#include "sharedGame/Buff.h" +#include "sharedGame/MatchMakingId.h" +#include "sharedGame/PlayerQuestData.h" +#include "sharedLog/Log.h" +#include "sharedMath/Quaternion.h" +#include "sharedMathArchive/TransformArchive.h" +#include "sharedMathArchive/VectorArchive.h" +#include "sharedNetworkMessages/BaselinesMessage.h" +#include "sharedNetworkMessages/BaselinesMessage.h" +#include "sharedNetworkMessages/DeltasMessage.h" +#include "sharedNetworkMessages/ObjectChannelMessages.h" +#include "sharedUtility/Location.h" +#include "swgSharedUtility/Attributes.def" + +// ====================================================================== + +/** + * Construct a snapshot. + * + * This and the header file should be the only places that the entire + * list of buffers is hard-coded. Every other place where you want to refer + * to all the buffers should use m_bufferList. This will reduce the number + * of places the code needs to be changed if new buffers are added. + * (Referring to a _specific_ buffer when you know you need that buffer + * is kosher.) + */ +SwgSnapshot::SwgSnapshot(DB::ModeQuery::Mode mode, bool useGoldDatabase) : + Snapshot(mode, useGoldDatabase), + m_battlefieldMarkerObjectBuffer(mode), + m_battlefieldParticipantBuffer(mode), + m_bountyHunterTargetBuffer(), + m_buildingObjectBuffer(mode), + m_cellObjectBuffer(mode), + m_cityObjectBuffer(mode), + m_creatureObjectBuffer(mode), + m_experienceBuffer(mode), + m_factoryObjectBuffer(mode), + m_guildObjectBuffer(mode), + m_harvesterInstallationObjectBuffer(mode), + m_installationObjectBuffer(mode), + m_intangibleObjectBuffer(mode), + m_locationBuffer(mode), + m_manufactureInstallationObjectBuffer(mode), + m_manufactureSchematicAttributeBuffer(mode), + m_manufactureSchematicObjectBuffer(mode), + m_messageBuffer(), + m_missionObjectBuffer(mode), + m_objectTableBuffer(mode), + m_objvarBuffer(mode, &m_objectTableBuffer, useGoldDatabase), + m_planetObjectBuffer(mode), + m_playerObjectBuffer(mode), + m_playerQuestObjectBuffer(mode), + m_propertyListBuffer(mode), + m_resourceContainerObjectBuffer(mode), + m_resourceTypeBuffer(), + m_scriptBuffer(), + m_shipObjectBuffer(mode), + m_staticObjectBuffer(mode), + m_tangibleObjectBuffer(mode), + m_universeObjectBuffer(mode), + m_vehicleObjectBuffer(mode), + m_waypointBuffer(mode), + m_weaponObjectBuffer(mode), + m_immediateDeleteStep(NULL), + m_offlineMoneyCustomPersistStep(NULL) +{ + m_bufferList.push_back(&m_battlefieldMarkerObjectBuffer); + m_bufferList.push_back(&m_battlefieldParticipantBuffer); + m_bufferList.push_back(&m_buildingObjectBuffer); + m_bufferList.push_back(&m_bountyHunterTargetBuffer); + m_bufferList.push_back(&m_cellObjectBuffer); + m_bufferList.push_back(&m_cityObjectBuffer); + m_bufferList.push_back(&m_creatureObjectBuffer); + m_bufferList.push_back(&m_experienceBuffer); + m_bufferList.push_back(&m_factoryObjectBuffer); + m_bufferList.push_back(&m_guildObjectBuffer); + m_bufferList.push_back(&m_harvesterInstallationObjectBuffer); + m_bufferList.push_back(&m_installationObjectBuffer); + m_bufferList.push_back(&m_intangibleObjectBuffer); + m_bufferList.push_back(&m_locationBuffer); + m_bufferList.push_back(&m_manufactureInstallationObjectBuffer); + m_bufferList.push_back(&m_manufactureSchematicAttributeBuffer); + m_bufferList.push_back(&m_manufactureSchematicObjectBuffer); + m_bufferList.push_back(&m_messageBuffer); + m_bufferList.push_back(&m_missionObjectBuffer); + m_bufferList.push_back(&m_objvarBuffer); + m_bufferList.push_back(&m_planetObjectBuffer); + m_bufferList.push_back(&m_playerObjectBuffer); + m_bufferList.push_back(&m_playerQuestObjectBuffer); + m_bufferList.push_back(&m_propertyListBuffer); + m_bufferList.push_back(&m_resourceContainerObjectBuffer); + m_bufferList.push_back(&m_resourceTypeBuffer); + m_bufferList.push_back(&m_scriptBuffer); + m_bufferList.push_back(&m_shipObjectBuffer); + m_bufferList.push_back(&m_staticObjectBuffer); + m_bufferList.push_back(&m_tangibleObjectBuffer); + m_bufferList.push_back(&m_universeObjectBuffer); + m_bufferList.push_back(&m_vehicleObjectBuffer); + m_bufferList.push_back(&m_waypointBuffer); + m_bufferList.push_back(&m_weaponObjectBuffer); + + // note: m_objectTableBuffer is left off bufferList intentionally +} + +// ---------------------------------------------------------------------- + +SwgSnapshot::~SwgSnapshot() +{ +} + +// ---------------------------------------------------------------------- + +/** + * Called by a worker thread. Saves the snapshot to the database + * @todo: would it be better to have SwgSnapshot add a CustomStep for + * the objectTableBuffer and not override this function? + */ + +bool SwgSnapshot::saveToDB(DB::Session *session) +{ + // artificial delay can be added here to help debug timing issues + if (ConfigServerDatabase::getWriteDelay() > 0) + { + LOG("SwgSnapshot::saveToDB",("Delaying writing of snapshot for %i seconds",ConfigServerDatabase::getWriteDelay())); + Os::sleep(ConfigServerDatabase::getWriteDelay()*1000); + } + + session->setAutoCommitMode(false); + + if (! (m_objectTableBuffer.save(session))) + return false; + if (! (Snapshot::saveToDB(session))) + return false; + + session->commitTransaction(); + + return true; +} + +// ---------------------------------------------------------------------- + +/** + * Called when a message is received to update an object's transform and container. + * + * Identifies what the message changes, and puts it in the appropriate + * table buffer. + */ + +void SwgSnapshot::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message) +{ + if ( message.isCreatureObject() ) //&& ( message.getPlayerControlled() )) + { + m_creatureObjectBuffer.handleUpdateObjectPosition(message); + } + + if (m_objectTableBuffer.handleUpdateObjectPosition(message)) return; + + FATAL(true,("UpdateObjectPosition was not handled by any of the object buffers.")); +} + +// ---------------------------------------------------------------------- + +/** + * Called when a message is received to delete an object. + * + * Tells the objectTableBuffer to set the deleted column to true. + */ + +void SwgSnapshot::handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason) +{ + m_objectTableBuffer.handleDeleteMessage(objectId, reasonCode, demandLoadedContainer, cascadeReason); + + for (BufferListType::iterator buffer=m_bufferList.begin(); buffer!=m_bufferList.end(); ++buffer) + { + (*buffer)->removeObject(objectId); // if the object is deleted, no reason to save other data for it + } + + if (immediate && (getMode() != DB::ModeQuery::mode_INSERT)) + { + if (!m_immediateDeleteStep) + { + m_immediateDeleteStep = new ImmediateDeleteCustomPersistStep; + addCustomPersistStep(m_immediateDeleteStep); + } + + m_immediateDeleteStep->addObject(objectId); + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::handleMessageTo(const MessageToPayload &data) +{ + m_messageBuffer.handleMessageTo(data); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::handleMessageToAck(const MessageToId &messageId) +{ + m_messageBuffer.handleMessageToAck(messageId); +} + +// ---------------------------------------------------------------------- + +/** + * Decodes the Objvars data for an object from the network package. + */ +void SwgSnapshot::decodeObjVars(NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline) +{ + std::vector commands; + if (isBaseline) + DynamicVariableList::MapType::unpack(data, commands); + else + DynamicVariableList::MapType::unpackDelta(data, commands); + m_objvarBuffer.updateObjvars(objectId,commands); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeObjVars(const NetworkId &objectId, Archive::ByteStream &data) const +{ + PROFILER_AUTO_BLOCK_DEFINE("encodeObjVars"); + static std::vector commands; + commands.clear(); + + m_objvarBuffer.getObjvarsForObject(objectId,commands); + DynamicVariableList::MapType::pack(data, commands); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeObjVarFreeFlags(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) +{ + UNREF(isBaseline); + int freePositions; + Archive::get(data,freePositions); + m_objectTableBuffer.decodeObjVarFreeFlags(objectId, freePositions); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeObjVarFreeFlags(const NetworkId & objectId, Archive::ByteStream &data) const +{ + PROFILER_AUTO_BLOCK_DEFINE("encodeObjVarFreeFlags"); + int freePositions = m_objectTableBuffer.encodeObjVarFreeFlags(objectId); + Archive::put(data, freePositions); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeScriptObject(NetworkId const & objectId, Archive::ReadIterator &data, bool /* isBaseline */) +{ + std::string packedScriptList; + Archive::get(data,packedScriptList); + + if (packedScriptList.length()==0) + packedScriptList=' '; // avoid confusing an empty list with NULL + + DBSchema::ObjectBufferRow *row=m_objectTableBuffer.findRowByIndex(objectId); + if (row==NULL) + row=m_objectTableBuffer.addEmptyRow(objectId); + + row->script_list=packedScriptList; + m_scriptBuffer.clearScripts(objectId); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeScriptObject(const NetworkId &objectId, Archive::ByteStream &data) const +{ + PROFILER_AUTO_BLOCK_DEFINE("encodeScriptObject"); + const DBSchema::ObjectBufferRow *row=m_objectTableBuffer.findConstRowByIndex(objectId); + if (row) + { + std::string temp; + row->script_list.getValue(temp); + if (temp.empty()) + { + // Object might have a non-converted script list + std::vector scripts; + m_scriptBuffer.getScriptsForObject(objectId, scripts); + + for (std::vector::const_iterator i=scripts.begin(); i!=scripts.end(); ++i) + { + temp+=(*i)+':'; + } + } + Archive::put(data,temp); + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline, int offset) +{ + if (isBaseline) + { + size_t size, baselineCommandCount; + Archive::get(data, size); + Archive::get(data, baselineCommandCount); + + Attributes::Value temp; + for (size_t i=0; i VectorType; + size_t numCommands, baselineCommandCount; + Archive::get(data, numCommands); + Archive::get(data, baselineCommandCount); + for (size_t count=0; count values; + m_creatureObjectBuffer.getAttributesForObject(objectId, values, offset, Attributes::NumberOfAttributes); + + Archive::put(data, Attributes::NumberOfAttributes); + Archive::put(data, static_cast(0)); // baselineCommandCount + if (values.size() < static_cast(Attributes::NumberOfAttributes)) + { + DEBUG_REPORT_LOG(true,("Object %s did not have valid attribute data in the database. Missing attributes will be set to 100.\n",objectId.getValueString().c_str())); + values.resize(Attributes::NumberOfAttributes, 100); + } + for (int i=0; i SetType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) + SetType::unpack(data, commands); + else + SetType::unpackDelta(data, commands); + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) + { + switch (i->cmd) + { + case SetType::Command::ERASE: + m_propertyListBuffer.deleteProperty(objectId, listId, i->value); + break; + case SetType::Command::INSERT: + m_propertyListBuffer.insertProperty(objectId, listId, i->value); + break; + case SetType::Command::CLEAR: + m_propertyListBuffer.clearProperties(objectId, listId); + break; + default: + FATAL(true,("Unknown AutoDeltaSet command.\n")); + } + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodePropertyList(const NetworkId &objectId, int listId, Archive::ByteStream &data) const +{ + typedef Archive::AutoDeltaSet SetType; + typedef std::set ValuesType; + ValuesType values; + + m_propertyListBuffer.getPropertyListForObject(objectId, listId, values); + SetType::pack(data, values); +} + +// ====================================================================== +// Loading functions + +/** + * Load the objects. + * + * This function will load all the objects listed in m_oidList. + */ +bool SwgSnapshot::load(DB::Session *session) +{ + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Load begin.\n")); + + std::string schema; + if (getUseGoldDatabase()) + schema=DatabaseProcess::getInstance().getGoldSchemaQualifier(); + else + schema=DatabaseProcess::getInstance().getSchemaQualifier(); + + session->setAutoCommitMode(false); + + int objectCount = 0; + int objectsLocated; + + for (LocatorListType::iterator loc=m_locatorList.begin(); loc!=m_locatorList.end(); ++loc) + { + if (! ((*loc)->locateObjects(session, schema, objectsLocated))) + return false; + objectCount += objectsLocated; + } + LOG("LoadTimes",("Snapshot has %i objects",objectCount)); + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Objects Located.\n")); + + if (objectCount > 0) + { + registerTags(); + + DB::TagSet tags; + + if (! (m_objectTableBuffer.load(session, tags, schema, getUseGoldDatabase()))) + return false; + m_objectTableBuffer.getTags(tags); + + for (BufferListType::iterator buffer=m_bufferList.begin(); buffer!=m_bufferList.end(); ++buffer) + { + if (! ((*buffer)->load(session, tags, schema, getUseGoldDatabase()))) + return false; + } + + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Load end.\n")); + } + else + { + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Load skipped because there were no objects.\n")); + } + + session->commitTransaction(); // will cause temp tables to be erased + return true; +} + +// ---------------------------------------------------------------------- + +/** + * Send the snapshot to the appropriate server. + * + * This function will send messages to the appropriate gameServer to + * create a proxy for the objects in the snapshot, then it will send a + * message to central to relinquish authority for the objects. + * + * @return true if the objects were sent, false if they were not. + */ +bool SwgSnapshot::send(GameServerConnection *connection) const +{ + PROFILER_AUTO_BLOCK_DEFINE("SwgSnapshot::send"); + + if (connection==0) + return false; + + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Sending Snapshot\n")); + + PROFILER_BLOCK_DEFINE(prebaselinesBlock,"sendPreBaselinesCustomData"); + PROFILER_BLOCK_ENTER(prebaselinesBlock); + for (LocatorListType::const_iterator loc=m_locatorList.begin(); loc!=m_locatorList.end(); ++loc) + { + (*loc)->sendPreBaselinesCustomData(*connection); + } + PROFILER_BLOCK_LEAVE(prebaselinesBlock); + + OIDListType oidList; + m_objectTableBuffer.getObjectList(oidList); + + PROFILER_BLOCK_DEFINE(sendObjectData,"send object data"); + PROFILER_BLOCK_ENTER(sendObjectData); + + static std::vector baselines; + baselines.clear(); + + for (OIDListType::iterator i=oidList.begin(); i!=oidList.end(); ++i) + { + PROFILER_BLOCK_DEFINE(createBlock, "object create and position"); + PROFILER_BLOCK_ENTER(createBlock); + + const DBSchema::ObjectBufferRow *baseData=m_objectTableBuffer.findConstRowByIndex((*i)); + NOT_NULL(baseData); + + NetworkId networkId=(*i); + DEBUG_FATAL(networkId != baseData->object_id.getValue(),("Object ID and row value didn't match")); + + uint32 crc = baseData->object_template_id.getValue(); + CreateObjectByCrcMessage com(networkId, + crc, + static_cast(baseData->type_id.getValue()), + true, + NetworkId(baseData->contained_by.getValue())); +// connection->send(com,true); + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("\tSent CreateObjectMessage for object %s\n",networkId.getValueString().c_str())); + + Transform t; + Quaternion q(static_cast(baseData->quaternion_w.getValue()), + static_cast(baseData->quaternion_x.getValue()), + static_cast(baseData->quaternion_y.getValue()), + static_cast(baseData->quaternion_z.getValue())); + q.getTransform(&t); // reorients the transform according to the quaternion + + t.validate(); + + t.setPosition_p(Vector (static_cast(baseData->x.getValue()), + static_cast(baseData->y.getValue()), + static_cast(baseData->z.getValue()))); + + UpdateObjectPositionMessage uopm( + NetworkId(baseData->object_id.getValue()), + t, + t, + NetworkId(baseData->contained_by.getValue()), + baseData->slot_arrangement.getValue(), + NetworkId(baseData->load_with.getValue()), + baseData->player_controlled.getValue(), + false); + +// connection->send(uopm,true); + + PROFILER_BLOCK_LEAVE(createBlock); + + PROFILER_BLOCK_DEFINE(encodeData,"encode data"); + PROFILER_BLOCK_ENTER(encodeData); + + bool okToSend = encodeParentClientData(networkId,baseData->type_id.getValue(),baselines); + okToSend = okToSend && encodeClientData(networkId,baseData->type_id.getValue(),baselines); + okToSend = okToSend && encodeServerData(networkId,baseData->type_id.getValue(),baselines); + okToSend = okToSend && encodeSharedData(networkId,baseData->type_id.getValue(),baselines); + + PROFILER_BLOCK_LEAVE(encodeData); + + if (okToSend) + { + PROFILER_AUTO_BLOCK_DEFINE("connection->send (baselines)"); + + connection->send(com,true); + connection->send(uopm,true); + } + else + { + (*i)=NetworkId::cms_invalid; + } + } + + BatchBaselinesMessage bbm(baselines); + connection->send(bbm,true); + + PROFILER_BLOCK_LEAVE(sendObjectData); + + PROFILER_BLOCK_DEFINE(sendEndBaselines,"send EndBaselines"); + PROFILER_BLOCK_ENTER(sendEndBaselines); + + // Send EndBaselines in reverse order (container & portal system requires this) + for (OIDListType::reverse_iterator r=oidList.rbegin(); r!=oidList.rend(); ++r) + { + if (*r != NetworkId::cms_invalid) + { + EndBaselinesMessage const ebm(*r); + connection->send(ebm,true); + } +// DEBUG_REPORT_LOG(true, ("\tSent EndBaselinesMessage for object %i\n",(*r).getValue())); + } + PROFILER_BLOCK_LEAVE(sendEndBaselines); + + // Send resource data (if any) after all objects but before the post-baselines custom data + m_resourceTypeBuffer.sendResourceTypeObjects(*connection); + m_bountyHunterTargetBuffer.sendBountyHunterTargetMessage (*connection); + + // Send post-baselines custom data, such as "UniverseComplete" messages, etc. + PROFILER_BLOCK_DEFINE(sendPostBaselinesCustomData,"sendPostBaselinesCustomData"); + PROFILER_BLOCK_ENTER(sendPostBaselinesCustomData); + + for (LocatorListType::const_iterator loc2=m_locatorList.begin(); loc2!=m_locatorList.end(); ++loc2) + { + (*loc2)->sendPostBaselinesCustomData(*connection); + } + PROFILER_BLOCK_LEAVE(sendPostBaselinesCustomData); + + // Send any MessageTos for these objects + // This must happen after EndBaselinesMessage is sent for all of the objects + { + PROFILER_AUTO_BLOCK_DEFINE("send MessageTos"); + + m_messageBuffer.sendMessages(*connection); + for (OIDListType::const_iterator i=oidList.begin(); i!=oidList.end(); ++i) + { + if (*i != NetworkId::cms_invalid) + MessageToManager::getInstance().sendMessagesForObject(*i, *connection); + } + } + + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Done sending Snapshot\n")); + return true; +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::loadAttributes(DB::Session *session, NetworkId const & objectId) +{ + UNREF(session); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::loadCommands(DB::Session *session, NetworkId const & objectId) +{ + UNREF(session); + UNREF(objectId); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::loadSkills(DB::Session *session, NetworkId const & objectId) +{ + UNREF(session); + UNREF(objectId); +} + +// ---------------------------------------------------------------------- + +/** + * Helper function to avoid having to put too much logic into generated code. + */ +void SwgSnapshot::decodeMissionLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableString<500> &planet, DB::BindableString<500> ®ion_name,DB::BindableNetworkId &cell) const +{ + MissionLocation temp; + Archive::get(data,temp); + temp.packToDatabase(x,y,z,planet,region_name, cell); +} + +// ---------------------------------------------------------------------- + +/** + * Helper function to avoid having to put too much logic into generated code. + */ +void SwgSnapshot::encodeMissionLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableString<500> &planet, const DB::BindableString<500> ®ion_name, const DB::BindableNetworkId &cell) const +{ + MissionLocation temp; + temp.unpackFromDatabase(x,y,z,planet,region_name, cell); + Archive::put(data,temp); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeVector(Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z) const +{ + Vector temp; + Archive::get(data,temp); + x.setValue(temp.x); + y.setValue(temp.y); + z.setValue(temp.z); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeVector(Archive::ByteStream &data, const DB::BindableDouble &x, const DB::BindableDouble &y, const DB::BindableDouble &z) const +{ + Vector temp; + x.getValue(temp.x); + y.getValue(temp.y); + z.getValue(temp.z); + Archive::put(data,temp); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeStringId(Archive::ReadIterator &data,DB::BufferString &table,DB::BufferString &text) const +{ + StringId temp; + Archive::get(data,temp); + temp.packToDatabase(table,text); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeStringId(Archive::ByteStream &data, const DB::BufferString &table, const DB::BufferString &text) const +{ + StringId temp; + temp.unpackFromDatabase(table,text); + Archive::put(data,temp); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::ignorePersistedFlag(const NetworkId &objectId, Archive::ReadIterator &data) const +{ + bool persisted; + Archive::get(data,persisted); + + UNREF(objectId); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeLocationDataList(const NetworkId &objectId, size_t listId, Archive::ReadIterator &data, bool isBaseline) +{ + if (isBaseline) + { + size_t size, baselineCommandCount; + Archive::get(data, size); + Archive::get(data, baselineCommandCount); + + LocationData temp; + for (size_t i=0; i VectorType; + size_t numCommands, baselineCommandCount; + Archive::get(data, numCommands); + Archive::get(data, baselineCommandCount); + for (size_t count=0; count values; + m_locationBuffer.getLocationList(objectId, listId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); + for (std::vector::iterator i=values.begin(); i!=values.end(); ++i) + { + Archive::put(data,*i); + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeExperience(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) +{ + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) + MapType::unpack(data, commands); + else + MapType::unpackDelta(data, commands); + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) + { + switch ((*i).cmd) + { + case MapType::Command::ERASE: + m_experienceBuffer.removeExperience(objectId, (*i).key); + break; + + case MapType::Command::ADD: + case MapType::Command::SET: + m_experienceBuffer.setExperience(objectId, (*i).key, (*i).value); + break; + + default: + FATAL(true,("Unknown AutoDeltaMap command.\n")); + } + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeExperience(const NetworkId &objectId, Archive::ByteStream &data) const +{ + typedef std::vector > ValuesType; + ValuesType values; + m_experienceBuffer.getExperienceForObject(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) + { + const unsigned char command = 0; //ADD + Archive::put(data, command); + Archive::put(data,(*i).first); + Archive::put(data,(*i).second); + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeBattlefieldParticipants(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) +{ + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) + MapType::unpack(data, commands); + else + MapType::unpackDelta(data, commands); + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) + { + switch ((*i).cmd) + { + case MapType::Command::ERASE: + m_battlefieldParticipantBuffer.removeParticipantForRegion(objectId, (*i).key); + break; + + case MapType::Command::ADD: + case MapType::Command::SET: + m_battlefieldParticipantBuffer.setParticipantForRegion(objectId, (*i).key, (*i).value); + break; + + default: + FATAL(true,("Unknown AutoDeltaMap command.\n")); + } + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeBattlefieldParticipants(const NetworkId &objectId, Archive::ByteStream &data) const +{ + typedef std::vector > ValuesType; + ValuesType values; + m_battlefieldParticipantBuffer.getParticipantsForRegion(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) + { + const unsigned char command = 0; //ADD + Archive::put(data, command); + Archive::put(data,(*i).first); + Archive::put(data,(*i).second); + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeManufactureSchematicAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) +{ + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) + MapType::unpack(data, commands); + else + MapType::unpackDelta(data, commands); + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) + { + switch ((*i).cmd) + { + case MapType::Command::ERASE: + m_manufactureSchematicAttributeBuffer.removeManufactureSchematicAttribute(objectId,(*i).key.getCanonicalRepresentation()); + break; + + case MapType::Command::ADD: + case MapType::Command::SET: + m_manufactureSchematicAttributeBuffer.setManufactureSchematicAttribute(objectId,(*i).key.getCanonicalRepresentation(),(*i).value); + break; + + default: + FATAL(true,("Unknown AutoDeltaMap command.\n")); + } + } +} + +void SwgSnapshot::encodeManufactureSchematicAttributes(const NetworkId & objectId, Archive::ByteStream &data) const +{ + typedef std::vector > ValuesType; + ValuesType values; + m_manufactureSchematicAttributeBuffer.getDataForObject(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) + { + const unsigned char command = 0; //ADD + Archive::put(data, command); + StringId temp((*i).first); + Archive::put(data,temp); + Archive::put(data,(*i).second); + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeMatchMakingId(Archive::ReadIterator &data, DB::BufferString &column) const +{ + MatchMakingId mmid; + std::string temp; + Archive::get(data, mmid); + mmid.packBitString(temp); + column.setValue(temp); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeMatchMakingId(Archive::ByteStream &data, const DB::BufferString &column) const +{ + MatchMakingId mmid; + std::string temp; + column.getValue(temp); + mmid.unPackBitString(temp); + Archive::put(data,mmid); +} +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeComponents(NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline) +{ + typedef Archive::AutoDeltaSet SetType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) + SetType::unpack(data, commands); + else + SetType::unpackDelta(data, commands); + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) + { + switch (i->cmd) + { + case SetType::Command::ERASE: + { + char buffer[50]; + _itoa(i->value,buffer,10); + m_propertyListBuffer.deleteProperty(objectId, 11, buffer); + break; + } + + case SetType::Command::INSERT: + { + char buffer[50]; + _itoa(i->value,buffer,10); + m_propertyListBuffer.insertProperty(objectId, 11, buffer); + break; + } + + case SetType::Command::CLEAR: + m_propertyListBuffer.clearProperties(objectId, 11); + break; + + default: + FATAL(true,("Unknown AutoDeltaSet command.\n")); + } + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeComponents(const NetworkId &objectId, Archive::ByteStream &data) const +{ + typedef Archive::AutoDeltaSet SetType; + typedef std::set PackedValuesType; + typedef std::set ValuesType; + + PackedValuesType packedValues; + m_propertyListBuffer.getPropertyListForObject(objectId, 11, packedValues); + + ValuesType values; + for (PackedValuesType::const_iterator i = packedValues.begin(); i != packedValues.end(); ++i) + values.insert(atoi((*i).c_str())); + + SetType::pack(data, values); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableNetworkId &cell, DB::BindableLong &planet) const +{ + Location temp; + Archive::get(data,temp); + Vector vec=temp.getCoordinates(); + x=vec.x; + y=vec.y; + z=vec.z; + cell=temp.getCell(); + planet=temp.getSceneIdCrc(); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableNetworkId &cell, const DB::BindableLong &planet) const +{ + Location temp(Vector(static_cast(x.getValue()),static_cast(y.getValue()),static_cast(z.getValue())),cell.getValue(),planet.getValue()); + Archive::put(data,temp); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeWaypoints(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) +{ + typedef Archive::AutoDeltaMap MapType; + typedef std::vector CommandList; + CommandList commands; + if (isBaseline) + MapType::unpack(data, commands); + else + MapType::unpackDelta(data, commands); + for (CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i) + { + switch ((*i).cmd) + { + case MapType::Command::ERASE: + m_waypointBuffer.removeWaypoint(objectId, (*i).key); + break; + + case MapType::Command::ADD: + case MapType::Command::SET: + m_waypointBuffer.setWaypoint(objectId, (*i).key, (*i).value); + break; + + default: + FATAL(true,("Unknown AutoDeltaMap command.\n")); + } + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeWaypoints(const NetworkId &objectId, Archive::ByteStream &data) const +{ + typedef std::vector ValuesType; + ValuesType values; + m_waypointBuffer.getWaypointsForObject(objectId, values); + + Archive::put(data, values.size()); + Archive::put(data, static_cast(0)); // baselineCommandCount + for (ValuesType::const_iterator i=values.begin(); i!=values.end(); ++i) + { + const unsigned char command = 0; //ADD + Archive::put(data, command); + Archive::put(data,i->m_networkId); + Archive::put(data,*i); + } +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeSingleWaypoint(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline) +{ + UNREF(isBaseline); // parameter is there for consistency. + + PersistableWaypoint value; + Archive::get(data, value); + + m_waypointBuffer.setWaypoint(objectId,value.m_networkId,value); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeSingleWaypoint(const NetworkId &objectId, Archive::ByteStream &data) const +{ + typedef std::vector ValuesType; + ValuesType values; + m_waypointBuffer.getWaypointsForObject(objectId, values); + + DEBUG_FATAL(values.size()!=1,("Object %s should have exactly 1 waypoint, but it has %i",objectId.getValueString().c_str(),values.size())); + + ValuesType::const_iterator i=values.begin(); + if (i!=values.end()) + Archive::put(data,*i); + else + Archive::put(data,PersistableWaypoint()); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::saveCompleted() +{ + m_messageBuffer.removeSavedMessagesFromMemory(); + Snapshot::saveCompleted(); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message) +{ + UNREF(message); + DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Received Commodities Data in non-commodities snapshot!\n")); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::startLoadAfterSaveComplete() +{ + DEBUG_WARNING(true,("Called startLoadAfterSaveComplete in non-commodities snapshot!\n")); +} + +// ---------------------------------------------------------------------- +/** + * For gold mode, return a list of all the objects in the world that may be + * ordinary (non-demand-load) containers. The live database will be checked + * for objects inside these objects. + */ +void SwgSnapshot::getWorldContainers(stdvector::fwd &containers) const +{ + m_objectTableBuffer.getWorldContainers(containers); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::handleAddResourceTypeMessage (AddResourceTypeMessage const & message) +{ + m_resourceTypeBuffer.handleAddResourceTypeMessage(message); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::handleBountyHunterTargetMessage (const BountyHunterTargetMessage &message) +{ + m_bountyHunterTargetBuffer.setBountyHunterTarget(message.GetObjectId(), message.GetTargetId()); +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary) +{ + // Object might be "offline" but still buffered. Try to handle it in memory first: + if (!m_objectTableBuffer.getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary)) + { + // Object is offline. Handle it in the DB + getOfflineMoneyCustomPersistStep()->getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary); + } +} + +// ---------------------------------------------------------------------- + +OfflineMoneyCustomPersistStep * SwgSnapshot::getOfflineMoneyCustomPersistStep() +{ + if (!m_offlineMoneyCustomPersistStep) + { + m_offlineMoneyCustomPersistStep = new OfflineMoneyCustomPersistStep; + addCustomPersistStep(m_offlineMoneyCustomPersistStep); + } + return m_offlineMoneyCustomPersistStep; +} + +// ---------------------------------------------------------------------- + +void SwgSnapshot::decodeQuests(NetworkId const & networkId, Archive::ReadIterator &data, + DB::BufferString &part1, DB::BufferString &part2, + DB::BufferString &part3, DB::BufferString &part4) const +{ + + const int ki_num_parts = 4; + const int ki_chunk_size = DBSchema::PlayerObjectRow::QUEST_DATA_SIZE; + static const std::string space(" "); + + std::string packedValue; + Archive::AutoDeltaPackedMap::unpack(data,packedValue); + + if (packedValue.length() > ki_chunk_size * ki_num_parts) + { + // Remove completed quests to save space. This is a last-ditch effort to save a crash, not a good way to + // handle it. + + WARNING(true,("QuestData: Object %s had too much quest data to be stored in the database. Truncating.",networkId.getValueString().c_str())); + int charsToRemove = packedValue.length() - ki_chunk_size * ki_num_parts; + char const * sourcePos = packedValue.c_str(); + std::string newPackedValue; + bool activeQuest=false; + char entry[100]; + char * entryPos = entry; + while (charsToRemove > 0 && *sourcePos != '\0') + { + *(entryPos++)=*sourcePos; + + if (*sourcePos==' ') + activeQuest=true; + if (*(sourcePos++)==':') + { + if (activeQuest) + { + // copy this active quest + *entryPos='\0'; + newPackedValue+=entry; + entryPos=entry; + activeQuest=false; + } + else + { + // don't copy this completed quest + charsToRemove -= entryPos-entry; + entryPos=entry; + } + } + } + packedValue = newPackedValue + sourcePos; + } + + + part1=std::string(packedValue,0,ki_chunk_size); + + // part2 + if (packedValue.length() > ki_chunk_size * 1) + part2=std::string(packedValue, ki_chunk_size * 1, ki_chunk_size); + else + part2=space; + + // part3 + if (packedValue.length() > ki_chunk_size * 2) + part3=std::string(packedValue, ki_chunk_size * 2, ki_chunk_size); + else + part3=space; + + // part4 + if (packedValue.length() > ki_chunk_size * 3) + part4=std::string(packedValue, ki_chunk_size * 3, ki_chunk_size); + else + part4=space; + } + +// ---------------------------------------------------------------------- + +void SwgSnapshot::encodeQuests(Archive::ByteStream &data, + DB::BufferString const &part1, DB::BufferString const &part2, + DB::BufferString const &part3, DB::BufferString const &part4) const +{ + std::string packedValue; + std::string packedValue2; + std::string packedValue3; + std::string packedValue4; + part1.getValue(packedValue); + part2.getValue(packedValue2); + part3.getValue(packedValue3); + part4.getValue(packedValue4); + if (packedValue2!=" ") + packedValue+=packedValue2; + if (packedValue3!=" ") + packedValue+=packedValue3; + if (packedValue4!=" ") + packedValue+=packedValue4; + Archive::AutoDeltaPackedMap::pack(data, packedValue); +} + +// ---------------------------------------------------------------------- + +#ifdef WIN32 +static const char* oldschoolBuffFormat = "%lu %I64u"; +static const char* versionTwoFormat = "%u %u %f %u %I64i %u:"; +#else +static const char* oldschoolBuffFormat = "%lu %llu"; +static const char* versionTwoFormat = "%u %u %f %u %lli %u:"; +#endif + +static const char* versionOneFormat = "%u %u %f %u:"; +static const char* versionFormat = "%uv"; + +void SwgSnapshot::decodePersistedBuffs (Archive::ReadIterator &data, DB::BufferString &dbString) const +{ + const unsigned version = 2; + + std::string packedValue; + + Archive::AutoDeltaMap temp; + Archive::get(data, temp); + std::map const& rawMap = temp.getMap(); + + FormattedString<200> formater; + + if(rawMap.empty()) + { + packedValue = " "; + } + else + { + packedValue += formater.sprintf(versionFormat, version); + + for(std::map::const_iterator i = rawMap.begin(); i != rawMap.end(); ++i) + { + uint32 tempCrc = (*i).first; + Buff::PackedBuff const & tempPacked = (*i).second; + packedValue += formater.sprintf(versionTwoFormat, tempCrc, tempPacked.endtime, tempPacked.value, tempPacked.duration, tempPacked.caster.getValue(), tempPacked.stackCount); + } + } + + dbString.setValue(packedValue); +} + +void SwgSnapshot::encodePersistedBuffs (Archive::ByteStream &data, DB::BufferString const& dbString) const +{ + // some persisted buffs in the database were written as a AutoDeltaPackedMap of Crc's and uint64 + // the new type ones are marked with a version number followed by a 'v' then the data + + std::string stringRepresentation; + dbString.getValue (stringRepresentation); + size_t numchars = stringRepresentation.size(); + + int version = -1; + + //format: [v] + + //extract the version + if (numchars > 0) + { + size_t vpos = stringRepresentation.find('v'); + if(vpos == stringRepresentation.npos) + { + version = 0; + } + else + { + std::string versionToken = stringRepresentation.substr(0,vpos); + sscanf(versionToken.c_str(), versionFormat, &version); + + stringRepresentation = stringRepresentation.substr(vpos+1); + } + } + + Archive::AutoDeltaMap::Command tempCommand; + std::vector::Command> commands; + char temp[200]; + + if(version == 0) + { + //string is the old AutoDeltaPackedMap written as [ :]* + uint64 tempPacked64; + uint32 tempCrc; + + int numbuffs = Archive::countCharacter(stringRepresentation,':'); + commands.reserve(numbuffs); + + int tempPos = 0; + for (std::string::const_iterator i=stringRepresentation.begin(); i!=stringRepresentation.end(); ++i) + { + if (*i==':') + { + temp[tempPos]='\0'; + sscanf(temp, oldschoolBuffFormat, &tempCrc, &tempPacked64); + + tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; + tempCommand.key = tempCrc; + tempCommand.value = Buff::makePackedBuff(tempPacked64); + + commands.push_back(tempCommand); + + tempPos=0; + } + else + { + temp[tempPos++]=*i; + } + } + } + else if (version == 1) + { + //version 1 written as [ :]* + uint32 tempCrc = 0, tempEndtime = 0, tempDuration = 0; + float tempValue = 0.0f; + + int numbuffs = Archive::countCharacter(stringRepresentation,':'); + commands.reserve(numbuffs); + + int tempPos = 0; + for (std::string::const_iterator i=stringRepresentation.begin(); i!=stringRepresentation.end(); ++i) + { + if (*i==':') + { + temp[tempPos]='\0'; + sscanf(temp, versionOneFormat, &tempCrc, &tempEndtime, &tempValue, &tempDuration); + + tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; + tempCommand.key = tempCrc; + tempCommand.value = Buff(tempCrc, tempEndtime, tempValue, tempDuration).getPackedBuffValue(); + + commands.push_back(tempCommand); + + tempPos=0; + } + else + { + temp[tempPos++]=*i; + } + } + } + else if (version == 2) + { + //version 2 written as [ :]* + uint32 tempCrc = 0, tempEndtime = 0, tempDuration = 0, tempStackCount = 0; + float tempValue = 0.0f; + int64 tempCaster = 0; + + int numbuffs = Archive::countCharacter(stringRepresentation,':'); + commands.reserve(numbuffs); + + int tempPos = 0; + for (std::string::const_iterator i=stringRepresentation.begin(); i!=stringRepresentation.end(); ++i) + { + if (*i==':') + { + temp[tempPos]='\0'; + sscanf(temp, versionTwoFormat, &tempCrc, &tempEndtime, &tempValue, &tempDuration, &tempCaster, &tempStackCount); + + tempCommand.cmd = Archive::AutoDeltaMap::Command::ADD; + tempCommand.key = tempCrc; + tempCommand.value = Buff(tempCrc, tempEndtime, tempValue, tempDuration, NetworkId(tempCaster), tempStackCount).getPackedBuffValue(); + + commands.push_back(tempCommand); + + tempPos=0; + } + else + { + temp[tempPos++]=*i; + } + } + } + else + { + //we don't know how to convert this string to buffs, treat it as though there were no buffs there at all + WARNING(true, ("encodePersistedBuffs: Cannot convert db string with version %d to buffs", version)); + } + + Archive::AutoDeltaMap::pack(data, commands); + +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.h b/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.h new file mode 100644 index 00000000..4e2c30a0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/SwgSnapshot.h @@ -0,0 +1,459 @@ +// ====================================================================== +// +// SwgSnapshot.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SwgSnapshot_H +#define INCLUDED_SwgSnapshot_H + +// ====================================================================== + +#include "Archive/ByteStream.h" +#include "serverDatabase/Snapshot.h" +#include "serverDatabase/TableBuffer.h" +#include "sharedFoundation/Tag.h" +#include "SwgDatabaseServer/BattlefieldParticipantBuffer.h" +#include "SwgDatabaseServer/BountyHunterTargetBuffer.h" +#include "SwgDatabaseServer/CreatureObjectBuffer.h" +#include "SwgDatabaseServer/ExperienceBuffer.h" +#include "SwgDatabaseServer/IndexedNetworkTableBuffer.h" +#include "SwgDatabaseServer/LocationBuffer.h" +#include "SwgDatabaseServer/ManufactureSchematicAttributeBuffer.h" +#include "SwgDatabaseServer/MessageBuffer.h" +#include "SwgDatabaseServer/ObjectQueries.h" +#include "SwgDatabaseServer/ObjectTableBuffer.h" +#include "SwgDatabaseServer/ObjvarBuffer.h" +#include "SwgDatabaseServer/PropertyListBuffer.h" +#include "SwgDatabaseServer/ResourceTypeBuffer.h" +#include "SwgDatabaseServer/Schema.h" +#include "SwgDatabaseServer/ScriptBuffer.h" +#include "SwgDatabaseServer/WaypointBuffer.h" + +namespace DB +{ + class Session; +} + +class BatchBaselinesMessageData; +class BaselinesMessage; +class DeltasMessage; +class GameServerConnection; +class ImmediateDeleteCustomPersistStep; +class NetworkTableBuffer; +class OfflineMoneyCustomPersistStep; +class UpdateObjectPositionMessage; + +typedef IndexedNetworkTableBuffer BattlefieldMarkerObjectBuffer; +typedef IndexedNetworkTableBuffer BuildingObjectBuffer; +typedef IndexedNetworkTableBuffer CellObjectBuffer; +typedef IndexedNetworkTableBuffer CityObjectBuffer; +typedef IndexedNetworkTableBuffer FactoryObjectBuffer; +typedef IndexedNetworkTableBuffer GuildObjectBuffer; +typedef IndexedNetworkTableBuffer HarvesterInstallationObjectBuffer; +typedef IndexedNetworkTableBuffer InstallationObjectBuffer; +typedef IndexedNetworkTableBuffer IntangibleObjectBuffer; +typedef IndexedNetworkTableBuffer ManufactureInstallationObjectBuffer; +typedef IndexedNetworkTableBuffer ManufactureSchematicObjectBuffer; +typedef IndexedNetworkTableBuffer MissionObjectBuffer; +typedef IndexedNetworkTableBuffer PlanetObjectBuffer; +typedef IndexedNetworkTableBuffer PlayerObjectBuffer; +typedef IndexedNetworkTableBuffer ResourceContainerObjectBuffer; +typedef IndexedNetworkTableBuffer ShipObjectBuffer; +typedef IndexedNetworkTableBuffer StaticObjectBuffer; +typedef IndexedNetworkTableBuffer TangibleObjectBuffer; +typedef IndexedNetworkTableBuffer UniverseObjectBuffer; +typedef IndexedNetworkTableBuffer VehicleObjectBuffer; +typedef IndexedNetworkTableBuffer WeaponObjectBuffer; +typedef IndexedNetworkTableBuffer PlayerQuestObjectBuffer; +// ====================================================================== + +/** + * A Snapshot customized to Star Wars Galaxies. + * + * @todo: there are a lot of public functions that could be made private + */ +class SwgSnapshot : public Snapshot +{ +public: + SwgSnapshot(DB::ModeQuery::Mode mode, bool useGoldDatabase); + ~SwgSnapshot(); + + // Network Functions: + virtual void handleUpdateObjectPosition(const UpdateObjectPositionMessage &message); + virtual void handleDeleteMessage (const NetworkId &objectID, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason); + virtual void handleMessageTo (const MessageToPayload &data); + virtual void handleMessageToAck (const MessageToId &messageId); + virtual void handleAddResourceTypeMessage (AddResourceTypeMessage const & message); + virtual void handleBountyHunterTargetMessage (const BountyHunterTargetMessage &message); + virtual bool send (GameServerConnection *connection) const; + + // Misc game-specific persistence + void getMoneyFromOfflineObject (uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary); + + // Saving and Loading: + virtual bool saveToDB(DB::Session *session); + virtual bool load (DB::Session *session); + virtual void saveCompleted (); + virtual void getWorldContainers (stdvector::fwd &containers) const; + + virtual void handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message); + virtual void startLoadAfterSaveComplete(); + + // Functions for object creation: + virtual void newObject(NetworkId const & objectId, int templateId, Tag typeId); + + void newBattlefieldMarkerObject (NetworkId const & objectId); + void newBuildingObject (NetworkId const & objectId); + void newCellObject (NetworkId const & objectId); + void newCityObject (NetworkId const & objectId); + void newCountingObject (NetworkId const & objectId); + void newCreatureObject (NetworkId const & objectId); + void newFactoryObject (NetworkId const & objectId); + void newGuildObject (NetworkId const & objectId); + void newHarvesterInstallationObject (NetworkId const & objectId); + void newInstallationObject (NetworkId const & objectId); + void newIntangibleObject (NetworkId const & objectId); + void newManufactureInstallationObject (NetworkId const & objectId); + void newManufactureSchematicObject (NetworkId const & objectId); + void newMissionObject (NetworkId const & objectId); + void newPlanetObject (NetworkId const & objectId); + void newPlayerObject (NetworkId const & objectId); + void newPlayerQuestObject (NetworkId const & objectId); + void newRegionCircleObject (NetworkId const & objectId); + void newRegionObject (NetworkId const & objectId); + void newRegionRectangleObject (NetworkId const & objectId); + void newResourceContainerObject (NetworkId const & objectId); + void newShipObject (NetworkId const & objectId); + void newStaticObject (NetworkId const & objectId); + void newTangibleObject (NetworkId const & objectId); + void newUniverseObject (NetworkId const & objectId); + void newVehicleObject (NetworkId const & objectId); + void newWeaponObject (NetworkId const & objectId); + + // Functions for object loading: +// virtual void addObjectIdForLoad(NetworkId const & objectId); + + void loadAttributes (DB::Session *session, NetworkId const & objectId); + void loadBattlefieldMarkerObject (DB::Session *session, NetworkId const & objectId); + void loadBuildingObject (DB::Session *session, NetworkId const & objectId); + void loadCellObject (DB::Session *session, NetworkId const & objectId); + void loadCityObject (DB::Session *session, NetworkId const & objectId); + void loadCommands (DB::Session *session, NetworkId const & objectId); + void loadCountingObject (DB::Session *session, NetworkId const & objectId); + void loadCreatureObject (DB::Session *session, NetworkId const & objectId); + void loadFactoryObject (DB::Session *session, NetworkId const & objectId); + void loadGuildObject (DB::Session *session, NetworkId const & objectId); + void loadHarvesterInstallationObject (DB::Session *session, NetworkId const & objectId); + void loadInstallationObject (DB::Session *session, NetworkId const & objectId); + void loadIntangibleObject (DB::Session *session, NetworkId const & objectId); + void loadManufactureInstallationObject (DB::Session *session, NetworkId const & objectId); + void loadManufactureSchematicObject (DB::Session *session, NetworkId const & objectId); + void loadMissionObject (DB::Session *session, NetworkId const & objectId); + void loadPlanetObject (DB::Session *session, NetworkId const & objectId); + void loadPlayerObject (DB::Session *session, NetworkId const & objectId); + void loadPlayerQuestObject (DB::Session *session, NetworkId const & objectId); + void loadRegionCircleObject (DB::Session *session, NetworkId const & objectId); + void loadRegionObject (DB::Session *session, NetworkId const & objectId); + void loadRegionRectangleObject (DB::Session *session, NetworkId const & objectId); + void loadResourceContainerObject (DB::Session *session, NetworkId const & objectId); + void loadSkills (DB::Session *session, NetworkId const & objectId); + void loadShipObject (DB::Session *session, NetworkId const & objectId); + void loadStaticObject (DB::Session *session, NetworkId const & objectId); + void loadTangibleObject (DB::Session *session, NetworkId const & objectId); + void loadUniverseObject (DB::Session *session, NetworkId const & objectId); + void loadVehicleObject (DB::Session *session, NetworkId const & objectId); + void loadWeaponObject (DB::Session *session, NetworkId const & objectId); + + +protected: + BattlefieldMarkerObjectBuffer m_battlefieldMarkerObjectBuffer; + BattlefieldParticipantBuffer m_battlefieldParticipantBuffer; + BountyHunterTargetBuffer m_bountyHunterTargetBuffer; + BuildingObjectBuffer m_buildingObjectBuffer; + CellObjectBuffer m_cellObjectBuffer; + CityObjectBuffer m_cityObjectBuffer; + CreatureObjectBuffer m_creatureObjectBuffer; + ExperienceBuffer m_experienceBuffer; + FactoryObjectBuffer m_factoryObjectBuffer; + GuildObjectBuffer m_guildObjectBuffer; + HarvesterInstallationObjectBuffer m_harvesterInstallationObjectBuffer; + InstallationObjectBuffer m_installationObjectBuffer; + IntangibleObjectBuffer m_intangibleObjectBuffer; + LocationBuffer m_locationBuffer; + ManufactureInstallationObjectBuffer m_manufactureInstallationObjectBuffer; + ManufactureSchematicAttributeBuffer m_manufactureSchematicAttributeBuffer; + ManufactureSchematicObjectBuffer m_manufactureSchematicObjectBuffer; + MessageBuffer m_messageBuffer; + MissionObjectBuffer m_missionObjectBuffer; + ObjectTableBuffer m_objectTableBuffer; + ObjvarBuffer m_objvarBuffer; + PlanetObjectBuffer m_planetObjectBuffer; + PlayerObjectBuffer m_playerObjectBuffer; + PlayerQuestObjectBuffer m_playerQuestObjectBuffer; + PropertyListBuffer m_propertyListBuffer; + ResourceContainerObjectBuffer m_resourceContainerObjectBuffer; + ResourceTypeBuffer m_resourceTypeBuffer; + ScriptBuffer m_scriptBuffer; + ShipObjectBuffer m_shipObjectBuffer; + StaticObjectBuffer m_staticObjectBuffer; + TangibleObjectBuffer m_tangibleObjectBuffer; + UniverseObjectBuffer m_universeObjectBuffer; + VehicleObjectBuffer m_vehicleObjectBuffer; + WaypointBuffer m_waypointBuffer; + WeaponObjectBuffer m_weaponObjectBuffer; + + typedef std::vector OIDListType; +// OIDListType m_oidList; + + ImmediateDeleteCustomPersistStep *m_immediateDeleteStep; + OfflineMoneyCustomPersistStep *m_offlineMoneyCustomPersistStep; + + private: + void registerTags(); + + void loadObject(DB::Session *session,const Tag &typeId, const NetworkId &objectId); + + virtual void decodeServerData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + virtual void decodeSharedData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + virtual void decodeClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + virtual void decodeParentClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline); + + virtual bool encodeParentClientData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + virtual bool encodeClientData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + virtual bool encodeServerData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + virtual bool encodeSharedData(NetworkId const & objectId, Tag typeId, stdvector::fwd &baselines) const; + + void decodeClientBattlefieldMarkerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientBuildingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientCellObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientCityObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientCreatureObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientGuildObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientHarvesterInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientIntangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientManufactureInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientMissionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientPlanetObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientPlayerQuestObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientRegionCircleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientRegionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientRegionRectangleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientResourceContainerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientServerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientShipObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientStaticObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientTangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientUniverseObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientVehicleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientWeaponObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + + void decodeServerBattlefieldMarkerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerBuildingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerCellObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerCityObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerCreatureObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerGuildObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerHarvesterInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerIntangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerManufactureInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerMissionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerPlanetObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerPlayerQuestObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerRegionCircleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerRegionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerRegionRectangleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerResourceContainerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerServerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerShipObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerStaticObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerTangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerUniverseObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerVehicleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerWeaponObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + + void decodeSharedBattlefieldMarkerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedBuildingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedCellObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedCityObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedCreatureObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedGuildObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedHarvesterInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedIntangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedManufactureInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedMissionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedPlanetObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedPlayerQuestObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedRegionCircleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedRegionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedRegionRectangleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedResourceContainerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedServerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedShipObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedStaticObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedTangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedUniverseObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedVehicleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedWeaponObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + + void decodeServerManufactureSchematicObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientManufactureSchematicObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeSharedManufactureSchematicObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + bool encodeServerManufactureSchematicObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientManufactureSchematicObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedManufactureSchematicObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + void decodeSharedFactoryObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerFactoryObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientFactoryObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + bool encodeServerFactoryObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedFactoryObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientFactoryObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + + void decodeSharedCountingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeServerCountingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + void decodeClientCountingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + + bool encodeSharedCountingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerCountingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientCountingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + + bool encodeClientBattlefieldMarkerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientBuildingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientCellObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientCityObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientCreatureObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientGuildObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientHarvesterInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientIntangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientManufactureInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientMissionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientPlanetObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientPlayerQuestObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientRegionCircleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientRegionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientRegionRectangleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientResourceContainerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientServerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientShipObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientStaticObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientTangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientUniverseObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientVehicleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeClientWeaponObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + + bool encodeServerBattlefieldMarkerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerBuildingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerCellObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerCityObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerCreatureObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerGuildObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerHarvesterInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerIntangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerManufactureInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerMissionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerPlanetObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerPlayerQuestObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerRegionCircleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerRegionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerRegionRectangleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerResourceContainerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerServerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerShipObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerStaticObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerTangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerUniverseObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerVehicleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeServerWeaponObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + + bool encodeSharedBattlefieldMarkerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedBuildingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedCellObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedCityObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedCreatureObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedGuildObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedHarvesterInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedIntangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedManufactureInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedMissionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedPlanetObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedPlayerQuestObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedRegionCircleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedRegionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedRegionRectangleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedResourceContainerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedServerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedShipObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedStaticObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedTangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedUniverseObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedVehicleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + bool encodeSharedWeaponObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + + void decodeParentClientPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline); + bool encodeParentClientPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const; + + private: + void decodeAttributes (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline, int offset); + void decodeBattlefieldParticipants(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline); + void decodePropertyList (const NetworkId &objectId, int listId, Archive::ReadIterator &data, bool isBaseline); + void decodeExperience (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeLocationDataList (const NetworkId &objectId, size_t listId, Archive::ReadIterator &data, bool isBaseline); + void decodeManufactureSchematicAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeMissionLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableString<500> &planet, DB::BindableString<500> ®ion_name,DB::BindableNetworkId &cell) const; + void decodeObjVars (NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeObjVarFreeFlags (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeScriptObject (NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeStringId (Archive::ReadIterator &data,DB::BufferString &table,DB::BufferString &text) const; + void decodeVector (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z) const; + void decodeMatchMakingId (Archive::ReadIterator &data, DB::BufferString &column) const; + void decodeComponents (NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableNetworkId &cell, DB::BindableLong &planet) const; + void decodeWaypoints (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeSingleWaypoint (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline); + void decodeQuests (NetworkId const & networkId, Archive::ReadIterator &data, DB::BufferString &part1, DB::BufferString &part2, DB::BufferString &part3, DB::BufferString &part4) const; + void decodePersistedBuffs (Archive::ReadIterator &data, DB::BufferString &dbString) const; + + void encodeAttributes (const NetworkId & objectId, Archive::ByteStream &data, int offset) const; + void encodeBattlefieldParticipants(const NetworkId &objectId, Archive::ByteStream &data) const; + void encodePropertyList (const NetworkId & objectId, int listId, Archive::ByteStream &data) const; + void encodeExperience (const NetworkId & objectId, Archive::ByteStream &data) const; + void encodeLocationDataList (const NetworkId & objectId, size_t listId, Archive::ByteStream &data) const; + void encodeManufactureSchematicAttributes(const NetworkId & objectId, Archive::ByteStream &data) const; + void encodeMissionLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableString<500> &planet, const DB::BindableString<500> ®ion_name, const DB::BindableNetworkId &cell) const; + void encodeObjVars (const NetworkId & objectId, Archive::ByteStream &data) const; + void encodeObjVarFreeFlags (const NetworkId & objectId, Archive::ByteStream &data) const; + void encodeScriptObject (const NetworkId & objectId, Archive::ByteStream &data) const; + void encodeStringId (Archive::ByteStream &data, const DB::BufferString &table, const DB::BufferString &text) const; + void encodeVector (Archive::ByteStream &data, const DB::BindableDouble &x, const DB::BindableDouble &y, const DB::BindableDouble &z) const; + void encodeMatchMakingId (Archive::ByteStream &data, const DB::BufferString &column) const; + void encodeComponents (const NetworkId &objectId, Archive::ByteStream &data) const; + void encodeLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableNetworkId &cell, const DB::BindableLong &planet) const; + void encodeWaypoints (const NetworkId & objectId, Archive::ByteStream &data) const; + void encodeSingleWaypoint (const NetworkId & objectId, Archive::ByteStream &data) const; + void encodeQuests (Archive::ByteStream &data, DB::BufferString const &part1, DB::BufferString const &part2, DB::BufferString const &part3, DB::BufferString const &part4) const; + void encodePersistedBuffs (Archive::ByteStream &data, DB::BufferString const& dbString) const; + + void ignorePersistedFlag (const NetworkId &objectId, Archive::ReadIterator &data) const; + + OfflineMoneyCustomPersistStep * SwgSnapshot::getOfflineMoneyCustomPersistStep(); + + private: + SwgSnapshot(const SwgSnapshot&); //disable + SwgSnapshot &operator=(const SwgSnapshot&); //disable +}; + +// ====================================================================== +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetAuctionAttributeList.h b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetAuctionAttributeList.h new file mode 100644 index 00000000..c1660d04 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetAuctionAttributeList.h @@ -0,0 +1 @@ +#include "../tasks/TaskGetAuctionAttributeList.h" diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetAuctionList.h b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetAuctionList.h new file mode 100644 index 00000000..f54a4233 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetAuctionList.h @@ -0,0 +1 @@ +#include "../tasks/TaskGetAuctionList.h" diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetBidList.h b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetBidList.h new file mode 100644 index 00000000..3dbbe292 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetBidList.h @@ -0,0 +1 @@ +#include "../tasks/TaskGetBidList.h" diff --git a/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetLocationList.h b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetLocationList.h new file mode 100644 index 00000000..d214f152 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/core/TaskGetLocationList.h @@ -0,0 +1 @@ +#include "../tasks/TaskGetLocationList.h" diff --git a/game/server/application/SwgDatabaseServer/src/shared/generated/Decoder_cpp.template b/game/server/application/SwgDatabaseServer/src/shared/generated/Decoder_cpp.template new file mode 100644 index 00000000..7005f139 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/generated/Decoder_cpp.template @@ -0,0 +1,52 @@ +// GENERATED CODE +// DO NOT EDIT THIS FILE + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/SwgSnapshot.h" + +#include "Archive/Archive.h" +#include "Archive/AutoDeltaPackedMap.h" +#include "sharedFoundation/AutoDeltaNetworkIdPackedMap.h" +#include "Archive/ByteStream.h" +#include "ObjectTableBuffer.h" +#include "Schema.h" +#include "ScriptBuffer.h" +#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h" +#include "serverGame/ServerBuildingObjectTemplate.h" +#include "serverGame/ServerCellObjectTemplate.h" +#include "serverGame/ServerCityObjectTemplate.h" +#include "serverGame/ServerCreatureObjectTemplate.h" +#include "serverGame/ServerFactoryObjectTemplate.h" +#include "serverGame/ServerGuildObjectTemplate.h" +#include "serverGame/ServerHarvesterInstallationObjectTemplate.h" +#include "serverGame/ServerInstallationObjectTemplate.h" +#include "serverGame/ServerIntangibleObjectTemplate.h" +#include "serverGame/ServerManufactureInstallationObjectTemplate.h" +#include "serverGame/ServerManufactureSchematicObjectTemplate.h" +#include "serverGame/ServerMissionObjectTemplate.h" +#include "serverGame/ServerObjectTemplate.h" +#include "serverGame/ServerPlanetObjectTemplate.h" +#include "serverGame/ServerPlayerQuestObjectTemplate.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "serverGame/ServerResourceContainerObjectTemplate.h" +#include "serverGame/ServerShipObjectTemplate.h" +#include "serverGame/ServerStaticObjectTemplate.h" +#include "serverGame/ServerTangibleObjectTemplate.h" +#include "serverGame/ServerVehicleObjectTemplate.h" +#include "serverGame/ServerWeaponObjectTemplate.h" +#include "serverUtility/MissionLocation.h" +#include "sharedDatabaseInterface/NullEncodedUnicodeString.h" +#include "sharedDatabaseInterface/NullEncodedStandardString.h" +#include "sharedFoundation/StationId.h" +#include "sharedGame/Buff.h" +#include "sharedGame/PlayerQuestData.h" +#include "swgSharedUtility/Attributes.def" +#include "swgSharedUtility/Postures.def" +#include "unicodeArchive/UnicodeArchive.h" + +// Auto-generated code has some warnings, but code is OK +#pragma warning(disable : 4065) +#pragma warning(disable : 4100) + +//!!!BEGIN GENERATED DECODER +//!!!END GENERATED DECODER diff --git a/game/server/application/SwgDatabaseServer/src/shared/generated/Encoder_cpp.template b/game/server/application/SwgDatabaseServer/src/shared/generated/Encoder_cpp.template new file mode 100644 index 00000000..494b6ce0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/generated/Encoder_cpp.template @@ -0,0 +1,53 @@ +// GENERATED CODE +// DO NOT EDIT THIS FILE + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/SwgSnapshot.h" + +#include "Archive/Archive.h" +#include "Archive/AutoDeltaPackedMap.h" +#include "Archive/ByteStream.h" +#include "ObjectTableBuffer.h" +#include "Schema.h" +#include "ScriptBuffer.h" +#include "serverDatabase/GameServerConnection.h" +#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h" +#include "serverGame/ServerBuildingObjectTemplate.h" +#include "serverGame/ServerCellObjectTemplate.h" +#include "serverGame/ServerCityObjectTemplate.h" +#include "serverGame/ServerCreatureObjectTemplate.h" +#include "serverGame/ServerFactoryObjectTemplate.h" +#include "serverGame/ServerGuildObjectTemplate.h" +#include "serverGame/ServerHarvesterInstallationObjectTemplate.h" +#include "serverGame/ServerInstallationObjectTemplate.h" +#include "serverGame/ServerIntangibleObjectTemplate.h" +#include "serverGame/ServerManufactureInstallationObjectTemplate.h" +#include "serverGame/ServerManufactureSchematicObjectTemplate.h" +#include "serverGame/ServerMissionObjectTemplate.h" +#include "serverGame/ServerObjectTemplate.h" +#include "serverGame/ServerPlanetObjectTemplate.h" +#include "serverGame/ServerPlayerQuestObjectTemplate.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "serverGame/ServerResourceContainerObjectTemplate.h" +#include "serverGame/ServerShipObjectTemplate.h" +#include "serverGame/ServerStaticObjectTemplate.h" +#include "serverGame/ServerTangibleObjectTemplate.h" +#include "serverGame/ServerVehicleObjectTemplate.h" +#include "serverGame/ServerWeaponObjectTemplate.h" +#include "serverUtility/MissionLocation.h" +#include "sharedDatabaseInterface/NullEncodedUnicodeString.h" +#include "sharedDatabaseInterface/NullEncodedStandardString.h" +#include "sharedDebug/Profiler.h" +#include "sharedFoundation/StationId.h" +#include "sharedGame/Buff.h" +#include "sharedGame/PlayerQuestData.h" +#include "sharedNetworkMessages/BaselinesMessage.h" +#include "sharedNetworkMessages/BatchBaselinesMessage.h" +#include "swgSharedUtility/Attributes.def" +#include "swgSharedUtility/Postures.def" +#include "unicodeArchive/UnicodeArchive.h" + +#include + +//!!!BEGIN GENERATED ENCODER +//!!!END GENERATED ENCODER diff --git a/game/server/application/SwgDatabaseServer/src/shared/generated/LoadObject_cpp.template b/game/server/application/SwgDatabaseServer/src/shared/generated/LoadObject_cpp.template new file mode 100644 index 00000000..1a0e94ac --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/generated/LoadObject_cpp.template @@ -0,0 +1,31 @@ +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/SwgSnapshot.h" + +#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h" +#include "serverGame/ServerBuildingObjectTemplate.h" +#include "serverGame/ServerCellObjectTemplate.h" +#include "serverGame/ServerCityObjectTemplate.h" +#include "serverGame/ServerConstructionContractObjectTemplate.h" +#include "serverGame/ServerCreatureObjectTemplate.h" +#include "serverGame/ServerDraftSchematicObjectTemplate.h" +#include "serverGame/ServerFactoryObjectTemplate.h" +#include "serverGame/ServerGuildObjectTemplate.h" +#include "serverGame/ServerHarvesterInstallationObjectTemplate.h" +#include "serverGame/ServerInstallationObjectTemplate.h" +#include "serverGame/ServerManufactureInstallationObjectTemplate.h" +#include "serverGame/ServerManufactureSchematicObjectTemplate.h" +#include "serverGame/ServerMissionObjectTemplate.h" +#include "serverGame/ServerObjectTemplate.h" +#include "serverGame/ServerPlanetObjectTemplate.h" +#include "serverGame/ServerPlayerQuestObjectTemplate.h" +#include "serverGame/ServerPlayerObjectTemplate.h" +#include "serverGame/ServerResourceContainerObjectTemplate.h" +#include "serverGame/ServerShipObjectTemplate.h" +#include "serverGame/ServerStaticObjectTemplate.h" +#include "serverGame/ServerTangibleObjectTemplate.h" +#include "serverGame/ServerVehicleObjectTemplate.h" +#include "serverGame/ServerWeaponObjectTemplate.h" + + +//!!!BEGIN GENERATED LOADOBJECT +//!!!END GENERATED LOADOBJECT diff --git a/game/server/application/SwgDatabaseServer/src/shared/generated/ObjectQueries_cpp.template b/game/server/application/SwgDatabaseServer/src/shared/generated/ObjectQueries_cpp.template new file mode 100644 index 00000000..067f2fac --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/generated/ObjectQueries_cpp.template @@ -0,0 +1,23 @@ +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "ObjectQueries.h" +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcess.h" + +using namespace DBQuery; +using namespace DBSchema; + +// ====================================================================== + +namespace ObjectQueriesNamespace +{ + const int ms_fetchBatchSize = 1000; +} +using namespace ObjectQueriesNamespace; + +// ====================================================================== + +//!!!BEGIN GENERATED QUERYDEFINITIONS + +//!!!END GENERATED QUERYDEFINITIONS + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/generated/ObjectQueries_h.template b/game/server/application/SwgDatabaseServer/src/shared/generated/ObjectQueries_h.template new file mode 100644 index 00000000..60021931 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/generated/ObjectQueries_h.template @@ -0,0 +1,34 @@ +// ====================================================================== +// +// ObjectQueries.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ObjectQueries_H +#define INCLUDED_ObjectQueries_H + +// ====================================================================== + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcessQuery.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "sharedFoundation/NetworkId.h" + +#include + +// ====================================================================== + +namespace DBQuery +{ + +//!!!BEGIN GENERATED QUERYDECLARATIONS + +//!!!END GENERATED QUERYDECLARATIONS + +// ====================================================================== + +} // namespace + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/generated/Schema_h.template b/game/server/application/SwgDatabaseServer/src/shared/generated/Schema_h.template new file mode 100644 index 00000000..0be172b0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/generated/Schema_h.template @@ -0,0 +1,258 @@ +// ====================================================================== +// +// Schema.h +// copyright (c) 2001 Sony Online Entertainment +// +// Edit the file Schema_h.template. Do not edit Schema.h. +// +// ====================================================================== + +#ifndef INCLUDED_Schema_H +#define INCLUDED_Schema_H + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/BufferString.h" +#include "sharedDatabaseInterface/DbRow.h" + +namespace DBSchema +{ + +struct PlayerObjectRow : public DB::Row +{ + enum {QUEST_DATA_SIZE=4000}; + + DB::BindableNetworkId object_id; + DB::BindableLong station_id; + DB::BindableNetworkId house_id; + DB::BindableLong account_num_lots; + DB::BindableBool account_is_outcast; + DB::BindableDouble account_cheater_level; + DB::BindableLong account_max_lots_adjustment; + DB::BindableString<200> personal_profile_id; + DB::BindableString<200> character_profile_id; + DB::BindableString<200> skill_title; + DB::BindableLong born_date; + DB::BindableLong played_time; + DB::BindableDouble force_regen_rate; + DB::BindableLong force_power; + DB::BindableLong max_force_power; + DB::BindableBitArray<2047> active_quests; + DB::BindableBitArray<2047> completed_quests; + DB::BindableLong current_quest; + DB::BindableString quests; + DB::BindableLong role_icon_choice; + DB::BindableString quests2; + DB::BindableString quests3; + DB::BindableString quests4; + DB::BindableString<200> skill_template; + DB::BindableString<200> working_skill; + DB::BindableLong current_gcw_points; + DB::BindableLong current_gcw_rating; + DB::BindableLong current_pvp_kills; + DB::BindableInt64 lifetime_gcw_points; + DB::BindableLong max_gcw_imperial_rating; + DB::BindableLong max_gcw_rebel_rating; + DB::BindableLong lifetime_pvp_kills; + DB::BindableLong next_gcw_rating_calc_time; + DB::BindableBitArray<16000> collections; + DB::BindableBool show_backpack; + DB::BindableBool show_helmet; + DB::BindableBitArray<16000> collections2; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + + void setPrimaryKey(const NetworkId &keyValue) + { + object_id.setValue(keyValue); + } + + NetworkId getPrimaryKey() const + { + return object_id.getValue(); + } + +}; + +struct PlayerObjectBufferRow : public DB::Row +{ + DB::BindableNetworkId object_id; + DB::BindableLong station_id; + DB::BindableNetworkId house_id; + DB::BindableLong account_num_lots; + DB::BindableBool account_is_outcast; + DB::BindableDouble account_cheater_level; + DB::BindableLong account_max_lots_adjustment; + DB::BufferString personal_profile_id; + DB::BufferString character_profile_id; + DB::BufferString skill_title; + DB::BindableLong born_date; + DB::BindableLong played_time; + DB::BindableDouble force_regen_rate; + DB::BindableLong force_power; + DB::BindableLong max_force_power; + DB::BindableBitArray<2047> active_quests; + DB::BindableBitArray<2047> completed_quests; + DB::BindableLong current_quest; + DB::BufferString quests; + DB::BindableLong role_icon_choice; + DB::BufferString quests2; + DB::BufferString quests3; + DB::BufferString quests4; + DB::BufferString skill_template; + DB::BufferString working_skill; + DB::BindableLong current_gcw_points; + DB::BindableLong current_gcw_rating; + DB::BindableLong current_pvp_kills; + DB::BindableInt64 lifetime_gcw_points; + DB::BindableLong max_gcw_imperial_rating; + DB::BindableLong max_gcw_rebel_rating; + DB::BindableLong lifetime_pvp_kills; + DB::BindableLong next_gcw_rating_calc_time; + DB::BindableBitArray<16000> collections; + DB::BindableBool show_backpack; + DB::BindableBool show_helmet; + DB::BindableBitArray<16000> collections2; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + + void setPrimaryKey(const NetworkId &keyValue) + { + object_id.setValue(keyValue); + } + + NetworkId getPrimaryKey() const + { + return object_id.getValue(); + } + + PlayerObjectBufferRow (const PlayerObjectRow & rhs) : + object_id (rhs.object_id), + station_id (rhs.station_id), + house_id (rhs.house_id), + account_num_lots (rhs.account_num_lots), + account_is_outcast (rhs.account_is_outcast), + account_cheater_level (rhs.account_cheater_level), + account_max_lots_adjustment (rhs.account_max_lots_adjustment), + personal_profile_id (rhs.personal_profile_id), + character_profile_id (rhs.character_profile_id), + skill_title (rhs.skill_title), + born_date (rhs.born_date), + played_time (rhs.played_time), + force_regen_rate (rhs.force_regen_rate), + force_power (rhs.force_power), + max_force_power (rhs.max_force_power), + active_quests (rhs.active_quests), + completed_quests (rhs.completed_quests), + current_quest (rhs.current_quest), + quests (rhs.quests), + role_icon_choice (rhs.role_icon_choice), + quests2 (rhs.quests2), + quests3 (rhs.quests3), + quests4 (rhs.quests4), + skill_template (rhs.skill_template), + working_skill (rhs.working_skill), + current_gcw_points (rhs.current_gcw_points), + current_gcw_rating (rhs.current_gcw_rating), + current_pvp_kills (rhs.current_pvp_kills), + lifetime_gcw_points (rhs.lifetime_gcw_points), + max_gcw_imperial_rating (rhs.max_gcw_imperial_rating), + max_gcw_rebel_rating (rhs.max_gcw_rebel_rating), + lifetime_pvp_kills (rhs.lifetime_pvp_kills), + next_gcw_rating_calc_time (rhs.next_gcw_rating_calc_time), + collections (rhs.collections), + show_backpack(rhs.show_backpack), + show_helmet(rhs.show_helmet), + collections2 (rhs.collections2) + { + } + + PlayerObjectBufferRow() : + object_id(), + station_id(), + house_id(), + account_num_lots(), + account_is_outcast(), + account_cheater_level(), + account_max_lots_adjustment(), + personal_profile_id(200), + character_profile_id(200), + skill_title(200), + born_date(), + played_time(), + force_regen_rate(), + force_power(), + max_force_power(), + active_quests(), + completed_quests(), + current_quest(), + quests(PlayerObjectRow::QUEST_DATA_SIZE), + role_icon_choice(), + quests2(PlayerObjectRow::QUEST_DATA_SIZE), + quests3(PlayerObjectRow::QUEST_DATA_SIZE), + quests4(PlayerObjectRow::QUEST_DATA_SIZE), + skill_template(200), + working_skill(200), + current_gcw_points(), + current_gcw_rating(), + current_pvp_kills(), + lifetime_gcw_points(), + max_gcw_imperial_rating(), + max_gcw_rebel_rating(), + lifetime_pvp_kills(), + next_gcw_rating_calc_time(), + collections(), + show_backpack(), + show_helmet(), + collections2() + { + } + +}; + +struct ObjectVariableRow : public DB::Row +{ + DB::BindableNetworkId object_id; + DB::BindableLong name_id; + DB::BindableLong type; + DB::BindableString<1000> value; + DB::BindableLong detached; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } +}; + +struct WaypointRow : public DB::Row +{ + DB::BindableNetworkId object_id; + DB::BindableNetworkId waypoint_id; + DB::BindableLong appearance_name_crc; + DB::BindableDouble location_x; + DB::BindableDouble location_y; + DB::BindableDouble location_z; + DB::BindableNetworkId location_cell; + DB::BindableLong location_scene; + DB::BindableUnicode<512> name; + DB::BindableLong color; + DB::BindableBool active; + DB::BindableBool detached; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } +}; + +//!!!BEGIN GENERATED DECLARATIONS +//!!!END GENERATED DECLARATIONS + +} +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/persistable/PersistableWaypoint.cpp b/game/server/application/SwgDatabaseServer/src/shared/persistable/PersistableWaypoint.cpp new file mode 100644 index 00000000..ba0c7cca --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/persistable/PersistableWaypoint.cpp @@ -0,0 +1,70 @@ +// ====================================================================== +// +// PersistableWaypoint.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/PersistableWaypoint.h" + +#include "Archive/Archive.h" +#include "sharedFoundation/NetworkIdArchive.h" +#include "sharedUtility/LocationArchive.h" +#include "unicodeArchive/UnicodeArchive.h" + +// ====================================================================== + +PersistableWaypoint::PersistableWaypoint() : + m_appearanceNameCrc(0), + m_location(), + m_name(), + m_networkId(NetworkId::cms_invalid), + m_color(0), + m_active(false), + m_detached(false) +{ +} + +#ifdef WIN32 +bool PersistableWaypoint::operator!=(const PersistableWaypoint& rhs) +{ + return m_networkId != rhs.m_networkId || + m_location != rhs.m_location || + m_name != rhs.m_name || + m_appearanceNameCrc != rhs.m_appearanceNameCrc || + m_color != rhs.m_color || + m_active != rhs.m_active || + m_detached != rhs.m_detached; +} +#endif + +// ====================================================================== + +namespace Archive +{ + void get (Archive::ReadIterator & source, PersistableWaypoint & target) + { + get(source, target.m_appearanceNameCrc); + get(source, target.m_location); + get(source, target.m_name); + get(source, target.m_networkId); + get(source, target.m_color); + get(source, target.m_active); + } + +//----------------------------------------------------------------------- + + void put (Archive::ByteStream & target, const PersistableWaypoint & source) + { + put(target, source.m_appearanceNameCrc); + put(target, source.m_location); + put(target, source.m_name); + put(target, source.m_networkId); + put(target, source.m_color); + put(target, source.m_active); + } + +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/persistable/PersistableWaypoint.h b/game/server/application/SwgDatabaseServer/src/shared/persistable/PersistableWaypoint.h new file mode 100644 index 00000000..7b6ec594 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/persistable/PersistableWaypoint.h @@ -0,0 +1,49 @@ +// ====================================================================== +// +// PersistableWaypoint.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_PersistableWaypoint_H +#define INCLUDED_PersistableWaypoint_H + +// ====================================================================== + +#include "sharedUtility/Location.h" +#include "Unicode.h" + +// ====================================================================== + +class PersistableWaypoint +{ + public: + unsigned int m_appearanceNameCrc; + Location m_location; + Unicode::String m_name; + NetworkId m_networkId; + unsigned char m_color; + bool m_active; + bool m_detached; + + public: + PersistableWaypoint(); +#ifdef WIN32 + bool operator!=(const PersistableWaypoint& rhs); +#endif +}; + +// ====================================================================== + +namespace Archive +{ + class ReadIterator; + class ByteStream; + + void get (Archive::ReadIterator & source, PersistableWaypoint & target); + void put (ByteStream & target, const PersistableWaypoint & source); +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/BattlefieldParticipantQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/BattlefieldParticipantQuery.cpp new file mode 100644 index 00000000..ff64211c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/BattlefieldParticipantQuery.cpp @@ -0,0 +1,134 @@ +// ====================================================================== +// +// BattlefieldParticipantQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/BattlefieldParticipantQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +using namespace DBQuery; + +// ====================================================================== + +BattlefieldParticipantQuery::BattlefieldParticipantQuery() : + ModeQuery(new DBSchema::BattlefieldParticipantRow) //lint !e1524 // We don't delete the new row (base class does) +{ +} + +// ---------------------------------------------------------------------- + +bool BattlefieldParticipantQuery::bindParameters() +{ + DBSchema::BattlefieldParticipantRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!bindParameter(myData->faction_id)) return false; + + if (!bindParameter(myData->character_object_id)) return false; + if (!bindParameter(myData->region_object_id)) return false; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + return true; +} + +bool BattlefieldParticipantQuery::bindColumns() +{ + DBSchema::BattlefieldParticipantRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } //lint !e788 //not all modes have an explicit case in the switch + + return true; +} + +// ---------------------------------------------------------------------- + +void BattlefieldParticipantQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_battlefield_participants (:faction_id, :character_object_id, :region_object_id); end;"; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } +} + +// ====================================================================== + +DBQuery::GetAllBattlefieldParticipant::GetAllBattlefieldParticipant(const std::string &schema) : + Query(), + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +bool GetAllBattlefieldParticipant::bindParameters() +{ + return true; +} + +bool GetAllBattlefieldParticipant::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].region_object_id)) return false; + if (!bindCol(m_data[0].character_object_id)) return false; + if (!bindCol(m_data[0].faction_id)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void GetAllBattlefieldParticipant::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_battlefield_participants(); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode GetAllBattlefieldParticipant::getExecutionMode() const +{ + if (getProtocol()==DB::PROTOCOL_OCI) + return (MODE_PLSQL_REFCURSOR); + else + { + FATAL(true,("ODBC mode is not supported for BattlefieldParticipant\n")); + return MODE_SQL; // return to avoid compiler warning + } +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/BattlefieldParticipantQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/BattlefieldParticipantQuery.h new file mode 100644 index 00000000..85e68956 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/BattlefieldParticipantQuery.h @@ -0,0 +1,66 @@ +// ====================================================================== +// +// BattlefieldParticipantQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_BattlefieldParticipantQuery_H +#define INCLUDED_BattlefieldParticipantQuery_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include + +// ====================================================================== + +namespace DBQuery +{ + + class BattlefieldParticipantQuery : public DB::ModeQuery + { + BattlefieldParticipantQuery(const BattlefieldParticipantQuery&); // disable + BattlefieldParticipantQuery& operator=(const BattlefieldParticipantQuery&); // disable + public: + BattlefieldParticipantQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + }; + +// ---------------------------------------------------------------------- + + class GetAllBattlefieldParticipant : public DB::Query + { + public: + GetAllBattlefieldParticipant(const std::string &schema); + + const std::vector &getData() const; + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode getExecutionMode() const; + + private: + GetAllBattlefieldParticipant(const GetAllBattlefieldParticipant&); // disable + GetAllBattlefieldParticipant& operator=(const GetAllBattlefieldParticipant&); // disable + + private: + std::vector m_data; + const std::string m_schema; + }; +} + +// ====================================================================== + +inline const std::vector &DBQuery::GetAllBattlefieldParticipant::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/BountyHunterTargetQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/BountyHunterTargetQuery.cpp new file mode 100644 index 00000000..19d7c733 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/BountyHunterTargetQuery.cpp @@ -0,0 +1,149 @@ +// ====================================================================== +// +// BountyHunterTargetQuery.cpp +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/BountyHunterTargetQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +namespace BountyHunterTargetQueryNamespace +{ + const int ms_fetchBatchSize = 1000; +} + +using namespace BountyHunterTargetQueryNamespace; +using namespace DBQuery; + +// ====================================================================== + +BountyHunterTargetQuery::BountyHunterTargetQuery() : + m_numItems(0) +{ +} + +// ---------------------------------------------------------------------- + +bool BountyHunterTargetQuery::setupData(DB::Session *session) +{ + if (!m_object_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_target_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool BountyHunterTargetQuery::addData(DBSchema::BountyHunterTargetRow const & data) +{ + if (!m_object_ids.push_back(data.object_id.getValueASCII())) return false; + if (!m_target_ids.push_back(data.target_id.getValueASCII())) return false; + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +int BountyHunterTargetQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetQuery::clearData() +{ + m_object_ids.clear(); + m_target_ids.clear(); + + m_numItems=0; +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetQuery::freeData() +{ + m_object_ids.free(); + m_target_ids.free(); +} + +// ---------------------------------------------------------------------- + + +bool BountyHunterTargetQuery::bindParameters() +{ + if (!bindParameter(m_object_ids)) return false; + if (!bindParameter(m_target_ids)) return false; + if (!bindParameter(m_numItems)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool BountyHunterTargetQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_bounty_hunter_target (:object_id, :target_id, :chunk_size); end;"; +} + +// ====================================================================== + +BountyHunterTargetQuerySelect::BountyHunterTargetQuerySelect(const std::string &schema) : + m_data(ms_fetchBatchSize), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +bool BountyHunterTargetQuerySelect::bindParameters () +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool BountyHunterTargetQuerySelect::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ms_fetchBatchSize); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].target_id)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +const std::vector & BountyHunterTargetQuerySelect::getData() const +{ + return m_data; +} + +// ---------------------------------------------------------------------- + +void BountyHunterTargetQuerySelect::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_bounty_hunter_targets; end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode BountyHunterTargetQuerySelect::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/BountyHunterTargetQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/BountyHunterTargetQuery.h new file mode 100644 index 00000000..0284094b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/BountyHunterTargetQuery.h @@ -0,0 +1,74 @@ +// ====================================================================== +// +// BountyHunterTargetQuery,h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_BountyHunterTargetQuery_H +#define INCLUDED_BountyHunterTargetQuery_H + +// ====================================================================== + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcessQuery.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" + +#include + +// ====================================================================== + +namespace DBQuery +{ + class BountyHunterTargetQuery : public DB::Query + { + BountyHunterTargetQuery(const BountyHunterTargetQuery&); + BountyHunterTargetQuery& operator= (const BountyHunterTargetQuery&); + public: + BountyHunterTargetQuery(); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(DBSchema::BountyHunterTargetRow const & data); + void clearData(); + void freeData(); + + int getNumItems() const; + + private: + DB::BindableVarrayString m_object_ids; + DB::BindableVarrayString m_target_ids; + DB::BindableLong m_numItems; + }; + + + class BountyHunterTargetQuerySelect : public DB::Query + { + public: + BountyHunterTargetQuerySelect(const std::string &schema); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL (std::string &sql); + + const std::vector & getData() const; + + protected: + virtual QueryMode getExecutionMode() const; + + private: + std::vector m_data; + const std::string m_schema; + + BountyHunterTargetQuerySelect (const BountyHunterTargetQuerySelect&); + BountyHunterTargetQuerySelect& operator= (const BountyHunterTargetQuerySelect&); + }; + +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesQuery.cpp new file mode 100644 index 00000000..9a245c47 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesQuery.cpp @@ -0,0 +1,988 @@ +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "CommoditiesQuery.h" +#include "serverDatabase/DatabaseProcess.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" + +using namespace DBQuery; +using namespace DBSchema; + + +// Static instance counters +volatile int AuctionLocationsRow::m_sAuctionRowsCreated = 0; +volatile int AuctionLocationsRow::m_sAuctionRowsDeleted = 0; + +volatile int MarketAuctionsRow::m_sAuctionRowsCreated = 0; +volatile int MarketAuctionsRow::m_sAuctionRowsDeleted = 0; + +volatile int MarketAuctionsRowDelete::m_sAuctionRowsCreated = 0; +volatile int MarketAuctionsRowDelete::m_sAuctionRowsDeleted = 0; + +volatile int MarketAuctionsRowUpdate::m_sAuctionRowsCreated = 0; +volatile int MarketAuctionsRowUpdate::m_sAuctionRowsDeleted = 0; + +volatile int MarketAuctionBidsRow::m_sAuctionRowsCreated = 0; +volatile int MarketAuctionBidsRow::m_sAuctionRowsDeleted = 0; + + + +// ====================================================================== + +namespace CommoditiesQueryNamespace +{ + const int ms_fetchBatchSize = 1000; +} +using namespace CommoditiesQueryNamespace; + +// ====================================================================== + +AuctionLocationsQuery::AuctionLocationsQuery() : + DatabaseProcessQuery(new AuctionLocationsRow), + m_numItems(0) +{ +} + +bool AuctionLocationsQuery::setupData(DB::Session *session) +{ + + switch(mode) + { + case mode_UPDATE: + if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_location_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_sales_taxes.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_sales_tax_bank_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_empty_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_last_access_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_inactive_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_status.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_search_enabled.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_entrance_charge.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + break; + + case mode_INSERT: + if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_location_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_sales_taxes.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_sales_tax_bank_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_empty_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_last_access_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_inactive_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_status.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_search_enabled.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_entrance_charge.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + return true; +} + +bool AuctionLocationsQuery::addData(const DB::Row *_data) +{ + const AuctionLocationsRow *myData=dynamic_cast(_data); + FATAL(myData == NULL, ("Adding NULL data into AuctionLocations")); + switch(mode) + { + case mode_UPDATE: + if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false; + if (!m_location_names.push_back(myData->location_name.getValueASCII())) return false; + if (!m_owner_ids.push_back(myData->owner_id.isNull(), myData->owner_id.getValueASCII())) return false; + if (!m_sales_taxes.push_back(myData->sales_tax.isNull(), myData->sales_tax.getValue())) return false; + if (!m_sales_tax_bank_ids.push_back(myData->sales_tax_bank_id.isNull(), myData->sales_tax_bank_id.getValue())) return false; + if (!m_empty_date.push_back(myData->empty_date.isNull(), myData->empty_date.getValue())) return false; + if (!m_last_access_date.push_back(myData->last_access_date.isNull(), myData->last_access_date.getValue())) return false; + if (!m_inactive_date.push_back(myData->inactive_date.isNull(), myData->inactive_date.getValue())) return false; + if (!m_status.push_back(myData->status.isNull(), myData->status.getValue())) return false; + if (!m_search_enabled.push_back(myData->search_enabled.isNull(), myData->search_enabled.getValue())) return false; + if (!m_entrance_charge.push_back(myData->entrance_charge.isNull(), myData->entrance_charge.getValue())) return false; + break; + + case mode_INSERT: + if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false; + if (!m_location_names.push_back(myData->location_name.getValueASCII())) return false; + if (!m_owner_ids.push_back(myData->owner_id.isNull(), myData->owner_id.getValueASCII())) return false; + if (!m_sales_taxes.push_back(myData->sales_tax.isNull(), myData->sales_tax.getValue())) return false; + if (!m_sales_tax_bank_ids.push_back(myData->sales_tax_bank_id.isNull(), myData->sales_tax_bank_id.getValue())) return false; + if (!m_empty_date.push_back(myData->empty_date.isNull(), myData->empty_date.getValue())) return false; + if (!m_last_access_date.push_back(myData->last_access_date.isNull(), myData->last_access_date.getValue())) return false; + if (!m_inactive_date.push_back(myData->inactive_date.isNull(), myData->inactive_date.getValue())) return false; + if (!m_status.push_back(myData->status.isNull(), myData->status.getValue())) return false; + if (!m_search_enabled.push_back(myData->search_enabled.isNull(), myData->search_enabled.getValue())) return false; + if (!m_entrance_charge.push_back(myData->entrance_charge.isNull(), myData->entrance_charge.getValue())) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +int AuctionLocationsQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +void AuctionLocationsQuery::clearData() +{ + switch(mode) + { + case mode_UPDATE: + m_location_ids.clear(); + m_location_names.clear(); + m_owner_ids.clear(); + m_sales_taxes.clear(); + m_sales_tax_bank_ids.clear(); + m_empty_date.clear(); + m_last_access_date.clear(); + m_inactive_date.clear(); + m_status.clear(); + m_search_enabled.clear(); + m_entrance_charge.clear(); + break; + + case mode_INSERT: + m_location_ids.clear(); + m_location_names.clear(); + m_owner_ids.clear(); + m_sales_taxes.clear(); + m_sales_tax_bank_ids.clear(); + m_empty_date.clear(); + m_last_access_date.clear(); + m_inactive_date.clear(); + m_status.clear(); + m_search_enabled.clear(); + m_entrance_charge.clear(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_location_ids.clear(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=0; +} + +void AuctionLocationsQuery::freeData() +{ + switch(mode) + { + case mode_UPDATE: + m_location_ids.free(); + m_location_names.free(); + m_owner_ids.free(); + m_sales_taxes.free(); + m_sales_tax_bank_ids.free(); + m_empty_date.free(); + m_last_access_date.free(); + m_inactive_date.free(); + m_status.free(); + m_search_enabled.free(); + m_entrance_charge.free(); + break; + + case mode_INSERT: + m_location_ids.free(); + m_location_names.free(); + m_owner_ids.free(); + m_sales_taxes.free(); + m_sales_tax_bank_ids.free(); + m_empty_date.free(); + m_last_access_date.free(); + m_inactive_date.free(); + m_status.free(); + m_search_enabled.free(); + m_entrance_charge.free(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_location_ids.free(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + +} + +bool AuctionLocationsQuery::bindParameters() +{ + switch(mode) + { + case mode_UPDATE: + if (!bindParameter(m_location_ids)) return false; + if (!bindParameter(m_location_names)) return false; + if (!bindParameter(m_owner_ids)) return false; + if (!bindParameter(m_sales_taxes)) return false; + if (!bindParameter(m_sales_tax_bank_ids)) return false; + if (!bindParameter(m_empty_date)) return false; + if (!bindParameter(m_last_access_date)) return false; + if (!bindParameter(m_inactive_date)) return false; + if (!bindParameter(m_status)) return false; + if (!bindParameter(m_search_enabled)) return false; + if (!bindParameter(m_entrance_charge)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + case mode_INSERT: + if (!bindParameter(m_location_ids)) return false; + if (!bindParameter(m_location_names)) return false; + if (!bindParameter(m_owner_ids)) return false; + if (!bindParameter(m_sales_taxes)) return false; + if (!bindParameter(m_sales_tax_bank_ids)) return false; + if (!bindParameter(m_empty_date)) return false; + if (!bindParameter(m_last_access_date)) return false; + if (!bindParameter(m_inactive_date)) return false; + if (!bindParameter(m_status)) return false; + if (!bindParameter(m_search_enabled)) return false; + if (!bindParameter(m_entrance_charge)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!bindParameter(m_location_ids)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } +return true; + +} + +bool AuctionLocationsQuery::bindColumns() +{ + return true; +} + +void AuctionLocationsQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + "cm_persister.update_auction_locations (:location_id, :location_name, :owner_id, :sales_tax, :sales_tax_bank_id, :empty_date, :last_access_date, :inactive_date, :status, :search_enabled, :entrance_charge, :chunk_size); end;"; + break; + + case mode_INSERT: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + "cm_persister.insert_auction_locations (:location_id, :location_name, :owner_id, :sales_tax, :sales_tax_bank_id, :empty_date, :last_access_date, :inactive_date, :status, :search_enabled, :entrance_charge, :chunk_size); end;"; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + "cm_persister.delete_auction_locations (:location_id, :chunk_size ); end;"; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + +} + +AuctionLocationsQuerySelect::AuctionLocationsQuerySelect(const std::string &schema) : + m_data(ms_fetchBatchSize), + m_schema(schema) +{ +} + +bool AuctionLocationsQuerySelect::bindParameters () +{ + return true; +} + +bool AuctionLocationsQuerySelect::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ms_fetchBatchSize); + + if (!bindCol(m_data[0].location_id)) return false; + if (!bindCol(m_data[0].location_name)) return false; + if (!bindCol(m_data[0].owner_id)) return false; + if (!bindCol(m_data[0].sales_tax)) return false; + if (!bindCol(m_data[0].sales_tax_bank_id)) return false; + if (!bindCol(m_data[0].empty_date)) return false; + if (!bindCol(m_data[0].last_access_date)) return false; + if (!bindCol(m_data[0].inactive_date)) return false; + if (!bindCol(m_data[0].status)) return false; + if (!bindCol(m_data[0].search_enabled)) return false; + if (!bindCol(m_data[0].entrance_charge)) return false; + return true; +} + +const std::vector & AuctionLocationsQuerySelect::getData() const +{ + return m_data; +} + +void AuctionLocationsQuerySelect::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"cm_loader.get_location_list(); end;"; +} + +DB::Query::QueryMode AuctionLocationsQuerySelect::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== + +MarketAuctionsQuery::MarketAuctionsQuery() : + DatabaseProcessQuery(new MarketAuctionsRow), + m_numItems(0) +{ +} + +bool MarketAuctionsQuery::setupData(DB::Session *session) +{ + + switch(mode) + { + case mode_UPDATE: + if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_actives.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + break; + + case mode_INSERT: + if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_creator_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_min_bids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_buy_now_prices.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_auction_timers.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_oobs.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false; + if (!m_user_descriptions.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false; + if (!m_categories.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_item_names.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false; + if (!m_item_timers.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_actives.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_item_sizes.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_object_template_ids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + return true; +} + +bool MarketAuctionsQuery::addData(const DB::Row *_data) +{ + switch(mode) + { + case mode_UPDATE: + { + const MarketAuctionsRowUpdate *myData=dynamic_cast(_data); + FATAL(myData == NULL, ("Adding NULL data into MarketAuctions for mode_UPDATE")); + + if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false; + if (!m_owner_ids.push_back(myData->owner_id.getValueASCII())) return false; + if (!m_actives.push_back(myData->active.isNull(), myData->active.getValue())) return false; + break; + } + + case mode_INSERT: + { + const MarketAuctionsRow *myData=dynamic_cast(_data); + FATAL(myData == NULL, ("Adding NULL data into MarketAuctions for mode_INSERT")); + + if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false; + if (!m_owner_ids.push_back(myData->owner_id.getValueASCII())) return false; + if (!m_creator_ids.push_back(myData->creator_id.isNull(), myData->creator_id.getValueASCII())) return false; + if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false; + if (!m_min_bids.push_back(myData->min_bid.isNull(), myData->min_bid.getValue())) return false; + if (!m_buy_now_prices.push_back(myData->buy_now_price.isNull(), myData->buy_now_price.getValue())) return false; + if (!m_auction_timers.push_back(myData->auction_timer.isNull(), myData->auction_timer.getValue())) return false; + if (!m_oobs.push_back(myData->oob.isNull(), myData->oob.getValueASCII())) return false; + if (!m_user_descriptions.push_back(myData->user_description.isNull(), myData->user_description.getValue())) return false; + if (!m_categories.push_back(myData->category.isNull(), myData->category.getValue())) return false; + if (!m_item_names.push_back(myData->item_name.isNull(), myData->item_name.getValue())) return false; + if (!m_item_timers.push_back(myData->item_timer.isNull(), myData->item_timer.getValue())) return false; + if (!m_actives.push_back(myData->active.isNull(), myData->active.getValue())) return false; + if (!m_item_sizes.push_back(myData->item_size.isNull(), myData->item_size.getValue())) return false; + if (!m_object_template_ids.push_back(myData->object_template_id.isNull(), myData->object_template_id.getValue())) return false; + break; + } + + case mode_SELECT: + break; + + case mode_DELETE: + { + const MarketAuctionsRowDelete *myData=dynamic_cast(_data); + FATAL(myData == NULL, ("Adding NULL data into MarketAuctions for mode_DELETE")); + + if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false; + break; + } + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +int MarketAuctionsQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +void MarketAuctionsQuery::clearData() +{ + switch(mode) + { + case mode_UPDATE: + m_item_ids.clear(); + m_owner_ids.clear(); + m_actives.clear(); + break; + + case mode_INSERT: + m_item_ids.clear(); + m_owner_ids.clear(); + m_creator_ids.clear(); + m_location_ids.clear(); + m_min_bids.clear(); + m_buy_now_prices.clear(); + m_auction_timers.clear(); + m_oobs.clear(); + m_user_descriptions.clear(); + m_categories.clear(); + m_item_names.clear(); + m_item_timers.clear(); + m_actives.clear(); + m_item_sizes.clear(); + m_object_template_ids.clear(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_item_ids.clear(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=0; +} + +void MarketAuctionsQuery::freeData() +{ + switch(mode) + { + case mode_UPDATE: + m_item_ids.free(); + m_owner_ids.free(); + m_actives.free(); + break; + + case mode_INSERT: + m_item_ids.free(); + m_owner_ids.free(); + m_creator_ids.free(); + m_location_ids.free(); + m_min_bids.free(); + m_buy_now_prices.free(); + m_auction_timers.free(); + m_oobs.free(); + m_user_descriptions.free(); + m_categories.free(); + m_item_names.free(); + m_item_timers.free(); + m_actives.free(); + m_item_sizes.free(); + m_object_template_ids.free(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_item_ids.free(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + +} + +bool MarketAuctionsQuery::bindParameters() +{ + switch(mode) + { + case mode_UPDATE: + if (!bindParameter(m_item_ids)) return false; + if (!bindParameter(m_owner_ids)) return false; + if (!bindParameter(m_actives)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + case mode_INSERT: + if (!bindParameter(m_item_ids)) return false; + if (!bindParameter(m_owner_ids)) return false; + if (!bindParameter(m_creator_ids)) return false; + if (!bindParameter(m_location_ids)) return false; + if (!bindParameter(m_min_bids)) return false; + if (!bindParameter(m_buy_now_prices)) return false; + if (!bindParameter(m_auction_timers)) return false; + if (!bindParameter(m_oobs)) return false; + if (!bindParameter(m_user_descriptions)) return false; + if (!bindParameter(m_categories)) return false; + if (!bindParameter(m_item_names)) return false; + if (!bindParameter(m_item_timers)) return false; + if (!bindParameter(m_actives)) return false; + if (!bindParameter(m_item_sizes)) return false; + if (!bindParameter(m_object_template_ids)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!bindParameter(m_item_ids)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } +return true; + +} + +bool MarketAuctionsQuery::bindColumns() +{ + return true; +} + +void MarketAuctionsQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + + "cm_persister.update_market_auctions (:item_id, :owner_id, :active, :chunk_size); end;"; + break; + + case mode_INSERT: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + + "cm_persister.insert_market_auctions (:item_id, :owner_id, :creator_id, :location_id, :min_bid, :buy_now_price, :auction_timer, :oob, :user_description, :category, :item_name, :item_timer, :active, :item_size, :object_template_id, :chunk_size); end;"; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + + "cm_persister.delete_market_auctions (:item_id, :chunk_size ); end;"; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + +} + +MarketAuctionsQuerySelect::MarketAuctionsQuerySelect(const std::string &schema) : + m_data(ms_fetchBatchSize), + m_schema(schema) +{ +} + +bool MarketAuctionsQuerySelect::bindParameters () +{ + return true; +} + +bool MarketAuctionsQuerySelect::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ms_fetchBatchSize); + + if (!bindCol(m_data[0].item_id)) return false; + if (!bindCol(m_data[0].owner_id)) return false; + if (!bindCol(m_data[0].creator_id)) return false; + if (!bindCol(m_data[0].location_id)) return false; + if (!bindCol(m_data[0].min_bid)) return false; + if (!bindCol(m_data[0].buy_now_price)) return false; + if (!bindCol(m_data[0].auction_timer)) return false; + if (!bindCol(m_data[0].oob)) return false; + if (!bindCol(m_data[0].user_description)) return false; + if (!bindCol(m_data[0].category)) return false; + if (!bindCol(m_data[0].item_name)) return false; + if (!bindCol(m_data[0].item_timer)) return false; + if (!bindCol(m_data[0].active)) return false; + if (!bindCol(m_data[0].item_size)) return false; + return true; +} + +const std::vector & MarketAuctionsQuerySelect::getData() const +{ + return m_data; +} + +void MarketAuctionsQuerySelect::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"cm_loader.get_auction_list(); end;"; +} + +DB::Query::QueryMode MarketAuctionsQuerySelect::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== + +MarketAuctionBidsQuery::MarketAuctionBidsQuery() : + DatabaseProcessQuery(new MarketAuctionBidsRow), + m_numItems(0) +{ +} + +bool MarketAuctionBidsQuery::setupData(DB::Session *session) +{ + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_bidder_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_bids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_max_proxy_bids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + return true; +} + +bool MarketAuctionBidsQuery::addData(const DB::Row *_data) +{ + const MarketAuctionBidsRow *myData=dynamic_cast(_data); + + FATAL(myData == NULL, ("Adding NULL data into MarketAuctionBids")); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false; + if (!m_bidder_ids.push_back(myData->bidder_id.getValueASCII())) return false; + if (!m_bids.push_back(myData->bid.getValue())) return false; + if (!m_max_proxy_bids.push_back(myData->max_proxy_bid.isNull(), myData->max_proxy_bid.getValue())) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +int MarketAuctionBidsQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +void MarketAuctionBidsQuery::clearData() +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + m_item_ids.clear(); + m_bidder_ids.clear(); + m_bids.clear(); + m_max_proxy_bids.clear(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_item_ids.clear(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=0; +} + +void MarketAuctionBidsQuery::freeData() +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + m_item_ids.free(); + m_bidder_ids.free(); + m_bids.free(); + m_max_proxy_bids.free(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_item_ids.free(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + +} + +bool MarketAuctionBidsQuery::bindParameters() +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!bindParameter(m_item_ids)) return false; + if (!bindParameter(m_bidder_ids)) return false; + if (!bindParameter(m_bids)) return false; + if (!bindParameter(m_max_proxy_bids)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!bindParameter(m_item_ids)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } +return true; + +} + +bool MarketAuctionBidsQuery::bindColumns() +{ + return true; +} + +void MarketAuctionBidsQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + + "cm_persister.insert_market_auction_bids (:item_id, :bidder_id, :bid, :max_proxy_bid, :chunk_size); end;"; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + + "cm_persister.delete_market_auction_bids (:item_id, :chunk_size ); end;"; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + +} + +MarketAuctionBidsQuerySelect::MarketAuctionBidsQuerySelect(const std::string &schema) : + m_data(ms_fetchBatchSize), + m_schema(schema) +{ +} + +bool MarketAuctionBidsQuerySelect::bindParameters () +{ + return true; +} + +bool MarketAuctionBidsQuerySelect::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ms_fetchBatchSize); + + if (!bindCol(m_data[0].item_id)) return false; + if (!bindCol(m_data[0].bidder_id)) return false; + if (!bindCol(m_data[0].bid)) return false; + if (!bindCol(m_data[0].max_proxy_bid)) return false; + return true; +} + +const std::vector & MarketAuctionBidsQuerySelect::getData() const +{ + return m_data; +} + +void MarketAuctionBidsQuerySelect::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"cm_loader.get_bid_list(); end;"; +} + +DB::Query::QueryMode MarketAuctionBidsQuerySelect::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} +// ====================================================================== + +MarketAuctionsAttributesQuery::MarketAuctionsAttributesQuery() : + DatabaseProcessQuery(new MarketAuctionsRow), + m_numItems(0) +{ +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsAttributesQuery::setupData(DB::Session *session) +{ + switch(mode) + { + case mode_INSERT: + if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_attribute_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_attribute_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + return true; +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsAttributesQuery::addData(NetworkId const & itemId, std::string const & attributeName, Unicode::String const & attributeValue) +{ + if (!m_item_ids.push_back(itemId)) return false; + if (!m_attribute_names.push_back(attributeName)) return false; + if (!m_attribute_values.push_back(attributeValue)) return false; + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +int MarketAuctionsAttributesQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsAttributesQuery::clearData() +{ + m_item_ids.clear(); + m_attribute_names.clear(); + m_attribute_values.clear(); + + m_numItems=0; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsAttributesQuery::freeData() +{ + m_item_ids.free(); + m_attribute_names.free(); + m_attribute_values.free(); +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsAttributesQuery::bindParameters() +{ + if (!bindParameter(m_item_ids)) return false; + if (!bindParameter(m_attribute_names)) return false; + if (!bindParameter(m_attribute_values)) return false; + if (!bindParameter(m_numItems)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool MarketAuctionsAttributesQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void MarketAuctionsAttributesQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + + "cm_persister.insert_auction_attributes (:item_ids, :attribute_names, :attribute_values, :num_items); end;"; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesQuery.h new file mode 100644 index 00000000..55469272 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesQuery.h @@ -0,0 +1,225 @@ +// CommoditiesQuery.h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_CommoditiesQuery_H +#define INCLUDED_CommoditiesQuery_H + +// ====================================================================== + +#include "serverDatabase/DatabaseProcessQuery.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "sharedFoundation/NetworkId.h" +#include "SwgDatabaseServer/CommoditiesSchema.h" + +#include + +// ====================================================================== + +namespace DBQuery +{ + +class AuctionLocationsQuery : public DatabaseProcessQuery +{ + AuctionLocationsQuery(const AuctionLocationsQuery&); + AuctionLocationsQuery& operator= (const AuctionLocationsQuery&); +public: + AuctionLocationsQuery(); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const DB::Row *_data); + void clearData(); + void freeData(); + + int getNumItems() const; + +private: + DB::BindableVarrayString m_location_ids; + DB::BindableVarrayString m_location_names; + DB::BindableVarrayString m_owner_ids; + DB::BindableVarrayNumber m_sales_taxes; + DB::BindableVarrayString m_sales_tax_bank_ids; + DB::BindableVarrayNumber m_empty_date; + DB::BindableVarrayNumber m_last_access_date; + DB::BindableVarrayNumber m_inactive_date; + DB::BindableVarrayNumber m_status; + DB::BindableVarrayString m_search_enabled; + DB::BindableVarrayNumber m_entrance_charge; + DB::BindableLong m_numItems; +}; + +class AuctionLocationsQuerySelect : public DB::Query +{ +public: + AuctionLocationsQuerySelect(const std::string &schema); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL (std::string &sql); + + const std::vector & getData() const; + +protected: + virtual QueryMode getExecutionMode() const; + +private: + + std::vector m_data; + const std::string m_schema; + + AuctionLocationsQuerySelect (const AuctionLocationsQuerySelect&); + AuctionLocationsQuerySelect& operator= (const AuctionLocationsQuerySelect&); +}; + + +// ====================================================================== + +class MarketAuctionsQuery : public DatabaseProcessQuery +{ + MarketAuctionsQuery(const MarketAuctionsQuery&); + MarketAuctionsQuery& operator= (const MarketAuctionsQuery&); +public: + MarketAuctionsQuery(); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const DB::Row *_data); + void clearData(); + void freeData(); + + int getNumItems() const; + +private: + DB::BindableVarrayString m_item_ids; + DB::BindableVarrayString m_owner_ids; + DB::BindableVarrayString m_creator_ids; + DB::BindableVarrayString m_location_ids; + DB::BindableVarrayNumber m_min_bids; + DB::BindableVarrayNumber m_buy_now_prices; + DB::BindableVarrayNumber m_auction_timers; + DB::BindableVarrayString m_oobs; + DB::BindableVarrayString m_user_descriptions; + DB::BindableVarrayNumber m_categories; + DB::BindableVarrayString m_item_names; + DB::BindableVarrayNumber m_item_timers; + DB::BindableVarrayNumber m_actives; + DB::BindableVarrayNumber m_item_sizes; + DB::BindableVarrayNumber m_object_template_ids; + DB::BindableLong m_numItems; +}; + +class MarketAuctionsQuerySelect : public DB::Query +{ +public: + MarketAuctionsQuerySelect(const std::string &schema); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL (std::string &sql); + + const std::vector & getData() const; + +protected: + virtual QueryMode getExecutionMode() const; + +private: + + std::vector m_data; + const std::string m_schema; + + MarketAuctionsQuerySelect (const MarketAuctionsQuerySelect&); + MarketAuctionsQuerySelect& operator= (const MarketAuctionsQuerySelect&); +}; + +// ====================================================================== + +class MarketAuctionBidsQuery : public DatabaseProcessQuery +{ + MarketAuctionBidsQuery(const MarketAuctionBidsQuery&); + MarketAuctionBidsQuery& operator= (const MarketAuctionBidsQuery&); +public: + MarketAuctionBidsQuery(); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const DB::Row *_data); + void clearData(); + void freeData(); + + int getNumItems() const; + +private: + DB::BindableVarrayString m_item_ids; + DB::BindableVarrayString m_bidder_ids; + DB::BindableVarrayNumber m_bids; + DB::BindableVarrayNumber m_max_proxy_bids; + DB::BindableLong m_numItems; +}; + +class MarketAuctionBidsQuerySelect : public DB::Query +{ +public: + MarketAuctionBidsQuerySelect(const std::string &schema); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL (std::string &sql); + + const std::vector & getData() const; + +protected: + virtual QueryMode getExecutionMode() const; + +private: + + std::vector m_data; + const std::string m_schema; + + MarketAuctionBidsQuerySelect (const MarketAuctionBidsQuerySelect&); + MarketAuctionBidsQuerySelect& operator= (const MarketAuctionBidsQuerySelect&); +}; + +// ====================================================================== + +class MarketAuctionsAttributesQuery : public DatabaseProcessQuery +{ + MarketAuctionsAttributesQuery(const MarketAuctionsAttributesQuery&); + MarketAuctionsAttributesQuery& operator= (const MarketAuctionsAttributesQuery&); +public: + MarketAuctionsAttributesQuery(); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(NetworkId const & itemId, std::string const & attributeName, Unicode::String const & attributeValue); + void clearData(); + void freeData(); + + int getNumItems() const; + +private: + DB::BindableVarrayString m_item_ids; + DB::BindableVarrayString m_attribute_names; + DB::BindableVarrayString m_attribute_values; + DB::BindableLong m_numItems; +}; + +// ====================================================================== + +} // namespace + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesSchema.h b/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesSchema.h new file mode 100644 index 00000000..f9ed09f9 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/CommoditiesSchema.h @@ -0,0 +1,230 @@ +// copyright (c) 2001 Sony Online Entertainment +// +// Edit the file Schema_h.template. Do not edit Schema.h. +// +// ====================================================================== + +#ifndef INCLUDED_CommoditiesSchema_H +#define INCLUDED_CommoditiesSchema_H + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbRow.h" + +namespace DBSchema +{ + +struct AuctionLocationsRow : public DB::Row +{ + AuctionLocationsRow() { ++m_sAuctionRowsCreated; } + ~AuctionLocationsRow() { ++m_sAuctionRowsDeleted; } + + + DB::BindableNetworkId location_id; + DB::BindableString<256> location_name; + DB::BindableNetworkId owner_id; + DB::BindableLong sales_tax; + DB::BindableNetworkId sales_tax_bank_id; + DB::BindableLong empty_date; + DB::BindableLong last_access_date; + DB::BindableLong inactive_date; + DB::BindableLong status; + DB::BindableBool search_enabled; + DB::BindableLong entrance_charge; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + + void setPrimaryKey(const NetworkId &keyValue) + { + location_id.setValue(keyValue); + } + + NetworkId getPrimaryKey() const + { + return location_id.getValue(); + } + + static int getRowsCreated() { return m_sAuctionRowsCreated; } + static int getRowsActive() + { + int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted; + //if ( i_retval < 0 ) + // return 0; + return i_retval; + } + +private: + static volatile int m_sAuctionRowsCreated; + static volatile int m_sAuctionRowsDeleted; + +}; + +struct MarketAuctionsRow : public DB::Row +{ + MarketAuctionsRow() { ++m_sAuctionRowsCreated; } + ~MarketAuctionsRow() { ++m_sAuctionRowsDeleted; } + + DB::BindableNetworkId item_id; + DB::BindableNetworkId owner_id; + DB::BindableNetworkId creator_id; + DB::BindableNetworkId location_id; + DB::BindableLong min_bid; + DB::BindableLong buy_now_price; + DB::BindableLong auction_timer; + DB::BindableString<4000> oob; + DB::BindableUnicode<1024>user_description; + DB::BindableLong category; + DB::BindableUnicode<1024>item_name; + DB::BindableLong item_timer; + DB::BindableLong active; + DB::BindableLong item_size; + DB::BindableLong object_template_id; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + + void setPrimaryKey(const NetworkId &keyValue) + { + item_id.setValue(keyValue); + } + + NetworkId getPrimaryKey() const + { + return item_id.getValue(); + } + + static int getRowsCreated() { return m_sAuctionRowsCreated; } + static int getRowsActive() + { + int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted; + //if ( i_retval < 0 ) + // return 0; + return i_retval; + } + +private: + static volatile int m_sAuctionRowsCreated; + static volatile int m_sAuctionRowsDeleted; +}; + +struct MarketAuctionsRowDelete : public DB::Row +{ + MarketAuctionsRowDelete() { ++m_sAuctionRowsCreated; } + ~MarketAuctionsRowDelete() { ++m_sAuctionRowsDeleted; } + + DB::BindableNetworkId item_id; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + + void setPrimaryKey(const NetworkId &keyValue) + { + item_id.setValue(keyValue); + } + + NetworkId getPrimaryKey() const + { + return item_id.getValue(); + } + + static int getRowsCreated() { return m_sAuctionRowsCreated; } + static int getRowsActive() + { + int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted; + if ( i_retval < 0 ) + return 0; + return i_retval; + } + +private: + static volatile int m_sAuctionRowsCreated; + static volatile int m_sAuctionRowsDeleted; +}; + +struct MarketAuctionsRowUpdate : public DB::Row +{ + MarketAuctionsRowUpdate() { ++m_sAuctionRowsCreated; } + ~MarketAuctionsRowUpdate() { ++m_sAuctionRowsDeleted; } + + DB::BindableNetworkId item_id; + DB::BindableNetworkId owner_id; + DB::BindableLong active; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + + void setPrimaryKey(const NetworkId &keyValue) + { + item_id.setValue(keyValue); + } + + NetworkId getPrimaryKey() const + { + return item_id.getValue(); + } + + static int getRowsCreated() { return m_sAuctionRowsCreated; } + static int getRowsActive() + { + int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted; + if ( i_retval < 0 ) + return 0; + return i_retval; + } + +private: + static volatile int m_sAuctionRowsCreated; + static volatile int m_sAuctionRowsDeleted; +}; + +struct MarketAuctionBidsRow : public DB::Row +{ + MarketAuctionBidsRow() { ++m_sAuctionRowsCreated; } + ~MarketAuctionBidsRow() { ++m_sAuctionRowsDeleted; } + + DB::BindableNetworkId item_id; + DB::BindableNetworkId bidder_id; + DB::BindableLong bid; + DB::BindableLong max_proxy_bid; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + + void setPrimaryKey(const NetworkId &keyValue) + { + item_id.setValue(keyValue); + } + + NetworkId getPrimaryKey() const + { + return item_id.getValue(); + } + + static int getRowsCreated() { return m_sAuctionRowsCreated; } + static int getRowsActive() + { + int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted; + if ( i_retval < 0 ) + return 0; + return i_retval; + } + +private: + static volatile int m_sAuctionRowsCreated; + static volatile int m_sAuctionRowsDeleted; +}; + +}; + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/DeleteDemandLoadedContainerQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/DeleteDemandLoadedContainerQuery.cpp new file mode 100644 index 00000000..d9985a34 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/DeleteDemandLoadedContainerQuery.cpp @@ -0,0 +1,106 @@ +// ====================================================================== +// +// DeleteDemandLoadedContainerQuery.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/DeleteDemandLoadedContainerQuery.h" + +#include "serverDatabase/DatabaseProcess.h" +#include "sharedFoundation/NetworkId.h" + +// ====================================================================== + +using namespace DBQuery; + +// ====================================================================== + +DeleteDemandLoadedContainerQuery::DeleteDemandLoadedContainerQuery() : + object_ids(), + reasons(), + num_items(0) +{ +} + +// ---------------------------------------------------------------------- + +DeleteDemandLoadedContainerQuery::~DeleteDemandLoadedContainerQuery() +{ +} + +// ---------------------------------------------------------------------- + +bool DeleteDemandLoadedContainerQuery::bindParameters() +{ + if (!bindParameter(object_ids)) return false; + if (!bindParameter(reasons)) return false; + if (!bindParameter(num_items)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool DeleteDemandLoadedContainerQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void DeleteDemandLoadedContainerQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.delete_demand_container (:object_ids, :reasons, :num_items); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode DeleteDemandLoadedContainerQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +bool DeleteDemandLoadedContainerQuery::addData(const NetworkId &networkId, int reason) +{ + if (!object_ids.push_back(networkId.getValueString())) return false; + if (!reasons.push_back(reason)) return false; + num_items=num_items.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +bool DeleteDemandLoadedContainerQuery::setupData(DB::Session &session) +{ + if (!object_ids.create(&session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!reasons.create(&session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + return true; +} + +// ---------------------------------------------------------------------- + +void DeleteDemandLoadedContainerQuery::clearData() +{ + object_ids.clear(); + reasons.clear(); +} + +// ---------------------------------------------------------------------- + +void DeleteDemandLoadedContainerQuery::freeData() +{ + object_ids.free(); + reasons.free(); +} + +// ---------------------------------------------------------------------- + +int DeleteDemandLoadedContainerQuery::getCount() const +{ + return num_items.getValue(); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/DeleteDemandLoadedContainerQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/DeleteDemandLoadedContainerQuery.h new file mode 100644 index 00000000..614e36ca --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/DeleteDemandLoadedContainerQuery.h @@ -0,0 +1,51 @@ +// ====================================================================== +// +// DeleteDemandLoadedContainerQuery.h +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_DeleteDemandLoadedContainerQuery_H +#define INCLUDED_DeleteDemandLoadedContainerQuery_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbBindableVarray.h" +#include "sharedDatabaseInterface/DbQuery.h" + +// ====================================================================== + +namespace DBQuery +{ + + class DeleteDemandLoadedContainerQuery : public DB::Query + { + public: + DeleteDemandLoadedContainerQuery(); + ~DeleteDemandLoadedContainerQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode getExecutionMode() const; + + bool addData(const NetworkId &networkId, int reason); + bool setupData(DB::Session &session); + void clearData(); + void freeData(); + int getCount() const; + + private: + DB::BindableVarrayString object_ids; + DB::BindableVarrayNumber reasons; + DB::BindableLong num_items; + + private: + DeleteDemandLoadedContainerQuery(const DeleteDemandLoadedContainerQuery&); + DeleteDemandLoadedContainerQuery& operator=(const DeleteDemandLoadedContainerQuery&); + }; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ExperienceQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/ExperienceQuery.cpp new file mode 100644 index 00000000..be0a1c3e --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ExperienceQuery.cpp @@ -0,0 +1,134 @@ +// ====================================================================== +// +// ExperienceQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/ExperienceQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +using namespace DBQuery; + +// ====================================================================== + +ExperienceQuery::ExperienceQuery() : + ModeQuery(new DBSchema::ExperiencePointRow) //lint !e1524 // We don't delete the new row (base class does) +{ +} + +// ---------------------------------------------------------------------- + +bool ExperienceQuery::bindParameters() +{ + DBSchema::ExperiencePointRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!bindParameter(myData->points)) return false; + + if (!bindParameter(myData->experience_type)) return false; + if (!bindParameter(myData->object_id)) return false; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + return true; +} + +bool ExperienceQuery::bindColumns() +{ + DBSchema::ExperiencePointRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } //lint !e788 //not all modes have an explicit case in the switch + + return true; +} + +// ---------------------------------------------------------------------- + +void ExperienceQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_experience (:points, :experience_type, :object_id); end;"; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } +} + +// ====================================================================== + +DBQuery::GetAllExperience::GetAllExperience(const std::string &schema) : + Query(), + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +bool GetAllExperience::bindParameters() +{ + return true; +} + +bool GetAllExperience::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].experience_type)) return false; + if (!bindCol(m_data[0].points)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void GetAllExperience::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_experience(); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode GetAllExperience::getExecutionMode() const +{ + if (getProtocol()==DB::PROTOCOL_OCI) + return (MODE_PLSQL_REFCURSOR); + else + { + FATAL(true,("ODBC mode is not supported for Experience\n")); + return MODE_SQL; // return to avoid compiler warning + } +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ExperienceQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/ExperienceQuery.h new file mode 100644 index 00000000..5b014ed2 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ExperienceQuery.h @@ -0,0 +1,66 @@ +// ====================================================================== +// +// ExperienceQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ExperienceQuery_H +#define INCLUDED_ExperienceQuery_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include + +// ====================================================================== + +namespace DBQuery +{ + + class ExperienceQuery : public DB::ModeQuery + { + ExperienceQuery(const ExperienceQuery&); // disable + ExperienceQuery& operator=(const ExperienceQuery&); // disable + public: + ExperienceQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + }; + +// ---------------------------------------------------------------------- + + class GetAllExperience : public DB::Query + { + public: + GetAllExperience(const std::string &schema); + + const std::vector &getData() const; + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode getExecutionMode() const; + + private: + GetAllExperience(const GetAllExperience&); // disable + GetAllExperience& operator=(const GetAllExperience&); // disable + + private: + std::vector m_data; + const std::string m_schema; + }; +} + +// ====================================================================== + +inline const std::vector & DBQuery::GetAllExperience::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/LocationQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/LocationQuery.cpp new file mode 100644 index 00000000..9e411091 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/LocationQuery.cpp @@ -0,0 +1,128 @@ +// ====================================================================== +// +// LocationQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/LocationQuery.h" + +#include "serverUtility/LocationData.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" + +using namespace DBQuery; + +// ====================================================================== + +SaveLocationQuery::SaveLocationQuery() +{ +} + +// ---------------------------------------------------------------------- + +bool SaveLocationQuery::bindParameters() +{ + if (!bindParameter(object_id)) return false; + if (!bindParameter(list_id)) return false; + if (!bindParameter(index)) return false; + if (!bindParameter(action)) return false; + if (!bindParameter(name)) return false; + if (!bindParameter(scene)) return false; + if (!bindParameter(x)) return false; + if (!bindParameter(y)) return false; + if (!bindParameter(z)) return false; + if (!bindParameter(radius)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool SaveLocationQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void SaveLocationQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_location(:object_id,:list_id,:sequence_number,:operation,:name,:scene,:x,:y,:z,:radius); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode SaveLocationQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +void SaveLocationQuery::setData(const NetworkId &newObjectId, size_t newListId, int newAction, int newIndex, const LocationData &newLocation) +{ + object_id = newObjectId; + list_id = static_cast(newListId); + index = newIndex; + action = newAction; + name = newLocation.name; + scene = newLocation.scene; + const Vector &vect = newLocation.location.getCenter(); + x = vect.x; + y = vect.y; + z = vect.z; + radius = newLocation.location.getRadius(); +} + +// ====================================================================== + +LoadLocationQuery::LoadLocationQuery(const std::string &schema) : + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +bool LoadLocationQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool LoadLocationQuery::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].list_id)) return false; + if (!bindCol(m_data[0].index)) return false; + if (!bindCol(m_data[0].name)) return false; + if (!bindCol(m_data[0].scene)) return false; + if (!bindCol(m_data[0].x)) return false; + if (!bindCol(m_data[0].y)) return false; + if (!bindCol(m_data[0].z)) return false; + if (!bindCol(m_data[0].radius)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void LoadLocationQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_location (); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode LoadLocationQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== + diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/LocationQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/LocationQuery.h new file mode 100644 index 00000000..21eb81f1 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/LocationQuery.h @@ -0,0 +1,97 @@ +// ====================================================================== +// +// LocationQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_LocationQuery_H +#define INCLUDED_LocationQuery_H + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include + +class LocationData; + +// ====================================================================== + +namespace DBQuery +{ + class SaveLocationQuery : public DB::Query + { + public: + SaveLocationQuery(); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode getExecutionMode() const; + + void setData(const NetworkId &objectId, size_t listId, int action, int index, const LocationData &location); + + public: + DB::BindableNetworkId object_id; + DB::BindableLong list_id; + DB::BindableLong index; + DB::BindableLong action; + DB::BindableUnicode<255> name; + DB::BindableString<50> scene; + DB::BindableDouble x; + DB::BindableDouble y; + DB::BindableDouble z; + DB::BindableDouble radius; + + private: + SaveLocationQuery(const SaveLocationQuery&); //disable + SaveLocationQuery &operator=(const SaveLocationQuery&); //disable + }; + +// ====================================================================== + + class LoadLocationQuery : public DB::Query + { + public: + struct LocationRow + { + DB::BindableNetworkId object_id; + DB::BindableLong list_id; + DB::BindableLong index; + DB::BindableUnicode<255> name; + DB::BindableString<50> scene; + DB::BindableDouble x; + DB::BindableDouble y; + DB::BindableDouble z; + DB::BindableDouble radius; + }; + + public: + LoadLocationQuery(const std::string &schema); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode getExecutionMode() const; + + const std::vector & getData() const; + + private: + std::vector m_data; + const std::string m_schema; + + private: + LoadLocationQuery(const LoadLocationQuery&); //disable + LoadLocationQuery &operator=(const LoadLocationQuery&); //disable + }; + +} //namespace + +// ====================================================================== + +inline const std::vector & DBQuery::LoadLocationQuery::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ManufactureSchematicAttributeQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/ManufactureSchematicAttributeQuery.cpp new file mode 100644 index 00000000..61f0980d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ManufactureSchematicAttributeQuery.cpp @@ -0,0 +1,130 @@ +// ====================================================================== +// +// ManufactureSchematicAttributeQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/ManufactureSchematicAttributeQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +using namespace DBQuery; + +// ====================================================================== + +ManufactureSchematicAttributeQuery::ManufactureSchematicAttributeQuery() : + ModeQuery(new DBSchema::ManufactureSchematicAttributeRow) //lint !e1524 // We don't delete the new row (base class does) +{ +} + +// ---------------------------------------------------------------------- + +bool ManufactureSchematicAttributeQuery::bindParameters() +{ + DBSchema::ManufactureSchematicAttributeRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!bindParameter(myData->action)) return false; + if (!bindParameter(myData->object_id)) return false; + if (!bindParameter(myData->attribute_type)) return false; + if (!bindParameter(myData->value)) return false; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } //lint !e788 //not all modes have an explicit case in the switch + + return true; +} + +bool ManufactureSchematicAttributeQuery::bindColumns() +{ + DBSchema::ManufactureSchematicAttributeRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } //lint !e788 //not all modes have an explicit case in the switch + + return true; +} + +// ---------------------------------------------------------------------- + +void ManufactureSchematicAttributeQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_manf_schem_attribute (:action, :object_id, :attribute_type, :value); end;"; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } //lint !e788 //not all modes have an explicit case in the switch +} + +// ====================================================================== + +DBQuery::GetAllManufactureSchematicAttributes::GetAllManufactureSchematicAttributes(const std::string &schema) : + Query(), + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +bool GetAllManufactureSchematicAttributes::bindParameters() +{ + + return true; +} + +bool GetAllManufactureSchematicAttributes::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].attribute_type)) return false; + if (!bindCol(m_data[0].value)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void GetAllManufactureSchematicAttributes::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_manf_schematic_attributes (); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode GetAllManufactureSchematicAttributes::getExecutionMode() const +{ + return (MODE_PLSQL_REFCURSOR); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ManufactureSchematicAttributeQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/ManufactureSchematicAttributeQuery.h new file mode 100644 index 00000000..0af50478 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ManufactureSchematicAttributeQuery.h @@ -0,0 +1,89 @@ +// ====================================================================== +// +// ManufactureSchematicAttributeQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ManufactureSchematicAttributeQuery_H +#define INCLUDED_ManufactureSchematicAttributeQuery_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include + +// ====================================================================== + +namespace DBSchema +{ + struct ManufactureSchematicAttributeRow : public DB::Row + { + DB::BindableNetworkId object_id; + DB::BindableLong action; + DB::BindableString<500> attribute_type; + DB::BindableDouble value; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + }; + +} + +// ---------------------------------------------------------------------- + +namespace DBQuery +{ + + class ManufactureSchematicAttributeQuery : public DB::ModeQuery + { + ManufactureSchematicAttributeQuery(const ManufactureSchematicAttributeQuery&); // disable + ManufactureSchematicAttributeQuery& operator=(const ManufactureSchematicAttributeQuery&); // disable + public: + ManufactureSchematicAttributeQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + }; + +// ---------------------------------------------------------------------- + + /** + * A query that gets all the attributes for an object. + */ + + class GetAllManufactureSchematicAttributes : public DB::Query + { + public: + GetAllManufactureSchematicAttributes(const std::string &schema); + + const std::vector &getData() const; + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode GetAllManufactureSchematicAttributes::getExecutionMode() const; + + private: + GetAllManufactureSchematicAttributes(const GetAllManufactureSchematicAttributes&); // disable + GetAllManufactureSchematicAttributes& operator=(const GetAllManufactureSchematicAttributes&); // disable + + private: + std::vector m_data; + const std::string m_schema; + }; +} + +// ====================================================================== + +inline const std::vector & DBQuery::GetAllManufactureSchematicAttributes::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/MessageQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/MessageQuery.cpp new file mode 100644 index 00000000..e3e59ce9 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/MessageQuery.cpp @@ -0,0 +1,349 @@ +// ====================================================================== +// +// MessageQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/MessageQuery.h" + +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedLog/Log.h" + +//TODO: don't save non-guaranteed messages + +// ====================================================================== + +using namespace DBQuery; +using namespace DB; + +// ---------------------------------------------------------------------- + +SaveMessageQuery::SaveMessageQuery() : + m_numItems(0), + m_enableDatabaseLogging(ConfigServerDatabase::getEnableDatabaseErrorLogging()) +{ +} + +// ---------------------------------------------------------------------- + +bool SaveMessageQuery::setupData(DB::Session *session) +{ + + if (!m_message_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_object_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_methods.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_packed_datas.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false; + if (!m_call_times.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_guaranteeds.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_delivery_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool SaveMessageQuery::addData(const MessageToPayload &data) +{ + if (data.getMethod().size() > 50) + { + WARNING(true, ("Attempt to save message \"%s\" to the MESSAGES table, which is too long", data.getMethod().c_str())); + } + else + { + if (!m_message_ids.push_back(data.getMessageId().getValueString())) return false; + if (!m_object_ids.push_back(data.getNetworkId().getValueString())) return false; + if (!m_methods.push_back(data.getMethod())) return false; + std::string utf8data; + convertMessageToUTF8(data.getPackedDataVector(), utf8data); + WARNING(utf8data.size() > 1000,("Message had data that was over 1000 bytes when packed to UTF8. Method: %s, Target: %s, Data: %s",data.getMethod().c_str(), data.getNetworkId().getValueString().c_str(), utf8data.c_str())); + if (!m_packed_datas.push_back(utf8data)) return false; + if (!m_call_times.push_back(static_cast(data.getCallTime()))) return false; + if (!m_guaranteeds.push_back(data.getGuaranteed())) return false; + if (!m_delivery_types.push_back(static_cast(data.getDeliveryType()))) return false; + + m_numItems=m_numItems.getValue() + 1; + + if (ConfigServerDatabase::getEnableVerboseMessageLogging()) + { + LOG("PersistedMessages",("Saving message: Method: %s, Target: %s, Data: %s",data.getMethod().c_str(), data.getNetworkId().getValueString().c_str(), utf8data.c_str())); + } + } + return true; +} + +// ---------------------------------------------------------------------- + +int SaveMessageQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +void SaveMessageQuery::clearData() +{ + m_message_ids.clear(); + m_object_ids.clear(); + m_methods.clear(); + m_packed_datas.clear(); + m_call_times.clear(); + m_guaranteeds.clear(); + m_delivery_types.clear(); + + m_numItems=0; + +} + +// ---------------------------------------------------------------------- + +void SaveMessageQuery::freeData() +{ + m_message_ids.free(); + m_object_ids.free(); + m_methods.free(); + m_packed_datas.free(); + m_call_times.free(); + m_guaranteeds.free(); + m_delivery_types.free(); + +} + +// ---------------------------------------------------------------------- + +bool SaveMessageQuery::bindParameters() +{ + if (!bindParameter(m_message_ids)) return false; + if (!bindParameter(m_object_ids)) return false; + if (!bindParameter(m_methods)) return false; + if (!bindParameter(m_packed_datas)) return false; + if (!bindParameter(m_call_times)) return false; + if (!bindParameter(m_guaranteeds)) return false; + if (!bindParameter(m_delivery_types)) return false; + if (!bindParameter(m_numItems)) return false; + if (!bindParameter(m_enableDatabaseLogging)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool SaveMessageQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void SaveMessageQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_message_batch(:message_id, :object_id, :method, :data, :call_time, :guaranteed, :delivery_type, :chunk_size, :enable_db_logging); end;"; +} + +// ---------------------------------------------------------------------- + +void SaveMessageQuery::convertMessageToUTF8(const std::vector & messageData, std::string & utf8Data) const +{ + int count = messageData.size(); + utf8Data.resize(0); + utf8Data.reserve(count * 2); + uint8 c; + for (int i = 0; i < count; ++i) + { + c = messageData[i]; + if (c >= 0x01 && c <= 0x7f) + { + // store the data as one byte + utf8Data += c; + } + else + { + // store the data as two bytes + utf8Data += static_cast(0xc0 | ((c >> 6) & 0x1f)); + utf8Data += static_cast(0x80 | (c & 0x3f)); + } + } +} + +// ---------------------------------------------------------------------- + +AckMessageQuery::AckMessageQuery() : + m_numItems(0), + m_enableDatabaseLogging(ConfigServerDatabase::getEnableDatabaseErrorLogging()) +{ +} + +// ---------------------------------------------------------------------- + +bool AckMessageQuery::setupData(DB::Session *session) +{ + return m_message_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000); +} + +// ---------------------------------------------------------------------- + +bool AckMessageQuery::addData(const MessageToId &MessageId) +{ + if (!m_message_ids.push_back(MessageId.getValueString())) + return false; + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +int AckMessageQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +void AckMessageQuery::clearData() +{ + m_message_ids.clear(); + + m_numItems=0; + +} + +// ---------------------------------------------------------------------- + +void AckMessageQuery::freeData() +{ + m_message_ids.free(); + +} +// ---------------------------------------------------------------------- + +bool AckMessageQuery::bindParameters() +{ + if (!bindParameter(m_message_ids)) return false; + if (!bindParameter(m_numItems)) return false; + if (!bindParameter(m_enableDatabaseLogging)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool AckMessageQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void AckMessageQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.acknowledge_message_batch(:message_id, :chunk_size, :enable_db_logging); end;"; +} + +// ====================================================================== + +LoadMessagesQuery::LoadMessagesQuery(const std::string &schema) : + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode LoadMessagesQuery::getExecutionMode() const +{ + if (getProtocol()==DB::PROTOCOL_OCI) + return (MODE_PLSQL_REFCURSOR); + else + return (MODE_SQL); +} + +// ---------------------------------------------------------------------- + +/* +void LoadMessagesQuery::getData(std::vector &buffer) +{ + MessageToPayload temp; + + size_t numRows = getNumRowsFetched(); + size_t count = 0; + + for (std::vector::const_iterator i=m_data.begin(); i!=m_data.end(); ++i) + { + if (++count > numRows) + break; + + std::string utf8data; + i->packed_data.getValue(utf8data); + std::vector packedDataVector; + convertUTF8ToMessage(utf8data, packedDataVector); + + temp.set( + i->object_id.getValue(), + i->message_id.getValue(), + Unicode::wideToNarrow(i->method.getValue()), + packedDataVector, + i->call_time.getValue(), + i->guaranteed.getValue(), + static_cast(i->delivery_type.getValue())); + + buffer.push_back(temp); + } +}*/ + +// ---------------------------------------------------------------------- + +bool LoadMessagesQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool LoadMessagesQuery::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].message_id)) return false; + if (!bindCol(m_data[0].method)) return false; + if (!bindCol(m_data[0].packed_data)) return false; + if (!bindCol(m_data[0].call_time)) return false; + if (!bindCol(m_data[0].guaranteed)) return false; + if (!bindCol(m_data[0].delivery_type)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +void LoadMessagesQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_messages(); end;"; +} + +// ---------------------------------------------------------------------- + +void LoadMessagesQuery::convertUTF8ToMessage(const std::string & utf8Data, std::vector & messageData) const +{ + int count = utf8Data.size(); + messageData.resize(0); + messageData.reserve(count); + uint8 c; + for (int i = 0; i < count; ++i) + { + c = utf8Data[i]; + if ((c & 0xc0) == 0xc0) + { + // data is stored in 2 bytes + messageData.push_back(static_cast(((c & 0x1f) << 6) + (utf8Data[++i] & 0x3f))); + } + else + { + // data is stored in 1 byte + messageData.push_back(c); + } + } +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/MessageQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/MessageQuery.h new file mode 100644 index 00000000..3db72bd9 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/MessageQuery.h @@ -0,0 +1,129 @@ +// ====================================================================== +// +// MessageQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_MessageQuery_H +#define INCLUDED_MessageQuery_H + +// ====================================================================== + +#include "serverNetworkMessages/MessageToPayload.h" +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" +#include + +// ====================================================================== + +namespace DBQuery +{ + + class SaveMessageQuery : public DB::Query + { + public: + SaveMessageQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const MessageToPayload &data); + void clearData(); + void freeData(); + + int getNumItems() const; + + private: + DB::BindableVarrayString m_message_ids; + DB::BindableVarrayString m_object_ids; + DB::BindableVarrayString m_methods; + DB::BindableVarrayString m_packed_datas; + DB::BindableVarrayNumber m_call_times; + DB::BindableVarrayString m_guaranteeds; + DB::BindableVarrayNumber m_delivery_types; + DB::BindableLong m_numItems; + DB::BindableLong m_enableDatabaseLogging; + + private: + SaveMessageQuery(const SaveMessageQuery&); // disable + SaveMessageQuery& operator=(const SaveMessageQuery&); // disable + + void convertMessageToUTF8(const stdvector::fwd & messageData, std::string & utf8Data) const; + }; + + class AckMessageQuery : public DB::Query + { + public: + AckMessageQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const MessageToId &MessageId); + void clearData(); + void freeData(); + + int getNumItems() const; + + private: + DB::BindableVarrayString m_message_ids; + DB::BindableLong m_numItems; + DB::BindableLong m_enableDatabaseLogging; + + private: + AckMessageQuery(const AckMessageQuery&); // disable + AckMessageQuery& operator=(const AckMessageQuery&); // disable + }; + + class LoadMessagesQuery : public DB::Query + { + LoadMessagesQuery(const LoadMessagesQuery&); // disable + LoadMessagesQuery& operator=(const LoadMessagesQuery&); // disable + + public: + struct MessageRow + { + DB::BindableNetworkId message_id; + DB::BindableNetworkId object_id; + DB::BindableString<50> method; + DB::BindableString<4000> packed_data; + DB::BindableLong call_time; + DB::BindableBool guaranteed; + DB::BindableLong delivery_type; + }; + + public: + LoadMessagesQuery(const std::string &schema); + + const std::vector & getData() const; + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual DB::Query::QueryMode getExecutionMode() const; + virtual void getSQL(std::string &sql); + + void convertUTF8ToMessage(const std::string & utf8Data, stdvector::fwd & messageData) const; + + private: + std::vector m_data; + const std::string m_schema; + }; +} + +// ====================================================================== + +inline const std::vector & DBQuery::LoadMessagesQuery::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectVariableQueries.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectVariableQueries.cpp new file mode 100644 index 00000000..7086a9c1 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectVariableQueries.cpp @@ -0,0 +1,284 @@ +// ====================================================================== +// +// ObjectVariableQueries.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "ObjectVariableQueries.h" + +#include "serverDatabase/DatabaseProcess.h" + +using namespace DBSchema; +using namespace DBQuery; + +// ====================================================================== + +namespace ObjectVariableQueriesNamespace +{ + static const size_t ms_fetchBatchSize=1000; +} +using namespace ObjectVariableQueriesNamespace; + +// ====================================================================== + +GenericObjectVariableQuery::GenericObjectVariableQuery() : + DatabaseProcessQuery(new ObjectVariableRow), + m_numItems(0) +{ +} + +// ---------------------------------------------------------------------- + +bool GenericObjectVariableQuery::setupData(DB::Session *session) +{ + if (!m_objectIds.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_nameIds.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool GenericObjectVariableQuery::addData(const NetworkId &objectId, int nameId, int typeId, const std::string &value) +{ + if (!m_objectIds.push_back(objectId.getValueString())) return false; + if (!m_nameIds.push_back(nameId)) return false; + if (!m_types.push_back(typeId)) return false; + if (!m_values.push_back(value)) return false; + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +int GenericObjectVariableQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +void GenericObjectVariableQuery::clearData() +{ + m_objectIds.clear(); + m_nameIds.clear(); + m_types.clear(); + m_values.clear(); + + m_numItems=0; +} + +// ---------------------------------------------------------------------- + +void GenericObjectVariableQuery::freeData() +{ + m_objectIds.free(); + m_nameIds.free(); + m_types.free(); + m_values.free(); +} + +// ---------------------------------------------------------------------- + +bool GenericObjectVariableQuery::bindParameters() +{ + if (!bindParameter(m_objectIds)) return false; + if (!bindParameter(m_nameIds)) return false; + if (!bindParameter(m_types)) return false; + if (!bindParameter(m_values)) return false; + if (!bindParameter(m_numItems)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool GenericObjectVariableQuery::bindColumns() +{ + return true; +} + +// ====================================================================== + +AddObjectVariableQuery::AddObjectVariableQuery() +{ +} + +// ---------------------------------------------------------------------- + +void AddObjectVariableQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.add_object_variable_batch (:object_id, :name_id, :type, :value, :count); end;"; +} + +// ====================================================================== + +UpdateObjectVariableQuery::UpdateObjectVariableQuery() +{ +} + +// ---------------------------------------------------------------------- + +void UpdateObjectVariableQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.update_object_variable_batch (:object_id, :name_id, :type, :value, :count); end;"; +} + +// ====================================================================== + +RemoveObjectVariableQuery::RemoveObjectVariableQuery() : + DatabaseProcessQuery(new ObjectVariableRow), + m_numItems(0) +{ +} + +// ---------------------------------------------------------------------- + +bool RemoveObjectVariableQuery::setupData(DB::Session *session) +{ + if (!m_objectIds.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_nameIds.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool RemoveObjectVariableQuery::addData(const NetworkId &objectId, int nameId) +{ + if (!m_objectIds.push_back(objectId.getValueString())) return false; + if (!m_nameIds.push_back(nameId)) return false; + m_numItems = m_numItems.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +void RemoveObjectVariableQuery::clearData() +{ + m_objectIds.clear(); + m_nameIds.clear(); + m_numItems=0; +} + +// ---------------------------------------------------------------------- + +void RemoveObjectVariableQuery::freeData() +{ + m_objectIds.free(); + m_nameIds.free(); +} + +// ---------------------------------------------------------------------- + +int RemoveObjectVariableQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +bool RemoveObjectVariableQuery::bindParameters() +{ + if (!bindParameter(m_objectIds)) return false; + if (!bindParameter(m_nameIds)) return false; + if (!bindParameter(m_numItems)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool RemoveObjectVariableQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void RemoveObjectVariableQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.remove_object_variable_batch (:object_id, :name_id, :count); end;"; +} + +// ====================================================================== + +GetAllObjectVariables::GetAllObjectVariables(const std::string &schema) : + m_data(ms_fetchBatchSize), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +bool GetAllObjectVariables::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool GetAllObjectVariables::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + + setColArrayMode(skipSize, ms_fetchBatchSize); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].name_id)) return false; + if (!bindCol(m_data[0].type)) return false; + if (!bindCol(m_data[0].value)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +void GetAllObjectVariables::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_object_variables; end;"; + //sql=std::string("select /*+ ORDERED USE_NL(T)*/ t.object_id, t.name_id, t.type, t.value from object_list l,object_variables t where l.object_id = t.object_id and nvl(t.detached,0) = 0"); +} + +// ---------------------------------------------------------------------- + +const std::vector &GetAllObjectVariables::getData() const +{ + return m_data; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode GetAllObjectVariables::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; + //return (MODE_SQL); +} + +// ====================================================================== + +GetObjectVariableOverrides::GetObjectVariableOverrides(const std::string &schema, const std::string &goldSchema) : + GetAllObjectVariables(schema), + gold_schema(goldSchema) +{ +} + +// ---------------------------------------------------------------------- + +void GetObjectVariableOverrides::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"gold_override.load_objvar_overrides(:gold_schema); end;"; +} + +// ---------------------------------------------------------------------- + +bool GetObjectVariableOverrides::bindParameters() +{ + if (!bindParameter(gold_schema)) return false; + return true; +} + +// ====================================================================== + diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectVariableQueries.h b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectVariableQueries.h new file mode 100644 index 00000000..44aef98f --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectVariableQueries.h @@ -0,0 +1,148 @@ +// ====================================================================== +// +// ObjectVariableQueries.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ObjectVariableQueries_H +#define INCLUDED_ObjectVariableQueries_H + +// ====================================================================== + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcessQuery.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "sharedFoundation/NetworkId.h" + +#include + +// ====================================================================== + +namespace DBQuery +{ + /** + * Base class for queries to add or update object variables + */ + class GenericObjectVariableQuery : public DatabaseProcessQuery + { + GenericObjectVariableQuery(const GenericObjectVariableQuery&); // disable + GenericObjectVariableQuery& operator=(const GenericObjectVariableQuery&); // disable + public: + GenericObjectVariableQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + + bool setupData(DB::Session *session); + bool addData(const NetworkId &objectId, int nameId, int typeId, const std::string &value); + void clearData(); + void freeData(); + + int getNumItems() const; + + private: + DB::BindableVarrayString m_objectIds; + DB::BindableVarrayNumber m_nameIds; + DB::BindableVarrayNumber m_types; + DB::BindableVarrayString m_values; + DB::BindableLong m_numItems; + }; + + class AddObjectVariableQuery : public GenericObjectVariableQuery + { + public: + AddObjectVariableQuery(); + virtual void getSQL(std::string &sql); + + private: + AddObjectVariableQuery(const AddObjectVariableQuery&); + AddObjectVariableQuery& operator=(const AddObjectVariableQuery&); + }; + + class UpdateObjectVariableQuery : public GenericObjectVariableQuery + { + public: + UpdateObjectVariableQuery(); + virtual void getSQL(std::string &sql); + + private: + UpdateObjectVariableQuery(const UpdateObjectVariableQuery&); + UpdateObjectVariableQuery& operator=(const UpdateObjectVariableQuery&); + }; + + class RemoveObjectVariableQuery : public DatabaseProcessQuery + { + RemoveObjectVariableQuery(const RemoveObjectVariableQuery&); // disable + RemoveObjectVariableQuery& operator=(const RemoveObjectVariableQuery&); // disable + public: + RemoveObjectVariableQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const NetworkId &objectId, int nameId); + void clearData(); + void freeData(); + + int getNumItems() const; + + private: + DB::BindableVarrayString m_objectIds; + DB::BindableVarrayNumber m_nameIds; + DB::BindableLong m_numItems; + }; + + /** + * Query to load all the object variables for an object at the same + * time. + */ + class GetAllObjectVariables : public DB::Query + { + public: + GetAllObjectVariables(const std::string &schema); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + const std::vector &getData() const; + + QueryMode getExecutionMode() const; + + protected: + std::vector m_data; + const std::string m_schema; + + private: + GetAllObjectVariables(const GetAllObjectVariables&); // disable + GetAllObjectVariables& operator=(const GetAllObjectVariables&); // disable + }; + + /** + * Get all the object variables from the local database that override + * those in the gold database. + */ + class GetObjectVariableOverrides : public GetAllObjectVariables + { + public: + GetObjectVariableOverrides(const std::string &schema, const std::string &goldSchema); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + + private: + DB::BindableString<50> gold_schema; + + private: + GetObjectVariableOverrides(const GetObjectVariableOverrides&); // disable + GetObjectVariableOverrides& operator=(const GetObjectVariableOverrides&); // disable + }; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectsTableQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectsTableQuery.cpp new file mode 100644 index 00000000..11624d22 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectsTableQuery.cpp @@ -0,0 +1,798 @@ +// ====================================================================== +// +// ObjectsTableQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/ObjectsTableQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +using namespace DBQuery; + + + + +using namespace DBSchema; + +// ====================================================================== + +ObjectsTableQuery::ObjectsTableQuery() : + DatabaseProcessQuery(new ObjectBufferRow), + m_numItems(0) +{ +} + +bool ObjectsTableQuery::setupData(DB::Session *session) +{ + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!m_object_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_xs.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_ys.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_zs.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_quaternion_ws.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_quaternion_xs.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_quaternion_ys.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_quaternion_zs.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_node_xs.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_node_ys.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_node_zs.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_type_ids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_scene_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_controller_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_deleteds.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_object_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_volumes.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_contained_bys.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_slot_arrangements.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_player_controlleds.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_cache_versions.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_load_contentss.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_cash_balances.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_bank_balances.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_complexitys.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_name_string_tables.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_name_string_texts.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_static_item_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_static_item_versions.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_conversion_ids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_object_template_ids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_load_withs.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_0_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_0_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_0_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_1_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_1_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_1_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_2_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_2_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_2_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_3_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_3_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_3_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_4_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_4_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_4_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_5_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_5_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_5_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_6_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_6_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_6_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_7_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_7_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_7_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_8_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_8_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_8_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_9_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_9_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_9_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_10_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_10_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_10_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_11_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_11_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_11_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_12_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_12_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_12_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_13_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_13_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_13_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_14_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_14_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_14_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_15_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_15_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_15_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_16_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_16_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_16_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_17_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_17_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_17_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_18_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_18_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_18_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_19_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_objvar_19_types.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_objvar_19_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_script_lists.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false; + + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!m_object_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + return true; +} + +bool ObjectsTableQuery::addData(const DB::Row *_data) +{ + const ObjectBufferRow *myData=safe_cast(_data); + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!m_object_ids.push_back(myData->object_id.getValueASCII())) return false; + if (!m_xs.push_back(myData->x.isNull(), myData->x.getValue())) return false; + if (!m_ys.push_back(myData->y.isNull(), myData->y.getValue())) return false; + if (!m_zs.push_back(myData->z.isNull(), myData->z.getValue())) return false; + if (!m_quaternion_ws.push_back(myData->quaternion_w.isNull(), myData->quaternion_w.getValue())) return false; + if (!m_quaternion_xs.push_back(myData->quaternion_x.isNull(), myData->quaternion_x.getValue())) return false; + if (!m_quaternion_ys.push_back(myData->quaternion_y.isNull(), myData->quaternion_y.getValue())) return false; + if (!m_quaternion_zs.push_back(myData->quaternion_z.isNull(), myData->quaternion_z.getValue())) return false; + if (!m_node_xs.push_back(myData->node_x.isNull(), myData->node_x.getValue())) return false; + if (!m_node_ys.push_back(myData->node_y.isNull(), myData->node_y.getValue())) return false; + if (!m_node_zs.push_back(myData->node_z.isNull(), myData->node_z.getValue())) return false; + if (!m_type_ids.push_back(myData->type_id.isNull(), myData->type_id.getValue())) return false; + if (!m_scene_ids.push_back(myData->scene_id.getValueASCII())) return false; + if (!m_controller_types.push_back(myData->controller_type.isNull(), myData->controller_type.getValue())) return false; + if (!m_deleteds.push_back(myData->deleted.isNull(), myData->deleted.getValue())) return false; + if (!m_object_names.push_back(myData->object_name.getValueASCII())) return false; + if (!m_volumes.push_back(myData->volume.isNull(), myData->volume.getValue())) return false; + if (!m_contained_bys.push_back(myData->contained_by.getValueASCII())) return false; + if (!m_slot_arrangements.push_back(myData->slot_arrangement.isNull(), myData->slot_arrangement.getValue())) return false; + if (!m_player_controlleds.push_back(myData->player_controlled.getValueASCII())) return false; + if (!m_cache_versions.push_back(myData->cache_version.isNull(), myData->cache_version.getValue())) return false; + if (!m_load_contentss.push_back(myData->load_contents.getValueASCII())) return false; + if (!m_cash_balances.push_back(myData->cash_balance.isNull(), myData->cash_balance.getValue())) return false; + if (!m_bank_balances.push_back(myData->bank_balance.isNull(), myData->bank_balance.getValue())) return false; + if (!m_complexitys.push_back(myData->complexity.isNull(), myData->complexity.getValue())) return false; + if (!m_name_string_tables.push_back(myData->name_string_table.getValueASCII())) return false; + if (!m_name_string_texts.push_back(myData->name_string_text.getValueASCII())) return false; + if (!m_static_item_names.push_back(myData->static_item_name.getValueASCII())) return false; + if (!m_static_item_versions.push_back(myData->static_item_version.isNull(), myData->static_item_version.getValue())) return false; + if (!m_conversion_ids.push_back(myData->conversion_id.isNull(), myData->conversion_id.getValue())) return false; + if (!m_object_template_ids.push_back(myData->object_template_id.isNull(), myData->object_template_id.getValue())) return false; + if (!m_load_withs.push_back(myData->load_with.getValueASCII())) return false; + if (!m_objvar_0_names.push_back(myData->objvar_0_name.getValueASCII())) return false; + if (!m_objvar_0_types.push_back(myData->objvar_0_type.isNull(), myData->objvar_0_type.getValue())) return false; + if (!m_objvar_0_values.push_back(myData->objvar_0_value.getValueASCII())) return false; + if (!m_objvar_1_names.push_back(myData->objvar_1_name.getValueASCII())) return false; + if (!m_objvar_1_types.push_back(myData->objvar_1_type.isNull(), myData->objvar_1_type.getValue())) return false; + if (!m_objvar_1_values.push_back(myData->objvar_1_value.getValueASCII())) return false; + if (!m_objvar_2_names.push_back(myData->objvar_2_name.getValueASCII())) return false; + if (!m_objvar_2_types.push_back(myData->objvar_2_type.isNull(), myData->objvar_2_type.getValue())) return false; + if (!m_objvar_2_values.push_back(myData->objvar_2_value.getValueASCII())) return false; + if (!m_objvar_3_names.push_back(myData->objvar_3_name.getValueASCII())) return false; + if (!m_objvar_3_types.push_back(myData->objvar_3_type.isNull(), myData->objvar_3_type.getValue())) return false; + if (!m_objvar_3_values.push_back(myData->objvar_3_value.getValueASCII())) return false; + if (!m_objvar_4_names.push_back(myData->objvar_4_name.getValueASCII())) return false; + if (!m_objvar_4_types.push_back(myData->objvar_4_type.isNull(), myData->objvar_4_type.getValue())) return false; + if (!m_objvar_4_values.push_back(myData->objvar_4_value.getValueASCII())) return false; + if (!m_objvar_5_names.push_back(myData->objvar_5_name.getValueASCII())) return false; + if (!m_objvar_5_types.push_back(myData->objvar_5_type.isNull(), myData->objvar_5_type.getValue())) return false; + if (!m_objvar_5_values.push_back(myData->objvar_5_value.getValueASCII())) return false; + if (!m_objvar_6_names.push_back(myData->objvar_6_name.getValueASCII())) return false; + if (!m_objvar_6_types.push_back(myData->objvar_6_type.isNull(), myData->objvar_6_type.getValue())) return false; + if (!m_objvar_6_values.push_back(myData->objvar_6_value.getValueASCII())) return false; + if (!m_objvar_7_names.push_back(myData->objvar_7_name.getValueASCII())) return false; + if (!m_objvar_7_types.push_back(myData->objvar_7_type.isNull(), myData->objvar_7_type.getValue())) return false; + if (!m_objvar_7_values.push_back(myData->objvar_7_value.getValueASCII())) return false; + if (!m_objvar_8_names.push_back(myData->objvar_8_name.getValueASCII())) return false; + if (!m_objvar_8_types.push_back(myData->objvar_8_type.isNull(), myData->objvar_8_type.getValue())) return false; + if (!m_objvar_8_values.push_back(myData->objvar_8_value.getValueASCII())) return false; + if (!m_objvar_9_names.push_back(myData->objvar_9_name.getValueASCII())) return false; + if (!m_objvar_9_types.push_back(myData->objvar_9_type.isNull(), myData->objvar_9_type.getValue())) return false; + if (!m_objvar_9_values.push_back(myData->objvar_9_value.getValueASCII())) return false; + if (!m_objvar_10_names.push_back(myData->objvar_10_name.getValueASCII())) return false; + if (!m_objvar_10_types.push_back(myData->objvar_10_type.isNull(), myData->objvar_10_type.getValue())) return false; + if (!m_objvar_10_values.push_back(myData->objvar_10_value.getValueASCII())) return false; + if (!m_objvar_11_names.push_back(myData->objvar_11_name.getValueASCII())) return false; + if (!m_objvar_11_types.push_back(myData->objvar_11_type.isNull(), myData->objvar_11_type.getValue())) return false; + if (!m_objvar_11_values.push_back(myData->objvar_11_value.getValueASCII())) return false; + if (!m_objvar_12_names.push_back(myData->objvar_12_name.getValueASCII())) return false; + if (!m_objvar_12_types.push_back(myData->objvar_12_type.isNull(), myData->objvar_12_type.getValue())) return false; + if (!m_objvar_12_values.push_back(myData->objvar_12_value.getValueASCII())) return false; + if (!m_objvar_13_names.push_back(myData->objvar_13_name.getValueASCII())) return false; + if (!m_objvar_13_types.push_back(myData->objvar_13_type.isNull(), myData->objvar_13_type.getValue())) return false; + if (!m_objvar_13_values.push_back(myData->objvar_13_value.getValueASCII())) return false; + if (!m_objvar_14_names.push_back(myData->objvar_14_name.getValueASCII())) return false; + if (!m_objvar_14_types.push_back(myData->objvar_14_type.isNull(), myData->objvar_14_type.getValue())) return false; + if (!m_objvar_14_values.push_back(myData->objvar_14_value.getValueASCII())) return false; + if (!m_objvar_15_names.push_back(myData->objvar_15_name.getValueASCII())) return false; + if (!m_objvar_15_types.push_back(myData->objvar_15_type.isNull(), myData->objvar_15_type.getValue())) return false; + if (!m_objvar_15_values.push_back(myData->objvar_15_value.getValueASCII())) return false; + if (!m_objvar_16_names.push_back(myData->objvar_16_name.getValueASCII())) return false; + if (!m_objvar_16_types.push_back(myData->objvar_16_type.isNull(), myData->objvar_16_type.getValue())) return false; + if (!m_objvar_16_values.push_back(myData->objvar_16_value.getValueASCII())) return false; + if (!m_objvar_17_names.push_back(myData->objvar_17_name.getValueASCII())) return false; + if (!m_objvar_17_types.push_back(myData->objvar_17_type.isNull(), myData->objvar_17_type.getValue())) return false; + if (!m_objvar_17_values.push_back(myData->objvar_17_value.getValueASCII())) return false; + if (!m_objvar_18_names.push_back(myData->objvar_18_name.getValueASCII())) return false; + if (!m_objvar_18_types.push_back(myData->objvar_18_type.isNull(), myData->objvar_18_type.getValue())) return false; + if (!m_objvar_18_values.push_back(myData->objvar_18_value.getValueASCII())) return false; + if (!m_objvar_19_names.push_back(myData->objvar_19_name.getValueASCII())) return false; + if (!m_objvar_19_types.push_back(myData->objvar_19_type.isNull(), myData->objvar_19_type.getValue())) return false; + if (!m_objvar_19_values.push_back(myData->objvar_19_value.getValueASCII())) return false; + if (!m_script_lists.push_back(myData->script_list.getValueASCII())) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!m_object_ids.push_back(myData->object_id.getValueASCII())) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +int ObjectsTableQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +void ObjectsTableQuery::clearData() +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + m_object_ids.clear(); + m_xs.clear(); + m_ys.clear(); + m_zs.clear(); + m_quaternion_ws.clear(); + m_quaternion_xs.clear(); + m_quaternion_ys.clear(); + m_quaternion_zs.clear(); + m_node_xs.clear(); + m_node_ys.clear(); + m_node_zs.clear(); + m_type_ids.clear(); + m_scene_ids.clear(); + m_controller_types.clear(); + m_deleteds.clear(); + m_object_names.clear(); + m_volumes.clear(); + m_contained_bys.clear(); + m_slot_arrangements.clear(); + m_player_controlleds.clear(); + m_cache_versions.clear(); + m_load_contentss.clear(); + m_cash_balances.clear(); + m_bank_balances.clear(); + m_complexitys.clear(); + m_name_string_tables.clear(); + m_name_string_texts.clear(); + m_static_item_names.clear(); + m_static_item_versions.clear(); + m_conversion_ids.clear(); + m_object_template_ids.clear(); + m_load_withs.clear(); + m_objvar_0_names.clear(); + m_objvar_0_types.clear(); + m_objvar_0_values.clear(); + m_objvar_1_names.clear(); + m_objvar_1_types.clear(); + m_objvar_1_values.clear(); + m_objvar_2_names.clear(); + m_objvar_2_types.clear(); + m_objvar_2_values.clear(); + m_objvar_3_names.clear(); + m_objvar_3_types.clear(); + m_objvar_3_values.clear(); + m_objvar_4_names.clear(); + m_objvar_4_types.clear(); + m_objvar_4_values.clear(); + m_objvar_5_names.clear(); + m_objvar_5_types.clear(); + m_objvar_5_values.clear(); + m_objvar_6_names.clear(); + m_objvar_6_types.clear(); + m_objvar_6_values.clear(); + m_objvar_7_names.clear(); + m_objvar_7_types.clear(); + m_objvar_7_values.clear(); + m_objvar_8_names.clear(); + m_objvar_8_types.clear(); + m_objvar_8_values.clear(); + m_objvar_9_names.clear(); + m_objvar_9_types.clear(); + m_objvar_9_values.clear(); + m_objvar_10_names.clear(); + m_objvar_10_types.clear(); + m_objvar_10_values.clear(); + m_objvar_11_names.clear(); + m_objvar_11_types.clear(); + m_objvar_11_values.clear(); + m_objvar_12_names.clear(); + m_objvar_12_types.clear(); + m_objvar_12_values.clear(); + m_objvar_13_names.clear(); + m_objvar_13_types.clear(); + m_objvar_13_values.clear(); + m_objvar_14_names.clear(); + m_objvar_14_types.clear(); + m_objvar_14_values.clear(); + m_objvar_15_names.clear(); + m_objvar_15_types.clear(); + m_objvar_15_values.clear(); + m_objvar_16_names.clear(); + m_objvar_16_types.clear(); + m_objvar_16_values.clear(); + m_objvar_17_names.clear(); + m_objvar_17_types.clear(); + m_objvar_17_values.clear(); + m_objvar_18_names.clear(); + m_objvar_18_types.clear(); + m_objvar_18_values.clear(); + m_objvar_19_names.clear(); + m_objvar_19_types.clear(); + m_objvar_19_values.clear(); + m_script_lists.clear(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_object_ids.clear(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + m_numItems=0; +} + +void ObjectsTableQuery::freeData() +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + m_object_ids.free(); + m_xs.free(); + m_ys.free(); + m_zs.free(); + m_quaternion_ws.free(); + m_quaternion_xs.free(); + m_quaternion_ys.free(); + m_quaternion_zs.free(); + m_node_xs.free(); + m_node_ys.free(); + m_node_zs.free(); + m_type_ids.free(); + m_scene_ids.free(); + m_controller_types.free(); + m_deleteds.free(); + m_object_names.free(); + m_volumes.free(); + m_contained_bys.free(); + m_slot_arrangements.free(); + m_player_controlleds.free(); + m_cache_versions.free(); + m_load_contentss.free(); + m_cash_balances.free(); + m_bank_balances.free(); + m_complexitys.free(); + m_name_string_tables.free(); + m_name_string_texts.free(); + m_static_item_names.free(); + m_static_item_versions.free(); + m_conversion_ids.free(); + m_object_template_ids.free(); + m_load_withs.free(); + m_objvar_0_names.free(); + m_objvar_0_types.free(); + m_objvar_0_values.free(); + m_objvar_1_names.free(); + m_objvar_1_types.free(); + m_objvar_1_values.free(); + m_objvar_2_names.free(); + m_objvar_2_types.free(); + m_objvar_2_values.free(); + m_objvar_3_names.free(); + m_objvar_3_types.free(); + m_objvar_3_values.free(); + m_objvar_4_names.free(); + m_objvar_4_types.free(); + m_objvar_4_values.free(); + m_objvar_5_names.free(); + m_objvar_5_types.free(); + m_objvar_5_values.free(); + m_objvar_6_names.free(); + m_objvar_6_types.free(); + m_objvar_6_values.free(); + m_objvar_7_names.free(); + m_objvar_7_types.free(); + m_objvar_7_values.free(); + m_objvar_8_names.free(); + m_objvar_8_types.free(); + m_objvar_8_values.free(); + m_objvar_9_names.free(); + m_objvar_9_types.free(); + m_objvar_9_values.free(); + m_objvar_10_names.free(); + m_objvar_10_types.free(); + m_objvar_10_values.free(); + m_objvar_11_names.free(); + m_objvar_11_types.free(); + m_objvar_11_values.free(); + m_objvar_12_names.free(); + m_objvar_12_types.free(); + m_objvar_12_values.free(); + m_objvar_13_names.free(); + m_objvar_13_types.free(); + m_objvar_13_values.free(); + m_objvar_14_names.free(); + m_objvar_14_types.free(); + m_objvar_14_values.free(); + m_objvar_15_names.free(); + m_objvar_15_types.free(); + m_objvar_15_values.free(); + m_objvar_16_names.free(); + m_objvar_16_types.free(); + m_objvar_16_values.free(); + m_objvar_17_names.free(); + m_objvar_17_types.free(); + m_objvar_17_values.free(); + m_objvar_18_names.free(); + m_objvar_18_types.free(); + m_objvar_18_values.free(); + m_objvar_19_names.free(); + m_objvar_19_types.free(); + m_objvar_19_values.free(); + m_script_lists.free(); + break; + + case mode_SELECT: + break; + + case mode_DELETE: + m_object_ids.free(); + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + +} + +bool ObjectsTableQuery::bindParameters() +{ + switch (mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!bindParameter(m_xs)) return false; + if (!bindParameter(m_ys)) return false; + if (!bindParameter(m_zs)) return false; + if (!bindParameter(m_quaternion_ws)) return false; + if (!bindParameter(m_quaternion_xs)) return false; + if (!bindParameter(m_quaternion_ys)) return false; + if (!bindParameter(m_quaternion_zs)) return false; + if (!bindParameter(m_node_xs)) return false; + if (!bindParameter(m_node_ys)) return false; + if (!bindParameter(m_node_zs)) return false; + if (!bindParameter(m_object_template_ids)) return false; + if (!bindParameter(m_type_ids)) return false; + if (!bindParameter(m_scene_ids)) return false; + if (!bindParameter(m_controller_types)) return false; + if (!bindParameter(m_deleteds)) return false; + if (!bindParameter(m_object_names)) return false; + if (!bindParameter(m_volumes)) return false; + if (!bindParameter(m_contained_bys)) return false; + if (!bindParameter(m_slot_arrangements)) return false; + if (!bindParameter(m_player_controlleds)) return false; + if (!bindParameter(m_cache_versions)) return false; + if (!bindParameter(m_load_contentss)) return false; + if (!bindParameter(m_cash_balances)) return false; + if (!bindParameter(m_bank_balances)) return false; + if (!bindParameter(m_complexitys)) return false; + if (!bindParameter(m_name_string_tables)) return false; + if (!bindParameter(m_name_string_texts)) return false; + if (!bindParameter(m_static_item_names)) return false; + if (!bindParameter(m_static_item_versions)) return false; + if (!bindParameter(m_conversion_ids)) return false; + if (!bindParameter(m_load_withs)) return false; + if (!bindParameter(m_objvar_0_names)) return false; + if (!bindParameter(m_objvar_0_types)) return false; + if (!bindParameter(m_objvar_0_values)) return false; + if (!bindParameter(m_objvar_1_names)) return false; + if (!bindParameter(m_objvar_1_types)) return false; + if (!bindParameter(m_objvar_1_values)) return false; + if (!bindParameter(m_objvar_2_names)) return false; + if (!bindParameter(m_objvar_2_types)) return false; + if (!bindParameter(m_objvar_2_values)) return false; + if (!bindParameter(m_objvar_3_names)) return false; + if (!bindParameter(m_objvar_3_types)) return false; + if (!bindParameter(m_objvar_3_values)) return false; + if (!bindParameter(m_objvar_4_names)) return false; + if (!bindParameter(m_objvar_4_types)) return false; + if (!bindParameter(m_objvar_4_values)) return false; + if (!bindParameter(m_objvar_5_names)) return false; + if (!bindParameter(m_objvar_5_types)) return false; + if (!bindParameter(m_objvar_5_values)) return false; + if (!bindParameter(m_objvar_6_names)) return false; + if (!bindParameter(m_objvar_6_types)) return false; + if (!bindParameter(m_objvar_6_values)) return false; + if (!bindParameter(m_objvar_7_names)) return false; + if (!bindParameter(m_objvar_7_types)) return false; + if (!bindParameter(m_objvar_7_values)) return false; + if (!bindParameter(m_objvar_8_names)) return false; + if (!bindParameter(m_objvar_8_types)) return false; + if (!bindParameter(m_objvar_8_values)) return false; + if (!bindParameter(m_objvar_9_names)) return false; + if (!bindParameter(m_objvar_9_types)) return false; + if (!bindParameter(m_objvar_9_values)) return false; + if (!bindParameter(m_objvar_10_names)) return false; + if (!bindParameter(m_objvar_10_types)) return false; + if (!bindParameter(m_objvar_10_values)) return false; + if (!bindParameter(m_objvar_11_names)) return false; + if (!bindParameter(m_objvar_11_types)) return false; + if (!bindParameter(m_objvar_11_values)) return false; + if (!bindParameter(m_objvar_12_names)) return false; + if (!bindParameter(m_objvar_12_types)) return false; + if (!bindParameter(m_objvar_12_values)) return false; + if (!bindParameter(m_objvar_13_names)) return false; + if (!bindParameter(m_objvar_13_types)) return false; + if (!bindParameter(m_objvar_13_values)) return false; + if (!bindParameter(m_objvar_14_names)) return false; + if (!bindParameter(m_objvar_14_types)) return false; + if (!bindParameter(m_objvar_14_values)) return false; + if (!bindParameter(m_objvar_15_names)) return false; + if (!bindParameter(m_objvar_15_types)) return false; + if (!bindParameter(m_objvar_15_values)) return false; + if (!bindParameter(m_objvar_16_names)) return false; + if (!bindParameter(m_objvar_16_types)) return false; + if (!bindParameter(m_objvar_16_values)) return false; + if (!bindParameter(m_objvar_17_names)) return false; + if (!bindParameter(m_objvar_17_types)) return false; + if (!bindParameter(m_objvar_17_values)) return false; + if (!bindParameter(m_objvar_18_names)) return false; + if (!bindParameter(m_objvar_18_types)) return false; + if (!bindParameter(m_objvar_18_values)) return false; + if (!bindParameter(m_objvar_19_names)) return false; + if (!bindParameter(m_objvar_19_types)) return false; + if (!bindParameter(m_objvar_19_values)) return false; + if (!bindParameter(m_script_lists)) return false; + if (!bindParameter(m_object_ids)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + case mode_SELECT: + break; + + case mode_DELETE: + if (!bindParameter(m_object_ids)) return false; + if (!bindParameter(m_numItems)) return false; + break; + + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + return true; +} + +bool ObjectsTableQuery::bindColumns() +{ + return true; +} + +void ObjectsTableQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_object (:x, :y, :z, :quaternion_w, :quaternion_x, :quaternion_y, :quaternion_z, :node_x, :node_y, :node_z, :object_template, :type_id, :scene_id, :controller_type, :deleted, :object_name, :volume, :contained_by, :slot_arrangement, :player_controlled, :cache_version, :load_contents, :cash_balance, :bank_balance, :complexity, :name_string_table, :name_string_text, :static_item_name, :static_item_version, :conversion_id, :load_with, :objvar_0_name, :objvar_0_type, :objvar_0_value, :objvar_1_name, :objvar_1_type, :objvar_1_value, :objvar_2_name, :objvar_2_type, :objvar_2_value, :objvar_3_name, :objvar_3_type, :objvar_3_value, :objvar_4_name, :objvar_4_type, :objvar_4_value, :objvar_5_name, :objvar_5_type, :objvar_5_value, :objvar_6_name, :objvar_6_type, :objvar_6_value, :objvar_7_name, :objvar_7_type, :objvar_7_value, :objvar_8_name, :objvar_8_type, :objvar_8_value, :objvar_9_name, :objvar_9_type, :objvar_9_value, :objvar_10_name, :objvar_10_type, :objvar_10_value, :objvar_11_name, :objvar_11_type, :objvar_11_value, :objvar_12_name, :objvar_12_type, :objvar_12_value, :objvar_13_name, :objvar_13_type, :objvar_13_value, :objvar_14_name, :objvar_14_type, :objvar_14_value, :objvar_15_name, :objvar_15_type, :objvar_15_value, :objvar_16_name, :objvar_16_type, :objvar_16_value, :objvar_17_name, :objvar_17_type, :objvar_17_value, :objvar_18_name, :objvar_18_type, :objvar_18_value, :objvar_19_name, :objvar_19_type, :objvar_19_value, :script_list, :object_id, :chunk_size); end;"; + break; + case mode_INSERT: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.add_object (:x,:y,:z,:quaternion_w,:quaternion_x,:quaternion_y,:quaternion_z,:node_x,:node_y,:node_z,:object_template,:type_id,:scene_id,:controller_type,:deleted,:object_name,:volume,:contained_by,:slot_arrangement,:player_controlled,:cache_version, :load_contents, :cash_balance, :bank_balance, :complexity, :name_string_table, :name_string_text, :static_item_name, :static_item_version, :conversion_id, :load_with, :objvar_0_name, :objvar_0_type, :objvar_0_value, :objvar_1_name, :objvar_1_type, :objvar_1_value, :objvar_2_name, :objvar_2_type, :objvar_2_value, :objvar_3_name, :objvar_3_type, :objvar_3_value, :objvar_4_name, :objvar_4_type, :objvar_4_value, :objvar_5_name, :objvar_5_type, :objvar_5_value, :objvar_6_name, :objvar_6_type, :objvar_6_value, :objvar_7_name, :objvar_7_type, :objvar_7_value, :objvar_8_name, :objvar_8_type, :objvar_8_value, :objvar_9_name, :objvar_9_type, :objvar_9_value, :objvar_10_name, :objvar_10_type, :objvar_10_value, :objvar_11_name, :objvar_11_type, :objvar_11_value, :objvar_12_name, :objvar_12_type, :objvar_12_value, :objvar_13_name, :objvar_13_type, :objvar_13_value, :objvar_14_name, :objvar_14_type, :objvar_14_value, :objvar_15_name, :objvar_15_type, :objvar_15_value, :objvar_16_name, :objvar_16_type, :objvar_16_value, :objvar_17_name, :objvar_17_type, :objvar_17_value, :objvar_18_name, :objvar_18_type, :objvar_18_value, :objvar_19_name, :objvar_19_type, :objvar_19_value, :script_list, :object_id, :chunk_size); end;"; + + break; + case mode_SELECT: + break; + case mode_DELETE: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.remove_object (:object_id, :chunk_size); end;"; + break; + default: + DEBUG_FATAL(true,("Bad query mode.")); + } +} + +void ObjectsTableQuery::setObjectId(const NetworkId &objectId) +{ + ObjectRow *myData=safe_cast(data); + myData->object_id.setValue(objectId); +} + +// ====================================================================== + +ObjectsTableQuerySelect::ObjectsTableQuerySelect(const std::string &schema) : + m_data(1000), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +ObjectsTableQuerySelect::~ObjectsTableQuerySelect() +{ +} + +// ---------------------------------------------------------------------- + +const std::vector & ObjectsTableQuerySelect::getData() +{ + return m_data; +} + +// ---------------------------------------------------------------------- + +bool ObjectsTableQuerySelect::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool ObjectsTableQuerySelect::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, 1000); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].x)) return false; + if (!bindCol(m_data[0].y)) return false; + if (!bindCol(m_data[0].z)) return false; + if (!bindCol(m_data[0].quaternion_w)) return false; + if (!bindCol(m_data[0].quaternion_x)) return false; + if (!bindCol(m_data[0].quaternion_y)) return false; + if (!bindCol(m_data[0].quaternion_z)) return false; + if (!bindCol(m_data[0].node_x)) return false; + if (!bindCol(m_data[0].node_y)) return false; + if (!bindCol(m_data[0].node_z)) return false; + if (!bindCol(m_data[0].object_template_id)) return false; + if (!bindCol(m_data[0].type_id)) return false; + if (!bindCol(m_data[0].scene_id)) return false; + if (!bindCol(m_data[0].controller_type)) return false; + if (!bindCol(m_data[0].deleted)) return false; + if (!bindCol(m_data[0].object_name)) return false; + if (!bindCol(m_data[0].volume)) return false; + if (!bindCol(m_data[0].contained_by)) return false; + if (!bindCol(m_data[0].slot_arrangement)) return false; + if (!bindCol(m_data[0].player_controlled)) return false; + if (!bindCol(m_data[0].cache_version)) return false; + if (!bindCol(m_data[0].load_contents)) return false; + if (!bindCol(m_data[0].cash_balance)) return false; + if (!bindCol(m_data[0].bank_balance)) return false; + if (!bindCol(m_data[0].complexity)) return false; + if (!bindCol(m_data[0].name_string_table)) return false; + if (!bindCol(m_data[0].name_string_text)) return false; + if (!bindCol(m_data[0].static_item_name)) return false; + if (!bindCol(m_data[0].static_item_version)) return false; + if (!bindCol(m_data[0].conversion_id)) return false; + if (!bindCol(m_data[0].load_with)) return false; + + if (!bindCol(m_data[0].objvar_0_name)) return false; + if (!bindCol(m_data[0].objvar_0_type)) return false; + if (!bindCol(m_data[0].objvar_0_value)) return false; + if (!bindCol(m_data[0].objvar_1_name)) return false; + if (!bindCol(m_data[0].objvar_1_type)) return false; + if (!bindCol(m_data[0].objvar_1_value)) return false; + if (!bindCol(m_data[0].objvar_2_name)) return false; + if (!bindCol(m_data[0].objvar_2_type)) return false; + if (!bindCol(m_data[0].objvar_2_value)) return false; + if (!bindCol(m_data[0].objvar_3_name)) return false; + if (!bindCol(m_data[0].objvar_3_type)) return false; + if (!bindCol(m_data[0].objvar_3_value)) return false; + if (!bindCol(m_data[0].objvar_4_name)) return false; + if (!bindCol(m_data[0].objvar_4_type)) return false; + if (!bindCol(m_data[0].objvar_4_value)) return false; + if (!bindCol(m_data[0].objvar_5_name)) return false; + if (!bindCol(m_data[0].objvar_5_type)) return false; + if (!bindCol(m_data[0].objvar_5_value)) return false; + if (!bindCol(m_data[0].objvar_6_name)) return false; + if (!bindCol(m_data[0].objvar_6_type)) return false; + if (!bindCol(m_data[0].objvar_6_value)) return false; + if (!bindCol(m_data[0].objvar_7_name)) return false; + if (!bindCol(m_data[0].objvar_7_type)) return false; + if (!bindCol(m_data[0].objvar_7_value)) return false; + if (!bindCol(m_data[0].objvar_8_name)) return false; + if (!bindCol(m_data[0].objvar_8_type)) return false; + if (!bindCol(m_data[0].objvar_8_value)) return false; + if (!bindCol(m_data[0].objvar_9_name)) return false; + if (!bindCol(m_data[0].objvar_9_type)) return false; + if (!bindCol(m_data[0].objvar_9_value)) return false; + + if (!bindCol(m_data[0].objvar_10_name)) return false; + if (!bindCol(m_data[0].objvar_10_type)) return false; + if (!bindCol(m_data[0].objvar_10_value)) return false; + if (!bindCol(m_data[0].objvar_11_name)) return false; + if (!bindCol(m_data[0].objvar_11_type)) return false; + if (!bindCol(m_data[0].objvar_11_value)) return false; + if (!bindCol(m_data[0].objvar_12_name)) return false; + if (!bindCol(m_data[0].objvar_12_type)) return false; + if (!bindCol(m_data[0].objvar_12_value)) return false; + if (!bindCol(m_data[0].objvar_13_name)) return false; + if (!bindCol(m_data[0].objvar_13_type)) return false; + if (!bindCol(m_data[0].objvar_13_value)) return false; + if (!bindCol(m_data[0].objvar_14_name)) return false; + if (!bindCol(m_data[0].objvar_14_type)) return false; + if (!bindCol(m_data[0].objvar_14_value)) return false; + if (!bindCol(m_data[0].objvar_15_name)) return false; + if (!bindCol(m_data[0].objvar_15_type)) return false; + if (!bindCol(m_data[0].objvar_15_value)) return false; + if (!bindCol(m_data[0].objvar_16_name)) return false; + if (!bindCol(m_data[0].objvar_16_type)) return false; + if (!bindCol(m_data[0].objvar_16_value)) return false; + if (!bindCol(m_data[0].objvar_17_name)) return false; + if (!bindCol(m_data[0].objvar_17_type)) return false; + if (!bindCol(m_data[0].objvar_17_value)) return false; + if (!bindCol(m_data[0].objvar_18_name)) return false; + if (!bindCol(m_data[0].objvar_18_type)) return false; + if (!bindCol(m_data[0].objvar_18_value)) return false; + if (!bindCol(m_data[0].objvar_19_name)) return false; + if (!bindCol(m_data[0].objvar_19_type)) return false; + if (!bindCol(m_data[0].objvar_19_value)) return false; + + if (!bindCol(m_data[0].script_list)) return false; + + if (!bindCol(m_data[0].container_level)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void ObjectsTableQuerySelect::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_object; end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode ObjectsTableQuerySelect::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectsTableQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectsTableQuery.h new file mode 100644 index 00000000..2817fe3d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ObjectsTableQuery.h @@ -0,0 +1,169 @@ +// ====================================================================== +// +// ObjectsTableQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ObjectsTableQuery_H +#define INCLUDED_ObjectsTableQuery_H + +// ====================================================================== +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcessQuery.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "sharedFoundation/NetworkId.h" + +#include +// ====================================================================== + +namespace DBQuery +{ + + class ObjectsTableQuery : public DatabaseProcessQuery + { + ObjectsTableQuery(const ObjectsTableQuery&); // disable + ObjectsTableQuery& operator=(const ObjectsTableQuery&); // disable + public: + ObjectsTableQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const DB::Row *_data); + void clearData(); + void freeData(); + + int getNumItems() const; + + void setObjectId(const NetworkId &objectId); + private: + DB::BindableVarrayString m_object_ids; + DB::BindableVarrayNumber m_xs; + DB::BindableVarrayNumber m_ys; + DB::BindableVarrayNumber m_zs; + DB::BindableVarrayNumber m_quaternion_ws; + DB::BindableVarrayNumber m_quaternion_xs; + DB::BindableVarrayNumber m_quaternion_ys; + DB::BindableVarrayNumber m_quaternion_zs; + DB::BindableVarrayNumber m_node_xs; + DB::BindableVarrayNumber m_node_ys; + DB::BindableVarrayNumber m_node_zs; + DB::BindableVarrayNumber m_type_ids; + DB::BindableVarrayString m_scene_ids; + DB::BindableVarrayNumber m_controller_types; + DB::BindableVarrayNumber m_deleteds; + DB::BindableVarrayString m_object_names; + DB::BindableVarrayNumber m_volumes; + DB::BindableVarrayString m_contained_bys; + DB::BindableVarrayNumber m_slot_arrangements; + DB::BindableVarrayString m_player_controlleds; + DB::BindableVarrayNumber m_cache_versions; + DB::BindableVarrayString m_load_contentss; + DB::BindableVarrayNumber m_cash_balances; + DB::BindableVarrayNumber m_bank_balances; + DB::BindableVarrayNumber m_complexitys; + DB::BindableVarrayString m_name_string_tables; + DB::BindableVarrayString m_name_string_texts; + DB::BindableVarrayString m_static_item_names; + DB::BindableVarrayNumber m_static_item_versions; + DB::BindableVarrayNumber m_conversion_ids; + DB::BindableVarrayNumber m_object_template_ids; + DB::BindableVarrayString m_load_withs; + DB::BindableVarrayString m_objvar_0_names; + DB::BindableVarrayNumber m_objvar_0_types; + DB::BindableVarrayString m_objvar_0_values; + DB::BindableVarrayString m_objvar_1_names; + DB::BindableVarrayNumber m_objvar_1_types; + DB::BindableVarrayString m_objvar_1_values; + DB::BindableVarrayString m_objvar_2_names; + DB::BindableVarrayNumber m_objvar_2_types; + DB::BindableVarrayString m_objvar_2_values; + DB::BindableVarrayString m_objvar_3_names; + DB::BindableVarrayNumber m_objvar_3_types; + DB::BindableVarrayString m_objvar_3_values; + DB::BindableVarrayString m_objvar_4_names; + DB::BindableVarrayNumber m_objvar_4_types; + DB::BindableVarrayString m_objvar_4_values; + DB::BindableVarrayString m_objvar_5_names; + DB::BindableVarrayNumber m_objvar_5_types; + DB::BindableVarrayString m_objvar_5_values; + DB::BindableVarrayString m_objvar_6_names; + DB::BindableVarrayNumber m_objvar_6_types; + DB::BindableVarrayString m_objvar_6_values; + DB::BindableVarrayString m_objvar_7_names; + DB::BindableVarrayNumber m_objvar_7_types; + DB::BindableVarrayString m_objvar_7_values; + DB::BindableVarrayString m_objvar_8_names; + DB::BindableVarrayNumber m_objvar_8_types; + DB::BindableVarrayString m_objvar_8_values; + DB::BindableVarrayString m_objvar_9_names; + DB::BindableVarrayNumber m_objvar_9_types; + DB::BindableVarrayString m_objvar_9_values; + DB::BindableVarrayString m_objvar_10_names; + DB::BindableVarrayNumber m_objvar_10_types; + DB::BindableVarrayString m_objvar_10_values; + DB::BindableVarrayString m_objvar_11_names; + DB::BindableVarrayNumber m_objvar_11_types; + DB::BindableVarrayString m_objvar_11_values; + DB::BindableVarrayString m_objvar_12_names; + DB::BindableVarrayNumber m_objvar_12_types; + DB::BindableVarrayString m_objvar_12_values; + DB::BindableVarrayString m_objvar_13_names; + DB::BindableVarrayNumber m_objvar_13_types; + DB::BindableVarrayString m_objvar_13_values; + DB::BindableVarrayString m_objvar_14_names; + DB::BindableVarrayNumber m_objvar_14_types; + DB::BindableVarrayString m_objvar_14_values; + DB::BindableVarrayString m_objvar_15_names; + DB::BindableVarrayNumber m_objvar_15_types; + DB::BindableVarrayString m_objvar_15_values; + DB::BindableVarrayString m_objvar_16_names; + DB::BindableVarrayNumber m_objvar_16_types; + DB::BindableVarrayString m_objvar_16_values; + DB::BindableVarrayString m_objvar_17_names; + DB::BindableVarrayNumber m_objvar_17_types; + DB::BindableVarrayString m_objvar_17_values; + DB::BindableVarrayString m_objvar_18_names; + DB::BindableVarrayNumber m_objvar_18_types; + DB::BindableVarrayString m_objvar_18_values; + DB::BindableVarrayString m_objvar_19_names; + DB::BindableVarrayNumber m_objvar_19_types; + DB::BindableVarrayString m_objvar_19_values; + DB::BindableVarrayString m_script_lists; + + DB::BindableLong m_numItems; + }; + + class ObjectsTableQuerySelect : public DB::Query + { + public: + ObjectsTableQuerySelect(const std::string &schema); + ~ObjectsTableQuerySelect(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + const std::vector & getData(); + + protected: + virtual QueryMode getExecutionMode() const; + + private: + std::vector m_data; + std::string m_schema; + + private: + ObjectsTableQuerySelect(const ObjectsTableQuerySelect&); // disable + ObjectsTableQuerySelect& operator=(const ObjectsTableQuerySelect&); // disable + }; + +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/OfflineMoneyCustomPersistStep.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/OfflineMoneyCustomPersistStep.cpp new file mode 100644 index 00000000..fea070c4 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/OfflineMoneyCustomPersistStep.cpp @@ -0,0 +1,193 @@ +// ====================================================================== +// +// OfflineMoneyCustomPersistStep.cpp +// copyright (c) 2005 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/OfflineMoneyCustomPersistStep.h" + +#include "serverDatabase/DatabaseProcess.h" +#include "serverNetworkMessages/GetMoneyFromOfflineObjectMessage.h" +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedFoundation/NetworkId.h" +#include +#include + +// ====================================================================== + +namespace OfflineMoneyCustomPersistStepNamespace +{ + struct GetMoneyData + { + uint32 m_replyServer; + NetworkId m_sourceObject; + int m_amount; + NetworkId m_replyTo; + std::string m_successCallback; + std::string m_failCallback; + std::vector m_packedDictionary; + bool m_success; + }; + + class MoneyGrabQuery: public DB::Query + { + public: + MoneyGrabQuery(); + + void setSource(NetworkId const & sourceObject, int amount); + bool getResult() const; + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + QueryMode getExecutionMode() const; + + private: + DB::BindableNetworkId m_sourceObject; + DB::BindableLong m_amount; + DB::BindableBool m_result; + + private: + MoneyGrabQuery(const MoneyGrabQuery&); // disable + MoneyGrabQuery& operator=(const MoneyGrabQuery&); // disable + }; +} + +using namespace OfflineMoneyCustomPersistStepNamespace; + +// ====================================================================== + +OfflineMoneyCustomPersistStep::OfflineMoneyCustomPersistStep() : + m_getMoneyRequests(new std::vector) +{ +} + +// ---------------------------------------------------------------------- + +OfflineMoneyCustomPersistStep::~OfflineMoneyCustomPersistStep() +{ + for (GetMoneyRequestsType::const_iterator i=m_getMoneyRequests->begin(); i!=m_getMoneyRequests->end(); ++i) + delete *i; + + delete m_getMoneyRequests; +} + +// ---------------------------------------------------------------------- + +void OfflineMoneyCustomPersistStep::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary) +{ + GetMoneyData * const data=new GetMoneyData; + data->m_replyServer=replyServer; + data->m_sourceObject=sourceObject; + data->m_amount=amount; + data->m_replyTo=replyTo; + data->m_successCallback=successCallback; + data->m_failCallback=failCallback; + data->m_packedDictionary=packedDictionary; + data->m_success=false; + + m_getMoneyRequests->push_back(data); +} + +// ---------------------------------------------------------------------- + +bool OfflineMoneyCustomPersistStep::beforePersist (DB::Session * /*session*/) +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool OfflineMoneyCustomPersistStep::afterPersist (DB::Session *session) +{ + if (m_getMoneyRequests->empty()) + return true; + + MoneyGrabQuery qry; + for (GetMoneyRequestsType::const_iterator i=m_getMoneyRequests->begin(); i!=m_getMoneyRequests->end(); ++i) + { + qry.setSource((*i)->m_sourceObject,(*i)->m_amount); + if (!session->exec(&qry)) + { + return false; + } + (*i)->m_success=qry.getResult(); + } + qry.done(); + + return true; +} + +// ---------------------------------------------------------------------- + +void OfflineMoneyCustomPersistStep::onComplete() +{ + for (GetMoneyRequestsType::const_iterator i=m_getMoneyRequests->begin(); i!=m_getMoneyRequests->end(); ++i) + { + GetMoneyFromOfflineObjectMessage replyMessage((*i)->m_sourceObject, (*i)->m_amount, (*i)->m_replyTo, (*i)->m_successCallback, (*i)->m_failCallback, (*i)->m_packedDictionary,(*i)->m_success); + DatabaseProcess::getInstance().sendToGameServer((*i)->m_replyServer, replyMessage); + } +} + +// ====================================================================== + +MoneyGrabQuery::MoneyGrabQuery() : + DB::Query(), + m_sourceObject(), + m_amount(), + m_result() +{ +} + +// ---------------------------------------------------------------------- + +void MoneyGrabQuery::setSource(NetworkId const & sourceObject, int amount) +{ + m_sourceObject=sourceObject; + m_amount=amount; +} + +// ---------------------------------------------------------------------- + +bool MoneyGrabQuery::getResult() const +{ + return m_result.getValue(); +} + +// ---------------------------------------------------------------------- + +bool MoneyGrabQuery::bindParameters() +{ + if (!bindParameter(m_result)) return false; + if (!bindParameter(m_sourceObject)) return false; + if (!bindParameter(m_amount)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool MoneyGrabQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void MoneyGrabQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.subtract_money_from_object(:object_id, :amount); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode MoneyGrabQuery::getExecutionMode() const +{ + return (MODE_PROCEXEC); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/OfflineMoneyCustomPersistStep.h b/game/server/application/SwgDatabaseServer/src/shared/queries/OfflineMoneyCustomPersistStep.h new file mode 100644 index 00000000..9efe0f23 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/OfflineMoneyCustomPersistStep.h @@ -0,0 +1,47 @@ +// ====================================================================== +// +// OfflineMoneyCustomPersistStep.h +// copyright (c) 2005 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_OfflineMoneyCustomPersistStep_H +#define INCLUDED_OfflineMoneyCustomPersistStep_H + +// ====================================================================== + +#include "serverDatabase/CustomPersistStep.h" + +// ====================================================================== + +namespace OfflineMoneyCustomPersistStepNamespace +{ + struct GetMoneyData; +} + +// ====================================================================== + +class OfflineMoneyCustomPersistStep : public CustomPersistStep +{ + public: + OfflineMoneyCustomPersistStep(); + ~OfflineMoneyCustomPersistStep(); + + void getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector::fwd const & packedDictionary); + + virtual bool beforePersist (DB::Session *session); + virtual bool afterPersist (DB::Session *session); + virtual void onComplete (); + + private: + typedef stdvector::fwd GetMoneyRequestsType; + GetMoneyRequestsType * const m_getMoneyRequests; + + private: + OfflineMoneyCustomPersistStep(const OfflineMoneyCustomPersistStep &); //disable + OfflineMoneyCustomPersistStep & operator=(const OfflineMoneyCustomPersistStep &); //disable +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/PropertyListQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/PropertyListQuery.cpp new file mode 100644 index 00000000..7d12e237 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/PropertyListQuery.cpp @@ -0,0 +1,154 @@ +// ====================================================================== +// +// PropertyListQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/PropertyListQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +using namespace DBQuery; + +// ====================================================================== + +PropertyListQuery::PropertyListQuery() : + ModeQuery(new DBSchema::PropertyListQueryData), //lint !e1524 // We don't delete the new row (base class does) + m_operations(-1), // init to -1 indicating an operation type has not yet been set for this query + m_numItems(0), + m_enableDatabaseLogging(ConfigServerDatabase::getEnableDatabaseErrorLogging()) +{ +} + +// ---------------------------------------------------------------------- + +bool PropertyListQuery::setupData(DB::Session *session) +{ + if (!m_object_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_list_ids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + if (!m_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool PropertyListQuery::addData(const NetworkId &networkId, int listId, const std::string &value, int operation) +{ + if (!m_object_ids.push_back(networkId.getValueString())) return false; + if (!m_list_ids.push_back(listId)) return false; + if (!m_values.push_back(value)) return false; + + if (m_operations.getValue() == -1) // if operation type for this query has not been initialized then do so + m_operations = operation; + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +int PropertyListQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +void PropertyListQuery::clearData() +{ + m_object_ids.clear(); + m_list_ids.clear(); + m_values.clear(); + + m_numItems=0; + m_operations= -1; // reset operation type to uninitialized in case someone tries to reuse same query for different operations +} + +// ---------------------------------------------------------------------- + +void PropertyListQuery::freeData() +{ + m_object_ids.free(); + m_list_ids.free(); + m_values.free(); +} + +// ---------------------------------------------------------------------- + +bool PropertyListQuery::bindParameters() +{ + if (!bindParameter(m_object_ids)) return false; + if (!bindParameter(m_list_ids)) return false; + if (!bindParameter(m_operations)) return false; + if (!bindParameter(m_values)) return false; + if (!bindParameter(m_numItems)) return false; + if (!bindParameter(m_enableDatabaseLogging)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool PropertyListQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void PropertyListQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.update_property_list_batch (:object_id, :list_id, :operation, :value, :chunk_size, :enable_db_logging); end;"; +} + +// ====================================================================== + +DBQuery::GetAllPropertyLists::GetAllPropertyLists(const std::string &schema) : + Query(), + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +bool GetAllPropertyLists::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool GetAllPropertyLists::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].list_id)) return false; + if (!bindCol(m_data[0].value)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +void GetAllPropertyLists::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_property_lists (); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode GetAllPropertyLists::getExecutionMode() const +{ + DEBUG_FATAL (getProtocol()!=DB::PROTOCOL_OCI,("PropertyList persistance is not supported for PostgreSQL.\n")); + return (MODE_PLSQL_REFCURSOR); +} + +// ====================================================================== + diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/PropertyListQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/PropertyListQuery.h new file mode 100644 index 00000000..0819e539 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/PropertyListQuery.h @@ -0,0 +1,115 @@ +// ====================================================================== +// +// PropertyListQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_PropertyListQuery_H +#define INCLUDED_PropertyListQuery_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" +#include "sharedDatabaseInterface/DbModeQuery.h" +#include + +// ====================================================================== + +namespace DBSchema +{ + struct PropertyListQueryData : public DB::Row + { + enum OperationType + { + ot_DELETE, + ot_INSERT, + ot_CLEAR + }; + + DB::BindableNetworkId object_id; + DB::BindableLong list_id; + DB::BindableLong operation; + DB::BindableString<500> value; //TODO: size + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + }; +} + +// ====================================================================== + +namespace DBQuery +{ + + class PropertyListQuery : public DB::ModeQuery + { + public: + PropertyListQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(const NetworkId &networkId, int listId, const std::string &value, int operation); + void clearData(); + void freeData(); + + int getNumItems() const; + + + private: + DB::BindableVarrayString m_object_ids; + DB::BindableVarrayNumber m_list_ids; + DB::BindableVarrayString m_values; + DB::BindableLong m_operations; + DB::BindableLong m_numItems; + DB::BindableLong m_enableDatabaseLogging; + + PropertyListQuery(const PropertyListQuery&); // disable + PropertyListQuery& operator=(const PropertyListQuery&); // disable + }; + +// ---------------------------------------------------------------------- + + /** + * A query that gets all the attributes for an object. + */ + + class GetAllPropertyLists : public DB::Query + { + public: + GetAllPropertyLists(const std::string &schema); + + const std::vector &getData() const; + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode GetAllPropertyLists::getExecutionMode() const; + + private: + GetAllPropertyLists(const GetAllPropertyLists&); // disable + GetAllPropertyLists& operator=(const GetAllPropertyLists&); // disable + + private: + std::vector m_data; + const std::string m_schema; + }; +} + +// ====================================================================== + +inline const std::vector &DBQuery::GetAllPropertyLists::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif + diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.cpp new file mode 100644 index 00000000..dfc8a70c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.cpp @@ -0,0 +1,173 @@ +// ====================================================================== +// +// ResourceTypeQuery.cpp +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/ResourceTypeQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +namespace ResourceTypeQueryNamespace +{ + const int ms_fetchBatchSize = 1000; +} + +using namespace ResourceTypeQueryNamespace; +using namespace DBQuery; + +// ====================================================================== + +ResourceTypeQuery::ResourceTypeQuery() : + m_numItems(0) +{ +} + +// ---------------------------------------------------------------------- + +bool ResourceTypeQuery::setupData(DB::Session *session) +{ + if (!m_resource_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_resource_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_resource_classes.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_attributes.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_fractal_seeds.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false; + if (!m_depleted_timestamps.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool ResourceTypeQuery::addData(DBSchema::ResourceTypeRow const & data) +{ + if (!m_resource_ids.push_back(data.resource_id.getValueASCII())) return false; + if (!m_resource_names.push_back(data.resource_name.getValueASCII())) return false; + if (!m_resource_classes.push_back(data.resource_class.getValueASCII())) return false; + if (!m_attributes.push_back(data.attributes.getValueASCII())) return false; + if (!m_fractal_seeds.push_back(data.fractal_seeds.getValueASCII())) return false; + if (!m_depleted_timestamps.push_back(data.depleted_timestamp.isNull(), data.depleted_timestamp.getValue())) return false; + + m_numItems=m_numItems.getValue() + 1; + return true; +} + +// ---------------------------------------------------------------------- + +int ResourceTypeQuery::getNumItems() const +{ + return m_numItems.getValue(); +} + +// ---------------------------------------------------------------------- + +void ResourceTypeQuery::clearData() +{ + m_resource_ids.clear(); + m_resource_names.clear(); + m_resource_classes.clear(); + m_attributes.clear(); + m_fractal_seeds.clear(); + m_depleted_timestamps.clear(); + + m_numItems=0; +} + +// ---------------------------------------------------------------------- + +void ResourceTypeQuery::freeData() +{ + m_resource_ids.free(); + m_resource_names.free(); + m_resource_classes.free(); + m_attributes.free(); + m_fractal_seeds.free(); + m_depleted_timestamps.free(); +} + +// ---------------------------------------------------------------------- + + +bool ResourceTypeQuery::bindParameters() +{ + if (!bindParameter(m_resource_ids)) return false; + if (!bindParameter(m_resource_names)) return false; + if (!bindParameter(m_resource_classes)) return false; + if (!bindParameter(m_attributes)) return false; + if (!bindParameter(m_fractal_seeds)) return false; + if (!bindParameter(m_depleted_timestamps)) return false; + if (!bindParameter(m_numItems)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool ResourceTypeQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +void ResourceTypeQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_resource_type (:resource_id, :resource_name, :resource_class, :attributes, :fractal_seeds, :depleted_timestamp, :chunk_size); end;"; +} + +// ====================================================================== + +ResourceTypeQuerySelect::ResourceTypeQuerySelect(const std::string &schema) : + m_data(ms_fetchBatchSize), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +bool ResourceTypeQuerySelect::bindParameters () +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool ResourceTypeQuerySelect::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ms_fetchBatchSize); + + if (!bindCol(m_data[0].resource_id)) return false; + if (!bindCol(m_data[0].resource_name)) return false; + if (!bindCol(m_data[0].resource_class)) return false; + if (!bindCol(m_data[0].attributes)) return false; + if (!bindCol(m_data[0].fractal_seeds)) return false; + if (!bindCol(m_data[0].depleted_timestamp)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +const std::vector & ResourceTypeQuerySelect::getData() const +{ + return m_data; +} + +// ---------------------------------------------------------------------- + +void ResourceTypeQuerySelect::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_resource_types; end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode ResourceTypeQuerySelect::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.h new file mode 100644 index 00000000..3a364ddf --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/ResourceTypeQuery.h @@ -0,0 +1,78 @@ +// ====================================================================== +// +// ResourceTypeQuery,h +// copyright (c) 2004 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_ResourceTypeQuery_H +#define INCLUDED_ResourceTypeQuery_H + +// ====================================================================== + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcessQuery.h" +#include "sharedDatabaseInterface/DbBindableVarray.h" + +#include + +// ====================================================================== + +namespace DBQuery +{ + class ResourceTypeQuery : public DB::Query + { + ResourceTypeQuery(const ResourceTypeQuery&); + ResourceTypeQuery& operator= (const ResourceTypeQuery&); + public: + ResourceTypeQuery(); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL(std::string &sql); + + bool setupData(DB::Session *session); + bool addData(DBSchema::ResourceTypeRow const & data); + void clearData(); + void freeData(); + + int getNumItems() const; + + private: + DB::BindableVarrayString m_resource_ids; + DB::BindableVarrayString m_resource_names; + DB::BindableVarrayString m_resource_classes; + DB::BindableVarrayString m_attributes; + DB::BindableVarrayString m_fractal_seeds; + DB::BindableVarrayNumber m_depleted_timestamps; + DB::BindableLong m_numItems; + }; + + + class ResourceTypeQuerySelect : public DB::Query + { + public: + ResourceTypeQuerySelect(const std::string &schema); + + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual void getSQL (std::string &sql); + + const std::vector & getData() const; + + protected: + virtual QueryMode getExecutionMode() const; + + private: + std::vector m_data; + const std::string m_schema; + + ResourceTypeQuerySelect (const ResourceTypeQuerySelect&); + ResourceTypeQuerySelect& operator= (const ResourceTypeQuerySelect&); + }; + +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/SkillQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/SkillQuery.cpp new file mode 100644 index 00000000..79b4276a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/SkillQuery.cpp @@ -0,0 +1,118 @@ +// ====================================================================== +// +// SkillQuery.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/SkillQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +using namespace DBQuery; + +// ====================================================================== + +SkillQuery::SkillQuery() : + ModeQuery(new DBSchema::SkillQueryData) //lint !e1524 // We don't delete the new row (base class does) +{ +} + +// ---------------------------------------------------------------------- + +bool SkillQuery::bindParameters() +{ + DBSchema::SkillQueryData *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!bindParameter(myData->object_id)) return false; + if (!bindParameter(myData->index)) return false; + if (!bindParameter(myData->operation)) return false; + if (!bindParameter(myData->skill)) return false; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + return true; +} + +bool SkillQuery::bindColumns() +{ + DBSchema::SkillQueryData *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + return true; +} + +// ---------------------------------------------------------------------- + +void SkillQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.update_skill (:object_id, :index, :operation, :skill); end;"; + break; + + case mode_SELECT: + default: + FATAL(true,("Bad query mode.")); + } +} + +// ---------------------------------------------------------------------- + +bool GetAllSkills::bindParameters() +{ + return true; +} + +bool GetAllSkills::bindColumns() +{ + if (!bindCol(m_data.object_id)) return false; + if (!bindCol(m_data.index)) return false; + if (!bindCol(m_data.skill)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +void GetAllSkills::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+DatabaseProcess::getInstance().getSchemaQualifier()+"loader.load_skills (); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode GetAllSkills::getExecutionMode() const +{ + DEBUG_FATAL (getProtocol()!=DB::PROTOCOL_OCI,("Skill persistance is not supported for PostgreSQL.\n")); + return (MODE_PLSQL_REFCURSOR); +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/SkillQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/SkillQuery.h new file mode 100644 index 00000000..04a457b4 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/SkillQuery.h @@ -0,0 +1,102 @@ +// ====================================================================== +// +// SkillQuery.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SkillQuery_H +#define INCLUDED_SkillQuery_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbModeQuery.h" + +// ====================================================================== + +namespace DBSchema +{ + struct SkillQueryData : public DB::Row + { + enum OperationType + { + ot_INSERT, + ot_DELETE, + ot_SET + }; + + DB::BindableNetworkId object_id; + DB::BindableLong index; + DB::BindableLong operation; + DB::BindableString<500> skill; //TODO: size + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + }; +} + +// ====================================================================== + +namespace DBQuery +{ + + class SkillQuery : public DB::ModeQuery + { + public: + SkillQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + + private: + SkillQuery(const SkillQuery&); // disable + SkillQuery& operator=(const SkillQuery&); // disable + }; + +// ---------------------------------------------------------------------- + + /** + * A query that gets all the attributes for an object. + */ + + class GetAllSkills : public DB::Query + { + public: + GetAllSkills(); + + const DBSchema::SkillQueryData &getData() const; + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode GetAllSkills::getExecutionMode() const; + + private: + GetAllSkills(const GetAllSkills&); // disable + GetAllSkills& operator=(const GetAllSkills&); // disable + + private: + DBSchema::SkillQueryData m_data; + }; +} + +// ====================================================================== + +inline const DBSchema::SkillQueryData &DBQuery::GetAllSkills::getData() const +{ + return m_data; +} + +// ---------------------------------------------------------------------- + +inline DBQuery::GetAllSkills::GetAllSkills() : Query(), m_data() +{ +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/WaypointQuery.cpp b/game/server/application/SwgDatabaseServer/src/shared/queries/WaypointQuery.cpp new file mode 100644 index 00000000..366be79b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/WaypointQuery.cpp @@ -0,0 +1,154 @@ +// ====================================================================== +// +// WaypointQuery.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "SwgDatabaseServer/WaypointQuery.h" + +#include "SwgDatabaseServer/Schema.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" + +// ====================================================================== + +using namespace DBQuery; + +// ====================================================================== + +WaypointQuery::WaypointQuery() : + ModeQuery(new DBSchema::WaypointRow) +{ +} + +// ---------------------------------------------------------------------- + +bool WaypointQuery::bindParameters() +{ + DBSchema::WaypointRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + if (!bindParameter(myData->object_id)) return false; + if (!bindParameter(myData->waypoint_id)) return false; + if (!bindParameter(myData->appearance_name_crc)) return false; + if (!bindParameter(myData->location_x)) return false; + if (!bindParameter(myData->location_y)) return false; + if (!bindParameter(myData->location_z)) return false; + if (!bindParameter(myData->location_cell)) return false; + if (!bindParameter(myData->location_scene)) return false; + if (!bindParameter(myData->name)) return false; + if (!bindParameter(myData->color)) return false; + if (!bindParameter(myData->active)) return false; + if (!bindParameter(myData->detached)) return false; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } + + return true; +} + +bool WaypointQuery::bindColumns() +{ + DBSchema::WaypointRow *myData=dynamic_cast(data); + NOT_NULL(myData); + + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } //lint !e788 //not all modes have an explicit case in the switch + + return true; +} + +// ---------------------------------------------------------------------- + +void WaypointQuery::getSQL(std::string &sql) +{ + switch(mode) + { + case mode_UPDATE: + case mode_INSERT: + sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_waypoint (:object_id,:waypoint_id,:appearance_name_crc,:location_x,:location_y,:location_z,:location_cell,:location_scene,:name,:color,:active,:detached); end;"; + break; + + case mode_SELECT: + default: + DEBUG_FATAL(true,("Bad query mode.")); + } +} + +// ====================================================================== + +DBQuery::GetAllWaypoints::GetAllWaypoints(const std::string &schema) : + Query(), + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +bool GetAllWaypoints::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool GetAllWaypoints::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].object_id)) return false; + if (!bindCol(m_data[0].waypoint_id)) return false; + if (!bindCol(m_data[0].appearance_name_crc)) return false; + if (!bindCol(m_data[0].location_x)) return false; + if (!bindCol(m_data[0].location_y)) return false; + if (!bindCol(m_data[0].location_z)) return false; + if (!bindCol(m_data[0].location_cell)) return false; + if (!bindCol(m_data[0].location_scene)) return false; + if (!bindCol(m_data[0].name)) return false; + if (!bindCol(m_data[0].color)) return false; + if (!bindCol(m_data[0].active)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void GetAllWaypoints::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+m_schema+"loader.load_waypoint(); end;"; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode GetAllWaypoints::getExecutionMode() const +{ + if (getProtocol()==DB::PROTOCOL_OCI) + return (MODE_PLSQL_REFCURSOR); + else + { + FATAL(true,("ODBC mode is not supported for Waypoint\n")); + return MODE_SQL; // return to avoid compiler warning + } +} + + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/queries/WaypointQuery.h b/game/server/application/SwgDatabaseServer/src/shared/queries/WaypointQuery.h new file mode 100644 index 00000000..6b8649a5 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/queries/WaypointQuery.h @@ -0,0 +1,66 @@ +// ====================================================================== +// +// WaypointQuery.h +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_WaypointQuery_H +#define INCLUDED_WaypointQuery_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbModeQuery.h" +#include "SwgDatabaseServer/Schema.h" +#include + +// ====================================================================== + +namespace DBQuery +{ + + class WaypointQuery : public DB::ModeQuery + { + WaypointQuery(const WaypointQuery&); // disable + WaypointQuery& operator=(const WaypointQuery&); // disable + public: + WaypointQuery(); + + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + }; + +// ---------------------------------------------------------------------- + + class GetAllWaypoints : public DB::Query + { + public: + GetAllWaypoints(const std::string &schema); + + const std::vector &getData() const; + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual void getSQL(std::string &sql); + virtual QueryMode getExecutionMode() const; + + private: + GetAllWaypoints(const GetAllWaypoints&); // disable + GetAllWaypoints& operator=(const GetAllWaypoints&); // disable + + private: + std::vector m_data; + const std::string m_schema; + }; +} + +// ====================================================================== + +inline const std::vector & DBQuery::GetAllWaypoints::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionAttributeList.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionAttributeList.cpp new file mode 100644 index 00000000..5a353f7e --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionAttributeList.cpp @@ -0,0 +1,122 @@ +// ====================================================================== +// +// TaskGetAuctionAttributeList.cpp +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskGetAuctionAttributeList.h" +#include "utf8.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "SwgDatabaseServer/CMLoader.h" + +// ====================================================================== + +TaskGetAuctionAttributeList::TaskGetAuctionAttributeList () : + TaskRequest(), + count(0) +{ + +} + +// ---------------------------------------------------------------------- + +bool TaskGetAuctionAttributeList::process(DB::Session *session) +{ + time_t startTime = ::time(0); + GetAuctionAttributesQuery qry; + + if (! (session->exec(&qry))) + return false; + + int rowsFetched; + int numRows; + int currentCount; + NetworkId item; + std::string attributeName; + Unicode::String attributeValue; + + while ((rowsFetched = qry.fetch()) > 0) + { + numRows = qry.getNumRowsFetched(); + currentCount = 0; + + CMLoader::getInstance().lockMutex(); + for (std::vector::const_iterator i = qry.m_data.begin(); i != qry.m_data.end(); ++i) + { + if (++currentCount > numRows) + break; + + count++; + i->item_id.getValue(item); + i->attribute_name.getValue(attributeName); + i->attribute_value.getValue(attributeValue); + CMLoader::getInstance().addMarketAuctionAttributesNoLockMutex(item,attributeName,attributeValue); + } + CMLoader::getInstance().unlockMutex(); + } + + qry.done(); + + REPORT_LOG(true, ("[Commodities Server] : %d auction attributes loaded to memory from database in (%d) seconds.\n", count, static_cast(::time(0) - startTime))); + if (rowsFetched < 0) + return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void TaskGetAuctionAttributeList::onComplete() +{ + CMLoader::getInstance().onLoadComplete("MARKET_AUCTION_ATTRIBUTES", count); +} + +// ====================================================================== + +TaskGetAuctionAttributeList::GetAuctionAttributesQuery::GetAuctionAttributesQuery() : + Query(), + m_data(ConfigServerDatabase::getAuctionAttributeLoadBatchSize()) +{ +} + +// ---------------------------------------------------------------------- + +void TaskGetAuctionAttributeList::GetAuctionAttributesQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+DatabaseProcess::getInstance().getSchemaQualifier()+"cm_loader.get_auction_attributes(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskGetAuctionAttributeList::GetAuctionAttributesQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskGetAuctionAttributeList::GetAuctionAttributesQuery::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ConfigServerDatabase::getAuctionAttributeLoadBatchSize()); + + if (!bindCol(m_data[0].item_id)) return false; + if (!bindCol(m_data[0].attribute_name)) return false; + if (!bindCol(m_data[0].attribute_value)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskGetAuctionAttributeList::GetAuctionAttributesQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionAttributeList.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionAttributeList.h new file mode 100644 index 00000000..e3a2536d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionAttributeList.h @@ -0,0 +1,73 @@ +// ====================================================================== +// +// TaskGetAuctionAttributeList.h +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// ====================================================================== + +#ifndef INCLUDED_TaskGetAuctionAttributeList_H +#define INCLUDED_TaskGetAuctionAttributeList_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbRow.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include + +// ====================================================================== + +namespace DBSchema +{ + struct AuctionAttributeRow : public DB::Row + { + DB::BindableNetworkId item_id; + DB::BindableString<1000> attribute_name; + DB::BindableUnicode<1000> attribute_value; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + }; +} + +// ====================================================================== + +class TaskGetAuctionAttributeList : public DB::TaskRequest +{ + public: + TaskGetAuctionAttributeList (); + + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + + class GetAuctionAttributesQuery : public DB::Query + { + public: + std::vector m_data; + + GetAuctionAttributesQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: //disable + GetAuctionAttributesQuery(const GetAuctionAttributesQuery&); + GetAuctionAttributesQuery& operator=(const GetAuctionAttributesQuery&); + }; + + int count; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionList.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionList.cpp new file mode 100644 index 00000000..0500326c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionList.cpp @@ -0,0 +1,148 @@ +// ====================================================================== +// +// TaskGetAuctionList.cpp +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// This task has a special decoding function for loading out of band +// data(OOB) from the database. This is the only place OOB is loaded. +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskGetAuctionList.h" +#include "utf8.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "serverDatabase/dBAuctionRecord.h" +#include "SwgDatabaseServer/CMLoader.h" + +// ====================================================================== + +TaskGetAuctionList::TaskGetAuctionList () : + TaskRequest(), + count(0) +{ + +} + +// ---------------------------------------------------------------------- + +bool TaskGetAuctionList::process(DB::Session *session) +{ + time_t startTime = ::time(0); + GetAuctionsQuery qry; + + if (! (session->exec(&qry))) + return false; + + int rowsFetched; + int numRows; + int currentCount; + AuctionRecord temp; + + while ((rowsFetched = qry.fetch()) > 0) + { + numRows = qry.getNumRowsFetched(); + currentCount = 0; + + CMLoader::getInstance().lockMutex(); + for (std::vector::const_iterator i = qry.m_data.begin(); i != qry.m_data.end(); ++i) + { + if (++currentCount > numRows) + break; + + count++; + i->creatorId.getValue(temp.m_creatorId); + i->minBid.getValue(temp.m_minBid); + i->auctionTimer.getValue(temp.m_auctionTimer); + i->buyNowPrice.getValue(temp.m_buyNowPrice); + i->userDescription.getValue(temp.m_userDescription); + i->oob.getValue(temp.m_oob); + i->locationId.getValue(temp.m_locationId); + i->itemId.getValue(temp.m_itemId); + i->category.getValue(temp.m_category); + i->itemTimer.getValue(temp.m_itemTimer); + i->itemName.getValue(temp.m_itemName); + i->ownerId.getValue(temp.m_ownerId); + i->active.getValue(temp.m_active); + i->itemSize.getValue(temp.m_itemSize); + i->itemTemplateId.getValue(temp.m_itemTemplateId); + CMLoader::getInstance().addMarketAuctionsNoLockMutex(temp); + } + CMLoader::getInstance().unlockMutex(); + } + + qry.done(); + + REPORT_LOG(true, ("[Commodities Server] : %d auctions loaded to memory from database in (%d) seconds.\n", count, static_cast(::time(0) - startTime))); + if (rowsFetched < 0) + return false; + + return true; +} + +// ---------------------------------------------------------------------- + +void TaskGetAuctionList::onComplete() +{ + CMLoader::getInstance().onLoadComplete("MARKET_AUCTIONS", count); +} + +// ====================================================================== + +TaskGetAuctionList::GetAuctionsQuery::GetAuctionsQuery() : + Query(), + m_data(ConfigServerDatabase::getAuctionLoadBatchSize()) +{ +} + +// ---------------------------------------------------------------------- + +void TaskGetAuctionList::GetAuctionsQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+DatabaseProcess::getInstance().getSchemaQualifier()+"cm_loader.get_auction_list(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskGetAuctionList::GetAuctionsQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskGetAuctionList::GetAuctionsQuery::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ConfigServerDatabase::getAuctionLoadBatchSize()); + + if (!bindCol(m_data[0].creatorId)) return false; + if (!bindCol(m_data[0].minBid)) return false; + if (!bindCol(m_data[0].auctionTimer)) return false; + if (!bindCol(m_data[0].buyNowPrice)) return false; + if (!bindCol(m_data[0].userDescription)) return false; + if (!bindCol(m_data[0].oob)) return false; + if (!bindCol(m_data[0].locationId)) return false; + if (!bindCol(m_data[0].itemId)) return false; + if (!bindCol(m_data[0].category)) return false; + if (!bindCol(m_data[0].itemTimer)) return false; + if (!bindCol(m_data[0].itemName)) return false; + if (!bindCol(m_data[0].ownerId)) return false; + if (!bindCol(m_data[0].active)) return false; + if (!bindCol(m_data[0].itemSize)) return false; + if (!bindCol(m_data[0].itemTemplateId)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskGetAuctionList::GetAuctionsQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionList.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionList.h new file mode 100644 index 00000000..418710df --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetAuctionList.h @@ -0,0 +1,88 @@ +// ====================================================================== +// +// TaskGetAuctionList.h +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// This task has a special decoding function for loading out of band +// data(OOB) from the database. This is the only place OOB is loaded. +// +// ====================================================================== + +#ifndef INCLUDED_TaskGetAuctionList_H +#define INCLUDED_TaskGetAuctionList_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbRow.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include + +// ====================================================================== + +namespace DBSchema +{ + struct AuctionRow : public DB::Row + { + DB::BindableNetworkId creatorId; + DB::BindableLong minBid; + DB::BindableLong auctionTimer; + DB::BindableLong buyNowPrice; + DB::BindableUnicode<1024> userDescription; + DB::BindableString<4000> oob; + DB::BindableNetworkId locationId; + DB::BindableNetworkId itemId; + DB::BindableLong category; + DB::BindableLong itemTimer; + DB::BindableUnicode<1024> itemName; + DB::BindableNetworkId ownerId; + DB::BindableLong active; + DB::BindableLong itemSize; + DB::BindableLong itemTemplateId; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + }; +} + +// ====================================================================== + +class TaskGetAuctionList : public DB::TaskRequest +{ + public: + TaskGetAuctionList (); + + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + + class GetAuctionsQuery : public DB::Query + { + public: + std::vector m_data; + + GetAuctionsQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: //disable + GetAuctionsQuery(const GetAuctionsQuery&); + GetAuctionsQuery& operator=(const GetAuctionsQuery&); + }; + + int count; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetBidList.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetBidList.cpp new file mode 100644 index 00000000..9a736cd3 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetBidList.cpp @@ -0,0 +1,120 @@ +// ====================================================================== +// +// TaskGetBidList.cpp +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskGetBidList.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "serverDatabase/dBBidRecord.h" +#include "serverNetworkMessages/GetMarketAuctionBidsMessage.h" +#include "SwgDatabaseServer/CMLoader.h" + +// ====================================================================== + +TaskGetBidList::TaskGetBidList () : + TaskRequest(), + count(0) +{ + +} + +// ---------------------------------------------------------------------- + +bool TaskGetBidList::process(DB::Session *session) +{ + time_t startTime = ::time(0); + GetBidsQuery qry; + + if (! (session->exec(&qry))) + return false; + + int rowsFetched; + int numRows; + int currentCount; + BidRecord temp; + + while ((rowsFetched = qry.fetch()) > 0) + { + numRows = qry.getNumRowsFetched(); + currentCount = 0; + + CMLoader::getInstance().lockMutex(); + for (std::vector::const_iterator i = qry.m_data.begin(); i != qry.m_data.end(); ++i) + { + if (++currentCount > numRows) + break; + + count++; + i->itemId.getValue(temp.m_itemId); + i->bidderId.getValue(temp.m_bidderId); + i->bid.getValue(temp.m_bid); + i->maxProxyBid.getValue(temp.m_maxProxyBid); + CMLoader::getInstance().addMarketAuctionBidNoLockMutex(temp); + } + CMLoader::getInstance().unlockMutex(); + } + + qry.done(); + + REPORT_LOG(true, ("[Commodities Server] : %d bids loaded to memory from database in (%d) seconds.\n", count, static_cast(::time(0) - startTime))); + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +void TaskGetBidList::onComplete() +{ + CMLoader::getInstance().onLoadComplete("MARKET_AUCTION_BIDS", count); +} + +// ====================================================================== + +TaskGetBidList::GetBidsQuery::GetBidsQuery() : + Query(), + m_data(ConfigServerDatabase::getAuctionBidLoadBatchSize()) +{ +} + +// ---------------------------------------------------------------------- + +void TaskGetBidList::GetBidsQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+DatabaseProcess::getInstance().getSchemaQualifier()+"cm_loader.get_bid_list(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskGetBidList::GetBidsQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskGetBidList::GetBidsQuery::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ConfigServerDatabase::getAuctionBidLoadBatchSize()); + + if (!bindCol(m_data[0].itemId)) return false; + if (!bindCol(m_data[0].bidderId)) return false; + if (!bindCol(m_data[0].bid)) return false; + if (!bindCol(m_data[0].maxProxyBid)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskGetBidList::GetBidsQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetBidList.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetBidList.h new file mode 100644 index 00000000..021147a3 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetBidList.h @@ -0,0 +1,75 @@ +// ====================================================================== +// +// TaskGetBidList.h +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// ====================================================================== + +#ifndef INCLUDED_TaskGetBidList_H +#define INCLUDED_TaskGetBidList_H + +// ====================================================================== + +#include "serverDatabase/dBBidRecord.h" +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbRow.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include + +// ====================================================================== + +namespace DBSchema +{ + struct AuctionBidRow : public DB::Row + { + DB::BindableNetworkId itemId; + DB::BindableNetworkId bidderId; + DB::BindableLong bid; + DB::BindableLong maxProxyBid; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + }; +} + +// ====================================================================== + +class TaskGetBidList : public DB::TaskRequest +{ + public: + TaskGetBidList (); + + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + + class GetBidsQuery : public DB::Query + { + public: + std::vector m_data; + + GetBidsQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: //disable + GetBidsQuery(const GetBidsQuery&); + GetBidsQuery& operator=(const GetBidsQuery&); + }; + + int count; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetCharacters.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetCharacters.cpp new file mode 100644 index 00000000..8b673f37 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetCharacters.cpp @@ -0,0 +1,81 @@ +// TaskGetCharacters.cpp +// copyright 2001 Verant Interactive +// Author: Calan Thurow + +//----------------------------------------------------------------------- + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskGetCharacters.h" + +#include "Unicode.h" +#include "serverDatabase/CharacterQueries.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverNetworkMessages/CharacterListMessage.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "unicodeArchive/UnicodeArchive.h" + +//----------------------------------------------------------------------- + +TaskGetCharacters::TaskGetCharacters(uint32 stationId) : + TaskRequest(), + m_stationId(stationId) +{ +} + +//----------------------------------------------------------------------- + +TaskGetCharacters::~TaskGetCharacters() +{ + for (CharactersType::iterator i=characters.begin(); i!=characters.end(); ++i) + { + delete *i; + } +} + +//----------------------------------------------------------------------- + +bool TaskGetCharacters::process(DB::Session *session) +{ + int rowsFetched; + DBQuery::GetCharacters qry; + + qry.setStationId(m_stationId); //lint !e713 //loss of precision ok //@todo check this + + if (! (session->exec(&qry))) + return false; + + while ((rowsFetched = qry.fetch()) > 0) + { + CharacterRec *cr=new CharacterRec; + + NOT_NULL(cr); + + cr->characterName = qry.getData().character_name.getValue(); + cr->characterId = NetworkId(qry.getData().object_id.getValue()); + cr->location = Unicode::wideToNarrow(qry.getData().scene_id.getValue()); + cr->objectTemplate = Unicode::wideToNarrow(qry.getData().object_template.getValue()); + cr->containerId = qry.getData().container_id.getValue(); + cr->x = static_cast(qry.getData().x.getValue()); + cr->y = static_cast(qry.getData().y.getValue()); + cr->z = static_cast(qry.getData().z.getValue()); + characters.push_back(cr); + } + + qry.done(); + return (rowsFetched >= 0); +} + +//----------------------------------------------------------------------- + +void TaskGetCharacters::onComplete() +{ + std::vector charlist; + for(CharactersType::iterator i = characters.begin(); i != characters.end(); ++i) + { + charlist.push_back(CharacterListMessageData((*i)->characterName, (*i)->objectTemplate, (*i)->characterId, (*i)->containerId, (*i)->location, Vector((*i)->x,(*i)->y,(*i)->z))); + } + CharacterListMessage msg(m_stationId, charlist); + DatabaseProcess::getInstance().sendToCentralServer(msg,true); +} + +//----------------------------------------------------------------------- diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetCharacters.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetCharacters.h new file mode 100644 index 00000000..ceabcbe2 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetCharacters.h @@ -0,0 +1,57 @@ +// ====================================================================== +// +// TaskGetCharacters.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskGetCharacters_H +#define INCLUDED_TaskGetCharacters_H + +// ====================================================================== + +#include + +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedFoundation/NetworkId.h" +#include "Unicode.h" + +//----------------------------------------------------------------------- + +class TaskGetCharacters:public DB::TaskRequest +{ + public: + struct CharacterRec + { + Unicode::String characterName; + std::string location; + std::string objectTemplate; + NetworkId characterId; + NetworkId containerId; + real x; + real y; + real z; + }; + + typedef std::vector CharactersType; + + TaskGetCharacters(uint32 stationId); + virtual ~TaskGetCharacters(); + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + protected: + CharactersType characters; + + private: + uint32 m_stationId; + + TaskGetCharacters(); + TaskGetCharacters(const TaskGetCharacters&); + TaskGetCharacters& operator=(const TaskGetCharacters& rhs); +}; + +//----------------------------------------------------------------------- + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetLocationList.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetLocationList.cpp new file mode 100644 index 00000000..ad50131b --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetLocationList.cpp @@ -0,0 +1,134 @@ +// ====================================================================== +// +// TaskGetLocationList.cpp +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskGetLocationList.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "serverDatabase/dBLocationRecord.h" +#include "serverNetworkMessages/GetAuctionLocationsMessage.h" +#include "SwgDatabaseServer/CMLoader.h" + +// ====================================================================== + +TaskGetLocationList::TaskGetLocationList () : + TaskRequest(), + count(0) +{ + +} + +// ---------------------------------------------------------------------- + +bool TaskGetLocationList::process(DB::Session *session) +{ + time_t startTime = ::time(0); + GetLocationsQuery qry; + + if (! (session->exec(&qry))) + return false; + + int rowsFetched; + int numRows; + int currentCount; + LocationRecord temp; + + while ((rowsFetched = qry.fetch()) > 0) + { + numRows = qry.getNumRowsFetched(); + currentCount = 0; + + CMLoader::getInstance().lockMutex(); + for (std::vector::const_iterator i = qry.m_data.begin(); i != qry.m_data.end(); ++i) + { + if (++currentCount > numRows) + break; + + count++; + i->locationId.getValue(temp.m_locationId); + i->ownerId.getValue(temp.m_ownerId); + i->locationString.getValue(temp.m_locationString); + i->salesTax.getValue(temp.m_salesTax); + i->salesTaxBankId.getValue(temp.m_salesTaxBankId); + i->emptyDate.getValue(temp.m_emptyDate); + i->lastAccessDate.getValue(temp.m_lastAccessDate); + i->inactiveDate.getValue(temp.m_inactiveDate); + i->status.getValue(temp.m_status); + i->searchEnabled.getValue(temp.m_searchEnabled); + i->entranceCharge.getValue(temp.m_entranceCharge); + CMLoader::getInstance().addAuctionLocationNoLockMutex(temp); + } + CMLoader::getInstance().unlockMutex(); + } + + qry.done(); + + REPORT_LOG(true, ("[Commodities Server] : %d locations loaded to memory from database in (%d) seconds.\n", count, static_cast(::time(0) - startTime))); + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +void TaskGetLocationList::onComplete() +{ + CMLoader::getInstance().onLoadComplete("AUCTION_LOCATIONS", count); +} + +// ====================================================================== + +TaskGetLocationList::GetLocationsQuery::GetLocationsQuery() : + Query(), + m_data(ConfigServerDatabase::getAuctionLocationLoadBatchSize()) +{ +} + +// ---------------------------------------------------------------------- + +void TaskGetLocationList::GetLocationsQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ")+DatabaseProcess::getInstance().getSchemaQualifier()+"cm_loader.get_location_list(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskGetLocationList::GetLocationsQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskGetLocationList::GetLocationsQuery::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, ConfigServerDatabase::getAuctionLocationLoadBatchSize()); + + if (!bindCol(m_data[0].locationId)) return false; + if (!bindCol(m_data[0].ownerId)) return false; + if (!bindCol(m_data[0].locationString)) return false; + if (!bindCol(m_data[0].salesTax)) return false; + if (!bindCol(m_data[0].salesTaxBankId)) return false; + if (!bindCol(m_data[0].emptyDate)) return false; + if (!bindCol(m_data[0].lastAccessDate)) return false; + if (!bindCol(m_data[0].inactiveDate)) return false; + if (!bindCol(m_data[0].status)) return false; + if (!bindCol(m_data[0].searchEnabled)) return false; + if (!bindCol(m_data[0].entranceCharge)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskGetLocationList::GetLocationsQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetLocationList.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetLocationList.h new file mode 100644 index 00000000..4529ad90 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskGetLocationList.h @@ -0,0 +1,82 @@ +// ====================================================================== +// +// TaskGetLocationList.h +// copyright (c) 2004 Sony Online Entertainment +// Author: Doug Mellencamp +// +// ====================================================================== + +#ifndef INCLUDED_TaskGetLocationList_H +#define INCLUDED_TaskGetLocationList_H + +// ====================================================================== + +#include "serverDatabase/dBLocationRecord.h" +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbRow.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include + +// ====================================================================== + +namespace DBSchema +{ + struct AuctionLocationRow : public DB::Row + { + DB::BindableNetworkId locationId; + DB::BindableNetworkId ownerId; + DB::BindableString<256> locationString; + DB::BindableLong salesTax; + DB::BindableNetworkId salesTaxBankId; + DB::BindableLong emptyDate; + DB::BindableLong lastAccessDate; + DB::BindableLong inactiveDate; + DB::BindableLong status; + DB::BindableBool searchEnabled; + DB::BindableLong entranceCharge; + + virtual void copy(const DB::Row &rhs) + { + *this = dynamic_cast(rhs); + } + }; +} + +// ====================================================================== + +class TaskGetLocationList : public DB::TaskRequest +{ + public: + explicit TaskGetLocationList (); + + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + + class GetLocationsQuery : public DB::Query + { + public: + std::vector m_data; + + GetLocationsQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + private: //disable + GetLocationsQuery(const GetLocationsQuery&); + GetLocationsQuery& operator=(const GetLocationsQuery&); + }; + + int count; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLoadObjvarNames.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLoadObjvarNames.cpp new file mode 100644 index 00000000..4e9c1af0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLoadObjvarNames.cpp @@ -0,0 +1,138 @@ +// ====================================================================== +// +// TaskLoadObjvarNames.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskLoadObjvarNames.h" + +#include "SwgDatabaseServer/ObjvarNameManager.h" +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverDatabase/Loader.h" +#include "sharedDatabaseInterface/DbSession.h" + + +volatile int TaskLoadObjvarNames::m_sObjvarNamesCount = 0; +volatile int TaskLoadObjvarNames::m_sGoldObjvarNamesCount = 0; + +// ====================================================================== + +bool TaskLoadObjvarNames::process(DB::Session *session) +{ + int rowsFetched = 0; + { + ObjvarNameQuery qry(DatabaseProcess::getInstance().getSchemaQualifier()); + if (! (session->exec(&qry))) + return false; + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + m_objvarNames.push_back(std::make_pair(i->name_id.getValue(), i->name.getValueASCII())); + ++m_sObjvarNamesCount; + } + } + } + + if (rowsFetched < 0) + return false; + if (ConfigServerDatabase::getEnableGoldDatabase()) + { + ObjvarNameQuery qry(DatabaseProcess::getInstance().getGoldSchemaQualifier()); + if (! (session->exec(&qry))) + return false; + while ((rowsFetched = qry.fetch()) > 0) + { + size_t numRows = qry.getNumRowsFetched(); + size_t count = 0; + const std::vector &data = qry.getData(); + + for (std::vector::const_iterator i=data.begin(); i!=data.end(); ++i) + { + if (++count > numRows) + break; + + m_goldObjvarNames.push_back(std::make_pair(i->name_id.getValue(), i->name.getValueASCII())); + ++m_sGoldObjvarNamesCount; + } + } + } + return (rowsFetched >= 0); +} + +// ---------------------------------------------------------------------- + +void TaskLoadObjvarNames::onComplete() +{ + { + for (std::vector >::const_iterator i=m_objvarNames.begin(); i!=m_objvarNames.end(); ++i) + { + ObjvarNameManager::getInstance().addNameMapping(i->first, i->second); + } + ObjvarNameManager::getInstance().allNamesLoaded(); + } + + if (ConfigServerDatabase::getEnableGoldDatabase()) + { + for (std::vector >::const_iterator i=m_goldObjvarNames.begin(); i!=m_goldObjvarNames.end(); ++i) + { + ObjvarNameManager::getGoldInstance().addNameMapping(i->first, i->second); + } + ObjvarNameManager::getGoldInstance().allNamesLoaded(); + } + + Loader::getInstance().startupLoadCompleted(); // Currently objvar names are the only startup data loaded. +} + +// ====================================================================== + +TaskLoadObjvarNames::ObjvarNameQuery::ObjvarNameQuery(const std::string &schema) : + m_data(ConfigServerDatabase::getDefaultFetchBatchSize()), + m_schema(schema) +{ +} + +// ---------------------------------------------------------------------- + +void TaskLoadObjvarNames::ObjvarNameQuery::getSQL(std::string &sql) +{ + sql="begin :result := "+m_schema+"objvar_names.get_name_list(); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskLoadObjvarNames::ObjvarNameQuery::bindParameters() +{ + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskLoadObjvarNames::ObjvarNameQuery::bindColumns() +{ + size_t skipSize = reinterpret_cast(&(m_data[1])) - reinterpret_cast(&(m_data[0])); + setColArrayMode(skipSize, m_data.size()); + + if (!bindCol(m_data[0].name_id)) return false; + if (!bindCol(m_data[0].name)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskLoadObjvarNames::ObjvarNameQuery::getExecutionMode() const +{ + return MODE_PLSQL_REFCURSOR; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLoadObjvarNames.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLoadObjvarNames.h new file mode 100644 index 00000000..0c85a1d0 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLoadObjvarNames.h @@ -0,0 +1,77 @@ +// ====================================================================== +// +// TaskLoadObjvarNames.h +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskLoadObjvarNames_H +#define INCLUDED_TaskLoadObjvarNames_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include + +// ====================================================================== + +class TaskLoadObjvarNames : public DB::TaskRequest +{ + public: + virtual bool process (DB::Session *session); + virtual void onComplete (); + + static int getObjvarNamesCount() { return m_sObjvarNamesCount; } + static int getGoldObjvarNamesCount() { return m_sGoldObjvarNamesCount; } + + private: + struct ObjvarNameRow + { + DB::BindableLong name_id; + DB::BindableString<500> name; + }; + + class ObjvarNameQuery : public DB::Query + { + public: + ObjvarNameQuery(const std::string &schema); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + const std::vector & getData() const; + + private: + + std::vector m_data; + std::string m_schema; + + private: + ObjvarNameQuery(const ObjvarNameQuery&); + ObjvarNameQuery& operator=(const ObjvarNameQuery&); + }; + + private: + std::vector > m_objvarNames; + std::vector > m_goldObjvarNames; + + + static volatile int m_sObjvarNamesCount; + static volatile int m_sGoldObjvarNamesCount; + +}; + +// ====================================================================== + +inline const std::vector & TaskLoadObjvarNames::ObjvarNameQuery::getData() const +{ + return m_data; +} + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLocateStructure.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLocateStructure.cpp new file mode 100644 index 00000000..1bafa34a --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLocateStructure.cpp @@ -0,0 +1,116 @@ +// ====================================================================== +// +// TaskLocateStructure.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskLocateStructure.h" + +#include "SwgLoader.h" +#include "Unicode.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverNetworkMessages/LocateStructureMessage.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include "sharedNetworkMessages/GenericValueTypeMessage.h" + +// ====================================================================== + +TaskLocateStructure::TaskLocateStructure(const NetworkId &itemId, const std::string &whoRequested) : + TaskRequest(), + m_itemId(itemId), + m_whoRequested(whoRequested) +{ +} + +//----------------------------------------------------------------------- + +TaskLocateStructure::~TaskLocateStructure() +{ +} + +//----------------------------------------------------------------------- + +bool TaskLocateStructure::process(DB::Session *session) +{ + LocateStructureQuery query; + query.item_id = m_itemId; + + if (! (session->exec(&query))) + return false; + query.done(); + + m_found = query.found.getValue(); + if (m_found) + { + m_x = query.x.getValue(); + m_z = query.z.getValue(); + m_sceneId = query.sceneId.getValueASCII(); + } + + LOG("CustomerService", ("playerStructure: Locate structure (%s): result %s", m_itemId.getValueString().c_str(), (m_found? "found": "not found"))); + return true; +} + +//----------------------------------------------------------------------- + +void TaskLocateStructure::onComplete() +{ + std::string message; + if (m_found) + { + LocateStructureMessage lsm(m_itemId, m_x, m_z, m_sceneId, m_whoRequested); + DatabaseProcess::getInstance().sendToAnyGameServer(lsm); + } + else + { + message = "Could not find object " + m_itemId.getValueString() + " in database"; + GenericValueTypeMessage > reply("DatabaseConsoleReplyMessage", + std::make_pair(m_whoRequested, message)); + DatabaseProcess::getInstance().sendToAnyGameServer(reply); + } +} + +// ====================================================================== + +void TaskLocateStructure::LocateStructureQuery::getSQL(std::string &sql) +{ + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier()+"loader.locate_structure(:item_id, :x, :z, :scene_id, :found); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskLocateStructure::LocateStructureQuery::bindParameters() +{ + if (!bindParameter(item_id)) return false; + if (!bindParameter(x)) return false; + if (!bindParameter(z)) return false; + if (!bindParameter(sceneId)) return false; + if (!bindParameter(found)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskLocateStructure::LocateStructureQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskLocateStructure::LocateStructureQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +TaskLocateStructure::LocateStructureQuery::LocateStructureQuery() +{ +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLocateStructure.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLocateStructure.h new file mode 100644 index 00000000..9723fe22 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskLocateStructure.h @@ -0,0 +1,71 @@ +// ====================================================================== +// +// TaskLocateStructure.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskLocateStructure_H +#define INCLUDED_TaskLocateStructure_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" + +//----------------------------------------------------------------------- + +class TaskLocateStructure:public DB::TaskRequest +{ + public: + TaskLocateStructure(const NetworkId &itemId, const std::string &whoRequested); + virtual ~TaskLocateStructure(); + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class LocateStructureQuery : public DB::Query + { + public: + LocateStructureQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + public: + // input: + DB::BindableNetworkId item_id; + + //output: + DB::BindableLong x; + DB::BindableLong z; + DB::BindableString<50> sceneId; + DB::BindableLong found; + + private: + LocateStructureQuery(const LocateStructureQuery&); + LocateStructureQuery& operator=(const LocateStructureQuery&); + }; + + private: + NetworkId m_itemId; + int m_x; + int m_z; + std::string m_sceneId; + int m_found; + std::string m_whoRequested; + + private: + //Disabled: + TaskLocateStructure(const TaskLocateStructure&); + TaskLocateStructure& operator=(const TaskLocateStructure& rhs); +}; + +//----------------------------------------------------------------------- + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskMoveToPlayer.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskMoveToPlayer.cpp new file mode 100644 index 00000000..529feb79 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskMoveToPlayer.cpp @@ -0,0 +1,175 @@ +// ====================================================================== +// +// TaskMoveToPlayer.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskMoveToPlayer.h" + +#include "SwgLoader.h" +#include "Unicode.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include "sharedNetworkMessages/GenericValueTypeMessage.h" + +// ====================================================================== + +TaskMoveToPlayer::TaskMoveToPlayer(const NetworkId &oid, const NetworkId &player, const std::string &whoRequested) : + TaskRequest(), + m_oid(oid), + m_player(player), + m_whoRequested(whoRequested) +{ +} + +//----------------------------------------------------------------------- + +TaskMoveToPlayer::~TaskMoveToPlayer() +{ +} + +//----------------------------------------------------------------------- + +bool TaskMoveToPlayer::process(DB::Session *session) +{ + MoveToPlayerQuery query; + query.oid = m_oid; + query.player = m_player; + + if (! (session->exec(&query))) + return false; + query.done(); + + m_result = query.result.getValue(); + + LOG("DatabaseRestore", ("Move Item (%s) to Player (%s): result %i", m_oid.getValueString().c_str(), m_player.getValueString().c_str(), m_result)); + return true; +} + +//----------------------------------------------------------------------- + +void TaskMoveToPlayer::onComplete() +{ + std::string message; + switch (m_result) + { + case 1: + message = "Item moved. (It may not reappear until the next server restart.)"; + break; + + case 2: + message = "Could not find player's inventory"; + break; + + case 3: + message = "Object id does not exist"; + break; + + case 4: + message = "The database returned an unknown error code"; + break; + + case 5: + message = "Object id cannot be a player"; + break; + + case 6: + message = "Object id cannot be object/tangible/inventory/character_inventory.iff"; + break; + + case 7: + message = "Object id cannot be object/tangible/mission_bag/mission_bag.iff"; + break; + + case 8: + message = "Object id cannot be object/tangible/datapad/character_datapad.iff"; + break; + + case 9: + message = "Object id cannot be object/tangible/bank/character_bank.iff"; + break; + + case 10: + message = "Object id cannot be object/weapon/melee/unarmed/unarmed_default_player.iff"; + break; + + case 11: + message = "Object id cannot be object/player/player.iff"; + break; + + case 12: + message = "Object id cannot be object/cell/cell.iff"; + break; + + case 13: + message = "Object id cannot be object/tangible/inventory/vendor_inventory.iff"; + break; + + case 14: + message = "Object cannot be contained directly by a datapad"; + break; + + case 15: + message = "Object cannot be a building"; + break; + + case 16: + message = "Object cannot be an installation"; + break; + + case 17: + message = "Object cannot be a ship"; + break; + + default: + message = "admin.move_item_to_player() returned an unknown error code"; + break; + } + + GenericValueTypeMessage > reply("DatabaseConsoleReplyMessage", + std::make_pair(m_whoRequested, message)); + DatabaseProcess::getInstance().sendToAnyGameServer(reply); +} + +// ====================================================================== + +void TaskMoveToPlayer::MoveToPlayerQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ") + DatabaseProcess::getInstance().getSchemaQualifier()+"admin.move_item_to_player (:item_id, :player_id); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskMoveToPlayer::MoveToPlayerQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + if (!bindParameter(oid)) return false; + if (!bindParameter(player)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskMoveToPlayer::MoveToPlayerQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskMoveToPlayer::MoveToPlayerQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +TaskMoveToPlayer::MoveToPlayerQuery::MoveToPlayerQuery() +{ +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskMoveToPlayer.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskMoveToPlayer.h new file mode 100644 index 00000000..9d1ccc69 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskMoveToPlayer.h @@ -0,0 +1,67 @@ +// ====================================================================== +// +// TaskMoveToPlayer.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskMoveToPlayer_H +#define INCLUDED_TaskMoveToPlayer_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" + +//----------------------------------------------------------------------- + +class TaskMoveToPlayer:public DB::TaskRequest +{ + public: + TaskMoveToPlayer(const NetworkId &oid, const NetworkId &player, const std::string &whoRequested); + virtual ~TaskMoveToPlayer(); + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class MoveToPlayerQuery : public DB::Query + { + public: + MoveToPlayerQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + public: + // input: + DB::BindableNetworkId oid; + DB::BindableNetworkId player; + + //output: + DB::BindableLong result; + + private: + MoveToPlayerQuery(const MoveToPlayerQuery&); + MoveToPlayerQuery& operator=(const MoveToPlayerQuery&); + }; + + private: + NetworkId m_oid; + NetworkId m_player; + std::string m_whoRequested; + int m_result; + + private: + //Disabled: + TaskMoveToPlayer(const TaskMoveToPlayer&); + TaskMoveToPlayer& operator=(const TaskMoveToPlayer& rhs); +}; + +//----------------------------------------------------------------------- + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreCharacter.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreCharacter.cpp new file mode 100644 index 00000000..863c7004 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreCharacter.cpp @@ -0,0 +1,126 @@ +// ====================================================================== +// +// TaskRestoreCharacter.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskRestoreCharacter.h" + +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include "sharedNetworkMessages/GenericValueTypeMessage.h" +#include "serverNetworkMessages/LoginRestoreCharacterMessage.h" +#include "unicodeArchive/UnicodeArchive.h" + +// ====================================================================== + +TaskRestoreCharacter::TaskRestoreCharacter(const NetworkId &characterId, const std::string &whoRequested) : + TaskRequest(), + m_characterId(characterId), + m_whoRequested(whoRequested) +{ +} + +//----------------------------------------------------------------------- + +TaskRestoreCharacter::~TaskRestoreCharacter() +{ +} + +//----------------------------------------------------------------------- + +bool TaskRestoreCharacter::process(DB::Session *session) +{ + RestoreCharacterQuery query; + query.character_id = m_characterId; + + if (! (session->exec(&query))) + return false; + query.done(); + + query.result.getValue(m_result); + query.character_name.getValue(m_characterName); + query.account.getValue(m_account); + query.template_id.getValue(m_templateId); + + LOG("DatabaseRestore", ("Restore Character (%s): result %i", m_characterId.getValueString().c_str(), m_result)); + return true; +} + +//----------------------------------------------------------------------- + +void TaskRestoreCharacter::onComplete() +{ + if (m_result==1) + { + LoginRestoreCharacterMessage msg(m_whoRequested, m_characterId, m_account, m_characterName, m_templateId, false); //TODO: "/restoreJedi" command + DatabaseProcess::getInstance().sendToCentralServer(msg, true); + } + else + { + std::string message; + switch (m_result) + { + case 2: + message = "Object id was incorrect or character was not deleted"; + break; + + case 3: + message = "There was an error in the database while attempting to restore the character."; + break; + + default: + message = "The database returned an unknown code in response to the request to restore the character."; + break; + } + + GenericValueTypeMessage > reply("DatabaseConsoleReplyMessage", + std::make_pair(m_whoRequested, message)); + DatabaseProcess::getInstance().sendToAnyGameServer(reply); + } +} + +// ====================================================================== + +void TaskRestoreCharacter::RestoreCharacterQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ") + DatabaseProcess::getInstance().getSchemaQualifier()+"admin.restore_character (:character_id, :character_name, :account, :template_id); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskRestoreCharacter::RestoreCharacterQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + if (!bindParameter(character_id)) return false; + if (!bindParameter(character_name)) return false; + if (!bindParameter(account)) return false; + if (!bindParameter(template_id)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskRestoreCharacter::RestoreCharacterQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskRestoreCharacter::RestoreCharacterQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +TaskRestoreCharacter::RestoreCharacterQuery::RestoreCharacterQuery() +{ +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreCharacter.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreCharacter.h new file mode 100644 index 00000000..2e043f3d --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreCharacter.h @@ -0,0 +1,72 @@ +// ====================================================================== +// +// TaskRestoreCharacter.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskRestoreCharacter_H +#define INCLUDED_TaskRestoreCharacter_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedFoundation/StationId.h" + +//----------------------------------------------------------------------- + +class TaskRestoreCharacter:public DB::TaskRequest +{ + public: + TaskRestoreCharacter(const NetworkId &characterId, const std::string &whoRequested); + virtual ~TaskRestoreCharacter(); + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class RestoreCharacterQuery : public DB::Query + { + public: + RestoreCharacterQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + public: + // input: + DB::BindableNetworkId character_id; + + //output: + DB::BindableLong result; + DB::BindableString<127> character_name; + DB::BindableLong account; + DB::BindableLong template_id; + + private: + RestoreCharacterQuery(const RestoreCharacterQuery&); + RestoreCharacterQuery& operator=(const RestoreCharacterQuery&); + }; + + private: + NetworkId m_characterId; + std::string m_whoRequested; + int m_result; + Unicode::String m_characterName; + StationId m_account; + int m_templateId; + + private: + //Disabled: + TaskRestoreCharacter(const TaskRestoreCharacter&); + TaskRestoreCharacter& operator=(const TaskRestoreCharacter& rhs); +}; + +//----------------------------------------------------------------------- + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreHouse.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreHouse.cpp new file mode 100644 index 00000000..21457af1 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreHouse.cpp @@ -0,0 +1,116 @@ +// ====================================================================== +// +// TaskRestoreHouse.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskRestoreHouse.h" + +#include "SwgLoader.h" +#include "Unicode.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include "sharedNetworkMessages/GenericValueTypeMessage.h" + +// ====================================================================== + +TaskRestoreHouse::TaskRestoreHouse(const NetworkId &houseId, const std::string &whoRequested) : + TaskRequest(), + m_houseId(houseId), + m_whoRequested(whoRequested) +{ +} + +//----------------------------------------------------------------------- + +TaskRestoreHouse::~TaskRestoreHouse() +{ +} + +//----------------------------------------------------------------------- + +bool TaskRestoreHouse::process(DB::Session *session) +{ + RestoreHouseQuery query; + query.house_id = m_houseId; + + if (! (session->exec(&query))) + return false; + query.done(); + + m_result = query.result.getValue(); + + LOG("DatabaseRestore", ("Restore house (%s): result %i", m_houseId.getValueString().c_str(), m_result)); + return true; +} + +//----------------------------------------------------------------------- + +void TaskRestoreHouse::onComplete() +{ + std::string message; + switch (m_result) + { + case 1: + message = "House restored. (It may not reappear until the next server restart.)"; + break; + + case 2: + message = "Object id was incorrect or house was not deleted"; + break; + + case 3: + message = "There was an error in the database while attempting to restore the house."; + break; + + default: + message = "The database returned an unknown code in response to the request to restore the house."; + break; + } + + GenericValueTypeMessage > reply("DatabaseConsoleReplyMessage", + std::make_pair(m_whoRequested, message)); + DatabaseProcess::getInstance().sendToAnyGameServer(reply); +} + +// ====================================================================== + +void TaskRestoreHouse::RestoreHouseQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ") + DatabaseProcess::getInstance().getSchemaQualifier()+"admin.restore_house (:house_id); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskRestoreHouse::RestoreHouseQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + if (!bindParameter(house_id)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskRestoreHouse::RestoreHouseQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskRestoreHouse::RestoreHouseQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +TaskRestoreHouse::RestoreHouseQuery::RestoreHouseQuery() +{ +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreHouse.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreHouse.h new file mode 100644 index 00000000..8b04e6bd --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskRestoreHouse.h @@ -0,0 +1,65 @@ +// ====================================================================== +// +// TaskRestoreHouse.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskRestoreHouse_H +#define INCLUDED_TaskRestoreHouse_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" + +//----------------------------------------------------------------------- + +class TaskRestoreHouse:public DB::TaskRequest +{ + public: + TaskRestoreHouse(const NetworkId &houseId, const std::string &whoRequested); + virtual ~TaskRestoreHouse(); + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class RestoreHouseQuery : public DB::Query + { + public: + RestoreHouseQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + public: + // input: + DB::BindableNetworkId house_id; + + //output: + DB::BindableLong result; + + private: + RestoreHouseQuery(const RestoreHouseQuery&); + RestoreHouseQuery& operator=(const RestoreHouseQuery&); + }; + + private: + NetworkId m_houseId; + std::string m_whoRequested; + int m_result; + + private: + //Disabled: + TaskRestoreHouse(const TaskRestoreHouse&); + TaskRestoreHouse& operator=(const TaskRestoreHouse& rhs); +}; + +//----------------------------------------------------------------------- + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskSaveObjvarNames.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskSaveObjvarNames.cpp new file mode 100644 index 00000000..f30e0962 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskSaveObjvarNames.cpp @@ -0,0 +1,88 @@ +// ====================================================================== +// +// TaskSaveObjvarNames.cpp +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskSaveObjvarNames.h" + +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include + +// ====================================================================== + +TaskSaveObjvarNames::TaskSaveObjvarNames(const NameList &names) : + m_objvarNames(new NameList(names)) +{ +} + +// ---------------------------------------------------------------------- + +TaskSaveObjvarNames::~TaskSaveObjvarNames() +{ + delete m_objvarNames; + m_objvarNames=NULL; +} + +// ---------------------------------------------------------------------- + +bool TaskSaveObjvarNames::process(DB::Session *session) +{ + ObjvarNameQuery qry; + for (NameList::const_iterator i=m_objvarNames->begin(); i!=m_objvarNames->end(); ++i) + { + qry.name_id = i->first; + qry.name = i->second; + + if (! (session->exec(&qry))) + return false; + } + return true; +} + +// ---------------------------------------------------------------------- + +void TaskSaveObjvarNames::onComplete() +{ +} + +// ====================================================================== + +TaskSaveObjvarNames::ObjvarNameQuery::ObjvarNameQuery() +{ +} + +// ---------------------------------------------------------------------- + +void TaskSaveObjvarNames::ObjvarNameQuery::getSQL(std::string &sql) +{ + sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"objvar_names.add_name(:id, :name); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskSaveObjvarNames::ObjvarNameQuery::bindParameters() +{ + if (!bindParameter(name_id)) return false; + if (!bindParameter(name)) return false; + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskSaveObjvarNames::ObjvarNameQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskSaveObjvarNames::ObjvarNameQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskSaveObjvarNames.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskSaveObjvarNames.h new file mode 100644 index 00000000..432a64a9 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskSaveObjvarNames.h @@ -0,0 +1,56 @@ +// ====================================================================== +// +// TaskSaveObjvarNames.h +// copyright (c) 2003 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskSaveObjvarNames_H +#define INCLUDED_TaskSaveObjvarNames_H + +// ====================================================================== + +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/Bindable.h" + +// ====================================================================== + +class TaskSaveObjvarNames : public DB::TaskRequest +{ + public: + typedef stdvector >::fwd NameList; + + public: + TaskSaveObjvarNames (const NameList &names); + ~TaskSaveObjvarNames (); + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class ObjvarNameQuery : public DB::Query + { + public: + ObjvarNameQuery(); + + virtual void getSQL (std::string &sql); + virtual bool bindParameters (); + virtual bool bindColumns (); + virtual QueryMode getExecutionMode () const; + + public: + DB::BindableLong name_id; + DB::BindableString<500> name; + + private: + ObjvarNameQuery(const ObjvarNameQuery&); + ObjvarNameQuery& operator=(const ObjvarNameQuery&); + }; + + private: + NameList *m_objvarNames; +}; + +// ====================================================================== + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskUndeleteItem.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskUndeleteItem.cpp new file mode 100644 index 00000000..b81b3243 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskUndeleteItem.cpp @@ -0,0 +1,120 @@ +// ====================================================================== +// +// TaskUndeleteItem.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskUndeleteItem.h" + +#include "SwgLoader.h" +#include "Unicode.h" +#include "serverDatabase/DatabaseProcess.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedLog/Log.h" +#include "sharedNetworkMessages/GenericValueTypeMessage.h" + +// ====================================================================== + +TaskUndeleteItem::TaskUndeleteItem(const NetworkId &itemId, const std::string &whoRequested) : + TaskRequest(), + m_itemId(itemId), + m_whoRequested(whoRequested) +{ +} + +//----------------------------------------------------------------------- + +TaskUndeleteItem::~TaskUndeleteItem() +{ +} + +//----------------------------------------------------------------------- + +bool TaskUndeleteItem::process(DB::Session *session) +{ + UndeleteItemQuery query; + query.item_id = m_itemId; + + if (! (session->exec(&query))) + return false; + query.done(); + + m_result = query.result.getValue(); + + LOG("DatabaseRestore", ("Undelete Item (%s): result %i", m_itemId.getValueString().c_str(), m_result)); + return true; +} + +//----------------------------------------------------------------------- + +void TaskUndeleteItem::onComplete() +{ + std::string message; + switch (m_result) + { + case 1: + message = "Item restored."; + break; + + case 2: + message = "Object id was incorrect or item was not deleted"; + break; + + case 3: + message = "There was an error in the database while attempting to undelete the item."; + break; + case 4: + message = "Item restored. Loading this item from database..."; + Loader::getInstance().locateStructure(m_itemId, m_whoRequested); + break; + + default: + message = "The database returned an unknown code in response to the request to undelete the item."; + break; + } + + GenericValueTypeMessage > reply("DatabaseConsoleReplyMessage", + std::make_pair(m_whoRequested, message)); + DatabaseProcess::getInstance().sendToAnyGameServer(reply); +} + +// ====================================================================== + +void TaskUndeleteItem::UndeleteItemQuery::getSQL(std::string &sql) +{ + sql=std::string("begin :result := ") + DatabaseProcess::getInstance().getSchemaQualifier()+"admin.undelete_item (:item_id); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskUndeleteItem::UndeleteItemQuery::bindParameters() +{ + if (!bindParameter(result)) return false; + if (!bindParameter(item_id)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskUndeleteItem::UndeleteItemQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskUndeleteItem::UndeleteItemQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +TaskUndeleteItem::UndeleteItemQuery::UndeleteItemQuery() +{ +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskUndeleteItem.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskUndeleteItem.h new file mode 100644 index 00000000..c5d08f76 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskUndeleteItem.h @@ -0,0 +1,65 @@ +// ====================================================================== +// +// TaskUndeleteItem.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskUndeleteItem_H +#define INCLUDED_TaskUndeleteItem_H + +// ====================================================================== + +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" + +//----------------------------------------------------------------------- + +class TaskUndeleteItem:public DB::TaskRequest +{ + public: + TaskUndeleteItem(const NetworkId &itemId, const std::string &whoRequested); + virtual ~TaskUndeleteItem(); + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + private: + class UndeleteItemQuery : public DB::Query + { + public: + UndeleteItemQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + public: + // input: + DB::BindableNetworkId item_id; + + //output: + DB::BindableLong result; + + private: + UndeleteItemQuery(const UndeleteItemQuery&); + UndeleteItemQuery& operator=(const UndeleteItemQuery&); + }; + + private: + NetworkId m_itemId; + std::string m_whoRequested; + int m_result; + + private: + //Disabled: + TaskUndeleteItem(const TaskUndeleteItem&); + TaskUndeleteItem& operator=(const TaskUndeleteItem& rhs); +}; + +//----------------------------------------------------------------------- + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskVerifyCharacter.cpp b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskVerifyCharacter.cpp new file mode 100644 index 00000000..9f79f40c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskVerifyCharacter.cpp @@ -0,0 +1,233 @@ +// ====================================================================== +// +// TaskVerifyCharacter.cpp +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" +#include "TaskVerifyCharacter.h" + +#include "SwgLoader.h" +#include "Unicode.h" +#include "serverDatabase/CharacterQueries.h" +#include "serverDatabase/DatabaseProcess.h" +#include "serverNetworkMessages/CharacterListMessage.h" +#include "serverNetworkMessages/TransferCharacterData.h" +#include "serverNetworkMessages/TransferCharacterDataArchive.h" +#include "serverNetworkMessages/ValidateCharacterForLoginReplyMessage.h" +#include "sharedDatabaseInterface/DbSession.h" +#include "sharedNetworkMessages/GenericValueTypeMessage.h" +#include "sharedLog/Log.h" +#include "unicodeArchive/UnicodeArchive.h" + +// ====================================================================== + +TaskVerifyCharacter::TaskVerifyCharacter(const std::string &schema) : + TaskRequest(), + m_characters(), + m_goldSchema(schema) +{ + LOG("TRACE_LOGIN", ("Create DB TaskVerifyCharacter")); +} + +//----------------------------------------------------------------------- + +TaskVerifyCharacter::~TaskVerifyCharacter() +{ +} + +//----------------------------------------------------------------------- + +bool TaskVerifyCharacter::process(DB::Session *session) +{ + LOG("TRACE_LOGIN", ("TaskVerifyCharacter -- starting process")); + + VerifyCharacterQuery query; + query.gold_schema.setValue(m_goldSchema); + + for (std::vector::iterator i=m_characters.begin(); i!=m_characters.end(); ++i) + { + query.station_id = static_cast((*i)->m_suid); + query.character_id = (*i)->m_characterId; + LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) -- processing", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + if(session->exec(&query)) + { + (*i)->m_characterName = query.character_name.getValue(); + (*i)->m_approved = query.approved.getValue(); + query.scene_id.getValue((*i)->m_sceneId); + (*i)->m_containerId = query.container_id.getValue(); + (*i)->m_x = static_cast(query.x.getValue()); + (*i)->m_y = static_cast(query.y.getValue()); + (*i)->m_z = static_cast(query.z.getValue()); + query.containment_flag.getValue((*i)->m_containment_flag); + } + else + { + return false; + } + } + + query.done(); + + LOG("TRACE_LOGIN", ("TaskVerifyCharacter -- finished process")); + return true; +} + +//----------------------------------------------------------------------- + +void TaskVerifyCharacter::onComplete() +{ +// REPORT_LOG(true, ("TaskVerifyCharacter::onComplete()\n")); + for (std::vector::iterator i=m_characters.begin(); i!=m_characters.end(); ++i) + { + if(! (*i)->m_transferCharacterData) + { + ValidateCharacterForLoginReplyMessage msg( + (*i)->m_approved, + (*i)->m_suid, + (*i)->m_characterId, + (*i)->m_containerId, + (*i)->m_sceneId, + Vector((*i)->m_x,(*i)->m_y,(*i)->m_z), + (*i)->m_characterName); + DatabaseProcess::getInstance().sendToCentralServer(msg,true); + if ((*i)->m_approved) + LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) completed -- success", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + else + LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) completed -- failure", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + // 0 = there was a database error trying to fix containment + // 1 = there is a recursive containment error in the character object chain that wasn't fixed + // 2 = there is a recursive containment error in the containment chain not in the character chain + // 3 = the containment chain is ok + // 4 = there was a recursive containment error in the character object chain that was fixed + switch ((*i)->m_containment_flag ) + { + case 0: LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) completed -- containment error (database error verifying containment)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + LOG("CustomerService", ("Login: TaskVerifyCharacter(%d, %s) completed -- containment error (database error verifying containment)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + break; + + case 1: LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) completed -- containment error (recursive containment error in the character object that wasn't fixed)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + LOG("CustomerService", ("Login: TaskVerifyCharacter(%d, %s) completed -- containment error (recursive containment error in the character object that wasn't fixed)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + break; + + case 2: LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) completed -- containment error (recursive containment error not in the character chain that must be fix manually)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + LOG("CustomerService", ("Login: TaskVerifyCharacter(%d, %s) completed -- containment error (recursive containment error not in the character chain that must be fix manually)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + break; + + case 3: //containment was OK so we don't need to log it + break; + + case 4: LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) completed -- containment error (recursive containment error in the character object that was fixed)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + LOG("CustomerService", ("Login: TaskVerifyCharacter(%d, %s) completed -- containment error (recursive containment error in the character object that was fixed)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + break; + + default: + LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) completed -- containment error (unknown containment flag)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + LOG("CustomerService", ("Login: TaskVerifyCharacter(%d, %s) completed -- containment error (unknown containment flag)", (*i)->m_suid, (*i)->m_characterId.getValueString().c_str())); + + break; + + } + } + else + { + const TransferCharacterData * d = (*i)->m_transferCharacterData; + TransferCharacterData responseData(*d); + responseData.setCharacterId((*i)->m_characterId); + responseData.setContainerId((*i)->m_containerId); + responseData.setScene((*i)->m_sceneId); + responseData.setStartingCoordinates(Vector((*i)->m_x, (*i)->m_y, (*i)->m_z)); + GenericValueTypeMessage response("TransferReplyLoginLocationData", responseData); // starting coordinates + DatabaseProcess::getInstance().sendToCentralServer(response, true); + LOG("CustomerService", ("CharacterTransfer: ***SwgDatabaseServer: sending TransferReplyLoginLocationData to central server for character %s\n", responseData.toString().c_str())); + } + + delete *i; + } + m_characters.clear(); + + dynamic_cast(SwgLoader::getInstance()).verifyCharacterFinished(this); +} + +// ====================================================================== + +void TaskVerifyCharacter::VerifyCharacterQuery::getSQL(std::string &sql) +{ + // Note: station id and character id are input parameters. The rest are pass-by-reference output parameters. + sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier()+"loader.verify_character (:station_id, :character_id, :gold_schema, :approved, :character_name, :scene_id, :container_id, :x, :y, :z, :containment_flag); end;"; +} + +// ---------------------------------------------------------------------- + +bool TaskVerifyCharacter::VerifyCharacterQuery::bindParameters() +{ + if (!bindParameter(station_id)) return false; + if (!bindParameter(character_id)) return false; + if (!bindParameter(gold_schema)) return false; + + if (!bindParameter(approved)) return false; + if (!bindParameter(character_name)) return false; + if (!bindParameter(scene_id)) return false; + if (!bindParameter(container_id)) return false; + if (!bindParameter(x)) return false; + if (!bindParameter(y)) return false; + if (!bindParameter(z)) return false; + if (!bindParameter(containment_flag)) return false; + + return true; +} + +// ---------------------------------------------------------------------- + +bool TaskVerifyCharacter::VerifyCharacterQuery::bindColumns() +{ + return true; +} + +// ---------------------------------------------------------------------- + +DB::Query::QueryMode TaskVerifyCharacter::VerifyCharacterQuery::getExecutionMode() const +{ + return MODE_PROCEXEC; +} + +// ---------------------------------------------------------------------- + +TaskVerifyCharacter::VerifyCharacterQuery::VerifyCharacterQuery() : + Query(), + station_id(), + character_id(), + gold_schema(), + character_name(), + approved(), + scene_id(), + container_id(), + x(), + y(), + z(), + containment_flag() +{ +} + +// ---------------------------------------------------------------------- + +void TaskVerifyCharacter::addCharacter(StationId suid, const NetworkId &characterId, const TransferCharacterData * transferCharacterData) +{ + LOG("TRACE_LOGIN", ("TaskVerifyCharacter(%d, %s) -- adding", suid, characterId.getValueString().c_str())); + + CharacterRecord *cr = new CharacterRecord; + cr->m_suid = suid; + cr->m_characterId = characterId; + cr->m_transferCharacterData = transferCharacterData; + m_characters.push_back(cr); +} + +// ====================================================================== diff --git a/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskVerifyCharacter.h b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskVerifyCharacter.h new file mode 100644 index 00000000..c9d69a69 --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/shared/tasks/TaskVerifyCharacter.h @@ -0,0 +1,99 @@ +// ====================================================================== +// +// TaskVerifyCharacter.h +// copyright (c) 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_TaskVerifyCharacter_H +#define INCLUDED_TaskVerifyCharacter_H + +// ====================================================================== + +#include + +#include "Unicode.h" +#include "sharedDatabaseInterface/Bindable.h" +#include "sharedDatabaseInterface/BindableNetworkId.h" +#include "sharedDatabaseInterface/DbQuery.h" +#include "sharedDatabaseInterface/DbTaskRequest.h" +#include "sharedFoundation/StationId.h" + +class TransferCharacterData; + +//----------------------------------------------------------------------- + +class TaskVerifyCharacter:public DB::TaskRequest +{ + public: + explicit TaskVerifyCharacter(const std::string &schema); + virtual ~TaskVerifyCharacter(); + + virtual bool process (DB::Session *session); + virtual void onComplete (); + + void addCharacter(StationId suid, const NetworkId &characterId, const TransferCharacterData * characterData); + + private: + class VerifyCharacterQuery : public DB::Query + { + public: + VerifyCharacterQuery(); + + virtual void getSQL(std::string &sql); + virtual bool bindParameters(); + virtual bool bindColumns(); + virtual QueryMode getExecutionMode() const; + + public: + // input: + DB::BindableLong station_id; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableNetworkId character_id; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableString<50> gold_schema; //lint !e1925 public data member Suppresed because it's in a private inner class + + //output: + DB::BindableString<128> character_name; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableBool approved; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableString<128> scene_id; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableNetworkId container_id; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableDouble x; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableDouble y; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableDouble z; //lint !e1925 public data member Suppresed because it's in a private inner class + DB::BindableLong containment_flag; + + private: + VerifyCharacterQuery(const VerifyCharacterQuery&); + VerifyCharacterQuery& operator=(const VerifyCharacterQuery&); + }; + + private: + class CharacterRecord + { + public: + StationId m_suid; //lint !e1925 public data member Suppresed because it's in a private inner class + NetworkId m_characterId; //lint !e1925 public data member Suppresed because it's in a private inner class + + Unicode::String m_characterName; //lint !e1925 public data member Suppresed because it's in a private inner class + bool m_approved; //lint !e1925 public data member Suppresed because it's in a private inner class + std::string m_sceneId; //lint !e1925 public data member Suppresed because it's in a private inner class + NetworkId m_containerId; //lint !e1925 public data member Suppresed because it's in a private inner class + float m_x; //lint !e1925 public data member Suppresed because it's in a private inner class + float m_y; //lint !e1925 public data member Suppresed because it's in a private inner class + float m_z; //lint !e1925 public data member Suppresed because it's in a private inner class + int m_containment_flag; + const TransferCharacterData * m_transferCharacterData; //lint !e1925 public data member Suppresed because it's in a private inner class + }; + + std::vector m_characters; + std::string m_goldSchema; + + private: + //Disabled: + TaskVerifyCharacter(); + TaskVerifyCharacter(const TaskVerifyCharacter&); + TaskVerifyCharacter& operator=(const TaskVerifyCharacter& rhs); +}; + +//----------------------------------------------------------------------- + +#endif diff --git a/game/server/application/SwgDatabaseServer/src/win32/FirstSwgDatabaseServer.cpp b/game/server/application/SwgDatabaseServer/src/win32/FirstSwgDatabaseServer.cpp new file mode 100644 index 00000000..d815aeca --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/win32/FirstSwgDatabaseServer.cpp @@ -0,0 +1 @@ +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" diff --git a/game/server/application/SwgDatabaseServer/src/win32/WinMain.cpp b/game/server/application/SwgDatabaseServer/src/win32/WinMain.cpp new file mode 100644 index 00000000..6e458a7c --- /dev/null +++ b/game/server/application/SwgDatabaseServer/src/win32/WinMain.cpp @@ -0,0 +1,87 @@ +#include "SwgDatabaseServer/FirstSwgDatabaseServer.h" + +#include "serverDatabase/ConfigServerDatabase.h" +#include "serverDatabase/DatabaseProcess.h" + +#include "sharedDebug/SetupSharedDebug.h" +#include "sharedFile/SetupSharedFile.h" +#include "sharedFile/TreeFile.h" +#include "sharedFoundation/SetupSharedFoundation.h" +#include "sharedLog/LogManager.h" +#include "sharedLog/SetupSharedLog.h" +#include "sharedNetwork/NetworkHandler.h" +#include "sharedNetwork/SetupSharedNetwork.h" +#include "sharedNetworkMessages/SetupSharedNetworkMessages.h" +#include "sharedObject/SetupSharedObject.h" +#include "sharedRandom/SetupSharedRandom.h" +#include "sharedThread/SetupSharedThread.h" +#include "SwgDatabaseServer/SwgDatabaseServer.h" + +#include + + +//_____________________________________________________________________ +int main(int argc, char ** argv) +{ + // command line hack + std::string cmdLine; + for(int i = 1; i < argc; ++i) + { + cmdLine += argv[i]; + if(i + 1 < argc) + { + cmdLine += " "; + } + } + + SetupSharedThread::install(); + SetupSharedDebug::install(1024); + + // -- setup foundation + SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game); + + setupFoundationData.commandLine = cmdLine.c_str(); + setupFoundationData.createWindow = false; + setupFoundationData.clockUsesSleep = true; + + SetupSharedFoundation::install (setupFoundationData); + + SetupSharedFile::install(false); + SetupSharedRandom::install(int(time(NULL))); + { + SetupSharedObject::Data data; + SetupSharedObject::setupDefaultGameData(data); + SetupSharedObject::install(data); + } + + SetupSharedNetwork::SetupData networkSetupData; + SetupSharedNetwork::getDefaultServerSetupData(networkSetupData); + SetupSharedNetwork::install(networkSetupData); + + SetupSharedNetworkMessages::install(); + + SetupSharedLog::install("SwgDatabaseServer"); + + TreeFile::addSearchAbsolute(0); + TreeFile::addSearchPath(".",0); + + //-- setup server + ConfigServerDatabase::install (); + + NetworkHandler::install(); + + SwgDatabaseServer::install(); + + //-- run server + SetupSharedFoundation::callbackWithExceptionHandling(SwgDatabaseServer::runStatic); + + NetworkHandler::remove(); + SetupSharedLog::remove(); + + SetupSharedFoundation::remove(); + SetupSharedThread::remove(); + + return 0; +} + +//_____________________________________________________________________