diff options
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/char.cpp | 3 | ||||
-rw-r--r-- | src/char/int_party.cpp | 84 | ||||
-rw-r--r-- | src/char/int_storage.cpp | 15 | ||||
-rw-r--r-- | src/char/int_storage.hpp | 4 | ||||
-rw-r--r-- | src/char/inter.cpp | 12 |
5 files changed, 44 insertions, 74 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp index 4f52663..98a2178 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -1506,7 +1506,7 @@ void parse_tologin(Session *ls) CharKey *k = &cp.key; CharData& cd = *cp.data.get(); CharData *c = &cd; - Storage *s = account2storage(k->account_id); + Borrowed<Storage> s = account2storage(k->account_id); int changes = 0; #define FIX(v) if (v == source_id) {v = dest_id; ++changes; } for (IOff0 j : IOff0::iter()) @@ -1520,7 +1520,6 @@ void parse_tologin(Session *ls) FIX(c->head_mid); FIX(c->head_bottom); - if (s) { for (SOff0 j : SOff0::iter()) { diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index 96a3f13..0ce827e 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -171,8 +171,7 @@ void inter_party_init(void) } PartyMost pm; - PartyPair pp; - pp.party_most = ± + PartyPair pp{PartyId(), borrow(pm)}; if (extract(line, &pp) && pp.party_id) { if (party_newid < next(pp.party_id)) @@ -212,9 +211,7 @@ int inter_party_save(void) } for (auto& pair : party_db) { - PartyPair tmp; - tmp.party_id = pair.first; - tmp.party_most = &pair.second; + PartyPair tmp{pair.first, borrow(pair.second)}; inter_party_save_sub(tmp, fp); } @@ -223,23 +220,21 @@ int inter_party_save(void) // パーティ名検索用 static -void search_partyname_sub(PartyPair p, PartyName str, PartyPair *dst) +void search_partyname_sub(PartyPair p, PartyName str, Borrowed<Option<PartyPair>> dst) { if (p->name == str) - *dst = p; + *dst = Some(p); } // パーティ名検索 static -PartyPair search_partyname(PartyName str) +Option<PartyPair> search_partyname(PartyName str) { - PartyPair p; + Option<PartyPair> p = None; for (auto& pair : party_db) { - PartyPair tmp; - tmp.party_id = pair.first; - tmp.party_most = &pair.second; - search_partyname_sub(tmp, str, &p); + PartyPair tmp{pair.first, borrow(pair.second)}; + search_partyname_sub(tmp, str, borrow(p)); } return p; @@ -315,9 +310,7 @@ void party_check_conflict(PartyId party_id, AccountId account_id, CharName nick) { for (auto& pair : party_db) { - PartyPair tmp; - tmp.party_id = pair.first; - tmp.party_most = &pair.second; + PartyPair tmp{pair.first, borrow(pair.second)}; party_check_conflict_sub(tmp, party_id, account_id, nick); } @@ -328,11 +321,11 @@ void party_check_conflict(PartyId party_id, AccountId account_id, CharName nick) // パーティ作成可否 static -void mapif_party_created(Session *s, AccountId account_id, const PartyPair p) +void mapif_party_created(Session *s, AccountId account_id, Option<PartyPair> p_) { Packet_Fixed<0x3820> fixed_20; fixed_20.account_id = account_id; - if (p) + if OPTION_IS_SOME(p, p_) { fixed_20.error = 0; fixed_20.party_id = p.party_id; @@ -492,22 +485,21 @@ void mapif_parse_CreateParty(Session *s, AccountId account_id, PartyName name, C if (!name.is_print()) { PRINTF("int_party: illegal party name [%s]\n"_fmt, name); - mapif_party_created(s, account_id, PartyPair()); + mapif_party_created(s, account_id, None); return; } } - if (search_partyname(name)) + if (search_partyname(name).is_some()) { PRINTF("int_party: same name party exists [%s]\n"_fmt, name); - mapif_party_created(s, account_id, PartyPair()); + mapif_party_created(s, account_id, None); return; } + PartyMost p {}; - PartyPair pp; - pp.party_most = &p; party_newid = next(party_newid); - pp.party_id = party_newid; + PartyPair pp{party_newid, borrow(p)}; p.name = name; p.exp = 0; p.item = 0; @@ -521,7 +513,7 @@ void mapif_parse_CreateParty(Session *s, AccountId account_id, PartyName name, C party_db.insert(pp.party_id, p); // pointer to noncanonical version - mapif_party_created(s, account_id, pp); + mapif_party_created(s, account_id, Some(pp)); mapif_party_info(s, pp); } @@ -529,11 +521,9 @@ void mapif_parse_CreateParty(Session *s, AccountId account_id, PartyName name, C static void mapif_parse_PartyInfo(Session *s, PartyId party_id) { - PartyPair p; - p.party_id = party_id; - p.party_most = party_db.search(party_id); - if (p) - mapif_party_info(s, p); + Option<P<PartyMost>> maybe_party_most = party_db.search(party_id); + if OPTION_IS_SOME(party_most, maybe_party_most) + mapif_party_info(s, PartyPair{party_id, party_most}); else mapif_party_noinfo(s, party_id); } @@ -543,14 +533,13 @@ static void mapif_parse_PartyAddMember(Session *s, PartyId party_id, AccountId account_id, CharName nick, MapName map, int lv) { - PartyPair p; - p.party_id = party_id; - p.party_most = party_db.search(party_id); - if (!p) - { - mapif_party_memberadded(s, party_id, account_id, 1); - return; - } + Option<P<PartyMost>> maybe_party_most = party_db.search(party_id); + P<PartyMost> party_most = TRY_UNWRAP(maybe_party_most, + { + mapif_party_memberadded(s, party_id, account_id, 1); + return; + }); + PartyPair p{party_id, party_most}; for (int i = 0; i < MAX_PARTY; i++) { @@ -585,11 +574,7 @@ static void mapif_parse_PartyChangeOption(Session *s, PartyId party_id, AccountId account_id, int exp, int item) { - PartyPair p; - p.party_id = party_id; - p.party_most = party_db.search(party_id); - if (!p) - return; + PartyPair p{party_id, TRY_UNWRAP(party_db.search(party_id), return)}; p->exp = exp; int flag = 0; @@ -607,11 +592,8 @@ void mapif_parse_PartyChangeOption(Session *s, PartyId party_id, AccountId accou // パーティ脱退要求 void mapif_parse_PartyLeave(Session *, PartyId party_id, AccountId account_id) { - PartyPair p; - p.party_id = party_id; - p.party_most = party_db.search(party_id); - if (!p) - return; + PartyPair p{party_id, TRY_UNWRAP(party_db.search(party_id), return)}; + for (int i = 0; i < MAX_PARTY; i++) { if (p->member[i].account_id != account_id) @@ -630,11 +612,7 @@ static void mapif_parse_PartyChangeMap(Session *s, PartyId party_id, AccountId account_id, MapName map, int online, int lv) { - PartyPair p; - p.party_id = party_id; - p.party_most = party_db.search(party_id); - if (!p) - return; + PartyPair p{party_id, TRY_UNWRAP(party_db.search(party_id), return)}; for (int i = 0; i < MAX_PARTY; i++) { diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index 76eff34..a2b0bc7 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -117,14 +117,10 @@ bool extract(XString str, Storage *p) } // アカウントから倉庫データインデックスを得る(新規倉庫追加可能) -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; } @@ -196,7 +192,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 +236,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); } diff --git a/src/char/int_storage.hpp b/src/char/int_storage.hpp index b8ec9db..0a80027 100644 --- a/src/char/int_storage.hpp +++ b/src/char/int_storage.hpp @@ -22,6 +22,8 @@ #include "fwd.hpp" +#include "../compat/fwd.hpp" + #include "../strings/fwd.hpp" #include "../net/fwd.hpp" @@ -34,7 +36,7 @@ namespace tmwa void inter_storage_init(void); int inter_storage_save(void); void inter_storage_delete(AccountId account_id); -Storage *account2storage(AccountId account_id); +Borrowed<Storage> account2storage(AccountId account_id); RecvResult inter_storage_parse_frommap(Session *ms, uint16_t); diff --git a/src/char/inter.cpp b/src/char/inter.cpp index f757991..2efcc83 100644 --- a/src/char/inter.cpp +++ b/src/char/inter.cpp @@ -264,12 +264,12 @@ void mapif_account_reg(Session *s, AccountId account_id, const std::vector<Packe static void mapif_account_reg_reply(Session *s, AccountId account_id) { - struct accreg *reg = accreg_db.search(account_id); + Option<P<struct accreg>> reg_ = accreg_db.search(account_id); Packet_Head<0x3804> head_04; head_04.account_id = account_id; std::vector<Packet_Repeat<0x3804>> repeat_04; - if (reg) + if OPTION_IS_SOME(reg, reg_) { repeat_04.resize(reg->reg_num); assert (reg->reg_num < ACCOUNT_REG_NUM); @@ -408,13 +408,9 @@ RecvResult mapif_parse_AccReg(Session *s) if (rv != RecvResult::Complete) return rv; - struct accreg *reg = accreg_db.search(head.account_id); - - if (reg == nullptr) + P<struct accreg> reg = accreg_db.init(head.account_id); { - AccountId account_id = head.account_id; - reg = accreg_db.init(account_id); - reg->account_id = account_id; + reg->account_id = head.account_id; } size_t jlim = std::min(repeat.size(), ACCOUNT_REG_NUM); |