TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RASession.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __RASESSION_H__
20 #define __RASESSION_H__
21 
22 #include <memory>
23 #include <boost/asio/ip/tcp.hpp>
24 #include <boost/asio/streambuf.hpp>
25 #include "Common.h"
26 
27 #include <future>
28 
29 using boost::asio::ip::tcp;
30 
31 const size_t bufferSize = 4096;
32 
33 class RASession : public std::enable_shared_from_this <RASession>
34 {
35 public:
36  RASession(tcp::socket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
37  {
38  }
39 
40  void Start();
41 
42  const std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); }
43  unsigned short GetRemotePort() const { return _socket.remote_endpoint().port(); }
44 
45 private:
46  int Send(const char* data);
47  std::string ReadString();
48  bool CheckAccessLevel(const std::string& user);
49  bool CheckPassword(const std::string& user, const std::string& pass);
50  bool ProcessCommand(std::string& command);
51 
52  static void CommandPrint(void* callbackArg, const char* text);
53  static void CommandFinished(void* callbackArg, bool);
54 
55  tcp::socket _socket;
56  boost::asio::streambuf _readBuffer;
57  boost::asio::streambuf _writeBuffer;
58  std::promise<void>* _commandExecuting;
59 };
60 
61 #endif
int Send(const char *data)
Definition: RASession.cpp:93
static void CommandPrint(void *callbackArg, const char *text)
Definition: RASession.cpp:207
const size_t bufferSize
Definition: RASession.h:31
STL namespace.
const std::string GetRemoteIpAddress() const
Definition: RASession.h:42
void Start()
Definition: RASession.cpp:32
unsigned short GetRemotePort() const
Definition: RASession.h:43
bool CheckPassword(const std::string &user, const std::string &pass)
Definition: RASession.cpp:154
Definition: RASession.h:33
bool ProcessCommand(std::string &command)
Definition: RASession.cpp:180
RASession(tcp::socket &&socket)
Definition: RASession.h:36
bool CheckAccessLevel(const std::string &user)
Definition: RASession.cpp:122
boost::asio::streambuf _readBuffer
Definition: RASession.h:56
std::string ReadString()
Definition: RASession.cpp:102
tcp::socket _socket
Definition: RASession.h:55
std::promise< void > * _commandExecuting
Definition: RASession.h:58
boost::asio::streambuf _writeBuffer
Definition: RASession.h:57
static void CommandFinished(void *callbackArg, bool)
Definition: RASession.cpp:216