aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/authserver/Server/AuthServer.cpp3
-rw-r--r--src/server/shared/CMakeLists.txt3
-rw-r--r--src/server/shared/Networking/AsyncAcceptor.h54
-rw-r--r--src/server/worldserver/CMakeLists.txt1
-rw-r--r--src/server/worldserver/Main.cpp3
-rw-r--r--src/server/worldserver/Master.cpp21
-rw-r--r--src/server/worldserver/Master.h2
-rw-r--r--src/server/worldserver/RemoteAccess/RARunnable.cpp2
-rw-r--r--src/server/worldserver/RemoteAccess/RASession.cpp52
-rw-r--r--src/server/worldserver/RemoteAccess/RASession.h56
10 files changed, 184 insertions, 13 deletions
diff --git a/src/server/authserver/Server/AuthServer.cpp b/src/server/authserver/Server/AuthServer.cpp
index 5c3ef247254..c5a0cff186f 100644
--- a/src/server/authserver/Server/AuthServer.cpp
+++ b/src/server/authserver/Server/AuthServer.cpp
@@ -35,6 +35,3 @@ void AuthServer::AsyncAccept()
AsyncAccept();
});
}
-
-
-
diff --git a/src/server/shared/CMakeLists.txt b/src/server/shared/CMakeLists.txt
index 63aecab0fb7..a61248f01ea 100644
--- a/src/server/shared/CMakeLists.txt
+++ b/src/server/shared/CMakeLists.txt
@@ -18,6 +18,7 @@ file(GLOB_RECURSE sources_Database Database/*.cpp Database/*.h)
file(GLOB_RECURSE sources_DataStores DataStores/*.cpp DataStores/*.h)
file(GLOB_RECURSE sources_Dynamic Dynamic/*.cpp Dynamic/*.h)
file(GLOB_RECURSE sources_Logging Logging/*.cpp Logging/*.h)
+file(GLOB_RECURSE sources_Networking Networking/*.cpp Networking/*.h)
file(GLOB_RECURSE sources_Packets Packets/*.cpp Packets/*.h)
file(GLOB_RECURSE sources_Threading Threading/*.cpp Threading/*.h)
file(GLOB_RECURSE sources_Utilities Utilities/*.cpp Utilities/*.h)
@@ -47,6 +48,7 @@ set(shared_STAT_SRCS
${sources_Debugging}
${sources_Dynamic}
${sources_Logging}
+ ${sources_Networking}
${sources_Packets}
${sources_Threading}
${sources_Utilities}
@@ -68,6 +70,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/Debugging
${CMAKE_CURRENT_SOURCE_DIR}/Dynamic
${CMAKE_CURRENT_SOURCE_DIR}/Logging
+ ${CMAKE_CURRENT_SOURCE_DIR}/Networking
${CMAKE_CURRENT_SOURCE_DIR}/Packets
${CMAKE_CURRENT_SOURCE_DIR}/Threading
${CMAKE_CURRENT_SOURCE_DIR}/Utilities
diff --git a/src/server/shared/Networking/AsyncAcceptor.h b/src/server/shared/Networking/AsyncAcceptor.h
new file mode 100644
index 00000000000..c54471fd01a
--- /dev/null
+++ b/src/server/shared/Networking/AsyncAcceptor.h
@@ -0,0 +1,54 @@
+/*
+* 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 __ASYNCACCEPT_H_
+#define __ASYNCACCEPT_H_
+
+#include <boost/asio.hpp>
+
+using boost::asio::ip::tcp;
+
+template <class T>
+class AsyncAcceptor
+{
+public:
+ AsyncAcceptor(boost::asio::io_service& ioService, std::string bindIp, int port) :
+ _socket(ioService),
+ _acceptor(ioService, tcp::endpoint(boost::asio::ip::address::from_string(bindIp), port))
+ {
+ AsyncAccept();
+ };
+
+private:
+ void AsyncAcceptor::AsyncAccept()
+ {
+ _acceptor.async_accept(_socket, [this](boost::system::error_code error)
+ {
+ if (!error)
+ {
+ std::make_shared<T>(std::move(_socket))->Start();
+ }
+
+ AsyncAccept();
+ });
+ }
+
+ tcp::acceptor _acceptor;
+ tcp::socket _socket;
+};
+
+#endif /* __ASYNCACCEPT_H_ */
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