summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account-server/accounthandler.cpp5
-rw-r--r--src/account-server/accounthandler.hpp2
-rw-r--r--src/account-server/main-account.cpp7
-rw-r--r--src/account-server/serverhandler.cpp4
-rw-r--r--src/account-server/serverhandler.hpp2
-rw-r--r--src/chat-server/chathandler.cpp4
-rw-r--r--src/chat-server/chathandler.hpp3
-rw-r--r--src/net/connectionhandler.cpp8
-rw-r--r--src/net/connectionhandler.hpp6
9 files changed, 25 insertions, 16 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index e785d809..d04671e2 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -90,11 +90,12 @@ AccountHandler::AccountHandler():
{
}
-bool AccountClientHandler::initialize(int port)
+bool AccountClientHandler::initialize(int port, const std::string &host)
{
accountHandler = new AccountHandler;
LOG_INFO("Account handler started:");
- return accountHandler->startListen(port);
+
+ return accountHandler->startListen(port, host);
}
void AccountClientHandler::deinitialize()
diff --git a/src/account-server/accounthandler.hpp b/src/account-server/accounthandler.hpp
index e509cb06..c5793b54 100644
--- a/src/account-server/accounthandler.hpp
+++ b/src/account-server/accounthandler.hpp
@@ -29,7 +29,7 @@ namespace AccountClientHandler
/**
* Creates a connection handler and starts listening on given port.
*/
- bool initialize(int port);
+ bool initialize(int port, const std::string &host);
/**
* Stops listening to messages and destroys the connection handler.
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index 7fec91b2..b207ae0e 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -315,9 +315,10 @@ int main(int argc, char *argv[])
initialize();
int port = Configuration::getValue("net_accountServerPort", DEFAULT_SERVER_PORT);
- if (!AccountClientHandler::initialize(port) ||
- !GameServerHandler::initialize(port + 1) ||
- !chatHandler->startListen(port + 2))
+ std::string host = Configuration::getValue("net_listenHost", std::string());
+ if (!AccountClientHandler::initialize(port, host) ||
+ !GameServerHandler::initialize(port + 1, host) ||
+ !chatHandler->startListen(port + 2, host))
{
LOG_FATAL("Unable to create an ENet server host.");
return 3;
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp
index 6def952f..5bfa6a57 100644
--- a/src/account-server/serverhandler.cpp
+++ b/src/account-server/serverhandler.cpp
@@ -90,11 +90,11 @@ class ServerHandler: public ConnectionHandler
static ServerHandler *serverHandler;
-bool GameServerHandler::initialize(int port)
+bool GameServerHandler::initialize(int port, const std::string &host)
{
serverHandler = new ServerHandler;
LOG_INFO("Game server handler started:");
- return serverHandler->startListen(port);
+ return serverHandler->startListen(port, host);
}
void GameServerHandler::deinitialize()
diff --git a/src/account-server/serverhandler.hpp b/src/account-server/serverhandler.hpp
index f89c6ddc..dab3cf2e 100644
--- a/src/account-server/serverhandler.hpp
+++ b/src/account-server/serverhandler.hpp
@@ -34,7 +34,7 @@ namespace GameServerHandler
/**
* Creates a connection handler and starts listening on given port.
*/
- bool initialize(int port);
+ bool initialize(int port, const std::string &host);
/**
* Stops listening to messages and destroys the connection handler.
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index 147107ae..5013a075 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -55,10 +55,10 @@ ChatHandler::ChatHandler():
{
}
-bool ChatHandler::startListen(enet_uint16 port)
+bool ChatHandler::startListen(enet_uint16 port, const std::string &host)
{
LOG_INFO("Chat handler started:");
- return ConnectionHandler::startListen(port);
+ return ConnectionHandler::startListen(port, host);
}
void ChatHandler::deletePendingClient(ChatClient *c)
diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp
index 1de44fc9..e23a7eba 100644
--- a/src/chat-server/chathandler.hpp
+++ b/src/chat-server/chathandler.hpp
@@ -64,13 +64,12 @@ class ChatHandler : public ConnectionHandler
std::vector<PartyInvite> mPartyInvitedUsers;
public:
-
ChatHandler();
/**
* Start the handler.
*/
- bool startListen(enet_uint16 port);
+ bool startListen(enet_uint16 port, const std::string &host);
/**
* Tell a list of users about an event in a chatchannel.
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp
index 123dc0b7..22fadc4c 100644
--- a/src/net/connectionhandler.cpp
+++ b/src/net/connectionhandler.cpp
@@ -30,12 +30,16 @@
#include "net/netcomputer.hpp"
#include "utils/logger.h"
-bool ConnectionHandler::startListen(enet_uint16 port)
+bool ConnectionHandler::startListen(enet_uint16 port,
+ const std::string &listenHost)
{
// Bind the server to the default localhost.
address.host = ENET_HOST_ANY;
address.port = port;
+ if (!listenHost.empty())
+ enet_address_set_host(&address, listenHost.c_str());
+
LOG_INFO("Listening on port " << port << "...");
host = enet_host_create(
&address /* the address to bind the server host to */,
@@ -43,7 +47,7 @@ bool ConnectionHandler::startListen(enet_uint16 port)
0 /* assume any amount of incoming bandwidth */,
0 /* assume any amount of outgoing bandwidth */);
- return host;
+ return host != 0;
}
void ConnectionHandler::stopListen()
diff --git a/src/net/connectionhandler.hpp b/src/net/connectionhandler.hpp
index d22224a7..8c8ecf40 100644
--- a/src/net/connectionhandler.hpp
+++ b/src/net/connectionhandler.hpp
@@ -23,6 +23,7 @@
#define _TMWSERV_CONNECTIONHANDLER_H_
#include <list>
+#include <string>
#include <enet/enet.h>
class MessageIn;
@@ -41,8 +42,11 @@ class ConnectionHandler
/**
* Open the server socket.
+ * @param port the port to listen to
+ * @host the host IP to listen on, defaults to the default localhost
*/
- bool startListen(enet_uint16 port);
+ bool startListen(enet_uint16 port,
+ const std::string &host = std::string());
/**
* Disconnect all the clients and close the server socket.