diff options
| author | leak <leak@bitmx.net> | 2014-07-02 17:38:44 +0200 |
|---|---|---|
| committer | leak <leak@bitmx.net> | 2014-07-02 17:38:44 +0200 |
| commit | 310f5e68467ee61b66796fdd88c7c9691d4bd2a0 (patch) | |
| tree | f182c5e0eb4d31c63dd851177b3afce2e1b187a0 /src/server/worldserver | |
| parent | c8fe4b8d5084dd26eb96a082422fcd68c090debc (diff) | |
Some ground work for ASIO based RemoteAccess handling
Diffstat (limited to 'src/server/worldserver')
| -rw-r--r-- | src/server/worldserver/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/server/worldserver/Main.cpp | 3 | ||||
| -rw-r--r-- | src/server/worldserver/Master.cpp | 21 | ||||
| -rw-r--r-- | src/server/worldserver/Master.h | 2 | ||||
| -rw-r--r-- | src/server/worldserver/RemoteAccess/RARunnable.cpp | 2 | ||||
| -rw-r--r-- | src/server/worldserver/RemoteAccess/RASession.cpp | 52 | ||||
| -rw-r--r-- | src/server/worldserver/RemoteAccess/RASession.h | 56 |
7 files changed, 127 insertions, 10 deletions
diff --git a/src/server/worldserver/CMakeLists.txt b/src/server/worldserver/CMakeLists.txt index c006e6c925c..9d2e859a7de 100644 --- a/src/server/worldserver/CMakeLists.txt +++ b/src/server/worldserver/CMakeLists.txt @@ -62,6 +62,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic/LinkedReference ${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic ${CMAKE_SOURCE_DIR}/src/server/shared/Logging + ${CMAKE_SOURCE_DIR}/src/server/shared/Networking ${CMAKE_SOURCE_DIR}/src/server/shared/Packets ${CMAKE_SOURCE_DIR}/src/server/shared/Threading ${CMAKE_SOURCE_DIR}/src/server/shared/Utilities diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 75d9ca5145d..bcc058c7fb3 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -22,7 +22,6 @@ #include <openssl/opensslv.h> #include <openssl/crypto.h> -#include <ace/Version.h> #include "Common.h" #include "Database/DatabaseEnv.h" @@ -135,7 +134,7 @@ extern int main(int argc, char** argv) TC_LOG_INFO("server.worldserver", "Using configuration file %s.", cfg_file); TC_LOG_INFO("server.worldserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); - TC_LOG_INFO("server.worldserver", "Using ACE version: %s", ACE_VERSION); + TC_LOG_INFO("server.worldserver", "Using Boost version: %s", BOOST_LIB_VERSION); ///- and run the 'Master' /// @todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd? diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index 920dc766900..5318652ad88 100644 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -22,7 +22,8 @@ #include <thread> -#include "Common.h" +#include "Master.h" + #include "SystemConfig.h" #include "World.h" #include "WorldRunnable.h" @@ -31,19 +32,17 @@ #include "Configuration/Config.h" #include "Database/DatabaseEnv.h" #include "Database/DatabaseWorkerPool.h" - #include "CliRunnable.h" #include "Log.h" -#include "Master.h" #include "RARunnable.h" #include "TCSoap.h" #include "Timer.h" #include "Util.h" #include "RealmList.h" - #include "BigNumber.h" #include "OpenSSLCrypto.h" -#include <boost/asio.hpp> +#include "AsyncAcceptor.h" +#include "RASession.h" #ifdef _WIN32 #include "ServiceWin32.h" @@ -165,8 +164,8 @@ int Master::Run() cliThread = new std::thread(CliThread); } - // TODO C++11/Boost - // std::thread rarThread(RemoteAccessThread); + if (sConfigMgr->GetBoolDefault("Ra.Enable", false)) + StartRaSocketAcceptor(_ioService); #if defined(_WIN32) || defined(__linux__) @@ -470,3 +469,11 @@ void Master::ClearOnlineAccounts() // Battleground instance ids reset at server restart CharacterDatabase.DirectExecute("UPDATE character_battleground_data SET instanceId = 0"); } + +void Master::StartRaSocketAcceptor(boost::asio::io_service& ioService) +{ + uint16 raPort = uint16(sConfigMgr->GetIntDefault("Ra.Port", 3443)); + std::string raListener = sConfigMgr->GetStringDefault("Ra.IP", "0.0.0.0"); + + AsyncAcceptor<RASession> raAcceptor(ioService, raListener, raPort); +} diff --git a/src/server/worldserver/Master.h b/src/server/worldserver/Master.h index d2a51b85f4b..3567d5ea933 100644 --- a/src/server/worldserver/Master.h +++ b/src/server/worldserver/Master.h @@ -23,6 +23,7 @@ #ifndef _MASTER_H #define _MASTER_H +#include <boost/asio.hpp> #include "Common.h" /// Start the server @@ -42,6 +43,7 @@ class Master void _StopDB(); void ClearOnlineAccounts(); + void StartRaSocketAcceptor(boost::asio::io_service& ioService); }; #define sMaster Master::instance() diff --git a/src/server/worldserver/RemoteAccess/RARunnable.cpp b/src/server/worldserver/RemoteAccess/RARunnable.cpp index 4efeb07ef25..b3461af5a87 100644 --- a/src/server/worldserver/RemoteAccess/RARunnable.cpp +++ b/src/server/worldserver/RemoteAccess/RARunnable.cpp @@ -22,7 +22,7 @@ #include "Common.h" #include "Config.h" #include "Log.h" -#include "RARunnable.h" +#include "RARunnable.h", #include "World.h" #include <ace/Reactor_Impl.h> diff --git a/src/server/worldserver/RemoteAccess/RASession.cpp b/src/server/worldserver/RemoteAccess/RASession.cpp new file mode 100644 index 00000000000..1438557e924 --- /dev/null +++ b/src/server/worldserver/RemoteAccess/RASession.cpp @@ -0,0 +1,52 @@ +/* +* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/> +* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along +* with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <memory> +#include <boost/asio.hpp> +#include <RASession.h> + +using boost::asio::ip::tcp; + +void RASession::AsyncRead() +{ + auto self(shared_from_this()); + + _socket.async_read_some(boost::asio::buffer(_readBuffer, 1), [this, self](boost::system::error_code error, size_t transferedBytes) + { + if (!error && transferedBytes == 1) + { + // let the magic happen + } + else + { + _socket.close(); + } + }); +} + +void RASession::AsyncWrite(std::size_t length) +{ + boost::asio::async_write(_socket, boost::asio::buffer(_writeBuffer, length), [this](boost::system::error_code error, std::size_t /*length*/) + { + if (error) + { + _socket.close(); + } + }); +} + diff --git a/src/server/worldserver/RemoteAccess/RASession.h b/src/server/worldserver/RemoteAccess/RASession.h new file mode 100644 index 00000000000..ed2a83a4f2c --- /dev/null +++ b/src/server/worldserver/RemoteAccess/RASession.h @@ -0,0 +1,56 @@ +/* +* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/> +* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along +* with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __RASESSION_H__ +#define __RASESSION_H__ + +#include <memory> +#include <boost/asio.hpp> +#include "Common.h" + +using boost::asio::ip::tcp; + +const size_t bufferSize = 4096; + +#define BUFFER_SIZE 4096 + +class RASession : public std::enable_shared_from_this <RASession> +{ +public: + RASession(tcp::socket socket) : _socket(std::move(socket)) + { + } + + void Start() + { + AsyncRead(); + } + + const std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); }; + unsigned short GetRemotePort() const { return _socket.remote_endpoint().port(); } + +private: + void AsyncRead(); + void AsyncWrite(size_t length); + + tcp::socket _socket; + char _readBuffer[BUFFER_SIZE]; + char _writeBuffer[BUFFER_SIZE]; +}; + +#endif |
