add get_player_card

This commit is contained in:
Martin Michelsen
2022-10-01 00:53:56 -07:00
parent 27bccc5571
commit 125c8f910c
5 changed files with 149 additions and 70 deletions
+26 -1
View File
@@ -243,6 +243,31 @@ static void server_command_get_self_card(shared_ptr<ServerState>, shared_ptr<Lob
send_guild_card(c, c); send_guild_card(c, c);
} }
static void proxy_command_get_player_card(shared_ptr<ServerState>,
ProxyServer::LinkedSession& session, const std::u16string& u16args) {
string args = encode_sjis(u16args);
bool any_card_sent = false;
for (const auto& p : session.lobby_players) {
if (!p.name.empty() && args == p.name) {
send_guild_card(session.client_channel, p.guild_card_number, decode_sjis(p.name), u"", u"", p.section_id, p.char_class);
any_card_sent = true;
}
}
if (!any_card_sent) {
try {
size_t index = stoull(args, nullptr, 0);
const auto& p = session.lobby_players.at(index);
if (!p.name.empty()) {
send_guild_card(session.client_channel, p.guild_card_number, decode_sjis(p.name), u"", u"", p.section_id, p.char_class);
}
} catch (const exception& e) {
send_text_message_printf(session.client_channel, "Error: %s", e.what());
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Lobby commands // Lobby commands
@@ -935,7 +960,7 @@ static const unordered_map<u16string, ChatCommandDefinition> chat_commands({
{u"$dbgid", {server_command_dbgid, nullptr, u"Usage:\ndbgid"}}, {u"$dbgid", {server_command_dbgid, nullptr, u"Usage:\ndbgid"}},
{u"$edit", {server_command_edit, nullptr , u"Usage:\nedit <stat> <value>"}}, {u"$edit", {server_command_edit, nullptr , u"Usage:\nedit <stat> <value>"}},
{u"$event", {server_command_lobby_event, proxy_command_lobby_event, u"Usage:\nevent <name>"}}, {u"$event", {server_command_lobby_event, proxy_command_lobby_event, u"Usage:\nevent <name>"}},
{u"$gc", {server_command_get_self_card, nullptr, u"Usage:\ngc"}}, {u"$gc", {server_command_get_self_card, proxy_command_get_player_card, u"Usage:\ngc"}},
{u"$infhp", {server_command_infinite_hp, proxy_command_infinite_hp, u"Usage:\ninfhp"}}, {u"$infhp", {server_command_infinite_hp, proxy_command_infinite_hp, u"Usage:\ninfhp"}},
{u"$inftp", {server_command_infinite_tp, proxy_command_infinite_tp, u"Usage:\ninftp"}}, {u"$inftp", {server_command_infinite_tp, proxy_command_infinite_tp, u"Usage:\ninftp"}},
{u"$item", {server_command_item, proxy_command_item, u"Usage:\nitem <item-code>"}}, {u"$item", {server_command_item, proxy_command_item, u"Usage:\nitem <item-code>"}},
+19 -14
View File
@@ -1002,13 +1002,14 @@ static HandlerResult S_65_67_68(shared_ptr<ServerState>,
num_replacements++; num_replacements++;
modified = true; modified = true;
} }
session.lobby_players[index].guild_card_number = cmd.entries[x].lobby_data.guild_card; auto& p = session.lobby_players[index];
p.guild_card_number = cmd.entries[x].lobby_data.guild_card;
ptext<char, 0x10> name = cmd.entries[x].disp.name; ptext<char, 0x10> name = cmd.entries[x].disp.name;
session.lobby_players[index].name = name; p.name = name;
p.section_id = cmd.entries[x].disp.section_id;
p.char_class = cmd.entries[x].disp.char_class;
session.log.info("Added lobby player: (%zu) %" PRIu32 " %s", session.log.info("Added lobby player: (%zu) %" PRIu32 " %s",
index, index, p.guild_card_number, p.name.c_str());
session.lobby_players[index].guild_card_number,
session.lobby_players[index].name.c_str());
} }
} }
if (num_replacements > 1) { if (num_replacements > 1) {
@@ -1057,17 +1058,18 @@ static HandlerResult S_64(shared_ptr<ServerState>,
cmd->lobby_data[x].guild_card = session.license->serial_number; cmd->lobby_data[x].guild_card = session.license->serial_number;
modified = true; modified = true;
} }
session.lobby_players[x].guild_card_number = cmd->lobby_data[x].guild_card; auto& p = session.lobby_players[x];
p.guild_card_number = cmd->lobby_data[x].guild_card;
if (cmd_ep3) { if (cmd_ep3) {
ptext<char, 0x10> name = cmd_ep3->players_ep3[x].disp.name; ptext<char, 0x10> name = cmd_ep3->players_ep3[x].disp.name;
session.lobby_players[x].name = name; p.name = name;
p.section_id = cmd_ep3->players_ep3[x].disp.section_id;
p.char_class = cmd_ep3->players_ep3[x].disp.char_class;
} else { } else {
session.lobby_players[x].name.clear(); p.name.clear();
} }
session.log.info("Added lobby player: (%zu) %" PRIu32 " %s", session.log.info("Added lobby player: (%zu) %" PRIu32 " %s",
x, x, p.guild_card_number, p.name.c_str());
session.lobby_players[x].guild_card_number,
session.lobby_players[x].name.c_str());
} }
if (session.override_section_id >= 0) { if (session.override_section_id >= 0) {
@@ -1098,8 +1100,9 @@ static HandlerResult S_66_69(shared_ptr<ServerState>,
if (index >= session.lobby_players.size()) { if (index >= session.lobby_players.size()) {
session.log.warning("Lobby leave command references missing position"); session.log.warning("Lobby leave command references missing position");
} else { } else {
session.lobby_players[index].guild_card_number = 0; auto& p = session.lobby_players[index];
session.lobby_players[index].name.clear(); p.guild_card_number = 0;
p.name.clear();
session.log.info("Removed lobby player (%zu)", index); session.log.info("Removed lobby player (%zu)", index);
} }
update_leader_id(session, cmd.leader_id); update_leader_id(session, cmd.leader_id);
@@ -1197,7 +1200,9 @@ template <typename SendGuildCardCmdT>
static HandlerResult C_6x(shared_ptr<ServerState> s, static HandlerResult C_6x(shared_ptr<ServerState> s,
ProxyServer::LinkedSession& session, uint16_t command, uint32_t flag, string& data) { ProxyServer::LinkedSession& session, uint16_t command, uint32_t flag, string& data) {
if (session.license && !data.empty()) { if (session.license && !data.empty()) {
if (data[0] == 0x06) { // On BB, the 6x06 command is blank - the server generates the actual Guild
// Card contents and sends it to the target client.
if (data[0] == 0x06 && session.version != GameVersion::BB) {
auto& cmd = check_size_t<SendGuildCardCmdT>(data); auto& cmd = check_size_t<SendGuildCardCmdT>(data);
if (cmd.guild_card_number == session.license->serial_number) { if (cmd.guild_card_number == session.license->serial_number) {
cmd.guild_card_number = session.remote_guild_card_number; cmd.guild_card_number = session.remote_guild_card_number;
+3 -1
View File
@@ -78,7 +78,9 @@ public:
struct LobbyPlayer { struct LobbyPlayer {
uint32_t guild_card_number; uint32_t guild_card_number;
std::string name; std::string name;
LobbyPlayer() : guild_card_number(0) { } uint8_t section_id;
uint8_t char_class;
LobbyPlayer() : guild_card_number(0), section_id(0), char_class(0) { }
}; };
std::vector<LobbyPlayer> lobby_players; std::vector<LobbyPlayer> lobby_players;
size_t lobby_client_id; size_t lobby_client_id;
+64 -25
View File
@@ -770,54 +770,93 @@ void send_card_search_result(
template <typename CmdT> template <typename CmdT>
void send_guild_card_dc_pc_v3_t(shared_ptr<Client> c, shared_ptr<Client> source) { void send_guild_card_dc_pc_v3_t(
Channel& ch,
uint32_t guild_card_number,
const u16string& name,
const u16string& description,
uint8_t section_id,
uint8_t char_class) {
CmdT cmd; CmdT cmd;
cmd.subcommand = 0x06; cmd.subcommand = 0x06;
cmd.size = sizeof(CmdT) / 4; cmd.size = sizeof(CmdT) / 4;
cmd.unused = 0x0000; cmd.unused = 0x0000;
cmd.player_tag = 0x00010000; cmd.player_tag = 0x00010000;
cmd.guild_card_number = source->license->serial_number; cmd.guild_card_number = guild_card_number;
cmd.name = source->game_data.player()->disp.name; cmd.name = name;
remove_language_marker_inplace(cmd.name); remove_language_marker_inplace(cmd.name);
cmd.description = source->game_data.player()->guild_card_description; cmd.description = description;
cmd.present = 1; cmd.present = 1;
cmd.present2 = 1; cmd.present2 = 1;
cmd.section_id = source->game_data.player()->disp.section_id; cmd.section_id = section_id;
cmd.char_class = source->game_data.player()->disp.char_class; cmd.char_class = char_class;
send_command_t(c, 0x62, c->lobby_client_id, cmd); ch.send(0x60, 0x00, &cmd, sizeof(cmd));
} }
void send_guild_card_bb(shared_ptr<Client> c, shared_ptr<Client> source) { static void send_guild_card_bb(
Channel& ch,
uint32_t guild_card_number,
const u16string& name,
const u16string& team_name,
const u16string& description,
uint8_t section_id,
uint8_t char_class) {
G_SendGuildCard_BB_6x06 cmd; G_SendGuildCard_BB_6x06 cmd;
cmd.subcommand = 0x06; cmd.subcommand = 0x06;
cmd.size = sizeof(cmd) / 4; cmd.size = sizeof(cmd) / 4;
cmd.unused = 0x0000; cmd.unused = 0x0000;
cmd.guild_card_number = source->license->serial_number; cmd.guild_card_number = guild_card_number;
cmd.name = remove_language_marker(source->game_data.player()->disp.name); cmd.name = remove_language_marker(name);
cmd.team_name = remove_language_marker(source->game_data.account()->team_name); cmd.team_name = remove_language_marker(team_name);
cmd.description = source->game_data.player()->guild_card_description; cmd.description = description;
cmd.present = 1; cmd.present = 1;
cmd.present2 = 1; cmd.present2 = 1;
cmd.section_id = source->game_data.player()->disp.section_id; cmd.section_id = section_id;
cmd.char_class = source->game_data.player()->disp.char_class; cmd.char_class = char_class;
send_command_t(c, 0x62, c->lobby_client_id, cmd); ch.send(0x60, 0x00, &cmd, sizeof(cmd));
} }
void send_guild_card(shared_ptr<Client> c, shared_ptr<Client> source) { void send_guild_card(
if (c->version() == GameVersion::DC) { Channel& ch,
send_guild_card_dc_pc_v3_t<G_SendGuildCard_DC_6x06>(c, source); uint32_t guild_card_number,
} else if (c->version() == GameVersion::PC) { const u16string& name,
send_guild_card_dc_pc_v3_t<G_SendGuildCard_PC_6x06>(c, source); const u16string& team_name,
} else if ((c->version() == GameVersion::GC) || const u16string& description,
(c->version() == GameVersion::XB)) { uint8_t section_id,
send_guild_card_dc_pc_v3_t<G_SendGuildCard_V3_6x06>(c, source); uint8_t char_class) {
} else if (c->version() == GameVersion::BB) { if (ch.version == GameVersion::DC) {
send_guild_card_bb(c, source); send_guild_card_dc_pc_v3_t<G_SendGuildCard_DC_6x06>(
ch, guild_card_number, name, description, section_id, char_class);
} else if (ch.version == GameVersion::PC) {
send_guild_card_dc_pc_v3_t<G_SendGuildCard_PC_6x06>(
ch, guild_card_number, name, description, section_id, char_class);
} else if ((ch.version == GameVersion::GC) ||
(ch.version == GameVersion::XB)) {
send_guild_card_dc_pc_v3_t<G_SendGuildCard_V3_6x06>(
ch, guild_card_number, name, description, section_id, char_class);
} else if (ch.version == GameVersion::BB) {
send_guild_card_bb(
ch, guild_card_number, name, team_name, description, section_id, char_class);
} else { } else {
throw logic_error("unimplemented versioned command"); throw logic_error("unimplemented versioned command");
} }
} }
void send_guild_card(shared_ptr<Client> c, shared_ptr<Client> source) {
if (!source->license) {
throw runtime_error("source player does not have a license");
}
uint32_t guild_card_number = source->license->serial_number;
u16string name = source->game_data.player()->disp.name;
u16string description = source->game_data.player()->guild_card_description;
uint8_t section_id = source->game_data.player()->disp.section_id;
uint8_t char_class = source->game_data.player()->disp.char_class;
send_guild_card(
c->channel, guild_card_number, name, u"", description, section_id, char_class);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
+8
View File
@@ -182,6 +182,14 @@ void send_card_search_result(
std::shared_ptr<Client> result, std::shared_ptr<Client> result,
std::shared_ptr<Lobby> result_lobby); std::shared_ptr<Lobby> result_lobby);
void send_guild_card(
Channel& ch,
uint32_t guild_card_number,
const u16string& name,
const u16string& team_name,
const u16string& description,
uint8_t section_id,
uint8_t char_class);
void send_guild_card(std::shared_ptr<Client> c, std::shared_ptr<Client> source); void send_guild_card(std::shared_ptr<Client> c, std::shared_ptr<Client> source);
void send_menu(std::shared_ptr<Client> c, const std::u16string& menu_name, void send_menu(std::shared_ptr<Client> c, const std::u16string& menu_name,
uint32_t menu_id, const std::vector<MenuItem>& items, bool is_info_menu = false); uint32_t menu_id, const std::vector<MenuItem>& items, bool is_info_menu = false);