etlist: allow ip:port address format

This commit is contained in:
Radegast 2012-10-14 01:21:36 +01:00
parent 471f474107
commit 70cb8932a2
3 changed files with 14 additions and 6 deletions

View file

@ -21,14 +21,22 @@
#include "connection.h" #include "connection.h"
Connection::Connection(boost::asio::io_service& io_service, Connection::Connection(boost::asio::io_service& io_service,
std::string server_name /*=etlegacy.com*/, std::string server_address /*=etlegacy.com*/,
int server_port /*=27960*/, unsigned short server_port /*=27960*/,
std::string message /*=getstatus*/, std::string message /*=getstatus*/,
float timeout /*=1.5*/) float timeout /*=1.5*/)
: io_service_(io_service), socket_(io_service, udp::v4()), timer_(io_service) : 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 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)); boost::lexical_cast<std::string>(server_port));
receiver_endpoint_ = *resolver.resolve(query); receiver_endpoint_ = *resolver.resolve(query);

View file

@ -36,7 +36,7 @@ class Connection
public: public:
Connection(boost::asio::io_service& io_service, Connection(boost::asio::io_service& io_service,
std::string server_name = "etlegacy.com", std::string server_name = "etlegacy.com",
int server_port = 27960, unsigned short server_port = 27960,
std::string message = "getstatus", std::string message = "getstatus",
float timeout = 1.5); float timeout = 1.5);
void close(); void close();

View file

@ -43,7 +43,7 @@ int main(int argc, char *argv[])
("server,s", boost::program_options::value<std::string>(), ("server,s", boost::program_options::value<std::string>(),
"server to query") "server to query")
("port,p", ("port,p",
boost::program_options::value<unsigned int>()->default_value(27960), boost::program_options::value<unsigned short>()->default_value(27960),
"port on the server") "port on the server")
("message,m", ("message,m",
boost::program_options::value<std::string>()->default_value("getstatus"), 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; boost::asio::io_service io_service;
Connection client(io_service, var_map["server"].as<std::string>(), 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["message"].as<std::string>(),
var_map["timeout"].as<float>()); var_map["timeout"].as<float>());
io_service.run(); io_service.run();