mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +02:00
work
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
#include "network/network.h"
|
||||
#include "network/message.h"
|
||||
#include "Logs.h"
|
||||
#include "sn_utils.h"
|
||||
|
||||
void network::connection::connected()
|
||||
{
|
||||
WriteLog("net: socket connected", logtype::net);
|
||||
|
||||
message hello;
|
||||
hello.type = message::CONNECT_REQUEST;
|
||||
send_message(hello);
|
||||
}
|
||||
|
||||
void network::connection::message_received(message &msg)
|
||||
@@ -19,6 +24,8 @@ void network::connection::message_received(message &msg)
|
||||
{
|
||||
message reply({message::CONNECT_ACCEPT});
|
||||
|
||||
WriteLog("client accepted", logtype::net);
|
||||
|
||||
std::string reply_buf;
|
||||
std::ostringstream stream(reply_buf);
|
||||
reply.serialize(stream);
|
||||
@@ -35,10 +42,12 @@ void network::connection::data_received(std::string &buffer)
|
||||
|
||||
void network::connection::send_message(message &msg)
|
||||
{
|
||||
std::shared_ptr<std::string> buf = std::make_shared<std::string>();
|
||||
std::ostringstream stream(*buf.get());
|
||||
std::ostringstream stream;
|
||||
sn_utils::ls_uint32(stream, 0x37305545);
|
||||
sn_utils::ls_uint32(stream, 2);
|
||||
msg.serialize(stream);
|
||||
stream.flush();
|
||||
|
||||
std::shared_ptr<std::string> buf = std::make_shared<std::string>(stream.str());
|
||||
send_data(buf);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
network::tcp_conn::tcp_conn(asio::io_context &io_ctx)
|
||||
: m_socket(io_ctx)
|
||||
{
|
||||
m_header_buffer.resize(12);
|
||||
m_header_buffer.resize(8);
|
||||
}
|
||||
|
||||
void network::tcp_conn::disconnect()
|
||||
@@ -16,6 +16,7 @@ void network::tcp_conn::disconnect()
|
||||
|
||||
void network::tcp_conn::connected()
|
||||
{
|
||||
connection::connected();
|
||||
read_header();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user