From 8f66b5246b9329e932c20d45238810a9f8a74a0e Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 15 May 2007 21:07:46 +0000 Subject: [PATCH] * set host IP on incoming game * Modify class TCPServer to take a boost::asio::ip::tcp::endpoint for member-function listen instead of a port number * Now use command line arguments for addresses to listen on (on each of those addresses we open port 9998 still) * Fix wrongly named include guards (lobby.hpp) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1646 4a71c877-e1ca-e34f-864e-861f7616d084 --- tools/lobbyserver_cpp/src/lobby.cpp | 3 +++ tools/lobbyserver_cpp/src/lobby.hpp | 6 +++--- tools/lobbyserver_cpp/src/main.cpp | 11 ++++++++++- tools/lobbyserver_cpp/src/networking/tcp_server.cpp | 9 +++------ tools/lobbyserver_cpp/src/networking/tcp_server.hpp | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/tools/lobbyserver_cpp/src/lobby.cpp b/tools/lobbyserver_cpp/src/lobby.cpp index 03de16231..d89e68de3 100644 --- a/tools/lobbyserver_cpp/src/lobby.cpp +++ b/tools/lobbyserver_cpp/src/lobby.cpp @@ -220,6 +220,9 @@ void GameLobby::addGame(boost::shared_ptr socket) { boost::asio::read(*socket, boost::asio::buffer(&newGameData, sizeof(GAMESTRUCT))); + strncpy(newGameData.desc.host, socket->remote_endpoint().address().to_string().c_str(), sizeof(newGameData.desc.host)); + newGameData.desc.host[sizeof(newGameData.desc.host) - 1] = 0; + lobbiedGame = newGameData; } catch (boost::asio::error& e) diff --git a/tools/lobbyserver_cpp/src/lobby.hpp b/tools/lobbyserver_cpp/src/lobby.hpp index d343b3cce..37aad04d6 100644 --- a/tools/lobbyserver_cpp/src/lobby.hpp +++ b/tools/lobbyserver_cpp/src/lobby.hpp @@ -21,8 +21,8 @@ $HeadURL$ */ -#ifndef _REQUESTHANDLER_HPP_ -#define _REQUESTHANDLER_HPP_ +#ifndef _LOBBY_HPP_ +#define _LOBBY_HPP_ #include @@ -43,4 +43,4 @@ class GameLobby impl* pimpl; }; -#endif // _REQUESTHANDLER_HPP_ +#endif // _LOBBY_HPP_ diff --git a/tools/lobbyserver_cpp/src/main.cpp b/tools/lobbyserver_cpp/src/main.cpp index de8525a03..cde65d488 100644 --- a/tools/lobbyserver_cpp/src/main.cpp +++ b/tools/lobbyserver_cpp/src/main.cpp @@ -53,7 +53,16 @@ int main(int argc, char* argv[]) boost::shared_ptr io_service(new boost::asio::io_service); TCPServer tcp_server(io_service, handleRequestInThread); - tcp_server.listen(lobbyPort); + for (unsigned int i = 1; i < static_cast(argc); ++i) + { + boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(argv[i]), lobbyPort); + { + boost::recursive_mutex::scoped_lock lock(cout_mutex); + std::cout << "Attempting to listen at: " << endpoint << std::endl; + } + tcp_server.listen(endpoint); + } + io_service->run(); returnValue = 0; } diff --git a/tools/lobbyserver_cpp/src/networking/tcp_server.cpp b/tools/lobbyserver_cpp/src/networking/tcp_server.cpp index ebfb9a31b..40b38dc20 100644 --- a/tools/lobbyserver_cpp/src/networking/tcp_server.cpp +++ b/tools/lobbyserver_cpp/src/networking/tcp_server.cpp @@ -84,11 +84,8 @@ TCPServer::~TCPServer() delete pimpl; } -void TCPServer::listen(unsigned short port) +void TCPServer::listen(const boost::asio::ip::tcp::endpoint& endpoint) { - // Listen on the specified port for incoming connections via IPv4 - pimpl->listen(boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)); - - // Listen on the specified port for incoming connections via IPv6 - pimpl->listen(boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), port)); + // Listen on the specified endpoint + pimpl->listen(endpoint); } diff --git a/tools/lobbyserver_cpp/src/networking/tcp_server.hpp b/tools/lobbyserver_cpp/src/networking/tcp_server.hpp index 10981ba72..cff03d6e1 100644 --- a/tools/lobbyserver_cpp/src/networking/tcp_server.hpp +++ b/tools/lobbyserver_cpp/src/networking/tcp_server.hpp @@ -37,7 +37,7 @@ class TCPServer : boost::noncopyable TCPServer(boost::shared_ptr io_service, const connectionHandler& handler); ~TCPServer(); - void listen(unsigned short port); + void listen(const boost::asio::ip::tcp::endpoint& endpoint); private: class impl;