Botcraft 1.21.4
Loading...
Searching...
No Matches
Botcraft::TCP_Com Class Reference

#include <TCP_Com.hpp>

Public Member Functions

 TCP_Com (const std::string &address, std::function< void(const std::vector< unsigned char > &)> callback)
 
 ~TCP_Com ()
 
bool IsInitialized () const
 
void close ()
 
void SendPacket (const std::vector< unsigned char > &msg)
 
void SetEncrypter (const std::shared_ptr< AESEncrypter > encrypter_)
 
const std::string & GetIp () const
 
const unsigned short GetPort () const
 

Private Member Functions

void handle_connect (const asio::error_code &error)
 
void handle_read (const asio::error_code &error, std::size_t bytes_transferred)
 
void do_write (const std::vector< unsigned char > &msg)
 
void handle_write (const asio::error_code &error)
 
void do_close ()
 
void SetIPAndPortFromAddress (const std::string &address)
 

Private Attributes

asio::io_service io_service
 
asio::ip::tcp::socket socket
 
std::thread thread_com
 
std::array< unsigned char, 512 > read_msg
 
std::vector< unsigned char > input_msg
 
std::deque< std::vector< unsigned char > > output_msg
 
std::function< void(const std::vector< unsigned char > &)> NewPacketCallback
 
std::mutex mutex_output
 
std::string ip
 
unsigned short port
 
std::shared_ptr< AESEncrypterencrypter
 
std::atomic< bool > initialized
 

Detailed Description

Definition at line 17 of file TCP_Com.hpp.

Constructor & Destructor Documentation

◆ TCP_Com()

Botcraft::TCP_Com::TCP_Com ( const std::string &  address,
std::function< void(const std::vector< unsigned char > &)>  callback 
)

◆ ~TCP_Com()

Botcraft::TCP_Com::~TCP_Com ( )

Member Function Documentation

◆ close()

void Botcraft::TCP_Com::close ( )

Definition at line 93 of file TCP_Com.cpp.

References do_close(), and io_service.

◆ do_close()

void Botcraft::TCP_Com::do_close ( )
private

Definition at line 222 of file TCP_Com.cpp.

References socket.

Referenced by close(), handle_read(), and handle_write().

◆ do_write()

void Botcraft::TCP_Com::do_write ( const std::vector< unsigned char > &  msg)
private

Definition at line 182 of file TCP_Com.cpp.

References handle_write(), mutex_output, output_msg, and socket.

Referenced by SendPacket().

◆ GetIp()

const std::string & Botcraft::TCP_Com::GetIp ( ) const

Definition at line 83 of file TCP_Com.cpp.

References ip.

◆ GetPort()

const unsigned short Botcraft::TCP_Com::GetPort ( ) const

Definition at line 88 of file TCP_Com.cpp.

References port.

◆ handle_connect()

void Botcraft::TCP_Com::handle_connect ( const asio::error_code &  error)
private

Definition at line 98 of file TCP_Com.cpp.

References handle_read(), initialized, LOG_ERROR, LOG_INFO, read_msg, and socket.

Referenced by TCP_Com().

◆ handle_read()

void Botcraft::TCP_Com::handle_read ( const asio::error_code &  error,
std::size_t  bytes_transferred 
)
private

Definition at line 114 of file TCP_Com.cpp.

References do_close(), encrypter, handle_read(), input_msg, NewPacketCallback, read_msg, and socket.

Referenced by handle_connect(), and handle_read().

◆ handle_write()

void Botcraft::TCP_Com::handle_write ( const asio::error_code &  error)
private

Definition at line 199 of file TCP_Com.cpp.

References do_close(), handle_write(), mutex_output, output_msg, and socket.

Referenced by do_write(), and handle_write().

◆ IsInitialized()

bool Botcraft::TCP_Com::IsInitialized ( ) const

Definition at line 49 of file TCP_Com.cpp.

References initialized.

◆ SendPacket()

void Botcraft::TCP_Com::SendPacket ( const std::vector< unsigned char > &  msg)

Definition at line 54 of file TCP_Com.cpp.

References do_write(), encrypter, and io_service.

◆ SetEncrypter()

void Botcraft::TCP_Com::SetEncrypter ( const std::shared_ptr< AESEncrypter encrypter_)

Definition at line 77 of file TCP_Com.cpp.

References encrypter.

◆ SetIPAndPortFromAddress()

Member Data Documentation

◆ encrypter

std::shared_ptr<AESEncrypter> Botcraft::TCP_Com::encrypter
private

Definition at line 69 of file TCP_Com.hpp.

Referenced by handle_read(), SendPacket(), and SetEncrypter().

◆ initialized

std::atomic<bool> Botcraft::TCP_Com::initialized
private

Definition at line 72 of file TCP_Com.hpp.

Referenced by handle_connect(), and IsInitialized().

◆ input_msg

std::vector<unsigned char> Botcraft::TCP_Com::input_msg
private

Definition at line 59 of file TCP_Com.hpp.

Referenced by handle_read().

◆ io_service

asio::io_service Botcraft::TCP_Com::io_service
private

Definition at line 53 of file TCP_Com.hpp.

Referenced by close(), SendPacket(), SetIPAndPortFromAddress(), and TCP_Com().

◆ ip

std::string Botcraft::TCP_Com::ip
private

Definition at line 65 of file TCP_Com.hpp.

Referenced by GetIp(), SetIPAndPortFromAddress(), and TCP_Com().

◆ mutex_output

std::mutex Botcraft::TCP_Com::mutex_output
private

Definition at line 63 of file TCP_Com.hpp.

Referenced by do_write(), and handle_write().

◆ NewPacketCallback

std::function<void(const std::vector<unsigned char>&)> Botcraft::TCP_Com::NewPacketCallback
private

Definition at line 62 of file TCP_Com.hpp.

Referenced by handle_read(), and TCP_Com().

◆ output_msg

std::deque<std::vector<unsigned char> > Botcraft::TCP_Com::output_msg
private

Definition at line 60 of file TCP_Com.hpp.

Referenced by do_write(), and handle_write().

◆ port

unsigned short Botcraft::TCP_Com::port
private

Definition at line 66 of file TCP_Com.hpp.

Referenced by GetPort(), SetIPAndPortFromAddress(), and TCP_Com().

◆ read_msg

std::array<unsigned char, 512> Botcraft::TCP_Com::read_msg
private

Definition at line 58 of file TCP_Com.hpp.

Referenced by handle_connect(), and handle_read().

◆ socket

asio::ip::tcp::socket Botcraft::TCP_Com::socket
private

Definition at line 54 of file TCP_Com.hpp.

Referenced by do_close(), do_write(), handle_connect(), handle_read(), handle_write(), and TCP_Com().

◆ thread_com

std::thread Botcraft::TCP_Com::thread_com
private

Definition at line 56 of file TCP_Com.hpp.

Referenced by TCP_Com(), and ~TCP_Com().


The documentation for this class was generated from the following files: