-
Notifications
You must be signed in to change notification settings - Fork 2
/
dmessage.c
247 lines (226 loc) · 6 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
/*
* dmessage.c
*
* for the client of a socket based protocol.
*/
#include "copyright.h"
#include <stdio.h>
#include <string.h>
#ifndef SVR4
#include <strings.h>
#endif
#include <math.h>
#include "netrek.h"
extern struct dmacro_list *distmacro;
void
dmessage(message, flags, from, to)
char *message;
unsigned char flags, from, to;
{
register int len;
W_Color color;
W_Window targwin;
int review = 1;
if (!me) {
/* not yet in game */
return;
}
len = strlen(message);
if (from == 255) {
/* From God */
color = textColor;
} else {
color = playerColor(&(players[from]));
}
if (new_messages) {
int take, destroy, team, kill, killp, killa, bomb, conq;
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;
#ifdef FEATURE
if (flags == (MCONFIG + MINDIV + MVALID) && from == 255) {
CheckFeatures(message);
#ifdef LOGMESG
if (logMess)
LogMessage(message);
#endif
return;
}
/* aha! A new type distress/macro call came in. parse it appropriately */
if (flags == (MTEAM | MDISTR | MVALID)) {
struct distress dist;
HandleGenDistr(message, from, to, &dist);
len = makedistress(&dist, message, distmacro[dist.distype].macro);
if (len <= 0)
return;
flags ^= MDISTR;
}
#endif
if (flags == conq)
fprintf(stdout, "%s\n", message);
if ((flags == team) || (flags == take) || (flags == destroy)) {
if(!reportTeamInReview)
review = 0;
targwin = messwt;
W_WriteText(messwt, 0, 0, color, message, len, W_MesgFont);
} else if ((flags == kill) || (flags == killp) || (flags == killa) ||
(flags == bomb)) {
if (reportKills)
W_WriteText(messwk, 0, 0, color, message, len, W_MesgFont);
else {
#ifdef LOGMESG
if (logMess)
LogMessage(message);
#endif
return;
}
/* don't send 'kill' style messages to review (total messages)
window if not requested */
if(!reportKillsInReview)
review = 0;
targwin = messwk;
} else if (flags & MINDIV) {
if(!reportIndInReview)
review = 0;
W_WriteText(messwi, 0, 0, color, message, len, W_MesgFont);
targwin = messwi;
} else { /* if we don't know where the message belongs
* by this time, stick it in the all board... */
if(!reportAllInReview)
review = 0;
targwin = messwa;
W_WriteText(messwa, 0, 0, color, message, len, W_MesgFont);
}
if(review)
W_WriteText(reviewWin, 0, 0, color, message, len, W_MesgFont);
#ifdef TTS
if (tts && from < MAXPLAYER && players[from].p_team == me->p_team &&
from != me->p_no && ((flags == team) || (flags & MINDIV))) {
char *s = message, *t = lastIn;
if (len > tts_max_len)
tts_len = tts_max_len;
else
tts_len = len;
/* RCD hack (need to add rcd) */
if (*s == ' ') {
*t++ = s[1];
*t++ = s[2];
*t++ = ':';
s += 9;
tts_len -= 6;
}
strncpy(t, s, tts_len);
t[tts_len - 1] = 0;
tts_width = W_TTSTextWidth(lastIn, tts_len);
tts_timer = tts_time;
}
#endif
} else {
/* Kludge stuff for report kills... */
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, W_MesgFont);
if (!reportKills)
return;
if(reportKillsInReview)
W_WriteText(reviewWin, 0, 0, color, message, len, W_MesgFont);
return;
}
#if defined(PIG_RESPONSE) || defined(FOR_MORONS)
/* PIG CALL! */
if (instr(message, " ")) {
#ifdef FOR_MORONS
extern int For_Morons;
if (For_Morons) {
pmessage("I'm a Moron!!", 0, MALL);
}
#else
pmessage(PIG_RESPONSE, from, MINDIV);
#endif /* FOR_MORONS */
}
#endif /* PIG_RESPONSE | FOR_MORONS */
if (flags & MTEAM) {
W_WriteText(messwt, 0, 0, color, message, len, W_MesgFont);
if(!reportTeamInReview)
review = 0;
targwin = messwt;
} else if ((flags & MINDIV)
#ifdef nodef
|| (flags & MGOD)
#endif
) {
W_WriteText(messwi, 0, 0, color, message, len, W_MesgFont);
if(!reportIndInReview)
review = 0;
targwin = messwi;
} else {
if(!reportAllInReview)
review = 0;
W_WriteText(messwa, 0, 0, color, message, len, W_MesgFont);
targwin = messwa;
}
if(review)
W_WriteText(reviewWin, 0, 0, color, message, len, W_MesgFont);
#ifdef TTS
if (tts && from < MAXPLAYER && players[from].p_team == me->p_team &&
from != me->p_no && ((flags & MTEAM) || (flags & MINDIV))) {
char *s = message, *t = lastIn;
if (len > tts_max_len)
tts_len = tts_max_len;
else
tts_len = len;
/* RCD hack (need to add rcd) */
if (*s == ' ') {
*t++ = s[1];
*t++ = s[2];
*t++ = ':';
s += 9;
tts_len -= 6;
}
strncpy(t, s, tts_len);
t[tts_len - 1] = 0;
tts_width = W_TTSTextWidth(lastIn, tts_len);
tts_timer = tts_time;
}
#endif
}
#ifdef EM
/*
* send warnings to warning or message window, if player doesn't have
* messages mapped
*/
if ((use_msgw && (targwin == messwi || targwin == messwt)) ||
(!W_IsMapped(targwin) && !W_IsMapped(reviewWin))) {
if (!messpend && messagew) { /* don't collide with messages being
* written! */
W_ClearWindow(messagew);
W_WriteText(messagew, 5, 5, color, message, len, W_RegularFont);
} else
warning(message);
}
#endif
#ifdef LOGMESG
if (logMess)
LogMessage(message);
#endif
}
int
instr(string1, string2)
char *string1, *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);
}