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.10 by root, Wed Sep 20 21:53:50 2006 UTC vs.
Revision 1.11 by root, Fri Sep 29 19:28:43 2006 UTC

229static int 229static int
230name_cmp (const chars_names * c1, const chars_names * c2) 230name_cmp (const chars_names * c1, const chars_names * c2)
231{ 231{
232 return strcasecmp (c1->namebuf, c2->namebuf); 232 return strcasecmp (c1->namebuf, c2->namebuf);
233} 233}
234
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 234
425int 235int
426command_afk (object *op, char *params) 236command_afk (object *op, char *params)
427{ 237{
428 if QUERY_FLAG 238 if QUERY_FLAG

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines