mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 07:49:19 +02:00
work
This commit is contained in:
@@ -7,12 +7,38 @@ void network::connection::connected()
|
||||
WriteLog("net: socket connected", logtype::net);
|
||||
}
|
||||
|
||||
void network::connection::message_received(message msg)
|
||||
void network::connection::message_received(message &msg)
|
||||
{
|
||||
if (msg.type == message::TYPE_MAX)
|
||||
{
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.type == message::CONNECT_REQUEST)
|
||||
{
|
||||
message reply({message::CONNECT_ACCEPT});
|
||||
|
||||
std::string reply_buf;
|
||||
std::ostringstream stream(reply_buf);
|
||||
reply.serialize(stream);
|
||||
}
|
||||
}
|
||||
|
||||
void network::connection::data_received(uint8_t *buffer, size_t len)
|
||||
void network::connection::data_received(std::string &buffer)
|
||||
{
|
||||
std::istringstream body(buffer);
|
||||
message msg = message::deserialize(body);
|
||||
|
||||
message_received(msg);
|
||||
}
|
||||
|
||||
void network::connection::send_message(message &msg)
|
||||
{
|
||||
std::shared_ptr<std::string> buf = std::make_shared<std::string>();
|
||||
std::ostringstream stream(*buf.get());
|
||||
msg.serialize(stream);
|
||||
stream.flush();
|
||||
|
||||
send_data(buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user