summaryrefslogtreecommitdiff
path: root/src/net/network.h
diff options
context:
space:
mode:
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