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.8 by root, Thu Sep 14 22:34:03 2006 UTC vs.
Revision 1.13 by root, Mon Oct 2 00:22:01 2006 UTC

34 */ 34 */
35 35
36void 36void
37map_info (object *op, char *search) 37map_info (object *op, char *search)
38{ 38{
39 mapstruct *m; 39 maptile *m;
40 char buf[MAX_BUF], map_path[MAX_BUF]; 40 char buf[MAX_BUF], map_path[MAX_BUF];
41 long sec = seconds (); 41 long sec = seconds ();
42 42
43 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);
44 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");
144} 144}
145 145
146void 146void
147current_map_info (object *op) 147current_map_info (object *op)
148{ 148{
149 mapstruct *m = op->map; 149 maptile *m = op->map;
150 150
151 if (!m) 151 if (!m)
152 return; 152 return;
153 153
154 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));
231{ 231{
232 return strcasecmp (c1->namebuf, c2->namebuf); 232 return strcasecmp (c1->namebuf, c2->namebuf);
233} 233}
234 234
235int 235int
236command_who (object *op, char *params)
237{
238 player *pl;
239 uint16 i;
240 region *reg;
241 char *format;
242 int num_players = 0;
243 int num_wiz = 0;
244 int num_afk = 0;
245 chars_names *chars = NULL;
246
247 /*
248 * The who formats are defined in config to be blank. They should have been
249 * overridden by the settings file, if there are no entries however, it will
250 * have stayed blank. Since this probably isn't what is wanted, we will check if
251 * new formats have been specified, and if not we will use the old defaults.
252 */
253 if (!strcmp (settings.who_format, ""))
254 strcpy (settings.who_format, "%N_%T%t%h%d%n[%m]");
255 if (!strcmp (settings.who_wiz_format, ""))
256 strcpy (settings.who_wiz_format, "%N_%T%t%h%d%nLevel %l [%m](@%i)(%c)");
257 if (op == NULL || QUERY_FLAG (op, FLAG_WIZ))
258 format = settings.who_wiz_format;
259 else
260 format = settings.who_format;
261
262 reg = get_region_from_string (params);
263
264 for (pl = first_player; pl != NULL; pl = pl->next)
265 {
266 if (pl->ob->map == NULL)
267 continue;
268 if (pl->hidden && !QUERY_FLAG (op, FLAG_WIZ))
269 continue;
270
271 if (!region_is_child_of_region (get_region_by_map (pl->ob->map), reg))
272 continue;
273
274 if (pl->state == ST_PLAYING || pl->state == ST_GET_PARTY_PASSWORD)
275 {
276
277 num_players++;
278 chars = (chars_names *) realloc (chars, num_players * sizeof (chars_names));
279 if (chars == NULL)
280 {
281 new_draw_info (NDI_UNIQUE, 0, op, "who failed - out of memory!");
282 return 0;
283 }
284 sprintf (chars[num_players - 1].namebuf, "%s", &pl->ob->name);
285 chars[num_players - 1].login_order = num_players;
286 /*Check for WIZ's & AFK's */
287 if (QUERY_FLAG (pl->ob, FLAG_WIZ))
288 num_wiz++;
289 if (QUERY_FLAG (pl->ob, FLAG_AFK))
290 num_afk++;
291 }
292 }
293 if (first_player != (player *) NULL)
294 {
295 if (reg == NULL)
296 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players (%d) -- WIZ(%d) AFK(%d)", num_players, num_wiz, num_afk);
297 else if (reg->longname == NULL)
298 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);
299 else
300 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players in %s (%d) -- WIZ(%d) AFK(%d)",
301 reg->longname, num_players, num_wiz, num_afk);
302 }
303 qsort (chars, num_players, sizeof (chars_names), (int (*)(const void *, const void *)) name_cmp);
304 for (i = 0; i < num_players; i++)
305 display_who_entry (op, find_player (chars[i].namebuf), format);
306 free (chars);
307 return 1;
308}
309
310/* Display a line of 'who' to op, about pl, using the formatting specified by format */
311void
312display_who_entry (object *op, player *pl, const char *format)
313{
314 char tmpbuf[MAX_BUF];
315 char outbuf[MAX_BUF];
316 size_t i;
317
318 outbuf[0] = '\0'; /* we strcat to this, so reset it here. */
319 if (pl == NULL)
320 {
321 LOG (llevError, "display_who_entry(): I was passed a null player");
322 return;
323 }
324 for (i = 0; i <= strlen (format); i++)
325 {
326 if (format[i] == '%')
327 {
328 i++;
329 get_who_escape_code_value (tmpbuf, format[i], pl);
330 strcat (outbuf, tmpbuf);
331 }
332 else if (format[i] == '_')
333 strcat (outbuf, " "); /* allow '_' to be used in place of spaces */
334 else
335 {
336 sprintf (tmpbuf, "%c", format[i]);
337 strcat (outbuf, tmpbuf);
338 }
339 }
340 new_draw_info (NDI_UNIQUE, 0, op, outbuf);
341}
342
343/* Returns the value of the escape code used in the who format specifier
344 * the values are:
345 * N Name of character
346 * t title of character
347 * T the optional "the " sequence value (depend if player has own_title or not)
348 * c count
349 * n newline
350 * h [Hostile] if character is hostile, nothing otherwise
351 * d [WIZ] if character is a dm, nothing otherwise
352 * a [AFK] if character is afk, nothing otherwise
353 * l the level of the character
354 * m the map path the character is currently on
355 * M the map name of the map the character is currently on
356 * r the region name (eg scorn, wolfsburg)
357 * R the regional title (eg The Kingdom of Scorn, The Port of Wolfsburg)
358 * i player's ip adress
359 * % a literal %
360 * _ a literal underscore
361 */
362
363void
364get_who_escape_code_value (char *return_val, const char letter, player *pl)
365{
366
367 switch (letter)
368 {
369 case 'N':
370 strcpy (return_val, pl->ob->name);
371 break;
372 case 't':
373 strcpy (return_val, (pl->own_title[0] == '\0' ? pl->title : pl->own_title));
374 break;
375 case 'T':
376 if (pl->own_title[0] == '\0')
377 strcpy (return_val, "the ");
378 else
379 *return_val = '\0';
380 break;
381 case 'c':
382 sprintf (return_val, "%d", pl->ob->count);
383 break;
384 case 'n':
385 strcpy (return_val, "\n");
386 break;
387 case 'h':
388 strcpy (return_val, pl->peaceful ? "" : " [Hostile]");
389 break;
390 case 'l':
391 sprintf (return_val, "%d", pl->ob->level);
392 break;
393 case 'd':
394 strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_WIZ) ? " [WIZ]" : ""));
395 break;
396 case 'a':
397 strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_AFK) ? " [AFK]" : ""));
398 break;
399 case 'm':
400 strcpy (return_val, pl->ob->map->path);
401 break;
402 case 'M':
403 strcpy (return_val, pl->ob->map->name ? pl->ob->map->name : "Untitled");
404 break;
405 case 'r':
406 strcpy (return_val, get_name_of_region_for_map (pl->ob->map));
407 break;
408 case 'R':
409 strcpy (return_val, get_region_longname (get_region_by_map (pl->ob->map)));
410 break;
411 case 'i':
412 strcpy (return_val, pl->socket.host);
413 break;
414 case '%':
415 strcpy (return_val, "%");
416 break;
417 case '_':
418 strcpy (return_val, "_");
419 break;
420 }
421
422}
423
424
425int
426command_afk (object *op, char *params) 236command_afk (object *op, char *params)
427{ 237{
428 if QUERY_FLAG 238 if QUERY_FLAG
429 (op, FLAG_AFK) 239 (op, FLAG_AFK)
430 { 240 {
647 { 457 {
648 dump_object (op->below); 458 dump_object (op->below);
649 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 459 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
650 /* Let's push that item on the dm's stack */ 460 /* Let's push that item on the dm's stack */
651 dm_stack_push (op->contr, op->below->count); 461 dm_stack_push (op->contr, op->below->count);
652 }
653 return 0;
654}
655
656int
657command_wizpass (object *op, char *params)
658{
659 int i;
660
661 if (!op)
662 return 0;
663
664 if (!params)
665 i = (QUERY_FLAG (op, FLAG_WIZPASS)) ? 0 : 1;
666 else
667 i = onoff_value (params);
668
669 if (i)
670 {
671 new_draw_info (NDI_UNIQUE, 0, op, "You will now walk through walls.\n");
672 SET_FLAG (op, FLAG_WIZPASS);
673 }
674 else
675 {
676 new_draw_info (NDI_UNIQUE, 0, op, "You will now be stopped by walls.\n");
677 CLEAR_FLAG (op, FLAG_WIZPASS);
678 }
679 return 0;
680}
681
682int
683command_wizcast (object *op, char *params)
684{
685 int i;
686
687 if (!op)
688 return 0;
689
690 if (!params)
691 i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1;
692 else
693 i = onoff_value (params);
694
695 if (i)
696 {
697 new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere.");
698 SET_FLAG (op, FLAG_WIZCAST);
699 }
700 else
701 {
702 new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas.");
703 CLEAR_FLAG (op, FLAG_WIZCAST);
704 } 462 }
705 return 0; 463 return 0;
706} 464}
707 465
708int 466int
930 688
931 689
932int 690int
933command_logs (object *op, char *params) 691command_logs (object *op, char *params)
934{ 692{
935 int i;
936 int first;
937
938 first = 1;
939 for (i = 2; i < socket_info.allocated_sockets; i++)
940 {
941 if (init_sockets[i].old_mode == Old_Listen)
942 {
943 if (first)
944 {
945 new_draw_info (NDI_UNIQUE, 0, op, "Kill-logs are sent to:");
946 first = 0;
947 }
948 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %s", init_sockets[i].host, init_sockets[i].comment);
949 }
950 }
951 if (first)
952 {
953 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.");
954 } 694
955 return 1; 695 return 1;
956} 696}
957 697
958int 698int
959command_applymode (object *op, char *params) 699command_applymode (object *op, char *params)
1685} 1425}
1686 1426
1687int 1427int
1688command_style_map_info (object *op, char *params) 1428command_style_map_info (object *op, char *params)
1689{ 1429{
1690 extern mapstruct *styles; 1430 extern maptile *styles;
1691 mapstruct *mp; 1431 maptile *mp;
1692 int maps_used = 0, mapmem = 0, objects_used = 0, x, y; 1432 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1693 object *tmp; 1433 object *tmp;
1694 1434
1695 for (mp = styles; mp != NULL; mp = mp->next) 1435 for (mp = styles; mp != NULL; mp = mp->next)
1696 { 1436 {
1697 maps_used++; 1437 maps_used++;
1698 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);
1699 for (x = 0; x < MAP_WIDTH (mp); x++) 1439 for (x = 0; x < MAP_WIDTH (mp); x++)
1700 { 1440 {
1701 for (y = 0; y < MAP_HEIGHT (mp); y++) 1441 for (y = 0; y < MAP_HEIGHT (mp); y++)
1702 { 1442 {
1703 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