Skip to content

Commit

Permalink
add more log messages around login commands; closes #583
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Dec 4, 2024
1 parent 760cec9 commit 3424d64
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 64 deletions.
23 changes: 23 additions & 0 deletions src/Account.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,29 @@ void Account::delete_file() const {
remove(filename.c_str());
}

string Login::str() const {
string ret = phosg::string_printf("Account:%08" PRIX32, this->account->account_id);
if (this->account_was_created) {
ret += " (new)";
}
if (this->dc_nte_license) {
ret += phosg::string_printf(" via DC NTE serial number %s", this->dc_nte_license->serial_number.c_str());
} else if (this->dc_license) {
ret += phosg::string_printf(" via DC serial number %08" PRIX32, this->dc_license->serial_number);
} else if (this->pc_license) {
ret += phosg::string_printf(" via PC serial number %08" PRIX32, this->pc_license->serial_number);
} else if (this->gc_license) {
ret += phosg::string_printf(" via GC serial number %010" PRIu32, this->gc_license->serial_number);
} else if (this->xb_license) {
ret += phosg::string_printf(" via XB user ID %016" PRIX64, this->xb_license->user_id);
} else if (this->bb_license) {
ret += phosg::string_printf(" via BB username %s", this->bb_license->username.c_str());
} else {
ret += phosg::string_printf(" artificially");
}
return ret;
}

