1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00
Files
vcmi/lib/serializer/Connection.h

92 lines
2.1 KiB
C
Raw Permalink Normal View History

/*
* Connection.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "BinaryDeserializer.h"
#include "BinarySerializer.h"
2023-01-18 02:02:17 +04:00
#include "../EnetService.h"
VCMI_LIB_NAMESPACE_BEGIN
struct CPack;
struct ConnectionBuffers;
/// Main class for network communication
/// Allows establishing connection and bidirectional read-write
class DLL_LINKAGE CConnection
: public IBinaryReader, public IBinaryWriter, public std::enable_shared_from_this<CConnection>
{
2023-01-18 02:02:17 +04:00
std::shared_ptr<EnetConnection> enetConnection;
void reportState(vstd::CLoggerBase * out) override;
int write(const void * data, unsigned size) override;
int read(void * data, unsigned size) override;
2023-01-03 03:52:44 +04:00
BinaryDeserializer iser;
BinarySerializer oser;
2023-01-10 04:47:00 +04:00
bool connected;
2023-01-10 04:47:00 +04:00
boost::mutex mutexRead;
boost::mutex mutexWrite;
public:
bool myEndianess, contactEndianess; //true if little endian, if endianness is different we'll have to revert received multi-byte vars
std::string contactUuid;
std::string name; //who uses this connection
std::string uuid;
int connectionID;
std::shared_ptr<boost::thread> handler;
2023-01-18 02:02:17 +04:00
CConnection(std::shared_ptr<EnetConnection>, std::string Name, std::string UUID);
const std::shared_ptr<EnetConnection> getEnetConnection() const;
2023-01-18 02:02:17 +04:00
void init();
void close();
bool isOpen() const;
template<class T>
CConnection &operator&(const T&);
virtual ~CConnection();
CPack * retrievePack();
void sendPack(const CPack * pack);
void disableStackSendingByID();
void enableStackSendingByID();
void disableSmartPointerSerialization();
2016-11-13 12:44:46 +03:00
void enableSmartPointerSerialization();
void disableSmartVectorMemberSerialization();
void enableSmartVectorMemberSerializatoin();
void enterLobbyConnectionMode();
void enterGameplayConnectionMode(CGameState * gs);
2017-08-11 16:50:00 +03:00
std::string toString() const;
template<class T>
CConnection & operator>>(T &t)
{
iser & t;
return * this;
}
template<class T>
CConnection & operator<<(const T &t)
{
oser & t;
return * this;
}
};
VCMI_LIB_NAMESPACE_END