diff options
| author | Shauren <shauren.trinity@gmail.com> | 2017-05-13 11:49:09 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2017-05-13 11:49:09 +0200 |
| commit | beb3316089b350a43e917d896e682298df8dcfc0 (patch) | |
| tree | 8006c52594009f226d834991d101c97057699594 /src/server/game | |
| parent | c00316d3d4b57826cc8e38feed24faf84832c04b (diff) | |
Core/Shared: Include cleanup
Diffstat (limited to 'src/server/game')
26 files changed, 693 insertions, 122 deletions
diff --git a/src/server/game/Achievements/CriteriaHandler.h b/src/server/game/Achievements/CriteriaHandler.h index 8959997041c..b69379ddc19 100644 --- a/src/server/game/Achievements/CriteriaHandler.h +++ b/src/server/game/Achievements/CriteriaHandler.h @@ -25,6 +25,7 @@ #include <map> #include <unordered_map> #include <vector> +#include <ctime> class Player; class Unit; diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index 88c718c19e7..11b319e2c09 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -33,6 +33,11 @@ #include "ChatLink.h" #include "Group.h" +ChatCommand::ChatCommand(char const* name, uint32 permission, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands /*= std::vector<ChatCommand>()*/) + : Name(ASSERT_NOTNULL(name)), Permission(permission), AllowConsole(allowConsole), Handler(handler), Help(std::move(help)), ChildCommands(std::move(childCommands)) +{ +} + // Lazy loading of the command table cache from commands and the // ScriptMgr should be thread safe since the player commands, // cli commands and ScriptMgr updates are all dispatched one after diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 697a92e65bb..e20479d8c51 100644 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -42,8 +42,7 @@ class TC_GAME_API ChatCommand typedef bool(*pHandler)(ChatHandler*, char const*); public: - ChatCommand(char const* name, uint32 permission, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands = std::vector<ChatCommand>()) - : Name(ASSERT_NOTNULL(name)), Permission(permission), AllowConsole(allowConsole), Handler(handler), Help(std::move(help)), ChildCommands(std::move(childCommands)) { } + ChatCommand(char const* name, uint32 permission, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands = std::vector<ChatCommand>()); char const* Name; uint32 Permission; // function pointer required correct align (use uint32) diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index c64a3bab4f0..c62dd2ee9b8 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -23,6 +23,7 @@ #include "Log.h" #include "TransportMgr.h" #include "World.h" +#include <cctype> // temporary hack until includes are sorted out (don't want to pull in Windows.h) #ifdef GetClassName diff --git a/src/server/game/DataStores/DB2Stores.h b/src/server/game/DataStores/DB2Stores.h index ea2d02883bd..2970bb56965 100644 --- a/src/server/game/DataStores/DB2Stores.h +++ b/src/server/game/DataStores/DB2Stores.h @@ -30,6 +30,11 @@ #include <unordered_set> #include <vector> + // temporary hack until includes are sorted out (don't want to pull in Windows.h) +#ifdef GetClassName +#undef GetClassName +#endif + TC_GAME_API extern DB2Storage<AchievementEntry> sAchievementStore; TC_GAME_API extern DB2Storage<AnimKitEntry> sAnimKitStore; TC_GAME_API extern DB2Storage<AreaTableEntry> sAreaTableStore; diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp index 292dcdd60a4..a353a8a2afd 100644 --- a/src/server/game/Entities/Object/ObjectGuid.cpp +++ b/src/server/game/Entities/Object/ObjectGuid.cpp @@ -17,6 +17,7 @@ */ #include "ObjectGuid.h" +#include "Errors.h" #include "Hash.h" #include "Log.h" #include "World.h" diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h index 883476b5f21..bcb029b2deb 100644 --- a/src/server/game/Entities/Object/ObjectGuid.h +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -248,15 +248,17 @@ class TC_GAME_API ObjectGuid LowType GetMaxCounter() const { return GetMaxCounter(GetHigh()); } + // deprecated uint8& operator[](uint32 index) { - ASSERT(index < sizeof(uint64) * 2); + //ASSERT(index < sizeof(uint64) * 2); return ((uint8*)&_low)[index]; } + // deprecated uint8 const& operator[](uint32 index) const { - ASSERT(index < sizeof(uint64) * 2); + //ASSERT(index < sizeof(uint64) * 2); return ((uint8 const*)&_low)[index]; } diff --git a/src/server/game/Entities/Object/Updates/UpdateData.cpp b/src/server/game/Entities/Object/Updates/UpdateData.cpp index 9f718024ec1..7a59f1cf236 100644 --- a/src/server/game/Entities/Object/Updates/UpdateData.cpp +++ b/src/server/game/Entities/Object/Updates/UpdateData.cpp @@ -18,6 +18,7 @@ #include "Common.h" #include "ByteBuffer.h" +#include "Errors.h" #include "WorldPacket.h" #include "UpdateData.h" #include "Opcodes.h" diff --git a/src/server/game/Grids/Dynamic/TypeContainer.h b/src/server/game/Grids/Dynamic/TypeContainer.h new file mode 100644 index 00000000000..7e825136755 --- /dev/null +++ b/src/server/game/Grids/Dynamic/TypeContainer.h @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef TRINITY_TYPECONTAINER_H +#define TRINITY_TYPECONTAINER_H + +/* + * Here, you'll find a series of containers that allow you to hold multiple + * types of object at the same time. + */ + +#include <map> +#include <unordered_map> +#include <vector> +#include "Define.h" +#include "Dynamic/TypeList.h" +#include "GridRefManager.h" + +/* + * @class ContainerMapList is a mulit-type container for map elements + * By itself its meaningless but collaborate along with TypeContainers, + * it become the most powerfully container in the whole system. + */ +template<class OBJECT> +struct ContainerMapList +{ + //std::map<OBJECT_HANDLE, OBJECT *> _element; + GridRefManager<OBJECT> _element; +}; + +template<> +struct ContainerMapList<TypeNull> /* nothing is in type null */ +{ +}; + +template<class H, class T> +struct ContainerMapList<TypeList<H, T> > +{ + ContainerMapList<H> _elements; + ContainerMapList<T> _TailElements; +}; + +template<class OBJECT, class KEY_TYPE> +struct ContainerUnorderedMap +{ + std::unordered_map<KEY_TYPE, OBJECT*> _element; +}; + +template<class KEY_TYPE> +struct ContainerUnorderedMap<TypeNull, KEY_TYPE> +{ +}; + +template<class H, class T, class KEY_TYPE> +struct ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE> +{ + ContainerUnorderedMap<H, KEY_TYPE> _elements; + ContainerUnorderedMap<T, KEY_TYPE> _TailElements; +}; + +#include "TypeContainerFunctions.h" + +/* + * @class TypeMapContainer contains a fixed number of types and is + * determined at compile time. This is probably the most complicated + * class and do its simplest thing, that is, holds objects + * of different types. + */ + +template<class OBJECT_TYPES> +class TypeMapContainer +{ + public: + template<class SPECIFIC_TYPE> size_t Count() const { return Trinity::Count(i_elements, (SPECIFIC_TYPE*)NULL); } + + /// inserts a specific object into the container + template<class SPECIFIC_TYPE> + bool insert(SPECIFIC_TYPE *obj) + { + SPECIFIC_TYPE* t = Trinity::Insert(i_elements, obj); + return (t != NULL); + } + + /// Removes the object from the container, and returns the removed object + //template<class SPECIFIC_TYPE> + //bool remove(SPECIFIC_TYPE* obj) + //{ + // SPECIFIC_TYPE* t = Trinity::Remove(i_elements, obj); + // return (t != NULL); + //} + + ContainerMapList<OBJECT_TYPES> & GetElements(void) { return i_elements; } + const ContainerMapList<OBJECT_TYPES> & GetElements(void) const { return i_elements;} + + private: + ContainerMapList<OBJECT_TYPES> i_elements; +}; + +template<class OBJECT_TYPES, class KEY_TYPE> +class TypeUnorderedMapContainer +{ +public: + template<class SPECIFIC_TYPE> + bool Insert(KEY_TYPE const& handle, SPECIFIC_TYPE* obj) + { + return Trinity::Insert(_elements, handle, obj); + } + + template<class SPECIFIC_TYPE> + bool Remove(KEY_TYPE const& handle) + { + return Trinity::Remove(_elements, handle, (SPECIFIC_TYPE*)NULL); + } + + template<class SPECIFIC_TYPE> + SPECIFIC_TYPE* Find(KEY_TYPE const& handle) + { + return Trinity::Find(_elements, handle, (SPECIFIC_TYPE*)NULL); + } + + ContainerUnorderedMap<OBJECT_TYPES, KEY_TYPE>& GetElements() { return _elements; } + ContainerUnorderedMap<OBJECT_TYPES, KEY_TYPE> const& GetElements() const { return _elements; } + +private: + ContainerUnorderedMap<OBJECT_TYPES, KEY_TYPE> _elements; +}; + +#endif diff --git a/src/server/game/Grids/Dynamic/TypeContainerFunctions.h b/src/server/game/Grids/Dynamic/TypeContainerFunctions.h new file mode 100644 index 00000000000..97d20922a05 --- /dev/null +++ b/src/server/game/Grids/Dynamic/TypeContainerFunctions.h @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef TYPECONTAINER_FUNCTIONS_H +#define TYPECONTAINER_FUNCTIONS_H + +/* + * Here you'll find a list of helper functions to make + * the TypeContainer usefull. Without it, its hard + * to access or mutate the container. + */ + +#include "Define.h" +#include "Dynamic/TypeList.h" +#include <map> +#include <unordered_map> + +namespace Trinity +{ + // Helpers + // Insert helpers + template<class SPECIFIC_TYPE, class KEY_TYPE> + bool Insert(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) + { + auto i = elements._element.find(handle); + if (i == elements._element.end()) + { + elements._element[handle] = obj; + return true; + } + else + { + ASSERT(i->second == obj, "Object with certain key already in but objects are different!"); + return false; + } + } + + template<class SPECIFIC_TYPE, class KEY_TYPE> + bool Insert(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) + { + return false; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE, class T> + bool Insert(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) + { + return false; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE, class H, class T> + bool Insert(ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* obj) + { + bool ret = Insert(elements._elements, handle, obj); + return ret ? ret : Insert(elements._TailElements, handle, obj); + } + + // Find helpers + template<class SPECIFIC_TYPE, class KEY_TYPE> + SPECIFIC_TYPE* Find(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE> const& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) + { + auto i = elements._element.find(handle); + if (i == elements._element.end()) + return nullptr; + else + return i->second; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE> + SPECIFIC_TYPE* Find(ContainerUnorderedMap<TypeNull, KEY_TYPE> const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) + { + return nullptr; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE, class T> + SPECIFIC_TYPE* Find(ContainerUnorderedMap<T, KEY_TYPE> const& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) + { + return nullptr; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE, class H, class T> + SPECIFIC_TYPE* Find(ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE> const& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) + { + SPECIFIC_TYPE* ret = Find(elements._elements, handle, (SPECIFIC_TYPE*)nullptr); + return ret ? ret : Find(elements._TailElements, handle, (SPECIFIC_TYPE*)nullptr); + } + + // Erase helpers + template<class SPECIFIC_TYPE, class KEY_TYPE> + bool Remove(ContainerUnorderedMap<SPECIFIC_TYPE, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) + { + elements._element.erase(handle); + return true; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE> + bool Remove(ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) + { + return false; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE, class T> + bool Remove(ContainerUnorderedMap<T, KEY_TYPE>& /*elements*/, KEY_TYPE const& /*handle*/, SPECIFIC_TYPE* /*obj*/) + { + return false; + } + + template<class SPECIFIC_TYPE, class KEY_TYPE, class H, class T> + bool Remove(ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& elements, KEY_TYPE const& handle, SPECIFIC_TYPE* /*obj*/) + { + bool ret = Remove(elements._elements, handle, (SPECIFIC_TYPE*)nullptr); + return ret ? ret : Remove(elements._TailElements, handle, (SPECIFIC_TYPE*)nullptr); + } + + /* ContainerMapList Helpers */ + // count functions + template<class SPECIFIC_TYPE> + size_t Count(ContainerMapList<SPECIFIC_TYPE> const& elements, SPECIFIC_TYPE* /*fake*/) + { + return elements._element.getSize(); + } + + template<class SPECIFIC_TYPE> + size_t Count(ContainerMapList<TypeNull> const& /*elements*/, SPECIFIC_TYPE* /*fake*/) + { + return 0; + } + + template<class SPECIFIC_TYPE, class T> + size_t Count(ContainerMapList<T> const& /*elements*/, SPECIFIC_TYPE* /*fake*/) + { + return 0; + } + + template<class SPECIFIC_TYPE, class T> + size_t Count(ContainerMapList<TypeList<SPECIFIC_TYPE, T>> const& elements, SPECIFIC_TYPE* fake) + { + return Count(elements._elements, fake); + } + + template<class SPECIFIC_TYPE, class H, class T> + size_t Count(ContainerMapList<TypeList<H, T>> const& elements, SPECIFIC_TYPE* fake) + { + return Count(elements._TailElements, fake); + } + + // non-const insert functions + template<class SPECIFIC_TYPE> + SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* obj) + { + //elements._element[hdl] = obj; + obj->AddToGrid(elements._element); + return obj; + } + + template<class SPECIFIC_TYPE> + SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*obj*/) + { + return nullptr; + } + + // this is a missed + template<class SPECIFIC_TYPE, class T> + SPECIFIC_TYPE* Insert(ContainerMapList<T>& /*elements*/, SPECIFIC_TYPE* /*obj*/) + { + return nullptr; // a missed + } + + // Recursion + template<class SPECIFIC_TYPE, class H, class T> + SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T>>& elements, SPECIFIC_TYPE* obj) + { + SPECIFIC_TYPE* t = Insert(elements._elements, obj); + return (t != nullptr ? t : Insert(elements._TailElements, obj)); + } + + //// non-const remove method + //template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<SPECIFIC_TYPE> & /*elements*/, SPECIFIC_TYPE *obj) + //{ + // obj->GetGridRef().unlink(); + // return obj; + //} + + //template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Remove(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/) + //{ + // return nullptr; + //} + + //// this is a missed + //template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Remove(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/) + //{ + // return nullptr; // a missed + //} + + //template<class SPECIFIC_TYPE, class T, class H> SPECIFIC_TYPE* Remove(ContainerMapList<TypeList<H, T> > &elements, SPECIFIC_TYPE *obj) + //{ + // // The head element is bad + // SPECIFIC_TYPE* t = Remove(elements._elements, obj); + // return (t != nullptr ? t : Remove(elements._TailElements, obj)); + //} +} +#endif + diff --git a/src/server/game/Grids/Dynamic/TypeContainerVisitor.h b/src/server/game/Grids/Dynamic/TypeContainerVisitor.h new file mode 100644 index 00000000000..f15cfe66758 --- /dev/null +++ b/src/server/game/Grids/Dynamic/TypeContainerVisitor.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef TRINITY_TYPECONTAINERVISITOR_H +#define TRINITY_TYPECONTAINERVISITOR_H + +/* + * @class TypeContainerVisitor is implemented as a visitor pattern. It is + * a visitor to the TypeContainerList or TypeContainerMapList. The visitor has + * to overload its types as a visit method is called. + */ + +#include "Define.h" +#include "Dynamic/TypeContainer.h" + +// forward declaration +template<class T, class Y> class TypeContainerVisitor; + +// visitor helper +template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c) +{ + v.Visit(c); +} + +// terminate condition container map list +template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) { } + +template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c) +{ + v.Visit(c._element); +} + +// recursion container map list +template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c) +{ + VisitorHelper(v, c._elements); + VisitorHelper(v, c._TailElements); +} + +// for TypeMapContainer +template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c) +{ + VisitorHelper(v, c.GetElements()); +} + +// TypeUnorderedMapContainer +template<class VISITOR, class KEY_TYPE> +void VisitorHelper(VISITOR& /*v*/, ContainerUnorderedMap<TypeNull, KEY_TYPE>& /*c*/) { } + +template<class VISITOR, class KEY_TYPE, class T> +void VisitorHelper(VISITOR& v, ContainerUnorderedMap<T, KEY_TYPE>& c) +{ + v.Visit(c._element); +} + +template<class VISITOR, class KEY_TYPE, class H, class T> +void VisitorHelper(VISITOR& v, ContainerUnorderedMap<TypeList<H, T>, KEY_TYPE>& c) +{ + VisitorHelper(v, c._elements); + VisitorHelper(v, c._TailElements); +} + +template<class VISITOR, class OBJECT_TYPES, class KEY_TYPE> +void VisitorHelper(VISITOR& v, TypeUnorderedMapContainer<OBJECT_TYPES, KEY_TYPE>& c) +{ + VisitorHelper(v, c.GetElements()); +} + +template<class VISITOR, class TYPE_CONTAINER> +class TypeContainerVisitor +{ + public: + TypeContainerVisitor(VISITOR &v) : i_visitor(v) { } + + void Visit(TYPE_CONTAINER &c) + { + VisitorHelper(i_visitor, c); + } + + void Visit(const TYPE_CONTAINER &c) const + { + VisitorHelper(i_visitor, c); + } + + private: + VISITOR &i_visitor; +}; +#endif + diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index 72e37927d0f..1347b823711 100644 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -478,6 +478,13 @@ time_t InstanceSaveManager::GetSubsequentResetTime(uint32 mapid, Difficulty diff return ((resetTime + MINUTE) / DAY * DAY) + period + diff; } +void InstanceSaveManager::SetResetTimeFor(uint32 mapid, Difficulty d, time_t t) +{ + ResetTimeByMapDifficultyMap::iterator itr = m_resetTimeByMapDifficulty.find(MAKE_PAIR64(mapid, d)); + ASSERT(itr != m_resetTimeByMapDifficulty.end()); + itr->second = t; +} + void InstanceSaveManager::ScheduleReset(bool add, time_t time, InstResetEvent event) { if (!add) diff --git a/src/server/game/Instances/InstanceSaveMgr.h b/src/server/game/Instances/InstanceSaveMgr.h index fcf7832a20a..63a2864d20b 100644 --- a/src/server/game/Instances/InstanceSaveMgr.h +++ b/src/server/game/Instances/InstanceSaveMgr.h @@ -199,12 +199,7 @@ class TC_GAME_API InstanceSaveManager } // Use this only when updating existing reset times - void SetResetTimeFor(uint32 mapid, Difficulty d, time_t t) - { - ResetTimeByMapDifficultyMap::iterator itr = m_resetTimeByMapDifficulty.find(MAKE_PAIR64(mapid, d)); - ASSERT(itr != m_resetTimeByMapDifficulty.end()); - itr->second = t; - } + void SetResetTimeFor(uint32 mapid, Difficulty d, time_t t); ResetTimeByMapDifficultyMap const& GetResetTimeMap() const { diff --git a/src/server/game/Server/Packet.cpp b/src/server/game/Server/Packet.cpp new file mode 100644 index 00000000000..09fdb85571f --- /dev/null +++ b/src/server/game/Server/Packet.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "Packet.h" +#include "Errors.h" + +WorldPackets::Packet::Packet(WorldPacket&& worldPacket) + : _worldPacket(std::move(worldPacket)) +{ +} + +WorldPackets::ServerPacket::ServerPacket(OpcodeServer opcode, size_t initialSize /*= 200*/, ConnectionType connection /*= CONNECTION_TYPE_DEFAULT*/) + : Packet(WorldPacket(opcode, initialSize, connection)) +{ +} + +void WorldPackets::ServerPacket::Read() +{ + ASSERT(!"Read not implemented for server packets."); +} + +WorldPackets::ClientPacket::ClientPacket(OpcodeClient expectedOpcode, WorldPacket&& packet) + : Packet(std::move(packet)) +{ + ASSERT(GetOpcode() == expectedOpcode); +} + +WorldPackets::ClientPacket::ClientPacket(WorldPacket&& packet) + : Packet(std::move(packet)) +{ +} + +WorldPacket const* WorldPackets::ClientPacket::Write() +{ + ASSERT(!"Write not allowed for client packets."); + // Shut up some compilers + return nullptr; +} diff --git a/src/server/game/Server/Packet.h b/src/server/game/Server/Packet.h index 02af9e5c9e9..4d7774586e0 100644 --- a/src/server/game/Server/Packet.h +++ b/src/server/game/Server/Packet.h @@ -25,7 +25,7 @@ namespace WorldPackets class TC_GAME_API Packet { public: - Packet(WorldPacket&& worldPacket) : _worldPacket(std::move(worldPacket)) { } + Packet(WorldPacket&& worldPacket); virtual ~Packet() = default; @@ -43,12 +43,12 @@ namespace WorldPackets WorldPacket _worldPacket; }; - class ServerPacket : public Packet + class TC_GAME_API ServerPacket : public Packet { public: - ServerPacket(OpcodeServer opcode, size_t initialSize = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : Packet(WorldPacket(opcode, initialSize, connection)) { } + ServerPacket(OpcodeServer opcode, size_t initialSize = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT); - void Read() override final { ASSERT(!"Read not implemented for server packets."); } + void Read() override final; void Clear() { _worldPacket.clear(); } WorldPacket&& Move() { return std::move(_worldPacket); } @@ -56,18 +56,13 @@ namespace WorldPackets OpcodeServer GetOpcode() const { return OpcodeServer(_worldPacket.GetOpcode()); } }; - class ClientPacket : public Packet + class TC_GAME_API ClientPacket : public Packet { public: - ClientPacket(WorldPacket&& packet) : Packet(std::move(packet)) { } - ClientPacket(OpcodeClient expectedOpcode, WorldPacket&& packet) : Packet(std::move(packet)) { ASSERT(GetOpcode() == expectedOpcode); } - - WorldPacket const* Write() override final - { - ASSERT(!"Write not allowed for client packets."); - // Shut up some compilers - return nullptr; - } + ClientPacket(WorldPacket&& packet); + ClientPacket(OpcodeClient expectedOpcode, WorldPacket&& packet); + + WorldPacket const* Write() override final; OpcodeClient GetOpcode() const { return OpcodeClient(_worldPacket.GetOpcode()); } }; diff --git a/src/server/game/Server/Packets/AreaTriggerPackets.h b/src/server/game/Server/Packets/AreaTriggerPackets.h index 02e30093501..379ec5cd0f8 100644 --- a/src/server/game/Server/Packets/AreaTriggerPackets.h +++ b/src/server/game/Server/Packets/AreaTriggerPackets.h @@ -22,6 +22,7 @@ #include "PacketUtilities.h" #include "ObjectGuid.h" #include "Optional.h" +#include <G3D/Vector3.h> namespace WorldPackets { diff --git a/src/server/game/Server/Packets/AuthenticationPackets.cpp b/src/server/game/Server/Packets/AuthenticationPackets.cpp index 70dec6bd274..531dc81caa1 100644 --- a/src/server/game/Server/Packets/AuthenticationPackets.cpp +++ b/src/server/game/Server/Packets/AuthenticationPackets.cpp @@ -336,35 +336,21 @@ WorldPackets::Auth::ConnectTo::ConnectTo() : ServerPacket(SMSG_CONNECT_TO, 8 + 4 WorldPacket const* WorldPackets::Auth::ConnectTo::Write() { - ByteBuffer payload; - uint16 port = Payload.Where.port(); - uint8 address[16] = { 0 }; - uint8 addressType = 3; - if (Payload.Where.address().is_v4()) - { - memcpy(address, Payload.Where.address().to_v4().to_bytes().data(), 4); - addressType = 1; - } - else - { - memcpy(address, Payload.Where.address().to_v6().to_bytes().data(), 16); - addressType = 2; - } - HmacSha1 hmacHash(64, WherePacketHmac); - hmacHash.UpdateData(address, 16); - hmacHash.UpdateData(&addressType, 1); - hmacHash.UpdateData((uint8* const)&port, 2); + hmacHash.UpdateData(Payload.Where.data(), 16); + hmacHash.UpdateData((uint8* const)&Payload.Type, 1); + hmacHash.UpdateData((uint8* const)&Payload.Port, 2); hmacHash.UpdateData((uint8* const)Haiku.c_str(), 71); hmacHash.UpdateData(Payload.PanamaKey, 32); hmacHash.UpdateData(PiDigits, 108); hmacHash.UpdateData(&Payload.XorMagic, 1); hmacHash.Finalize(); + ByteBuffer payload; payload << uint32(Payload.Adler32); - payload << uint8(addressType); - payload.append(address, 16); - payload << uint16(port); + payload << uint8(Payload.Type); + payload.append(Payload.Where.data(), 16); + payload << uint16(Payload.Port); payload.append(Haiku.data(), 71); payload.append(Payload.PanamaKey, 32); payload.append(PiDigits, 108); diff --git a/src/server/game/Server/Packets/AuthenticationPackets.h b/src/server/game/Server/Packets/AuthenticationPackets.h index 68f32e6ce5e..5c1bf9f6da6 100644 --- a/src/server/game/Server/Packets/AuthenticationPackets.h +++ b/src/server/game/Server/Packets/AuthenticationPackets.h @@ -198,9 +198,18 @@ namespace WorldPackets static std::string const Haiku; static uint8 const PiDigits[130]; + public: + enum AddressType : uint8 + { + IPv4 = 1, + IPv6 = 2 + }; + struct ConnectPayload { - tcp::endpoint Where; + std::array<uint8, 16> Where; + uint16 Port; + AddressType Type; uint32 Adler32 = 0; uint8 XorMagic = 0x2A; uint8 PanamaKey[32]; diff --git a/src/server/game/Server/Packets/BattlegroundPackets.h b/src/server/game/Server/Packets/BattlegroundPackets.h index 725edc21d41..6e52d872dc9 100644 --- a/src/server/game/Server/Packets/BattlegroundPackets.h +++ b/src/server/game/Server/Packets/BattlegroundPackets.h @@ -24,6 +24,7 @@ #include "PacketUtilities.h" #include "Packet.h" #include "Optional.h" +#include <G3D/Vector3.h> namespace WorldPackets { diff --git a/src/server/game/Server/Packets/ChannelPackets.cpp b/src/server/game/Server/Packets/ChannelPackets.cpp index 799d6214d4e..7ddcf009a99 100644 --- a/src/server/game/Server/Packets/ChannelPackets.cpp +++ b/src/server/game/Server/Packets/ChannelPackets.cpp @@ -16,6 +16,7 @@ */ #include "ChannelPackets.h" +#include "Errors.h" WorldPacket const* WorldPackets::Channel::ChannelListResponse::Write() { @@ -118,6 +119,34 @@ WorldPacket const* WorldPackets::Channel::UserlistUpdate::Write() return &_worldPacket; } +WorldPackets::Channel::ChannelPlayerCommand::ChannelPlayerCommand(WorldPacket&& packet) : ClientPacket(std::move(packet)) +{ + switch (GetOpcode()) + { + default: + ABORT(); + case CMSG_CHAT_CHANNEL_ANNOUNCEMENTS: + case CMSG_CHAT_CHANNEL_BAN: + case CMSG_CHAT_CHANNEL_DECLINE_INVITE: + case CMSG_CHAT_CHANNEL_DISPLAY_LIST: + case CMSG_CHAT_CHANNEL_INVITE: + case CMSG_CHAT_CHANNEL_KICK: + case CMSG_CHAT_CHANNEL_LIST: + case CMSG_CHAT_CHANNEL_MODERATE: + case CMSG_CHAT_CHANNEL_MODERATOR: + case CMSG_CHAT_CHANNEL_MUTE: + case CMSG_CHAT_CHANNEL_OWNER: + case CMSG_CHAT_CHANNEL_PASSWORD: + case CMSG_CHAT_CHANNEL_SET_OWNER: + case CMSG_CHAT_CHANNEL_SILENCE_ALL: + case CMSG_CHAT_CHANNEL_UNBAN: + case CMSG_CHAT_CHANNEL_UNMODERATOR: + case CMSG_CHAT_CHANNEL_UNMUTE: + case CMSG_CHAT_CHANNEL_UNSILENCE_ALL: + break; + } +} + void WorldPackets::Channel::ChannelPlayerCommand::Read() { switch (GetOpcode()) diff --git a/src/server/game/Server/Packets/ChannelPackets.h b/src/server/game/Server/Packets/ChannelPackets.h index a60a3d34def..e0ecf8f82f9 100644 --- a/src/server/game/Server/Packets/ChannelPackets.h +++ b/src/server/game/Server/Packets/ChannelPackets.h @@ -139,33 +139,7 @@ namespace WorldPackets class ChannelPlayerCommand final : public ClientPacket { public: - ChannelPlayerCommand(WorldPacket&& packet) : ClientPacket(std::move(packet)) - { - switch (GetOpcode()) - { - default: - ABORT(); - case CMSG_CHAT_CHANNEL_ANNOUNCEMENTS: - case CMSG_CHAT_CHANNEL_BAN: - case CMSG_CHAT_CHANNEL_DECLINE_INVITE: - case CMSG_CHAT_CHANNEL_DISPLAY_LIST: - case CMSG_CHAT_CHANNEL_INVITE: - case CMSG_CHAT_CHANNEL_KICK: - case CMSG_CHAT_CHANNEL_LIST: - case CMSG_CHAT_CHANNEL_MODERATE: - case CMSG_CHAT_CHANNEL_MODERATOR: - case CMSG_CHAT_CHANNEL_MUTE: - case CMSG_CHAT_CHANNEL_OWNER: - case CMSG_CHAT_CHANNEL_PASSWORD: - case CMSG_CHAT_CHANNEL_SET_OWNER: - case CMSG_CHAT_CHANNEL_SILENCE_ALL: - case CMSG_CHAT_CHANNEL_UNBAN: - case CMSG_CHAT_CHANNEL_UNMODERATOR: - case CMSG_CHAT_CHANNEL_UNMUTE: - case CMSG_CHAT_CHANNEL_UNSILENCE_ALL: - break; - } - } + ChannelPlayerCommand(WorldPacket&& packet); void Read() override; diff --git a/src/server/game/Server/Packets/PacketUtilities.cpp b/src/server/game/Server/Packets/PacketUtilities.cpp new file mode 100644 index 00000000000..a9560fac6c0 --- /dev/null +++ b/src/server/game/Server/Packets/PacketUtilities.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "PacketUtilities.h" +#include "Errors.h" +#include <G3D/Vector2.h> +#include <G3D/Vector3.h> +#include <sstream> +#include <array> + +ByteBuffer& operator<<(ByteBuffer& data, G3D::Vector2 const& v) +{ + data << v.x << v.y; + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, G3D::Vector3 const& v) +{ + data << v.x << v.y << v.z; + return data; +} + +ByteBuffer& operator>>(ByteBuffer& data, G3D::Vector2& v) +{ + data >> v.x >> v.y; + return data; +} + +ByteBuffer& operator>>(ByteBuffer& data, G3D::Vector3& v) +{ + data >> v.x >> v.y >> v.z; + return data; +} + +WorldPackets::PacketArrayMaxCapacityException::PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit) +{ + std::ostringstream builder; + builder << "Attempted to read more array elements from packet " << requestedSize << " than allowed " << sizeLimit; + message().assign(builder.str()); +} + +void WorldPackets::CheckCompactArrayMaskOverflow(std::size_t index, std::size_t limit) +{ + ASSERT(index < limit, "Attempted to insert " SZFMTD " values into CompactArray but it can only hold " SZFMTD, index, limit); +} diff --git a/src/server/game/Server/Packets/PacketUtilities.h b/src/server/game/Server/Packets/PacketUtilities.h index 20820c1a089..4182c098eb1 100644 --- a/src/server/game/Server/Packets/PacketUtilities.h +++ b/src/server/game/Server/Packets/PacketUtilities.h @@ -19,47 +19,26 @@ #define PacketUtilities_h__ #include "ByteBuffer.h" -#include <G3D/Vector2.h> -#include <G3D/Vector3.h> #include <boost/container/static_vector.hpp> -#include <sstream> -#include <array> -inline ByteBuffer& operator<<(ByteBuffer& data, G3D::Vector2 const& v) +namespace G3D { - data << v.x << v.y; - return data; + class Vector2; + class Vector3; } -inline ByteBuffer& operator>>(ByteBuffer& data, G3D::Vector2& v) -{ - data >> v.x >> v.y; - return data; -} +ByteBuffer& operator<<(ByteBuffer& data, G3D::Vector2 const& v); +ByteBuffer& operator>>(ByteBuffer& data, G3D::Vector2& v); -inline ByteBuffer& operator<<(ByteBuffer& data, G3D::Vector3 const& v) -{ - data << v.x << v.y << v.z; - return data; -} - -inline ByteBuffer& operator>>(ByteBuffer& data, G3D::Vector3& v) -{ - data >> v.x >> v.y >> v.z; - return data; -} +ByteBuffer& operator<<(ByteBuffer& data, G3D::Vector3 const& v); +ByteBuffer& operator>>(ByteBuffer& data, G3D::Vector3& v); namespace WorldPackets { class PacketArrayMaxCapacityException : public ByteBufferException { public: - PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit) - { - std::ostringstream builder; - builder << "Attempted to read more array elements from packet " << requestedSize << " than allowed " << sizeLimit; - message().assign(builder.str()); - } + PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit); }; /** @@ -122,6 +101,8 @@ namespace WorldPackets storage_type _storage; }; + void CheckCompactArrayMaskOverflow(std::size_t index, std::size_t limit); + template <typename T> class CompactArray { @@ -137,14 +118,14 @@ namespace WorldPackets right._mask = 0; } - CompactArray& operator= (CompactArray const& right) + CompactArray& operator=(CompactArray const& right) { _mask = right._mask; _contents = right._contents; return *this; } - CompactArray& operator= (CompactArray&& right) + CompactArray& operator=(CompactArray&& right) { _mask = right._mask; right._mask = 0; @@ -153,12 +134,12 @@ namespace WorldPackets } uint32 GetMask() const { return _mask; } - T const& operator[](size_t index) const { return _contents.at(index); } - size_t GetSize() const { return _contents.size(); } + T const& operator[](std::size_t index) const { return _contents.at(index); } + std::size_t GetSize() const { return _contents.size(); } - void Insert(size_t index, T const& value) + void Insert(std::size_t index, T const& value) { - ASSERT(index < 0x20); + CheckCompactArrayMaskOverflow(index, sizeof(_mask) * 8); _mask |= 1 << index; if (_contents.size() <= index) @@ -192,11 +173,9 @@ namespace WorldPackets { uint32 mask = v.GetMask(); data << uint32(mask); - for (size_t i = 0; i < v.GetSize(); ++i) - { + for (std::size_t i = 0; i < v.GetSize(); ++i) if (mask & (1 << i)) data << v[i]; - } return data; } @@ -207,15 +186,9 @@ namespace WorldPackets uint32 mask; data >> mask; - for (size_t index = 0; mask != 0; mask >>= 1, ++index) - { + for (std::size_t index = 0; mask != 0; mask >>= 1, ++index) if ((mask & 1) != 0) - { - T value; - data >> value; - v.Insert(index, value); - } - } + v.Insert(index, data.read<T>()); return data; } diff --git a/src/server/game/Server/Packets/SystemPackets.cpp b/src/server/game/Server/Packets/SystemPackets.cpp index 9ceca6444e8..1b85ba77e31 100644 --- a/src/server/game/Server/Packets/SystemPackets.cpp +++ b/src/server/game/Server/Packets/SystemPackets.cpp @@ -16,6 +16,7 @@ */ #include "SystemPackets.h" +#include "Errors.h" WorldPacket const* WorldPackets::System::FeatureSystemStatus::Write() { diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 8a9aa4d8844..8f1f87bcf18 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -711,8 +711,7 @@ void WorldSession::Handle_EarlyProccess(WorldPacket& recvPacket) void WorldSession::SendConnectToInstance(WorldPackets::Auth::ConnectToSerial serial) { boost::system::error_code ignored_error; - boost::asio::ip::tcp::endpoint instanceAddress = realm.GetAddressForClient(boost::asio::ip::address::from_string(GetRemoteAddress(), ignored_error)); - instanceAddress.port(sWorld->getIntConfig(CONFIG_PORT_INSTANCE)); + boost::asio::ip::address instanceAddress = realm.GetAddressForClient(boost::asio::ip::address::from_string(GetRemoteAddress(), ignored_error)); _instanceConnectKey.Fields.AccountId = GetAccountId(); _instanceConnectKey.Fields.ConnectionType = CONNECTION_TYPE_INSTANCE; @@ -721,7 +720,17 @@ void WorldSession::SendConnectToInstance(WorldPackets::Auth::ConnectToSerial ser WorldPackets::Auth::ConnectTo connectTo; connectTo.Key = _instanceConnectKey.Raw; connectTo.Serial = serial; - connectTo.Payload.Where = instanceAddress; + connectTo.Payload.Port = sWorld->getIntConfig(CONFIG_PORT_INSTANCE); + if (instanceAddress.is_v4()) + { + memcpy(connectTo.Payload.Where.data(), instanceAddress.to_v4().to_bytes().data(), 4); + connectTo.Payload.Type = WorldPackets::Auth::ConnectTo::IPv4; + } + else + { + memcpy(connectTo.Payload.Where.data(), instanceAddress.to_v6().to_bytes().data(), 16); + connectTo.Payload.Type = WorldPackets::Auth::ConnectTo::IPv6; + } connectTo.Con = CONNECTION_TYPE_INSTANCE; SendPacket(connectTo.Write()); diff --git a/src/server/game/Services/WorldserverService.cpp b/src/server/game/Services/WorldserverService.cpp index 3c468519901..8dabf131e68 100644 --- a/src/server/game/Services/WorldserverService.cpp +++ b/src/server/game/Services/WorldserverService.cpp @@ -21,6 +21,7 @@ #include "RealmList.pb.h" #include "BattlenetRpcErrorCodes.h" #include "ProtobufJSON.h" +#include <boost/asio/ip/address.hpp> #include <zlib.h> Battlenet::GameUtilitiesService::GameUtilitiesService(WorldSession* session) : BaseService(session) |