size_t AccountIndex::count() const {
shared_lock g(this->lock);
return this->by_account_id.size();
Expand Down
2 changes: 2 additions & 0 deletions src/Account.hh
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ struct Login {
std::shared_ptr<GCLicense> gc_license;
std::shared_ptr<XBLicense> xb_license;
std::shared_ptr<BBLicense> bb_license;

std::string str() const;
};

class AccountIndex {
Expand Down
12 changes: 11 additions & 1 deletion src/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ void Client::update_channel_name() {
auto player = this->character(false, false);
if (player) {
string name_str = player->disp.name.decode(this->language());
this->channel.name = phosg::string_printf("C-%" PRIX64 " (%s) @ %s", this->id, name_str.c_str(), ip_str.c_str());
size_t level = player->disp.stats.level + 1;
this->channel.name = phosg::string_printf("C-%" PRIX64 " (%s Lv.%zu) @ %s", this->id, name_str.c_str(), level, ip_str.c_str());
} else {
this->channel.name = phosg::string_printf("C-%" PRIX64 " @ %s", this->id, ip_str.c_str());
}
this->log.info("Channel name updated from player data: %s", this->channel.name.c_str());
}

void Client::reschedule_save_game_data_event() {
Expand Down Expand Up @@ -479,6 +481,14 @@ void Client::suspend_timeouts() {
this->log.info("Timeouts suspended");
}

void Client::set_login(shared_ptr<Login> login) {
this->login = login;
if (this->log.should_log(phosg::LogLevel::INFO)) {
string login_str = this->login->str();
this->log.info("Login: %s", login_str.c_str());
}
}

void Client::create_battle_overlay(shared_ptr<const BattleRules> rules, shared_ptr<const LevelTable> level_table) {
this->overlay_character_data = make_shared<PSOBBCharacterFile>(*this->character(true, false));

Expand Down
3 changes: 1 addition & 2 deletions src/Client.hh
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ public:

void suspend_timeouts();

const std::string& get_bb_username() const;
void set_bb_username(const std::string& bb_username);
void set_login(std::shared_ptr<Login> login);

void create_battle_overlay(std::shared_ptr<const BattleRules> rules, std::shared_ptr<const LevelTable> level_table);
void create_challenge_overlay(Version version, size_t template_index, std::shared_ptr<const LevelTable> level_table);
Expand Down
3 changes: 0 additions & 3 deletions src/PatchServer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ private:

static void dispatch_idle_timeout(evutil_socket_t, short, void* ctx);
void idle_timeout();

const std::string& get_bb_username() const;
void set_bb_username(const std::string& bb_username);
};

struct ListeningSocket {
Expand Down
34 changes: 21 additions & 13 deletions src/ProxyServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ std::shared_ptr<ServerState> ProxyServer::UnlinkedSession::require_server_state(
return this->require_server()->state;
}

void ProxyServer::UnlinkedSession::set_login(std::shared_ptr<Login> login) {
this->login = login;
if (this->log.should_log(phosg::LogLevel::INFO)) {
string login_str = this->login->str();
this->log.info("Login: %s", login_str.c_str());
}
}

void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint32_t, std::string& data) {
auto* ses = reinterpret_cast<UnlinkedSession*>(ch.context_obj);
auto server = ses->require_server();
Expand All @@ -298,7 +306,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
ses->log.info("Version changed to DC_NTE");
ses->config.specific_version = SPECIFIC_VERSION_DC_NTE;
const auto& cmd = check_size_t<C_Login_DCNTE_8B>(data, sizeof(C_LoginExtended_DCNTE_8B));
ses->login = s->account_index->from_dc_nte_credentials(cmd.serial_number.decode(), cmd.access_key.decode(), false);
ses->set_login(s->account_index->from_dc_nte_credentials(cmd.serial_number.decode(), cmd.access_key.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
Expand All @@ -310,8 +318,8 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
ses->config.specific_version = SPECIFIC_VERSION_DC_V1_INDETERMINATE;
}
const auto& cmd = check_size_t<C_LoginV1_DC_93>(data);
ses->login = s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false);
ses->set_login(s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
Expand All @@ -322,16 +330,16 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
ses->log.info("Version changed to GC_NTE");
ses->channel.version = Version::GC_NTE;
ses->config.specific_version = SPECIFIC_VERSION_GC_NTE;
ses->login = s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false);
ses->set_login(s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false));
} else { // DC V2
ses->log.info("Version changed to DC_V2");
ses->channel.version = Version::DC_V2;
if (specific_version_is_indeterminate(ses->config.specific_version)) {
ses->config.specific_version = SPECIFIC_VERSION_DC_V2_INDETERMINATE;
}
ses->login = s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false);
ses->set_login(s->account_index->from_dc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false));
}
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
Expand All @@ -349,8 +357,8 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
throw runtime_error("command is not 9D");
}
const auto& cmd = check_size_t<C_Login_DC_PC_GC_9D>(data, sizeof(C_LoginExtended_PC_9D));
ses->login = s->account_index->from_pc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false);
ses->set_login(s->account_index->from_pc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), cmd.name.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
Expand All @@ -363,8 +371,8 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
// We should only get a 9E while the session is unlinked
if (command == 0x9E) {
const auto& cmd = check_size_t<C_Login_GC_9E>(data, sizeof(C_LoginExtended_GC_9E));
ses->login = s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false);
ses->set_login(s->account_index->from_gc_credentials(
stoul(cmd.serial_number.decode(), nullptr, 16), cmd.access_key.decode(), nullptr, cmd.name.decode(), false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
Expand All @@ -388,7 +396,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
string xb_gamertag = cmd.serial_number.decode();
uint64_t xb_user_id = stoull(cmd.access_key.decode(), nullptr, 16);
uint64_t xb_account_id = cmd.netloc.account_id;
ses->login = s->account_index->from_xb_credentials(xb_gamertag, xb_user_id, xb_account_id, false);
ses->set_login(s->account_index->from_xb_credentials(xb_gamertag, xb_user_id, xb_account_id, false));
ses->sub_version = cmd.sub_version;
ses->channel.language = cmd.language;
ses->character_name = cmd.name.decode(ses->channel.language);
Expand All @@ -412,7 +420,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3
}
const auto& cmd = check_size_t<C_LoginBase_BB_93>(data, 0xFFFF);
string password = cmd.password.decode();
ses->login = s->account_index->from_bb_credentials(cmd.username.decode(), &password, s->allow_unregistered_users);
ses->set_login(s->account_index->from_bb_credentials(cmd.username.decode(), &password, s->allow_unregistered_users));
ses->login_command_bb = std::move(data);
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ProxyServer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ private:
return this->channel.version;
}

void set_login(std::shared_ptr<Login> login);

void receive_and_process_commands();

static void on_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
Expand Down
Loading

0 comments on commit 3424d64

Please sign in to comment.