diff options
Diffstat (limited to 'src/char/int_storage.cpp')
-rw-r--r-- | src/char/int_storage.cpp | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index 76eff34..32af231 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -28,30 +28,30 @@ #include "../generic/db.hpp" #include "../io/cxxstdio.hpp" -#include "../io/cxxstdio_enums.hpp" +#include "../io/extract.hpp" #include "../io/lock.hpp" #include "../io/read.hpp" #include "../io/write.hpp" -#include "../net/packets.hpp" - #include "../proto2/char-map.hpp" -#include "../mmo/extract.hpp" -#include "../mmo/mmo.hpp" +#include "../mmo/cxxstdio_enums.hpp" + +#include "../high/extract_mmo.hpp" +#include "../high/mmo.hpp" + +#include "../wire/packets.hpp" + +#include "globals.hpp" +#include "inter_conf.hpp" #include "../poison.hpp" namespace tmwa { -// ファイル名のデフォルト -// inter_config_read()で再設定される -AString storage_txt = "save/storage.txt"_s; - -static -Map<AccountId, Storage> storage_db; - +namespace char_ +{ // 倉庫データを文字列に変換 static AString storage_tostr(Storage *p) @@ -90,10 +90,11 @@ AString storage_tostr(Storage *p) return AString(); return AString(str); } +} // namespace char_ // 文字列を倉庫データに変換 static -bool extract(XString str, Storage *p) +bool impl_extract(XString str, Storage *p) { std::vector<Item> storage_items; if (!extract(str, @@ -116,15 +117,13 @@ bool extract(XString str, Storage *p) return true; } +namespace char_ +{ // アカウントから倉庫データインデックスを得る(新規倉庫追加可能) -Storage *account2storage(AccountId account_id) +Borrowed<Storage> account2storage(AccountId account_id) { - Storage *s = storage_db.search(account_id); - if (s == nullptr) - { - s = storage_db.init(account_id); - s->account_id = account_id; - } + P<Storage> s = storage_db.init(account_id); + s->account_id = account_id; return s; } @@ -134,10 +133,10 @@ void inter_storage_init(void) { int c = 0; - io::ReadFile in(storage_txt); + io::ReadFile in(inter_conf.storage_txt); if (!in.is_open()) { - PRINTF("cant't read : %s\n"_fmt, storage_txt); + PRINTF("cant't read : %s\n"_fmt, inter_conf.storage_txt); return; } @@ -152,7 +151,7 @@ void inter_storage_init(void) else { PRINTF("int_storage: broken data [%s] line %d\n"_fmt, - storage_txt, c); + inter_conf.storage_txt, c); } c++; } @@ -170,12 +169,12 @@ void inter_storage_save_sub(Storage *data, io::WriteFile& fp) // 倉庫データを書き込む int inter_storage_save(void) { - io::WriteLock fp(storage_txt); + io::WriteLock fp(inter_conf.storage_txt); if (!fp.is_open()) { PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n"_fmt, - storage_txt); + inter_conf.storage_txt); return 1; } for (auto& pair : storage_db) @@ -196,7 +195,7 @@ void inter_storage_delete(AccountId account_id) static void mapif_load_storage(Session *ss, AccountId account_id) { - Storage *st = account2storage(account_id); + P<Storage> st = account2storage(account_id); Packet_Payload<0x3810> payload_10; payload_10.account_id = account_id; payload_10.storage = *st; @@ -240,11 +239,10 @@ RecvResult mapif_parse_SaveStorage(Session *ss) if (rv != RecvResult::Complete) return rv; - Storage *st; AccountId account_id = payload.account_id; { - st = account2storage(account_id); + P<Storage> st = account2storage(account_id); *st = payload.storage; mapif_save_storage_ack(ss, account_id); } @@ -273,4 +271,5 @@ RecvResult inter_storage_parse_frommap(Session *ms, uint16_t packet_id) } return rv; } +} // namespace char_ } // namespace tmwa |