/*! * @brief 保存フロア用テンポラリファイルを削除する / Kill temporal files * @details Should be called just before the game quit. * @return なし */ void clear_saved_floor_files(void) { char floor_savefile[1024]; int i; #ifdef SET_UID # ifdef SECURE /* Get "games" permissions */ beGames(); # endif #endif for (i = 0; i < MAX_SAVED_FLOORS; i++) { saved_floor_type *sf_ptr = &saved_floors[i]; /* No temporal file */ if (!sf_ptr->floor_id) continue; if (sf_ptr->floor_id == p_ptr->floor_id) continue; /* File name */ sprintf(floor_savefile, "%s.F%02d", savefile, i); /* Grab permissions */ safe_setuid_grab(); /* Simply kill the temporal file */ (void)fd_kill(floor_savefile); /* Drop permissions */ safe_setuid_drop(); } #ifdef SET_UID # ifdef SECURE /* Drop "games" permissions */ bePlayer(); # endif #endif }
/*! * @brief ファイルロック処理 * @return なし */ void remove_loc(void) { #ifdef VERIFY_SAVEFILE char temp[1024]; #endif /* VERIFY_SAVEFILE */ #ifdef SET_UID # ifdef SECURE /* Get "games" permissions */ beGames(); # endif /* SECURE */ #endif /* SET_UID */ #ifdef VERIFY_SAVEFILE /* Lock on savefile */ strcpy(temp, savefile); strcat(temp, ".lok"); /* Remove lock file */ fd_kill(temp); #endif /* VERIFY_SAVEFILE */ #ifdef SET_UID # ifdef SECURE /* Drop "games" permissions */ bePlayer(); # endif /* SECURE */ #endif /* SET_UID */ }
/*! * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data * @param sf_ptr 保存フロア参照ポインタ * @param mode 保存オプション * @return なし */ bool save_floor(saved_floor_type *sf_ptr, u32b mode) { FILE *old_fff = NULL; byte old_xor_byte = 0; u32b old_v_stamp = 0; u32b old_x_stamp = 0; char floor_savefile[1024]; int fd = -1; bool ok = FALSE; if (!(mode & SLF_SECOND)) { #ifdef SET_UID # ifdef SECURE /* Get "games" permissions */ beGames(); # endif #endif } /* We have one file already opened */ else { /* Backup original values */ old_fff = fff; old_xor_byte = xor_byte; old_v_stamp = v_stamp; old_x_stamp = x_stamp; } /* New savefile */ sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id); /* Grab permissions */ safe_setuid_grab(); /* Remove it */ fd_kill(floor_savefile); /* Drop permissions */ safe_setuid_drop(); /* Attempt to save the player */ /* No file yet */ fff = NULL; /* File type is "SAVE" */ FILE_TYPE(FILE_TYPE_SAVE); /* Grab permissions */ safe_setuid_grab(); /* Create the savefile */ fd = fd_make(floor_savefile, 0644); /* Drop permissions */ safe_setuid_drop(); /* File is okay */ if (fd >= 0) { /* Close the "fd" */ (void)fd_close(fd); /* Grab permissions */ safe_setuid_grab(); /* Open the savefile */ fff = my_fopen(floor_savefile, "wb"); /* Drop permissions */ safe_setuid_drop(); /* Successful open */ if (fff) { /* Write the savefile */ if (save_floor_aux(sf_ptr)) ok = TRUE; /* Attempt to close it */ if (my_fclose(fff)) ok = FALSE; } /* Remove "broken" files */ if (!ok) { /* Grab permissions */ safe_setuid_grab(); (void)fd_kill(floor_savefile); /* Drop permissions */ safe_setuid_drop(); } } if (!(mode & SLF_SECOND)) { #ifdef SET_UID # ifdef SECURE /* Drop "games" permissions */ bePlayer(); # endif #endif } /* We have one file already opened */ else { /* Restore original values */ fff = old_fff; xor_byte = old_xor_byte; v_stamp = old_v_stamp; x_stamp = old_x_stamp; } /* Return the result */ return ok; }
/*! * @brief セーブデータ書き込みのメインルーチン / * Attempt to save the player in a savefile * @return 成功すればtrue */ bool save_player(void) { int result = FALSE; char safe[1024]; #ifdef SET_UID # ifdef SECURE /* Get "games" permissions */ beGames(); # endif #endif /* New savefile */ strcpy(safe, savefile); strcat(safe, ".new"); #ifdef VM /* Hack -- support "flat directory" usage on VM/ESA */ strcpy(safe, savefile); strcat(safe, "n"); #endif /* VM */ /* Grab permissions */ safe_setuid_grab(); /* Remove it */ fd_kill(safe); /* Drop permissions */ safe_setuid_drop(); update_playtime(); /* Attempt to save the player */ if (save_player_aux(safe)) { char temp[1024]; /* Old savefile */ strcpy(temp, savefile); strcat(temp, ".old"); #ifdef VM /* Hack -- support "flat directory" usage on VM/ESA */ strcpy(temp, savefile); strcat(temp, "o"); #endif /* VM */ /* Grab permissions */ safe_setuid_grab(); /* Remove it */ fd_kill(temp); /* Preserve old savefile */ fd_move(savefile, temp); /* Activate new savefile */ fd_move(safe, savefile); /* Remove preserved savefile */ fd_kill(temp); /* Drop permissions */ safe_setuid_drop(); /* Hack -- Pretend the character was loaded */ character_loaded = TRUE; #ifdef VERIFY_SAVEFILE /* Lock on savefile */ strcpy(temp, savefile); strcat(temp, ".lok"); /* Grab permissions */ safe_setuid_grab(); /* Remove lock file */ fd_kill(temp); /* Drop permissions */ safe_setuid_drop(); #endif /* Success */ result = TRUE; } #ifdef SET_UID # ifdef SECURE /* Drop "games" permissions */ bePlayer(); # endif #endif /* Return the result */ return (result); }
/*! * @brief 保存フロア配列を初期化する / Initialize saved_floors array. * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除する。 * @details Make sure that old temporal files are not remaining as gurbages. * @return なし */ void init_saved_floors(bool force) { char floor_savefile[1024]; int i; int fd = -1; BIT_FLAGS mode = 0644; #ifdef SET_UID # ifdef SECURE /* Get "games" permissions */ beGames(); # endif #endif for (i = 0; i < MAX_SAVED_FLOORS; i++) { saved_floor_type *sf_ptr = &saved_floors[i]; /* File name */ sprintf(floor_savefile, "%s.F%02d", savefile, i); /* Grab permissions */ safe_setuid_grab(); /* Try to create the file */ fd = fd_make(floor_savefile, mode); /* Drop permissions */ safe_setuid_drop(); /* Failed! */ if (fd < 0) { if (!force) { #ifdef JP msg_print("エラー:古いテンポラリ・ファイルが残っています。"); msg_print("短愚蛮怒を二重に起動していないか確認してください。"); msg_print("過去に短愚蛮怒がクラッシュした場合は一時ファイルを"); msg_print("強制的に削除して実行を続けられます。"); if (!get_check("強制的に削除してもよろしいですか?")) quit("実行中止"); #else msg_print("Error: There are old temporal files."); msg_print("Make sure you are not running two game processes simultaneously."); msg_print("If the temporal files are garbages of old crashed process, "); msg_print("you can delete it safely."); if (!get_check("Do you delete old temporal files? ")) quit("Aborted."); #endif force = TRUE; } } else { /* Close the "fd" */ (void)fd_close(fd); } /* Grab permissions */ safe_setuid_grab(); /* Simply kill the temporal file */ (void)fd_kill(floor_savefile); /* Drop permissions */ safe_setuid_drop(); sf_ptr->floor_id = 0; } /* No floor_id used yet (No.0 is reserved to indicate non existance) */ max_floor_id = 1; /* vist_mark is from 1 */ latest_visit_mark = 1; /* A sign to mark temporal files */ saved_floor_file_sign = (u32b)time(NULL); /* No next floor yet */ new_floor_id = 0; /* No change floor mode yet */ change_floor_mode = 0; #ifdef SET_UID # ifdef SECURE /* Drop "games" permissions */ bePlayer(); # endif #endif }