ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/main.C
(Generate patch)

Comparing deliantra/server/server/main.C (file contents):
Revision 1.23 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.30 by root, Sat Sep 16 22:24:13 2006 UTC

1
2/*
3 * static char *rcsid_main_c =
4 * "$Id: main.C,v 1.23 2006/09/10 15:59:57 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#include <object.h> 25#include <object.h>
32#include <tod.h> 26#include <tod.h>
197 * goes someplace. 191 * goes someplace.
198 */ 192 */
199void 193void
200enter_player_savebed (object *op) 194enter_player_savebed (object *op)
201{ 195{
202 mapstruct *oldmap = op->map; 196 maptile *oldmap = op->map;
203 object *tmp; 197 object *tmp;
204 198
205 tmp = get_object (); 199 tmp = get_object ();
206 200
207 EXIT_PATH (tmp) = op->contr->savebed_map; 201 EXIT_PATH (tmp) = op->contr->savebed_map;
232 * the counts on the map if needed. 226 * the counts on the map if needed.
233 */ 227 */
234void 228void
235leave_map (object *op) 229leave_map (object *op)
236{ 230{
237 mapstruct *oldmap = op->map; 231 maptile *oldmap = op->map;
238 232
239 remove_ob (op); 233 remove_ob (op);
240 234
241 if (oldmap) 235 if (oldmap)
242 { 236 {
255 * player to - it could be the map he just came from if the load failed for 249 * player to - it could be the map he just came from if the load failed for
256 * whatever reason. If default map coordinates are to be used, then 250 * whatever reason. If default map coordinates are to be used, then
257 * the function that calls this should figure them out. 251 * the function that calls this should figure them out.
258 */ 252 */
259static void 253static void
260enter_map (object *op, mapstruct *newmap, int x, int y) 254enter_map (object *op, maptile *newmap, int x, int y)
261{ 255{
262 mapstruct *oldmap = op->map; 256 maptile *oldmap = op->map;
263 257
264 if (out_of_map (newmap, x, y)) 258 if (out_of_map (newmap, x, y))
265 { 259 {
266 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); 260 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y);
267 x = MAP_ENTER_X (newmap); 261 x = MAP_ENTER_X (newmap);
387 } 381 }
388 } 382 }
389} 383}
390 384
391void 385void
392set_map_timeout (mapstruct *oldmap) 386set_map_timeout (maptile *oldmap)
393{ 387{
394#if MAP_MAXTIMEOUT 388#if MAP_MAXTIMEOUT
395 oldmap->timeout = MAP_TIMEOUT (oldmap); 389 oldmap->timeout = MAP_TIMEOUT (oldmap);
396 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is 390 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is
397 * lower than the min value. 391 * lower than the min value.
418 */ 412 */
419char * 413char *
420clean_path (const char *file) 414clean_path (const char *file)
421{ 415{
422 static char newpath[MAX_BUF], *cp; 416 static char newpath[MAX_BUF], *cp;
417 assign (newpath, file);
423 418
424 strncpy (newpath, file, MAX_BUF - 1);
425 newpath[MAX_BUF - 1] = '\0';
426 for (cp = newpath; *cp != '\0'; cp++) 419 for (cp = newpath; *cp != '\0'; cp++)
427 {
428 if (*cp == '/') 420 if (*cp == '/')
429 *cp = '_'; 421 *cp = '_';
430 } 422
431 return newpath; 423 return newpath;
432} 424}
433 425
434 426
435/* unclean_path takes a path and replaces all _ with / 427/* unclean_path takes a path and replaces all _ with /
443unclean_path (const char *src) 435unclean_path (const char *src)
444{ 436{
445 static char newpath[MAX_BUF], *cp; 437 static char newpath[MAX_BUF], *cp;
446 438
447 cp = strrchr (src, '/'); 439 cp = strrchr (src, '/');
448 if (cp) 440 assign (newpath, cp ? cp + 1 : src);
449 strncpy (newpath, cp + 1, MAX_BUF - 1);
450 else
451 strncpy (newpath, src, MAX_BUF - 1);
452 newpath[MAX_BUF - 1] = '\0';
453 441
454 for (cp = newpath; *cp != '\0'; cp++) 442 for (cp = newpath; *cp != '\0'; cp++)
455 {
456 if (*cp == '_') 443 if (*cp == '_')
457 *cp = '/'; 444 *cp = '/';
458 } 445
459 return newpath; 446 return newpath;
460} 447}
461 448
462 449
463/* The player is trying to enter a randomly generated map. In this case, generate the 450/* The player is trying to enter a randomly generated map. In this case, generate the
465 */ 452 */
466 453
467static void 454static void
468enter_random_map (object *pl, object *exit_ob) 455enter_random_map (object *pl, object *exit_ob)
469{ 456{
470 mapstruct *new_map; 457 maptile *new_map;
471 char newmap_name[HUGE_BUF], *cp; 458 char newmap_name[HUGE_BUF], *cp;
472 static int reference_number = 0; 459 static int reference_number = 0;
473 RMParms rp; 460 RMParms rp;
474 461
475 memset (&rp, 0, sizeof (RMParms)); 462 memset (&rp, 0, sizeof (RMParms));
535 */ 522 */
536 523
537static void 524static void
538enter_fixed_template_map (object *pl, object *exit_ob) 525enter_fixed_template_map (object *pl, object *exit_ob)
539{ 526{
540 mapstruct *new_map; 527 maptile *new_map;
541 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; 528 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap;
542 const char *new_map_name; 529 const char *new_map_name;
543 530
544 /* Split the exit path string into two parts, one 531 /* Split the exit path string into two parts, one
545 * for where to store the map, and one for were 532 * for where to store the map, and one for were
627 */ 614 */
628 615
629static void 616static void
630enter_random_template_map (object *pl, object *exit_ob) 617enter_random_template_map (object *pl, object *exit_ob)
631{ 618{
632 mapstruct *new_map; 619 maptile *new_map;
633 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; 620 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF];
634 const char *new_map_name; 621 const char *new_map_name;
635 RMParms rp; 622 RMParms rp;
636 623
637 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 624 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
699 */ 686 */
700static void 687static void
701enter_unique_map (object *op, object *exit_ob) 688enter_unique_map (object *op, object *exit_ob)
702{ 689{
703 char apartment[HUGE_BUF]; 690 char apartment[HUGE_BUF];
704 mapstruct *newmap; 691 maptile *newmap;
705 692
706 if (EXIT_PATH (exit_ob)[0] == '/') 693 if (EXIT_PATH (exit_ob)[0] == '/')
707 { 694 {
708 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); 695 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob)));
709 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); 696 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE);
832 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); 819 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob);
833 820
834 /* 'Normal' exits that do not do anything special 821 /* 'Normal' exits that do not do anything special
835 * Simple enough we don't need another routine for it. 822 * Simple enough we don't need another routine for it.
836 */ 823 */
837 mapstruct *newmap; 824 maptile *newmap;
838 825
839 if (exit_ob->map) 826 if (exit_ob->map)
840 { 827 {
841 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); 828 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0);
842 /* Random map was previously generated, but is no longer about. Lets generate a new 829 /* Random map was previously generated, but is no longer about. Lets generate a new
931 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); 918 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1);
932 } 919 }
933 else 920 else
934 { 921 {
935 int flags = 0; 922 int flags = 0;
936 mapstruct *newmap; 923 maptile *newmap;
937 924
938 925
939 /* Hypothetically, I guess its possible that a standard map matches 926 /* Hypothetically, I guess its possible that a standard map matches
940 * the localdir, but that seems pretty unlikely - unlikely enough that 927 * the localdir, but that seems pretty unlikely - unlikely enough that
941 * I'm not going to attempt to try to deal with that possibility. 928 * I'm not going to attempt to try to deal with that possibility.
977 964
978#if 0 // dead code, schmorp 965#if 0 // dead code, schmorp
979void 966void
980process_active_maps () 967process_active_maps ()
981{ 968{
982 for (mapstruct *map = first_map; map != NULL; map = map->next) 969 for (maptile *map = first_map; map != NULL; map = map->next)
983 if (map->in_memory == MAP_IN_MEMORY) 970 if (map->in_memory == MAP_IN_MEMORY)
984 if (players_on_map (map, TRUE)) 971 if (players_on_map (map, TRUE))
985 process_events (map); 972 process_events (map);
986} 973}
987#endif 974#endif
993 * objects have been updated, process_players2() does the processing that 980 * objects have been updated, process_players2() does the processing that
994 * is needed after the players have been updated. 981 * is needed after the players have been updated.
995 */ 982 */
996 983
997void 984void
998process_players1 (mapstruct *map) 985process_players1 (maptile *map)
999{ 986{
1000 int flag; 987 int flag;
1001 player *pl, *plnext; 988 player *pl, *plnext;
1002 989
1003 /* Basically, we keep looping until all the players have done their actions. */ 990 /* Basically, we keep looping until all the players have done their actions. */
1070 /* draw(pl->ob); *//* updated in socket code */ 1057 /* draw(pl->ob); *//* updated in socket code */
1071 } 1058 }
1072} 1059}
1073 1060
1074void 1061void
1075process_players2 (mapstruct *map) 1062process_players2 (maptile *map)
1076{ 1063{
1077 player *pl; 1064 player *pl;
1078 1065
1079 /* Then check if any players should use weapon-speed instead of speed */ 1066 /* Then check if any players should use weapon-speed instead of speed */
1080 for (pl = first_player; pl != NULL; pl = pl->next) 1067 for (pl = first_player; pl != NULL; pl = pl->next)
1110 pl->ob->speed_left = pl->ob->speed; 1097 pl->ob->speed_left = pl->ob->speed;
1111 } 1098 }
1112} 1099}
1113 1100
1114void 1101void
1115process_events (mapstruct *map) 1102process_events (maptile *map)
1116{ 1103{
1117 object *op; 1104 object *op;
1105
1106 static object *marker;
1107 if (!marker)
1118 object *marker = get_object (); 1108 marker = get_object ();
1119 tag_t tag;
1120 1109
1121 process_players1 (map); 1110 process_players1 (map);
1122 1111
1123 marker->active_next = active_objects; 1112 marker->active_next = active_objects;
1124 1113
1129 active_objects = marker; 1118 active_objects = marker;
1130 1119
1131 while (marker->active_next) 1120 while (marker->active_next)
1132 { 1121 {
1133 op = marker->active_next; 1122 op = marker->active_next;
1134 tag = op->count;
1135 1123
1136 /* Move marker forward - swap op and marker */ 1124 /* Move marker forward - swap op and marker */
1137 op->active_prev = marker->active_prev; 1125 op->active_prev = marker->active_prev;
1138 1126
1139 if (op->active_prev) 1127 if (op->active_prev)
1226 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); 1214 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null");
1227 } 1215 }
1228#endif 1216#endif
1229 --op->speed_left; 1217 --op->speed_left;
1230 process_object (op); 1218 process_object (op);
1219
1231 if (was_destroyed (op, tag)) 1220 if (op->destroyed ())
1232 continue; 1221 continue;
1233 } 1222 }
1223
1234 if (settings.casting_time == TRUE && op->casting_time > 0) 1224 if (settings.casting_time == TRUE && op->casting_time > 0)
1235 op->casting_time--; 1225 op->casting_time--;
1226
1236 if (op->speed_left <= 0) 1227 if (op->speed_left <= 0)
1237 op->speed_left += FABS (op->speed); 1228 op->speed_left += FABS (op->speed);
1238 } 1229 }
1239 1230
1240 /* Remove marker object from active list */ 1231 /* Remove marker object from active list */
1242 marker->active_prev->active_next = NULL; 1233 marker->active_prev->active_next = NULL;
1243 else 1234 else
1244 active_objects = NULL; 1235 active_objects = NULL;
1245 1236
1246 process_players2 (map); 1237 process_players2 (map);
1247
1248 free_object (marker);
1249} 1238}
1250 1239
1251void 1240void
1252clean_tmp_files (void) 1241clean_tmp_files (void)
1253{ 1242{
1254 mapstruct *m, *next; 1243 maptile *m, *next;
1255 1244
1256 LOG (llevInfo, "Cleaning up...\n"); 1245 LOG (llevInfo, "Cleaning up...\n");
1257 1246
1258 /* We save the maps - it may not be intuitive why, but if there are unique 1247 /* We save the maps - it may not be intuitive why, but if there are unique
1259 * items, we need to save the map so they get saved off. Perhaps we should 1248 * items, we need to save the map so they get saved off. Perhaps we should
1286 1275
1287/* clean up everything before exiting */ 1276/* clean up everything before exiting */
1288void 1277void
1289cleanup (void) 1278cleanup (void)
1290{ 1279{
1291 LOG (llevDebug, "Cleanup called. freeing data.\n"); 1280 LOG (llevDebug, "Cleanup called.\n");
1281
1282 for (player *pl = first_player; pl != NULL; pl = pl->next)
1283 save_player (pl->ob, 0);
1284
1285 for (player *pl = first_player; pl != NULL; pl = pl->next)
1286 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1287 leave_map (pl->ob);
1288
1292 clean_tmp_files (); 1289 clean_tmp_files ();
1293 write_book_archive (); 1290 write_book_archive ();
1294#ifdef MEMORY_DEBUG
1295 free_all_maps ();
1296 free_style_maps ();
1297 free_all_object_data ();
1298 free_all_archs ();
1299 free_all_treasures ();
1300 free_all_images ();
1301 free_all_newserver ();
1302 free_all_recipes ();
1303 free_all_readable ();
1304 free_all_god ();
1305 free_all_anim ();
1306 /* See what the string data that is out there that hasn't been freed. */
1307 1291
1308/* LOG(llevDebug, ss_dump_table(0xff));*/ 1292 INVOKE_GLOBAL (CLEANUP);
1309#endif 1293
1310 exit (0); 1294 _exit (0);
1311} 1295}
1312 1296
1313void 1297void
1314leave (player *pl, int draw_exit) 1298leave (player *pl, int draw_exit)
1315{ 1299{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines