-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pack.hpp
143 lines (129 loc) · 2.04 KB
/
Pack.hpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef _Pack_HPP_
#define _Pack_HPP_
#include <iostream>
#include <cstring>
#define CMD_LOGIN 101
#define CMD_MESSAGE 102
#define CMD_PRIVATEMESSAGE 103
#define CMD_BROADCAST 104
#define CMD_NAME 105
#define CMD_TEST 106
#define CMD_HEART 107
class Header
{
public:
int LENGTH;
int CMD;
Header() :LENGTH(0), CMD(0) {}
};
class Pack
{
public:
int LENGTH;
int CMD;
Pack() :LENGTH(0), CMD(0) {}
};
class LoginPack : public Pack
{
public:
char userName[32];
char passWord[32];
LoginPack()
{
strcpy(userName, "\0");
strcpy(passWord, "\0");
LENGTH = sizeof(LoginPack);
CMD = CMD_LOGIN;
}
LoginPack(char un[32], char pw[32])
{
strcpy(userName, un);
strcpy(passWord, pw);
LENGTH = sizeof(LoginPack);
CMD = CMD_LOGIN;
}
};
class MessagePack : public Pack
{
public:
char message[1016];
MessagePack()
{
strcpy(message, "\0");
LENGTH = sizeof(MessagePack);
CMD = CMD_MESSAGE;
}
MessagePack(const char* msg)
{
strcpy(message, msg);
LENGTH = sizeof(MessagePack);
CMD = CMD_MESSAGE;
}
};
class PrivateMessagePack : public Pack
{
public:
char targetName[32];
char message[4056];
PrivateMessagePack()
{
strcpy(targetName, "\0");
strcpy(message, "\0");
LENGTH = sizeof(PrivateMessagePack);
CMD = CMD_PRIVATEMESSAGE;
}
};
class BroadcastPack : public Pack
{
public:
char message[1016];
BroadcastPack()
{
strcpy(message, "\0");
LENGTH = sizeof(BroadcastPack);
CMD = CMD_BROADCAST;
}
BroadcastPack(const char* msg)
{
strcpy(message, msg);
LENGTH = sizeof(BroadcastPack);
CMD = CMD_BROADCAST;
}
};
class NamePack : public Pack
{
public:
char name[32];
NamePack()
{
LENGTH = sizeof(NamePack);
CMD = CMD_NAME;
}
};
class TestPack: public Pack
{
public:
char message[504];
TestPack()
{
strcpy(message, "\0");
LENGTH = sizeof(TestPack);
CMD = CMD_TEST;
}
TestPack(const char* msg)
{
strcpy(message, msg);
LENGTH = sizeof(TestPack);
CMD = CMD_TEST;
}
};
class HeartPack : public Pack
{
public:
HeartPack()
{
LENGTH = sizeof(HeartPack);
CMD = CMD_HEART;
}
};
#endif // !_Pack_HPP_