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.22 by root, Thu Dec 21 06:12:37 2006 UTC vs.
Revision 1.32 by root, Fri Jan 19 17:50:11 2007 UTC

1
2/* 1/*
3 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
4 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
83 83
84 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 84 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
85 return; 85 return;
86 86
87 if (pl->type == PLAYER) 87 if (pl->type == PLAYER)
88 esrv_print_msg (pl->contr->socket, colr, (char *) tmp); 88 esrv_print_msg (pl->contr->ns, colr, (char *) tmp);
89} 89}
90 90
91/** 91/**
92 * Prints out the contents of specified buffer structures, 92 * Prints out the contents of specified buffer structures,
93 * and clears the string. 93 * and clears the string.
185void 185void
186new_draw_info (int flags, int pri, const object *pl, const char *buf) 186new_draw_info (int flags, int pri, const object *pl, const char *buf)
187{ 187{
188 if (flags & NDI_ALL) 188 if (flags & NDI_ALL)
189 { 189 {
190 player *tmppl; 190 for_all_players (pl)
191
192 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next)
193 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); 191 new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf);
194 192
195 return; 193 return;
196 } 194 }
197 195
198 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 196 if (!pl || pl->type != PLAYER || !pl->contr || !pl->contr->ns)
199 {
200 /* Write to the socket? */
201 print_message (0, NULL, buf);
202 return;
203 }
204
205 if (pl->type != PLAYER)
206 return; 197 return;
207 198
208 if (pri >= pl->contr->listening) 199 if (pri >= pl->contr->listening)
209 return; 200 return;
210 201
211 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) 202 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE))
212 /* following prints stuff out, as appropriate */
213 check_output_buffers (pl, buf); 203 check_output_buffers (pl, buf);
214 else 204 else
215 print_message (flags & NDI_COLOR_MASK, pl, buf); 205 print_message (flags & NDI_COLOR_MASK, pl, buf);
216} 206}
217 207
227new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) 217new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...)
228{ 218{
229 char buf[HUGE_BUF]; 219 char buf[HUGE_BUF];
230 220
231 va_list ap; 221 va_list ap;
232
233 va_start (ap, format); 222 va_start (ap, format);
234
235 vsnprintf (buf, HUGE_BUF, format, ap); 223 vsnprintf (buf, HUGE_BUF, format, ap);
236
237 va_end (ap); 224 va_end (ap);
238 225
239 new_draw_info (flags, pri, pl, buf); 226 new_draw_info (flags, pri, pl, buf);
240} 227}
241 228
247 return; 234 return;
248 235
249 if (pri >= pl->contr->listening) 236 if (pri >= pl->contr->listening)
250 return; 237 return;
251 238
252 if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) 239 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
253 { 240 {
254 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); 241 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
255 242
256 if (buf == NULL) 243 if (buf == NULL)
257 LOG (llevError, "info::draw_ext_info -> Out of memory!"); 244 LOG (llevError, "info::draw_ext_info -> Out of memory!");
262 new_draw_info (flags, pri, pl, buf); 249 new_draw_info (flags, pri, pl, buf);
263 free (buf); 250 free (buf);
264 } 251 }
265 } 252 }
266 else 253 else
267 esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); 254 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message);
268} 255}
269 256
270void 257void
271draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) 258draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
272{ 259{
273
274 char buf[HUGE_BUF]; 260 char buf[HUGE_BUF];
275 261
276 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 262 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
277 return; 263 return;
278 264
279 if (pri >= pl->contr->listening) 265 if (pri >= pl->contr->listening)
280 return; 266 return;
281 267
282 if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) 268 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
283 { 269 {
284 va_list ap; 270 va_list ap;
285 271
286 LOG (llevDebug, "Non supported extension text type for client.\n"); 272 LOG (llevDebug, "Non supported extension text type for client.\n");
287 va_start (ap, new_format); 273 va_start (ap, new_format);
296 282
297 va_start (ap, new_format); 283 va_start (ap, new_format);
298 vsnprintf (buf, HUGE_BUF, new_format, ap); 284 vsnprintf (buf, HUGE_BUF, new_format, ap);
299 va_end (ap); 285 va_end (ap);
300 strip_media_tag (buf); 286 strip_media_tag (buf);
301 esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); 287 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
302 } 288 }
303} 289}
304 290
305/** 291/**
306 * Writes to everyone on the map *except* op. This is useful for emotions. 292 * Writes to everyone on the map *except* op. This is useful for emotions.
309void 295void
310new_info_map_except (int color, maptile * map, object *op, const char *str) 296new_info_map_except (int color, maptile * map, object *op, const char *str)
311{ 297{
312 player *pl; 298 player *pl;
313 299
314 for (pl = first_player; pl != NULL; pl = pl->next) 300 for_all_players (pl)
315 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) 301 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op)
316 {
317 new_draw_info (color, 0, pl->ob, str); 302 new_draw_info (color, 0, pl->ob, str);
318 }
319} 303}
320 304
321/** 305/**
322 * Writes to everyone on the map except op1 and op2 306 * Writes to everyone on the map except op1 and op2
323 */ 307 */
325void 309void
326new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) 310new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
327{ 311{
328 player *pl; 312 player *pl;
329 313
330 for (pl = first_player; pl != NULL; pl = pl->next) 314 for_all_players (pl)
331 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) 315 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
332 {
333 new_draw_info (color, 0, pl->ob, str); 316 new_draw_info (color, 0, pl->ob, str);
334 }
335} 317}
336 318
337/** 319/**
338 * Writes to everyone on the specified map 320 * Writes to everyone on the specified map
339 */ 321 */
341void 323void
342new_info_map (int color, maptile * map, const char *str) 324new_info_map (int color, maptile * map, const char *str)
343{ 325{
344 player *pl; 326 player *pl;
345 327
346 for (pl = first_player; pl != NULL; pl = pl->next) 328 for_all_players (pl)
347 if (pl->ob != NULL && pl->ob->map == map) 329 if (pl->ob != NULL && pl->ob->map == map)
348 {
349 new_draw_info (color, 0, pl->ob, str); 330 new_draw_info (color, 0, pl->ob, str);
350 }
351} 331}
352
353 332
354/** 333/**
355 * This does nothing now. However, in theory, we should probably send 334 * This does nothing now. However, in theory, we should probably send
356 * something to the client and let the client figure out how it might want 335 * something to the client and let the client figure out how it might want
357 * to handle this 336 * to handle this
464magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) 443magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py)
465{ 444{
466 int x, y, dx, dy, mflags; 445 int x, y, dx, dy, mflags;
467 sint16 nx, ny; 446 sint16 nx, ny;
468 maptile *mp; 447 maptile *mp;
469 New_Face *f; 448 facetile *f;
470 449
471 for (dx = -1; dx <= 1; dx++) 450 for (dx = -1; dx <= 1; dx++)
472 { 451 {
473 for (dy = -1; dy <= 1; dy++) 452 for (dy = -1; dy <= 1; dy++)
474 { 453 {
518 * being nonzero have been changed to check for 1. Also, since 497 * being nonzero have been changed to check for 1. Also, since
519 * map_mark is a char value, putting 2 in should cause no problems. 498 * map_mark is a char value, putting 2 in should cause no problems.
520 * 499 *
521 * This function examines the map the player is on, and determines what 500 * This function examines the map the player is on, and determines what
522 * is visible. 2 is set for walls or objects that blocks view. 1 501 * is visible. 2 is set for walls or objects that blocks view. 1
523 * is for open spaces. map_mark should already have been initialized 502 * is for open spaces. map_mark should already have been initialised
524 * to zero before this is called. 503 * to zero before this is called.
525 * strength is an initial strength*2 rectangular area that we automatically 504 * strength is an initial strength*2 rectangular area that we automatically
526 * see in/penetrate through. 505 * see in/penetrate through.
527 */ 506 */
528 507
530magic_mapping_mark (object *pl, char *map_mark, int strength) 509magic_mapping_mark (object *pl, char *map_mark, int strength)
531{ 510{
532 int x, y, mflags; 511 int x, y, mflags;
533 sint16 nx, ny; 512 sint16 nx, ny;
534 maptile *mp; 513 maptile *mp;
535 New_Face *f; 514 facetile *f;
536 515
537 for (x = -strength; x < strength; x++) 516 for (x = -strength; x < strength; x++)
538 { 517 {
539 for (y = -strength; y < strength; y++) 518 for (y = -strength; y < strength; y++)
540 { 519 {
570 * The following function is a lot messier than it really should be, 549 * The following function is a lot messier than it really should be,
571 * but there is no real easy solution. 550 * but there is no real easy solution.
572 * 551 *
573 * Mark Wedel 552 * Mark Wedel
574 */ 553 */
575
576void 554void
577draw_magic_map (object *pl) 555draw_magic_map (object *pl)
578{ 556{
579 char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); 557 char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1);
580 int xmin, xmax, ymin, ymax; 558 int xmin, xmax, ymin, ymax;
598 xmax = 0; 576 xmax = 0;
599 ymax = 0; 577 ymax = 0;
600 578
601 for (int x = 0; x < MAGIC_MAP_SIZE; x++) 579 for (int x = 0; x < MAGIC_MAP_SIZE; x++)
602 for (int y = 0; y < MAGIC_MAP_SIZE; y++) 580 for (int y = 0; y < MAGIC_MAP_SIZE; y++)
603 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) 581 if (map_mark[x + pl->map->width * y] | FACE_FLOOR)
604 { 582 {
605 xmin = x < xmin ? x : xmin; 583 xmin = x < xmin ? x : xmin;
606 xmax = x > xmax ? x : xmax; 584 xmax = x > xmax ? x : xmax;
607 ymin = y < ymin ? y : ymin; 585 ymin = y < ymin ? y : ymin;
608 ymax = y > ymax ? y : ymax; 586 ymax = y > ymax ? y : ymax;
614 592
615 for (int y = ymin; y <= ymax; y++) 593 for (int y = ymin; y <= ymax; y++)
616 for (int x = xmin; x <= xmax; x++) 594 for (int x = xmin; x <= xmax; x++)
617 sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); 595 sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR);
618 596
619 pl->contr->socket->send_packet (sl); 597 pl->contr->ns->send_packet (sl);
620 598
621 free (map_mark); 599 free (map_mark);
622} 600}
623 601
624/** 602/**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines