Dispatch GC EXP before game loading
This commit is contained in:
@@ -33,6 +33,60 @@ const char* BATTLE_TABLE_DISCONNECT_HOOK_NAME = "battle_table_state";
|
||||
const char* QUEST_BARRIER_DISCONNECT_HOOK_NAME = "quest_barrier";
|
||||
const char* ADD_NEXT_CLIENT_DISCONNECT_HOOK_NAME = "add_next_game_client";
|
||||
|
||||
|
||||
static void dispatch_gc_v3_exp_patch_for_lobby(shared_ptr<Client> c, shared_ptr<Lobby> l) {
|
||||
if (c->version() != Version::GC_V3) {
|
||||
return;
|
||||
}
|
||||
if (!c->check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL)) {
|
||||
return;
|
||||
}
|
||||
if (!c->login || !c->login->account) {
|
||||
return;
|
||||
}
|
||||
if (!c->login->account->auto_patches_enabled.count("PsoPeepsGCEXP_enabled")) {
|
||||
return;
|
||||
}
|
||||
if (!l || !l->is_game()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* episode_str = nullptr;
|
||||
switch (l->episode) {
|
||||
case Episode::EP1:
|
||||
episode_str = "ep1";
|
||||
break;
|
||||
case Episode::EP2:
|
||||
episode_str = "ep2";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
auto server_state = c->require_server_state();
|
||||
|
||||
string key = "PsoPeepsGCEXP_internal_";
|
||||
key += std::to_string(server_state->psopeeps_gc_exp_multiplier);
|
||||
key += "x_";
|
||||
key += episode_str;
|
||||
|
||||
void* lobby_token = l.get();
|
||||
if ((c->last_psopeeps_gc_exp_lobby == lobby_token) &&
|
||||
(c->last_psopeeps_gc_exp_key == key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
auto fn = server_state->client_functions->get(key, c->specific_version);
|
||||
send_function_call(c->channel, c->enabled_flags, fn);
|
||||
c->enabled_flags |= fn->client_flag;
|
||||
c->last_psopeeps_gc_exp_lobby = lobby_token;
|
||||
c->last_psopeeps_gc_exp_key = key;
|
||||
} catch (const out_of_range&) {
|
||||
c->log.warning_f("GC V3 EXP dispatcher could not find client function {}", key);
|
||||
}
|
||||
}
|
||||
|
||||
static string bb_test_taint_filename(shared_ptr<Client> c) {
|
||||
return c->character_filename() + ".test-tainted";
|
||||
}
|
||||
@@ -3163,6 +3217,7 @@ static void on_10_game_menu(shared_ptr<Client> c, uint32_t item_id, const std::s
|
||||
}
|
||||
switch (game->join_error_for_client(c, &password)) {
|
||||
case Lobby::JoinError::ALLOWED:
|
||||
dispatch_gc_v3_exp_patch_for_lobby(c, game);
|
||||
if (!s->change_client_lobby(c, game)) {
|
||||
throw logic_error("client cannot join game after all preconditions satisfied");
|
||||
}
|
||||
@@ -5290,6 +5345,7 @@ static asio::awaitable<void> on_C1_PC(shared_ptr<Client> c, Channel::Message& ms
|
||||
}
|
||||
auto game = create_game_generic(s, c, cmd.name.decode(c->language()), cmd.password.decode(c->language()), Episode::EP1, mode, cmd.difficulty, true);
|
||||
if (game) {
|
||||
dispatch_gc_v3_exp_patch_for_lobby(c, game);
|
||||
s->change_client_lobby(c, game);
|
||||
c->set_flag(Client::Flag::LOADING);
|
||||
c->log.info_f("LOADING flag set");
|
||||
@@ -5372,6 +5428,7 @@ static asio::awaitable<void> on_0C_C1_E7_EC(shared_ptr<Client> c, Channel::Messa
|
||||
}
|
||||
|
||||
if (game) {
|
||||
dispatch_gc_v3_exp_patch_for_lobby(c, game);
|
||||
s->change_client_lobby(c, game);
|
||||
c->set_flag(Client::Flag::LOADING);
|
||||
c->log.info_f("LOADING flag set");
|
||||
@@ -5428,6 +5485,7 @@ static asio::awaitable<void> on_C1_BB(shared_ptr<Client> c, Channel::Message& ms
|
||||
|
||||
auto game = create_game_generic(s, c, cmd.name.decode(c->language()), cmd.password.decode(c->language()), episode, mode, cmd.difficulty);
|
||||
if (game) {
|
||||
dispatch_gc_v3_exp_patch_for_lobby(c, game);
|
||||
s->change_client_lobby(c, game);
|
||||
c->set_flag(Client::Flag::LOADING);
|
||||
c->log.info_f("LOADING flag set");
|
||||
|
||||
Reference in New Issue
Block a user