PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/server/game/Server/WorldSocket.h

https://gitlab.com/IlluminatiCore/IlluminatiCore
C Header | 90 lines | 51 code | 22 blank | 17 comment | 1 complexity | fc9620fa3c63e95365f61d973e4becae MD5 | raw file
Possible License(s): GPL-2.0, BSD-2-Clause
  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 __WORLDSOCKET_H__
  19. #define __WORLDSOCKET_H__
  20. #include "Common.h"
  21. #include "WorldPacketCrypt.h"
  22. #include "ServerPktHeader.h"
  23. #include "Socket.h"
  24. #include "Util.h"
  25. #include "WorldPacket.h"
  26. #include "WorldSession.h"
  27. #include <chrono>
  28. #include <boost/asio/ip/tcp.hpp>
  29. #include <boost/asio/buffer.hpp>
  30. using boost::asio::ip::tcp;
  31. #pragma pack(push, 1)
  32. struct ClientPktHeader
  33. {
  34. uint16 size;
  35. uint32 cmd;
  36. bool IsValidSize() const { return size >= 4 && size < 10240; }
  37. bool IsValidOpcode() const { return cmd < NUM_OPCODE_HANDLERS; }
  38. };
  39. #pragma pack(pop)
  40. class WorldSocket : public Socket<WorldSocket>
  41. {
  42. static std::string const ServerConnectionInitialize;
  43. static std::string const ClientConnectionInitialize;
  44. public:
  45. WorldSocket(tcp::socket&& socket);
  46. WorldSocket(WorldSocket const& right) = delete;
  47. WorldSocket& operator=(WorldSocket const& right) = delete;
  48. void Start() override;
  49. void SendPacket(WorldPacket& packet);
  50. protected:
  51. void ReadHandler() override;
  52. bool ReadHeaderHandler();
  53. bool ReadDataHandler();
  54. private:
  55. void HandleSendAuthSession();
  56. void HandleAuthSession(WorldPacket& recvPacket);
  57. void SendAuthResponseError(uint8 code);
  58. void HandlePing(WorldPacket& recvPacket);
  59. uint32 _authSeed;
  60. WorldPacketCrypt _authCrypt;
  61. std::chrono::steady_clock::time_point _LastPingTime;
  62. uint32 _OverSpeedPings;
  63. WorldSession* _worldSession;
  64. MessageBuffer _headerBuffer;
  65. MessageBuffer _packetBuffer;
  66. bool _initialized;
  67. };
  68. #endif