-
Notifications
You must be signed in to change notification settings - Fork 0
/
mxp.cpp
executable file
·245 lines (214 loc) · 5.17 KB
/
mxp.cpp
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "mud.h"
#include "mxp.h"
/*
* Count number of mxp tags need converting
* ie. < becomes <
* > becomes >
* & becomes &
*/
int count_mxp_tags (const int bMXP, const char *txt, int length)
{
char c;
const char * p;
int count;
int bInTag = FALSE;
int bInEntity = FALSE;
for (p = txt, count = 0; length > 0; p++, length--)
{
c = *p;
if (bInTag) /* in a tag, eg. <send> */
{
if (!bMXP)
count--; /* not output if not MXP */
if (c == MXP_ENDc)
bInTag = FALSE;
} /* end of being inside a tag */
else if (bInEntity) /* in a tag, eg. <send> */
{
if (!bMXP)
count--; /* not output if not MXP */
if (c == ';')
bInEntity = FALSE;
} /* end of being inside a tag */
else
{
switch (c)
{
case MXP_BEGc:
bInTag = TRUE;
if (!bMXP)
count--; /* not output if not MXP */
break;
case MXP_ENDc: /* shouldn't get this case */
if (!bMXP)
count--; /* not output if not MXP */
break;
case MXP_AMPc:
bInEntity = TRUE;
if (!bMXP)
count--; /* not output if not MXP */
break;
default:
if (bMXP)
{
switch (c)
{
case '<': /* < becomes < */
case '>': /* > becomes > */
count += 3;
break;
case '&':
count += 4; /* & becomes & */
break;
case '"': /* " becomes " */
count += 5;
break;
} /* end of inner switch */
} /* end of MXP enabled */
} /* end of switch on character */
} /* end of counting special characters */
}
return count;
} /* end of count_mxp_tags */
void convert_mxp_tags (const int bMXP, char * dest, const char *src, int length)
{
char c;
const char * ps;
char * pd;
int bInTag = FALSE;
int bInEntity = FALSE;
for (ps = src, pd = dest; length > 0; ps++, length--)
{
c = *ps;
if (bInTag) /* in a tag, eg. <send> */
{
if (c == MXP_ENDc)
{
bInTag = FALSE;
if (bMXP)
*pd++ = '>';
}
else if (bMXP)
*pd++ = c; /* copy tag only in MXP mode */
} /* end of being inside a tag */
else if (bInEntity) /* in a tag, eg. <send> */
{
if (bMXP)
*pd++ = c; /* copy tag only in MXP mode */
if (c == ';')
bInEntity = FALSE;
} /* end of being inside a tag */
else
{
switch (c)
{
case MXP_BEGc:
bInTag = TRUE;
if (bMXP)
*pd++ = '<';
break;
case MXP_ENDc: /* shouldn't get this case */
if (bMXP)
*pd++ = '>';
break;
case MXP_AMPc:
bInEntity = TRUE;
if (bMXP)
*pd++ = '&';
break;
default:
if (bMXP)
{
switch (c)
{
case '<':
memcpy (pd, "<", 4);
pd += 4;
break;
case '>':
memcpy (pd, ">", 4);
pd += 4;
break;
case '&':
memcpy (pd, "&", 5);
pd += 5;
break;
case '"':
memcpy (pd, """, 6);
pd += 6;
break;
default:
*pd++ = c;
break; /* end of default */
} /* end of inner switch */
}
else
*pd++ = c; /* not MXP - just copy character */
break;
} /* end of switch on character */
}
} /* end of converting special characters */
} /* end of convert_mxp_tags */
/* set up MXP */
//void turn_on_mxp (PlayerConnection *d)
//{
// d->EnableMXP();
/*d->mxp = TRUE; // turn it on now
write_to_buffer( d, (const char*) start_mxp_str, 0 );
write_to_buffer( d, MXPMODE (6), 0 ); // permanent secure mode
write_to_buffer( d, MXPTAG ("!-- Set up MXP elements --"), 0);
// Exit tag
write_to_buffer( d, MXPTAG ("!ELEMENT Ex '<send>' FLAG=RoomExit"), 0);
// Room description tag
write_to_buffer( d, MXPTAG ("!ELEMENT rdesc '<p>' FLAG=RoomDesc"), 0);
// Get an item tag (for things on the ground)
write_to_buffer( d, MXPTAG
("!ELEMENT Get \"<send href='"
"get '&name;'|"
"examine '&name;'|"
"drink '&name;'"
"' "
"hint='RH mouse click to use this object|"
"Get &desc;|"
"Examine &desc;|"
"Drink from &desc;"
"'>\" ATT='name desc'"),
0);
// Drop an item tag (for things in the inventory)
write_to_buffer( d, MXPTAG
("!ELEMENT Drop \"<send href='"
"drop '&name;'|"
"examine '&name;'|"
"look in '&name;'|"
"wear '&name;'|"
"eat '&name;'|"
"drink '&name;'"
"' "
"hint='RH mouse click to use this object|"
"Drop &desc;|"
"Examine &desc;|"
"Look inside &desc;|"
"Wear &desc;|"
"Eat &desc;|"
"Drink &desc;"
"'>\" ATT='name desc'"),
0);
// Bid an item tag (for things in the auction)
write_to_buffer( d, MXPTAG
("!ELEMENT Bid \"<send href='bid '&name;'' "
"hint='Bid for &desc;'>\" "
"ATT='name desc'"),
0);
// List an item tag (for things in a shop)
write_to_buffer( d, MXPTAG
("!ELEMENT List \"<send href='buy '&name;'' "
"hint='Buy &desc;'>\" "
"ATT='name desc'"),
0);
// Player tag (for who lists, tells etc.)
write_to_buffer( d, MXPTAG
("!ELEMENT Player \"<send href='tell '&name;' ' "
"hint='Send a message to &name;' prompt>\" "
"ATT='name'"),
0);*/
//} /* end of turn_on_mxp */