Skip to content

Commit

Permalink
Stop messages to tracker creating endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Bqleine committed Aug 24, 2023
1 parent 5e0e16b commit f58069b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SRC = main.cpp \
upnp_init.cpp \
upnp_actions.cpp \
Bot.cpp

SRC_UPNP = upnp.cpp \
upnp_init.cpp \
upnp_actions.cpp
Expand Down
8 changes: 5 additions & 3 deletions client/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void bot(asio::ip::tcp::socket &socket)
b.connectToTracker();
}

void tracker(asio::ip::tcp::socket &socket)
[[noreturn]] void tracker(asio::ip::tcp::socket &socket)
{
asio::io_service io_service;
asio::ip::tcp::acceptor acceptor_server(io_service, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 3612));
Expand All @@ -26,10 +26,12 @@ void tracker(asio::ip::tcp::socket &socket)
}
});
while (true) {
asio::read_until(socket, asio::dynamic_buffer(received_buffer), "\r\n");
std::size_t n = asio::read_until(socket, asio::dynamic_buffer(received_buffer), "\r\n");
std::cout << "Sending message to all bots: " << received_buffer << std::endl;
std::string line = received_buffer.substr(0, n);
received_buffer.erase(0, n);
for (auto &client : clients) {
asio::write(client, asio::buffer(received_buffer));
asio::write(client, asio::buffer(line));
}
}
}
Expand Down

0 comments on commit f58069b

Please sign in to comment.