ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/info.C
(Generate patch)

Comparing deliantra/server/socket/info.C (file contents):
Revision 1.3 by root, Thu Aug 31 17:54:15 2006 UTC vs.
Revision 1.5 by root, Sun Sep 10 13:43:33 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines