ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.83
Committed: Fri Mar 26 00:59:22 2010 UTC (14 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-3_0
Changes since 1.82: +2 -2 lines
Log Message:
remove bogus 2007 copyright that was added wrongly by the script, update to affero license

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.81 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.83 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 pippijn 1.36 *
8 root 1.75 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * 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.75 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.59 *
22 root 1.65 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.36 */
24 elmex 1.1
25     #include <global.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     typedef struct
31 root 1.7 {
32     char namebuf[MAX_BUF];
33     int login_order;
34     } chars_names;
35 elmex 1.1
36 root 1.7 int
37     command_time (object *op, char *params)
38 elmex 1.1 {
39 root 1.2 print_tod (op);
40     return 1;
41     }
42 elmex 1.1
43 root 1.7 int
44     command_debug (object *op, char *params)
45 elmex 1.1 {
46 root 1.7 int i;
47     char buf[MAX_BUF];
48    
49     if (params == NULL || !sscanf (params, "%d", &i))
50     {
51     sprintf (buf, "Global debug level is %d.", settings.debug);
52     new_draw_info (NDI_UNIQUE, 0, op, buf);
53 elmex 1.1 return 1;
54     }
55 root 1.58
56     settings.debug = i;
57    
58 root 1.7 sprintf (buf, "Set debug level to %d.", i);
59     new_draw_info (NDI_UNIQUE, 0, op, buf);
60     return 1;
61     }
62 elmex 1.1
63     /*
64     * Those dumps should be just one dump with good parser
65     */
66    
67 root 1.7 int
68     command_dumpbelow (object *op, char *params)
69 elmex 1.1 {
70 root 1.7 if (op && op->below)
71     {
72 root 1.14 char *dump = dump_object (op->below);
73     new_draw_info (NDI_UNIQUE, 0, op, dump);
74     free (dump);
75 elmex 1.1 /* Let's push that item on the dm's stack */
76 root 1.7 dm_stack_push (op->contr, op->below->count);
77     }
78 elmex 1.1 return 0;
79     }
80    
81 root 1.7 int
82     command_version (object *op, char *params)
83 elmex 1.1 {
84 root 1.7 version (op);
85     return 0;
86 elmex 1.1 }
87    
88     /* Prints out some useful information for the character. Everything we print
89     * out can be determined by the docs, so we aren't revealing anything extra -
90     * rather, we are making it convenient to find the values. params have
91     * no meaning here.
92     */
93 root 1.7 int
94     command_statistics (object *pl, char *params)
95 elmex 1.1 {
96 root 1.7 if (!pl->contr)
97     return 1;
98 root 1.73
99 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
100 root 1.73
101     msg << " Experience: " << pl->stats.exp << '\n'
102     << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n'
103     << "\n Stat Nat/Real/Max\n";
104    
105     for (int i = 0; i < NUM_STATS; ++i)
106     msg.printf (" %s %2d/ %3d/%3d\n", short_stat_name [i], pl->contr->orig_stats.stat (i), pl->stats.stat (i), 20 + pl->arch->stats.stat (i));
107    
108     msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
109    
110     pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
111 elmex 1.1
112 root 1.7 /* Can't think of anything else to print right now */
113     return 0;
114 elmex 1.1 }
115    
116 root 1.7 int
117     command_fix_me (object *op, char *params)
118 elmex 1.1 {
119 root 1.67 op->update_weight ();
120 root 1.27 op->update_stats ();
121 pippijn 1.51 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
122    
123 root 1.7 return 1;
124 elmex 1.1 }
125    
126 root 1.7 int
127     command_bowmode (object *op, char *params)
128 elmex 1.1 {
129 root 1.7 bowtype_t oldtype = op->contr->bowtype;
130 root 1.73 static const char *const types[] = {
131     "normal", "threewide", "spreadshot", "firenorth",
132 root 1.7 "firene", "fireeast", "firese", "firesouth",
133     "firesw", "firewest", "firenw", "bestarrow"
134     };
135     char buf[MAX_BUF];
136     int i, found;
137    
138     if (!params)
139     {
140     new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]);
141     return 1;
142     }
143    
144     for (i = 0, found = 0; i <= bow_bestarrow; i++)
145     {
146     if (!strcmp (params, types[i]))
147     {
148     found++;
149     op->contr->bowtype = (bowtype_t) i;
150     break;
151 root 1.3 }
152 elmex 1.1 }
153 root 1.38
154 root 1.7 if (!found)
155     {
156     sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
157 root 1.73
158 root 1.7 for (i = 0; i <= bow_bestarrow; i++)
159     {
160     strcat (buf, " ");
161     strcat (buf, types[i]);
162     if (i < bow_nw)
163     strcat (buf, ",");
164     else
165     strcat (buf, ".");
166 root 1.3 }
167 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
168     return 0;
169 elmex 1.1 }
170 root 1.38
171 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]);
172     return 1;
173 elmex 1.1 }
174    
175 root 1.7 int
176     command_showpets (object *op, char *params)
177 elmex 1.1 {
178 root 1.7 int counter = 0, target = 0;
179     int have_shown_pet = 0;
180    
181 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
182 root 1.73
183     if (params)
184 root 1.7 target = atoi (params);
185 root 1.73
186     for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
187 root 1.7 {
188     object *ob = obl->ob;
189    
190 root 1.22 if (ob->owner == op)
191 root 1.7 {
192     if (target == 0)
193     {
194     if (counter == 0)
195 root 1.73 msg << "T<Pets>\n\n";
196    
197     msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
198 root 1.7 }
199     else if (!have_shown_pet && ++counter == target)
200     {
201 root 1.73 msg.printf ("T<%s>\n\n"
202     " level %d\n"
203     " %d/%d HP, %d/%d SP\n"
204     " Str %2d\n"
205     " Dex %2d\n"
206     " Con %2d\n"
207     " Int %2d\n"
208     " Wis %2d\n"
209     " Cha %2d\n"
210     " Pow %2d\n"
211     " wc %d damage %d ac %d\n",
212     &ob->name,
213 root 1.80 ob->level,
214 root 1.73 ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp,
215     ob->stats.Str,
216     ob->stats.Dex,
217     ob->stats.Con,
218     ob->stats.Int,
219     ob->stats.Wis,
220     ob->stats.Cha,
221     ob->stats.Pow,
222     ob->stats.wc, ob->stats.dam, ob->stats.ac);
223    
224 root 1.7 have_shown_pet = 1;
225 root 1.3 }
226     }
227 elmex 1.1 }
228 root 1.73
229 root 1.7 if (counter == 0)
230 root 1.73 msg << "you have no pets.";
231 root 1.7 else if (target != 0 && have_shown_pet == 0)
232 root 1.73 msg << "no such pet.";
233    
234     op->contr->infobox (MSG_CHANNEL ("pets"), msg);
235    
236 root 1.7 return 0;
237 elmex 1.1 }
238    
239 root 1.7 int
240     command_resistances (object *op, char *params)
241 elmex 1.1 {
242 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
243 elmex 1.1
244 root 1.73 msg << "Resistances:\n\n";
245 elmex 1.1
246 root 1.73 for (int i = 0; i < NROFATTACKS; i++)
247     if (i != ATNR_INTERNAL)
248     msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
249 elmex 1.1
250 root 1.7 /* If dragon player, let's display natural resistances */
251 root 1.82 if (op->is_dragon ())
252 root 1.73 for (object *tmp = op->inv; tmp; tmp = tmp->below)
253     if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
254     {
255     msg << "\nOf those, these are natural skin resistances:\n\n";
256    
257     for (int attack = 0; attack < NROFATTACKS; attack++)
258     if (atnr_is_dragon_enabled (attack))
259     msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
260 root 1.7
261 root 1.73 break;
262 elmex 1.1 }
263 root 1.73
264     op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
265 elmex 1.1
266 root 1.7 return 0;
267 elmex 1.1 }
268 root 1.7
269     int
270     command_title (object *op, char *params)
271 elmex 1.1 {
272 root 1.7 char buf[MAX_BUF];
273    
274     if (settings.set_title == FALSE)
275     {
276     new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
277     return 1;
278 elmex 1.1 }
279 root 1.7
280     /* dragon players cannot change titles */
281 root 1.82 if (op->is_dragon ())
282 root 1.7 {
283     new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
284     return 1;
285     }
286    
287     if (params == NULL)
288     {
289     if (op->contr->own_title[0] == '\0')
290     sprintf (buf, "Your title is '%s'.", op->contr->title);
291     else
292     sprintf (buf, "Your title is '%s'.", op->contr->own_title);
293     new_draw_info (NDI_UNIQUE, 0, op, buf);
294     return 1;
295     }
296     if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
297     {
298     if (op->contr->own_title[0] == '\0')
299     new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
300     else
301     new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
302     op->contr->own_title[0] = '\0';
303     return 1;
304     }
305    
306     if ((int) strlen (params) >= MAX_NAME)
307     {
308     new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
309     return 1;
310     }
311     strcpy (op->contr->own_title, params);
312     return 1;
313 elmex 1.1 }
314    
315 root 1.7 int
316     command_kill_pets (object *op, char *params)
317 elmex 1.1 {
318 root 1.7 objectlink *obl, *next;
319     int counter = 0, removecount = 0;
320    
321 root 1.57 if (!params)
322 root 1.7 {
323     terminate_all_pets (op);
324     new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
325     }
326     else
327     {
328     int target = atoi (params);
329    
330 root 1.57 for (obl = first_friendly_object; obl; obl = next)
331 root 1.7 {
332     object *ob = obl->ob;
333    
334     next = obl->next;
335 root 1.56
336 root 1.22 if (ob->owner == op)
337 root 1.7 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
338     {
339 root 1.71 ob->destroy ();
340 root 1.3 removecount++;
341 root 1.7 }
342 root 1.3 }
343 root 1.56
344 root 1.7 if (removecount != 0)
345     new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
346     else
347     new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
348 elmex 1.1 }
349 root 1.56
350 root 1.7 return 0;
351 elmex 1.1 }