diff --git a/src/CommandFormats.hh b/src/CommandFormats.hh index a254d22c..9dcb241f 100644 --- a/src/CommandFormats.hh +++ b/src/CommandFormats.hh @@ -1031,14 +1031,18 @@ struct S_Unknown_PC_V3_80 { // uninitialized data for security reasons before forwarding and things seem to // work fine. -struct SC_SimpleMail_V3_81 { +template +struct SC_SimpleMail_81 { le_uint32_t player_tag; le_uint32_t from_guild_card_number; - ptext from_name; + ptext from_name; le_uint32_t to_guild_card_number; - ptext text; + ptext text; }; +struct SC_SimpleMail_PC_81 : SC_SimpleMail_81 { }; +struct SC_SimpleMail_V3_81 : SC_SimpleMail_81 { }; + // 82: Invalid command // 83 (S->C): Lobby menu diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index adf03ad9..7546e1b8 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -1724,15 +1724,25 @@ void process_choice_search(shared_ptr, shared_ptr c, void process_simple_mail(shared_ptr s, shared_ptr c, uint16_t, uint32_t, const string& data) { // 81 - if ((c->version != GameVersion::GC) && (c->version != GameVersion::XB)) { - // TODO: implement this for non-V3 + u16string message; + uint32_t to_guild_card_number; + if ((c->version == GameVersion::GC) || (c->version == GameVersion::XB)) { + const auto& cmd = check_size_t(data); + to_guild_card_number = cmd.to_guild_card_number; + message = decode_sjis(cmd.text); + + } else if (c->version == GameVersion::PC) { + const auto& cmd = check_size_t(data); + to_guild_card_number = cmd.to_guild_card_number; + message = cmd.text; + + } else { + // TODO send_text_message(c, u"$C6Simple Mail is not\nsupported yet on\nthis platform."); return; } - const auto& cmd = check_size_t(data); - - auto target = s->find_client(nullptr, cmd.to_guild_card_number); + auto target = s->find_client(nullptr, to_guild_card_number); // If the sender is blocked, don't forward the mail for (size_t y = 0; y < 30; y++) { @@ -1749,8 +1759,11 @@ void process_simple_mail(shared_ptr s, shared_ptr c, } // Forward the message - u16string msg = decode_sjis(cmd.text); - send_simple_mail(target, c->license->serial_number, c->game_data.player()->disp.name, msg); + send_simple_mail( + target, + c->license->serial_number, + c->game_data.player()->disp.name, + message); } diff --git a/src/SendCommands.cc b/src/SendCommands.cc index f6bb634b..abebfe54 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -556,9 +556,13 @@ void send_chat_message(shared_ptr c, uint32_t from_guild_card_number, send_header_text(c->channel, 0x06, from_guild_card_number, data, false); } -void send_simple_mail_v3(shared_ptr c, uint32_t from_guild_card_number, - const u16string& from_name, const u16string& text) { - SC_SimpleMail_V3_81 cmd; +template +void send_simple_mail_t( + shared_ptr c, + uint32_t from_guild_card_number, + const u16string& from_name, + const u16string& text) { + CmdT cmd; cmd.player_tag = 0x00010000; cmd.from_guild_card_number = from_guild_card_number; cmd.from_name = from_name; @@ -570,7 +574,11 @@ void send_simple_mail_v3(shared_ptr c, uint32_t from_guild_card_number, void send_simple_mail(shared_ptr c, uint32_t from_guild_card_number, const u16string& from_name, const u16string& text) { if ((c->version == GameVersion::GC) || (c->version == GameVersion::XB)) { - send_simple_mail_v3(c, from_guild_card_number, from_name, text); + send_simple_mail_t( + c, from_guild_card_number, from_name, text); + } else if (c->version == GameVersion::PC) { + send_simple_mail_t( + c, from_guild_card_number, from_name, text); } else { throw logic_error("unimplemented versioned command"); }