aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2017-05-13 11:49:09 +0200
committerShauren <shauren.trinity@gmail.com>2017-05-13 11:49:09 +0200
commitbeb3316089b350a43e917d896e682298df8dcfc0 (patch)
tree8006c52594009f226d834991d101c97057699594 /src/server/shared
parentc00316d3d4b57826cc8e38feed24faf84832c04b (diff)
Core/Shared: Include cleanup
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/DataStores/DB2DatabaseLoader.h5
-rw-r--r--src/server/shared/Dynamic/TypeContainer.h143
-rw-r--r--src/server/shared/Dynamic/TypeContainerFunctions.h217
-rw-r--r--src/server/shared/Dynamic/TypeContainerVisitor.h104
-rw-r--r--src/server/shared/JSON/ProtobufJSON.cpp12
-rw-r--r--src/server/shared/JSON/ProtobufJSON.h11
-rw-r--r--src/server/shared/Networking/AsyncAcceptor.h3
-rw-r--r--src/server/shared/Packets/ByteBuffer.cpp78
-rw-r--r--src/server/shared/Packets/ByteBuffer.h96
-rw-r--r--src/server/shared/PrecompiledHeaders/sharedPCH.h14
-rw-r--r--src/server/shared/Realm/Realm.cpp21
-rw-r--r--src/server/shared/Realm/Realm.h17
-rw-r--r--src/server/shared/Realm/RealmList.cpp40
-rw-r--r--src/server/shared/Realm/RealmList.h35
14 files changed, 181 insertions, 615 deletions
diff --git a/src/server/shared/DataStores/DB2DatabaseLoader.h b/src/server/shared/DataStores/DB2DatabaseLoader.h
index f288b46859b..d7ee8006cb1 100644
--- a/src/server/shared/DataStores/DB2DatabaseLoader.h
+++ b/src/server/shared/DataStores/DB2DatabaseLoader.h
@@ -19,7 +19,10 @@
#define DB2_DATABASE_LOADER_H
#include "DB2FileLoader.h"
-#include "Implementation/HotfixDatabase.h"
+#include <string>
+#include <vector>
+
+enum HotfixDatabaseStatements : uint32;
struct TC_SHARED_API DB2LoadInfo : public DB2FileLoadInfo
{
diff --git a/src/server/shared/Dynamic/TypeContainer.h b/src/server/shared/Dynamic/TypeContainer.h
deleted file mode 100644
index 7e825136755..00000000000
--- a/src/server/shared/Dynamic/TypeContainer.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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/shared/Dynamic/TypeContainerFunctions.h b/src/server/shared/Dynamic/TypeContainerFunctions.h
deleted file mode 100644
index 97d20922a05..00000000000
--- a/src/server/shared/Dynamic/TypeContainerFunctions.h
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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/shared/Dynamic/TypeContainerVisitor.h b/src/server/shared/Dynamic/TypeContainerVisitor.h
deleted file mode 100644
index f15cfe66758..00000000000
--- a/src/server/shared/Dynamic/TypeContainerVisitor.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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/shared/JSON/ProtobufJSON.cpp b/src/server/shared/JSON/ProtobufJSON.cpp
index 68e46f3fd57..dcf7dc0436f 100644
--- a/src/server/shared/JSON/ProtobufJSON.cpp
+++ b/src/server/shared/JSON/ProtobufJSON.cpp
@@ -16,10 +16,10 @@
*/
#include "ProtobufJSON.h"
-#include "StringFormat.h"
-#include "Common.h"
#include "Errors.h"
#include "Log.h"
+#include "StringFormat.h"
+#include <google/protobuf/message.h>
#include <rapidjson/writer.h>
#include <rapidjson/reader.h>
#include <rapidjson/stringbuffer.h>
@@ -186,7 +186,7 @@ void Serializer::WriteRepeatedMessageField(google::protobuf::Message const& valu
class Deserializer : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>, Deserializer>
{
public:
- bool ReadMessage(std::string json, google::protobuf::Message* message);
+ bool ReadMessage(std::string const& json, google::protobuf::Message* message);
bool Key(const Ch* str, rapidjson::SizeType length, bool copy);
bool Null();
@@ -213,7 +213,7 @@ private:
std::vector<std::string> _errors;
};
-bool Deserializer::ReadMessage(std::string json, google::protobuf::Message* message)
+bool Deserializer::ReadMessage(std::string const& json, google::protobuf::Message* message)
{
rapidjson::StringStream ss(json.c_str());
@@ -443,10 +443,10 @@ std::string JSON::Serialize(google::protobuf::Message const& message)
return serializer.GetString();
}
-bool JSON::Deserialize(std::string json, google::protobuf::Message* message)
+bool JSON::Deserialize(std::string const& json, google::protobuf::Message* message)
{
Deserializer deserializer;
- if (!deserializer.ReadMessage(std::forward<std::string>(json), message))
+ if (!deserializer.ReadMessage(json, message))
{
for (std::size_t i = 0; i < deserializer.GetErrors().size(); ++i)
TC_LOG_ERROR("json", "%s", deserializer.GetErrors()[i].c_str());
diff --git a/src/server/shared/JSON/ProtobufJSON.h b/src/server/shared/JSON/ProtobufJSON.h
index 876028e518c..bae1cffc1d6 100644
--- a/src/server/shared/JSON/ProtobufJSON.h
+++ b/src/server/shared/JSON/ProtobufJSON.h
@@ -19,13 +19,20 @@
#define ProtobufJSON_h__
#include "Define.h"
-#include <google/protobuf/message.h>
#include <string>
+namespace google
+{
+ namespace protobuf
+ {
+ class Message;
+ }
+}
+
namespace JSON
{
TC_SHARED_API std::string Serialize(google::protobuf::Message const& message);
- TC_SHARED_API bool Deserialize(std::string json, google::protobuf::Message* message);
+ TC_SHARED_API bool Deserialize(std::string const& json, google::protobuf::Message* message);
}
#endif // ProtobufJSON_h__
diff --git a/src/server/shared/Networking/AsyncAcceptor.h b/src/server/shared/Networking/AsyncAcceptor.h
index 7c827ec4454..dc6c5332c23 100644
--- a/src/server/shared/Networking/AsyncAcceptor.h
+++ b/src/server/shared/Networking/AsyncAcceptor.h
@@ -19,7 +19,8 @@
#define __ASYNCACCEPT_H_
#include "Log.h"
-#include <boost/asio.hpp>
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/ip/address.hpp>
#include <functional>
#include <atomic>
diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp
index efc5e587168..d06e18ff234 100644
--- a/src/server/shared/Packets/ByteBuffer.cpp
+++ b/src/server/shared/Packets/ByteBuffer.cpp
@@ -17,10 +17,12 @@
*/
#include "ByteBuffer.h"
+#include "Errors.h"
#include "MessageBuffer.h"
-#include "Common.h"
#include "Log.h"
+#include "Util.h"
#include <sstream>
+#include <ctime>
ByteBuffer::ByteBuffer(MessageBuffer&& buffer) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0), _storage(buffer.Move())
{
@@ -37,6 +39,80 @@ ByteBufferPositionException::ByteBufferPositionException(size_t pos, size_t size
message().assign(ss.str());
}
+ByteBuffer& ByteBuffer::operator>>(float& value)
+{
+ value = read<float>();
+ if (!std::isfinite(value))
+ throw ByteBufferException();
+ return *this;
+}
+
+ByteBuffer& ByteBuffer::operator>>(double& value)
+{
+ value = read<double>();
+ if (!std::isfinite(value))
+ throw ByteBufferException();
+ return *this;
+}
+
+uint32 ByteBuffer::ReadPackedTime()
+{
+ uint32 packedDate = read<uint32>();
+ tm lt = tm();
+
+ lt.tm_min = packedDate & 0x3F;
+ lt.tm_hour = (packedDate >> 6) & 0x1F;
+ //lt.tm_wday = (packedDate >> 11) & 7;
+ lt.tm_mday = ((packedDate >> 14) & 0x3F) + 1;
+ lt.tm_mon = (packedDate >> 20) & 0xF;
+ lt.tm_year = ((packedDate >> 24) & 0x1F) + 100;
+
+ return uint32(mktime(&lt));
+}
+
+void ByteBuffer::append(const uint8 *src, size_t cnt)
+{
+ ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
+ ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
+ ASSERT(size() < 10000000);
+
+ FlushBits();
+ _storage.insert(_storage.begin() + _wpos, src, src + cnt);
+ _wpos += cnt;
+}
+
+void ByteBuffer::AppendPackedTime(time_t time)
+{
+ tm lt;
+ localtime_r(&time, &lt);
+ append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
+}
+
+void ByteBuffer::put(size_t pos, const uint8 *src, size_t cnt)
+{
+ ASSERT(pos + cnt <= size(), "Attempted to put value with size: " SZFMTD " in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", cnt, pos, size());
+ ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
+ ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
+
+ std::memcpy(&_storage[pos], src, cnt);
+}
+
+void ByteBuffer::PutBits(std::size_t pos, std::size_t value, uint32 bitCount)
+{
+ ASSERT(pos + bitCount <= size() * 8, "Attempted to put %u bits in ByteBuffer (bitpos: " SZFMTD " size: " SZFMTD ")", bitCount, pos, size());
+ ASSERT(bitCount, "Attempted to put a zero bits in ByteBuffer");
+
+ for (uint32 i = 0; i < bitCount; ++i)
+ {
+ std::size_t wp = (pos + i) / 8;
+ std::size_t bit = (pos + i) % 8;
+ if ((value >> (bitCount - i - 1)) & 1)
+ _storage[wp] |= 1 << (7 - bit);
+ else
+ _storage[wp] &= ~(1 << (7 - bit));
+ }
+}
+
void ByteBuffer::print_storage() const
{
if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index 82cc00a0f4e..93c6aaf83f8 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -20,11 +20,10 @@
#define _BYTEBUFFER_H
#include "Define.h"
-#include "Errors.h"
#include "ByteConverter.h"
-#include "Util.h"
+#include <string>
+#include <vector>
#include <cstring>
-#include <ctime>
class MessageBuffer;
@@ -151,7 +150,7 @@ class TC_SHARED_API ByteBuffer
_curbitval = 0;
}
- bool WriteBit(uint32 bit)
+ bool WriteBit(bool bit)
{
--_bitpos;
if (bit)
@@ -164,7 +163,7 @@ class TC_SHARED_API ByteBuffer
_curbitval = 0;
}
- return (bit != 0);
+ return bit;
}
bool ReadBit()
@@ -179,7 +178,7 @@ class TC_SHARED_API ByteBuffer
return ((_curbitval >> (7-_bitpos)) & 1) != 0;
}
- template <typename T> void WriteBits(T value, int32 bits)
+ void WriteBits(std::size_t value, int32 bits)
{
for (int32 i = bits - 1; i >= 0; --i)
WriteBit((value >> i) & 1);
@@ -208,7 +207,8 @@ class TC_SHARED_API ByteBuffer
append<uint8>(b ^ 1);
}
- template <typename T> void put(size_t pos, T value)
+ template <typename T>
+ void put(std::size_t pos, T value)
{
static_assert(std::is_fundamental<T>::value, "append(compound)");
EndianConvert(value);
@@ -227,22 +227,7 @@ class TC_SHARED_API ByteBuffer
* @param value Data to write.
* @param bitCount Number of bits to store the value on.
*/
- template <typename T>
- void PutBits(size_t pos, T value, uint32 bitCount)
- {
- ASSERT(pos + bitCount <= size() * 8, "Attempted to put " SZFMTD " bits in ByteBuffer (bitpos: " SZFMTD " size: " SZFMTD ")", bitCount, pos, size());
- ASSERT(bitCount, "Attempted to put a zero bits in ByteBuffer");
-
- for (uint32 i = 0; i < bitCount; ++i)
- {
- size_t wp = (pos + i) / 8;
- size_t bit = (pos + i) % 8;
- if ((value >> (bitCount - i - 1)) & 1)
- _storage[wp] |= 1 << (7 - bit);
- else
- _storage[wp] &= ~(1 << (7 - bit));
- }
- }
+ void PutBits(std::size_t pos, std::size_t value, uint32 bitCount);
ByteBuffer &operator<<(uint8 value)
{
@@ -377,21 +362,8 @@ class TC_SHARED_API ByteBuffer
return *this;
}
- ByteBuffer &operator>>(float &value)
- {
- value = read<float>();
- if (!std::isfinite(value))
- throw ByteBufferException();
- return *this;
- }
-
- ByteBuffer &operator>>(double &value)
- {
- value = read<double>();
- if (!std::isfinite(value))
- throw ByteBufferException();
- return *this;
- }
+ ByteBuffer &operator>>(float &value);
+ ByteBuffer &operator>>(double &value);
ByteBuffer &operator>>(std::string& value)
{
@@ -531,26 +503,7 @@ class TC_SHARED_API ByteBuffer
append(str, len);
}
- uint32 ReadPackedTime()
- {
- uint32 packedDate = read<uint32>();
- tm lt = tm();
-
- lt.tm_min = packedDate & 0x3F;
- lt.tm_hour = (packedDate >> 6) & 0x1F;
- //lt.tm_wday = (packedDate >> 11) & 7;
- lt.tm_mday = ((packedDate >> 14) & 0x3F) + 1;
- lt.tm_mon = (packedDate >> 20) & 0xF;
- lt.tm_year = ((packedDate >> 24) & 0x1F) + 100;
-
- return uint32(mktime(&lt));
- }
-
- ByteBuffer& ReadPackedTime(uint32& time)
- {
- time = ReadPackedTime();
- return *this;
- }
+ uint32 ReadPackedTime();
uint8* contents()
{
@@ -592,16 +545,7 @@ class TC_SHARED_API ByteBuffer
return append((const uint8 *)src, cnt * sizeof(T));
}
- void append(const uint8 *src, size_t cnt)
- {
- ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
- ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", _wpos, size());
- ASSERT(size() < 10000000);
-
- FlushBits();
- _storage.insert(_storage.begin() + _wpos, src, src + cnt);
- _wpos += cnt;
- }
+ void append(const uint8 *src, size_t cnt);
void append(const ByteBuffer& buffer)
{
@@ -652,21 +596,9 @@ class TC_SHARED_API ByteBuffer
return resultSize;
}
- void AppendPackedTime(time_t time)
- {
- tm lt;
- localtime_r(&time, &lt);
- append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
- }
-
- void put(size_t pos, const uint8 *src, size_t cnt)
- {
- ASSERT(pos + cnt <= size(), "Attempted to put value with size: " SZFMTD " in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", cnt, pos, size());
- ASSERT(src, "Attempted to put a NULL-pointer in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
- ASSERT(cnt, "Attempted to put a zero-sized value in ByteBuffer (pos: " SZFMTD " size: " SZFMTD ")", pos, size());
+ void AppendPackedTime(time_t time);
- std::memcpy(&_storage[pos], src, cnt);
- }
+ void put(size_t pos, const uint8 *src, size_t cnt);
void print_storage() const;
diff --git a/src/server/shared/PrecompiledHeaders/sharedPCH.h b/src/server/shared/PrecompiledHeaders/sharedPCH.h
index d99476bc7a8..b2b6b602297 100644
--- a/src/server/shared/PrecompiledHeaders/sharedPCH.h
+++ b/src/server/shared/PrecompiledHeaders/sharedPCH.h
@@ -1,10 +1,12 @@
//add here most rarely modified headers to speed up debug build compilation
#include "Common.h"
-#include "Log.h"
-#include "DatabaseWorker.h"
-#include "SQLOperation.h"
+#include "DB2Meta.h"
+#include "Define.h"
#include "Errors.h"
-#include "TypeList.h"
-#include "TaskScheduler.h"
-#include "EventMap.h"
+#include "Log.h"
+#include <boost/asio/ip/tcp.hpp>
+#include <atomic>
+#include <memory>
+#include <string>
+#include <vector>
diff --git a/src/server/shared/Realm/Realm.cpp b/src/server/shared/Realm/Realm.cpp
index 85438bcf151..45e5b445297 100644
--- a/src/server/shared/Realm/Realm.cpp
+++ b/src/server/shared/Realm/Realm.cpp
@@ -17,40 +17,39 @@
#include "Realm.h"
#include "StringFormat.h"
+#include <boost/asio/ip/address.hpp>
-ip::tcp::endpoint Realm::GetAddressForClient(ip::address const& clientAddr) const
+boost::asio::ip::address Realm::GetAddressForClient(boost::asio::ip::address const& clientAddr) const
{
- ip::address realmIp;
+ boost::asio::ip::address realmIp;
// Attempt to send best address for client
if (clientAddr.is_loopback())
{
// Try guessing if realm is also connected locally
- if (LocalAddress.is_loopback() || ExternalAddress.is_loopback())
+ if (LocalAddress->is_loopback() || ExternalAddress->is_loopback())
realmIp = clientAddr;
else
{
// Assume that user connecting from the machine that bnetserver is located on
// has all realms available in his local network
- realmIp = LocalAddress;
+ realmIp = *LocalAddress;
}
}
else
{
if (clientAddr.is_v4() &&
- (clientAddr.to_v4().to_ulong() & LocalSubnetMask.to_v4().to_ulong()) ==
- (LocalAddress.to_v4().to_ulong() & LocalSubnetMask.to_v4().to_ulong()))
+ (clientAddr.to_v4().to_ulong() & LocalSubnetMask->to_v4().to_ulong()) ==
+ (LocalAddress->to_v4().to_ulong() & LocalSubnetMask->to_v4().to_ulong()))
{
- realmIp = LocalAddress;
+ realmIp = *LocalAddress;
}
else
- realmIp = ExternalAddress;
+ realmIp = *ExternalAddress;
}
- ip::tcp::endpoint endpoint(realmIp, Port);
-
// Return external IP
- return endpoint;
+ return realmIp;
}
uint32 Realm::GetConfigId() const
diff --git a/src/server/shared/Realm/Realm.h b/src/server/shared/Realm/Realm.h
index 94a752357b2..21675fe149b 100644
--- a/src/server/shared/Realm/Realm.h
+++ b/src/server/shared/Realm/Realm.h
@@ -19,10 +19,7 @@
#define Realm_h__
#include "Common.h"
-#include <boost/asio/ip/address.hpp>
-#include <boost/asio/ip/tcp.hpp>
-
-using namespace boost::asio;
+#include "AsioHacksFwd.h"
enum RealmFlags
{
@@ -37,8 +34,6 @@ enum RealmFlags
REALM_FLAG_FULL = 0x80
};
-#pragma pack(push, 1)
-
namespace Battlenet
{
struct TC_SHARED_API RealmHandle
@@ -63,8 +58,6 @@ namespace Battlenet
};
}
-#pragma pack(pop)
-
/// Type of server, this is values from second column of Cfg_Configs.dbc
enum RealmType
{
@@ -85,9 +78,9 @@ struct TC_SHARED_API Realm
{
Battlenet::RealmHandle Id;
uint32 Build;
- ip::address ExternalAddress;
- ip::address LocalAddress;
- ip::address LocalSubnetMask;
+ std::unique_ptr<boost::asio::ip::address> ExternalAddress;
+ std::unique_ptr<boost::asio::ip::address> LocalAddress;
+ std::unique_ptr<boost::asio::ip::address> LocalSubnetMask;
uint16 Port;
std::string Name;
uint8 Type;
@@ -96,7 +89,7 @@ struct TC_SHARED_API Realm
AccountTypes AllowedSecurityLevel;
float PopulationLevel;
- ip::tcp::endpoint GetAddressForClient(ip::address const& clientAddr) const;
+ boost::asio::ip::address GetAddressForClient(boost::asio::ip::address const& clientAddr) const;
uint32 GetConfigId() const;
static uint32 const ConfigIdByType[MAX_CLIENT_REALM_TYPE];
diff --git a/src/server/shared/Realm/RealmList.cpp b/src/server/shared/Realm/RealmList.cpp
index c949490c63f..93bb4fc98ff 100644
--- a/src/server/shared/Realm/RealmList.cpp
+++ b/src/server/shared/Realm/RealmList.cpp
@@ -18,23 +18,25 @@
#include "RealmList.h"
#include "BattlenetRpcErrorCodes.h"
+#include "BigNumber.h"
#include "DatabaseEnv.h"
+#include "Errors.h"
#include "Log.h"
#include "ProtobufJSON.h"
#include "SHA256.h"
-#include "BigNumber.h"
#include "Util.h"
#include "game_utilities_service.pb.h"
#include "RealmList.pb.h"
+#include <boost/asio/deadline_timer.hpp>
+#include <boost/asio/ip/tcp.hpp>
#include <zlib.h>
-RealmList::RealmList() : _updateInterval(0), _updateTimer(nullptr), _resolver(nullptr)
+RealmList::RealmList() : _updateInterval(0)
{
}
RealmList::~RealmList()
{
- delete _updateTimer;
}
RealmList* RealmList::Instance()
@@ -47,8 +49,8 @@ RealmList* RealmList::Instance()
void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval)
{
_updateInterval = updateInterval;
- _updateTimer = new boost::asio::deadline_timer(ioService);
- _resolver = new boost::asio::ip::tcp::resolver(ioService);
+ _updateTimer = Trinity::make_unique<boost::asio::deadline_timer>(ioService);
+ _resolver = Trinity::make_unique<boost::asio::ip::tcp::resolver>(ioService);
// Get the content of the realmlist table in the database
UpdateRealms(boost::system::error_code());
@@ -59,8 +61,9 @@ void RealmList::Close()
_updateTimer->cancel();
}
-void RealmList::UpdateRealm(Battlenet::RealmHandle const& id, uint32 build, const std::string& name, ip::address const& address, ip::address const& localAddr,
- ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel,
+void RealmList::UpdateRealm(Battlenet::RealmHandle const& id, uint32 build, std::string const& name,
+ boost::asio::ip::address const& address, boost::asio::ip::address const& localAddr, boost::asio::ip::address const& localSubmask,
+ uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel,
float population)
{
// Create new if not exist or update existed
@@ -74,9 +77,12 @@ void RealmList::UpdateRealm(Battlenet::RealmHandle const& id, uint32 build, cons
realm.Timezone = timezone;
realm.AllowedSecurityLevel = allowedSecurityLevel;
realm.PopulationLevel = population;
- realm.ExternalAddress = address;
- realm.LocalAddress = localAddr;
- realm.LocalSubnetMask = localSubmask;
+ if (!realm.ExternalAddress || *realm.ExternalAddress != address)
+ realm.ExternalAddress = Trinity::make_unique<boost::asio::ip::address>(address);
+ if (!realm.LocalAddress || *realm.LocalAddress != localAddr)
+ realm.LocalAddress = Trinity::make_unique<boost::asio::ip::address>(localAddr);
+ if (!realm.LocalSubnetMask || *realm.LocalSubnetMask != localSubmask)
+ realm.LocalSubnetMask = Trinity::make_unique<boost::asio::ip::address>(localSubmask);
realm.Port = port;
}
@@ -108,7 +114,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
Field* fields = result->Fetch();
uint32 realmId = fields[0].GetUInt32();
std::string name = fields[1].GetString();
- boost::asio::ip::tcp::resolver::query externalAddressQuery(ip::tcp::v4(), fields[2].GetString(), "");
+ boost::asio::ip::tcp::resolver::query externalAddressQuery(boost::asio::ip::tcp::v4(), fields[2].GetString(), "");
boost::system::error_code ec;
boost::asio::ip::tcp::resolver::iterator endPoint = _resolver->resolve(externalAddressQuery, ec);
@@ -118,9 +124,9 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
continue;
}
- ip::address externalAddress = (*endPoint).endpoint().address();
+ boost::asio::ip::address externalAddress = endPoint->endpoint().address();
- boost::asio::ip::tcp::resolver::query localAddressQuery(ip::tcp::v4(), fields[3].GetString(), "");
+ boost::asio::ip::tcp::resolver::query localAddressQuery(boost::asio::ip::tcp::v4(), fields[3].GetString(), "");
endPoint = _resolver->resolve(localAddressQuery, ec);
if (endPoint == end || ec)
{
@@ -128,9 +134,9 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
continue;
}
- ip::address localAddress = (*endPoint).endpoint().address();
+ boost::asio::ip::address localAddress = endPoint->endpoint().address();
- boost::asio::ip::tcp::resolver::query localSubmaskQuery(ip::tcp::v4(), fields[4].GetString(), "");
+ boost::asio::ip::tcp::resolver::query localSubmaskQuery(boost::asio::ip::tcp::v4(), fields[4].GetString(), "");
endPoint = _resolver->resolve(localSubmaskQuery, ec);
if (endPoint == end || ec)
{
@@ -138,7 +144,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
continue;
}
- ip::address localSubmask = (*endPoint).endpoint().address();
+ boost::asio::ip::address localSubmask = endPoint->endpoint().address();
uint16 port = fields[5].GetUInt16();
uint8 icon = fields[6].GetUInt8();
@@ -355,7 +361,7 @@ uint32 RealmList::JoinRealm(uint32 realmAddress, uint32 build, boost::asio::ip::
addressFamily->set_family(1);
JSON::RealmList::IPAddress* address = addressFamily->add_addresses();
- address->set_ip(realm->GetAddressForClient(clientAddress).address().to_string());
+ address->set_ip(realm->GetAddressForClient(clientAddress).to_string());
address->set_port(realm->Port);
std::string json = "JSONRealmListServerIPAddresses:" + JSON::Serialize(serverAddresses);
diff --git a/src/server/shared/Realm/RealmList.h b/src/server/shared/Realm/RealmList.h
index 594ca2bf1f6..de16bfdceff 100644
--- a/src/server/shared/Realm/RealmList.h
+++ b/src/server/shared/Realm/RealmList.h
@@ -19,15 +19,12 @@
#ifndef _REALMLIST_H
#define _REALMLIST_H
-#include "Common.h"
-#include "Realm/Realm.h"
-#include <boost/asio/ip/address.hpp>
-#include <boost/asio/ip/tcp.hpp>
-#include <boost/asio/io_service.hpp>
-#include <boost/asio/deadline_timer.hpp>
+#include "Define.h"
+#include "Realm.h"
+#include <map>
+#include <vector>
+#include <unordered_set>
#include <unordered_set>
-
-using namespace boost::asio;
struct RealmBuildInfo
{
@@ -38,6 +35,19 @@ struct RealmBuildInfo
uint32 HotfixVersion;
};
+namespace boost
+{
+ namespace asio
+ {
+ class io_service;
+ }
+
+ namespace system
+ {
+ class error_code;
+ }
+}
+
namespace bgs
{
namespace protocol
@@ -89,14 +99,15 @@ private:
RealmList();
void UpdateRealms(boost::system::error_code const& error);
- void UpdateRealm(Battlenet::RealmHandle const& id, uint32 build, const std::string& name, ip::address const& address, ip::address const& localAddr,
- ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population);
+ void UpdateRealm(Battlenet::RealmHandle const& id, uint32 build, std::string const& name,
+ boost::asio::ip::address const& address, boost::asio::ip::address const& localAddr, boost::asio::ip::address const& localSubmask,
+ uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population);
RealmMap _realms;
std::unordered_set<std::string> _subRegions;
uint32 _updateInterval;
- boost::asio::deadline_timer* _updateTimer;
- boost::asio::ip::tcp::resolver* _resolver;
+ std::unique_ptr<boost::asio::deadline_timer> _updateTimer;
+ std::unique_ptr<boost::asio::ip::tcp_resolver> _resolver;
};
#define sRealmList RealmList::Instance()