1 | /* |
1 | /* |
2 | * static char *rcsid_main_c = |
2 | * static char *rcsid_main_c = |
3 | * "$Id: main.c,v 1.1.1.1 2006/02/03 07:14:32 root Exp $"; |
3 | * "$Id: main.c,v 1.15 2006/08/11 12:21:35 elmex Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
511 | exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
511 | exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
512 | return; |
512 | return; |
513 | } |
513 | } |
514 | *sourcemap++ = '\0'; |
514 | *sourcemap++ = '\0'; |
515 | |
515 | |
516 | /* If we are not coming from a template map, we can use reletive directories |
516 | /* If we are not coming from a template map, we can use relative directories |
517 | * for the map to generate from. |
517 | * for the map to generate from. |
518 | */ |
518 | */ |
519 | if (!exit_ob->map->template) { |
519 | if (!exit_ob->map->template) { |
520 | sourcemap = path_combine_and_normalize(exit_ob->map->path, sourcemap); |
520 | sourcemap = path_combine_and_normalize(exit_ob->map->path, sourcemap); |
521 | } |
521 | } |
… | |
… | |
719 | /* It may be nice to support other creatures moving across |
719 | /* It may be nice to support other creatures moving across |
720 | * exits, but right now a lot of the code looks at op->contr, |
720 | * exits, but right now a lot of the code looks at op->contr, |
721 | * so thta is an RFE. |
721 | * so thta is an RFE. |
722 | */ |
722 | */ |
723 | if (op->type != PLAYER) return; |
723 | if (op->type != PLAYER) return; |
|
|
724 | |
|
|
725 | /* Need to remove player from transport */ |
|
|
726 | if (op->contr->transport) apply_transport(op, op->contr->transport, AP_UNAPPLY); |
724 | |
727 | |
725 | /* First, lets figure out what map the player is going to go to */ |
728 | /* First, lets figure out what map the player is going to go to */ |
726 | if (exit_ob){ |
729 | if (exit_ob){ |
727 | |
730 | |
728 | /* check to see if we make a template map */ |
731 | /* check to see if we make a template map */ |
… | |
… | |
782 | else |
785 | else |
783 | newmap = ready_map_name(EXIT_PATH(exit_ob), 0); |
786 | newmap = ready_map_name(EXIT_PATH(exit_ob), 0); |
784 | } |
787 | } |
785 | if (!newmap) |
788 | if (!newmap) |
786 | { |
789 | { |
|
|
790 | if (exit_ob->name) |
787 | new_draw_info_format(NDI_UNIQUE, 0, op, "The %s is closed.", exit_ob->name); |
791 | new_draw_info_format(NDI_UNIQUE, 0, op, "The %s is closed.", exit_ob->name); |
|
|
792 | /* don't cry to momma if name is not set - as in tmp objects |
|
|
793 | * used by the savebed code and character creation */ |
788 | return; |
794 | return; |
789 | } |
795 | } |
790 | |
796 | |
791 | /* This supports the old behaviour, but it really should not be used. |
797 | /* This supports the old behaviour, but it really should not be used. |
792 | * I will note for example that with this method, it is impossible to |
798 | * I will note for example that with this method, it is impossible to |
… | |
… | |
933 | if ((pl->last_save_tick+AUTOSAVE)<pticks && pl->state==ST_PLAYING) { |
939 | if ((pl->last_save_tick+AUTOSAVE)<pticks && pl->state==ST_PLAYING) { |
934 | /* Don't save the player on unholy ground. Instead, increase the |
940 | /* Don't save the player on unholy ground. Instead, increase the |
935 | * tick time so it will be about 10 seconds before we try and save |
941 | * tick time so it will be about 10 seconds before we try and save |
936 | * again. |
942 | * again. |
937 | */ |
943 | */ |
938 | if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { |
944 | // if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { |
939 | pl->last_save_tick += 100; |
945 | // pl->last_save_tick += 100; |
940 | } else { |
946 | // } else { |
941 | save_player(pl->ob,1); |
947 | save_player(pl->ob,1); |
942 | pl->last_save_tick = pticks; |
948 | pl->last_save_tick = pticks; |
943 | } |
949 | // } |
944 | } |
950 | } |
945 | #endif |
951 | #endif |
946 | } /* end of for loop for all the players */ |
952 | } /* end of for loop for all the players */ |
947 | } /* for flag */ |
953 | } /* for flag */ |
948 | for(pl=first_player;pl!=NULL;pl=pl->next) { |
954 | for(pl=first_player;pl!=NULL;pl=pl->next) { |
… | |
… | |
1083 | continue; |
1089 | continue; |
1084 | |
1090 | |
1085 | /* Animate the object. Bug of feature that andim_speed |
1091 | /* Animate the object. Bug of feature that andim_speed |
1086 | * is based on ticks, and not the creatures speed? |
1092 | * is based on ticks, and not the creatures speed? |
1087 | */ |
1093 | */ |
1088 | if (op->anim_speed && op->last_anim >= op->anim_speed) { |
1094 | if (op->anim_speed && op->last_anim >= op->anim_speed) |
|
|
1095 | { |
|
|
1096 | if ((op->type==PLAYER)||(op->type==MONSTER)) |
|
|
1097 | animate_object(op, op->facing); |
|
|
1098 | else |
1089 | animate_object (op, op->direction); |
1099 | animate_object (op, op->direction); |
|
|
1100 | |
1090 | op->last_anim = 1; |
1101 | op->last_anim = 1; |
1091 | } else { |
1102 | } |
|
|
1103 | else |
1092 | op->last_anim++; |
1104 | op->last_anim++; |
1093 | } |
|
|
1094 | |
1105 | |
1095 | if (op->speed_left > 0) { |
1106 | if (op->speed_left > 0) { |
1096 | #if 0 |
1107 | #if 0 |
1097 | /* I've seen occasional crashes in move_symptom() with it |
1108 | /* I've seen occasional crashes in move_symptom() with it |
1098 | * crashing because op is removed - add some debugging to |
1109 | * crashing because op is removed - add some debugging to |
… | |
… | |
1181 | #endif |
1192 | #endif |
1182 | exit(0); |
1193 | exit(0); |
1183 | } |
1194 | } |
1184 | |
1195 | |
1185 | void leave(player *pl, int draw_exit) { |
1196 | void leave(player *pl, int draw_exit) { |
1186 | char buf[MAX_BUF]; |
|
|
1187 | |
|
|
1188 | if (pl!=NULL) { |
1197 | if (pl != NULL) { |
1189 | /* We do this so that the socket handling routine can do the final |
1198 | /* We do this so that the socket handling routine can do the final |
1190 | * cleanup. We also leave that loop to actually handle the freeing |
1199 | * cleanup. We also leave that loop to actually handle the freeing |
1191 | * of the data. |
1200 | * of the data. |
1192 | */ |
1201 | */ |
1193 | if (draw_exit==0) |
1202 | if (pl->ob->type != DEAD_OBJECT) |
1194 | { |
1203 | { |
1195 | } |
1204 | execute_global_event (EVENT_LOGOUT, pl, pl->socket.host); |
1196 | pl->socket.status=Ns_Dead; |
|
|
1197 | LOG(llevInfo,"LOGOUT: Player named %s from ip %s\n", pl->ob->name, |
1205 | LOG (llevInfo,"LOGOUT: Player named %s from ip %s\n", pl->ob->name, pl->socket.host); |
1198 | pl->socket.host); |
|
|
1199 | |
1206 | |
1200 | (void) sprintf(buf,"%s left the game.",pl->ob->name); |
1207 | pl->socket.status = Ns_Dead; |
1201 | if (pl->ob->map) { |
1208 | |
1202 | if (pl->ob->map->in_memory==MAP_IN_MEMORY) |
|
|
1203 | pl->ob->map->timeout = MAP_TIMEOUT(pl->ob->map); |
|
|
1204 | pl->ob->map->players--; |
|
|
1205 | pl->ob->map=NULL; |
|
|
1206 | } |
|
|
1207 | pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */ |
|
|
1208 | } |
|
|
1209 | /* If a hidden dm dropped connection do not create |
1209 | /* If a hidden dm dropped connection do not create |
1210 | * inconsistencies by showing that they have left the game |
1210 | * inconsistencies by showing that they have left the game |
1211 | */ |
1211 | */ |
1212 | if (!(QUERY_FLAG(pl->ob,FLAG_WIZ) && pl->ob->contr->hidden) && |
1212 | if (!(QUERY_FLAG(pl->ob,FLAG_WIZ) && pl->ob->contr->hidden) |
1213 | (pl!=NULL && draw_exit) && |
1213 | && draw_exit |
1214 | (pl->state != ST_GET_NAME && pl->state!=ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD)) |
1214 | && (pl->state != ST_GET_NAME && pl->state!=ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD)) |
|
|
1215 | { |
|
|
1216 | char buf[MAX_BUF]; |
|
|
1217 | sprintf (buf, "%s left the game.", pl->ob->name); |
1215 | new_draw_info(NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf); |
1218 | new_draw_info(NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf); |
|
|
1219 | } |
|
|
1220 | |
|
|
1221 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1222 | leave_map (pl->ob); |
|
|
1223 | |
|
|
1224 | pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */ |
|
|
1225 | } |
|
|
1226 | } |
1216 | } |
1227 | } |
1217 | |
1228 | |
1218 | int forbid_play(void) |
1229 | int forbid_play(void) |
1219 | { |
1230 | { |
1220 | #if !defined(_IBMR2) && !defined(___IBMR2) && defined(PERM_FILE) |
1231 | #if !defined(_IBMR2) && !defined(___IBMR2) && defined(PERM_FILE) |
… | |
… | |
1333 | doeric_server(); |
1344 | doeric_server(); |
1334 | process_events(NULL); /* "do" something with objects with speed */ |
1345 | process_events(NULL); /* "do" something with objects with speed */ |
1335 | cftimer_process_timers();/* Process the crossfire Timers */ |
1346 | cftimer_process_timers();/* Process the crossfire Timers */ |
1336 | /* Lauwenmark : Here we handle the CLOCK global event */ |
1347 | /* Lauwenmark : Here we handle the CLOCK global event */ |
1337 | execute_global_event(EVENT_CLOCK); |
1348 | execute_global_event(EVENT_CLOCK); |
|
|
1349 | flush_sockets(); |
1338 | check_active_maps(); /* Removes unused maps after a certain timeout */ |
1350 | check_active_maps(); /* Removes unused maps after a certain timeout */ |
1339 | do_specials(); /* Routines called from time to time. */ |
1351 | do_specials(); /* Routines called from time to time. */ |
1340 | |
1352 | |
1341 | sleep_delta(); /* Slepp proper amount of time before next tick */ |
1353 | sleep_delta(); /* Slepp proper amount of time before next tick */ |
1342 | } |
1354 | } |