aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-10-17 22:48:06 +0200
committerShauren <shauren.trinity@gmail.com>2014-10-17 22:48:06 +0200
commitf773a9e05340d4de7dd16d0e375a12611c3995b6 (patch)
tree37ff1c708f636216d618cd0e7bf51ec140582ac0 /src
parent40cff79b253869ce16f4e6870380a1b63dcbe664 (diff)
Core: Implemented IPC (Inter-process communication) between worldserver and bnetserver using ZeroMQ library.
* Implemented ToonReady and ToonLoggedOut battle.net packets
Diffstat (limited to 'src')
-rw-r--r--src/server/CMakeLists.txt1
-rw-r--r--src/server/bnetserver/CMakeLists.txt6
-rw-r--r--src/server/bnetserver/Main.cpp16
-rw-r--r--src/server/bnetserver/Packets/BitStream.h12
-rw-r--r--src/server/bnetserver/Packets/FriendsPackets.cpp2
-rw-r--r--src/server/bnetserver/Packets/PacketManager.cpp4
-rw-r--r--src/server/bnetserver/Packets/WoWRealmPackets.cpp52
-rw-r--r--src/server/bnetserver/Packets/WoWRealmPackets.h27
-rw-r--r--src/server/bnetserver/Realms/RealmList.cpp24
-rw-r--r--src/server/bnetserver/Realms/RealmList.h11
-rw-r--r--src/server/bnetserver/Realms/WorldListener.cpp109
-rw-r--r--src/server/bnetserver/Realms/WorldListener.h63
-rw-r--r--src/server/bnetserver/Server/Session.h2
-rw-r--r--src/server/bnetserver/Server/SessionManager.cpp19
-rw-r--r--src/server/bnetserver/Server/SessionManager.h3
-rw-r--r--src/server/bnetserver/bnetserver.conf.dist7
-rw-r--r--src/server/collision/CMakeLists.txt1
-rw-r--r--src/server/game/AuctionHouse/AuctionHouseMgr.cpp2
-rw-r--r--src/server/game/CMakeLists.txt3
-rw-r--r--src/server/game/Chat/Chat.cpp2
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp7
-rw-r--r--src/server/game/Handlers/MiscHandler.cpp2
-rw-r--r--src/server/game/Server/BattlenetServerManager.cpp66
-rw-r--r--src/server/game/Server/BattlenetServerManager.h55
-rw-r--r--src/server/game/Server/WorldSession.cpp12
-rw-r--r--src/server/game/Server/WorldSocket.cpp4
-rw-r--r--src/server/game/World/World.cpp12
-rw-r--r--src/server/game/World/World.h3
-rw-r--r--src/server/ipc/CMakeLists.txt24
-rw-r--r--src/server/ipc/Commands.cpp81
-rw-r--r--src/server/ipc/Commands.h83
-rw-r--r--src/server/ipc/ZMQTask.cpp93
-rw-r--r--src/server/ipc/ZMQTask.h52
-rw-r--r--src/server/ipc/ZmqContext.cpp52
-rw-r--r--src/server/ipc/ZmqContext.h55
-rw-r--r--src/server/ipc/ZmqListener.cpp69
-rw-r--r--src/server/ipc/ZmqListener.h51
-rw-r--r--src/server/ipc/ZmqMux.cpp67
-rw-r--r--src/server/ipc/ZmqMux.h47
-rw-r--r--src/server/ipc/ZmqWorker.cpp70
-rw-r--r--src/server/ipc/ZmqWorker.h44
-rw-r--r--src/server/scripts/CMakeLists.txt1
-rw-r--r--src/server/scripts/Commands/cs_gm.cpp2
-rw-r--r--src/server/scripts/Commands/cs_misc.cpp2
-rw-r--r--src/server/scripts/Commands/cs_rbac.cpp2
-rw-r--r--src/server/scripts/Commands/cs_ticket.cpp6
-rw-r--r--src/server/worldserver/CMakeLists.txt6
-rw-r--r--src/server/worldserver/Main.cpp49
-rw-r--r--src/server/worldserver/worldserver.conf.dist21
49 files changed, 1336 insertions, 68 deletions
diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt
index ea2ad3abac7..e691b9527a5 100644
--- a/src/server/CMakeLists.txt
+++ b/src/server/CMakeLists.txt
@@ -25,6 +25,7 @@ if( SERVERS )
add_subdirectory(game)
add_subdirectory(collision)
add_subdirectory(authserver)
+ add_subdirectory(ipc)
add_subdirectory(bnetserver)
add_subdirectory(scripts)
add_subdirectory(worldserver)
diff --git a/src/server/bnetserver/CMakeLists.txt b/src/server/bnetserver/CMakeLists.txt
index 9d99ac7f0c5..5b854018d47 100644
--- a/src/server/bnetserver/CMakeLists.txt
+++ b/src/server/bnetserver/CMakeLists.txt
@@ -45,6 +45,7 @@ endif()
include_directories(
${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/dep/zmqpp
${CMAKE_SOURCE_DIR}/src/server/shared
${CMAKE_SOURCE_DIR}/src/server/shared/Configuration
${CMAKE_SOURCE_DIR}/src/server/shared/Database
@@ -56,6 +57,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/shared/Networking
${CMAKE_SOURCE_DIR}/src/server/shared/Threading
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
+ ${CMAKE_SOURCE_DIR}/src/server/ipc
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/Authentication
${CMAKE_CURRENT_SOURCE_DIR}/Realms
@@ -64,6 +66,7 @@ include_directories(
${MYSQL_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${VALGRIND_INCLUDE_DIR}
+ ${ZMQ_INCLUDE_DIR}
)
add_executable(bnetserver
@@ -80,9 +83,12 @@ if( NOT WIN32 )
endif()
target_link_libraries(bnetserver
+ ipc
shared
+ zmqpp
${MYSQL_LIBRARY}
${OPENSSL_LIBRARIES}
+ ${ZMQ_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES}
)
diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp
index ff891304bd3..ce90019c011 100644
--- a/src/server/bnetserver/Main.cpp
+++ b/src/server/bnetserver/Main.cpp
@@ -35,6 +35,7 @@
#include "RealmList.h"
#include "SystemConfig.h"
#include "Util.h"
+#include "ZmqContext.h"
#include <cstdlib>
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -94,12 +95,21 @@ int main(int argc, char** argv)
}
}
+ int32 worldListenPort = sConfigMgr->GetIntDefault("WorldserverListenPort", 1118);
+ if (worldListenPort < 0 || worldListenPort > 0xFFFF)
+ {
+ TC_LOG_ERROR("server.bnetserver", "Specified worldserver listen port (%d) out of allowed range (1-65535)", worldListenPort);
+ return 1;
+ }
+
// Initialize the database connection
if (!StartDB())
return 1;
+ sIpcContext->Initialize();
+
// Get the list of realms for the server
- sRealmList->Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10));
+ sRealmList->Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10), worldListenPort);
// Start the listening port (acceptor) for auth connections
int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119);
@@ -135,6 +145,10 @@ int main(int argc, char** argv)
// Start the io service worker loop
_ioService.run();
+ sIpcContext->Close();
+
+ sRealmList->Close();
+
// Close the Database Pool and library
StopDB();
diff --git a/src/server/bnetserver/Packets/BitStream.h b/src/server/bnetserver/Packets/BitStream.h
index 952ec5a39e2..54c61ab3bbf 100644
--- a/src/server/bnetserver/Packets/BitStream.h
+++ b/src/server/bnetserver/Packets/BitStream.h
@@ -212,14 +212,6 @@ namespace Battlenet
}
}
- void SetReadPos(uint32 bits)
- {
- if (bits > _writePos)
- throw BitStreamPositionException(true, bits, 0, _writePos);
-
- _readPos = bits;
- }
-
bool IsRead() const { return _readPos >= _writePos; }
uint8* GetBuffer() { return _buffer.data(); }
@@ -227,6 +219,10 @@ namespace Battlenet
size_t GetSize() const { return ((_writePos + 7) & ~7) / 8; }
+ // These methods are meant to only be used when their corresponding actions in the client ignore the value completely
+ void ReadSkip(uint32 bitCount) { _readPos += bitCount; }
+ void WriteSkip(uint32 bitCount) { Write(0, bitCount); }
+
private:
uint32 _writePos;
uint32 _readPos;
diff --git a/src/server/bnetserver/Packets/FriendsPackets.cpp b/src/server/bnetserver/Packets/FriendsPackets.cpp
index 14c5fb3a665..2659ec6204f 100644
--- a/src/server/bnetserver/Packets/FriendsPackets.cpp
+++ b/src/server/bnetserver/Packets/FriendsPackets.cpp
@@ -132,7 +132,7 @@ std::string Battlenet::Friends::SocialNetworkCheckConnectedResult::ToString() co
void Battlenet::Friends::SocialNetworkCheckConnectedResult::Write()
{
- _stream.Write(0, 23); // Ignored
+ _stream.WriteSkip(23);
_stream.Write(Result, 16);
_stream.Write(SocialNetworkId, 32);
}
diff --git a/src/server/bnetserver/Packets/PacketManager.cpp b/src/server/bnetserver/Packets/PacketManager.cpp
index 019cf48ac30..e18f3dc5ffb 100644
--- a/src/server/bnetserver/Packets/PacketManager.cpp
+++ b/src/server/bnetserver/Packets/PacketManager.cpp
@@ -115,8 +115,8 @@ void Battlenet::PacketManager::RegisterWoWRealmPackets()
REGISTER_SERVER_PACKET(PacketHeader(WoWRealm::SMSG_LIST_SUBSCRIBE_RESPONSE, WOWREALM), WoWRealm::ListSubscribeResponse);
REGISTER_SERVER_PACKET(PacketHeader(WoWRealm::SMSG_LIST_UPDATE, WOWREALM), WoWRealm::ListUpdate);
REGISTER_SERVER_PACKET(PacketHeader(WoWRealm::SMSG_LIST_COMPLETE, WOWREALM), WoWRealm::ListComplete);
- REGISTER_SERVER_PACKET_NAME(PacketHeader(WoWRealm::SMSG_TOON_READY, WOWREALM), "WoWRealm::ToonReady");
- REGISTER_SERVER_PACKET_NAME(PacketHeader(WoWRealm::SMSG_TOON_LOGGED_OUT, WOWREALM), "WoWRealm::ToonLoggedOut");
+ REGISTER_SERVER_PACKET(PacketHeader(WoWRealm::SMSG_TOON_READY, WOWREALM), WoWRealm::ToonReady);
+ REGISTER_SERVER_PACKET(PacketHeader(WoWRealm::SMSG_TOON_LOGGED_OUT, WOWREALM), WoWRealm::ToonLoggedOut);
REGISTER_SERVER_PACKET(PacketHeader(WoWRealm::SMSG_JOIN_RESPONSE_V2, WOWREALM), WoWRealm::JoinResponseV2);
}
diff --git a/src/server/bnetserver/Packets/WoWRealmPackets.cpp b/src/server/bnetserver/Packets/WoWRealmPackets.cpp
index beeeb14895c..986152cbccb 100644
--- a/src/server/bnetserver/Packets/WoWRealmPackets.cpp
+++ b/src/server/bnetserver/Packets/WoWRealmPackets.cpp
@@ -40,6 +40,26 @@ void Battlenet::WoWRealm::ListUnsubscribe::CallHandler(Session* session)
session->HandleListUnsubscribe(*this);
}
+void Battlenet::WoWRealm::JoinRequestV2::Read()
+{
+ Realm.Battlegroup = _stream.Read<uint8>(8);
+ Realm.Index = _stream.Read<uint32>(32);
+ Realm.Region = _stream.Read<uint8>(8);
+ ClientSeed = _stream.Read<uint32>(32);
+}
+
+std::string Battlenet::WoWRealm::JoinRequestV2::ToString() const
+{
+ std::ostringstream stream;
+ stream << "Battlenet::WoWRealm::JoinRequestV2 ClientSeed " << ClientSeed << " Region " << uint32(Realm.Region) << " Battlegroup " << uint32(Realm.Battlegroup) << " Index " << Realm.Index;
+ return stream.str().c_str();
+}
+
+void Battlenet::WoWRealm::JoinRequestV2::CallHandler(Session* session)
+{
+ session->HandleJoinRequestV2(*this);
+}
+
Battlenet::WoWRealm::ListSubscribeResponse::~ListSubscribeResponse()
{
for (ServerPacket* realmData : RealmData)
@@ -143,24 +163,32 @@ std::string Battlenet::WoWRealm::ListUpdate::ToString() const
return stream.str().c_str();
}
-void Battlenet::WoWRealm::JoinRequestV2::Read()
+void Battlenet::WoWRealm::ToonReady::Write()
{
- Realm.Battlegroup = _stream.Read<uint8>(8);
- Realm.Index = _stream.Read<uint32>(32);
- Realm.Region = _stream.Read<uint8>(8);
- ClientSeed = _stream.Read<uint32>(32);
+ _stream.Write(Realm.Region, 8);
+ _stream.WriteFourCC(Game);
+ uint32 realmAddress = ((Realm.Battlegroup << 16) & 0xFF0000) | uint16(Realm.Index);
+ _stream.Write(realmAddress, 32);
+ _stream.WriteString(Name, 7, -2);
+ _stream.WriteSkip(7);
+ _stream.Write(Guid, 64);
+ _stream.WriteFourCC(Game);
+ _stream.Write(Realm.Region, 8);
+ _stream.WriteSkip(21);
+ _stream.Write(realmAddress, 32);
+ _stream.WriteSkip(9);
+ _stream.Write(0, 64); // Unknown
+ _stream.Write(0, 32); // Unknown
}
-std::string Battlenet::WoWRealm::JoinRequestV2::ToString() const
+std::string Battlenet::WoWRealm::ToonReady::ToString() const
{
std::ostringstream stream;
- stream << "Battlenet::WoWRealm::JoinRequestV2 ClientSeed " << ClientSeed << " Region " << uint32(Realm.Region) << " Battlegroup " << uint32(Realm.Battlegroup) << " Index " << Realm.Index;
- return stream.str().c_str();
-}
+ stream << "Battlenet::WoWRealm::ToonReady" << " Game: " << Game
+ << ", Region: " << uint32(Realm.Region) << ", Battlegroup: " << uint32(Realm.Battlegroup) << ", Index: " << Realm.Index
+ << ", Guid: " << Guid << ", Name: " << Name;
-void Battlenet::WoWRealm::JoinRequestV2::CallHandler(Session* session)
-{
- session->HandleJoinRequestV2(*this);
+ return stream.str().c_str();
}
void Battlenet::WoWRealm::JoinResponseV2::Write()
diff --git a/src/server/bnetserver/Packets/WoWRealmPackets.h b/src/server/bnetserver/Packets/WoWRealmPackets.h
index 2b1390a9067..b411c63100a 100644
--- a/src/server/bnetserver/Packets/WoWRealmPackets.h
+++ b/src/server/bnetserver/Packets/WoWRealmPackets.h
@@ -153,6 +153,33 @@ namespace Battlenet
std::string ToString() const override { return "Battlenet::WoWRealm::ListComplete"; }
};
+ class ToonReady final : public ServerPacket
+ {
+ public:
+ ToonReady() : ServerPacket(PacketHeader(SMSG_TOON_READY, WOWREALM)), Game("WoW"), Guid(0)
+ {
+ }
+
+ void Write() override;
+ std::string ToString() const override;
+
+ std::string Game;
+ RealmId Realm;
+ uint64 Guid;
+ std::string Name;
+ };
+
+ class ToonLoggedOut final : public ServerPacket
+ {
+ public:
+ ToonLoggedOut() : ServerPacket(PacketHeader(SMSG_TOON_LOGGED_OUT, WOWREALM))
+ {
+ }
+
+ void Write() override { }
+ std::string ToString() const override { return "Battlenet::WoWRealm::ToonLoggedOut"; }
+ };
+
class JoinResponseV2 final : public ServerPacket
{
public:
diff --git a/src/server/bnetserver/Realms/RealmList.cpp b/src/server/bnetserver/Realms/RealmList.cpp
index 2bf93e12cb3..cc7e1d492a8 100644
--- a/src/server/bnetserver/Realms/RealmList.cpp
+++ b/src/server/bnetserver/Realms/RealmList.cpp
@@ -16,12 +16,21 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <boost/asio/ip/tcp.hpp>
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "SessionManager.h"
#include "Util.h"
+#include "Commands.h"
#include "RealmList.h"
+#include <boost/asio/ip/tcp.hpp>
+
+Battlenet::RealmId& Battlenet::RealmId::operator=(Battlenet::RealmHandle const& handle)
+{
+ Region = handle.Region;
+ Battlegroup = handle.Battlegroup;
+ Index = handle.Index;
+ return *this;
+}
ip::tcp::endpoint Realm::GetAddressForClient(ip::address const& clientAddr) const
{
@@ -58,7 +67,7 @@ ip::tcp::endpoint Realm::GetAddressForClient(ip::address const& clientAddr) cons
return endpoint;
}
-RealmList::RealmList() : _updateInterval(0), _updateTimer(nullptr), _resolver(nullptr)
+RealmList::RealmList() : _updateInterval(0), _updateTimer(nullptr), _resolver(nullptr), _worldListener(nullptr)
{
}
@@ -66,10 +75,11 @@ RealmList::~RealmList()
{
delete _updateTimer;
delete _resolver;
+ delete _worldListener;
}
// Load the realm list from the database
-void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval)
+void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval, uint16 worldListenPort)
{
_updateInterval = updateInterval;
_updateTimer = new boost::asio::deadline_timer(ioService);
@@ -77,6 +87,14 @@ void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInte
// Get the content of the realmlist table in the database
UpdateRealms(boost::system::error_code());
+
+ _worldListener = new WorldListener(worldListenPort);
+ _worldListener->Start();
+}
+
+void RealmList::Close()
+{
+ _worldListener->End();
}
template<typename FieldType>
diff --git a/src/server/bnetserver/Realms/RealmList.h b/src/server/bnetserver/Realms/RealmList.h
index a4d3d77ff56..dc78a00dfdd 100644
--- a/src/server/bnetserver/Realms/RealmList.h
+++ b/src/server/bnetserver/Realms/RealmList.h
@@ -19,11 +19,12 @@
#ifndef _REALMLIST_H
#define _REALMLIST_H
+#include "Common.h"
+#include "WorldListener.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 "Common.h"
using namespace boost::asio;
@@ -44,6 +45,8 @@ enum RealmFlags
namespace Battlenet
{
+ struct RealmHandle;
+
struct RealmId
{
RealmId() : Region(0), Battlegroup(0), Index(0), Build(0) { }
@@ -59,6 +62,8 @@ namespace Battlenet
{
return memcmp(this, &r, sizeof(RealmId) - sizeof(Build)) < 0;
}
+
+ RealmId& operator=(RealmHandle const& handle);
};
}
@@ -98,7 +103,8 @@ public:
~RealmList();
- void Initialize(boost::asio::io_service& ioService, uint32 updateInterval);
+ void Initialize(boost::asio::io_service& ioService, uint32 updateInterval, uint16 worldListenPort);
+ void Close();
RealmMap const& GetRealms() const { return _realms; }
Realm const* GetRealm(Battlenet::RealmId const& id) const;
@@ -114,6 +120,7 @@ private:
uint32 _updateInterval;
boost::asio::deadline_timer* _updateTimer;
boost::asio::ip::tcp::resolver* _resolver;
+ WorldListener* _worldListener;
};
#define sRealmList RealmList::instance()
diff --git a/src/server/bnetserver/Realms/WorldListener.cpp b/src/server/bnetserver/Realms/WorldListener.cpp
new file mode 100644
index 00000000000..30886a67310
--- /dev/null
+++ b/src/server/bnetserver/Realms/WorldListener.cpp
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2008-2014 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 "Log.h"
+#include "SessionManager.h"
+#include "WoWRealmPackets.h"
+#include "ZmqContext.h"
+#include "WorldListener.h"
+
+WorldListener::HandlerTable const WorldListener::_handlers;
+
+WorldListener::HandlerTable::HandlerTable()
+{
+#define DEFINE_HANDLER(opc, func) _handlers[opc] = { func, #opc }
+
+ DEFINE_HANDLER(BNET_CHANGE_TOON_ONLINE_STATE, &WorldListener::HandleToonOnlineStatusChange);
+
+#undef DEFINE_HANDLER
+}
+
+WorldListener::WorldListener(uint16 worldListenPort) : _worldListenPort(worldListenPort)
+{
+ _worldSocket = sIpcContext->CreateNewSocket(zmqpp::socket_type::pull);
+}
+
+WorldListener::~WorldListener()
+{
+ delete _worldSocket;
+}
+
+void WorldListener::Run()
+{
+ while (!ProcessExit())
+ {
+ _poller->poll();
+ if (_poller->events(*_worldSocket) & zmqpp::poller::poll_in)
+ {
+ int32 op1;
+ do
+ {
+ zmqpp::message msg;
+ _worldSocket->receive(msg);
+ Dispatch(msg);
+ _worldSocket->get(zmqpp::socket_option::events, op1);
+ } while (op1 & zmqpp::poller::poll_in);
+ }
+ }
+}
+
+void WorldListener::HandleOpen()
+{
+ _worldSocket->bind(std::string("tcp://*:") + std::to_string(_worldListenPort));
+ _poller->add(*_worldSocket);
+ TC_LOG_INFO("server.ipc", "Listening on connections from worldservers...");
+}
+
+void WorldListener::HandleClose()
+{
+ _worldSocket->close();
+ TC_LOG_INFO("server.ipc", "Shutting down connections from worldservers...");
+}
+
+void WorldListener::Dispatch(zmqpp::message& msg) const
+{
+ Battlenet::Header ipcHeader;
+ msg >> ipcHeader;
+
+ if (ipcHeader.Ipc.Channel != IPC_CHANNEL_BNET)
+ return;
+
+ if (ipcHeader.Ipc.Command < IPC_BNET_MAX_COMMAND)
+ (this->*_handlers[ipcHeader.Ipc.Command].Handler)(ipcHeader.Realm, msg);
+}
+
+void WorldListener::HandleToonOnlineStatusChange(Battlenet::RealmHandle const& realm, zmqpp::message& msg) const
+{
+ Battlenet::ToonHandle toonHandle;
+ bool online;
+ msg >> toonHandle;
+ msg >> online;
+
+ if (Battlenet::Session* session = sSessionMgr.GetSession(toonHandle.AccountId, toonHandle.GameAccountId))
+ {
+ if (online)
+ {
+ Battlenet::WoWRealm::ToonReady* toonReady = new Battlenet::WoWRealm::ToonReady();
+ toonReady->Realm = realm;
+ toonReady->Guid = toonHandle.Guid;
+ toonReady->Name = toonHandle.Name;
+ session->AsyncWrite(toonReady);
+ }
+ else
+ session->AsyncWrite(new Battlenet::WoWRealm::ToonLoggedOut());
+ }
+}
diff --git a/src/server/bnetserver/Realms/WorldListener.h b/src/server/bnetserver/Realms/WorldListener.h
new file mode 100644
index 00000000000..04d5342449c
--- /dev/null
+++ b/src/server/bnetserver/Realms/WorldListener.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef WorldListener_h__
+#define WorldListener_h__
+
+#include "ZMQTask.h"
+#include "Commands.h"
+
+class WorldListener : public ZMQTask
+{
+public:
+ explicit WorldListener(uint16 worldListenPort);
+ ~WorldListener();
+ void Run() override;
+
+protected:
+ void HandleOpen() override;
+ void HandleClose() override;
+
+private:
+ void Dispatch(zmqpp::message& msg) const;
+
+ typedef void(WorldListener::*PacketHandler)(Battlenet::RealmHandle const& realm, zmqpp::message& msg) const;
+ class HandlerTable
+ {
+ public:
+ HandlerTable();
+
+ struct HandlerInfo
+ {
+ PacketHandler Handler;
+ char const* Name;
+ };
+
+ HandlerInfo const& operator[](uint8 opcode) const { return _handlers[opcode]; }
+
+ private:
+ HandlerInfo _handlers[IPC_BNET_MAX_COMMAND];
+ };
+
+ void HandleToonOnlineStatusChange(Battlenet::RealmHandle const& realm, zmqpp::message& msg) const;
+
+ zmqpp::socket* _worldSocket;
+ uint16 _worldListenPort;
+ static HandlerTable const _handlers;
+};
+
+#endif // WorldListener_h__
diff --git a/src/server/bnetserver/Server/Session.h b/src/server/bnetserver/Server/Session.h
index a2c587841a4..c932115a04b 100644
--- a/src/server/bnetserver/Server/Session.h
+++ b/src/server/bnetserver/Server/Session.h
@@ -93,9 +93,9 @@ namespace Battlenet
bool IsSubscribedToRealmListUpdates() const { return _subscribedToRealmListUpdates; }
- protected:
void AsyncWrite(ServerPacket* packet);
+ protected:
void ReadHandler() override;
private:
diff --git a/src/server/bnetserver/Server/SessionManager.cpp b/src/server/bnetserver/Server/SessionManager.cpp
index 8dcee55ec6c..9e5836dab8d 100644
--- a/src/server/bnetserver/Server/SessionManager.cpp
+++ b/src/server/bnetserver/Server/SessionManager.cpp
@@ -49,3 +49,22 @@ void Battlenet::SessionManager::RemoveSession(Session* session)
_sessions.erase({ session->GetAccountId(), session->GetGameAccountId() });
_sessionsByAccountId[session->GetAccountId()].remove(session);
}
+
+Battlenet::Session* Battlenet::SessionManager::GetSession(uint32 accountId, uint32 gameAccountId) const
+{
+ auto itr = _sessions.find({ accountId, gameAccountId });
+ if (itr != _sessions.end())
+ return itr->second;
+
+ return nullptr;
+}
+
+std::list<Battlenet::Session*> Battlenet::SessionManager::GetSessions(uint32 accountId) const
+{
+ std::list<Session*> sessions;
+ auto itr = _sessionsByAccountId.find(accountId);
+ if (itr != _sessionsByAccountId.end())
+ sessions = itr->second;
+
+ return sessions;
+}
diff --git a/src/server/bnetserver/Server/SessionManager.h b/src/server/bnetserver/Server/SessionManager.h
index bbd78c052d2..08ca5ce2b4e 100644
--- a/src/server/bnetserver/Server/SessionManager.h
+++ b/src/server/bnetserver/Server/SessionManager.h
@@ -60,6 +60,9 @@ namespace Battlenet
void RemoveSession(Session* /*session*/);
+ Session* GetSession(uint32 accountId, uint32 gameAccountId) const;
+ std::list<Session*> GetSessions(uint32 accountId) const;
+
template<typename Iterator>
void LockedForEach(Iterator iterator)
{
diff --git a/src/server/bnetserver/bnetserver.conf.dist b/src/server/bnetserver/bnetserver.conf.dist
index 84456c117b3..102ddb9906a 100644
--- a/src/server/bnetserver/bnetserver.conf.dist
+++ b/src/server/bnetserver/bnetserver.conf.dist
@@ -47,6 +47,13 @@ LogsDir = ""
MaxPingTime = 30
#
+# WorldserverListenPort
+# Description: TCP port to listen on for incoming worldserver IPC.
+# Default: 1118
+
+WorldserverListenPort = 1118
+
+#
# BattlenetPort
# Description: TCP port to reach the auth server for battle.net connections.
# Default: 1119
diff --git a/src/server/collision/CMakeLists.txt b/src/server/collision/CMakeLists.txt
index 1c5fcbee52e..3aac255be29 100644
--- a/src/server/collision/CMakeLists.txt
+++ b/src/server/collision/CMakeLists.txt
@@ -47,6 +47,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/shared/Packets
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
${CMAKE_SOURCE_DIR}/src/server/shared/DataStores
+ ${CMAKE_SOURCE_DIR}/src/server/ipc
${CMAKE_SOURCE_DIR}/src/server/game/Addons
${CMAKE_SOURCE_DIR}/src/server/game/Conditions
${CMAKE_SOURCE_DIR}/src/server/game/Entities/Item
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
index 79512e57fe3..6550bccc06d 100644
--- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
+++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
@@ -107,7 +107,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction&
else
{
bidderAccId = sObjectMgr->GetPlayerAccountIdByGUID(bidderGuid);
- logGmTrade = AccountMgr::HasPermission(bidderAccId, rbac::RBAC_PERM_LOG_GM_TRADE, realmID);
+ logGmTrade = AccountMgr::HasPermission(bidderAccId, rbac::RBAC_PERM_LOG_GM_TRADE, realmHandle.Index);
if (logGmTrade && !sObjectMgr->GetPlayerNameByGUID(bidderGuid, bidderName))
bidderName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
diff --git a/src/server/game/CMakeLists.txt b/src/server/game/CMakeLists.txt
index 0d1b460500e..27b3ea2c381 100644
--- a/src/server/game/CMakeLists.txt
+++ b/src/server/game/CMakeLists.txt
@@ -111,6 +111,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/dep/g3dlite/include
${CMAKE_SOURCE_DIR}/dep/SFMT
${CMAKE_SOURCE_DIR}/dep/zlib
+ ${CMAKE_SOURCE_DIR}/dep/zmqpp
${CMAKE_SOURCE_DIR}/src/server/collision
${CMAKE_SOURCE_DIR}/src/server/collision/Management
${CMAKE_SOURCE_DIR}/src/server/collision/Models
@@ -129,6 +130,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/shared/Packets
${CMAKE_SOURCE_DIR}/src/server/shared/Threading
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
+ ${CMAKE_SOURCE_DIR}/src/server/ipc
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/Accounts
${CMAKE_CURRENT_SOURCE_DIR}/Achievements
@@ -205,6 +207,7 @@ include_directories(
${MYSQL_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${VALGRIND_INCLUDE_DIR}
+ ${ZMQ_INCLUDE_DIR}
)
add_library(game STATIC
diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp
index ace13989efb..6dfd25495d2 100644
--- a/src/server/game/Chat/Chat.cpp
+++ b/src/server/game/Chat/Chat.cpp
@@ -160,7 +160,7 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
if (target)
target_sec = target->GetSecurity();
else if (target_account)
- target_sec = AccountMgr::GetSecurity(target_account, realmID);
+ target_sec = AccountMgr::GetSecurity(target_account, realmHandle.Index);
else
return true; // caller must report error for (target == NULL && target_account == 0)
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index 2cae8427161..bef7aada6e9 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -47,6 +47,7 @@
#include "World.h"
#include "WorldPacket.h"
#include "WorldSession.h"
+#include "BattlenetServerManager.h"
class LoginQueryHolder : public SQLQueryHolder
{
@@ -689,13 +690,13 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS_BY_REALM);
stmt->setUInt32(0, GetAccountId());
- stmt->setUInt32(1, realmID);
+ stmt->setUInt32(1, realmHandle.Index);
trans->Append(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS);
stmt->setUInt32(0, createInfo->CharCount);
stmt->setUInt32(1, GetAccountId());
- stmt->setUInt32(2, realmID);
+ stmt->setUInt32(2, realmHandle.Index);
trans->Append(stmt);
LoginDatabase.CommitTransaction(trans);
@@ -1139,6 +1140,8 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
sScriptMgr->OnPlayerLogin(pCurrChar, firstLogin);
+ sBattlenetServer.SendChangeToonOnlineState(GetBattlenetAccountId(), GetAccountId(), _player->GetGUID(), _player->GetName(), true);
+
delete holder;
}
diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp
index 8d11b9bf41d..3f7cf24206d 100644
--- a/src/server/game/Handlers/MiscHandler.cpp
+++ b/src/server/game/Handlers/MiscHandler.cpp
@@ -609,7 +609,7 @@ void WorldSession::HandleAddFriendOpcodeCallBack(PreparedQueryResult result, std
team = Player::TeamForRace(fields[1].GetUInt8());
friendAccountId = fields[2].GetUInt32();
- if (HasPermission(rbac::RBAC_PERM_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realmID)))
+ if (HasPermission(rbac::RBAC_PERM_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realmHandle.Index)))
{
if (friendGuid)
{
diff --git a/src/server/game/Server/BattlenetServerManager.cpp b/src/server/game/Server/BattlenetServerManager.cpp
new file mode 100644
index 00000000000..b267926c6ff
--- /dev/null
+++ b/src/server/game/Server/BattlenetServerManager.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2008-2014 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 "Config.h"
+#include "World.h"
+#include "ZmqContext.h"
+#include "BattlenetServerManager.h"
+
+void Battlenet::ServerManager::InitializeConnection()
+{
+ std::string bnetserverAddress = sConfigMgr->GetStringDefault("BnetServer.Address", "127.0.0.1");
+ int32 bnetserverPort = sConfigMgr->GetIntDefault("BnetServer.Port", 1118);
+ _socket = new ZmqMux("inproc://bnetmgr", "tcp://" + bnetserverAddress + ":" + std::to_string(bnetserverPort));
+ _socket->Start();
+}
+
+void Battlenet::ServerManager::CloseConnection()
+{
+ _socket->End();
+ delete _socket;
+ _socket = nullptr;
+}
+
+Battlenet::Header Battlenet::ServerManager::CreateHeader(BnetCommands command)
+{
+ Header header;
+ header.Ipc.Channel = IPC_CHANNEL_BNET;
+ header.Ipc.Command = command;
+ header.Realm = realmHandle;
+ return header;
+}
+
+void Battlenet::ServerManager::SendChangeToonOnlineState(uint32 battlenetAccountId, uint32 gameAccountId, ObjectGuid guid, std::string const& name, bool online)
+{
+ // Do nothing for Grunt login
+ if (!battlenetAccountId)
+ return;
+
+ Header header = CreateHeader(BNET_CHANGE_TOON_ONLINE_STATE);
+ ToonHandle toon;
+ toon.AccountId = battlenetAccountId;
+ toon.GameAccountId = gameAccountId;
+ toon.Guid = guid;
+ toon.Name = name;
+
+ zmqpp::message msg;
+ msg << header;
+ msg << toon;
+ msg << online;
+
+ _socket->Send(&msg);
+}
diff --git a/src/server/game/Server/BattlenetServerManager.h b/src/server/game/Server/BattlenetServerManager.h
new file mode 100644
index 00000000000..fe103a1c981
--- /dev/null
+++ b/src/server/game/Server/BattlenetServerManager.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef BattlenetMgr_h__
+#define BattlenetMgr_h__
+
+#include "ZmqMux.h"
+#include "Commands.h"
+
+namespace zmqpp
+{
+ class socket;
+}
+
+namespace Battlenet
+{
+ class ServerManager
+ {
+ ServerManager() : _socket(nullptr) { }
+
+ public:
+ void InitializeConnection();
+ void CloseConnection();
+
+ static ServerManager& Instance()
+ {
+ static ServerManager instance;
+ return instance;
+ }
+
+ void SendChangeToonOnlineState(uint32 battlenetAccountId, uint32 gameAccountId, ObjectGuid guid, std::string const& name, bool online);
+
+ private:
+ static Header CreateHeader(BnetCommands command);
+ ZmqMux* _socket;
+ };
+}
+
+#define sBattlenetServer Battlenet::ServerManager::Instance()
+
+#endif // BattlenetMgr_h__
diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp
index 4c183939460..0fd46f0d20b 100644
--- a/src/server/game/Server/WorldSession.cpp
+++ b/src/server/game/Server/WorldSession.cpp
@@ -47,6 +47,7 @@
#include "Transport.h"
#include "WardenWin.h"
#include "WardenMac.h"
+#include "BattlenetServerManager.h"
namespace {
@@ -582,6 +583,9 @@ void WorldSession::LogoutPlayer(bool save)
_player->CleanupsBeforeDelete();
TC_LOG_INFO("entities.player.character", "Account: %d (IP: %s) Logout Character:[%s] (GUID: %u) Level: %d",
GetAccountId(), GetRemoteAddress().c_str(), _player->GetName().c_str(), _player->GetGUIDLow(), _player->getLevel());
+
+ sBattlenetServer.SendChangeToonOnlineState(GetBattlenetAccountId(), GetAccountId(), _player->GetGUID(), _player->GetName(), false);
+
if (Map* _map = _player->FindMap())
_map->RemovePlayerFromMap(_player, true);
@@ -1143,11 +1147,11 @@ void WorldSession::LoadPermissions()
AccountMgr::GetName(id, name);
uint8 secLevel = GetSecurity();
- _RBACData = new rbac::RBACData(id, name, realmID, secLevel);
+ _RBACData = new rbac::RBACData(id, name, realmHandle.Index, secLevel);
_RBACData->LoadFromDB();
TC_LOG_DEBUG("rbac", "WorldSession::LoadPermissions [AccountId: %u, Name: %s, realmId: %d, secLevel: %u]",
- id, name.c_str(), realmID, secLevel);
+ id, name.c_str(), realmHandle.Index, secLevel);
}
rbac::RBACData* WorldSession::GetRBACData()
@@ -1162,7 +1166,7 @@ bool WorldSession::HasPermission(uint32 permission)
bool hasPermission = _RBACData->HasPermission(permission);
TC_LOG_DEBUG("rbac", "WorldSession::HasPermission [AccountId: %u, Name: %s, realmId: %d]",
- _RBACData->GetId(), _RBACData->GetName().c_str(), realmID);
+ _RBACData->GetId(), _RBACData->GetName().c_str(), realmHandle.Index);
return hasPermission;
}
@@ -1170,7 +1174,7 @@ bool WorldSession::HasPermission(uint32 permission)
void WorldSession::InvalidateRBACData()
{
TC_LOG_DEBUG("rbac", "WorldSession::Invalidaterbac::RBACData [AccountId: %u, Name: %s, realmId: %d]",
- _RBACData->GetId(), _RBACData->GetName().c_str(), realmID);
+ _RBACData->GetId(), _RBACData->GetName().c_str(), realmHandle.Index);
delete _RBACData;
_RBACData = NULL;
}
diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp
index bff343bdcb1..7933ddfeb4d 100644
--- a/src/server/game/Server/WorldSocket.cpp
+++ b/src/server/game/Server/WorldSocket.cpp
@@ -406,7 +406,7 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
return;
}
- if (realmIndex != realmID)
+ if (realmIndex != realmHandle.Index)
{
SendAuthResponseError(REALM_LIST_REALM_NOT_FOUND);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Sent Auth Response (bad realm).");
@@ -485,7 +485,7 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_GMLEVEL_BY_REALMID);
stmt->setUInt32(0, id);
- stmt->setInt32(1, int32(realmID));
+ stmt->setInt32(1, int32(realmHandle.Index));
result = LoginDatabase.Query(stmt);
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index 6adb93d4742..4b114255dbc 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -1375,7 +1375,7 @@ void World::SetInitialWorldSettings()
uint32 server_type = IsFFAPvPRealm() ? uint32(REALM_TYPE_PVP) : getIntConfig(CONFIG_GAME_TYPE);
uint32 realm_zone = getIntConfig(CONFIG_REALM_ZONE);
- LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID); // One-time query
+ LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmHandle.Index); // One-time query
///- Remove the bones (they should not exist in DB though) and old corpses after a restart
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_OLD_CORPSES);
@@ -1797,7 +1797,7 @@ void World::SetInitialWorldSettings()
m_startTime = m_gameTime;
LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES(%u, %u, 0, '%s')",
- realmID, uint32(m_startTime), _FULLVERSION); // One-time query
+ realmHandle.Index, uint32(m_startTime), _FULLVERSION); // One-time query
m_timers[WUPDATE_WEATHERS].SetInterval(1*IN_MILLISECONDS);
m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS);
@@ -2079,7 +2079,7 @@ void World::Update(uint32 diff)
stmt->setUInt32(0, tmpDiff);
stmt->setUInt16(1, uint16(maxOnlinePlayers));
- stmt->setUInt32(2, realmID);
+ stmt->setUInt32(2, realmHandle.Index);
stmt->setUInt32(3, uint32(m_startTime));
LoginDatabase.Execute(stmt);
@@ -2809,13 +2809,13 @@ void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount)
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS_BY_REALM);
stmt->setUInt32(0, accountId);
- stmt->setUInt32(1, realmID);
+ stmt->setUInt32(1, realmHandle.Index);
LoginDatabase.Execute(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS);
stmt->setUInt8(0, charCount);
stmt->setUInt32(1, accountId);
- stmt->setUInt32(2, realmID);
+ stmt->setUInt32(2, realmHandle.Index);
LoginDatabase.Execute(stmt);
}
}
@@ -2984,7 +2984,7 @@ void World::ResetCurrencyWeekCap()
void World::LoadDBAllowedSecurityLevel()
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_REALMLIST_SECURITY_LEVEL);
- stmt->setInt32(0, int32(realmID));
+ stmt->setInt32(0, int32(realmHandle.Index));
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index 49d154d8db6..2c74e3929fe 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -24,6 +24,7 @@
#define __WORLD_H
#include "Common.h"
+#include "Commands.h"
#include "ObjectGuid.h"
#include "Timer.h"
#include "SharedDefines.h"
@@ -879,7 +880,7 @@ class World
std::deque<std::future<PreparedQueryResult>> m_realmCharCallbacks;
};
-extern uint32 realmID;
+extern Battlenet::RealmHandle realmHandle;
#define sWorld World::instance()
#endif
diff --git a/src/server/ipc/CMakeLists.txt b/src/server/ipc/CMakeLists.txt
new file mode 100644
index 00000000000..93a5d630dfe
--- /dev/null
+++ b/src/server/ipc/CMakeLists.txt
@@ -0,0 +1,24 @@
+# Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+file(GLOB_RECURSE sources_ipc *.cpp *.h)
+
+set(ipc_SRCS
+ ${sources_ipc}
+)
+
+include_directories(
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/dep/zmqpp
+ ${CMAKE_SOURCE_DIR}/src/server/shared/
+ ${ZMQ_INCLUDE_DIR}
+)
+
+add_library(ipc STATIC ${ipc_SRCS})
diff --git a/src/server/ipc/Commands.cpp b/src/server/ipc/Commands.cpp
new file mode 100644
index 00000000000..8e494fc34b9
--- /dev/null
+++ b/src/server/ipc/Commands.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2008-2014 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 "Commands.h"
+#include <zmqpp/message.hpp>
+
+zmqpp::message& operator>>(zmqpp::message& msg, IPCHeader& header)
+{
+ msg >> header.Channel;
+ msg >> header.Command;
+ return msg;
+}
+
+zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::RealmHandle& realm)
+{
+ msg >> realm.Region;
+ msg >> realm.Battlegroup;
+ msg >> realm.Index;
+ return msg;
+}
+
+zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::Header& header)
+{
+ msg >> header.Ipc;
+ msg >> header.Realm;
+ return msg;
+}
+
+zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::ToonHandle& toonHandle)
+{
+ msg >> toonHandle.AccountId;
+ msg >> toonHandle.GameAccountId;
+ msg >> toonHandle.Guid;
+ msg >> toonHandle.Name;
+ return msg;
+}
+
+zmqpp::message& operator<<(zmqpp::message& msg, IPCHeader& header)
+{
+ msg << header.Channel;
+ msg << header.Command;
+ return msg;
+}
+
+zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::RealmHandle& realm)
+{
+ msg << realm.Region;
+ msg << realm.Battlegroup;
+ msg << realm.Index;
+ return msg;
+}
+
+zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::Header& header)
+{
+ msg << header.Ipc;
+ msg << header.Realm;
+ return msg;
+}
+
+zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::ToonHandle& toonHandle)
+{
+ msg << toonHandle.AccountId;
+ msg << toonHandle.GameAccountId;
+ msg << toonHandle.Guid;
+ msg << toonHandle.Name;
+ return msg;
+}
diff --git a/src/server/ipc/Commands.h b/src/server/ipc/Commands.h
new file mode 100644
index 00000000000..05309a45022
--- /dev/null
+++ b/src/server/ipc/Commands.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef _COMMANDS_H
+#define _COMMANDS_H
+
+#include "Define.h"
+#include <string>
+
+enum Channels
+{
+ IPC_CHANNEL_BNET,
+
+ MAX_IPC_CHANNELS,
+};
+
+enum BnetCommands
+{
+ BNET_CHANGE_TOON_ONLINE_STATE,
+
+ IPC_BNET_MAX_COMMAND
+};
+
+struct IPCHeader
+{
+ uint8 Channel;
+ uint8 Command;
+};
+
+namespace Battlenet
+{
+ struct RealmHandle
+ {
+ uint8 Region;
+ uint8 Battlegroup;
+ uint32 Index;
+ };
+
+ struct Header
+ {
+ IPCHeader Ipc;
+ RealmHandle Realm;
+ };
+
+ struct ToonHandle
+ {
+ uint32 AccountId;
+ uint32 GameAccountId;
+ uint64 Guid;
+ std::string Name;
+ };
+}
+
+namespace zmqpp
+{
+ class message;
+}
+
+zmqpp::message& operator>>(zmqpp::message& msg, IPCHeader& header);
+zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::RealmHandle& realm);
+zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::Header& header);
+zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::ToonHandle& toonHandle);
+
+zmqpp::message& operator<<(zmqpp::message& msg, IPCHeader& header);
+zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::RealmHandle& realm);
+zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::Header& header);
+zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::ToonHandle& toonHandle);
+
+#endif // _COMMANDS_H
diff --git a/src/server/ipc/ZMQTask.cpp b/src/server/ipc/ZMQTask.cpp
new file mode 100644
index 00000000000..0d25dc2babf
--- /dev/null
+++ b/src/server/ipc/ZMQTask.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2008-2014 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 "ZMQTask.h"
+#include "ZmqContext.h"
+#include <zmqpp/message.hpp>
+
+ZMQTask::ZMQTask()
+{
+ _poller = new zmqpp::poller();
+}
+
+ZMQTask::~ZMQTask()
+{
+ delete _poller;
+ _poller = NULL;
+ delete _inproc;
+ delete _thread;
+}
+
+void ZMQTask::Start()
+{
+ _inproc = sIpcContext->CreateInprocSubscriber();
+ _poller->add(*_inproc);
+
+ HandleOpen();
+ _thread = new std::thread(&ZMQTask::Run, this);
+}
+
+void ZMQTask::End()
+{
+ _thread->join();
+ _inproc->close();
+ HandleClose();
+}
+
+bool ZMQTask::ProcessExit()
+{
+ if (_poller->events(*_inproc) == zmqpp::poller::poll_in)
+ {
+ int op1;
+ do
+ {
+ zmqpp::message msg;
+ if (!_inproc->receive(msg, true))
+ return false; //No more messages to read from sock. This shouldn't happen.
+
+ // strip 'internalmq.' from message
+ std::string cmd = msg.get(0).substr(11);
+ if (cmd == "kill")
+ return true;
+
+ _inproc->get(zmqpp::socket_option::events, op1);
+ } while (op1 & zmqpp::poller::poll_in);
+ }
+
+ return false;
+}
+
+void ZMQTask::Pipeline(zmqpp::socket* from, zmqpp::socket* to)
+{
+ /*
+ Push messages from socket to socket.
+ */
+ if (_poller->events(*from) == zmqpp::poller::poll_in)
+ {
+ int32 op1, op2;
+ do
+ {
+ zmqpp::message msg;
+ if (!from->receive(msg, true))
+ return; //No more messages to read from socket. This shouldn't happen.
+
+ to->send(msg);
+ from->get(zmqpp::socket_option::events, op1);
+ to->get(zmqpp::socket_option::events, op2);
+ } while(op1 & zmqpp::poller::poll_in && op2 & zmqpp::poller::poll_out);
+ }
+}
diff --git a/src/server/ipc/ZMQTask.h b/src/server/ipc/ZMQTask.h
new file mode 100644
index 00000000000..24251893aaa
--- /dev/null
+++ b/src/server/ipc/ZMQTask.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef __ZMQTASK_H
+#define __ZMQTASK_H
+
+#include "Define.h"
+#include <thread>
+#include <zmqpp/poller.hpp>
+#include <zmqpp/socket.hpp>
+
+/*
+ This class serves as a base for all long running tasks
+ It is set up to terminate its running task upon receiving "kill" command
+*/
+class ZMQTask
+{
+public:
+ ZMQTask();
+ virtual ~ZMQTask();
+
+ void Start();
+ void End();
+ virtual void Run() = 0;
+
+protected:
+ virtual void HandleOpen() { }
+ virtual void HandleClose() { }
+ void Pipeline(zmqpp::socket* from, zmqpp::socket* to);
+ bool ProcessExit();
+
+ zmqpp::poller* _poller;
+
+ zmqpp::socket* _inproc;
+ std::thread* _thread;
+};
+
+#endif // __ZMQTASK_H
diff --git a/src/server/ipc/ZmqContext.cpp b/src/server/ipc/ZmqContext.cpp
new file mode 100644
index 00000000000..305e6b1d843
--- /dev/null
+++ b/src/server/ipc/ZmqContext.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008-2014 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 "ZmqContext.h"
+
+ZmqContext::ZmqContext() : _inproc(nullptr)
+{
+}
+
+ZmqContext::~ZmqContext()
+{
+ delete _inproc;
+}
+
+zmqpp::socket* ZmqContext::CreateNewSocket(zmqpp::socket_type type)
+{
+ std::unique_lock<std::mutex> lock(_mutex);
+ return new zmqpp::socket(_context, type);
+}
+
+void ZmqContext::Initialize()
+{
+ _inproc = new zmqpp::socket(_context, zmqpp::socket_type::pub);
+ _inproc->bind("inproc://workers");
+}
+
+zmqpp::socket* ZmqContext::CreateInprocSubscriber()
+{
+ zmqpp::socket* sub = CreateNewSocket(zmqpp::socket_type::sub);
+ sub->connect("inproc://workers");
+ sub->subscribe("internalmq.");
+ return sub;
+}
+
+void ZmqContext::Close()
+{
+ _inproc->send("internalmq.kill");
+}
diff --git a/src/server/ipc/ZmqContext.h b/src/server/ipc/ZmqContext.h
new file mode 100644
index 00000000000..a6ad12b1b70
--- /dev/null
+++ b/src/server/ipc/ZmqContext.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef __ZMQCONTEX_H
+#define __ZMQCONTEX_H
+
+#include <zmqpp/zmqpp.hpp>
+#include <mutex>
+
+/*
+ * We need to serialize access to zmq context otherwise stuff blows up.
+ */
+class ZmqContext
+{
+public:
+ ~ZmqContext();
+
+ static ZmqContext* Instance()
+ {
+ static ZmqContext instance;
+ return &instance;
+ }
+
+ zmqpp::socket* CreateNewSocket(zmqpp::socket_type);
+ void Initialize();
+ zmqpp::socket* CreateInprocSubscriber();
+ void Close();
+
+private:
+ ZmqContext();
+ ZmqContext(ZmqContext const&) = delete;
+ ZmqContext& operator=(ZmqContext const&) = delete;
+
+ zmqpp::context _context;
+ std::mutex _mutex;
+ zmqpp::socket* _inproc;
+};
+
+#define sIpcContext ZmqContext::Instance()
+
+#endif
diff --git a/src/server/ipc/ZmqListener.cpp b/src/server/ipc/ZmqListener.cpp
new file mode 100644
index 00000000000..98333305e58
--- /dev/null
+++ b/src/server/ipc/ZmqListener.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2008-2014 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 "ZmqListener.h"
+#include "ZmqContext.h"
+
+ZmqListener::ZmqListener(std::string const& from, std::string const& to)
+{
+ _from = sIpcContext->CreateNewSocket(zmqpp::socket_type::sub);
+ _to = sIpcContext->CreateNewSocket(zmqpp::socket_type::push);
+ _from->connect(from);
+ _to->bind(to);
+}
+
+ZmqListener::~ZmqListener()
+{
+ delete _from;
+ delete _to;
+}
+
+void ZmqListener::HandleOpen()
+{
+}
+
+void ZmqListener::HandleClose()
+{
+ _from->close();
+ _to->close();
+}
+
+void ZmqListener::Run()
+{
+ while (!ProcessExit())
+ {
+ _poller->poll();
+
+ while (_poller->events(*_from) & zmqpp::poller::poll_in &&
+ _poller->events(*_to) & zmqpp::poller::poll_out)
+ {
+ zmqpp::message msg;
+ _from->receive(msg);
+ _to->send(msg);
+ }
+ }
+}
+
+void ZmqListener::Subscribe(std::string const& keyword)
+{
+ _from->subscribe(keyword);
+}
+
+void ZmqListener::Unsubscribe(std::string const& keyword)
+{
+ _from->unsubscribe(keyword);
+}
diff --git a/src/server/ipc/ZmqListener.h b/src/server/ipc/ZmqListener.h
new file mode 100644
index 00000000000..8b79ba67f6d
--- /dev/null
+++ b/src/server/ipc/ZmqListener.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef __ZMQLISTENER_H
+#define __ZMQLISTENER_H
+
+#include "ZMQTask.h"
+#include <zmqpp/zmqpp.hpp>
+
+class ZmqListener : public ZMQTask
+{
+/*
+ * Read broadcasts from remote PUB socket, and forward them to
+ * another socket.
+ *
+ * from - client SUB socket
+ * to - listen PUSH socket
+ *
+ */
+public:
+ ZmqListener(std::string const& from, std::string const& to);
+ ~ZmqListener();
+ void Run() override;
+
+ void Subscribe(std::string const& keyword);
+ void Unsubscribe(std::string const& keyword);
+
+protected:
+ void HandleOpen() override;
+ void HandleClose() override;
+
+private:
+ zmqpp::socket* _from;
+ zmqpp::socket* _to;
+};
+
+#endif
diff --git a/src/server/ipc/ZmqMux.cpp b/src/server/ipc/ZmqMux.cpp
new file mode 100644
index 00000000000..4b5a4f48b05
--- /dev/null
+++ b/src/server/ipc/ZmqMux.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2008-2014 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 "ZmqMux.h"
+#include "ZmqContext.h"
+
+ZmqMux::ZmqMux(std::string from_uri, std::string to_uri):
+ _fromAddress(from_uri)
+{
+ printf("Opening muxer thread from %s to %s\n", from_uri.c_str(), to_uri.c_str());
+ _from = sIpcContext->CreateNewSocket(zmqpp::socket_type::pull);
+ _to = sIpcContext->CreateNewSocket(zmqpp::socket_type::push);
+
+ _from->bind(from_uri);
+ _to->connect(to_uri);
+}
+
+ZmqMux::~ZmqMux()
+{
+ delete _from;
+ delete _to;
+}
+
+void ZmqMux::HandleOpen()
+{
+ _poller->add(*_from);
+ _poller->add(*_to, zmqpp::poller::poll_out);
+}
+
+bool ZmqMux::Send(zmqpp::message* m, bool dont_block)
+{
+ if (_socket.get() == nullptr)
+ {
+ _socket.reset(sIpcContext->CreateNewSocket(zmqpp::socket_type::push));
+ _socket->connect(_fromAddress);
+ }
+
+ return _socket->send(*m, dont_block);
+}
+
+void ZmqMux::Run()
+{
+ for (;;)
+ {
+ if (!_poller->poll())
+ break;
+
+ if (ProcessExit())
+ break;
+
+ Pipeline(_from, _to);
+ }
+}
diff --git a/src/server/ipc/ZmqMux.h b/src/server/ipc/ZmqMux.h
new file mode 100644
index 00000000000..4b81f11daaf
--- /dev/null
+++ b/src/server/ipc/ZmqMux.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef __ZMQMUX_H
+#define __ZMQMUX_H
+
+#include "ZMQTask.h"
+#include <string>
+#include <boost/thread/tss.hpp>
+
+/*
+ * Multiplexes zmq messages from many threads,
+ * and then passes them to another socket.
+ */
+class ZmqMux : public ZMQTask
+{
+public:
+ ZmqMux(std::string from, std::string to);
+ ~ZmqMux();
+ bool Send(zmqpp::message*, bool dont_block = false);
+ void Run() override;
+
+protected:
+ void HandleOpen() override;
+
+private:
+ boost::thread_specific_ptr<zmqpp::socket> _socket;
+ zmqpp::socket* _from;
+ zmqpp::socket* _to;
+ std::string const _fromAddress;
+};
+
+#endif
diff --git a/src/server/ipc/ZmqWorker.cpp b/src/server/ipc/ZmqWorker.cpp
new file mode 100644
index 00000000000..f205ea831b5
--- /dev/null
+++ b/src/server/ipc/ZmqWorker.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2008-2014 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 "ZmqWorker.h"
+#include "ZmqContext.h"
+
+ZmqWorker::ZmqWorker(std::string task_uri, std::string res_uri) :
+ _taskUri(task_uri), _resultsUri(res_uri)
+{
+}
+
+ZmqWorker::~ZmqWorker()
+{
+ delete _taskQueue;
+ delete _results;
+ delete _inproc;
+}
+
+void ZmqWorker::HandleOpen()
+{
+ _taskQueue = sIpcContext->CreateNewSocket(zmqpp::socket_type::pull);
+ _results = sIpcContext->CreateNewSocket(zmqpp::socket_type::push);
+
+ _taskQueue->connect(_taskUri);
+ _results->connect(_resultsUri);
+
+ _poller->add(*_taskQueue);
+}
+
+void ZmqWorker::HandleClose()
+{
+ _taskQueue->close();
+ _results->close();
+}
+
+void ZmqWorker::Run()
+{
+ while (!ProcessExit())
+ {
+ _poller->poll();
+ if (_poller->events(*_taskQueue) & zmqpp::poller::poll_in)
+ PerformWork();
+ }
+}
+
+void ZmqWorker::PerformWork()
+{
+ int32 op1;
+ do
+ {
+ zmqpp::message msg;
+ _taskQueue->receive(msg);
+ Dispatch(msg);
+ _taskQueue->get(zmqpp::socket_option::events, op1);
+ } while (op1 & zmqpp::poller::poll_in);
+}
diff --git a/src/server/ipc/ZmqWorker.h b/src/server/ipc/ZmqWorker.h
new file mode 100644
index 00000000000..b3e221e9129
--- /dev/null
+++ b/src/server/ipc/ZmqWorker.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2008-2014 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/>.
+ */
+
+#ifndef __ZMQWORKER_H
+#define __ZMQWORKER_H
+
+#include "ZMQTask.h"
+#include <zmqpp/zmqpp.hpp>
+
+class ZmqWorker : public ZMQTask
+{
+public:
+ ZmqWorker(std::string task_uri, std::string res_uri);
+ ~ZmqWorker();
+ void Run() override;
+
+protected:
+ void HandleOpen() override;
+ void HandleClose() override;
+ zmqpp::socket* _results;
+
+private:
+ void PerformWork();
+ virtual void Dispatch(zmqpp::message const&) = 0;
+ zmqpp::socket* _taskQueue;
+ std::string _taskUri;
+ std::string _resultsUri;
+};
+
+#endif
diff --git a/src/server/scripts/CMakeLists.txt b/src/server/scripts/CMakeLists.txt
index e92c883eeff..eab6a36d02e 100644
--- a/src/server/scripts/CMakeLists.txt
+++ b/src/server/scripts/CMakeLists.txt
@@ -64,6 +64,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/shared/Packets
${CMAKE_SOURCE_DIR}/src/server/shared/Threading
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
+ ${CMAKE_SOURCE_DIR}/src/server/ipc
${CMAKE_SOURCE_DIR}/src/server/collision
${CMAKE_SOURCE_DIR}/src/server/collision/Management
${CMAKE_SOURCE_DIR}/src/server/collision/Models
diff --git a/src/server/scripts/Commands/cs_gm.cpp b/src/server/scripts/Commands/cs_gm.cpp
index 27ec4835ce6..4c5b68516ca 100644
--- a/src/server/scripts/Commands/cs_gm.cpp
+++ b/src/server/scripts/Commands/cs_gm.cpp
@@ -163,7 +163,7 @@ public:
///- Get the accounts with GM Level >0
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_GM_ACCOUNTS);
stmt->setUInt8(0, uint8(SEC_MODERATOR));
- stmt->setInt32(1, int32(realmID));
+ stmt->setInt32(1, int32(realmHandle.Index));
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp
index 386be81c198..6fa3c6512b7 100644
--- a/src/server/scripts/Commands/cs_misc.cpp
+++ b/src/server/scripts/Commands/cs_misc.cpp
@@ -1542,7 +1542,7 @@ public:
// Query the prepared statement for login data
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_PINFO);
- stmt->setInt32(0, int32(realmID));
+ stmt->setInt32(0, int32(realmHandle.Index));
stmt->setUInt32(1, accId);
PreparedQueryResult result = LoginDatabase.Query(stmt);
diff --git a/src/server/scripts/Commands/cs_rbac.cpp b/src/server/scripts/Commands/cs_rbac.cpp
index 95ef5ab6984..ab960026d69 100644
--- a/src/server/scripts/Commands/cs_rbac.cpp
+++ b/src/server/scripts/Commands/cs_rbac.cpp
@@ -160,7 +160,7 @@ public:
if (!rdata)
{
- data->rbac = new rbac::RBACData(accountId, accountName, realmID, AccountMgr::GetSecurity(accountId, realmID));
+ data->rbac = new rbac::RBACData(accountId, accountName, realmHandle.Index, AccountMgr::GetSecurity(accountId, realmHandle.Index));
data->rbac->LoadFromDB();
data->needDelete = true;
}
diff --git a/src/server/scripts/Commands/cs_ticket.cpp b/src/server/scripts/Commands/cs_ticket.cpp
index 674658f41ff..f2aa046676f 100644
--- a/src/server/scripts/Commands/cs_ticket.cpp
+++ b/src/server/scripts/Commands/cs_ticket.cpp
@@ -98,7 +98,7 @@ public:
ObjectGuid targetGuid = sObjectMgr->GetPlayerGUIDByName(target);
uint32 accountId = sObjectMgr->GetPlayerAccountIdByGUID(targetGuid);
// Target must exist and have administrative rights
- if (!AccountMgr::HasPermission(accountId, rbac::RBAC_PERM_COMMANDS_BE_ASSIGNED_TICKET, realmID))
+ if (!AccountMgr::HasPermission(accountId, rbac::RBAC_PERM_COMMANDS_BE_ASSIGNED_TICKET, realmHandle.Index))
{
handler->SendSysMessage(LANG_COMMAND_TICKETASSIGNERROR_A);
return true;
@@ -122,7 +122,7 @@ public:
// Assign ticket
SQLTransaction trans = SQLTransaction(NULL);
- ticket->SetAssignedTo(targetGuid, AccountMgr::IsAdminAccount(AccountMgr::GetSecurity(accountId, realmID)));
+ ticket->SetAssignedTo(targetGuid, AccountMgr::IsAdminAccount(AccountMgr::GetSecurity(accountId, realmHandle.Index)));
ticket->SaveToDB(trans);
sTicketMgr->UpdateLastChange();
@@ -378,7 +378,7 @@ public:
{
ObjectGuid guid = ticket->GetAssignedToGUID();
uint32 accountId = sObjectMgr->GetPlayerAccountIdByGUID(guid);
- security = AccountMgr::GetSecurity(accountId, realmID);
+ security = AccountMgr::GetSecurity(accountId, realmHandle.Index);
}
// Check security
diff --git a/src/server/worldserver/CMakeLists.txt b/src/server/worldserver/CMakeLists.txt
index 0cdf5f13f79..65972e680ef 100644
--- a/src/server/worldserver/CMakeLists.txt
+++ b/src/server/worldserver/CMakeLists.txt
@@ -47,6 +47,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/dep/gsoap
${CMAKE_SOURCE_DIR}/dep/sockets/include
${CMAKE_SOURCE_DIR}/dep/SFMT
+ ${CMAKE_SOURCE_DIR}/dep/zmqpp
${CMAKE_SOURCE_DIR}/src/server/collision
${CMAKE_SOURCE_DIR}/src/server/collision/Management
${CMAKE_SOURCE_DIR}/src/server/collision/Models
@@ -64,6 +65,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/shared/Packets
${CMAKE_SOURCE_DIR}/src/server/shared/Threading
${CMAKE_SOURCE_DIR}/src/server/shared/Utilities
+ ${CMAKE_SOURCE_DIR}/src/server/ipc
${CMAKE_SOURCE_DIR}/src/server/game
${CMAKE_SOURCE_DIR}/src/server/game/Accounts
${CMAKE_SOURCE_DIR}/src/server/game/Achievements
@@ -141,6 +143,7 @@ include_directories(
${MYSQL_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${VALGRIND_INCLUDE_DIR}
+ ${ZMQ_INCLUDE_DIR}
)
add_executable(worldserver
@@ -164,18 +167,21 @@ set_target_properties(worldserver PROPERTIES LINK_FLAGS "${worldserver_LINK_FLAG
target_link_libraries(worldserver
game
+ ipc
shared
scripts
collision
g3dlib
gsoap
Detour
+ zmqpp
${JEMALLOC_LIBRARY}
${READLINE_LIBRARY}
${TERMCAP_LIBRARY}
${MYSQL_LIBRARY}
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARIES}
+ ${ZMQ_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES}
)
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index 6c93343b8de..c5127b8f3e2 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -20,13 +20,9 @@
/// @{
/// \file
-#include <openssl/opensslv.h>
-#include <openssl/crypto.h>
-#include <boost/asio/io_service.hpp>
-#include <boost/asio/deadline_timer.hpp>
-#include <boost/program_options.hpp>
-
#include "Common.h"
+#include "Commands.h"
+#include "ZmqContext.h"
#include "DatabaseEnv.h"
#include "AsyncAcceptor.h"
#include "RASession.h"
@@ -47,6 +43,12 @@
#include "SystemConfig.h"
#include "WorldSocket.h"
#include "WorldSocketMgr.h"
+#include "BattlenetServerManager.h"
+#include <openssl/opensslv.h>
+#include <openssl/crypto.h>
+#include <boost/asio/io_service.hpp>
+#include <boost/asio/deadline_timer.hpp>
+#include <boost/program_options.hpp>
using namespace boost::program_options;
@@ -79,7 +81,7 @@ uint32 _maxCoreStuckTimeInMs(0);
WorldDatabaseWorkerPool WorldDatabase; ///< Accessor to the world database
CharacterDatabaseWorkerPool CharacterDatabase; ///< Accessor to the character database
LoginDatabaseWorkerPool LoginDatabase; ///< Accessor to the realm/login database
-uint32 realmID; ///< Id of the realm
+Battlenet::RealmHandle realmHandle; ///< Id of the realm
void SignalHandler(const boost::system::error_code& error, int signalNumber);
void FreezeDetectorHandler(const boost::system::error_code& error);
@@ -188,7 +190,7 @@ extern int main(int argc, char** argv)
}
// Set server offline (not connectable)
- LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = (flag & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_INVALID, realmID);
+ LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = (flag & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_INVALID, realmHandle.Index);
// Initialize the World
sWorld->SetInitialWorldSettings();
@@ -223,7 +225,7 @@ extern int main(int argc, char** argv)
sWorldSocketMgr.StartNetwork(_ioService, worldListener, worldPort);
// Set server online (allow connecting now)
- LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag & ~%u, population = 0 WHERE id = '%u'", REALM_FLAG_INVALID, realmID);
+ LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag & ~%u, population = 0 WHERE id = '%u'", REALM_FLAG_INVALID, realmHandle.Index);
// Start the freeze check callback cycle in 5 seconds (cycle itself is 1 sec)
if (int coreStuckTime = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
@@ -234,6 +236,10 @@ extern int main(int argc, char** argv)
TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", coreStuckTime);
}
+ sIpcContext->Initialize();
+
+ sBattlenetServer.InitializeConnection();
+
TC_LOG_INFO("server.worldserver", "%s (worldserver-daemon) ready...", _FULLVERSION);
sScriptMgr->OnStartup();
@@ -245,6 +251,10 @@ extern int main(int argc, char** argv)
sScriptMgr->OnShutdown();
+ sIpcContext->Close();
+
+ sBattlenetServer.CloseConnection();
+
sWorld->KickAll(); // save and kick all players
sWorld->UpdateSessions(1); // real players unload required UpdateSessions call
@@ -260,7 +270,7 @@ extern int main(int argc, char** argv)
sOutdoorPvPMgr->Die();
// set server offline
- LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, realmID);
+ LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, realmHandle.Index);
// Clean up threads if any
if (soapThread != nullptr)
@@ -523,13 +533,24 @@ bool StartDB()
}
///- Get the realm Id from the configuration file
- realmID = sConfigMgr->GetIntDefault("RealmID", 0);
- if (!realmID)
+ realmHandle.Index = sConfigMgr->GetIntDefault("RealmID", 0);
+ if (!realmHandle.Index)
{
TC_LOG_ERROR("server.worldserver", "Realm ID not defined in configuration file");
return false;
}
- TC_LOG_INFO("server.worldserver", "Realm running as realm ID %d", realmID);
+
+ QueryResult realmIdQuery = LoginDatabase.PQuery("SELECT `Region`,`Battlegroup` FROM `realmlist` WHERE `id`=%u", realmHandle.Index);
+ if (!realmIdQuery)
+ {
+ TC_LOG_ERROR("server.worldserver", "Realm id %u not defined in realmlist table", realmHandle.Index);
+ return false;
+ }
+
+ realmHandle.Region = (*realmIdQuery)[0].GetUInt8();
+ realmHandle.Battlegroup = (*realmIdQuery)[1].GetUInt8();
+
+ TC_LOG_INFO("server.worldserver", "Realm running as realm ID %u region %u battlegroup %u", realmHandle.Index, uint32(realmHandle.Region), uint32(realmHandle.Battlegroup));
///- Clean the database before starting
ClearOnlineAccounts();
@@ -556,7 +577,7 @@ void StopDB()
void ClearOnlineAccounts()
{
// Reset online status for all accounts with characters on the current realm
- LoginDatabase.DirectPExecute("UPDATE account SET online = 0 WHERE online > 0 AND id IN (SELECT acctid FROM realmcharacters WHERE realmid = %d)", realmID);
+ LoginDatabase.DirectPExecute("UPDATE account SET online = 0 WHERE online > 0 AND id IN (SELECT acctid FROM realmcharacters WHERE realmid = %d)", realmHandle.Index);
// Reset online status for all characters
CharacterDatabase.DirectExecute("UPDATE characters SET online = 0 WHERE online <> 0");
diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist
index 6c3972de421..57d97756d70 100644
--- a/src/server/worldserver/worldserver.conf.dist
+++ b/src/server/worldserver/worldserver.conf.dist
@@ -3324,3 +3324,24 @@ PacketSpoof.BanDuration = 86400
#
###################################################################################################
+
+###################################################################################################
+# IPC SETTINGS
+#
+# BnetServer.Address
+# Description: Determines IP address of battle.net server to connect to.
+# Default: 127.0.0.1
+#
+
+BnetServer.Address = 127.0.0.1
+
+#
+# BnetServer.Port
+# Description: Determines port to use when connecting to battle.net server.
+# Default: 1118
+#
+
+BnetServer.Port = 1118
+
+#
+###################################################################################################