use spectator text field for something
This commit is contained in:
+4
-4
@@ -153,10 +153,10 @@ void Lobby::add_client(shared_ptr<Client> c, ssize_t required_client_id) {
|
||||
if (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) {
|
||||
auto watched_l = this->watched_lobby.lock();
|
||||
if (watched_l) {
|
||||
send_ep3_update_spectator_count(watched_l);
|
||||
send_ep3_update_game_metadata(watched_l);
|
||||
}
|
||||
} else {
|
||||
send_ep3_update_spectator_count(this->shared_from_this());
|
||||
send_ep3_update_game_metadata(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,10 +194,10 @@ void Lobby::remove_client(shared_ptr<Client> c) {
|
||||
if (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) {
|
||||
auto watched_l = this->watched_lobby.lock();
|
||||
if (watched_l) {
|
||||
send_ep3_update_spectator_count(watched_l);
|
||||
send_ep3_update_game_metadata(watched_l);
|
||||
}
|
||||
} else {
|
||||
send_ep3_update_spectator_count(this->shared_from_this());
|
||||
send_ep3_update_game_metadata(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-2
@@ -3568,7 +3568,7 @@ static void on_6F(shared_ptr<Client> c, uint16_t, uint32_t, const string& data)
|
||||
watched_lobby->ep3_server->send_commands_for_joining_spectator(
|
||||
c->channel, c->flags & Client::Flag::IS_EP3_TRIAL_EDITION);
|
||||
}
|
||||
send_ep3_update_spectator_count(watched_lobby);
|
||||
send_ep3_update_game_metadata(watched_lobby);
|
||||
}
|
||||
|
||||
// If there are more players to bring in, try to do so
|
||||
@@ -3576,6 +3576,26 @@ static void on_6F(shared_ptr<Client> c, uint16_t, uint32_t, const string& data)
|
||||
add_next_game_client(l);
|
||||
}
|
||||
|
||||
static void on_99_GC(shared_ptr<Client> c, uint16_t, uint32_t, const string& data) {
|
||||
check_size_v(data.size(), 0);
|
||||
|
||||
// This is an odd place to send 6xB4x52, but there's a reason for it. If the
|
||||
// client receives 6xB4x52 while it's loading the battlefield, it won't set
|
||||
// the spectator count or top-bar text. But the client doesn't send anything
|
||||
// when it's done loading the battlefield, so we have to have some other way
|
||||
// of knowing when it's ready. We do this by sending a B1 (server time)
|
||||
// command immediately after the E8 (join spectator team) command, which
|
||||
// allows us to delay sending the 6xB4x52 until the server responds with a 99
|
||||
// command after loading is done.
|
||||
auto l = c->lobby.lock();
|
||||
if (l && l->is_game() && (l->episode == Episode::EP3) && (l->flags & Lobby::Flag::IS_SPECTATOR_TEAM)) {
|
||||
auto watched_l = l->watched_lobby.lock();
|
||||
if (watched_l) {
|
||||
send_ep3_update_game_metadata(watched_l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void on_D0_V3_BB(shared_ptr<Client> c, uint16_t, uint32_t, const string& data) {
|
||||
const auto& cmd = check_size_t<SC_TradeItems_D0_D3>(data);
|
||||
|
||||
@@ -4129,7 +4149,7 @@ static on_command_t handlers[0x100][6] = {
|
||||
/* 96 */ {nullptr, on_96, on_96, on_96, on_96, nullptr},
|
||||
/* 97 */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
|
||||
/* 98 */ {nullptr, on_61_98, on_61_98, on_61_98, on_61_98, on_61_98},
|
||||
/* 99 */ {nullptr, on_ignored, on_ignored, on_ignored, on_ignored, on_ignored},
|
||||
/* 99 */ {nullptr, on_ignored, on_ignored, on_99_GC, on_ignored, on_ignored},
|
||||
/* 9A */ {nullptr, on_9A, on_9A, on_9A, nullptr, nullptr},
|
||||
/* 9B */ {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
|
||||
/* 9C */ {nullptr, on_9C, on_9C, on_9C, on_9C, nullptr},
|
||||
|
||||
+46
-20
@@ -2645,38 +2645,64 @@ void send_ep3_tournament_match_result(shared_ptr<Lobby> l, uint32_t meseta_rewar
|
||||
}
|
||||
}
|
||||
|
||||
void send_ep3_update_spectator_count(shared_ptr<Lobby> l) {
|
||||
G_SetGameMetadata_GC_Ep3_6xB4x52 cmd;
|
||||
void send_ep3_update_game_metadata(shared_ptr<Lobby> l) {
|
||||
size_t total_spectators = 0;
|
||||
for (auto watcher_l : l->watcher_lobbies) {
|
||||
for (auto c : watcher_l->clients) {
|
||||
cmd.total_spectators += (c.get() != nullptr);
|
||||
total_spectators += (c.get() != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make s available here so we can apply masking if needed (perhaps by
|
||||
// adding a weak_ptr in Lobby... it'd be dumb to require s to be passed in to
|
||||
// this function just to check a behavior flag)
|
||||
auto s = l->require_server_state();
|
||||
|
||||
// Note: We can't use send_command_t(l, ...) here because that would send the
|
||||
// same command to l and to all watcher lobbies. The commands should have
|
||||
// different values depending on who's in each watcher lobby, so we have to
|
||||
// manually send to each client here.
|
||||
for (auto c : l->clients) {
|
||||
if (c) {
|
||||
send_command_t(c, 0xC9, 0x00, cmd);
|
||||
{
|
||||
G_SetGameMetadata_GC_Ep3_6xB4x52 cmd;
|
||||
cmd.total_spectators = total_spectators;
|
||||
if (!(s->ep3_behavior_flags & Episode3::BehaviorFlag::DISABLE_MASKING)) {
|
||||
uint8_t mask_key = (random_object<uint32_t>() % 0xFF) + 1;
|
||||
set_mask_for_ep3_game_command(&cmd, sizeof(cmd), mask_key);
|
||||
}
|
||||
}
|
||||
for (auto watcher_l : l->watcher_lobbies) {
|
||||
cmd.local_spectators = 0;
|
||||
for (auto c : watcher_l->clients) {
|
||||
cmd.local_spectators += (c.get() != nullptr);
|
||||
}
|
||||
for (auto c : watcher_l->clients) {
|
||||
// Note: We can't use send_command_t(l, ...) here because that would send
|
||||
// the same command to l and to all watcher lobbies. The commands should
|
||||
// have different values depending on who's in each watcher lobby, so we
|
||||
// have to manually send to each client here.
|
||||
for (auto c : l->clients) {
|
||||
if (c) {
|
||||
send_command_t(c, 0xC9, 0x00, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!l->watcher_lobbies.empty()) {
|
||||
string text;
|
||||
auto tourn = l->tournament_match ? l->tournament_match->tournament.lock() : 0;
|
||||
if (l->tournament_match && tourn) {
|
||||
if (tourn->get_final_match() == l->tournament_match) {
|
||||
text = string_printf("Viewing final match of tournament %s", tourn->get_name().c_str());
|
||||
} else {
|
||||
text = string_printf(
|
||||
"Viewing match in round %zu of tournament %s",
|
||||
l->tournament_match->round_num, tourn->get_name().c_str());
|
||||
}
|
||||
} else {
|
||||
text = "Viewing battle in game " + encode_sjis(l->name);
|
||||
}
|
||||
add_color_inplace(text);
|
||||
for (auto watcher_l : l->watcher_lobbies) {
|
||||
G_SetGameMetadata_GC_Ep3_6xB4x52 cmd;
|
||||
cmd.local_spectators = 0;
|
||||
for (auto c : watcher_l->clients) {
|
||||
cmd.local_spectators += (c.get() != nullptr);
|
||||
}
|
||||
cmd.total_spectators = total_spectators;
|
||||
cmd.text_size = text.size();
|
||||
cmd.text = text;
|
||||
if (!(s->ep3_behavior_flags & Episode3::BehaviorFlag::DISABLE_MASKING)) {
|
||||
uint8_t mask_key = (random_object<uint32_t>() % 0xFF) + 1;
|
||||
set_mask_for_ep3_game_command(&cmd, sizeof(cmd), mask_key);
|
||||
}
|
||||
send_command_t(watcher_l, 0xC9, 0x00, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_mask_for_ep3_game_command(void* vdata, size_t size, uint8_t mask_key) {
|
||||
|
||||
+1
-1
@@ -338,7 +338,7 @@ void send_ep3_tournament_details(
|
||||
std::shared_ptr<const Episode3::Tournament> t);
|
||||
void send_ep3_game_details(
|
||||
std::shared_ptr<Client> c, std::shared_ptr<Lobby> l);
|
||||
void send_ep3_update_spectator_count(std::shared_ptr<Lobby> l);
|
||||
void send_ep3_update_game_metadata(std::shared_ptr<Lobby> l);
|
||||
void send_ep3_card_auction(std::shared_ptr<Lobby> l);
|
||||
void send_ep3_disband_watcher_lobbies(std::shared_ptr<Lobby> primary_l);
|
||||
|
||||
|
||||
@@ -613,6 +613,12 @@ size_t add_color_inplace(T* a, size_t max_chars) {
|
||||
return d - orig_d;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_color_inplace(std::basic_string<T>& s) {
|
||||
size_t new_size = add_color_inplace(s.data(), s.size());
|
||||
s.resize(new_size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_color(StringWriter& w, const T* src, size_t max_input_chars) {
|
||||
for (size_t x = 0; (x < max_input_chars) && *src; x++) {
|
||||
|
||||
Reference in New Issue
Block a user