TrinityCore
RASession.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __RASESSION_H__
19#define __RASESSION_H__
20
21#include "Define.h"
22#include <boost/asio/ip/tcp.hpp>
23#include <boost/asio/streambuf.hpp>
24#include <future>
25#include <memory>
26
27const size_t bufferSize = 4096;
28
29class RASession : public std::enable_shared_from_this <RASession>
30{
31public:
32 RASession(boost::asio::ip::tcp::socket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
33 {
34 }
35
36 void Start();
37
38 std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); }
39 uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); }
40
41private:
42 int Send(std::string_view data);
43 std::string ReadString();
44 bool CheckAccessLevel(const std::string& user);
45 bool ProcessCommand(std::string& command);
46
47 static void CommandPrint(void* callbackArg, std::string_view text);
48 static void CommandFinished(void* callbackArg, bool);
49
50 boost::asio::ip::tcp::socket _socket;
51 boost::asio::streambuf _readBuffer;
52 boost::asio::streambuf _writeBuffer;
53 std::promise<void>* _commandExecuting;
54};
55
56#endif
uint16_t uint16
Definition: Define.h:143
const size_t bufferSize
Definition: RASession.h:27
int Send(std::string_view data)
Definition: RASession.cpp:91
boost::asio::ip::tcp::socket _socket
Definition: RASession.h:50
std::string GetRemoteIpAddress() const
Definition: RASession.h:38
static void CommandFinished(void *callbackArg, bool)
Definition: RASession.cpp:188
std::string ReadString()
Definition: RASession.cpp:100
RASession(boost::asio::ip::tcp::socket &&socket)
Definition: RASession.h:32
bool CheckAccessLevel(const std::string &user)
Definition: RASession.cpp:120
std::promise< void > * _commandExecuting
Definition: RASession.h:53
boost::asio::streambuf _writeBuffer
Definition: RASession.h:52
boost::asio::streambuf _readBuffer
Definition: RASession.h:51
uint16 GetRemotePort() const
Definition: RASession.h:39
bool ProcessCommand(std::string &command)
Definition: RASession.cpp:152
static void CommandPrint(void *callbackArg, std::string_view text)
Definition: RASession.cpp:179
void Start()
Definition: RASession.cpp:30
STL namespace.