summaryrefslogtreecommitdiff
path: root/MySpace/NetMessage.h
blob: 826130267d60d1d6fb5177f85e28eb0d0cfa34cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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