ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.63
Committed: Fri Aug 10 05:25:16 2007 UTC (16 years, 9 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.62: +0 -180 lines
Log Message:
move hiscore and whereabouts to perl

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.59 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 pippijn 1.36 *
4 root 1.59 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5     * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 Frank Tore Johansen
7 pippijn 1.36 *
8 root 1.62 * Crossfire TRT is free software: you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation, either version 3 of the License, or
11     * (at your option) any later version.
12 pippijn 1.36 *
13 root 1.62 * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17 pippijn 1.36 *
18 root 1.62 * You should have received a copy of the GNU General Public License
19     * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 root 1.59 *
21     * The authors can be reached via e-mail to <crossfire@schmorp.de>
22 pippijn 1.36 */
23 elmex 1.1
24     #include <global.h>
25     #include <loader.h>
26 root 1.21 #include <sproto.h>
27    
28 pippijn 1.55 /* Handles misc. input request - things like hash table, malloc, maps, etc */
29 elmex 1.1
30 root 1.7 int
31     command_motd (object *op, char *params)
32 elmex 1.1 {
33 root 1.7 display_motd (op);
34     return 1;
35 elmex 1.1 }
36    
37     #ifdef DEBUG_MALLOC_LEVEL
38 root 1.7 int
39     command_malloc_verify (object *op, char *parms)
40 elmex 1.1 {
41 root 1.7 extern int malloc_verify (void);
42 pippijn 1.54
43 root 1.7 if (!malloc_verify ())
44     new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
45     else
46     new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
47     return 1;
48     }
49 elmex 1.1 #endif
50    
51     typedef struct
52 root 1.7 {
53     char namebuf[MAX_BUF];
54     int login_order;
55     } chars_names;
56 elmex 1.1
57 root 1.7 int
58     command_time (object *op, char *params)
59 elmex 1.1 {
60 root 1.2 print_tod (op);
61     return 1;
62     }
63 elmex 1.1
64 root 1.7 int
65     command_debug (object *op, char *params)
66 elmex 1.1 {
67 root 1.7 int i;
68     char buf[MAX_BUF];
69    
70     if (params == NULL || !sscanf (params, "%d", &i))
71     {
72     sprintf (buf, "Global debug level is %d.", settings.debug);
73     new_draw_info (NDI_UNIQUE, 0, op, buf);
74 elmex 1.1 return 1;
75     }
76 root 1.58
77     settings.debug = i;
78    
79 root 1.7 sprintf (buf, "Set debug level to %d.", i);
80     new_draw_info (NDI_UNIQUE, 0, op, buf);
81     return 1;
82     }
83 elmex 1.1
84    
85     /*
86     * Those dumps should be just one dump with good parser
87     */
88    
89 root 1.7 int
90     command_dumpbelow (object *op, char *params)
91 elmex 1.1 {
92 root 1.7 if (op && op->below)
93     {
94 root 1.14 char *dump = dump_object (op->below);
95     new_draw_info (NDI_UNIQUE, 0, op, dump);
96     free (dump);
97 elmex 1.1 /* Let's push that item on the dm's stack */
98 root 1.7 dm_stack_push (op->contr, op->below->count);
99     }
100 elmex 1.1 return 0;
101     }
102    
103 root 1.7 int
104     command_dumpfriendlyobjects (object *op, char *params)
105 elmex 1.1 {
106 root 1.7 dump_friendly_objects ();
107 elmex 1.1 return 0;
108     }
109    
110 root 1.7 int
111     command_printlos (object *op, char *params)
112 elmex 1.1 {
113     if (op)
114 root 1.7 print_los (op);
115 elmex 1.1 return 0;
116     }
117    
118    
119 root 1.7 int
120     command_version (object *op, char *params)
121 elmex 1.1 {
122 root 1.7 version (op);
123     return 0;
124 elmex 1.1 }
125    
126     #ifndef BUG_LOG
127 root 1.7 # define BUG_LOG "bug_log"
128 elmex 1.1 #endif
129 root 1.7 void
130     bug_report (const char *reportstring)
131     {
132     FILE *fp;
133    
134     if ((fp = fopen (BUG_LOG, "a")) != NULL)
135     {
136     fprintf (fp, "%s\n", reportstring);
137     fclose (fp);
138     }
139     else
140     {
141     LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
142 elmex 1.1 }
143 root 1.7 }
144    
145 elmex 1.1 /* Prints out some useful information for the character. Everything we print
146     * out can be determined by the docs, so we aren't revealing anything extra -
147     * rather, we are making it convenient to find the values. params have
148     * no meaning here.
149     */
150 root 1.7 int
151     command_statistics (object *pl, char *params)
152 elmex 1.1 {
153 root 1.7 if (!pl->contr)
154     return 1;
155 root 1.18 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
156     new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
157 root 1.7 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
158 elmex 1.1
159 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
160 root 1.61 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->stats.Str);
161 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
162 root 1.61 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->stats.Dex);
163 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
164 root 1.61 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->stats.Con);
165 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
166 root 1.61 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->stats.Int);
167 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
168 root 1.61 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->stats.Wis);
169 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
170 root 1.61 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->stats.Pow);
171 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
172 root 1.61 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->stats.Cha);
173 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
174 elmex 1.1
175 root 1.7 /* Can't think of anything else to print right now */
176     return 0;
177 elmex 1.1 }
178    
179 root 1.7 int
180     command_fix_me (object *op, char *params)
181 elmex 1.1 {
182 root 1.7 sum_weight (op);
183 root 1.27 op->update_stats ();
184 pippijn 1.51 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
185    
186 root 1.7 return 1;
187 elmex 1.1 }
188    
189 root 1.7 int
190     command_logs (object *op, char *params)
191 elmex 1.1 {
192 root 1.10 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
193 elmex 1.1
194 root 1.7 return 1;
195 elmex 1.1 }
196    
197 root 1.7 int
198     command_bowmode (object *op, char *params)
199 elmex 1.1 {
200 root 1.7 bowtype_t oldtype = op->contr->bowtype;
201     static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth",
202     "firene", "fireeast", "firese", "firesouth",
203     "firesw", "firewest", "firenw", "bestarrow"
204     };
205     char buf[MAX_BUF];
206     int i, found;
207    
208     if (!params)
209     {
210     new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]);
211     return 1;
212     }
213    
214     for (i = 0, found = 0; i <= bow_bestarrow; i++)
215     {
216     if (!strcmp (params, types[i]))
217     {
218     found++;
219     op->contr->bowtype = (bowtype_t) i;
220     break;
221 root 1.3 }
222 elmex 1.1 }
223 root 1.38
224 root 1.7 if (!found)
225     {
226     sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
227     for (i = 0; i <= bow_bestarrow; i++)
228     {
229     strcat (buf, " ");
230     strcat (buf, types[i]);
231     if (i < bow_nw)
232     strcat (buf, ",");
233     else
234     strcat (buf, ".");
235 root 1.3 }
236 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
237     return 0;
238 elmex 1.1 }
239 root 1.38
240 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
241     return 1;
242 elmex 1.1 }
243    
244 root 1.7 int
245     command_showpets (object *op, char *params)
246 elmex 1.1 {
247 root 1.7 objectlink *obl, *next;
248     int counter = 0, target = 0;
249     int have_shown_pet = 0;
250    
251     if (params != NULL)
252     target = atoi (params);
253     for (obl = first_friendly_object; obl != NULL; obl = next)
254     {
255     object *ob = obl->ob;
256    
257     next = obl->next;
258 root 1.22 if (ob->owner == op)
259 root 1.7 {
260     if (target == 0)
261     {
262     if (counter == 0)
263     new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
264     new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level);
265     }
266     else if (!have_shown_pet && ++counter == target)
267     {
268     new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name);
269     new_draw_info_format (NDI_UNIQUE, 0, op, "%d/%d HP, %d/%d SP", ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp);
270     /* this is not a nice way to do this, it should be made to be more like the statistics command */
271     new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str);
272     new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex);
273     new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con);
274     new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int);
275     new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis);
276     new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha);
277     new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow);
278     new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac);
279     have_shown_pet = 1;
280 root 1.3 }
281     }
282 elmex 1.1 }
283 root 1.7 if (counter == 0)
284     new_draw_info (NDI_UNIQUE, 0, op, "you have no pets.");
285     else if (target != 0 && have_shown_pet == 0)
286     new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
287     return 0;
288 elmex 1.1 }
289    
290 root 1.7 int
291     command_resistances (object *op, char *params)
292 elmex 1.1 {
293 root 1.7 int i;
294 elmex 1.1
295 root 1.7 if (!op)
296     return 0;
297    
298     for (i = 0; i < NROFATTACKS; i++)
299     {
300     if (i == ATNR_INTERNAL)
301     continue;
302 elmex 1.1
303 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
304 elmex 1.1 }
305    
306 root 1.7 /* If dragon player, let's display natural resistances */
307     if (is_dragon_pl (op))
308     {
309     int attack;
310     object *tmp;
311    
312     for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
313 elmex 1.1 {
314 root 1.60 if ((tmp->type == FORCE) && (strcmp (tmp->arch->archname, "dragon_skin_force") == 0))
315 elmex 1.1 {
316 root 1.7 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
317     for (attack = 0; attack < NROFATTACKS; attack++)
318 elmex 1.1 {
319 root 1.7 if (atnr_is_dragon_enabled (attack))
320 elmex 1.1 {
321 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
322 elmex 1.1 }
323     }
324 root 1.7 break;
325 elmex 1.1 }
326     }
327 root 1.7 }
328 elmex 1.1
329 root 1.7 return 0;
330 elmex 1.1 }
331 root 1.7
332 elmex 1.1 /*
333     * Actual commands.
334     * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
335     */
336    
337 root 1.7 int
338     onoff_value (const char *line)
339 elmex 1.1 {
340     int i;
341    
342 root 1.7 if (sscanf (line, "%d", &i))
343 elmex 1.1 return (i != 0);
344 root 1.7 switch (line[0])
345     {
346     case 'o':
347     switch (line[1])
348     {
349     case 'n':
350     return 1; /* on */
351     default:
352     return 0; /* o[ff] */
353     }
354     case 'y': /* y[es] */
355     case 'k': /* k[ylla] */
356     case 's':
357     case 'd':
358     return 1;
359     case 'n': /* n[o] */
360     case 'e': /* e[i] */
361     case 'u':
362     default:
363     return 0;
364     }
365 elmex 1.1 }
366    
367 root 1.7 int
368     command_title (object *op, char *params)
369 elmex 1.1 {
370 root 1.7 char buf[MAX_BUF];
371    
372     if (settings.set_title == FALSE)
373     {
374     new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
375     return 1;
376 elmex 1.1 }
377 root 1.7
378     /* dragon players cannot change titles */
379     if (is_dragon_pl (op))
380     {
381     new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
382     return 1;
383     }
384    
385     if (params == NULL)
386     {
387     if (op->contr->own_title[0] == '\0')
388     sprintf (buf, "Your title is '%s'.", op->contr->title);
389     else
390     sprintf (buf, "Your title is '%s'.", op->contr->own_title);
391     new_draw_info (NDI_UNIQUE, 0, op, buf);
392     return 1;
393     }
394     if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
395     {
396     if (op->contr->own_title[0] == '\0')
397     new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
398     else
399     new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
400     op->contr->own_title[0] = '\0';
401     return 1;
402     }
403    
404     if ((int) strlen (params) >= MAX_NAME)
405     {
406     new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
407     return 1;
408     }
409     strcpy (op->contr->own_title, params);
410     return 1;
411 elmex 1.1 }
412    
413 root 1.7 int
414     command_kill_pets (object *op, char *params)
415 elmex 1.1 {
416 root 1.7 objectlink *obl, *next;
417     int counter = 0, removecount = 0;
418    
419 root 1.57 if (!params)
420 root 1.7 {
421     terminate_all_pets (op);
422     new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
423     }
424     else
425     {
426     int target = atoi (params);
427    
428 root 1.57 for (obl = first_friendly_object; obl; obl = next)
429 root 1.7 {
430     object *ob = obl->ob;
431    
432     next = obl->next;
433 root 1.56
434 root 1.22 if (ob->owner == op)
435 root 1.7 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
436     {
437 root 1.20 ob->destroy ();
438 root 1.3 removecount++;
439 root 1.7 }
440 root 1.3 }
441 root 1.56
442 root 1.7 if (removecount != 0)
443     new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
444     else
445     new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
446 elmex 1.1 }
447 root 1.56
448 root 1.7 return 0;
449 elmex 1.1 }