![]() |
Botcraft 1.21.4
|
#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< AESEncrypter > | encrypter |
std::atomic< bool > | initialized |
Definition at line 17 of file TCP_Com.hpp.
Botcraft::TCP_Com::TCP_Com | ( | const std::string & | address, |
std::function< void(const std::vector< unsigned char > &)> | callback | ||
) |
Definition at line 20 of file TCP_Com.cpp.
References Botcraft::Logger::GetInstance(), handle_connect(), io_service, ip, LOG_INFO, NewPacketCallback, port, Botcraft::Logger::RegisterThread(), SetIPAndPortFromAddress(), socket, and thread_com.
Botcraft::TCP_Com::~TCP_Com | ( | ) |
Definition at line 40 of file TCP_Com.cpp.
References Botcraft::Logger::GetInstance(), thread_com, and Botcraft::Logger::UnregisterThread().
void Botcraft::TCP_Com::close | ( | ) |
Definition at line 93 of file TCP_Com.cpp.
References do_close(), and io_service.
|
private |
Definition at line 222 of file TCP_Com.cpp.
References socket.
Referenced by close(), handle_read(), and handle_write().
|
private |
Definition at line 182 of file TCP_Com.cpp.
References handle_write(), mutex_output, output_msg, and socket.
Referenced by SendPacket().
const std::string & Botcraft::TCP_Com::GetIp | ( | ) | const |
Definition at line 83 of file TCP_Com.cpp.
References ip.
const unsigned short Botcraft::TCP_Com::GetPort | ( | ) | const |
Definition at line 88 of file TCP_Com.cpp.
References port.
|
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().
|
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().
|
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().
bool Botcraft::TCP_Com::IsInitialized | ( | ) | const |
Definition at line 49 of file TCP_Com.cpp.
References initialized.
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.
void Botcraft::TCP_Com::SetEncrypter | ( | const std::shared_ptr< AESEncrypter > | encrypter_ | ) |
Definition at line 77 of file TCP_Com.cpp.
References encrypter.
|
private |
Definition at line 227 of file TCP_Com.cpp.
References Botcraft::DNSMessage::GetAnswers(), Botcraft::DNSSrvData::GetNameLabels(), Botcraft::DNSMessage::GetNumberAnswer(), Botcraft::DNSSrvData::GetPort(), io_service, ip, LOG_INFO, LOG_WARNING, port, ProtocolCraft::NetworkType::Read(), Botcraft::DNSQuestion::SetClassCode(), Botcraft::DNSMessage::SetFlagAA(), Botcraft::DNSMessage::SetFlagOPCode(), Botcraft::DNSMessage::SetFlagQR(), Botcraft::DNSMessage::SetFlagRA(), Botcraft::DNSMessage::SetFlagRCode(), Botcraft::DNSMessage::SetFlagRD(), Botcraft::DNSMessage::SetFlagTC(), Botcraft::DNSMessage::SetFlagZ(), Botcraft::DNSMessage::SetIdentification(), Botcraft::DNSQuestion::SetNameLabels(), Botcraft::DNSMessage::SetNumberAdditionalRR(), Botcraft::DNSMessage::SetNumberAnswer(), Botcraft::DNSMessage::SetNumberAuthority(), Botcraft::DNSMessage::SetNumberQuestion(), Botcraft::DNSMessage::SetQuestions(), Botcraft::DNSQuestion::SetTypeCode(), Botcraft::Utilities::SplitString(), and ProtocolCraft::NetworkType::Write().
Referenced by TCP_Com().
|
private |
Definition at line 69 of file TCP_Com.hpp.
Referenced by handle_read(), SendPacket(), and SetEncrypter().
|
private |
Definition at line 72 of file TCP_Com.hpp.
Referenced by handle_connect(), and IsInitialized().
|
private |
Definition at line 59 of file TCP_Com.hpp.
Referenced by handle_read().
|
private |
Definition at line 53 of file TCP_Com.hpp.
Referenced by close(), SendPacket(), SetIPAndPortFromAddress(), and TCP_Com().
|
private |
Definition at line 65 of file TCP_Com.hpp.
Referenced by GetIp(), SetIPAndPortFromAddress(), and TCP_Com().
|
private |
Definition at line 63 of file TCP_Com.hpp.
Referenced by do_write(), and handle_write().
|
private |
Definition at line 62 of file TCP_Com.hpp.
Referenced by handle_read(), and TCP_Com().
|
private |
Definition at line 60 of file TCP_Com.hpp.
Referenced by do_write(), and handle_write().
|
private |
Definition at line 66 of file TCP_Com.hpp.
Referenced by GetPort(), SetIPAndPortFromAddress(), and TCP_Com().
|
private |
Definition at line 58 of file TCP_Com.hpp.
Referenced by handle_connect(), and handle_read().
|
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().
|
private |
Definition at line 56 of file TCP_Com.hpp.
Referenced by TCP_Com(), and ~TCP_Com().