Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clone exit and not removing the player on the death screen #1117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,7 @@ void Player::onRemoveCreature(Creature* creature, bool isLogout) {
guild->removeMember(this);
}

g_game().removePlayerUniqueLogin(this);
loginPosition = getPosition();
lastLogout = time(nullptr);
SPDLOG_INFO("{} has logged out", getName());
Expand Down
1 change: 1 addition & 0 deletions src/creatures/players/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,7 @@ class Player final : public Creature, public Cylinder {
int8_t offlineTrainingSkill = SKILL_NONE;
int32_t offlineTrainingTime = 0;
int32_t idleTime = 0;
int32_t m_deathTime = 0;
uint32_t coinBalance = 0;
uint32_t coinTransferableBalance = 0;
uint16_t expBoostStamina = 0;
Expand Down
33 changes: 33 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9126,6 +9126,39 @@ void Game::removePlayerUniqueLogin(Player* player) {
m_uniqueLoginPlayerNames.erase(lowercase_name);
}

void Game::playerCheckActivity(const std::string &playerName, int interval) {
Player* player = getPlayerUniqueLogin(playerName);
if (!player) {
return;
}

if (player->getIP() == 0) {
g_game().removePlayerUniqueLogin(playerName);
IOLoginData::updateOnlineStatus(player->guid, false);
SPDLOG_INFO("Player with name '{}' has logged out due to exited in death screen", player->getName());
player->disconnect();
return;
}

if (!player->isDead() || player->client == nullptr) {
return;
}

if (!player->isAccessPlayer()) {
player->m_deathTime += interval;
const int32_t kickAfterMinutes = g_configManager().getNumber(KICK_AFTER_MINUTES);
if (player->m_deathTime > (kickAfterMinutes * 60000) + 60000) {
SPDLOG_INFO("Player with name '{}' has logged out due to inactivity after death", player->getName());
g_game().removePlayerUniqueLogin(playerName);
IOLoginData::updateOnlineStatus(player->guid, false);
player->disconnect();
return;
}
}

g_scheduler().addEvent(createSchedulerTask(1000, std::bind(&Game::playerCheckActivity, this, playerName, interval)));
}

void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, uint32_t maxMoveItems /* = 0*/) {
Player* player = getPlayerByID(playerId);
if (!player) {
Expand Down
1 change: 1 addition & 0 deletions src/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ class Game {
* @param player A pointer to the Player object to remove.
*/
void removePlayerUniqueLogin(Player* player);
void playerCheckActivity(const std::string &playerName, int interval);

private:
std::map<uint32_t, int32_t> forgeMonsterEventIds;
Expand Down
4 changes: 2 additions & 2 deletions src/server/network/protocol/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class Protocol : public std::enable_shared_from_this<Protocol> {

protected:
void disconnect() const {
if (auto connection = getConnection();
connection != nullptr) {
if (auto connection = getConnection()) {
connection->close();
}
}

void enableXTEAEncryption() {
encryptionEnabled = true;
}
Expand Down
18 changes: 12 additions & 6 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ void ProtocolGame::AddItem(NetworkMessage &msg, const Item* item) {
void ProtocolGame::release() {
// dispatcher thread
if (player && player->client == shared_from_this()) {
g_game().removePlayerUniqueLogin(player);
player->client.reset();
player->decrementReferenceCounter();
player = nullptr;
Expand Down Expand Up @@ -407,20 +406,20 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS
foundPlayer->disconnect();
foundPlayer->isConnecting = true;

eventConnect = g_scheduler().addEvent(createSchedulerTask(1000, std::bind(&ProtocolGame::connect, getThis(), foundPlayer->getID(), operatingSystem)));
eventConnect = g_scheduler().addEvent(createSchedulerTask(1000, std::bind(&ProtocolGame::connect, getThis(), foundPlayer->getName(), operatingSystem)));
} else {
connect(foundPlayer->getID(), operatingSystem);
connect(foundPlayer->getName(), operatingSystem);
}
}
OutputMessagePool::getInstance().addProtocolToAutosend(shared_from_this());
sendBosstiaryCooldownTimer();
}

void ProtocolGame::connect(uint32_t playerId, OperatingSystem_t operatingSystem) {
void ProtocolGame::connect(const std::string &playerName, OperatingSystem_t operatingSystem) {
eventConnect = 0;

Player* foundPlayer = g_game().getPlayerByID(playerId);
if (!foundPlayer || foundPlayer->client) {
Player* foundPlayer = g_game().getPlayerUniqueLogin(playerName);
if (!foundPlayer) {
disconnectClient("You are already logged in.");
return;
}
Expand Down Expand Up @@ -655,6 +654,12 @@ void ProtocolGame::parsePacket(NetworkMessage &msg) {
}

if (player->isDead() || player->getHealth() <= 0) {
// Check player activity on death screen
if (m_playerDeathTime == 0) {
addGameTask(&Game::playerCheckActivity, player->getName(), 1000);
m_playerDeathTime++;
}

g_dispatcher().addTask(createTask(std::bind(&ProtocolGame::parsePacketDead, getThis(), recvbyte)));
return;
}
Expand Down Expand Up @@ -689,6 +694,7 @@ void ProtocolGame::parsePacketDead(uint8_t recvbyte) {

g_dispatcher().addTask(createTask(std::bind(&ProtocolGame::sendAddCreature, getThis(), player, player->getPosition(), 0, false)));
g_dispatcher().addTask(createTask(std::bind(&ProtocolGame::addBless, getThis())));
resetPlayerDeathTime();
return;
}

Expand Down
8 changes: 7 additions & 1 deletion src/server/network/protocol/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ProtocolGame final : public Protocol {
ProtocolGame_ptr getThis() {
return std::static_pointer_cast<ProtocolGame>(shared_from_this());
}
void connect(uint32_t playerId, OperatingSystem_t operatingSystem);
void connect(const std::string &playerName, OperatingSystem_t operatingSystem);
void disconnectClient(const std::string &message) const;
void writeToOutputBuffer(const NetworkMessage &msg);

Expand Down Expand Up @@ -490,6 +490,12 @@ class ProtocolGame final : public Protocol {

// Hazard system
void reloadHazardSystemIcon(uint16_t reference);

uint8_t m_playerDeathTime = 0;

void resetPlayerDeathTime() {
m_playerDeathTime = 0;
}
};

#endif // SRC_SERVER_NETWORK_PROTOCOL_PROTOCOLGAME_H_