diff options
Diffstat (limited to 'MySpace/NetMessage.h')
-rw-r--r-- | MySpace/NetMessage.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/MySpace/NetMessage.h b/MySpace/NetMessage.h new file mode 100644 index 0000000..8261302 --- /dev/null +++ b/MySpace/NetMessage.h @@ -0,0 +1,58 @@ +#ifndef _NET_MESSAGE_INC
+#define _NET_MESSAGE_INC
+
+#include "collection.h"
+
+class NMString {
+public:
+ NMString();
+ NMString(const NMString &other);
+ NMString(char *t);
+ virtual ~NMString();
+
+ const bool operator<(const NMString &other) const;
+ const bool operator==(const NMString &other) const;
+ NMString &operator=(const NMString &other);
+
+ char *text;
+};
+
+class NetMessage: public Map<NMString, NMString> {
+public:
+ NetMessage();
+ virtual ~NetMessage();
+
+ int parse(char *data, int size);
+
+ bool get_string(char *key, char *buff, int buffsize);
+ bool get_data(char *key, char *buff, int *size);
+ int get_int(char *key);
+
+ static char *unescape_inplace(char *val);
+};
+
+class KeyValue: public Pair<NMString, NMString> {
+public:
+ KeyValue(const NMString &k, const NMString &v): Pair<NMString, NMString>(k, v) {}
+ KeyValue &operator=(const KeyValue &other) {
+ first = other.first;
+ second = other.second;
+ return *this;
+ }
+};
+
+class ClientNetMessage: public LinkedList< KeyValue > {
+public:
+ ClientNetMessage();
+ virtual ~ClientNetMessage();
+
+ int ClientNetMessage::make_packet(char *buff, int size);
+
+ void add_string(char *key, char *buff);
+ void add_data(char *key, char *buff, int size);
+ void add_int(char *key, int i);
+
+ static char *escape(char *val);
+};
+
+#endif
|