allow to specify the server
This commit is contained in:
parent
56aa4261f6
commit
61ae519b09
14
src/main.cc
14
src/main.cc
|
@ -46,6 +46,7 @@ class Bot {
|
||||||
asio::any_io_executor executor;
|
asio::any_io_executor executor;
|
||||||
asio::steady_timer timer;
|
asio::steady_timer timer;
|
||||||
asio::ip::tcp::socket socket;
|
asio::ip::tcp::socket socket;
|
||||||
|
std::string server;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string pass;
|
std::string pass;
|
||||||
std::random_device generator;
|
std::random_device generator;
|
||||||
|
@ -63,14 +64,15 @@ class Bot {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bot(asio::any_io_executor executor, std::string_view name,
|
Bot(asio::any_io_executor executor, std::string_view name,
|
||||||
std::string_view pass);
|
std::string_view pass, std::string_view server);
|
||||||
};
|
};
|
||||||
|
|
||||||
Bot::Bot(asio::any_io_executor executor, std::string_view name,
|
Bot::Bot(asio::any_io_executor executor, std::string_view name,
|
||||||
std::string_view pass)
|
std::string_view pass, std::string_view server)
|
||||||
: executor{executor},
|
: executor{executor},
|
||||||
timer{executor},
|
timer{executor},
|
||||||
socket{executor},
|
socket{executor},
|
||||||
|
server{server},
|
||||||
name{name},
|
name{name},
|
||||||
pass{pass} {
|
pass{pass} {
|
||||||
asio::co_spawn(executor, std::bind(&Bot::Protocol, this), asio::detached);
|
asio::co_spawn(executor, std::bind(&Bot::Protocol, this), asio::detached);
|
||||||
|
@ -78,7 +80,7 @@ Bot::Bot(asio::any_io_executor executor, std::string_view name,
|
||||||
|
|
||||||
asio::awaitable<void> Bot::Protocol() {
|
asio::awaitable<void> Bot::Protocol() {
|
||||||
asio::ip::tcp::resolver resolver{executor};
|
asio::ip::tcp::resolver resolver{executor};
|
||||||
asio::ip::tcp::resolver::query query{"94.45.241.27", "4000"};
|
asio::ip::tcp::resolver::query query{server, "4000"};
|
||||||
auto host = co_await resolver.async_resolve(query, asio::use_awaitable);
|
auto host = co_await resolver.async_resolve(query, asio::use_awaitable);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -276,13 +278,13 @@ asio::awaitable<void> Bot::ChooseMove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc < 3) {
|
if (argc < 4) {
|
||||||
std::cerr << "usage: " << argv[0] << " <name> <pass>" << std::endl;
|
std::cerr << "usage: " << argv[0] << " <name> <pass> <server>" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
asio::io_context context;
|
asio::io_context context;
|
||||||
Bot bot{context.get_executor(), argv[1], argv[2]};
|
Bot bot{context.get_executor(), argv[1], argv[2], argv[3]};
|
||||||
context.run();
|
context.run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue