PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/server/worldserver/RemoteAccess/RASession.h

https://gitlab.com/tkrokli/TrinityCore_434
C Header | 61 lines | 32 code | 12 blank | 17 comment | 0 complexity | bebf9f6a8ad7faa28ac5173e6128c9ee MD5 | raw file
 1/*
 2* Copyright (C) 2008-2015 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
29using boost::asio::ip::tcp;
30
31const size_t bufferSize = 4096;
32
33class RASession : public std::enable_shared_from_this <RASession>
34{
35public:
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
45private:
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