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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines