summaryrefslogtreecommitdiff
path: root/src/net/network.h
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-20 11:56:23 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-20 11:56:23 +0000
commitae45030b2ebd5b07f8cfd234696fd024e6de9e66 (patch)
tree465affc2bd7df675edb428d7f003e5dbbba84c0e /src/net/network.h
parent01591924a4f33d5a5e4a86db6c256c8ce797a820 (diff)
downloadmana-client-ae45030b2ebd5b07f8cfd234696fd024e6de9e66.tar.gz
mana-client-ae45030b2ebd5b07f8cfd234696fd024e6de9e66.tar.bz2
mana-client-ae45030b2ebd5b07f8cfd234696fd024e6de9e66.tar.xz
mana-client-ae45030b2ebd5b07f8cfd234696fd024e6de9e66.zip
Added documentation and did a bit of cleanup.
Diffstat (limited to 'src/net/network.h')
-rw-r--r--src/net/network.h55
1 files changed, 47 insertions, 8 deletions
diff --git a/src/net/network.h b/src/net/network.h
index 49583b9d..40255e44 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -25,7 +25,6 @@
#define _TMW_NETWORK_
#include <map>
-#include <queue>
#include <string>
#include <guichan.hpp>
@@ -33,15 +32,26 @@
#include <enet/enet.h>
class MessageHandler;
-class MessageIn;
class MessageOut;
+/**
+ * The client network layer. Facilitates connecting and communicating to the
+ * account, game and chat servers. Also routes incoming message to the
+ * appropriate message handlers.
+ */
class Network
{
public:
friend class MessageOut;
+ /**
+ * Constructor. Sets up the local host.
+ */
Network();
+
+ /**
+ * Destructor.
+ */
~Network();
typedef enum {
@@ -50,15 +60,30 @@ class Network
CHAT
} Server;
+ /**
+ * Connects to the given server with the specified address and port.
+ * This method is non-blocking, use isConnected to check whether the
+ * server is connected.
+ */
bool
connect(Server server, const std::string &address, short port);
+ /**
+ * Disconnects from the given server.
+ */
void
disconnect(Server server);
+ /**
+ * Registers a message handler. A message handler handles a certain
+ * subset of incoming messages.
+ */
void
registerHandler(MessageHandler *handler);
+ /**
+ * Unregisters a message handler.
+ */
void
unregisterHandler(MessageHandler *handler);
@@ -68,15 +93,18 @@ class Network
int
getState() const { return mState; }
+ /**
+ * Returns whether the given server is connected.
+ */
bool
isConnected(Server server) const;
void
- dispatchMessage(ENetPacket *packet);
-
- void
flush();
+ /**
+ * Send a message to a given server. The server should be connected.
+ */
void
send(Server server, const MessageOut &msg);
@@ -86,11 +114,22 @@ class Network
};
private:
+ /**
+ * The local host.
+ */
ENetHost *mClient;
- ENetPeer *mAccountServer;
- ENetPeer *mGameServer;
- ENetPeer *mChatServer;
+ /**
+ * An array holding the peers of the account, game and chat servers.
+ */
+ ENetPeer *mServers[3];
+
+ /**
+ * Dispatches a message to the appropriate message handler and
+ * destroys it afterwards.
+ */
+ void
+ dispatchMessage(ENetPacket *packet);
unsigned int mToSkip;