ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.68
Committed: Tue May 6 16:55:26 2008 UTC (16 years ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_6, rel-2_54, rel-2_55, rel-2_56, rel-2_61
Changes since 1.67: +1 -1 lines
Log Message:
update copyright

File Contents

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