fix disconnect when sending mail to offline user

This commit is contained in:
Martin Michelsen
2022-09-22 16:55:58 -07:00
parent 8afc952294
commit a1c86189e4
+14 -2
View File
@@ -2079,8 +2079,18 @@ static void on_simple_mail(shared_ptr<ServerState> s, shared_ptr<Client> c,
throw logic_error("invalid game version"); throw logic_error("invalid game version");
} }
auto target = s->find_client(nullptr, to_guild_card_number); shared_ptr<Client> target;
try {
target = s->find_client(nullptr, to_guild_card_number);
} catch (const out_of_range&) { }
if (!target) {
// TODO: We should store pending messages for accounts somewhere, and send
// them when the player signs on again. We should also persist the player's
// autoreply setting when they're offline and use it if appropriate here.
send_text_message(c, u"$C6Player is offline");
} else {
// If the sender is blocked, don't forward the mail // If the sender is blocked, don't forward the mail
for (size_t y = 0; y < 30; y++) { for (size_t y = 0; y < 30; y++) {
if (target->game_data.account()->blocked_senders.data()[y] == c->license->serial_number) { if (target->game_data.account()->blocked_senders.data()[y] == c->license->serial_number) {
@@ -2088,7 +2098,8 @@ static void on_simple_mail(shared_ptr<ServerState> s, shared_ptr<Client> c,
} }
} }
// If the target has auto-reply enabled, send the autoreply // If the target has auto-reply enabled, send the autoreply. Note that we also
// forward the message in this case.
if (!target->game_data.player()->auto_reply.empty()) { if (!target->game_data.player()->auto_reply.empty()) {
send_simple_mail(c, target->license->serial_number, send_simple_mail(c, target->license->serial_number,
target->game_data.player()->disp.name, target->game_data.player()->disp.name,
@@ -2101,6 +2112,7 @@ static void on_simple_mail(shared_ptr<ServerState> s, shared_ptr<Client> c,
c->license->serial_number, c->license->serial_number,
c->game_data.player()->disp.name, c->game_data.player()->disp.name,
message); message);
}
} }