forked from quozl/netrek-client-cow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmessage.c
285 lines (261 loc) · 6.42 KB
/
dmessage.c
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* dmessage.c
*
* for the client of a socket based protocol.
*
*/
#include "config.h"
#include "copyright.h"
#include <stdio.h>
#include <math.h>
#include <time.h>
#include INC_SYS_TIME
#include "Wlib.h"
#include "defs.h"
#include "struct.h"
#include "data.h"
#include "version.h"
#include "patchlevel.h"
#include "beeplite.h"
#include "censor.h"
#include "distress.h"
#include "smessage.h"
#include "dmessage.h"
extern char cowid[];
static int version_sent = 0;
static int instr(char *string1, char *string2);
void dmessage(char *message, unsigned char flags, unsigned char from, unsigned char to)
{
register int len;
W_Color color;
char timebuf[10];
time_t curtime;
struct tm *tm;
int take, destroy, team, kill, killp, killa, bomb, conq;
struct distress dist;
take = MTEAM + MTAKE + MVALID;
destroy = MTEAM + MDEST + MVALID;
kill = MALL + MKILL + MVALID;
killp = MALL + MKILLP + MVALID;
killa = MALL + MKILLA + MVALID;
bomb = MTEAM + MBOMB + MVALID;
team = MTEAM + MVALID;
conq = MALL + MCONQ + MVALID;
time(&curtime);
tm = localtime(&curtime);
sprintf(timebuf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
len = strlen(message);
if (from == 255)
{
/* From God */
color = textColor;
}
else
{
color = playerColor(&(players[from]));
}
if (censorMessages)
if ((flags != kill) && (flags != killp) &&
(flags != killa) && (flags != bomb) &&
(flags != take) && (flags != destroy))
censor(message);
/* aha! A new type distress/macro call came in. parse it appropriately */
if (flags == (MTEAM | MDISTR | MVALID))
{
HandleGenDistr(message, from, to, &dist);
len = makedistress(&dist, message, distmacro[dist.distype].macro);
#ifdef BEEPLITE
if (UseLite)
rcdlite(&dist);
#endif
if (len <= 0)
return;
flags ^= MDISTR;
}
if (niftyNewMessages)
{
if (logmess)
{
if (logFile != NULL)
{
fprintf(logFile, "%s: %s\n", timebuf, message);
fflush(logFile);
}
else
{
printf("%s: %s\n", timebuf, message);
}
}
if (!(logmess && logFile == NULL) && flags == conq)
{
/* output conquer stuff to stdout in addition to message window */
fprintf(stdout, "%s\n", message);
if (instr(message, "kill"))
{
fprintf(stdout, "NOTE: The server here does not properly set message flags\n");
fprintf(stdout, "You should probably pester the server god to update....\n");
}
}
if (flags == (MCONFIG + MINDIV + MVALID))
{
return;
}
if ((flags == team) || (flags == take) || (flags == destroy))
{
W_WriteText(messwt, 0, 0, color, message, len, shipFont(me));
if ((flags == team) &&
!strncmp(message + 10, " ", 5) && (message[15] == 0))
{
printf("dmessage:flags==team PIG call from=%d\n", from);
if (!versionHide) pmessage(cowid, from, MINDIV);
}
}
else if ((flags == kill) || (flags == killp) ||
(flags == killa) || (flags == bomb))
{
W_WriteText(messwk, 0, 0, color, message, len, 0);
if (!reportKills)
return; /* HW */
}
else if (flags & MINDIV)
{
W_WriteText(messwi, 0, 0, color, message, len, 0);
if (!strncmp(message + 10, " ", 5) && (message[15] == 0))
{
printf("dmessage:MINDIV PIG call from=%d\n", from);
if (!versionHide) pmessage(cowid, from, MINDIV);
}
}
else
{ /* if we don't know where *
* * the message beLONGs by
* * * this time, stick it
* in * * the all board... */
W_WriteText(messwa, 0, 0, color, message, len, 0);
if (!strncmp(message + 10, " ", 5) && (message[15] == 0))
{
if (!versionHide) pmessage(cowid, from, MINDIV);
}
}
W_WriteText(reviewWin, 0, 0, color, message, len, 0);
}
else
{
/* ok, here we have the old kludge nastiness that we can turn on if we
* * * HAVE to. yuk, blech, ptooie... */
if ((strncmp(message, "GOD->ALL", 8) == 0 &&
(instr(message, "was kill") ||
instr(message, "killed by"))) ||
(*message != ' ' && instr(message, "We are being attacked")))
{
W_WriteText(messwk, 0, 0, color, message, len, 0);
if (!reportKills)
return;
W_WriteText(reviewWin, 0, 0, color, message, len, 0);
if (logmess)
{
if (logFile != NULL)
{
fprintf(logFile, "%s ", timebuf);
fprintf(logFile, "%s\n", message);
fflush(logFile);
}
else
{
printf("%s ", message);
printf("%s\n", timebuf);
}
}
return;
}
switch (flags & (MTEAM | MINDIV | MALL))
{
case MTEAM:
W_WriteText(messwt, 0, 0, color, message, len, 0);
if (!strncmp(message + 10, " ", 5) && (message[15] == 0))
{
if (!versionHide) pmessage(cowid, from, MINDIV);
}
if (logmess)
{
if (logFile != NULL)
{
fprintf(logFile, "%s ", timebuf);
fprintf(logFile, "%s\n", message);
fflush(logFile);
}
else
{
printf("%s ", message);
printf("%s\n", timebuf);
}
}
break;
case MINDIV:
if (!(flags & MCONFIG))
W_WriteText(messwi, 0, 0, color, message, len, 0);
if (!strncmp(message + 10, " ", 5) && (message[15] == 0))
{
if (!versionHide) pmessage(cowid, from, MINDIV);
}
if (logmess)
{
if (logFile != NULL)
{
fprintf(logFile, "%s ", timebuf);
fprintf(logFile, "%s\n", message);
fflush(logFile);
}
else
{
printf("%s ", message);
printf("%s\n", timebuf);
}
}
break;
default:
W_WriteText(messwa, 0, 0, color, message, len, 0);
if (!strncmp(message + 10, " ", 5) && (message[15] == 0))
{
if (!versionHide) pmessage(cowid, from, MINDIV);
}
if (logmess)
{
if (logFile != NULL)
{
fprintf(logFile, "%s ", timebuf);
fprintf(logFile, "%s\n", message);
fflush(logFile);
}
else
{
printf("%s", message);
printf("%s\n", timebuf);
}
}
break;
}
W_WriteText(reviewWin, 0, 0, color, message, len, 0);
}
}
static int instr(char *string1, char *string2)
{
char *s;
int length;
length = strlen(string2);
for (s = string1; *s != 0; s++)
{
if (*s == *string2 && strncmp(s, string2, length) == 0)
return (1);
}
return (0);
}
void sendVersion(void)
{
char client_ver[80];
if (!version_sent)
{
version_sent = 1;
sprintf(client_ver, "@netrek-client-cow %s.%d", mvers, PATCHLEVEL);
pmessage(client_ver, me->p_no, MINDIV | MCONFIG);
}
}