… | |
… | |
31 | # ifdef HAVE_CRYPT_H |
31 | # ifdef HAVE_CRYPT_H |
32 | # include <crypt.h> |
32 | # include <crypt.h> |
33 | # endif |
33 | # endif |
34 | #endif |
34 | #endif |
35 | |
35 | |
36 | #ifndef __CEXTRACT__ |
|
|
37 | # include <sproto.h> |
36 | #include <sproto.h> |
38 | #endif |
|
|
39 | |
|
|
40 | #ifdef HAVE_TIME_H |
|
|
41 | # include <time.h> |
37 | #include <time.h> |
42 | #endif |
|
|
43 | |
38 | |
44 | #include <../random_maps/random_map.h> |
39 | #include <../random_maps/random_map.h> |
45 | #include <../random_maps/rproto.h> |
40 | #include <../random_maps/rproto.h> |
46 | #include "path.h" |
41 | #include "path.h" |
47 | |
42 | |
… | |
… | |
158 | * simple case at top - no encryption - makes it easier to read. |
153 | * simple case at top - no encryption - makes it easier to read. |
159 | */ |
154 | */ |
160 | char * |
155 | char * |
161 | crypt_string (char *str, char *salt) |
156 | crypt_string (char *str, char *salt) |
162 | { |
157 | { |
163 | #if defined(WIN32) || (defined(__FreeBSD__) && !defined(HAVE_LIBDES)) |
158 | #if (defined(__FreeBSD__) && !defined(HAVE_LIBDES)) |
164 | return (str); |
159 | return (str); |
165 | #else |
160 | #else |
166 | static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
161 | static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
167 | char s[2]; |
162 | char s[2]; |
168 | |
163 | |
… | |
… | |
194 | enter_player_savebed (object *op) |
189 | enter_player_savebed (object *op) |
195 | { |
190 | { |
196 | maptile *oldmap = op->map; |
191 | maptile *oldmap = op->map; |
197 | object *tmp; |
192 | object *tmp; |
198 | |
193 | |
199 | tmp = get_object (); |
194 | tmp = object::create (); |
200 | |
195 | |
201 | EXIT_PATH (tmp) = op->contr->savebed_map; |
196 | EXIT_PATH (tmp) = op->contr->savebed_map; |
202 | EXIT_X (tmp) = op->contr->bed_x; |
197 | EXIT_X (tmp) = op->contr->bed_x; |
203 | EXIT_Y (tmp) = op->contr->bed_y; |
198 | EXIT_Y (tmp) = op->contr->bed_y; |
204 | enter_exit (op, tmp); |
199 | enter_exit (op, tmp); |
… | |
… | |
217 | EXIT_PATH (tmp) = op->contr->savebed_map; |
212 | EXIT_PATH (tmp) = op->contr->savebed_map; |
218 | EXIT_X (tmp) = op->contr->bed_x; |
213 | EXIT_X (tmp) = op->contr->bed_x; |
219 | EXIT_Y (tmp) = op->contr->bed_y; |
214 | EXIT_Y (tmp) = op->contr->bed_y; |
220 | enter_exit (op, tmp); |
215 | enter_exit (op, tmp); |
221 | } |
216 | } |
222 | free_object (tmp); |
217 | |
|
|
218 | tmp->destroy (); |
223 | } |
219 | } |
224 | |
220 | |
225 | /* All this really is is a glorified remove_object that also updates |
221 | /* All this really is is a glorified remove_object that also updates |
226 | * the counts on the map if needed. |
222 | * the counts on the map if needed. |
227 | */ |
223 | */ |
228 | void |
224 | void |
229 | leave_map (object *op) |
225 | leave_map (object *op) |
230 | { |
226 | { |
231 | maptile *oldmap = op->map; |
227 | maptile *oldmap = op->map; |
232 | |
228 | |
233 | remove_ob (op); |
229 | op->remove (); |
234 | |
230 | |
235 | if (oldmap) |
231 | if (oldmap) |
236 | { |
232 | { |
237 | if (!op->contr->hidden) |
233 | if (!op->contr->hidden) |
238 | oldmap->players--; |
234 | oldmap->players--; |
… | |
… | |
298 | /* not much we can do in this case. */ |
294 | /* not much we can do in this case. */ |
299 | LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", newmap->path, x, y); |
295 | LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", newmap->path, x, y); |
300 | } |
296 | } |
301 | } /* end if looking for free spot */ |
297 | } /* end if looking for free spot */ |
302 | |
298 | |
303 | if (op->map != NULL) |
299 | if (op->map) |
304 | if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) |
300 | if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) |
305 | return; |
301 | return; |
306 | |
302 | |
307 | if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) |
303 | if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) |
308 | return; |
304 | return; |
… | |
… | |
311 | return; |
307 | return; |
312 | |
308 | |
313 | /* If it is a player login, he has yet to be inserted anyplace. |
309 | /* If it is a player login, he has yet to be inserted anyplace. |
314 | * otherwise, we need to deal with removing the player here. |
310 | * otherwise, we need to deal with removing the player here. |
315 | */ |
311 | */ |
316 | remove_ob (op); |
312 | op->remove (); |
317 | |
313 | |
318 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
314 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
319 | op->x = x; |
315 | op->x = x; |
320 | op->y = y; |
316 | op->y = y; |
321 | op->map = newmap; |
317 | op->map = newmap; |
… | |
… | |
338 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) |
334 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) |
339 | { |
335 | { |
340 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
336 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
341 | x, y, 1, SIZEOFFREE); |
337 | x, y, 1, SIZEOFFREE); |
342 | |
338 | |
343 | remove_ob (op->contr->ranges[range_golem]); |
339 | op->contr->ranges[range_golem]->remove (); |
344 | |
340 | |
345 | if (i == -1) |
341 | if (i == -1) |
346 | { |
342 | { |
347 | remove_friendly_object (op->contr->ranges[range_golem]); |
343 | remove_friendly_object (op->contr->ranges[range_golem]); |
348 | free_object (op->contr->ranges[range_golem]); |
344 | op->contr->ranges[range_golem]->destroy (); |
349 | op->contr->ranges[range_golem] = NULL; |
345 | op->contr->ranges[range_golem] = 0; |
350 | op->contr->golem_count = 0; |
|
|
351 | } |
346 | } |
352 | else |
347 | else |
353 | { |
348 | { |
354 | for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
349 | for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
355 | { |
350 | { |
… | |
… | |
777 | #define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
772 | #define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
778 | object *tmp; |
773 | object *tmp; |
779 | |
774 | |
780 | /* It may be nice to support other creatures moving across |
775 | /* It may be nice to support other creatures moving across |
781 | * exits, but right now a lot of the code looks at op->contr, |
776 | * exits, but right now a lot of the code looks at op->contr, |
782 | * so thta is an RFE. |
777 | * so that is an RFE. |
783 | */ |
778 | */ |
784 | if (op->type != PLAYER) |
779 | if (op->type != PLAYER) |
785 | return; |
780 | return; |
786 | |
781 | |
787 | /* First, lets figure out what map the player is going to go to */ |
782 | /* First, lets figure out what map the player is going to go to */ |
… | |
… | |
893 | if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) |
888 | if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) |
894 | break; |
889 | break; |
895 | } |
890 | } |
896 | if (tmp) |
891 | if (tmp) |
897 | { |
892 | { |
898 | remove_ob (tmp); |
893 | tmp->remove (); |
899 | free_object (tmp); |
894 | tmp->destroy (); |
900 | } |
895 | } |
901 | |
896 | |
902 | strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); |
897 | strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); |
903 | op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); |
898 | op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); |
904 | save_player (op, 1); |
899 | save_player (op, 1); |
… | |
… | |
950 | |
945 | |
951 | enter_map (op, newmap, op->x, op->y); |
946 | enter_map (op, newmap, op->x, op->y); |
952 | } |
947 | } |
953 | } |
948 | } |
954 | |
949 | |
955 | /* |
|
|
956 | * process_active_maps(): Works like process_events(), but it only |
|
|
957 | * processes maps which a player is on. |
|
|
958 | * |
|
|
959 | */ |
|
|
960 | |
|
|
961 | #if 0 // dead code, schmorp |
|
|
962 | void |
|
|
963 | process_active_maps () |
|
|
964 | { |
|
|
965 | for (maptile *map = first_map; map != NULL; map = map->next) |
|
|
966 | if (map->in_memory == MAP_IN_MEMORY) |
|
|
967 | if (players_on_map (map, TRUE)) |
|
|
968 | process_events (map); |
|
|
969 | } |
|
|
970 | #endif |
|
|
971 | |
|
|
972 | /* process_players1 and process_players2 do all the player related stuff. |
950 | /* process_players1 and process_players2 do all the player related stuff. |
973 | * I moved it out of process events and process_map. This was to some |
951 | * I moved it out of process events and process_map. This was to some |
974 | * extent for debugging as well as to get a better idea of the time used |
952 | * extent for debugging as well as to get a better idea of the time used |
975 | * by the various functions. process_players1() does the processing before |
953 | * by the various functions. process_players1() does the processing before |
976 | * objects have been updated, process_players2() does the processing that |
954 | * objects have been updated, process_players2() does the processing that |
977 | * is needed after the players have been updated. |
955 | * is needed after the players have been updated. |
978 | */ |
956 | */ |
979 | |
957 | static void |
980 | void |
|
|
981 | process_players1 (maptile *map) |
958 | process_players1 () |
982 | { |
959 | { |
983 | int flag; |
960 | int flag; |
984 | player *pl, *plnext; |
|
|
985 | |
|
|
986 | /* Basically, we keep looping until all the players have done their actions. */ |
961 | /* Basically, we keep looping until all the players have done their actions. */ |
987 | for (flag = 1; flag != 0;) |
962 | for (flag = 1; flag != 0;) |
988 | { |
963 | { |
989 | flag = 0; |
964 | flag = 0; |
990 | for (pl = first_player; pl != NULL; pl = plnext) |
965 | for (player *plnext, *pl = first_player; pl; pl = plnext) |
991 | { |
966 | { |
992 | plnext = pl->next; /* In case a player exits the game in handle_player() */ |
967 | plnext = pl->next; /* In case a player exits the game in handle_player() */ |
993 | |
968 | |
994 | if (pl->ob == NULL) |
969 | if (!pl->ob) |
995 | continue; |
|
|
996 | |
|
|
997 | if (map != NULL && pl->ob->map != map) |
|
|
998 | continue; |
970 | continue; |
999 | |
971 | |
1000 | if (pl->ob->speed_left > 0) |
972 | if (pl->ob->speed_left > 0) |
1001 | { |
973 | { |
1002 | if (handle_newcs_player (pl->ob)) |
974 | if (handle_newcs_player (pl->ob)) |
… | |
… | |
1016 | /* check for ST_PLAYING state so that we don't try to save off when |
988 | /* check for ST_PLAYING state so that we don't try to save off when |
1017 | * the player is logging in. |
989 | * the player is logging in. |
1018 | */ |
990 | */ |
1019 | if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) |
991 | if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) |
1020 | { |
992 | { |
1021 | /* Don't save the player on unholy ground. Instead, increase the |
|
|
1022 | * tick time so it will be about 10 seconds before we try and save |
|
|
1023 | * again. |
|
|
1024 | */ |
|
|
1025 | // if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { |
|
|
1026 | // pl->last_save_tick += 100; |
|
|
1027 | // } else { |
|
|
1028 | save_player (pl->ob, 1); |
993 | save_player (pl->ob, 1); |
1029 | pl->last_save_tick = pticks; |
994 | pl->last_save_tick = pticks; |
1030 | // } |
|
|
1031 | } |
995 | } |
1032 | #endif |
996 | #endif |
1033 | } /* end of for loop for all the players */ |
997 | } /* end of for loop for all the players */ |
1034 | } /* for flag */ |
998 | } /* for flag */ |
|
|
999 | |
1035 | for (pl = first_player; pl != NULL; pl = pl->next) |
1000 | for (player *pl = first_player; pl; pl = pl->next) |
1036 | { |
1001 | { |
1037 | if (map != NULL && (pl->ob == NULL || pl->ob->map != map)) |
|
|
1038 | continue; |
|
|
1039 | if (settings.casting_time == TRUE) |
1002 | if (settings.casting_time) |
1040 | { |
1003 | { |
1041 | if (pl->ob->casting_time > 0) |
1004 | if (pl->ob->casting_time > 0) |
1042 | { |
1005 | { |
1043 | pl->ob->casting_time--; |
1006 | pl->ob->casting_time--; |
1044 | pl->ob->start_holding = 1; |
1007 | pl->ob->start_holding = 1; |
1045 | } |
1008 | } |
|
|
1009 | |
1046 | /* set spell_state so we can update the range in stats field */ |
1010 | /* set spell_state so we can update the range in stats field */ |
1047 | if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) |
1011 | if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) |
1048 | { |
|
|
1049 | pl->ob->start_holding = 0; |
1012 | pl->ob->start_holding = 0; |
1050 | } |
1013 | } |
1051 | } |
1014 | |
1052 | do_some_living (pl->ob); |
1015 | do_some_living (pl->ob); |
1053 | /* draw(pl->ob); *//* updated in socket code */ |
|
|
1054 | } |
1016 | } |
1055 | } |
1017 | } |
1056 | |
1018 | |
1057 | void |
1019 | static void |
1058 | process_players2 (maptile *map) |
1020 | process_players2 () |
1059 | { |
1021 | { |
1060 | player *pl; |
|
|
1061 | |
|
|
1062 | /* Then check if any players should use weapon-speed instead of speed */ |
1022 | /* Then check if any players should use weapon-speed instead of speed */ |
1063 | for (pl = first_player; pl != NULL; pl = pl->next) |
1023 | for (player *pl = first_player; pl; pl = pl->next) |
1064 | { |
1024 | { |
1065 | if (map != NULL) |
|
|
1066 | { |
|
|
1067 | if (pl->ob == NULL || QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1068 | continue; |
|
|
1069 | else if (pl->loading != NULL) /* Player is blocked */ |
|
|
1070 | pl->ob->speed_left -= pl->ob->speed; |
|
|
1071 | if (pl->ob->map != map) |
|
|
1072 | continue; |
|
|
1073 | } |
|
|
1074 | |
|
|
1075 | /* The code that did weapon_sp handling here was out of place - |
1025 | /* The code that did weapon_sp handling here was out of place - |
1076 | * this isn't called until after the player has finished there |
1026 | * this isn't called until after the player has finished there |
1077 | * actions, and is thus out of place. All we do here is bounds |
1027 | * actions, and is thus out of place. All we do here is bounds |
1078 | * checking. |
1028 | * checking. |
1079 | */ |
1029 | */ |
… | |
… | |
1085 | /* This needs to be here - if the player is running, we need to |
1035 | /* This needs to be here - if the player is running, we need to |
1086 | * clear this each tick, but new commands are not being received |
1036 | * clear this each tick, but new commands are not being received |
1087 | * so execute_newserver_command() is never called |
1037 | * so execute_newserver_command() is never called |
1088 | */ |
1038 | */ |
1089 | pl->has_hit = 0; |
1039 | pl->has_hit = 0; |
1090 | |
|
|
1091 | } |
1040 | } |
1092 | else if (pl->ob->speed_left > pl->ob->speed) |
1041 | else if (pl->ob->speed_left > pl->ob->speed) |
1093 | pl->ob->speed_left = pl->ob->speed; |
1042 | pl->ob->speed_left = pl->ob->speed; |
1094 | } |
1043 | } |
1095 | } |
1044 | } |
1096 | |
1045 | |
1097 | void |
1046 | void |
1098 | process_events (maptile *map) |
1047 | process_events () |
1099 | { |
1048 | { |
1100 | object *op; |
1049 | object *op; |
1101 | |
1050 | |
1102 | static object *marker; |
1051 | static object *marker; |
|
|
1052 | |
1103 | if (!marker) |
1053 | if (!marker) |
1104 | marker = get_object (); |
1054 | marker = object::create (); |
1105 | |
1055 | |
1106 | process_players1 (map); |
1056 | process_players1 (); |
1107 | |
1057 | |
1108 | marker->active_next = active_objects; |
1058 | marker->active_next = active_objects; |
1109 | |
1059 | |
1110 | if (marker->active_next) |
1060 | if (marker->active_next) |
1111 | marker->active_next->active_prev = marker; |
1061 | marker->active_next->active_prev = marker; |
… | |
… | |
1153 | * around. |
1103 | * around. |
1154 | */ |
1104 | */ |
1155 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1105 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1156 | { |
1106 | { |
1157 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1107 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1158 | dump_object (op); |
1108 | char *dump = dump_object (op); |
1159 | LOG (llevError, errmsg); |
1109 | LOG (llevError, dump); |
1160 | free_object (op); |
1110 | free (dump); |
|
|
1111 | op->destroy (); |
1161 | continue; |
1112 | continue; |
1162 | } |
1113 | } |
1163 | |
1114 | |
1164 | if (!op->speed) |
1115 | if (!op->speed) |
1165 | { |
1116 | { |
1166 | LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); |
1117 | LOG (llevError, "BUG: process_events(): Object %s has no speed, " |
|
|
1118 | "but is on active list\n", &op->arch->name); |
1167 | update_ob_speed (op); |
1119 | update_ob_speed (op); |
1168 | continue; |
1120 | continue; |
1169 | } |
1121 | } |
1170 | |
1122 | |
1171 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) |
1123 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP) |
1172 | { |
1124 | { |
1173 | LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); |
1125 | LOG (llevError, "BUG: process_events(): Object without map or " |
|
|
1126 | "inventory is on active list: %s (%d)\n", &op->name, op->count); |
1174 | op->speed = 0; |
1127 | op->speed = 0; |
1175 | update_ob_speed (op); |
1128 | update_ob_speed (op); |
1176 | continue; |
1129 | continue; |
1177 | } |
1130 | } |
1178 | |
1131 | |
1179 | if (map != NULL && op->map != map) |
|
|
1180 | continue; |
|
|
1181 | |
|
|
1182 | /* Animate the object. Bug of feature that andim_speed |
1132 | /* Animate the object. Bug or feature that anim_speed |
1183 | * is based on ticks, and not the creatures speed? |
1133 | * is based on ticks, and not the creatures speed? |
1184 | */ |
1134 | */ |
1185 | if (op->anim_speed && op->last_anim >= op->anim_speed) |
1135 | if (op->anim_speed && op->last_anim >= op->anim_speed) |
1186 | { |
1136 | { |
1187 | if ((op->type == PLAYER) || (op->type == MONSTER)) |
1137 | if ((op->type == PLAYER) || (op->type == MONSTER)) |
… | |
… | |
1228 | if (marker->active_prev != NULL) |
1178 | if (marker->active_prev != NULL) |
1229 | marker->active_prev->active_next = NULL; |
1179 | marker->active_prev->active_next = NULL; |
1230 | else |
1180 | else |
1231 | active_objects = NULL; |
1181 | active_objects = NULL; |
1232 | |
1182 | |
1233 | process_players2 (map); |
1183 | process_players2 (); |
1234 | } |
1184 | } |
1235 | |
1185 | |
1236 | void |
1186 | void |
1237 | clean_tmp_files (void) |
1187 | clean_tmp_files (void) |
1238 | { |
1188 | { |
… | |
… | |
1242 | |
1192 | |
1243 | /* We save the maps - it may not be intuitive why, but if there are unique |
1193 | /* We save the maps - it may not be intuitive why, but if there are unique |
1244 | * items, we need to save the map so they get saved off. Perhaps we should |
1194 | * items, we need to save the map so they get saved off. Perhaps we should |
1245 | * just make a special function that only saves the unique items. |
1195 | * just make a special function that only saves the unique items. |
1246 | */ |
1196 | */ |
1247 | for (m = first_map; m != NULL; m = next) |
1197 | for (m = first_map; m; m = next) |
1248 | { |
1198 | { |
1249 | next = m->next; |
1199 | next = m->next; |
|
|
1200 | |
1250 | if (m->in_memory == MAP_IN_MEMORY) |
1201 | if (m->in_memory == MAP_IN_MEMORY) |
1251 | { |
1202 | { |
1252 | /* If we want to reuse the temp maps, swap it out (note that will also |
1203 | /* If we want to reuse the temp maps, swap it out (note that will also |
1253 | * update the log file. Otherwise, save the map (mostly for unique item |
1204 | * update the log file. |
1254 | * stuff). Note that the clean_tmp_map is called after the end of |
|
|
1255 | * the for loop but is in the #else bracket. IF we are recycling the maps, |
|
|
1256 | * we certainly don't want the temp maps removed. |
|
|
1257 | */ |
1205 | */ |
1258 | |
1206 | |
1259 | /* XXX The above comment is dead wrong */ |
|
|
1260 | if (settings.recycle_tmp_maps == TRUE) |
|
|
1261 | swap_map (m); |
1207 | swap_map (m); |
1262 | else |
|
|
1263 | { |
|
|
1264 | new_save_map (m, 0); /* note we save here into a overlay map */ |
|
|
1265 | clean_tmp_map (m); |
|
|
1266 | } |
1208 | } |
1267 | } |
|
|
1268 | } |
1209 | } |
|
|
1210 | |
1269 | write_todclock (); /* lets just write the clock here */ |
1211 | write_todclock (); /* lets just write the clock here */ |
1270 | } |
1212 | } |
1271 | |
1213 | |
1272 | /* clean up everything before exiting */ |
1214 | /* clean up everything before exiting */ |
1273 | void |
1215 | void |
… | |
… | |
1299 | * cleanup. We also leave that loop to actually handle the freeing |
1241 | * cleanup. We also leave that loop to actually handle the freeing |
1300 | * of the data. |
1242 | * of the data. |
1301 | */ |
1243 | */ |
1302 | if (pl->ob->type != DEAD_OBJECT) |
1244 | if (pl->ob->type != DEAD_OBJECT) |
1303 | { |
1245 | { |
1304 | pl->socket.status = Ns_Dead; |
1246 | pl->socket->status = Ns_Dead; |
1305 | |
1247 | |
1306 | /* If a hidden dm dropped connection do not create |
1248 | /* If a hidden dm dropped connection do not create |
1307 | * inconsistencies by showing that they have left the game |
1249 | * inconsistencies by showing that they have left the game |
1308 | */ |
1250 | */ |
1309 | if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) |
1251 | if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) |
1310 | && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD)) |
1252 | && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD)) |
1311 | { |
1253 | { |
1312 | if (pl->ob->map) |
1254 | if (pl->ob->map) |
1313 | { |
1255 | { |
1314 | INVOKE_PLAYER (LOGOUT, pl); |
1256 | INVOKE_PLAYER (LOGOUT, pl); |
1315 | LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host); |
1257 | LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket->host); |
1316 | } |
1258 | } |
1317 | |
1259 | |
1318 | char buf[MAX_BUF]; |
1260 | char buf[MAX_BUF]; |
1319 | |
1261 | |
1320 | sprintf (buf, "%s left the game.", &pl->ob->name); |
1262 | sprintf (buf, "%s left the game.", &pl->ob->name); |
… | |
… | |
1396 | extern unsigned long todtick; |
1338 | extern unsigned long todtick; |
1397 | |
1339 | |
1398 | void |
1340 | void |
1399 | do_specials (void) |
1341 | do_specials (void) |
1400 | { |
1342 | { |
1401 | |
|
|
1402 | #ifdef WATCHDOG |
|
|
1403 | if (!(pticks % 503)) |
|
|
1404 | watchdog (); |
|
|
1405 | #endif |
|
|
1406 | |
|
|
1407 | if (!(pticks % PTICKS_PER_CLOCK)) |
1343 | if (!(pticks % PTICKS_PER_CLOCK)) |
1408 | tick_the_clock (); |
1344 | tick_the_clock (); |
1409 | |
1345 | |
1410 | if (!(pticks % 7)) |
1346 | if (!(pticks % 7)) |
1411 | shstr::gc (); |
1347 | shstr::gc (); |
… | |
… | |
1414 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1350 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1415 | |
1351 | |
1416 | if (!(pticks % 2503)) |
1352 | if (!(pticks % 2503)) |
1417 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1353 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1418 | |
1354 | |
1419 | if (!(pticks % 2521)) |
|
|
1420 | metaserver_update (); /* 2500 ticks is about 5 minutes */ |
|
|
1421 | |
|
|
1422 | if (!(pticks % 5003)) |
1355 | if (!(pticks % 5003)) |
1423 | write_book_archive (); |
1356 | write_book_archive (); |
1424 | |
1357 | |
1425 | if (!(pticks % 5009)) |
1358 | if (!(pticks % 5009)) |
1426 | clean_friendly_list (); |
1359 | clean_friendly_list (); |
… | |
… | |
1435 | void |
1368 | void |
1436 | server_tick () |
1369 | server_tick () |
1437 | { |
1370 | { |
1438 | nroferrors = 0; |
1371 | nroferrors = 0; |
1439 | |
1372 | |
|
|
1373 | // first do the user visible stuff |
1440 | doeric_server (); |
1374 | doeric_server (); |
1441 | INVOKE_GLOBAL (CLOCK); |
1375 | INVOKE_GLOBAL (CLOCK); |
1442 | process_events (NULL); /* "do" something with objects with speed */ |
1376 | process_events (); /* "do" something with objects with speed */ |
1443 | flush_sockets (); |
1377 | flush_sockets (); |
|
|
1378 | |
|
|
1379 | // then do some bookkeeping, should not really be here |
1444 | check_active_maps (); /* Removes unused maps after a certain timeout */ |
1380 | check_active_maps (); /* Removes unused maps after a certain timeout */ |
1445 | do_specials (); /* Routines called from time to time. */ |
1381 | do_specials (); /* Routines called from time to time. */ |
1446 | object::free_mortals (); |
1382 | object::free_mortals (); |
1447 | |
1383 | |
1448 | ++pticks; |
1384 | ++pticks; |