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

https://gitlab.com/IlluminatiCore/IlluminatiCore · C Header · 63 lines · 33 code · 13 blank · 17 comment · 0 complexity · aa90d3300ce31df34993e0f5d7e97559 MD5 · raw file

  1. /*
  2. * Copyright (C) 2008-2014 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. #ifndef __RASESSION_H__
  19. #define __RASESSION_H__
  20. #include <memory>
  21. #include <boost/asio/ip/tcp.hpp>
  22. #include <boost/asio/streambuf.hpp>
  23. #include "Common.h"
  24. #include <future>
  25. using boost::asio::ip::tcp;
  26. const size_t bufferSize = 4096;
  27. #define BUFFER_SIZE 4096
  28. class RASession : public std::enable_shared_from_this <RASession>
  29. {
  30. public:
  31. RASession(tcp::socket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
  32. {
  33. }
  34. void Start();
  35. const std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); }
  36. unsigned short GetRemotePort() const { return _socket.remote_endpoint().port(); }
  37. private:
  38. int Send(const char* data);
  39. std::string ReadString();
  40. bool CheckAccessLevel(const std::string& user);
  41. bool CheckPassword(const std::string& user, const std::string& pass);
  42. bool ProcessCommand(std::string& command);
  43. static void CommandPrint(void* callbackArg, const char* text);
  44. static void CommandFinished(void* callbackArg, bool);
  45. tcp::socket _socket;
  46. boost::asio::streambuf _readBuffer;
  47. boost::asio::streambuf _writeBuffer;
  48. std::promise<void>* _commandExecuting;
  49. };
  50. #endif