* 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
master
Giel van Schijndel 2007-05-15 21:07:46 +00:00
parent d85d317842
commit 8f66b5246b
5 changed files with 20 additions and 11 deletions

View File

@ -220,6 +220,9 @@ void GameLobby::addGame(boost::shared_ptr<boost::asio::ip::tcp::socket> 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)

View File

@ -21,8 +21,8 @@
$HeadURL$
*/
#ifndef _REQUESTHANDLER_HPP_
#define _REQUESTHANDLER_HPP_
#ifndef _LOBBY_HPP_
#define _LOBBY_HPP_
#include <boost/asio.hpp>
@ -43,4 +43,4 @@ class GameLobby
impl* pimpl;
};
#endif // _REQUESTHANDLER_HPP_
#endif // _LOBBY_HPP_

View File

@ -53,7 +53,16 @@ int main(int argc, char* argv[])
boost::shared_ptr<boost::asio::io_service> 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<unsigned int>(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;
}

View File

@ -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);
}

View File

@ -37,7 +37,7 @@ class TCPServer : boost::noncopyable
TCPServer(boost::shared_ptr<boost::asio::io_service> io_service, const connectionHandler& handler);
~TCPServer();
void listen(unsigned short port);
void listen(const boost::asio::ip::tcp::endpoint& endpoint);
private:
class impl;