mirror of
https://github.com/etlegacy/etlegacy-tools.git
synced 2024-11-09 22:31:37 +00:00
etlist: allow ip:port address format
This commit is contained in:
parent
471f474107
commit
70cb8932a2
3 changed files with 14 additions and 6 deletions
|
@ -21,14 +21,22 @@
|
|||
#include "connection.h"
|
||||
|
||||
Connection::Connection(boost::asio::io_service& io_service,
|
||||
std::string server_name /*=etlegacy.com*/,
|
||||
int server_port /*=27960*/,
|
||||
std::string server_address /*=etlegacy.com*/,
|
||||
unsigned short server_port /*=27960*/,
|
||||
std::string message /*=getstatus*/,
|
||||
float timeout /*=1.5*/)
|
||||
: io_service_(io_service), socket_(io_service, udp::v4()), timer_(io_service)
|
||||
{
|
||||
// Allow ip:port address format
|
||||
if (server_address.find(":") != std::string::npos)
|
||||
{
|
||||
server_port = boost::lexical_cast<unsigned short>
|
||||
(server_address.substr(server_address.find(":") + 1));
|
||||
server_address = server_address.substr(0, server_address.find(":"));
|
||||
}
|
||||
|
||||
udp::resolver resolver(io_service_);
|
||||
udp::resolver::query query(udp::v4(), server_name,
|
||||
udp::resolver::query query(udp::v4(), server_address,
|
||||
boost::lexical_cast<std::string>(server_port));
|
||||
receiver_endpoint_ = *resolver.resolve(query);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class Connection
|
|||
public:
|
||||
Connection(boost::asio::io_service& io_service,
|
||||
std::string server_name = "etlegacy.com",
|
||||
int server_port = 27960,
|
||||
unsigned short server_port = 27960,
|
||||
std::string message = "getstatus",
|
||||
float timeout = 1.5);
|
||||
void close();
|
||||
|
|
|
@ -43,7 +43,7 @@ int main(int argc, char *argv[])
|
|||
("server,s", boost::program_options::value<std::string>(),
|
||||
"server to query")
|
||||
("port,p",
|
||||
boost::program_options::value<unsigned int>()->default_value(27960),
|
||||
boost::program_options::value<unsigned short>()->default_value(27960),
|
||||
"port on the server")
|
||||
("message,m",
|
||||
boost::program_options::value<std::string>()->default_value("getstatus"),
|
||||
|
@ -74,7 +74,7 @@ int main(int argc, char *argv[])
|
|||
*/
|
||||
boost::asio::io_service io_service;
|
||||
Connection client(io_service, var_map["server"].as<std::string>(),
|
||||
var_map["port"].as<unsigned int>(),
|
||||
var_map["port"].as<unsigned short>(),
|
||||
var_map["message"].as<std::string>(),
|
||||
var_map["timeout"].as<float>());
|
||||
io_service.run();
|
||||
|
|
Loading…
Reference in a new issue