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

Comparing deliantra/server/server/c_misc.C (file contents):
Revision 1.7 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.13 by root, Mon Oct 2 00:22:01 2006 UTC

1
2/*
3 * static char *rcsid_c_misc_c =
4 * "$Id: c_misc.C,v 1.7 2006/09/10 15:59:57 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#include <loader.h> 25#include <loader.h>
32#ifndef __CEXTRACT__ 26#ifndef __CEXTRACT__
40 */ 34 */
41 35
42void 36void
43map_info (object *op, char *search) 37map_info (object *op, char *search)
44{ 38{
45 mapstruct *m; 39 maptile *m;
46 char buf[MAX_BUF], map_path[MAX_BUF]; 40 char buf[MAX_BUF], map_path[MAX_BUF];
47 long sec = seconds (); 41 long sec = seconds ();
48 42
49 new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); 43 new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
50 new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset"); 44 new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset");
150} 144}
151 145
152void 146void
153current_map_info (object *op) 147current_map_info (object *op)
154{ 148{
155 mapstruct *m = op->map; 149 maptile *m = op->map;
156 150
157 if (!m) 151 if (!m)
158 return; 152 return;
159 153
160 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m)); 154 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m));
237{ 231{
238 return strcasecmp (c1->namebuf, c2->namebuf); 232 return strcasecmp (c1->namebuf, c2->namebuf);
239} 233}
240 234
241int 235int
242command_who (object *op, char *params)
243{
244 player *pl;
245 uint16 i;
246 region *reg;
247 char *format;
248 int num_players = 0;
249 int num_wiz = 0;
250 int num_afk = 0;
251 chars_names *chars = NULL;
252
253 /*
254 * The who formats are defined in config to be blank. They should have been
255 * overridden by the settings file, if there are no entries however, it will
256 * have stayed blank. Since this probably isn't what is wanted, we will check if
257 * new formats have been specified, and if not we will use the old defaults.
258 */
259 if (!strcmp (settings.who_format, ""))
260 strcpy (settings.who_format, "%N_%T%t%h%d%n[%m]");
261 if (!strcmp (settings.who_wiz_format, ""))
262 strcpy (settings.who_wiz_format, "%N_%T%t%h%d%nLevel %l [%m](@%i)(%c)");
263 if (op == NULL || QUERY_FLAG (op, FLAG_WIZ))
264 format = settings.who_wiz_format;
265 else
266 format = settings.who_format;
267
268 reg = get_region_from_string (params);
269
270 for (pl = first_player; pl != NULL; pl = pl->next)
271 {
272 if (pl->ob->map == NULL)
273 continue;
274 if (pl->hidden && !QUERY_FLAG (op, FLAG_WIZ))
275 continue;
276
277 if (!region_is_child_of_region (get_region_by_map (pl->ob->map), reg))
278 continue;
279
280 if (pl->state == ST_PLAYING || pl->state == ST_GET_PARTY_PASSWORD)
281 {
282
283 num_players++;
284 chars = (chars_names *) realloc (chars, num_players * sizeof (chars_names));
285 if (chars == NULL)
286 {
287 new_draw_info (NDI_UNIQUE, 0, op, "who failed - out of memory!");
288 return 0;
289 }
290 sprintf (chars[num_players - 1].namebuf, "%s", &pl->ob->name);
291 chars[num_players - 1].login_order = num_players;
292 /*Check for WIZ's & AFK's */
293 if (QUERY_FLAG (pl->ob, FLAG_WIZ))
294 num_wiz++;
295 if (QUERY_FLAG (pl->ob, FLAG_AFK))
296 num_afk++;
297 }
298 }
299 if (first_player != (player *) NULL)
300 {
301 if (reg == NULL)
302 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players (%d) -- WIZ(%d) AFK(%d)", num_players, num_wiz, num_afk);
303 else if (reg->longname == NULL)
304 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players in %s (%d) -- WIZ(%d) AFK(%d)", reg->name, num_players, num_wiz, num_afk);
305 else
306 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players in %s (%d) -- WIZ(%d) AFK(%d)",
307 reg->longname, num_players, num_wiz, num_afk);
308 }
309 qsort (chars, num_players, sizeof (chars_names), (int (*)(const void *, const void *)) name_cmp);
310 for (i = 0; i < num_players; i++)
311 display_who_entry (op, find_player (chars[i].namebuf), format);
312 free (chars);
313 return 1;
314}
315
316/* Display a line of 'who' to op, about pl, using the formatting specified by format */
317void
318display_who_entry (object *op, player *pl, const char *format)
319{
320 char tmpbuf[MAX_BUF];
321 char outbuf[MAX_BUF];
322 size_t i;
323
324 outbuf[0] = '\0'; /* we strcat to this, so reset it here. */
325 if (pl == NULL)
326 {
327 LOG (llevError, "display_who_entry(): I was passed a null player");
328 return;
329 }
330 for (i = 0; i <= strlen (format); i++)
331 {
332 if (format[i] == '%')
333 {
334 i++;
335 get_who_escape_code_value (tmpbuf, format[i], pl);
336 strcat (outbuf, tmpbuf);
337 }
338 else if (format[i] == '_')
339 strcat (outbuf, " "); /* allow '_' to be used in place of spaces */
340 else
341 {
342 sprintf (tmpbuf, "%c", format[i]);
343 strcat (outbuf, tmpbuf);
344 }
345 }
346 new_draw_info (NDI_UNIQUE, 0, op, outbuf);
347}
348
349/* Returns the value of the escape code used in the who format specifier
350 * the values are:
351 * N Name of character
352 * t title of character
353 * T the optional "the " sequence value (depend if player has own_title or not)
354 * c count
355 * n newline
356 * h [Hostile] if character is hostile, nothing otherwise
357 * d [WIZ] if character is a dm, nothing otherwise
358 * a [AFK] if character is afk, nothing otherwise
359 * l the level of the character
360 * m the map path the character is currently on
361 * M the map name of the map the character is currently on
362 * r the region name (eg scorn, wolfsburg)
363 * R the regional title (eg The Kingdom of Scorn, The Port of Wolfsburg)
364 * i player's ip adress
365 * % a literal %
366 * _ a literal underscore
367 */
368
369void
370get_who_escape_code_value (char *return_val, const char letter, player *pl)
371{
372
373 switch (letter)
374 {
375 case 'N':
376 strcpy (return_val, pl->ob->name);
377 break;
378 case 't':
379 strcpy (return_val, (pl->own_title[0] == '\0' ? pl->title : pl->own_title));
380 break;
381 case 'T':
382 if (pl->own_title[0] == '\0')
383 strcpy (return_val, "the ");
384 else
385 *return_val = '\0';
386 break;
387 case 'c':
388 sprintf (return_val, "%d", pl->ob->count);
389 break;
390 case 'n':
391 strcpy (return_val, "\n");
392 break;
393 case 'h':
394 strcpy (return_val, pl->peaceful ? "" : " [Hostile]");
395 break;
396 case 'l':
397 sprintf (return_val, "%d", pl->ob->level);
398 break;
399 case 'd':
400 strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_WIZ) ? " [WIZ]" : ""));
401 break;
402 case 'a':
403 strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_AFK) ? " [AFK]" : ""));
404 break;
405 case 'm':
406 strcpy (return_val, pl->ob->map->path);
407 break;
408 case 'M':
409 strcpy (return_val, pl->ob->map->name ? pl->ob->map->name : "Untitled");
410 break;
411 case 'r':
412 strcpy (return_val, get_name_of_region_for_map (pl->ob->map));
413 break;
414 case 'R':
415 strcpy (return_val, get_region_longname (get_region_by_map (pl->ob->map)));
416 break;
417 case 'i':
418 strcpy (return_val, pl->socket.host);
419 break;
420 case '%':
421 strcpy (return_val, "%");
422 break;
423 case '_':
424 strcpy (return_val, "_");
425 break;
426 }
427
428}
429
430
431int
432command_afk (object *op, char *params) 236command_afk (object *op, char *params)
433{ 237{
434 if QUERY_FLAG 238 if QUERY_FLAG
435 (op, FLAG_AFK) 239 (op, FLAG_AFK)
436 { 240 {
653 { 457 {
654 dump_object (op->below); 458 dump_object (op->below);
655 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 459 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
656 /* Let's push that item on the dm's stack */ 460 /* Let's push that item on the dm's stack */
657 dm_stack_push (op->contr, op->below->count); 461 dm_stack_push (op->contr, op->below->count);
658 }
659 return 0;
660}
661
662int
663command_wizpass (object *op, char *params)
664{
665 int i;
666
667 if (!op)
668 return 0;
669
670 if (!params)
671 i = (QUERY_FLAG (op, FLAG_WIZPASS)) ? 0 : 1;
672 else
673 i = onoff_value (params);
674
675 if (i)
676 {
677 new_draw_info (NDI_UNIQUE, 0, op, "You will now walk through walls.\n");
678 SET_FLAG (op, FLAG_WIZPASS);
679 }
680 else
681 {
682 new_draw_info (NDI_UNIQUE, 0, op, "You will now be stopped by walls.\n");
683 CLEAR_FLAG (op, FLAG_WIZPASS);
684 }
685 return 0;
686}
687
688int
689command_wizcast (object *op, char *params)
690{
691 int i;
692
693 if (!op)
694 return 0;
695
696 if (!params)
697 i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1;
698 else
699 i = onoff_value (params);
700
701 if (i)
702 {
703 new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere.");
704 SET_FLAG (op, FLAG_WIZCAST);
705 }
706 else
707 {
708 new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas.");
709 CLEAR_FLAG (op, FLAG_WIZCAST);
710 } 462 }
711 return 0; 463 return 0;
712} 464}
713 465
714int 466int
936 688
937 689
938int 690int
939command_logs (object *op, char *params) 691command_logs (object *op, char *params)
940{ 692{
941 int i;
942 int first;
943
944 first = 1;
945 for (i = 2; i < socket_info.allocated_sockets; i++)
946 {
947 if (init_sockets[i].old_mode == Old_Listen)
948 {
949 if (first)
950 {
951 new_draw_info (NDI_UNIQUE, 0, op, "Kill-logs are sent to:");
952 first = 0;
953 }
954 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %s", init_sockets[i].host, init_sockets[i].comment);
955 }
956 }
957 if (first)
958 {
959 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); 693 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
960 } 694
961 return 1; 695 return 1;
962} 696}
963 697
964int 698int
965command_applymode (object *op, char *params) 699command_applymode (object *op, char *params)
1691} 1425}
1692 1426
1693int 1427int
1694command_style_map_info (object *op, char *params) 1428command_style_map_info (object *op, char *params)
1695{ 1429{
1696 extern mapstruct *styles; 1430 extern maptile *styles;
1697 mapstruct *mp; 1431 maptile *mp;
1698 int maps_used = 0, mapmem = 0, objects_used = 0, x, y; 1432 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1699 object *tmp; 1433 object *tmp;
1700 1434
1701 for (mp = styles; mp != NULL; mp = mp->next) 1435 for (mp = styles; mp != NULL; mp = mp->next)
1702 { 1436 {
1703 maps_used++; 1437 maps_used++;
1704 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (mapstruct); 1438 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1705 for (x = 0; x < MAP_WIDTH (mp); x++) 1439 for (x = 0; x < MAP_WIDTH (mp); x++)
1706 { 1440 {
1707 for (y = 0; y < MAP_HEIGHT (mp); y++) 1441 for (y = 0; y < MAP_HEIGHT (mp); y++)
1708 { 1442 {
1709 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) 1443 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines