1 | /* |
|
|
2 | * static char *rcsid_sock_info_c = |
|
|
3 | * "$Id: info.C,v 1.4 2006/09/03 00:18:43 root Exp $"; |
|
|
4 | */ |
|
|
5 | |
1 | |
6 | /* |
2 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
8 | |
4 | |
9 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
… | |
… | |
21 | |
17 | |
22 | You should have received a copy of the GNU General Public License |
18 | You should have received a copy of the GNU General Public License |
23 | along with this program; if not, write to the Free Software |
19 | along with this program; if not, write to the Free Software |
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 | |
21 | |
26 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
27 | */ |
23 | */ |
28 | |
24 | |
29 | /** |
25 | /** |
30 | * \file |
26 | * \file |
31 | * Basic client output functions. |
27 | * Basic client output functions. |
… | |
… | |
46 | * Draws a normal message on the client. It is pretty |
42 | * Draws a normal message on the client. It is pretty |
47 | * much the same thing as the draw_info above, but takes a color |
43 | * much the same thing as the draw_info above, but takes a color |
48 | * parameter. the esrv_drawinfo functions should probably be |
44 | * parameter. the esrv_drawinfo functions should probably be |
49 | * replaced with this, just using black as the color. |
45 | * replaced with this, just using black as the color. |
50 | */ |
46 | */ |
|
|
47 | static void |
51 | static void esrv_print_msg(NewSocket *ns,int color, const char *str) |
48 | esrv_print_msg (client_socket * ns, int color, const char *str) |
52 | { |
49 | { |
53 | char buf[HUGE_BUF]; |
50 | packet sl; |
54 | |
51 | |
55 | if (ns->status == Ns_Old) { |
52 | if (ns->status == Ns_Old) |
56 | snprintf(buf,HUGE_BUF,"%s\n", str); |
53 | sl.printf ("%s\n", str); |
57 | } else { |
54 | else |
58 | snprintf(buf,HUGE_BUF, "drawinfo %d %s", color, str); |
55 | sl.printf ("drawinfo %d %s", color, str); |
59 | } |
56 | |
60 | /* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ |
57 | ns->send_packet (sl); |
61 | Write_String_To_Socket(ns, buf, strlen(buf)); |
|
|
62 | } |
58 | } |
63 | |
59 | |
64 | /** |
60 | /** |
65 | * Draws an extended message on the client. |
61 | * Draws an extended message on the client. |
66 | * ns the socket to send message to |
62 | * ns the socket to send message to |
… | |
… | |
68 | * type, |
64 | * type, |
69 | * subtype type and subtype of text message |
65 | * subtype type and subtype of text message |
70 | * intro Intro message to send with main message if client does not support the message type |
66 | * intro Intro message to send with main message if client does not support the message type |
71 | * message The main message |
67 | * message The main message |
72 | */ |
68 | */ |
|
|
69 | static void |
73 | static void esrv_print_ext_msg(NewSocket *ns,int color,uint8 type, uint8 subtype, const char *message) |
70 | esrv_print_ext_msg (client_socket * ns, int color, uint8 type, uint8 subtype, const char *message) |
74 | { |
71 | { |
75 | char buf[HUGE_BUF]; |
72 | packet sl; |
|
|
73 | |
76 | snprintf(buf,HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
74 | sl.printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
77 | Write_String_To_Socket(ns, buf, strlen(buf)); |
75 | ns->send_packet (sl); |
78 | /* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/ |
|
|
79 | |
|
|
80 | } |
76 | } |
81 | |
77 | |
82 | /** |
78 | /** |
83 | * Frontend for esrv_print_msg |
79 | * Frontend for esrv_print_msg |
84 | * \param colr message color |
80 | * \param colr message color |
… | |
… | |
88 | * If pl is NULL or without contr set, writes message to log. |
84 | * If pl is NULL or without contr set, writes message to log. |
89 | * |
85 | * |
90 | * Else sends message to player via esrv_print_msg |
86 | * Else sends message to player via esrv_print_msg |
91 | */ |
87 | */ |
92 | |
88 | |
|
|
89 | static void |
93 | static void print_message(int colr, const object *pl, const char *tmp) { |
90 | print_message (int colr, const object *pl, const char *tmp) |
|
|
91 | { |
94 | |
92 | |
95 | if(tmp == (char *) NULL) { |
93 | if (!tmp) |
96 | tmp="[NULL]"; |
94 | tmp = "[NULL]"; |
97 | } |
|
|
98 | |
95 | |
99 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
96 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
100 | return; |
97 | return; |
101 | |
98 | |
102 | if (pl->type == PLAYER) { |
99 | if (pl->type == PLAYER) |
103 | esrv_print_msg(&pl->contr->socket,colr,(char*) tmp); |
100 | esrv_print_msg (pl->contr->socket, colr, (char *) tmp); |
104 | return; |
|
|
105 | } |
|
|
106 | } |
101 | } |
107 | |
|
|
108 | |
102 | |
109 | /** |
103 | /** |
110 | * Prints out the contents of specified buffer structures, |
104 | * Prints out the contents of specified buffer structures, |
111 | * and clears the string. |
105 | * and clears the string. |
112 | */ |
106 | */ |
113 | |
107 | |
|
|
108 | void |
114 | void flush_output_element(const object *pl, Output_Buf *outputs) |
109 | flush_output_element (const object *pl, Output_Buf * outputs) |
115 | { |
110 | { |
116 | char tbuf[MAX_BUF]; |
111 | char tbuf[MAX_BUF]; |
117 | |
112 | |
118 | if (outputs->buf==NULL) return; |
113 | if (outputs->buf == NULL) |
|
|
114 | return; |
119 | if (outputs->count > 1) { |
115 | if (outputs->count > 1) |
|
|
116 | { |
120 | snprintf(tbuf,MAX_BUF, "%d times %s", outputs->count, &outputs->buf); |
117 | snprintf (tbuf, MAX_BUF, "%d times %s", outputs->count, &outputs->buf); |
121 | print_message(NDI_BLACK, pl, tbuf); |
118 | print_message (NDI_BLACK, pl, tbuf); |
|
|
119 | } |
122 | } else |
120 | else |
123 | print_message(NDI_BLACK, pl, &outputs->buf); |
121 | print_message (NDI_BLACK, pl, &outputs->buf); |
124 | |
122 | |
125 | outputs->buf=NULL; |
123 | outputs->buf = NULL; |
126 | outputs->first_update=0; /* This way, it will be reused */ |
124 | outputs->first_update = 0; /* This way, it will be reused */ |
127 | } |
125 | } |
128 | |
126 | |
129 | /** |
127 | /** |
130 | * Sends message to player through output buffers. |
128 | * Sends message to player through output buffers. |
131 | * \param pl player to send message |
129 | * \param pl player to send message |
… | |
… | |
139 | * |
137 | * |
140 | * If message not already in buffers, flushes olders buffer, |
138 | * If message not already in buffers, flushes olders buffer, |
141 | * and adds message to queue. |
139 | * and adds message to queue. |
142 | */ |
140 | */ |
143 | |
141 | |
|
|
142 | static void |
144 | static void check_output_buffers(const object *pl, const char *buf) |
143 | check_output_buffers (const object *pl, const char *buf) |
145 | { |
144 | { |
146 | int i, oldest=0; |
145 | int i, oldest = 0; |
147 | |
146 | |
148 | if (pl->contr->outputs_count<2) { |
147 | if (pl->contr->outputs_count < 2) |
|
|
148 | { |
149 | print_message(NDI_BLACK, pl, buf); |
149 | print_message (NDI_BLACK, pl, buf); |
150 | return; |
150 | return; |
|
|
151 | } |
|
|
152 | else |
151 | } |
153 | { |
152 | else { |
|
|
153 | for (i=0; i<NUM_OUTPUT_BUFS; i++) { |
154 | for (i = 0; i < NUM_OUTPUT_BUFS; i++) |
154 | if (pl->contr->outputs[i].buf && |
|
|
155 | !strcmp(buf, pl->contr->outputs[i].buf)) break; |
|
|
156 | else if (pl->contr->outputs[i].first_update < |
|
|
157 | pl->contr->outputs[oldest].first_update) |
|
|
158 | oldest=i; |
|
|
159 | } |
155 | { |
|
|
156 | if (pl->contr->outputs[i].buf && !strcmp (buf, pl->contr->outputs[i].buf)) |
|
|
157 | break; |
|
|
158 | else if (pl->contr->outputs[i].first_update < pl->contr->outputs[oldest].first_update) |
|
|
159 | oldest = i; |
|
|
160 | } |
160 | /* We found a match */ |
161 | /* We found a match */ |
161 | if (i<NUM_OUTPUT_BUFS) { |
162 | if (i < NUM_OUTPUT_BUFS) |
|
|
163 | { |
162 | pl->contr->outputs[i].count++; |
164 | pl->contr->outputs[i].count++; |
163 | if (pl->contr->outputs[i].count>=pl->contr->outputs_count) { |
165 | if (pl->contr->outputs[i].count >= pl->contr->outputs_count) |
|
|
166 | { |
164 | flush_output_element(pl, &pl->contr->outputs[i]); |
167 | flush_output_element (pl, &pl->contr->outputs[i]); |
165 | } |
168 | } |
166 | } |
169 | } |
167 | /* No match - flush the oldest, and put the new one in */ |
170 | /* No match - flush the oldest, and put the new one in */ |
168 | else { |
171 | else |
|
|
172 | { |
169 | flush_output_element(pl, &pl->contr->outputs[oldest]); |
173 | flush_output_element (pl, &pl->contr->outputs[oldest]); |
170 | |
174 | |
171 | pl->contr->outputs[oldest].first_update = pticks; |
175 | pl->contr->outputs[oldest].first_update = pticks; |
172 | pl->contr->outputs[oldest].count = 1; |
176 | pl->contr->outputs[oldest].count = 1; |
173 | pl->contr->outputs[oldest].buf = buf; |
177 | pl->contr->outputs[oldest].buf = buf; |
174 | } |
|
|
175 | } |
|
|
176 | } |
|
|
177 | |
178 | } |
|
|
179 | } |
|
|
180 | } |
|
|
181 | |
178 | |
182 | |
179 | |
183 | |
180 | /** |
184 | /** |
181 | * Sends message to player(s). |
185 | * Sends message to player(s). |
182 | * |
186 | * |
… | |
… | |
192 | * |
196 | * |
193 | * If message is black, and not NDI_UNIQUE, gets sent through output buffers. |
197 | * If message is black, and not NDI_UNIQUE, gets sent through output buffers. |
194 | * |
198 | * |
195 | */ |
199 | */ |
196 | |
200 | |
|
|
201 | void |
197 | void new_draw_info(int flags, int pri, const object *pl, const char *buf) |
202 | new_draw_info (int flags, int pri, const object *pl, const char *buf) |
198 | { |
203 | { |
199 | |
204 | |
200 | if (flags & NDI_ALL) { |
205 | if (flags & NDI_ALL) |
|
|
206 | { |
201 | player *tmppl; |
207 | player *tmppl; |
202 | int i; |
|
|
203 | |
208 | |
204 | for (tmppl=first_player; tmppl!=NULL; tmppl=tmppl->next) |
209 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
205 | new_draw_info((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
210 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
206 | |
211 | |
207 | for (i=1; i<socket_info.allocated_sockets; i++) { |
|
|
208 | if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri< 10) { |
|
|
209 | cs_write_string(&init_sockets[i], buf, strlen(buf)); |
|
|
210 | /* Most messages don't have a newline, so add one */ |
|
|
211 | cs_write_string(&init_sockets[i], "\n", 1); |
|
|
212 | } |
|
|
213 | } |
|
|
214 | |
|
|
215 | return; |
212 | return; |
216 | } |
213 | } |
|
|
214 | |
217 | if(!pl || (pl->type==PLAYER && pl->contr==NULL)) { |
215 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
|
|
216 | { |
218 | /* Write to the socket? */ |
217 | /* Write to the socket? */ |
219 | print_message(0, NULL, buf); |
218 | print_message (0, NULL, buf); |
220 | return; |
219 | return; |
221 | } |
220 | } |
|
|
221 | |
222 | if (pl->type!=PLAYER) return; |
222 | if (pl->type != PLAYER) |
|
|
223 | return; |
|
|
224 | |
223 | if (pri>=pl->contr->listening) return; |
225 | if (pri >= pl->contr->listening) |
|
|
226 | return; |
224 | |
227 | |
225 | if ((flags&NDI_COLOR_MASK)==NDI_BLACK && !(flags &NDI_UNIQUE)) { |
228 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
226 | /* following prints stuff out, as appropriate */ |
229 | /* following prints stuff out, as appropriate */ |
227 | check_output_buffers(pl, buf); |
230 | check_output_buffers (pl, buf); |
228 | } |
|
|
229 | else { |
231 | else |
230 | print_message(flags&NDI_COLOR_MASK, pl, buf); |
232 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
231 | } |
|
|
232 | } |
233 | } |
233 | |
234 | |
234 | /** |
235 | /** |
235 | * Wrapper for new_draw_info printf-like. |
236 | * Wrapper for new_draw_info printf-like. |
236 | * |
237 | * |
… | |
… | |
238 | * formatting, so instead of the calling function having to do it, we do |
239 | * formatting, so instead of the calling function having to do it, we do |
239 | * it here. It may also have advantages in the future for reduction of |
240 | * it here. It may also have advantages in the future for reduction of |
240 | * client/server bandwidth (client could keep track of various strings |
241 | * client/server bandwidth (client could keep track of various strings |
241 | */ |
242 | */ |
242 | |
243 | |
|
|
244 | void |
243 | void new_draw_info_format(int flags, int pri, const object *pl, const char *format, ...) |
245 | new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) |
244 | { |
246 | { |
245 | char buf[HUGE_BUF]; |
247 | char buf[HUGE_BUF]; |
246 | |
248 | |
247 | va_list ap; |
249 | va_list ap; |
|
|
250 | |
248 | va_start(ap, format); |
251 | va_start (ap, format); |
249 | |
252 | |
250 | vsnprintf(buf, HUGE_BUF, format, ap); |
253 | vsnprintf (buf, HUGE_BUF, format, ap); |
251 | |
254 | |
252 | va_end(ap); |
255 | va_end (ap); |
253 | |
256 | |
254 | new_draw_info(flags, pri, pl, buf); |
257 | new_draw_info (flags, pri, pl, buf); |
255 | } |
258 | } |
256 | |
259 | |
257 | |
260 | |
258 | void draw_ext_info( |
261 | void |
259 | int flags, int pri, const object *pl, uint8 type, |
262 | draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) |
260 | uint8 subtype, const char* message, const char* oldmessage){ |
263 | { |
261 | |
264 | |
262 | if(!pl || (pl->type!=PLAYER) || (pl->contr==NULL)) |
265 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
263 | return; |
266 | return; |
264 | |
267 | |
265 | if (pri>=pl->contr->listening) return; |
268 | if (pri >= pl->contr->listening) |
|
|
269 | return; |
|
|
270 | |
266 | if (!CLIENT_SUPPORT_READABLES(&pl->contr->socket,type)){ |
271 | if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) |
|
|
272 | { |
267 | char *buf = (char*)malloc(strlen(oldmessage==NULL?message:oldmessage)+1); |
273 | char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); |
|
|
274 | |
268 | if (buf==NULL) |
275 | if (buf == NULL) |
269 | LOG(llevError,"info::draw_ext_info -> Out of memory!"); |
276 | LOG (llevError, "info::draw_ext_info -> Out of memory!"); |
270 | else{ |
277 | else |
|
|
278 | { |
271 | strcpy(buf,oldmessage==NULL?message:oldmessage); |
279 | strcpy (buf, oldmessage == NULL ? message : oldmessage); |
272 | strip_media_tag(buf); |
280 | strip_media_tag (buf); |
273 | new_draw_info(flags, pri, pl, buf); |
281 | new_draw_info (flags, pri, pl, buf); |
274 | free(buf); |
282 | free (buf); |
275 | } |
283 | } |
|
|
284 | } |
276 | }else{ |
285 | else |
277 | esrv_print_ext_msg(&pl->contr->socket,flags&NDI_COLOR_MASK,type,subtype,message); |
286 | esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); |
278 | } |
|
|
279 | } |
287 | } |
280 | |
288 | |
281 | void draw_ext_info_format( |
289 | void |
282 | int flags, int pri, const object *pl, uint8 type, |
290 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
283 | uint8 subtype, const char* old_format, |
291 | { |
284 | char* new_format, ...){ |
292 | |
285 | |
|
|
286 | char buf[HUGE_BUF]; |
293 | char buf[HUGE_BUF]; |
|
|
294 | |
287 | if(!pl || (pl->type!=PLAYER) || (pl->contr==NULL)) |
295 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
288 | return; |
296 | return; |
289 | |
297 | |
290 | if (pri>=pl->contr->listening) return; |
298 | if (pri >= pl->contr->listening) |
|
|
299 | return; |
|
|
300 | |
291 | if (!CLIENT_SUPPORT_READABLES(&pl->contr->socket,type)){ |
301 | if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) |
|
|
302 | { |
292 | va_list ap; |
303 | va_list ap; |
|
|
304 | |
293 | LOG(llevDebug,"Non supported extension text type for client.\n"); |
305 | LOG (llevDebug, "Non supported extension text type for client.\n"); |
294 | va_start(ap, new_format); |
306 | va_start (ap, new_format); |
295 | vsnprintf(buf, HUGE_BUF, old_format, ap); |
307 | vsnprintf (buf, HUGE_BUF, old_format, ap); |
296 | va_end(ap); |
308 | va_end (ap); |
297 | new_draw_info(flags, pri, pl, buf); |
309 | new_draw_info (flags, pri, pl, buf); |
298 | return; |
310 | return; |
299 | }else{ |
311 | } |
|
|
312 | else |
|
|
313 | { |
300 | va_list ap; |
314 | va_list ap; |
|
|
315 | |
301 | va_start(ap, new_format); |
316 | va_start (ap, new_format); |
302 | vsnprintf(buf, HUGE_BUF, new_format, ap); |
317 | vsnprintf (buf, HUGE_BUF, new_format, ap); |
303 | va_end(ap); |
318 | va_end (ap); |
304 | strip_media_tag(buf); |
319 | strip_media_tag (buf); |
305 | esrv_print_ext_msg(&pl->contr->socket,flags&NDI_COLOR_MASK,type,subtype,buf); |
320 | esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); |
306 | } |
321 | } |
307 | } |
322 | } |
|
|
323 | |
308 | /** |
324 | /** |
309 | * Writes to everyone on the map *except* op. This is useful for emotions. |
325 | * Writes to everyone on the map *except* op. This is useful for emotions. |
310 | */ |
326 | */ |
311 | |
327 | |
|
|
328 | void |
312 | void new_info_map_except(int color, mapstruct *map, object *op, const char *str) { |
329 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
|
|
330 | { |
313 | player *pl; |
331 | player *pl; |
314 | |
332 | |
315 | for(pl = first_player; pl != NULL; pl = pl->next) |
333 | for (pl = first_player; pl != NULL; pl = pl->next) |
316 | if(pl->ob != NULL && pl->ob->map == map && pl->ob != op) { |
334 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
|
|
335 | { |
317 | new_draw_info(color, 0, pl->ob, str); |
336 | new_draw_info (color, 0, pl->ob, str); |
318 | } |
337 | } |
319 | } |
338 | } |
320 | |
339 | |
321 | /** |
340 | /** |
322 | * Writes to everyone on the map except op1 and op2 |
341 | * Writes to everyone on the map except op1 and op2 |
323 | */ |
342 | */ |
324 | |
343 | |
|
|
344 | void |
325 | void new_info_map_except2(int color, mapstruct *map, object *op1, object *op2, |
345 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
326 | const char *str) { |
346 | { |
327 | player *pl; |
347 | player *pl; |
328 | |
348 | |
329 | for(pl = first_player; pl != NULL; pl = pl->next) |
349 | for (pl = first_player; pl != NULL; pl = pl->next) |
330 | if(pl->ob != NULL && pl->ob->map == map |
350 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
331 | && pl->ob != op1 && pl->ob != op2) { |
351 | { |
332 | new_draw_info(color, 0, pl->ob, str); |
352 | new_draw_info (color, 0, pl->ob, str); |
333 | } |
353 | } |
334 | } |
354 | } |
335 | |
355 | |
336 | /** |
356 | /** |
337 | * Writes to everyone on the specified map |
357 | * Writes to everyone on the specified map |
338 | */ |
358 | */ |
339 | |
359 | |
|
|
360 | void |
340 | void new_info_map(int color, mapstruct *map, const char *str) { |
361 | new_info_map (int color, maptile * map, const char *str) |
|
|
362 | { |
341 | player *pl; |
363 | player *pl; |
342 | |
364 | |
343 | for(pl = first_player; pl != NULL; pl = pl->next) |
365 | for (pl = first_player; pl != NULL; pl = pl->next) |
344 | if(pl->ob != NULL && pl->ob->map == map) { |
366 | if (pl->ob != NULL && pl->ob->map == map) |
|
|
367 | { |
345 | new_draw_info(color, 0, pl->ob, str); |
368 | new_draw_info (color, 0, pl->ob, str); |
346 | } |
369 | } |
347 | } |
370 | } |
348 | |
371 | |
349 | |
372 | |
350 | /** |
373 | /** |
351 | * This does nothing now. However, in theory, we should probably send |
374 | * This does nothing now. However, in theory, we should probably send |
352 | * something to the client and let the client figure out how it might want |
375 | * something to the client and let the client figure out how it might want |
353 | * to handle this |
376 | * to handle this |
354 | */ |
377 | */ |
|
|
378 | void |
355 | void clear_win_info(object *op) |
379 | clear_win_info (object *op) |
356 | { |
380 | { |
357 | } |
381 | } |
358 | |
382 | |
359 | /** |
383 | /** |
360 | * Get player's current range attack in obuf. |
384 | * Get player's current range attack in obuf. |
361 | */ |
385 | */ |
|
|
386 | void |
362 | void rangetostring(object *pl,char *obuf) |
387 | rangetostring (object *pl, char *obuf) |
363 | { |
388 | { |
364 | switch(pl->contr->shoottype) { |
389 | switch (pl->contr->shoottype) |
|
|
390 | { |
365 | case range_none: |
391 | case range_none: |
366 | strcpy(obuf,"Range: nothing"); |
392 | strcpy (obuf, "Range: nothing"); |
|
|
393 | break; |
|
|
394 | |
|
|
395 | case range_bow: |
|
|
396 | { |
|
|
397 | object *op; |
|
|
398 | |
|
|
399 | for (op = pl->inv; op; op = op->below) |
|
|
400 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
401 | break; |
|
|
402 | |
|
|
403 | if (op == NULL) |
367 | break; |
404 | break; |
368 | |
405 | |
369 | case range_bow: |
406 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
370 | { |
|
|
371 | object *op; |
|
|
372 | |
|
|
373 | for (op = pl->inv; op; op=op->below) |
|
|
374 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
375 | break; |
|
|
376 | if(op==NULL) break; |
|
|
377 | |
|
|
378 | sprintf (obuf, "Range: %s (%s)", query_base_name(op, 0), |
|
|
379 | op->race ? (const char *)op->race : "nothing"); |
|
|
380 | } |
407 | } |
381 | break; |
408 | break; |
382 | |
409 | |
383 | case range_magic: |
410 | case range_magic: |
384 | if (settings.casting_time == TRUE) { |
411 | if (settings.casting_time == TRUE) |
|
|
412 | { |
385 | if (pl->casting_time > -1) { |
413 | if (pl->casting_time > -1) |
|
|
414 | { |
386 | if (pl->casting_time == 0) |
415 | if (pl->casting_time == 0) |
387 | sprintf(obuf,"Range: Holding spell (%s)", |
416 | sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); |
388 | (const char *)pl->spell->name); |
|
|
389 | else |
|
|
390 | sprintf(obuf,"Range: Casting spell (%s)", |
|
|
391 | (const char *)pl->spell->name); |
|
|
392 | } else |
417 | else |
393 | sprintf(obuf,"Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
418 | sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); |
|
|
419 | } |
394 | } else |
420 | else |
395 | sprintf(obuf,"Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
421 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
|
|
422 | } |
|
|
423 | else |
|
|
424 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
396 | break; |
425 | break; |
397 | |
426 | |
398 | case range_misc: |
427 | case range_misc: |
399 | sprintf(obuf,"Range: %s", pl->contr->ranges[range_misc] ? |
428 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
400 | query_base_name(pl->contr->ranges[range_misc],0) : "none"); |
|
|
401 | break; |
429 | break; |
402 | |
430 | |
403 | /* range_scroll is only used for controlling golems. If the |
431 | /* range_scroll is only used for controlling golems. If the |
404 | * the player does not have a golem, reset some things. |
432 | * the player does not have a golem, reset some things. |
405 | */ |
433 | */ |
406 | case range_golem: |
434 | case range_golem: |
407 | if (pl->contr->ranges[range_golem]!=NULL) |
435 | if (pl->contr->ranges[range_golem] != NULL) |
408 | sprintf(obuf,"Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
436 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
409 | else { |
437 | else |
|
|
438 | { |
410 | pl->contr->shoottype = range_none; |
439 | pl->contr->shoottype = range_none; |
411 | strcpy(obuf,"Range: nothing"); |
440 | strcpy (obuf, "Range: nothing"); |
412 | } |
441 | } |
413 | break; |
|
|
414 | |
|
|
415 | case range_skill: |
|
|
416 | sprintf(obuf,"Skill: %s", pl->chosen_skill!=NULL ? |
|
|
417 | (const char *)pl->chosen_skill->name : "none"); |
|
|
418 | break; |
|
|
419 | |
|
|
420 | case range_builder: |
|
|
421 | sprintf( obuf, "Builder: %s", query_base_name( pl->contr->ranges[ range_builder ], 0 ) ); |
|
|
422 | break; |
442 | break; |
423 | |
443 | |
|
|
444 | case range_skill: |
|
|
445 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
|
|
446 | break; |
|
|
447 | |
|
|
448 | case range_builder: |
|
|
449 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
|
|
450 | break; |
|
|
451 | |
424 | default: |
452 | default: |
425 | strcpy(obuf,"Range: illegal"); |
453 | strcpy (obuf, "Range: illegal"); |
426 | } |
454 | } |
427 | } |
455 | } |
428 | |
456 | |
429 | /** |
457 | /** |
430 | * Sets player title. |
458 | * Sets player title. |
431 | */ |
459 | */ |
|
|
460 | void |
432 | void set_title(object *pl, char *buf) |
461 | set_title (object *pl, char *buf) |
433 | { |
462 | { |
434 | /* Eneq(@csd.uu.se): Let players define their own titles. */ |
463 | /* Eneq(@csd.uu.se): Let players define their own titles. */ |
435 | if (pl->contr->own_title[0]=='\0') |
464 | if (pl->contr->own_title[0] == '\0') |
436 | sprintf(buf,"Player: %s the %s",(const char *)pl->name,(const char *)pl->contr->title); |
465 | sprintf (buf, "Player: %s the %s", (const char *) pl->name, (const char *) pl->contr->title); |
437 | else |
466 | else |
438 | sprintf(buf,"Player: %s %s",(const char *)pl->name,(const char *)pl->contr->own_title); |
467 | sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); |
439 | } |
468 | } |
440 | |
469 | |
441 | |
470 | |
442 | /** |
471 | /** |
443 | * Helper for magic map creation. |
472 | * Helper for magic map creation. |
… | |
… | |
448 | * |
477 | * |
449 | * This function examines all the adjacant spaces next to px, py. |
478 | * This function examines all the adjacant spaces next to px, py. |
450 | * It updates the map_mark arrow with the color and high bits set |
479 | * It updates the map_mark arrow with the color and high bits set |
451 | * for various code values. |
480 | * for various code values. |
452 | */ |
481 | */ |
|
|
482 | static void |
453 | static void magic_mapping_mark_recursive(object *pl, char *map_mark, int px, int py) |
483 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
454 | { |
484 | { |
455 | int x, y, dx, dy,mflags; |
485 | int x, y, dx, dy, mflags; |
456 | sint16 nx, ny; |
486 | sint16 nx, ny; |
457 | mapstruct *mp; |
487 | maptile *mp; |
458 | New_Face *f; |
488 | New_Face *f; |
459 | |
489 | |
460 | for (dx = -1; dx <= 1; dx++) { |
490 | for (dx = -1; dx <= 1; dx++) |
|
|
491 | { |
461 | for (dy = -1; dy <= 1; dy++) { |
492 | for (dy = -1; dy <= 1; dy++) |
|
|
493 | { |
462 | x = px + dx; |
494 | x = px + dx; |
463 | y = py + dy; |
495 | y = py + dy; |
464 | |
496 | |
465 | if (FABS(x) >= MAGIC_MAP_HALF || FABS(y) >= MAGIC_MAP_HALF) continue; |
497 | if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) |
|
|
498 | continue; |
466 | |
499 | |
467 | mp = pl->map; |
500 | mp = pl->map; |
468 | nx = pl->x + x; |
501 | nx = pl->x + x; |
469 | ny = pl->y + y; |
502 | ny = pl->y + y; |
470 | |
503 | |
471 | mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
504 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
472 | if (mflags & P_OUT_OF_MAP) continue; |
505 | if (mflags & P_OUT_OF_MAP) |
|
|
506 | continue; |
473 | |
507 | |
474 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] == 0) { |
508 | if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) |
|
|
509 | { |
475 | f= GET_MAP_FACE(mp, nx, ny, 0); |
510 | f = GET_MAP_FACE (mp, nx, ny, 0); |
476 | if (f == blank_face) |
511 | if (f == blank_face) |
477 | f= GET_MAP_FACE(mp, nx, ny, 1); |
512 | f = GET_MAP_FACE (mp, nx, ny, 1); |
478 | if (f == blank_face) |
513 | if (f == blank_face) |
479 | f= GET_MAP_FACE(mp, nx, ny, 2); |
514 | f = GET_MAP_FACE (mp, nx, ny, 2); |
480 | |
515 | |
481 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
516 | /* Should probably have P_NO_MAGIC here also, but then shops don't |
482 | * work. |
517 | * work. |
483 | */ |
518 | */ |
484 | if (mflags & P_BLOCKSVIEW) |
519 | if (mflags & P_BLOCKSVIEW) |
485 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_WALL | (f?f->magicmap:0); |
520 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | (f ? f->magicmap : 0); |
486 | else { |
521 | else |
|
|
522 | { |
487 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f?f->magicmap:0); |
523 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); |
488 | magic_mapping_mark_recursive(pl, map_mark, x, y); |
524 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
489 | } |
525 | } |
490 | } |
526 | } |
491 | } |
527 | } |
492 | } |
528 | } |
493 | } |
529 | } |
… | |
… | |
507 | * to zero before this is called. |
543 | * to zero before this is called. |
508 | * strength is an initial strength*2 rectangular area that we automatically |
544 | * strength is an initial strength*2 rectangular area that we automatically |
509 | * see in/penetrate through. |
545 | * see in/penetrate through. |
510 | */ |
546 | */ |
511 | |
547 | |
|
|
548 | void |
512 | void magic_mapping_mark(object *pl, char *map_mark, int strength) |
549 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
513 | { |
550 | { |
514 | int x, y, mflags; |
551 | int x, y, mflags; |
515 | sint16 nx, ny; |
552 | sint16 nx, ny; |
516 | mapstruct *mp; |
553 | maptile *mp; |
517 | New_Face *f; |
554 | New_Face *f; |
518 | |
555 | |
519 | for (x = -strength; x <strength; x++) { |
556 | for (x = -strength; x < strength; x++) |
|
|
557 | { |
520 | for (y = -strength; y <strength; y++) { |
558 | for (y = -strength; y < strength; y++) |
|
|
559 | { |
521 | mp = pl->map; |
560 | mp = pl->map; |
522 | nx = pl->x + x; |
561 | nx = pl->x + x; |
523 | ny = pl->y + y; |
562 | ny = pl->y + y; |
524 | mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
563 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
525 | if (mflags & P_OUT_OF_MAP) |
564 | if (mflags & P_OUT_OF_MAP) |
526 | continue; |
565 | continue; |
527 | else { |
566 | else |
|
|
567 | { |
528 | f= GET_MAP_FACE(mp, nx, ny, 0); |
568 | f = GET_MAP_FACE (mp, nx, ny, 0); |
529 | if (f == blank_face) |
569 | if (f == blank_face) |
530 | f= GET_MAP_FACE(mp, nx, ny, 1); |
570 | f = GET_MAP_FACE (mp, nx, ny, 1); |
531 | if (f == blank_face) |
571 | if (f == blank_face) |
532 | f= GET_MAP_FACE(mp, nx, ny, 2); |
572 | f = GET_MAP_FACE (mp, nx, ny, 2); |
533 | } |
573 | } |
534 | |
574 | |
535 | if (mflags & P_BLOCKSVIEW) |
575 | if (mflags & P_BLOCKSVIEW) |
536 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_WALL | (f?f->magicmap:0); |
576 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | (f ? f->magicmap : 0); |
537 | else { |
577 | else |
|
|
578 | { |
538 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE* (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f?f->magicmap:0); |
579 | map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); |
539 | magic_mapping_mark_recursive(pl, map_mark, x, y); |
580 | magic_mapping_mark_recursive (pl, map_mark, x, y); |
540 | } |
581 | } |
541 | } |
582 | } |
542 | } |
583 | } |
543 | } |
584 | } |
544 | |
585 | |
… | |
… | |
550 | * but there is no real easy solution. |
591 | * but there is no real easy solution. |
551 | * |
592 | * |
552 | * Mark Wedel |
593 | * Mark Wedel |
553 | */ |
594 | */ |
554 | |
595 | |
|
|
596 | void |
555 | void draw_magic_map(object *pl) |
597 | draw_magic_map (object *pl) |
556 | { |
598 | { |
557 | int x,y; |
|
|
558 | char *map_mark = (char *) calloc(MAGIC_MAP_SIZE*MAGIC_MAP_SIZE, 1); |
599 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
559 | int xmin, xmax, ymin, ymax; |
600 | int xmin, xmax, ymin, ymax; |
560 | SockList sl; |
|
|
561 | |
601 | |
562 | if (pl->type!=PLAYER) { |
602 | if (pl->type != PLAYER) |
|
|
603 | { |
563 | LOG(llevError,"Non player object called draw_map.\n"); |
604 | LOG (llevError, "Non player object called draw_map.\n"); |
564 | return; |
605 | return; |
565 | } |
|
|
566 | |
606 | } |
|
|
607 | |
567 | /* First, we figure out what spaces are 'reachable' by the player */ |
608 | /* First, we figure out what spaces are 'reachable' by the player */ |
568 | magic_mapping_mark(pl, map_mark, 3); |
609 | magic_mapping_mark (pl, map_mark, 3); |
569 | |
610 | |
570 | /* We now go through and figure out what spaces have been |
611 | /* We now go through and figure out what spaces have been |
571 | * marked, and thus figure out rectangular region we send |
612 | * marked, and thus figure out rectangular region we send |
572 | * to the client (eg, if only a 10x10 area is visible, we only |
613 | * to the client (eg, if only a 10x10 area is visible, we only |
573 | * want to send those 100 spaces.) |
614 | * want to send those 100 spaces.) |
574 | */ |
615 | */ |
575 | xmin = MAGIC_MAP_SIZE; |
616 | xmin = MAGIC_MAP_SIZE; |
576 | ymin = MAGIC_MAP_SIZE; |
617 | ymin = MAGIC_MAP_SIZE; |
577 | xmax = 0; |
618 | xmax = 0; |
578 | ymax = 0; |
619 | ymax = 0; |
|
|
620 | |
579 | for(x = 0; x < MAGIC_MAP_SIZE ; x++) { |
621 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
580 | for(y = 0; y < MAGIC_MAP_SIZE; y++) { |
622 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
581 | if (map_mark[x + MAP_WIDTH(pl->map) * y] | FACE_FLOOR) { |
623 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
|
|
624 | { |
582 | xmin = x < xmin ? x : xmin; |
625 | xmin = x < xmin ? x : xmin; |
583 | xmax = x > xmax ? x : xmax; |
626 | xmax = x > xmax ? x : xmax; |
584 | ymin = y < ymin ? y : ymin; |
627 | ymin = y < ymin ? y : ymin; |
585 | ymax = y > ymax ? y : ymax; |
628 | ymax = y > ymax ? y : ymax; |
586 | } |
629 | } |
587 | } |
|
|
588 | } |
|
|
589 | |
630 | |
590 | sl.buf= (unsigned char*) malloc(MAXSOCKBUF); |
631 | packet sl; |
591 | snprintf((char*)sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax-xmin+1), (ymax-ymin+1), |
632 | sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
592 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
633 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
593 | sl.len=strlen((char*)sl.buf); |
634 | |
594 | |
|
|
595 | for (y = ymin; y <= ymax; y++) { |
635 | for (int y = ymin; y <= ymax; y++) |
596 | for (x = xmin; x <= xmax; x++) { |
636 | for (int x = xmin; x <= xmax; x++) |
597 | sl.buf[sl.len++]= map_mark[x+MAGIC_MAP_SIZE*y] & ~FACE_FLOOR; |
637 | sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); |
598 | } /* x loop */ |
638 | |
599 | } /* y loop */ |
|
|
600 | |
|
|
601 | Send_With_Handling(&pl->contr->socket, &sl); |
639 | Send_With_Handling (pl->contr->socket, &sl); |
602 | free(sl.buf); |
640 | |
603 | free(map_mark); |
641 | free (map_mark); |
604 | } |
642 | } |
605 | |
643 | |
606 | |
644 | |
607 | /** |
645 | /** |
608 | * Send a kill log record to sockets |
646 | * Send a kill log record to sockets |
609 | */ |
647 | */ |
610 | |
648 | |
611 | void Log_Kill(const char *Who, |
649 | void |
612 | const char *What, int WhatType, |
650 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
613 | const char *With, int WithType) |
|
|
614 | { |
651 | { |
615 | int i; |
|
|
616 | size_t len; |
652 | size_t len; |
617 | char buf[MAX_BUF]; |
653 | char buf[MAX_BUF]; |
618 | |
654 | |
619 | if (With!=NULL) { |
655 | if (With != NULL) |
620 | snprintf(buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n",Who,What,WhatType,With,WithType); |
656 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
621 | } |
|
|
622 | else { |
657 | else |
623 | snprintf(buf,MAX_BUF, "%s\t%s\t%d\n",Who,What,WhatType); |
658 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
624 | } |
659 | |
625 | len=strlen(buf); |
660 | len = strlen (buf); |
626 | for(i=1; i<socket_info.allocated_sockets; i++) { |
|
|
627 | if (init_sockets[i].old_mode == Old_Listen) { |
|
|
628 | cs_write_string(&init_sockets[i], buf, len); |
|
|
629 | } |
|
|
630 | } |
|
|
631 | } |
661 | } |