Files
Viano-Core/src/server/game/Server/WorldSocket.h
T
Shauren 548aa119ac Core/Networking: Fixed unsafe access to _worldSession member in WorldSocket
(cherry picked from commit bed88e0dd475af5b73cea03821f7fb7cb9ddce9d)

Core/Networking: Fixed deadlock in HandlePing if the client is about to be kicked for overspeed pings

(cherry picked from commit 3da0f7e40920b652d2222fa88dbb4b516d24725d)

Core/Networking: Cleanup CloseSocket calls from read failures in WorldSocket

(cherry picked from commit 18343a7309fbf53a3509749c0a5ca1f8ea273c57)

Conflicts:
	src/server/game/Server/WorldSocket.cpp

Ref #14474
2015-04-04 23:07:41 +01:00

93 lines
2.5 KiB
C++

/*
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WORLDSOCKET_H__
#define __WORLDSOCKET_H__
#include "Common.h"
#include "AuthCrypt.h"
#include "ServerPktHeader.h"
#include "Socket.h"
#include "Util.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include <chrono>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/buffer.hpp>
using boost::asio::ip::tcp;
#pragma pack(push, 1)
struct ClientPktHeader
{
uint16 size;
uint32 cmd;
bool IsValidSize() const { return size >= 4 && size < 10240; }
bool IsValidOpcode() const { return cmd < NUM_MSG_TYPES; }
};
#pragma pack(pop)
class WorldSocket : public Socket<WorldSocket>
{
public:
WorldSocket(tcp::socket&& socket);
WorldSocket(WorldSocket const& right) = delete;
WorldSocket& operator=(WorldSocket const& right) = delete;
void Start() override;
void SendPacket(WorldPacket const& packet);
protected:
void OnClose() override;
void ReadHandler() override;
bool ReadHeaderHandler();
bool ReadDataHandler();
private:
/// writes network.opcode log
/// accessing WorldSession is not threadsafe, only do it when holding _worldSessionLock
void LogOpcodeText(uint16 opcode, std::unique_lock<std::mutex> const& guard) const;
/// sends and logs network.opcode without accessing WorldSession
void SendPacketAndLogOpcode(WorldPacket const& packet);
void HandleSendAuthSession();
void HandleAuthSession(WorldPacket& recvPacket);
void SendAuthResponseError(uint8 code);
bool HandlePing(WorldPacket& recvPacket);
uint32 _authSeed;
AuthCrypt _authCrypt;
std::chrono::steady_clock::time_point _LastPingTime;
uint32 _OverSpeedPings;
std::mutex _worldSessionLock;
WorldSession* _worldSession;
bool _authed;
MessageBuffer _headerBuffer;
MessageBuffer _packetBuffer;
};
#endif