diff options
author | Shauren <shauren.trinity@gmail.com> | 2016-03-20 18:50:25 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-03-20 18:50:25 +0100 |
commit | 92e247b22674dc78a7836947af3f656cc84ac1a1 (patch) | |
tree | e2d08b1bc05cd51bebd2dc29635cd96b539f239e /src | |
parent | 1fea358becc00d358e0c79a86645258080aea5b5 (diff) |
Core/Dep: Removed ZMQ dependency in preparation for future changes
Diffstat (limited to 'src')
28 files changed, 6 insertions, 1204 deletions
diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index b8400f496c7..f4a7246d9b0 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -27,7 +27,6 @@ endif(WIN32) add_subdirectory(database) add_subdirectory(shared) -add_subdirectory(ipc) add_subdirectory(bnetserver) add_subdirectory(game) add_subdirectory(scripts) diff --git a/src/server/bnetserver/CMakeLists.txt b/src/server/bnetserver/CMakeLists.txt index 81aabc3eed8..7aa861499d9 100644 --- a/src/server/bnetserver/CMakeLists.txt +++ b/src/server/bnetserver/CMakeLists.txt @@ -43,8 +43,7 @@ endif() target_link_libraries(bnetserver PUBLIC - shared - ipc) + shared) CollectIncludeDirectories( ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp index 310683dec37..65b8d6e772b 100644 --- a/src/server/bnetserver/Main.cpp +++ b/src/server/bnetserver/Main.cpp @@ -36,7 +36,6 @@ #include "RealmList.h" #include "GitRevision.h" #include "Util.h" -#include "ZmqContext.h" #include "DatabaseLoader.h" #include <cstdlib> #include <iostream> @@ -136,23 +135,14 @@ 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(); - _ioService = new boost::asio::io_service(); // Get the list of realms for the server - sRealmList->Initialize(*_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10), worldListenPort); + sRealmList->Initialize(*_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10)); // Start the listening port (acceptor) for auth connections int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119); @@ -209,8 +199,6 @@ int main(int argc, char** argv) sSessionMgr.StopNetwork(); - sIpcContext->Close(); - sRealmList->Close(); // Close the Database Pool and library diff --git a/src/server/bnetserver/Realms/RealmList.cpp b/src/server/bnetserver/Realms/RealmList.cpp index d3f40a8cc97..056ddef39d4 100644 --- a/src/server/bnetserver/Realms/RealmList.cpp +++ b/src/server/bnetserver/Realms/RealmList.cpp @@ -20,23 +20,20 @@ #include "Database/DatabaseEnv.h" #include "SessionManager.h" #include "Util.h" -#include "Commands.h" #include "RealmList.h" #include <boost/asio/ip/tcp.hpp> -RealmList::RealmList() : _updateInterval(0), _updateTimer(nullptr), _resolver(nullptr), _worldListener(nullptr) +RealmList::RealmList() : _updateInterval(0), _updateTimer(nullptr), _resolver(nullptr) { } 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, uint16 worldListenPort) +void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval) { _updateInterval = updateInterval; _updateTimer = new boost::asio::deadline_timer(ioService); @@ -44,14 +41,10 @@ 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(); _updateTimer->cancel(); } diff --git a/src/server/bnetserver/Realms/RealmList.h b/src/server/bnetserver/Realms/RealmList.h index 388d4d5e1aa..fe3c9185ccf 100644 --- a/src/server/bnetserver/Realms/RealmList.h +++ b/src/server/bnetserver/Realms/RealmList.h @@ -21,7 +21,6 @@ #include "Common.h" #include "Realm/Realm.h" -#include "WorldListener.h" #include <boost/asio/ip/address.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/io_service.hpp> @@ -43,7 +42,7 @@ public: ~RealmList(); - void Initialize(boost::asio::io_service& ioService, uint32 updateInterval, uint16 worldListenPort); + void Initialize(boost::asio::io_service& ioService, uint32 updateInterval); void Close(); RealmMap const& GetRealms() const { return _realms; } @@ -60,7 +59,6 @@ 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 deleted file mode 100644 index 2dd9bcdfa2f..00000000000 --- a/src/server/bnetserver/Realms/WorldListener.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2008-2016 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() -{ - try - { - _worldSocket->bind(std::string("tcp://*:") + std::to_string(_worldListenPort)); - } - catch (zmqpp::zmq_internal_exception& ex) - { - TC_LOG_FATAL("server.ipc", "Could not bind to WorldserverListenPort %u. Exception: %s. Shutting down bnetserver.", _worldListenPort, ex.what()); - abort(); - } - - _poller->add(*_worldSocket); - TC_LOG_INFO("server.ipc", "Listening on connections from worldservers on port %u...", _worldListenPort); -} - -void WorldListener::HandleClose() -{ - _worldSocket->close(); - TC_LOG_INFO("server.ipc", "Shutting down connections from worldservers..."); -} - -void WorldListener::Dispatch(zmqpp::message& msg) const -{ - IPC::BattlenetComm::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 -{ - IPC::BattlenetComm::ToonHandle toonHandle; - bool online; - msg >> toonHandle; - msg >> online; - - if (Battlenet::Session* session = sSessionMgr.GetSession(toonHandle.AccountId, toonHandle.GameAccountId)) - { - if (online) - { - if (!session->IsToonOnline()) - { - Battlenet::WoWRealm::ToonReady* toonReady = new Battlenet::WoWRealm::ToonReady(); - toonReady->Name.Region = realm.Region; - toonReady->Name.ProgramId = "WoW"; - toonReady->Name.Realm = realm.GetAddress(); - toonReady->Name.Name = toonHandle.Name; - - toonReady->Handle.Region = realm.Region; - toonReady->Handle.ProgramId = "WoW"; - toonReady->Handle.Realm = realm.GetAddress(); - toonReady->Handle.Id = toonHandle.Guid; - - session->SetToonOnline(true); - session->AsyncWrite(toonReady); - } - } - else if (session->IsToonOnline()) - { - session->AsyncWrite(new Battlenet::WoWRealm::ToonLoggedOut()); - session->SetToonOnline(false); - } - } -} diff --git a/src/server/bnetserver/Realms/WorldListener.h b/src/server/bnetserver/Realms/WorldListener.h deleted file mode 100644 index e5b1ff41201..00000000000 --- a/src/server/bnetserver/Realms/WorldListener.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2008-2016 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/bnetserver.conf.dist b/src/server/bnetserver/bnetserver.conf.dist index cf5d27699d8..252a29440b5 100644 --- a/src/server/bnetserver/bnetserver.conf.dist +++ b/src/server/bnetserver/bnetserver.conf.dist @@ -48,13 +48,6 @@ 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/game/CMakeLists.txt b/src/server/game/CMakeLists.txt index 1dbc75d10af..bba0614d421 100644 --- a/src/server/game/CMakeLists.txt +++ b/src/server/game/CMakeLists.txt @@ -40,7 +40,7 @@ target_include_directories(game target_link_libraries(game PUBLIC - ipc + shared Detour) set_target_properties(game diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index ef197cbe541..dff529891b6 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -21,7 +21,6 @@ #include "ArenaTeamMgr.h" #include "AuthenticationPackets.h" #include "Battleground.h" -#include "BattlenetServerManager.h" #include "BattlePetPackets.h" #include "CalendarMgr.h" #include "CharacterPackets.h" @@ -1138,8 +1137,6 @@ 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/Server/BattlenetServerManager.cpp b/src/server/game/Server/BattlenetServerManager.cpp deleted file mode 100644 index 1256943e565..00000000000 --- a/src/server/game/Server/BattlenetServerManager.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 IPC::BattlenetComm::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 IPC::BattlenetComm::ServerManager::CloseConnection() -{ - _socket->End(); - delete _socket; - _socket = nullptr; -} - -IPC::BattlenetComm::ServerManager& IPC::BattlenetComm::ServerManager::Instance() -{ - static ServerManager instance; - return instance; -} - -IPC::BattlenetComm::Header IPC::BattlenetComm::ServerManager::CreateHeader(BnetCommands command) -{ - Header header; - header.Ipc.Channel = IPC_CHANNEL_BNET; - header.Ipc.Command = command; - header.Realm = realm.Id; - return header; -} - -void IPC::BattlenetComm::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.GetCounter(); - toon.Name = name; - - zmqpp::message msg; - msg << header; - msg << toon; - msg << online; - - Send(&msg); -} - -void IPC::BattlenetComm::ServerManager::Send(zmqpp::message* msg) -{ - if (!_socket) - return; - - _socket->Send(msg); -} diff --git a/src/server/game/Server/BattlenetServerManager.h b/src/server/game/Server/BattlenetServerManager.h deleted file mode 100644 index 3892ac5040f..00000000000 --- a/src/server/game/Server/BattlenetServerManager.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2008-2016 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; - class message; -} - -namespace IPC -{ - namespace BattlenetComm - { - class ServerManager - { - ServerManager() : _socket(nullptr) { } - - public: - void InitializeConnection(); - void CloseConnection(); - - static ServerManager& Instance(); - - void SendChangeToonOnlineState(uint32 battlenetAccountId, uint32 gameAccountId, ObjectGuid guid, std::string const& name, bool online); - - private: - void Send(zmqpp::message* msg); - - static Header CreateHeader(BnetCommands command); - ZmqMux* _socket; - }; - } -} - -#define sBattlenetServer IPC::BattlenetComm::ServerManager::Instance() - -#endif // BattlenetMgr_h__ diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index f68fc5efaf5..ebb3ea02896 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -42,7 +42,6 @@ #include "SocialMgr.h" #include "ScriptMgr.h" #include "WardenWin.h" -#include "BattlenetServerManager.h" #include "AuthenticationPackets.h" #include "CharacterPackets.h" #include "ClientConfigPackets.h" @@ -612,8 +611,6 @@ void WorldSession::LogoutPlayer(bool save) TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Logout Character:[%s] (%s) Level: %d", GetAccountId(), GetRemoteAddress().c_str(), _player->GetName().c_str(), _player->GetGUID().ToString().c_str(), _player->getLevel()); - sBattlenetServer.SendChangeToonOnlineState(GetBattlenetAccountId(), GetAccountId(), _player->GetGUID(), _player->GetName(), false); - if (Map* _map = _player->FindMap()) _map->RemovePlayerFromMap(_player, true); diff --git a/src/server/ipc/CMakeLists.txt b/src/server/ipc/CMakeLists.txt deleted file mode 100644 index 8469c922066..00000000000 --- a/src/server/ipc/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2008-2016 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. - -CollectSourceFiles( - ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE_SOURCES) - -GroupSources(${CMAKE_CURRENT_SOURCE_DIR}) - -add_library(ipc ${PRIVATE_SOURCES}) - -target_include_directories(ipc - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}) - -target_link_libraries(ipc - PUBLIC - shared - zmqpp) - -set_target_properties(ipc - PROPERTIES - FOLDER - "server") diff --git a/src/server/ipc/Commands.cpp b/src/server/ipc/Commands.cpp deleted file mode 100644 index 3eb78cbc14a..00000000000 --- a/src/server/ipc/Commands.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2008-2016 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, IPC::Header& header) -{ - msg >> header.Channel; - msg >> header.Command; - return msg; -} - -zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::RealmHandle& realm) -{ - msg >> realm.Region; - msg >> realm.Site; - msg >> realm.Realm; - return msg; -} - -zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::Header& header) -{ - msg >> header.Ipc; - msg >> header.Realm; - return msg; -} - -zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle& toonHandle) -{ - msg >> toonHandle.AccountId; - msg >> toonHandle.GameAccountId; - msg >> toonHandle.Guid; - msg >> toonHandle.Name; - return msg; -} - -zmqpp::message& operator<<(zmqpp::message& msg, IPC::Header const& header) -{ - msg << header.Channel; - msg << header.Command; - return msg; -} - -zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::RealmHandle const& realm) -{ - msg << realm.Region; - msg << realm.Site; - msg << realm.Realm; - return msg; -} - -zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::Header const& header) -{ - msg << header.Ipc; - msg << header.Realm; - return msg; -} - -zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle const& 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 deleted file mode 100644 index 618e8ca0509..00000000000 --- a/src/server/ipc/Commands.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 "Realm/Realm.h" -#include <string> - -enum Channels -{ - IPC_CHANNEL_BNET, - - MAX_IPC_CHANNELS, -}; - -enum BnetCommands -{ - BNET_CHANGE_TOON_ONLINE_STATE, - - IPC_BNET_MAX_COMMAND -}; - -namespace IPC -{ - struct Header - { - uint8 Channel; - uint8 Command; - }; - - namespace BattlenetComm - { - struct Header - { - IPC::Header Ipc; - Battlenet::RealmHandle Realm; - }; - - struct ToonHandle - { - uint32 AccountId; - uint32 GameAccountId; - uint64 Guid; - std::string Name; - }; - } -} - -namespace zmqpp -{ - class message; -} - -zmqpp::message& operator>>(zmqpp::message& msg, IPC::Header& header); -zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::RealmHandle& realm); -zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::Header& header); -zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle& toonHandle); - -zmqpp::message& operator<<(zmqpp::message& msg, IPC::Header const& header); -zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::RealmHandle const& realm); -zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::Header const& header); -zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle const& toonHandle); - -#endif // _COMMANDS_H diff --git a/src/server/ipc/ZMQTask.cpp b/src/server/ipc/ZMQTask.cpp deleted file mode 100644 index 6d359d9b10a..00000000000 --- a/src/server/ipc/ZMQTask.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2008-2016 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(); - _poller->remove(*_inproc); - _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 deleted file mode 100644 index 85773adbfd1..00000000000 --- a/src/server/ipc/ZMQTask.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 = nullptr; - std::thread* _thread = nullptr; -}; - -#endif // __ZMQTASK_H diff --git a/src/server/ipc/ZmqContext.cpp b/src/server/ipc/ZmqContext.cpp deleted file mode 100644 index bc062de8e88..00000000000 --- a/src/server/ipc/ZmqContext.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2008-2016 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() -{ -} - -zmqpp::socket* ZmqContext::CreateNewSocket(zmqpp::socket_type type) -{ - std::unique_lock<std::mutex> lock(_mutex); - zmqpp::socket* socket = new zmqpp::socket(_context, type); - socket->set(zmqpp::socket_option::linger, 0); - return socket; -} - -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"); - delete _inproc; - _inproc = nullptr; -} diff --git a/src/server/ipc/ZmqContext.h b/src/server/ipc/ZmqContext.h deleted file mode 100644 index 99f49a8c597..00000000000 --- a/src/server/ipc/ZmqContext.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 deleted file mode 100644 index a7cf78f8a92..00000000000 --- a/src/server/ipc/ZmqListener.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 deleted file mode 100644 index 07798b81886..00000000000 --- a/src/server/ipc/ZmqListener.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 deleted file mode 100644 index d6dcd0f73f6..00000000000 --- a/src/server/ipc/ZmqMux.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 const& fromUri, std::string const& toUri): - _fromAddress(fromUri) -{ - printf("Opening muxer thread from %s to %s\n", fromUri.c_str(), toUri.c_str()); - _from = sIpcContext->CreateNewSocket(zmqpp::socket_type::pull); - _to = sIpcContext->CreateNewSocket(zmqpp::socket_type::push); - - _from->bind(fromUri); - _to->connect(toUri); -} - -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 (;;) - { - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - if (!_poller->poll()) - break; - - if (ProcessExit()) - break; - - Pipeline(_from, _to); - } -} diff --git a/src/server/ipc/ZmqMux.h b/src/server/ipc/ZmqMux.h deleted file mode 100644 index 1009382f101..00000000000 --- a/src/server/ipc/ZmqMux.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 const& from, std::string const& 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 deleted file mode 100644 index 617730ad013..00000000000 --- a/src/server/ipc/ZmqWorker.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 const& taskUri, std::string const& resUri) : - _taskUri(taskUri), _resultsUri(resUri) -{ -} - -ZmqWorker::~ZmqWorker() -{ - delete _taskQueue; - delete _results; -} - -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 deleted file mode 100644 index 21d2d95ac18..00000000000 --- a/src/server/ipc/ZmqWorker.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008-2016 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 const& taskUri, std::string const& resUri); - ~ZmqWorker(); - void Run() override; - -protected: - void HandleOpen() override; - void HandleClose() override; - zmqpp::socket* _results = nullptr; - -private: - void PerformWork(); - virtual void Dispatch(zmqpp::message const&) = 0; - zmqpp::socket* _taskQueue = nullptr; - std::string _taskUri; - std::string _resultsUri; -}; - -#endif diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 5b94521817f..8c801736ef4 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -21,8 +21,6 @@ /// \file #include "Common.h" -#include "Commands.h" -#include "ZmqContext.h" #include "DatabaseEnv.h" #include "AsyncAcceptor.h" #include "RASession.h" @@ -43,7 +41,6 @@ #include "GitRevision.h" #include "WorldSocket.h" #include "WorldSocketMgr.h" -#include "BattlenetServerManager.h" #include "Realm/Realm.h" #include "DatabaseLoader.h" #include "AppenderDB.h" @@ -240,10 +237,6 @@ 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...", GitRevision::GetFullVersion()); sScriptMgr->OnStartup(); @@ -257,10 +250,6 @@ 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 diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index b3a6a13bd45..1b4ad557c0d 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -3626,24 +3626,3 @@ 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 - -# -################################################################################################### |