summaryrefslogtreecommitdiff
path: root/src/net/network.h
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-08-26 17:24:43 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-08-26 17:24:43 +0000
commit07b6070c25faedd78c2e26825bd700dc294f00cf (patch)
tree6a3053ad2a88ee6f0091fafba6607bc82231f7f6 /src/net/network.h
parent00d7badb647b4293c444c0374985b7f1ea8a1ed1 (diff)
downloadmana-client-07b6070c25faedd78c2e26825bd700dc294f00cf.tar.gz
mana-client-07b6070c25faedd78c2e26825bd700dc294f00cf.tar.bz2
mana-client-07b6070c25faedd78c2e26825bd700dc294f00cf.tar.xz
mana-client-07b6070c25faedd78c2e26825bd700dc294f00cf.zip
Made the Network class a purely static interface, as there is only one instance.
Diffstat (limited to 'src/net/network.h')
-rw-r--r--src/net/network.h79
1 files changed, 25 insertions, 54 deletions
diff --git a/src/net/network.h b/src/net/network.h
index 40255e44..861fa2b3 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -42,108 +42,79 @@ class MessageOut;
class Network
{
public:
- friend class MessageOut;
-
/**
- * Constructor. Sets up the local host.
+ * Sets up the local host.
*/
- Network();
+ static void
+ initialize();
/**
- * Destructor.
+ * Closes the connections.
*/
- ~Network();
+ static void
+ finalize();
- typedef enum {
+ enum Server {
ACCOUNT,
GAME,
CHAT
- } Server;
+ };
+
+ enum State {
+ NET_OK,
+ NET_ERROR
+ };
/**
* 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
+ static bool
connect(Server server, const std::string &address, short port);
/**
* Disconnects from the given server.
*/
- void
+ static void
disconnect(Server server);
/**
* Registers a message handler. A message handler handles a certain
* subset of incoming messages.
*/
- void
+ static void
registerHandler(MessageHandler *handler);
/**
* Unregisters a message handler.
*/
- void
+ static void
unregisterHandler(MessageHandler *handler);
- void
+ static void
clearHandlers();
- int
- getState() const { return mState; }
+ static State
+ getState();
/**
* Returns whether the given server is connected.
*/
- bool
- isConnected(Server server) const;
+ static bool
+ isConnected(Server server);
- void
+ static void
flush();
/**
- * Send a message to a given server. The server should be connected.
+ * Sends a message to a given server. The server should be connected.
*/
- void
+ static void
send(Server server, const MessageOut &msg);
-
- enum State {
- NET_OK,
- NET_ERROR
- };
-
- private:
- /**
- * The local host.
- */
- ENetHost *mClient;
-
- /**
- * 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;
-
- int mState;
-
- typedef std::map<unsigned short, MessageHandler*> MessageHandlers;
- typedef MessageHandlers::iterator MessageHandlerIterator;
- MessageHandlers mMessageHandlers;
};
/** Convert an address from int format to string */
char *iptostring(int address);
-// TODO: remove this global, just a temp solution.
-extern Network *network;
-
#endif