Skip to content

Commit

Permalink
feat: login protection
Browse files Browse the repository at this point in the history
  • Loading branch information
murilo09 committed Jan 7, 2025
1 parent f253373 commit 3697df6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ maintainModeMessage = ""
-- NOTE: valid values for worldType are: "pvp", "no-pvp" and "pvp-enforced"
-- NOTE: removeBeginningWeaponAmmunition: spears, arrows, bolt have endless ammo (allows training for paladins)
-- NOTE: refundManaOnBeginningWeapons: wand of vortex and snakebite refund mana used (allows training for mages)
-- NOTE: loginProtectionTime in MS
worldType = "pvp"
hotkeyAimbotEnabled = true
protectionLevel = 7
Expand All @@ -47,6 +48,7 @@ monthKillsToRedSkull = 10
redSkullDuration = 1
blackSkullDuration = 3
orangeSkullDuration = 7
loginProtectionTime = 10 * 1000

cleanProtectionZones = false

Expand Down
1 change: 1 addition & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ enum ConfigKey_t : uint16_t {
ONSLAUGHT_CHANCE_FORMULA_C,
OPTIMIZE_DATABASE,
ORANGE_SKULL_DURATION,
LOGIN_PROTECTION_TIME,
OWNER_EMAIL,
OWNER_NAME,
PARALLELISM,
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ bool ConfigManager::load() {
loadIntConfig(L, MONTH_KILLS_TO_RED, "monthKillsToRedSkull", 10);
loadIntConfig(L, MULTIPLIER_ATTACKONFIST, "multiplierSpeedOnFist", 5);
loadIntConfig(L, ORANGE_SKULL_DURATION, "orangeSkullDuration", 7);
loadIntConfig(L, LOGIN_PROTECTION_TIME, "loginProtectionTime", 10000);
loadIntConfig(L, PARALLELISM, "parallelism", 2);
loadIntConfig(L, PARTY_LIST_MAX_DISTANCE, "partyListMaxDistance", 0);
loadIntConfig(L, PREY_BONUS_REROLL_PRICE, "preyBonusRerollPrice", 1);
Expand Down
4 changes: 4 additions & 0 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,10 @@ bool Monster::selectTarget(const std::shared_ptr<Creature> &creature) {
return false;
}

if (creature && creature->getPlayer()->isLoginProtected()) {
return false;
}

auto it = getTargetIterator(creature);
if (it == targetList.end()) {
// Target not found in our target list.
Expand Down
10 changes: 10 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,16 @@ bool Player::canDoPotionAction() const {
return nextPotionAction <= OTSYS_TIME();
}

void Player::setLoginProtection() {
loginProtectionTime = OTSYS_TIME() + g_configManager().getNumber(LOGIN_PROTECTION_TIME);
}
bool Player::isLoginProtected() const {
return loginProtectionTime > OTSYS_TIME();
}
void Player::resetLoginProtection() {
loginProtectionTime = 0;
}

void Player::cancelPush() {
if (actionTaskEventPush != 0) {
g_dispatcher().stopEvent(actionTaskEventPush);
Expand Down
5 changes: 5 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ class Player final : public Creature, public Cylinder, public Bankable {
void setNextPotionAction(int64_t time);
bool canDoPotionAction() const;

void setLoginProtection();
bool isLoginProtected() const;
void resetLoginProtection();

void cancelPush();

void setModuleDelay(uint8_t byteortype, int16_t delay);
Expand Down Expand Up @@ -1421,6 +1425,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
int64_t nextPotionAction = 0;
int64_t lastQuickLootNotification = 0;
int64_t lastWalking = 0;
int64_t loginProtectionTime = 0;
uint64_t asyncOngoingTasks = 0;

std::vector<Kill> unjustifiedKills;
Expand Down
10 changes: 10 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,7 @@ void Game::playerMove(uint32_t playerId, Direction direction) {
return;
}

player->resetLoginProtection();
player->resetIdleTime();
player->setNextWalkActionTask(nullptr);
player->cancelPush();
Expand All @@ -3518,6 +3519,7 @@ void Game::forcePlayerMove(uint32_t playerId, Direction direction) {
return;
}

player->resetLoginProtection();
player->resetIdleTime();
player->setNextWalkActionTask(nullptr);
player->cancelPush();
Expand Down Expand Up @@ -3693,6 +3695,7 @@ void Game::playerAutoWalk(uint32_t playerId, const std::vector<Direction> &listD
return;
}

player->resetLoginProtection();
player->resetIdleTime();
player->setNextWalkTask(nullptr);
player->startAutoWalk(listDir, false);
Expand All @@ -3709,6 +3712,7 @@ void Game::forcePlayerAutoWalk(uint32_t playerId, const std::vector<Direction> &
player->sendCancelTarget();
player->setFollowCreature(nullptr);

player->resetLoginProtection();
player->resetIdleTime();
player->setNextWalkTask(nullptr);

Expand Down Expand Up @@ -3842,6 +3846,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f
return;
}

player->resetLoginProtection();
player->resetIdleTime();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(nullptr);
Expand Down Expand Up @@ -3963,6 +3968,7 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo
return;
}

player->resetLoginProtection();
player->resetIdleTime();
player->setNextActionTask(nullptr);

Expand Down Expand Up @@ -4127,6 +4133,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin
return;
}

player->resetLoginProtection();
player->resetIdleTime();
if (it.isRune() || it.type == ITEM_TYPE_POTION) {
player->setNextPotionActionTask(nullptr);
Expand Down Expand Up @@ -5911,6 +5918,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) {
}

if (player->getAttackedCreature() && creatureId == 0) {
player->resetLoginProtection();
player->setAttackedCreature(nullptr);
player->sendCancelTarget();
return;
Expand Down Expand Up @@ -6085,6 +6093,7 @@ void Game::playerTurn(uint32_t playerId, Direction dir) {
return;
}

player->resetLoginProtection();
player->resetIdleTime();
internalCreatureTurn(player, dir);
}
Expand Down Expand Up @@ -6208,6 +6217,7 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c
return;
}

player->resetLoginProtection();
player->resetIdleTime();

if (playerSaySpell(player, type, text)) {
Expand Down
2 changes: 2 additions & 0 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS

player->lastIP = player->getIP();
player->lastLoginSaved = std::max<time_t>(time(nullptr), player->lastLoginSaved + 1);
player->loginProtectionTime = OTSYS_TIME() + g_configManager().getNumber(LOGIN_PROTECTION_TIME);
acceptPackets = true;
} else {
if (eventConnect != 0 || !g_configManager().getBoolean(REPLACE_KICK_ON_LOGIN)) {
Expand Down Expand Up @@ -666,6 +667,7 @@ void ProtocolGame::connect(const std::string &playerName, OperatingSystem_t oper
sendAddCreature(player, player->getPosition(), 0, true);
player->lastIP = player->getIP();
player->lastLoginSaved = std::max<time_t>(time(nullptr), player->lastLoginSaved + 1);
player->setLoginProtection();
player->resetIdleTime();
acceptPackets = true;
}
Expand Down

0 comments on commit 3697df6

Please sign in to comment.