summaryrefslogtreecommitdiff
path: root/src/net/network.h
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-24 13:05:27 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-24 13:05:27 +0000
commitb5a95c2e1151ce61a2615cffcbb6821c150f40fd (patch)
treedaca526b12ba0d9f761af3d65d033719ea50c8d3 /src/net/network.h
parentd5e8513e085b6fc8da2ea4bb7151ac8e98be74c8 (diff)
downloadmana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.tar.gz
mana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.tar.bz2
mana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.tar.xz
mana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.zip
Make sure that when a network error occurs, the error message is available and
shown to the user. Also, only enable Register button when all necessary fields are filled in.
Diffstat (limited to 'src/net/network.h')
-rw-r--r--src/net/network.h67
1 files changed, 49 insertions, 18 deletions
diff --git a/src/net/network.h b/src/net/network.h
index 13929ec1..d6fec761 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -41,29 +41,52 @@ class Network
friend class MessageOut;
Network();
+
~Network();
- bool connect(const std::string &address, short port);
- void disconnect();
+ bool
+ connect(const std::string &address, short port);
+
+ void
+ disconnect();
+
+ void
+ registerHandler(MessageHandler *handler);
+
+ void
+ unregisterHandler(MessageHandler *handler);
+
+ void
+ clearHandlers();
+
+ int
+ getState() const { return mState; }
- void registerHandler(MessageHandler *handler);
- void unregisterHandler(MessageHandler *handler);
- void clearHandlers();
+ const std::string&
+ getError() const { return mError; }
- int getState() const { return mState; }
- bool isConnected() const { return mState == CONNECTED; }
+ bool
+ isConnected() const { return mState == CONNECTED; }
- int getInSize() const { return mInSize; }
+ int
+ getInSize() const { return mInSize; }
- void skip(int len);
+ void
+ skip(int len);
- bool messageReady();
- MessageIn getNextMessage();
+ bool
+ messageReady();
- void dispatchMessages();
- void flush();
+ MessageIn
+ getNextMessage();
- // ERROR replaced by NET_ERROR because already defined in Windows
+ void
+ dispatchMessages();
+
+ void
+ flush();
+
+ // ERROR replaced by NET_ERROR because already defined in Windows
enum {
IDLE,
CONNECTED,
@@ -73,7 +96,17 @@ class Network
};
protected:
- Uint16 readWord(int pos);
+ void
+ setError(const std::string& error);
+
+ Uint16
+ readWord(int pos);
+
+ bool
+ realConnect();
+
+ void
+ receive();
TCPsocket mSocket;
@@ -86,6 +119,7 @@ class Network
unsigned int mToSkip;
int mState;
+ std::string mError;
SDL_Thread *mWorkerThread;
SDL_mutex *mMutex;
@@ -93,9 +127,6 @@ class Network
typedef std::map<Uint16, MessageHandler*> MessageHandlers;
typedef MessageHandlers::iterator MessageHandlerIterator;
MessageHandlers mMessageHandlers;
-
- bool realConnect();
- void receive();
};
/** Convert an address from int format to string */