1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
8 | it under the terms of the GNU General Public License as published by |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | (at your option) any later version. |
11 | * any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, but |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | GNU General Public License for more details. |
16 | * for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License along |
18 | along with this program; if not, write to the Free Software |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <loader.h> |
26 | #include <loader.h> |
26 | #ifndef __CEXTRACT__ |
|
|
27 | # include <sproto.h> |
27 | #include <sproto.h> |
28 | #endif |
|
|
29 | |
28 | |
30 | extern weathermap_t **weathermap; |
|
|
31 | |
|
|
32 | /* Handles misc. input request - things like hash table, malloc, maps, |
29 | /* Handles misc. input request - things like hash table, malloc, maps, etc */ |
33 | * who, etc. |
|
|
34 | */ |
|
|
35 | |
|
|
36 | void |
|
|
37 | map_info (object *op, char *search) |
|
|
38 | { |
|
|
39 | maptile *m; |
|
|
40 | char buf[MAX_BUF], map_path[MAX_BUF]; |
|
|
41 | long sec = seconds (); |
|
|
42 | |
|
|
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"); |
|
|
45 | for (m = first_map; m != NULL; m = m->next) |
|
|
46 | { |
|
|
47 | |
|
|
48 | if (search && strstr (m->path, search) == NULL) |
|
|
49 | continue; /* Skip unwanted maps */ |
|
|
50 | /* Print out the last 18 characters of the map name... */ |
|
|
51 | if (strlen (m->path) <= 18) |
|
|
52 | strcpy (map_path, m->path); |
|
|
53 | else |
|
|
54 | strcpy (map_path, m->path + strlen (m->path) - 18); |
|
|
55 | sprintf (buf, "%-18.18s %2d %2d %1d %4d %2d %02d:%02d:%02d", |
|
|
56 | map_path, m->players, players_on_map (m, FALSE), |
|
|
57 | m->in_memory, m->timeout, m->difficulty, |
|
|
58 | (MAP_WHEN_RESET (m) % 86400) / 3600, (MAP_WHEN_RESET (m) % 3600) / 60, MAP_WHEN_RESET (m) % 60); |
|
|
59 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
60 | } |
|
|
61 | } |
|
|
62 | |
|
|
63 | /* This command dumps the body information for object *op. |
|
|
64 | * it doesn't care what the params are. |
|
|
65 | * This is mostly meant as a debug command. |
|
|
66 | */ |
|
|
67 | int |
|
|
68 | command_body (object *op, char *params) |
|
|
69 | { |
|
|
70 | int i; |
|
|
71 | |
|
|
72 | /* Too hard to try and make a header that lines everything up, so just |
|
|
73 | * give a description. |
|
|
74 | */ |
|
|
75 | new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location."); |
|
|
76 | new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has."); |
|
|
77 | new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available."); |
|
|
78 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
|
|
79 | { |
|
|
80 | /* really debugging - normally body_used should not be set to anything |
|
|
81 | * if body_info isn't also set. |
|
|
82 | */ |
|
|
83 | if (op->body_info[i] || op->body_used[i]) |
|
|
84 | { |
|
|
85 | new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]); |
|
|
86 | } |
|
|
87 | } |
|
|
88 | if (!QUERY_FLAG (op, FLAG_USE_ARMOUR)) |
|
|
89 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor"); |
|
|
90 | if (!QUERY_FLAG (op, FLAG_USE_WEAPON)) |
|
|
91 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons"); |
|
|
92 | |
|
|
93 | return 1; |
|
|
94 | } |
|
|
95 | |
|
|
96 | |
30 | |
97 | int |
31 | int |
98 | command_motd (object *op, char *params) |
32 | command_motd (object *op, char *params) |
99 | { |
33 | { |
100 | display_motd (op); |
34 | display_motd (op); |
101 | return 1; |
35 | return 1; |
102 | } |
36 | } |
103 | |
37 | |
104 | int |
|
|
105 | command_bug (object *op, char *params) |
|
|
106 | { |
|
|
107 | char buf[MAX_BUF]; |
|
|
108 | |
|
|
109 | if (params == NULL) |
|
|
110 | { |
|
|
111 | new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); |
|
|
112 | return 1; |
|
|
113 | } |
|
|
114 | strcpy (buf, op->name); |
|
|
115 | strcat (buf, " bug-reports: "); |
|
|
116 | strncat (buf, ++params, MAX_BUF - strlen (buf)); |
|
|
117 | buf[MAX_BUF - 1] = '\0'; |
|
|
118 | bug_report (buf); |
|
|
119 | LOG (llevError, "%s\n", buf); |
|
|
120 | new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf); |
|
|
121 | new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!"); |
|
|
122 | return 1; |
|
|
123 | } |
|
|
124 | |
|
|
125 | /* |
|
|
126 | * Pretty much identical to current map_info, but on a bigger scale |
|
|
127 | * This function returns the name of the players current region, and |
|
|
128 | * a description of it. It is there merely for flavour text. |
|
|
129 | */ |
|
|
130 | void |
|
|
131 | current_region_info (object *op) |
|
|
132 | { |
|
|
133 | /* |
|
|
134 | * Ok I /suppose/ I should write a seperate function for this, but it isn't |
|
|
135 | * going to be /that/ slow, and won't get called much |
|
|
136 | */ |
|
|
137 | region *r = get_region_by_name (get_name_of_region_for_map (op->map)); |
|
|
138 | |
|
|
139 | if (!r) |
|
|
140 | return; |
|
|
141 | /* This should only be possible if regions are not operating on this server. */ |
|
|
142 | |
|
|
143 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r)); |
|
|
144 | } |
|
|
145 | |
|
|
146 | void |
|
|
147 | current_map_info (object *op) |
|
|
148 | { |
|
|
149 | maptile *m = op->map; |
|
|
150 | |
|
|
151 | if (!m) |
|
|
152 | return; |
|
|
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)); |
|
|
155 | |
|
|
156 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
157 | { |
|
|
158 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
159 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
|
|
160 | m->players, m->difficulty, MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m), MAP_TIMEOUT (m)); |
|
|
161 | |
|
|
162 | } |
|
|
163 | if (m->msg) |
|
|
164 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
|
|
165 | } |
|
|
166 | |
|
|
167 | #ifdef DEBUG_MALLOC_LEVEL |
38 | #ifdef DEBUG_MALLOC_LEVEL |
168 | int |
39 | int |
169 | command_malloc_verify (object *op, char *parms) |
40 | command_malloc_verify (object *op, char *parms) |
170 | { |
41 | { |
171 | extern int malloc_verify (void); |
42 | extern int malloc_verify (void); |
172 | |
43 | |
173 | if (!malloc_verify ()) |
44 | if (!malloc_verify ()) |
174 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
45 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
175 | else |
46 | else |
176 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
47 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
177 | return 1; |
48 | return 1; |
… | |
… | |
179 | #endif |
50 | #endif |
180 | |
51 | |
181 | int |
52 | int |
182 | command_whereabouts (object *op, char *params) |
53 | command_whereabouts (object *op, char *params) |
183 | { |
54 | { |
184 | |
55 | //TODO: should obviously not waste space in struct region for this. |
185 | region *reg; |
|
|
186 | player *pl; |
|
|
187 | |
|
|
188 | /* |
56 | /* |
189 | * reset the counter on the region, then use it to store the number of |
57 | * reset the counter on the region, then use it to store the number of |
190 | * players there. |
58 | * players there. |
191 | * I don't know how thread-safe this would be, I suspect not very.... |
59 | * I don't know how thread-safe this would be, I suspect not very.... |
192 | */ |
60 | */ |
193 | for (reg = first_region; reg != NULL; reg = reg->next) |
61 | for_all_regions (rgn) |
194 | { |
|
|
195 | reg->counter = 0; |
62 | rgn->counter = 0; |
196 | } |
63 | |
197 | for (pl = first_player; pl != NULL; pl = pl->next) |
64 | for_all_players (pl) |
198 | if (pl->ob->map != NULL) |
65 | if (pl->ob->map) |
199 | get_region_by_map (pl->ob->map)->counter++; |
66 | ++pl->ob->region ()->counter; |
200 | |
67 | |
201 | /* we only want to print out by places with a 'longname' field... */ |
68 | /* we only want to print out by places with a 'longname' field... */ |
202 | for (reg = first_region; reg != NULL; reg = reg->next) |
69 | for_all_regions (rgn) |
203 | { |
70 | { |
204 | if (reg->longname == NULL && reg->counter > 0) |
71 | if (!rgn->longname && rgn->counter > 0) |
205 | { |
72 | { |
206 | if (reg->parent != NULL) |
73 | if (rgn->parent) |
207 | { |
74 | { |
208 | reg->parent->counter += reg->counter; |
75 | rgn->parent->counter += rgn->counter; |
209 | reg->counter = 0; |
76 | rgn->counter = 0; |
210 | } |
77 | } |
211 | else /*uh oh, we shouldn't be here. */ |
78 | else /*uh oh, we shouldn't be here. */ |
212 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); |
79 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name); |
213 | } |
80 | } |
214 | } |
81 | } |
|
|
82 | |
215 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
83 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
216 | for (reg = first_region; reg != NULL; reg = reg->next) |
84 | |
|
|
85 | for_all_regions (rgn) |
217 | if (reg->counter > 0) |
86 | if (rgn->counter) |
218 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); |
87 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname); |
|
|
88 | |
219 | return 1; |
89 | return 1; |
220 | } |
90 | } |
221 | |
91 | |
222 | typedef struct |
92 | typedef struct |
223 | { |
93 | { |
224 | char namebuf[MAX_BUF]; |
94 | char namebuf[MAX_BUF]; |
225 | int login_order; |
95 | int login_order; |
226 | } chars_names; |
96 | } chars_names; |
227 | |
97 | |
228 | /*local functon for qsort comparison*/ |
|
|
229 | static int |
|
|
230 | name_cmp (const chars_names * c1, const chars_names * c2) |
|
|
231 | { |
|
|
232 | return strcasecmp (c1->namebuf, c2->namebuf); |
|
|
233 | } |
|
|
234 | |
|
|
235 | int |
|
|
236 | command_afk (object *op, char *params) |
|
|
237 | { |
|
|
238 | if QUERY_FLAG |
|
|
239 | (op, FLAG_AFK) |
|
|
240 | { |
|
|
241 | CLEAR_FLAG (op, FLAG_AFK); |
|
|
242 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK"); |
|
|
243 | } |
|
|
244 | else |
|
|
245 | { |
|
|
246 | SET_FLAG (op, FLAG_AFK); |
|
|
247 | new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK"); |
|
|
248 | } |
|
|
249 | return 1; |
|
|
250 | } |
|
|
251 | |
|
|
252 | int |
|
|
253 | command_mapinfo (object *op, char *params) |
|
|
254 | { |
|
|
255 | current_map_info (op); |
|
|
256 | return 1; |
|
|
257 | } |
|
|
258 | |
|
|
259 | int |
|
|
260 | command_whereami (object *op, char *params) |
|
|
261 | { |
|
|
262 | current_region_info (op); |
|
|
263 | return 1; |
|
|
264 | } |
|
|
265 | |
|
|
266 | int |
|
|
267 | command_maps (object *op, char *params) |
|
|
268 | { |
|
|
269 | map_info (op, params); |
|
|
270 | return 1; |
|
|
271 | } |
|
|
272 | |
|
|
273 | int |
98 | int |
274 | command_time (object *op, char *params) |
99 | command_time (object *op, char *params) |
275 | { |
100 | { |
276 | print_tod (op); |
101 | print_tod (op); |
277 | return 1; |
102 | return 1; |
278 | } |
103 | } |
279 | |
104 | |
280 | int |
105 | int |
281 | command_weather (object *op, char *params) |
106 | command_weather (object *op, char *params) |
282 | { |
107 | { |
|
|
108 | #if 0 |
283 | int wx, wy, temp, sky; |
109 | int wx, wy, temp, sky; |
284 | char buf[MAX_BUF]; |
110 | char buf[MAX_BUF]; |
285 | |
111 | |
286 | if (settings.dynamiclevel < 1) |
112 | if (settings.dynamiclevel < 1) |
287 | return 1; |
113 | return 1; |
… | |
… | |
403 | break; |
229 | break; |
404 | case SKY_BLIZZARD: |
230 | case SKY_BLIZZARD: |
405 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
231 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
406 | break; |
232 | break; |
407 | } |
233 | } |
408 | return 1; |
234 | #endif |
409 | } |
|
|
410 | |
|
|
411 | int |
|
|
412 | command_archs (object *op, char *params) |
|
|
413 | { |
|
|
414 | arch_info (op); |
|
|
415 | return 1; |
235 | return 1; |
416 | } |
236 | } |
417 | |
237 | |
418 | int |
238 | int |
419 | command_hiscore (object *op, char *params) |
239 | command_hiscore (object *op, char *params) |
… | |
… | |
432 | { |
252 | { |
433 | sprintf (buf, "Global debug level is %d.", settings.debug); |
253 | sprintf (buf, "Global debug level is %d.", settings.debug); |
434 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
254 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
435 | return 1; |
255 | return 1; |
436 | } |
256 | } |
437 | if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) |
257 | |
438 | { |
258 | settings.debug = i; |
439 | new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); |
259 | |
440 | return 1; |
|
|
441 | } |
|
|
442 | settings.debug = (enum LogLevel) FABS (i); |
|
|
443 | sprintf (buf, "Set debug level to %d.", i); |
260 | sprintf (buf, "Set debug level to %d.", i); |
444 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
261 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
445 | return 1; |
262 | return 1; |
446 | } |
263 | } |
447 | |
264 | |
… | |
… | |
453 | int |
270 | int |
454 | command_dumpbelow (object *op, char *params) |
271 | command_dumpbelow (object *op, char *params) |
455 | { |
272 | { |
456 | if (op && op->below) |
273 | if (op && op->below) |
457 | { |
274 | { |
458 | dump_object (op->below); |
275 | char *dump = dump_object (op->below); |
459 | new_draw_info (NDI_UNIQUE, 0, op, errmsg); |
276 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
|
|
277 | free (dump); |
460 | /* Let's push that item on the dm's stack */ |
278 | /* Let's push that item on the dm's stack */ |
461 | dm_stack_push (op->contr, op->below->count); |
279 | dm_stack_push (op->contr, op->below->count); |
462 | } |
280 | } |
463 | return 0; |
281 | return 0; |
464 | } |
282 | } |
465 | |
283 | |
466 | int |
284 | int |
467 | command_dumpallobjects (object *op, char *params) |
|
|
468 | { |
|
|
469 | dump_all_objects (); |
|
|
470 | return 0; |
|
|
471 | } |
|
|
472 | |
|
|
473 | int |
|
|
474 | command_dumpfriendlyobjects (object *op, char *params) |
285 | command_dumpfriendlyobjects (object *op, char *params) |
475 | { |
286 | { |
476 | dump_friendly_objects (); |
287 | dump_friendly_objects (); |
477 | return 0; |
|
|
478 | } |
|
|
479 | |
|
|
480 | int |
|
|
481 | command_dumpallarchetypes (object *op, char *params) |
|
|
482 | { |
|
|
483 | dump_all_archetypes (); |
|
|
484 | return 0; |
|
|
485 | } |
|
|
486 | |
|
|
487 | int |
|
|
488 | command_dumpmap (object *op, char *params) |
|
|
489 | { |
|
|
490 | if (op) |
|
|
491 | dump_map (op->map); |
|
|
492 | return 0; |
|
|
493 | } |
|
|
494 | |
|
|
495 | int |
|
|
496 | command_dumpallmaps (object *op, char *params) |
|
|
497 | { |
|
|
498 | dump_all_maps (); |
|
|
499 | return 0; |
288 | return 0; |
500 | } |
289 | } |
501 | |
290 | |
502 | int |
291 | int |
503 | command_printlos (object *op, char *params) |
292 | command_printlos (object *op, char *params) |
… | |
… | |
512 | command_version (object *op, char *params) |
301 | command_version (object *op, char *params) |
513 | { |
302 | { |
514 | version (op); |
303 | version (op); |
515 | return 0; |
304 | return 0; |
516 | } |
305 | } |
517 | |
|
|
518 | |
306 | |
519 | #ifndef BUG_LOG |
307 | #ifndef BUG_LOG |
520 | # define BUG_LOG "bug_log" |
308 | # define BUG_LOG "bug_log" |
521 | #endif |
309 | #endif |
522 | void |
310 | void |
… | |
… | |
533 | { |
321 | { |
534 | LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); |
322 | LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); |
535 | } |
323 | } |
536 | } |
324 | } |
537 | |
325 | |
538 | int |
|
|
539 | command_output_sync (object *op, char *params) |
|
|
540 | { |
|
|
541 | int val; |
|
|
542 | |
|
|
543 | if (!params) |
|
|
544 | { |
|
|
545 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync); |
|
|
546 | return 1; |
|
|
547 | } |
|
|
548 | val = atoi (params); |
|
|
549 | if (val > 0) |
|
|
550 | { |
|
|
551 | op->contr->outputs_sync = val; |
|
|
552 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync); |
|
|
553 | } |
|
|
554 | else |
|
|
555 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync."); |
|
|
556 | |
|
|
557 | return 1; |
|
|
558 | } |
|
|
559 | |
|
|
560 | int |
|
|
561 | command_output_count (object *op, char *params) |
|
|
562 | { |
|
|
563 | int val; |
|
|
564 | |
|
|
565 | if (!params) |
|
|
566 | { |
|
|
567 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count); |
|
|
568 | return 1; |
|
|
569 | } |
|
|
570 | val = atoi (params); |
|
|
571 | if (val > 0) |
|
|
572 | { |
|
|
573 | op->contr->outputs_count = val; |
|
|
574 | new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count); |
|
|
575 | } |
|
|
576 | else |
|
|
577 | new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count."); |
|
|
578 | |
|
|
579 | return 1; |
|
|
580 | } |
|
|
581 | |
|
|
582 | int |
|
|
583 | command_listen (object *op, char *params) |
|
|
584 | { |
|
|
585 | int i; |
|
|
586 | |
|
|
587 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
588 | { |
|
|
589 | new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening); |
|
|
590 | return 1; |
|
|
591 | } |
|
|
592 | op->contr->listening = (char) i; |
|
|
593 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i); |
|
|
594 | return 1; |
|
|
595 | } |
|
|
596 | |
|
|
597 | /* Prints out some useful information for the character. Everything we print |
326 | /* Prints out some useful information for the character. Everything we print |
598 | * out can be determined by the docs, so we aren't revealing anything extra - |
327 | * out can be determined by the docs, so we aren't revealing anything extra - |
599 | * rather, we are making it convenient to find the values. params have |
328 | * rather, we are making it convenient to find the values. params have |
600 | * no meaning here. |
329 | * no meaning here. |
601 | */ |
330 | */ |
602 | int |
331 | int |
603 | command_statistics (object *pl, char *params) |
332 | command_statistics (object *pl, char *params) |
604 | { |
333 | { |
605 | if (!pl->contr) |
334 | if (!pl->contr) |
606 | return 1; |
335 | return 1; |
607 | #ifndef WIN32 |
|
|
608 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp); |
|
|
609 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul)); |
|
|
610 | #else |
|
|
611 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); |
336 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp); |
612 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); |
337 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul)); |
613 | #endif |
|
|
614 | new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); |
338 | new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); |
615 | |
339 | |
616 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", |
340 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", |
617 | pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); |
341 | pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); |
618 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", |
342 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", |
… | |
… | |
635 | |
359 | |
636 | int |
360 | int |
637 | command_fix_me (object *op, char *params) |
361 | command_fix_me (object *op, char *params) |
638 | { |
362 | { |
639 | sum_weight (op); |
363 | sum_weight (op); |
640 | fix_player (op); |
364 | op->update_stats (); |
641 | return 1; |
365 | new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
642 | } |
|
|
643 | |
366 | |
644 | int |
|
|
645 | command_players (object *op, char *paramss) |
|
|
646 | { |
|
|
647 | char buf[MAX_BUF]; |
|
|
648 | char *t; |
|
|
649 | DIR *Dir; |
|
|
650 | |
|
|
651 | sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir); |
|
|
652 | t = buf + strlen (buf); |
|
|
653 | if ((Dir = opendir (buf)) != NULL) |
|
|
654 | { |
|
|
655 | const struct dirent *Entry; |
|
|
656 | |
|
|
657 | while ((Entry = readdir (Dir)) != NULL) |
|
|
658 | { |
|
|
659 | /* skip '.' , '..' */ |
|
|
660 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
|
|
661 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
|
|
662 | { |
|
|
663 | struct stat Stat; |
|
|
664 | |
|
|
665 | strcpy (t, Entry->d_name); |
|
|
666 | if (stat (buf, &Stat) == 0) |
|
|
667 | { |
|
|
668 | /* This was not posix compatible |
|
|
669 | * if ((Stat.st_mode & S_IFMT)==S_IFDIR) { |
|
|
670 | */ |
|
|
671 | if (S_ISDIR (Stat.st_mode)) |
|
|
672 | { |
|
|
673 | char buf2[MAX_BUF]; |
|
|
674 | struct tm *tm = localtime (&Stat.st_mtime); |
|
|
675 | |
|
|
676 | sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d", |
|
|
677 | Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
|
678 | new_draw_info (NDI_UNIQUE, 0, op, buf2); |
|
|
679 | } |
|
|
680 | } |
|
|
681 | } |
|
|
682 | } |
|
|
683 | } |
|
|
684 | closedir (Dir); |
|
|
685 | return 0; |
367 | return 1; |
686 | } |
368 | } |
687 | |
|
|
688 | |
|
|
689 | |
369 | |
690 | int |
370 | int |
691 | command_logs (object *op, char *params) |
371 | command_logs (object *op, char *params) |
692 | { |
372 | { |
693 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
373 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
694 | |
374 | |
695 | return 1; |
|
|
696 | } |
|
|
697 | |
|
|
698 | int |
|
|
699 | command_applymode (object *op, char *params) |
|
|
700 | { |
|
|
701 | unapplymode unapply = op->contr->unapply; |
|
|
702 | static const char *const types[] = { "nochoice", "never", "always" }; |
|
|
703 | |
|
|
704 | if (!params) |
|
|
705 | { |
|
|
706 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]); |
|
|
707 | return 1; |
|
|
708 | } |
|
|
709 | |
|
|
710 | if (!strcmp (params, "nochoice")) |
|
|
711 | op->contr->unapply = unapply_nochoice; |
|
|
712 | else if (!strcmp (params, "never")) |
|
|
713 | op->contr->unapply = unapply_never; |
|
|
714 | else if (!strcmp (params, "always")) |
|
|
715 | op->contr->unapply = unapply_always; |
|
|
716 | else |
|
|
717 | { |
|
|
718 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
|
|
719 | return 0; |
|
|
720 | } |
|
|
721 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
|
|
722 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
|
|
723 | return 1; |
375 | return 1; |
724 | } |
376 | } |
725 | |
377 | |
726 | int |
378 | int |
727 | command_bowmode (object *op, char *params) |
379 | command_bowmode (object *op, char *params) |
… | |
… | |
747 | found++; |
399 | found++; |
748 | op->contr->bowtype = (bowtype_t) i; |
400 | op->contr->bowtype = (bowtype_t) i; |
749 | break; |
401 | break; |
750 | } |
402 | } |
751 | } |
403 | } |
|
|
404 | |
752 | if (!found) |
405 | if (!found) |
753 | { |
406 | { |
754 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
407 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
755 | for (i = 0; i <= bow_bestarrow; i++) |
408 | for (i = 0; i <= bow_bestarrow; i++) |
756 | { |
409 | { |
… | |
… | |
762 | strcat (buf, "."); |
415 | strcat (buf, "."); |
763 | } |
416 | } |
764 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
417 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
765 | return 0; |
418 | return 0; |
766 | } |
419 | } |
|
|
420 | |
767 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
421 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
768 | return 1; |
|
|
769 | } |
|
|
770 | |
|
|
771 | int |
|
|
772 | command_petmode (object *op, char *params) |
|
|
773 | { |
|
|
774 | petmode_t oldtype = op->contr->petmode; |
|
|
775 | static const char *const types[] = { "normal", "sad", "defend", "arena" }; |
|
|
776 | |
|
|
777 | if (!params) |
|
|
778 | { |
|
|
779 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]); |
|
|
780 | return 1; |
|
|
781 | } |
|
|
782 | |
|
|
783 | if (!strcmp (params, "normal")) |
|
|
784 | op->contr->petmode = pet_normal; |
|
|
785 | else if (!strcmp (params, "sad")) |
|
|
786 | op->contr->petmode = pet_sad; |
|
|
787 | else if (!strcmp (params, "defend")) |
|
|
788 | op->contr->petmode = pet_defend; |
|
|
789 | else if (!strcmp (params, "arena")) |
|
|
790 | op->contr->petmode = pet_arena; |
|
|
791 | else |
|
|
792 | { |
|
|
793 | new_draw_info_format (NDI_UNIQUE, 0, op, |
|
|
794 | "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params); |
|
|
795 | return 0; |
|
|
796 | } |
|
|
797 | new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]); |
|
|
798 | return 1; |
422 | return 1; |
799 | } |
423 | } |
800 | |
424 | |
801 | int |
425 | int |
802 | command_showpets (object *op, char *params) |
426 | command_showpets (object *op, char *params) |
… | |
… | |
810 | for (obl = first_friendly_object; obl != NULL; obl = next) |
434 | for (obl = first_friendly_object; obl != NULL; obl = next) |
811 | { |
435 | { |
812 | object *ob = obl->ob; |
436 | object *ob = obl->ob; |
813 | |
437 | |
814 | next = obl->next; |
438 | next = obl->next; |
815 | if (get_owner (ob) == op) |
439 | if (ob->owner == op) |
816 | { |
440 | { |
817 | if (target == 0) |
441 | if (target == 0) |
818 | { |
442 | { |
819 | if (counter == 0) |
443 | if (counter == 0) |
820 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
444 | new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); |
… | |
… | |
843 | new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); |
467 | new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); |
844 | return 0; |
468 | return 0; |
845 | } |
469 | } |
846 | |
470 | |
847 | int |
471 | int |
848 | command_usekeys (object *op, char *params) |
|
|
849 | { |
|
|
850 | usekeytype oldtype = op->contr->usekeys; |
|
|
851 | static const char *const types[] = { "inventory", "keyrings", "containers" }; |
|
|
852 | |
|
|
853 | if (!params) |
|
|
854 | { |
|
|
855 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]); |
|
|
856 | return 1; |
|
|
857 | } |
|
|
858 | |
|
|
859 | if (!strcmp (params, "inventory")) |
|
|
860 | op->contr->usekeys = key_inventory; |
|
|
861 | else if (!strcmp (params, "keyrings")) |
|
|
862 | op->contr->usekeys = keyrings; |
|
|
863 | else if (!strcmp (params, "containers")) |
|
|
864 | op->contr->usekeys = containers; |
|
|
865 | else |
|
|
866 | { |
|
|
867 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params); |
|
|
868 | return 0; |
|
|
869 | } |
|
|
870 | new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]); |
|
|
871 | return 1; |
|
|
872 | } |
|
|
873 | |
|
|
874 | int |
|
|
875 | command_resistances (object *op, char *params) |
472 | command_resistances (object *op, char *params) |
876 | { |
473 | { |
877 | int i; |
474 | int i; |
878 | |
475 | |
879 | if (!op) |
476 | if (!op) |
… | |
… | |
893 | int attack; |
490 | int attack; |
894 | object *tmp; |
491 | object *tmp; |
895 | |
492 | |
896 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
493 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
897 | { |
494 | { |
898 | if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) |
495 | if ((tmp->type == FORCE) && (strcmp (tmp->arch->archname, "dragon_skin_force") == 0)) |
899 | { |
496 | { |
900 | new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); |
497 | new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); |
901 | for (attack = 0; attack < NROFATTACKS; attack++) |
498 | for (attack = 0; attack < NROFATTACKS; attack++) |
902 | { |
499 | { |
903 | if (atnr_is_dragon_enabled (attack)) |
500 | if (atnr_is_dragon_enabled (attack)) |
… | |
… | |
915 | |
512 | |
916 | /* |
513 | /* |
917 | * Actual commands. |
514 | * Actual commands. |
918 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
515 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
919 | */ |
516 | */ |
920 | |
|
|
921 | |
|
|
922 | static void |
|
|
923 | help_topics (object *op, int what) |
|
|
924 | { |
|
|
925 | DIR *dirp; |
|
|
926 | struct dirent *de; |
|
|
927 | char filename[MAX_BUF], line[80]; |
|
|
928 | int namelen, linelen = 0; |
|
|
929 | |
|
|
930 | switch (what) |
|
|
931 | { |
|
|
932 | case 1: |
|
|
933 | sprintf (filename, "%s/wizhelp", settings.datadir); |
|
|
934 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
935 | break; |
|
|
936 | case 3: |
|
|
937 | sprintf (filename, "%s/mischelp", settings.datadir); |
|
|
938 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
|
|
939 | break; |
|
|
940 | default: |
|
|
941 | sprintf (filename, "%s/help", settings.datadir); |
|
|
942 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
943 | break; |
|
|
944 | } |
|
|
945 | if (!(dirp = opendir (filename))) |
|
|
946 | return; |
|
|
947 | |
|
|
948 | line[0] = '\0'; |
|
|
949 | for (de = readdir (dirp); de; de = readdir (dirp)) |
|
|
950 | { |
|
|
951 | namelen = NAMLEN (de); |
|
|
952 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
|
|
953 | continue; |
|
|
954 | linelen += namelen + 1; |
|
|
955 | if (linelen > 42) |
|
|
956 | { |
|
|
957 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
958 | sprintf (line, " %s", de->d_name); |
|
|
959 | linelen = namelen + 1; |
|
|
960 | continue; |
|
|
961 | } |
|
|
962 | strcat (line, " "); |
|
|
963 | strcat (line, de->d_name); |
|
|
964 | } |
|
|
965 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
966 | closedir (dirp); |
|
|
967 | } |
|
|
968 | |
|
|
969 | static void |
|
|
970 | show_commands (object *op, int what) |
|
|
971 | { |
|
|
972 | char line[80]; |
|
|
973 | int i, size, namelen, linelen = 0; |
|
|
974 | CommArray_s *ap; |
|
|
975 | extern CommArray_s Commands[], WizCommands[]; |
|
|
976 | extern const int CommandsSize, WizCommandsSize; |
|
|
977 | |
|
|
978 | switch (what) |
|
|
979 | { |
|
|
980 | case 1: |
|
|
981 | ap = WizCommands; |
|
|
982 | size = WizCommandsSize; |
|
|
983 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
984 | break; |
|
|
985 | case 2: |
|
|
986 | ap = CommunicationCommands; |
|
|
987 | size = CommunicationCommandSize; |
|
|
988 | new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:"); |
|
|
989 | break; |
|
|
990 | default: |
|
|
991 | ap = Commands; |
|
|
992 | size = CommandsSize; |
|
|
993 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
994 | break; |
|
|
995 | } |
|
|
996 | |
|
|
997 | line[0] = '\0'; |
|
|
998 | for (i = 0; i < size; i++) |
|
|
999 | { |
|
|
1000 | namelen = strlen (ap[i].name); |
|
|
1001 | linelen += namelen + 1; |
|
|
1002 | if (linelen > 42) |
|
|
1003 | { |
|
|
1004 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1005 | sprintf (line, " %s", ap[i].name); |
|
|
1006 | linelen = namelen + 1; |
|
|
1007 | continue; |
|
|
1008 | } |
|
|
1009 | strcat (line, " "); |
|
|
1010 | strcat (line, ap[i].name); |
|
|
1011 | } |
|
|
1012 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1013 | } |
|
|
1014 | |
|
|
1015 | |
|
|
1016 | int |
|
|
1017 | command_help (object *op, char *params) |
|
|
1018 | { |
|
|
1019 | struct stat st; |
|
|
1020 | FILE *fp; |
|
|
1021 | char filename[MAX_BUF], line[MAX_BUF]; |
|
|
1022 | int len; |
|
|
1023 | |
|
|
1024 | if (op != NULL) |
|
|
1025 | clear_win_info (op); |
|
|
1026 | |
|
|
1027 | /* |
|
|
1028 | * Main help page? |
|
|
1029 | */ |
|
|
1030 | if (!params) |
|
|
1031 | { |
|
|
1032 | sprintf (filename, "%s/def_help", settings.datadir); |
|
|
1033 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1034 | { |
|
|
1035 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
1036 | return 0; |
|
|
1037 | } |
|
|
1038 | while (fgets (line, MAX_BUF, fp)) |
|
|
1039 | { |
|
|
1040 | line[MAX_BUF - 1] = '\0'; |
|
|
1041 | len = strlen (line) - 1; |
|
|
1042 | if (line[len] == '\n') |
|
|
1043 | line[len] = '\0'; |
|
|
1044 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1045 | } |
|
|
1046 | fclose (fp); |
|
|
1047 | return 0; |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | /* |
|
|
1051 | * Topics list |
|
|
1052 | */ |
|
|
1053 | if (!strcmp (params, "topics")) |
|
|
1054 | { |
|
|
1055 | help_topics (op, 3); |
|
|
1056 | help_topics (op, 0); |
|
|
1057 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
1058 | help_topics (op, 1); |
|
|
1059 | return 0; |
|
|
1060 | } |
|
|
1061 | |
|
|
1062 | /* |
|
|
1063 | * Commands list |
|
|
1064 | */ |
|
|
1065 | if (!strcmp (params, "commands")) |
|
|
1066 | { |
|
|
1067 | show_commands (op, 0); |
|
|
1068 | show_commands (op, 2); /* show comm commands */ |
|
|
1069 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
1070 | show_commands (op, 1); |
|
|
1071 | return 0; |
|
|
1072 | } |
|
|
1073 | |
|
|
1074 | /* |
|
|
1075 | * User wants info about command |
|
|
1076 | */ |
|
|
1077 | if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/')) |
|
|
1078 | { |
|
|
1079 | sprintf (line, "Illegal characters in '%s'", params); |
|
|
1080 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1081 | return 0; |
|
|
1082 | } |
|
|
1083 | |
|
|
1084 | sprintf (filename, "%s/mischelp/%s", settings.datadir, params); |
|
|
1085 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
1086 | { |
|
|
1087 | if (op) |
|
|
1088 | { |
|
|
1089 | sprintf (filename, "%s/help/%s", settings.datadir, params); |
|
|
1090 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
1091 | { |
|
|
1092 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
1093 | { |
|
|
1094 | sprintf (filename, "%s/wizhelp/%s", settings.datadir, params); |
|
|
1095 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
1096 | goto nohelp; |
|
|
1097 | } |
|
|
1098 | else |
|
|
1099 | goto nohelp; |
|
|
1100 | } |
|
|
1101 | } |
|
|
1102 | } |
|
|
1103 | |
|
|
1104 | /* |
|
|
1105 | * Found that. Just cat it to screen. |
|
|
1106 | */ |
|
|
1107 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
1108 | { |
|
|
1109 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
1110 | return 0; |
|
|
1111 | } |
|
|
1112 | sprintf (line, "Help about '%s'", params); |
|
|
1113 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1114 | while (fgets (line, MAX_BUF, fp)) |
|
|
1115 | { |
|
|
1116 | line[MAX_BUF - 1] = '\0'; |
|
|
1117 | len = strlen (line) - 1; |
|
|
1118 | if (line[len] == '\n') |
|
|
1119 | line[len] = '\0'; |
|
|
1120 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1121 | } |
|
|
1122 | fclose (fp); |
|
|
1123 | return 0; |
|
|
1124 | |
|
|
1125 | /* |
|
|
1126 | * No_help -escape |
|
|
1127 | */ |
|
|
1128 | nohelp: |
|
|
1129 | sprintf (line, "No help available on '%s'", params); |
|
|
1130 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
1131 | return 0; |
|
|
1132 | } |
|
|
1133 | |
|
|
1134 | |
517 | |
1135 | int |
518 | int |
1136 | onoff_value (const char *line) |
519 | onoff_value (const char *line) |
1137 | { |
520 | { |
1138 | int i; |
521 | int i; |
… | |
… | |
1161 | return 0; |
544 | return 0; |
1162 | } |
545 | } |
1163 | } |
546 | } |
1164 | |
547 | |
1165 | int |
548 | int |
1166 | command_quit (object *op, char *params) |
|
|
1167 | { |
|
|
1168 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1169 | "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit."); |
|
|
1170 | return 1; |
|
|
1171 | } |
|
|
1172 | |
|
|
1173 | int |
|
|
1174 | command_real_quit (object *op, char *params) |
|
|
1175 | { |
|
|
1176 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):"); |
|
|
1177 | |
|
|
1178 | op->contr->state = ST_CONFIRM_QUIT; |
|
|
1179 | return 1; |
|
|
1180 | } |
|
|
1181 | |
|
|
1182 | /* |
|
|
1183 | * don't allow people to exit explore mode. It otherwise becomes |
|
|
1184 | * really easy to abuse this. |
|
|
1185 | */ |
|
|
1186 | int |
|
|
1187 | command_explore (object *op, char *params) |
|
|
1188 | { |
|
|
1189 | if (settings.explore_mode == FALSE) |
|
|
1190 | return 1; |
|
|
1191 | /* |
|
|
1192 | * I guess this is the best way to see if we are solo or not. Actually, |
|
|
1193 | * are there any cases when first_player->next==NULL and we are not solo? |
|
|
1194 | */ |
|
|
1195 | if ((first_player != op->contr) || (first_player->next != NULL)) |
|
|
1196 | { |
|
|
1197 | new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party"); |
|
|
1198 | } |
|
|
1199 | else if (op->contr->explore) |
|
|
1200 | new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode"); |
|
|
1201 | else |
|
|
1202 | { |
|
|
1203 | op->contr->explore = 1; |
|
|
1204 | new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode"); |
|
|
1205 | } |
|
|
1206 | return 1; |
|
|
1207 | } |
|
|
1208 | |
|
|
1209 | int |
|
|
1210 | command_sound (object *op, char *params) |
|
|
1211 | { |
|
|
1212 | if (op->contr->socket.sound) |
|
|
1213 | { |
|
|
1214 | op->contr->socket.sound = 0; |
|
|
1215 | new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden..."); |
|
|
1216 | } |
|
|
1217 | else |
|
|
1218 | { |
|
|
1219 | op->contr->socket.sound = 1; |
|
|
1220 | new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); |
|
|
1221 | } |
|
|
1222 | return 1; |
|
|
1223 | } |
|
|
1224 | |
|
|
1225 | /* Perhaps these should be in player.c, but that file is |
|
|
1226 | * already a bit big. |
|
|
1227 | */ |
|
|
1228 | |
|
|
1229 | void |
|
|
1230 | receive_player_name (object *op, char k) |
|
|
1231 | { |
|
|
1232 | |
|
|
1233 | if (!check_name (op->contr, op->contr->write_buf + 1)) |
|
|
1234 | { |
|
|
1235 | get_name (op); |
|
|
1236 | return; |
|
|
1237 | } |
|
|
1238 | op->name = op->contr->write_buf + 1; |
|
|
1239 | op->name_pl = op->contr->write_buf + 1; |
|
|
1240 | new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf); |
|
|
1241 | op->contr->name_changed = 1; |
|
|
1242 | get_password (op); |
|
|
1243 | } |
|
|
1244 | |
|
|
1245 | void |
|
|
1246 | receive_player_password (object *op, char k) |
|
|
1247 | { |
|
|
1248 | |
|
|
1249 | unsigned int pwd_len = strlen (op->contr->write_buf); |
|
|
1250 | |
|
|
1251 | if (pwd_len <= 1 || pwd_len > 17) |
|
|
1252 | { |
|
|
1253 | get_name (op); |
|
|
1254 | return; |
|
|
1255 | } |
|
|
1256 | new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */ |
|
|
1257 | |
|
|
1258 | if (checkbanned (op->name, op->contr->socket.host)) |
|
|
1259 | { |
|
|
1260 | LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host); |
|
|
1261 | new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play."); |
|
|
1262 | get_name (op); |
|
|
1263 | return; |
|
|
1264 | } |
|
|
1265 | |
|
|
1266 | if (op->contr->state == ST_CONFIRM_PASSWORD) |
|
|
1267 | { |
|
|
1268 | if (!check_password (op->contr->write_buf + 1, op->contr->password)) |
|
|
1269 | { |
|
|
1270 | new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match."); |
|
|
1271 | get_name (op); |
|
|
1272 | return; |
|
|
1273 | } |
|
|
1274 | clear_win_info (op); |
|
|
1275 | display_motd (op); |
|
|
1276 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1277 | new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!"); |
|
|
1278 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
1279 | Roll_Again (op); |
|
|
1280 | op->contr->state = ST_ROLL_STAT; |
|
|
1281 | return; |
|
|
1282 | } |
|
|
1283 | strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL)); |
|
|
1284 | op->contr->state = ST_ROLL_STAT; |
|
|
1285 | check_login (op); |
|
|
1286 | return; |
|
|
1287 | } |
|
|
1288 | |
|
|
1289 | |
|
|
1290 | int |
|
|
1291 | explore_mode (void) |
|
|
1292 | { |
|
|
1293 | player *pl; |
|
|
1294 | |
|
|
1295 | if (settings.explore_mode == TRUE) |
|
|
1296 | { |
|
|
1297 | for (pl = first_player; pl != (player *) NULL; pl = pl->next) |
|
|
1298 | if (pl->explore) |
|
|
1299 | return 1; |
|
|
1300 | } |
|
|
1301 | return 0; |
|
|
1302 | } |
|
|
1303 | |
|
|
1304 | |
|
|
1305 | int |
|
|
1306 | command_title (object *op, char *params) |
549 | command_title (object *op, char *params) |
1307 | { |
550 | { |
1308 | char buf[MAX_BUF]; |
551 | char buf[MAX_BUF]; |
1309 | |
552 | |
1310 | if (settings.set_title == FALSE) |
553 | if (settings.set_title == FALSE) |
… | |
… | |
1347 | strcpy (op->contr->own_title, params); |
590 | strcpy (op->contr->own_title, params); |
1348 | return 1; |
591 | return 1; |
1349 | } |
592 | } |
1350 | |
593 | |
1351 | int |
594 | int |
1352 | command_save (object *op, char *params) |
|
|
1353 | { |
|
|
1354 | // if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) { |
|
|
1355 | // new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground"); |
|
|
1356 | // } else |
|
|
1357 | if (!op->stats.exp) |
|
|
1358 | { |
|
|
1359 | new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet."); |
|
|
1360 | } |
|
|
1361 | else |
|
|
1362 | { |
|
|
1363 | if (save_player (op, 1)) |
|
|
1364 | new_draw_info (NDI_UNIQUE, 0, op, "You have been saved."); |
|
|
1365 | else |
|
|
1366 | new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!"); |
|
|
1367 | } |
|
|
1368 | return 1; |
|
|
1369 | } |
|
|
1370 | |
|
|
1371 | |
|
|
1372 | int |
|
|
1373 | command_peaceful (object *op, char *params) |
|
|
1374 | { |
|
|
1375 | new_draw_info (NDI_UNIQUE, 0, op, |
|
|
1376 | "You cannot change your peaceful setting with this command." |
|
|
1377 | " Please speak to the priest in the temple of Gorokh" |
|
|
1378 | " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again."); |
|
|
1379 | |
|
|
1380 | /* |
|
|
1381 | if((op->contr->peaceful=!op->contr->peaceful)) |
|
|
1382 | new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players."); |
|
|
1383 | else |
|
|
1384 | new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players."); |
|
|
1385 | */ |
|
|
1386 | return 1; |
|
|
1387 | } |
|
|
1388 | |
|
|
1389 | |
|
|
1390 | |
|
|
1391 | int |
|
|
1392 | command_wimpy (object *op, char *params) |
|
|
1393 | { |
|
|
1394 | int i; |
|
|
1395 | char buf[MAX_BUF]; |
|
|
1396 | |
|
|
1397 | if (params == NULL || !sscanf (params, "%d", &i)) |
|
|
1398 | { |
|
|
1399 | sprintf (buf, "Your current wimpy level is %d.", op->run_away); |
|
|
1400 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1401 | return 1; |
|
|
1402 | } |
|
|
1403 | sprintf (buf, "Your new wimpy level is %d.", i); |
|
|
1404 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
1405 | op->run_away = i; |
|
|
1406 | return 1; |
|
|
1407 | } |
|
|
1408 | |
|
|
1409 | |
|
|
1410 | int |
|
|
1411 | command_brace (object *op, char *params) |
|
|
1412 | { |
|
|
1413 | if (!params) |
|
|
1414 | op->contr->braced = !op->contr->braced; |
|
|
1415 | else |
|
|
1416 | op->contr->braced = onoff_value (params); |
|
|
1417 | |
|
|
1418 | if (op->contr->braced) |
|
|
1419 | new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); |
|
|
1420 | else |
|
|
1421 | new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); |
|
|
1422 | |
|
|
1423 | fix_player (op); |
|
|
1424 | return 0; |
|
|
1425 | } |
|
|
1426 | |
|
|
1427 | int |
|
|
1428 | command_style_map_info (object *op, char *params) |
|
|
1429 | { |
|
|
1430 | extern maptile *styles; |
|
|
1431 | maptile *mp; |
|
|
1432 | int maps_used = 0, mapmem = 0, objects_used = 0, x, y; |
|
|
1433 | object *tmp; |
|
|
1434 | |
|
|
1435 | for (mp = styles; mp != NULL; mp = mp->next) |
|
|
1436 | { |
|
|
1437 | maps_used++; |
|
|
1438 | mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile); |
|
|
1439 | for (x = 0; x < MAP_WIDTH (mp); x++) |
|
|
1440 | { |
|
|
1441 | for (y = 0; y < MAP_HEIGHT (mp); y++) |
|
|
1442 | { |
|
|
1443 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1444 | objects_used++; |
|
|
1445 | } |
|
|
1446 | } |
|
|
1447 | } |
|
|
1448 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used); |
|
|
1449 | new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not"); |
|
|
1450 | new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem); |
|
|
1451 | new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used); |
|
|
1452 | new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object)); |
|
|
1453 | return 0; |
|
|
1454 | } |
|
|
1455 | |
|
|
1456 | int |
|
|
1457 | command_kill_pets (object *op, char *params) |
595 | command_kill_pets (object *op, char *params) |
1458 | { |
596 | { |
1459 | objectlink *obl, *next; |
597 | objectlink *obl, *next; |
1460 | int counter = 0, removecount = 0; |
598 | int counter = 0, removecount = 0; |
1461 | |
599 | |
1462 | if (params == NULL) |
600 | if (!params) |
1463 | { |
601 | { |
1464 | terminate_all_pets (op); |
602 | terminate_all_pets (op); |
1465 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
603 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
1466 | } |
604 | } |
1467 | else |
605 | else |
1468 | { |
606 | { |
1469 | int target = atoi (params); |
607 | int target = atoi (params); |
1470 | |
608 | |
1471 | for (obl = first_friendly_object; obl != NULL; obl = next) |
609 | for (obl = first_friendly_object; obl; obl = next) |
1472 | { |
610 | { |
1473 | object *ob = obl->ob; |
611 | object *ob = obl->ob; |
1474 | |
612 | |
1475 | next = obl->next; |
613 | next = obl->next; |
|
|
614 | |
1476 | if (get_owner (ob) == op) |
615 | if (ob->owner == op) |
1477 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
616 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
1478 | { |
617 | { |
1479 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
1480 | remove_ob (ob); |
|
|
1481 | remove_friendly_object (ob); |
|
|
1482 | free_object (ob); |
618 | ob->destroy (); |
1483 | removecount++; |
619 | removecount++; |
1484 | } |
620 | } |
1485 | } |
621 | } |
|
|
622 | |
1486 | if (removecount != 0) |
623 | if (removecount != 0) |
1487 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
624 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
1488 | else |
625 | else |
1489 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
626 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
1490 | } |
627 | } |
|
|
628 | |
1491 | return 0; |
629 | return 0; |
1492 | } |
630 | } |