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/RemoteAccess | |
| parent | c8fe4b8d5084dd26eb96a082422fcd68c090debc (diff) | |
Some ground work for ASIO based RemoteAccess handling
Diffstat (limited to 'src/server/worldserver/RemoteAccess')
| -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 |
3 files changed, 109 insertions, 1 deletions
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 |
