diff options
Diffstat (limited to 'src')
45 files changed, 468 insertions, 336 deletions
diff --git a/src/common/Utilities/AsioHacksFwd.h b/src/common/Utilities/AsioHacksFwd.h index 6d4c9f5a3ed..402c390f4f0 100644 --- a/src/common/Utilities/AsioHacksFwd.h +++ b/src/common/Utilities/AsioHacksFwd.h @@ -27,6 +27,26 @@ namespace boost namespace asio { + namespace ip + { + class address; + + class tcp; + + template <typename InternetProtocol> + class basic_endpoint; + + typedef basic_endpoint<tcp> tcp_endpoint; + + template <typename InternetProtocol> + class resolver_service; + + template <typename InternetProtocol, typename ResolverService> + class basic_resolver; + + typedef basic_resolver<tcp, resolver_service<tcp>> tcp_resolver; + } + template <typename Time> struct time_traits; diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp index 9d598d63b61..5957ae980aa 100644 --- a/src/server/bnetserver/Main.cpp +++ b/src/server/bnetserver/Main.cpp @@ -36,10 +36,12 @@ #include "SessionManager.h" #include "SslContext.h" #include "Util.h" +#include <boost/asio/signal_set.hpp> #include <boost/program_options.hpp> #include <boost/filesystem/operations.hpp> #include <google/protobuf/stubs/common.h> #include <iostream> +#include <csignal> using boost::asio::ip::tcp; using namespace boost::program_options; diff --git a/src/server/bnetserver/Server/Session.cpp b/src/server/bnetserver/Server/Session.cpp index a504b6a85ea..1c7d4aed521 100644 --- a/src/server/bnetserver/Server/Session.cpp +++ b/src/server/bnetserver/Server/Session.cpp @@ -78,7 +78,7 @@ Battlenet::Session::~Session() void Battlenet::Session::AsyncHandshake() { - underlying_stream().async_handshake(ssl::stream_base::server, std::bind(&Session::HandshakeHandler, shared_from_this(), std::placeholders::_1)); + underlying_stream().async_handshake(boost::asio::ssl::stream_base::server, std::bind(&Session::HandshakeHandler, shared_from_this(), std::placeholders::_1)); } void Battlenet::Session::Start() @@ -229,7 +229,7 @@ uint32 Battlenet::Session::HandleLogon(authentication::v1::LogonRequest const* l _locale = logonRequest->locale(); _os = logonRequest->platform(); - ip::tcp::endpoint const& endpoint = sLoginService.GetAddressForClient(GetRemoteIpAddress()); + boost::asio::ip::tcp::endpoint const& endpoint = sLoginService.GetAddressForClient(GetRemoteIpAddress()); challenge::v1::ChallengeExternalRequest externalChallenge; externalChallenge.set_payload_type("web_auth_url"); 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/shared/Dynamic/TypeContainer.h b/src/server/game/Grids/Dynamic/TypeContainer.h index 7e825136755..7e825136755 100644 --- a/src/server/shared/Dynamic/TypeContainer.h +++ b/src/server/game/Grids/Dynamic/TypeContainer.h diff --git a/src/server/shared/Dynamic/TypeContainerFunctions.h b/src/server/game/Grids/Dynamic/TypeContainerFunctions.h index 97d20922a05..97d20922a05 100644 --- a/src/server/shared/Dynamic/TypeContainerFunctions.h +++ b/src/server/game/Grids/Dynamic/TypeContainerFunctions.h diff --git a/src/server/shared/Dynamic/TypeContainerVisitor.h b/src/server/game/Grids/Dynamic/TypeContainerVisitor.h index f15cfe66758..f15cfe66758 100644 --- a/src/server/shared/Dynamic/TypeContainerVisitor.h +++ b/src/server/game/Grids/Dynamic/TypeContainerVisitor.h 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) diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index 3b6010d4283..5c8332beba8 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -28,6 +28,7 @@ EndScriptData */ #include "Log.h" #include "Player.h" #include "ScriptMgr.h" +#include <boost/asio/ip/address_v4.hpp> class account_commandscript : public CommandScript { @@ -287,7 +288,7 @@ public: if (param == "on") { PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LOGON_COUNTRY); - uint32 ip = inet_addr(handler->GetSession()->GetRemoteAddress().c_str()); + uint32 ip = boost::asio::ip::address_v4::from_string(handler->GetSession()->GetRemoteAddress()).to_ulong(); EndianConvertReverse(ip); stmt->setUInt32(0, ip); PreparedQueryResult result = LoginDatabase.Query(stmt); diff --git a/src/server/scripts/Commands/cs_battlenet_account.cpp b/src/server/scripts/Commands/cs_battlenet_account.cpp index 64d4647e8bf..c62db6d774b 100644 --- a/src/server/scripts/Commands/cs_battlenet_account.cpp +++ b/src/server/scripts/Commands/cs_battlenet_account.cpp @@ -23,6 +23,7 @@ #include "Player.h" #include "ScriptMgr.h" #include "Util.h" +#include <boost/asio/ip/address_v4.hpp> class battlenet_account_commandscript : public CommandScript { @@ -140,7 +141,7 @@ public: if (param == "on") { PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LOGON_COUNTRY); - uint32 ip = inet_addr(handler->GetSession()->GetRemoteAddress().c_str()); + uint32 ip = boost::asio::ip::address_v4::from_string(handler->GetSession()->GetRemoteAddress()).to_ulong(); EndianConvertReverse(ip); stmt->setUInt32(0, ip); PreparedQueryResult result = LoginDatabase.Query(stmt); diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index 678c7342eda..470119122fb 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -41,6 +41,7 @@ #include "MiscPackets.h" #include "Transport.h" #include "MapManager.h" +#include <boost/asio/ip/address_v4.hpp> // temporary hack until database includes are sorted out (don't want to pull in Windows.h everywhere from mysql.h) #ifdef GetClassName @@ -1774,7 +1775,7 @@ public: lastIp = fields[4].GetString(); lastLogin = fields[5].GetString(); - uint32 ip = inet_addr(lastIp.c_str()); + uint32 ip = boost::asio::ip::address_v4::from_string(lastIp).to_ulong();; EndianConvertReverse(ip); // If ip2nation table is populated, it displays the country 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/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(<)); +} + +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, <); + 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(<)); - } - - 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, <); - 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() diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 12a8631f324..08cb7cd58c9 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -52,9 +52,11 @@ #include <openssl/crypto.h> #include <boost/asio/io_service.hpp> #include <boost/asio/deadline_timer.hpp> +#include <boost/asio/signal_set.hpp> #include <boost/filesystem/operations.hpp> #include <boost/program_options.hpp> #include <google/protobuf/stubs/common.h> +#include <csignal> using namespace boost::program_options; namespace fs = boost::filesystem; @@ -107,7 +109,7 @@ void StopDB(); void WorldUpdateLoop(); void ClearOnlineAccounts(); void ShutdownCLIThread(std::thread* cliThread); -bool LoadRealmInfo(boost::asio::io_service& ioService); +bool LoadRealmInfo(); variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& cfg_service); /// Launch the Trinity server @@ -226,7 +228,7 @@ extern int main(int argc, char** argv) std::shared_ptr<void> sRealmListHandle(nullptr, [](void*) { sRealmList->Close(); }); - LoadRealmInfo(*ioService); + LoadRealmInfo(); sMetric->Initialize(realm.Name, *ioService, []() { @@ -509,59 +511,26 @@ AsyncAcceptor* StartRaSocketAcceptor(boost::asio::io_service& ioService) return acceptor; } -bool LoadRealmInfo(boost::asio::io_service& ioService) +bool LoadRealmInfo() { - boost::asio::ip::tcp::resolver resolver(ioService); - boost::asio::ip::tcp::resolver::iterator end; - - QueryResult result = LoginDatabase.PQuery("SELECT id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild, Region, Battlegroup FROM realmlist WHERE id = %u", realm.Id.Realm); - if (!result) - return false; - - Field* fields = result->Fetch(); - realm.Name = fields[1].GetString(); - boost::asio::ip::tcp::resolver::query externalAddressQuery(ip::tcp::v4(), fields[2].GetString(), ""); - - boost::system::error_code ec; - boost::asio::ip::tcp::resolver::iterator endPoint = resolver.resolve(externalAddressQuery, ec); - if (endPoint == end || ec) - { - TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[2].GetString().c_str()); - return false; - } - - realm.ExternalAddress = (*endPoint).endpoint().address(); - - boost::asio::ip::tcp::resolver::query localAddressQuery(ip::tcp::v4(), fields[3].GetString(), ""); - endPoint = resolver.resolve(localAddressQuery, ec); - if (endPoint == end || ec) - { - TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[3].GetString().c_str()); - return false; - } - - realm.LocalAddress = (*endPoint).endpoint().address(); - - boost::asio::ip::tcp::resolver::query localSubmaskQuery(ip::tcp::v4(), fields[4].GetString(), ""); - endPoint = resolver.resolve(localSubmaskQuery, ec); - if (endPoint == end || ec) + if (Realm const* realmListRealm = sRealmList->GetRealm(realm.Id)) { - TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[4].GetString().c_str()); - return false; + realm.Id = realmListRealm->Id; + realm.Build = realmListRealm->Build; + realm.ExternalAddress = Trinity::make_unique<boost::asio::ip::address>(*realmListRealm->ExternalAddress); + realm.LocalAddress = Trinity::make_unique<boost::asio::ip::address>(*realmListRealm->LocalAddress); + realm.LocalSubnetMask = Trinity::make_unique<boost::asio::ip::address>(*realmListRealm->LocalSubnetMask); + realm.Port = realmListRealm->Port; + realm.Name = realmListRealm->Name; + realm.Type = realmListRealm->Type; + realm.Flags = realmListRealm->Flags; + realm.Timezone = realmListRealm->Timezone; + realm.AllowedSecurityLevel = realmListRealm->AllowedSecurityLevel; + realm.PopulationLevel = realmListRealm->PopulationLevel; + return true; } - realm.LocalSubnetMask = (*endPoint).endpoint().address(); - - realm.Port = fields[5].GetUInt16(); - realm.Type = fields[6].GetUInt8(); - realm.Flags = RealmFlags(fields[7].GetUInt8()); - realm.Timezone = fields[8].GetUInt8(); - realm.AllowedSecurityLevel = AccountTypes(fields[9].GetUInt8()); - realm.PopulationLevel = fields[10].GetFloat(); - realm.Id.Region = fields[12].GetUInt8(); - realm.Id.Site = fields[13].GetUInt8(); - realm.Build = fields[11].GetUInt32(); - return true; + return false; } /// Initialize connection to the databases diff --git a/src/server/worldserver/RemoteAccess/RASession.cpp b/src/server/worldserver/RemoteAccess/RASession.cpp index 96a62f20d21..5957c6e6c57 100644 --- a/src/server/worldserver/RemoteAccess/RASession.cpp +++ b/src/server/worldserver/RemoteAccess/RASession.cpp @@ -16,16 +16,17 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <memory> -#include <boost/asio/write.hpp> -#include <boost/asio/read_until.hpp> -#include <boost/array.hpp> #include "RASession.h" #include "AccountMgr.h" -#include "Log.h" +#include "Config.h" #include "DatabaseEnv.h" +#include "Log.h" +#include "Util.h" #include "World.h" -#include "Config.h" +#include <boost/asio/write.hpp> +#include <boost/asio/read_until.hpp> +#include <array> +#include <memory> using boost::asio::ip::tcp; @@ -39,7 +40,7 @@ void RASession::Start() if (_socket.available() > 0) { // Handle subnegotiation - boost::array<char, 1024> buf; + std::array<char, 1024> buf; _socket.read_some(boost::asio::buffer(buf)); // Send the end-of-negotiation packet |