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.31 by root, Wed Dec 27 09:28:02 2006 UTC vs.
Revision 1.44 by root, Thu Feb 15 04:04:22 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License 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
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <loader.h> 26#include <loader.h>
26#include <sproto.h> 27#include <sproto.h>
27 28
28#include <dirent.h>
29
30extern 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,
33 * who, etc. 30 * who, etc.
34 */ 31 */
35
36void
37map_info (object *op, char *search)
38{
39 maptile *m;
40 char buf[MAX_BUF], map_path[MAX_BUF];
41 long sec = time (0);
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
46 for_all_maps (m)
47 {
48 if (search && !strstr (m->path, search))
49 continue; /* Skip unwanted maps */
50
51 /* Print out the last 18 characters of the map name... */
52 if (strlen (m->path) <= 18)
53 strcpy (map_path, m->path);
54 else
55 strcpy (map_path, m->path + strlen (m->path) - 18);
56
57 sprintf (buf, "%-18.18s %2d %2d %1d %4d %2d %02d:%02d:%02d",
58 map_path, m->players, players_on_map (m, FALSE),
59 m->in_memory, m->timeout, m->difficulty,
60 (m->reset_time % 86400) / 3600, (m->reset_time % 3600) / 60, m->reset_time % 60);
61 new_draw_info (NDI_UNIQUE, 0, op, buf);
62 }
63}
64 32
65/* This command dumps the body information for object *op. 33/* This command dumps the body information for object *op.
66 * it doesn't care what the params are. 34 * it doesn't care what the params are.
67 * This is mostly meant as a debug command. 35 * This is mostly meant as a debug command.
68 */ 36 */
111 if (params == NULL) 79 if (params == NULL)
112 { 80 {
113 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?"); 81 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
114 return 1; 82 return 1;
115 } 83 }
116 strcpy (buf, op->name); 84 assign (buf, op->name);
117 strcat (buf, " bug-reports: "); 85 strcat (buf, " bug-reports: ");
118 strncat (buf, ++params, MAX_BUF - strlen (buf)); 86 strncat (buf, ++params, MAX_BUF - strlen (buf));
119 buf[MAX_BUF - 1] = '\0'; 87 buf[MAX_BUF - 1] = '\0';
120 bug_report (buf); 88 bug_report (buf);
121 LOG (llevError, "%s\n", buf); 89 LOG (llevError, "%s\n", buf);
130 * a description of it. It is there merely for flavour text. 98 * a description of it. It is there merely for flavour text.
131 */ 99 */
132void 100void
133current_region_info (object *op) 101current_region_info (object *op)
134{ 102{
135 /* 103 if (region *reg = op->region ())
136 * Ok I /suppose/ I should write a seperate function for this, but it isn't
137 * going to be /that/ slow, and won't get called much
138 */
139 region *r = get_region_by_name (get_name_of_region_for_map (op->map));
140
141 if (!r)
142 return;
143 /* This should only be possible if regions are not operating on this server. */
144
145 new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r)); 104 new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", &reg->longname, &reg->msg);
146} 105}
147 106
148void 107void
149current_map_info (object *op) 108current_map_info (object *op)
150{ 109{
151 maptile *m = op->map; 110 maptile *m = op->map;
152 111
153 if (!m) 112 if (!m)
154 return; 113 return;
155 114
156 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m)); 115 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname);
157 116
158 if (QUERY_FLAG (op, FLAG_WIZ)) 117 if (QUERY_FLAG (op, FLAG_WIZ))
159 {
160 new_draw_info_format (NDI_UNIQUE, 0, op, 118 new_draw_info_format (NDI_UNIQUE, 0, op,
161 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", 119 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
162 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); 120 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
163 121
164 }
165 if (m->msg) 122 if (m->msg)
166 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); 123 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
167} 124}
168 125
169#ifdef DEBUG_MALLOC_LEVEL 126#ifdef DEBUG_MALLOC_LEVEL
181#endif 138#endif
182 139
183int 140int
184command_whereabouts (object *op, char *params) 141command_whereabouts (object *op, char *params)
185{ 142{
186 143 //TODO: should obviously not waste space in struct region for this.
187 region *reg;
188 player *pl;
189
190 /* 144 /*
191 * reset the counter on the region, then use it to store the number of 145 * reset the counter on the region, then use it to store the number of
192 * players there. 146 * players there.
193 * I don't know how thread-safe this would be, I suspect not very.... 147 * I don't know how thread-safe this would be, I suspect not very....
194 */ 148 */
195 for (reg = first_region; reg != NULL; reg = reg->next) 149 for_all_regions (rgn)
196 {
197 reg->counter = 0; 150 rgn->counter = 0;
198 } 151
199 for_all_players (pl) 152 for_all_players (pl)
200 if (pl->ob->map != NULL) 153 if (pl->ob->map)
201 get_region_by_map (pl->ob->map)->counter++; 154 ++pl->ob->region ()->counter;
202 155
203 /* we only want to print out by places with a 'longname' field... */ 156 /* we only want to print out by places with a 'longname' field... */
204 for (reg = first_region; reg != NULL; reg = reg->next) 157 for_all_regions (rgn)
205 { 158 {
206 if (reg->longname == NULL && reg->counter > 0) 159 if (!rgn->longname && rgn->counter > 0)
207 { 160 {
208 if (reg->parent != NULL) 161 if (rgn->parent)
209 { 162 {
210 reg->parent->counter += reg->counter; 163 rgn->parent->counter += rgn->counter;
211 reg->counter = 0; 164 rgn->counter = 0;
212 } 165 }
213 else /*uh oh, we shouldn't be here. */ 166 else /*uh oh, we shouldn't be here. */
214 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); 167 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name);
215 } 168 }
216 } 169 }
170
217 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); 171 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
218 for (reg = first_region; reg != NULL; reg = reg->next) 172
173 for_all_regions (rgn)
219 if (reg->counter > 0) 174 if (rgn->counter)
220 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); 175 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname);
176
221 return 1; 177 return 1;
222} 178}
223 179
224typedef struct 180typedef struct
225{ 181{
251 current_region_info (op); 207 current_region_info (op);
252 return 1; 208 return 1;
253} 209}
254 210
255int 211int
256command_maps (object *op, char *params)
257{
258 map_info (op, params);
259 return 1;
260}
261
262int
263command_time (object *op, char *params) 212command_time (object *op, char *params)
264{ 213{
265 print_tod (op); 214 print_tod (op);
266 return 1; 215 return 1;
267} 216}
268 217
269int 218int
270command_weather (object *op, char *params) 219command_weather (object *op, char *params)
271{ 220{
221#if 0
272 int wx, wy, temp, sky; 222 int wx, wy, temp, sky;
273 char buf[MAX_BUF]; 223 char buf[MAX_BUF];
274 224
275 if (settings.dynamiclevel < 1) 225 if (settings.dynamiclevel < 1)
276 return 1; 226 return 1;
392 break; 342 break;
393 case SKY_BLIZZARD: 343 case SKY_BLIZZARD:
394 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); 344 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
395 break; 345 break;
396 } 346 }
397 return 1; 347#endif
398}
399
400int
401command_archs (object *op, char *params)
402{
403 arch_info (op);
404 return 1; 348 return 1;
405} 349}
406 350
407int 351int
408command_hiscore (object *op, char *params) 352command_hiscore (object *op, char *params)
459 dump_friendly_objects (); 403 dump_friendly_objects ();
460 return 0; 404 return 0;
461} 405}
462 406
463int 407int
464command_dumpmap (object *op, char *params)
465{
466 if (op)
467 dump_map (op->map);
468 return 0;
469}
470
471int
472command_dumpallmaps (object *op, char *params)
473{
474 dump_all_maps ();
475 return 0;
476}
477
478int
479command_printlos (object *op, char *params) 408command_printlos (object *op, char *params)
480{ 409{
481 if (op) 410 if (op)
482 print_los (op); 411 print_los (op);
483 return 0; 412 return 0;
488command_version (object *op, char *params) 417command_version (object *op, char *params)
489{ 418{
490 version (op); 419 version (op);
491 return 0; 420 return 0;
492} 421}
493
494 422
495#ifndef BUG_LOG 423#ifndef BUG_LOG
496# define BUG_LOG "bug_log" 424# define BUG_LOG "bug_log"
497#endif 425#endif
498void 426void
611 op->update_stats (); 539 op->update_stats ();
612 return 1; 540 return 1;
613} 541}
614 542
615int 543int
616command_players (object *op, char *paramss)
617{
618 char buf[MAX_BUF];
619 char *t;
620 DIR *Dir;
621
622 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
623 t = buf + strlen (buf);
624 if ((Dir = opendir (buf)) != NULL)
625 {
626 const struct dirent *Entry;
627
628 while ((Entry = readdir (Dir)))
629 {
630 /* skip '.' , '..' */
631 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
632 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
633 {
634 struct stat Stat;
635
636 strcpy (t, Entry->d_name);
637 if (stat (buf, &Stat) == 0)
638 {
639 /* This was not posix compatible
640 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
641 */
642 if (S_ISDIR (Stat.st_mode))
643 {
644 char buf2[MAX_BUF];
645 struct tm *tm = localtime (&Stat.st_mtime);
646
647 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
648 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
649 new_draw_info (NDI_UNIQUE, 0, op, buf2);
650 }
651 }
652 }
653 }
654 }
655 closedir (Dir);
656 return 0;
657}
658
659
660
661int
662command_logs (object *op, char *params) 544command_logs (object *op, char *params)
663{ 545{
664 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); 546 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
665 547
666 return 1; 548 return 1;
687 else 569 else
688 { 570 {
689 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); 571 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
690 return 0; 572 return 0;
691 } 573 }
574
692 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", 575 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
693 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); 576 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
694 return 1; 577 return 1;
695} 578}
696 579
718 found++; 601 found++;
719 op->contr->bowtype = (bowtype_t) i; 602 op->contr->bowtype = (bowtype_t) i;
720 break; 603 break;
721 } 604 }
722 } 605 }
606
723 if (!found) 607 if (!found)
724 { 608 {
725 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 609 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
726 for (i = 0; i <= bow_bestarrow; i++) 610 for (i = 0; i <= bow_bestarrow; i++)
727 { 611 {
733 strcat (buf, "."); 617 strcat (buf, ".");
734 } 618 }
735 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 619 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
736 return 0; 620 return 0;
737 } 621 }
622
738 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 623 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
739 return 1; 624 return 1;
740} 625}
741 626
742int 627int
1133 return 0; 1018 return 0;
1134 } 1019 }
1135} 1020}
1136 1021
1137int 1022int
1138command_quit (object *op, char *params)
1139{
1140 new_draw_info (NDI_UNIQUE, 0, op,
1141 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1142 return 1;
1143}
1144
1145int
1146command_real_quit (object *op, char *params)
1147{
1148 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1149
1150 op->contr->ns->state = ST_CONFIRM_QUIT;
1151 return 1;
1152}
1153
1154/*
1155 * don't allow people to exit explore mode. It otherwise becomes
1156 * really easy to abuse this.
1157 */
1158int
1159command_explore (object *op, char *params)
1160{
1161 if (settings.explore_mode == FALSE)
1162 return 1;
1163 /*
1164 * I guess this is the best way to see if we are solo or not. Actually,
1165 * are there any cases when first_player->next==NULL and we are not solo?
1166 */
1167 if ((first_player != op->contr) || (first_player->next != NULL))
1168 {
1169 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1170 }
1171 else if (op->contr->explore)
1172 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1173 else
1174 {
1175 op->contr->explore = 1;
1176 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1177 }
1178 return 1;
1179}
1180
1181int
1182command_sound (object *op, char *params) 1023command_sound (object *op, char *params)
1183{ 1024{
1184 if (op->contr->ns->sound) 1025 if (op->contr->ns->sound)
1185 { 1026 {
1186 op->contr->ns->sound = 0; 1027 op->contr->ns->sound = 0;
1191 op->contr->ns->sound = 1; 1032 op->contr->ns->sound = 1;
1192 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled."); 1033 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1193 } 1034 }
1194 1035
1195 return 1; 1036 return 1;
1196}
1197
1198int
1199explore_mode (void)
1200{
1201 player *pl;
1202
1203 if (settings.explore_mode == TRUE)
1204 {
1205 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1206 if (pl->explore)
1207 return 1;
1208 }
1209 return 0;
1210} 1037}
1211 1038
1212int 1039int
1213command_title (object *op, char *params) 1040command_title (object *op, char *params)
1214{ 1041{
1254 strcpy (op->contr->own_title, params); 1081 strcpy (op->contr->own_title, params);
1255 return 1; 1082 return 1;
1256} 1083}
1257 1084
1258int 1085int
1259command_save (object *op, char *params)
1260{
1261 if (!op->stats.exp)
1262 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1263 else
1264 {
1265 op->contr->save ();
1266 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1267 }
1268
1269 return 1;
1270}
1271
1272int
1273command_peaceful (object *op, char *params) 1086command_peaceful (object *op, char *params)
1274{ 1087{
1275 new_draw_info (NDI_UNIQUE, 0, op, 1088 new_draw_info (NDI_UNIQUE, 0, op,
1276 "You cannot change your peaceful setting with this command." 1089 "You cannot change your peaceful setting with this command."
1277 " Please speak to the priest in the temple of Gorokh" 1090 " Please speak to the priest in the temple of Gorokh"
1316 new_draw_info (NDI_UNIQUE, 0, op, "You are braced."); 1129 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1317 else 1130 else
1318 new_draw_info (NDI_UNIQUE, 0, op, "Not braced."); 1131 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1319 1132
1320 op->update_stats (); 1133 op->update_stats ();
1321 return 0;
1322}
1323
1324int
1325command_style_map_info (object *op, char *params)
1326{
1327 extern maptile *styles;
1328 maptile *mp;
1329 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1330 object *tmp;
1331
1332 for (mp = styles; mp != NULL; mp = mp->next)
1333 {
1334 maps_used++;
1335 mapmem += mp->width * mp->height * (sizeof (object *) + sizeof (mapspace)) + sizeof (maptile);
1336 for (x = 0; x < mp->width; x++)
1337 {
1338 for (y = 0; y < mp->height; y++)
1339 {
1340 for (tmp = GET_MAP_OB (mp, x, y); tmp != NULL; tmp = tmp->above)
1341 objects_used++;
1342 }
1343 }
1344 }
1345 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1346 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1347 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1348 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1349 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1350 return 0; 1134 return 0;
1351} 1135}
1352 1136
1353int 1137int
1354command_kill_pets (object *op, char *params) 1138command_kill_pets (object *op, char *params)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines