16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 07:49:19 +02:00
This commit is contained in:
milek7
2018-12-09 19:03:02 +01:00
parent f525a77e23
commit 35af6d48d6
6 changed files with 86 additions and 35 deletions

View File

@@ -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);
}