summaryrefslogtreecommitdiff
path: root/src/connectionhandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/connectionhandler.h')
-rw-r--r--src/connectionhandler.h28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
index dd6cf207..d56fc09d 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -26,6 +26,7 @@
#include <list>
#include <map>
+#include <enet/enet.h>
#include "being.h"
@@ -35,9 +36,6 @@ class MessageHandler;
class MessageOut;
class NetComputer;
-// Forward declaration
-class ListenThreadData;
-
/**
* Data related to a connected client. This includes the buffer for incoming
* messages and the related socket.
@@ -61,19 +59,22 @@ class ClientData
class ConnectionHandler
{
public:
- typedef std::list<NetComputer*> NetComputers;
/**
- * Constructor.
+ * Open the server socket.
*/
- ConnectionHandler();
+ bool startListen(enet_uint16 port);
/**
- * Starts listening to the server socket. It accepts new connections
- * and receives data from connected clients. All computers are
- * disconnected when listening stops.
+ * Disconnect all the clients and close the server socket.
*/
- void startListen(ListenThreadData *ltd);
+ void stopListen();
+
+ /**
+ * Process outgoing messages and listen to the server socket for
+ * incoming messages and new connections.
+ */
+ void process();
/**
* Called when a computer connects to a network session.
@@ -146,8 +147,13 @@ class ConnectionHandler
const char eventId);
private:
- std::map<unsigned int, MessageHandler*> handlers;
+ ENetAddress address; /**< Includes the port to listen to. */
+ ENetHost *host; /**< The host that listen for connections. */
+
+ typedef std::map< unsigned int, MessageHandler * > HandlerMap;
+ HandlerMap handlers;
+ typedef std::list<NetComputer*> NetComputers;
NetComputers clients;
};