Skip to content

Commit

Permalink
Fix logout message connection lost on bed and offline training and re…
Browse files Browse the repository at this point in the history
…move unused tag on druid familiar (#221)

Fixes connection lost message when using an bed or offline training statues, added a check to identify when a player was "forced" removed
  • Loading branch information
omeranha authored Mar 11, 2022
1 parent 1527549 commit e6abcc8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion data/monster/familiars/druid_familiar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ monster.race = "undead"
monster.corpse = 0
monster.speed = 309
monster.manaCost = 3000
monster.maxSummons = 0

monster.changeTarget = {
interval = 4000,
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/actions/other/skill_trainer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function skillTrainer.onUse(player, item, fromPosition, target, toPosition, isHo
end

player:setOfflineTrainingSkill(skill)
player:remove()
player:remove(false)
return true
end

Expand Down
8 changes: 4 additions & 4 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ void Player::onThink(uint32_t interval)
idleTime += interval;
const int32_t kickAfterMinutes = g_configManager().getNumber(KICK_AFTER_MINUTES);
if (idleTime > (kickAfterMinutes * 60000) + 60000) {
kickPlayer(true);
removePlayer(true);
} else if (client && idleTime == 60000 * kickAfterMinutes) {
std::ostringstream ss;
ss << "There was no variation in your behaviour for " << kickAfterMinutes << " minutes. You will be disconnected in one minute if there is no change in your actions until then.";
Expand Down Expand Up @@ -2696,11 +2696,11 @@ void Player::addList()
g_game.addPlayer(this);
}

void Player::kickPlayer(bool displayEffect)
void Player::removePlayer(bool displayEffect, bool forced /*= true*/)
{
g_creatureEvents->playerLogout(this);
if (client) {
client->logout(displayEffect, true);
client->logout(displayEffect, forced);
} else {
g_game.removeCreature(this);
}
Expand Down Expand Up @@ -4187,7 +4187,7 @@ void Player::onPlacedCreature()
{
//scripting event - onLogin
if (!g_creatureEvents->playerLogin(this)) {
kickPlayer(true);
removePlayer(true);
}

sendUnjustifiedPoints();
Expand Down
3 changes: 2 additions & 1 deletion src/creatures/players/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Player final : public Creature, public Cylinder

void removeList() override;
void addList() override;
void kickPlayer(bool displayEffect);
void removePlayer(bool displayEffect, bool forced = true);

static uint64_t getExpForLevel(int32_t lv) {
lv--;
Expand Down Expand Up @@ -2202,6 +2202,7 @@ class Player final : public Creature, public Cylinder
friend class IOLoginData;
friend class ProtocolGame;
friend class MoveEvent;
friend class BedItem;

account::Account *account_;
};
Expand Down
6 changes: 3 additions & 3 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void Game::setGameState(GameState_t newState)
//kick all players that are still online
auto it = players.begin();
while (it != players.end()) {
it->second->kickPlayer(true);
it->second->removePlayer(true);
it = players.begin();
}

Expand All @@ -333,7 +333,7 @@ void Game::setGameState(GameState_t newState)
auto it = players.begin();
while (it != players.end()) {
if (!it->second->hasFlag(PlayerFlag_CanAlwaysLogin)) {
it->second->kickPlayer(true);
it->second->removePlayer(true);
it = players.begin();
} else {
++it;
Expand Down Expand Up @@ -7016,7 +7016,7 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect)
return;
}

player->kickPlayer(displayEffect);
player->removePlayer(displayEffect);
}

void Game::playerCyclopediaCharacterInfo(Player* player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) {
Expand Down
5 changes: 2 additions & 3 deletions src/items/bed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ bool BedItem::sleep(Player* player)
// display 'Zzzz'/sleep effect
g_game.addMagicEffect(player->getPosition(), CONST_ME_SLEEP);

// kick player after he sees himself walk onto the bed and it change id
uint32_t playerId = player->getID();
g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS, std::bind(&Game::kickPlayer, &g_game, playerId, false)));
// logout player after he sees himself walk onto the bed and it change id
g_scheduler.addEvent(createSchedulerTask(SCHEDULER_MINTICKS, std::bind(&ProtocolGame::logout, player->client, false, false)));

// change self and partner's appearance
updateAppearance(player);
Expand Down
9 changes: 7 additions & 2 deletions src/lua/functions/creatures/creature_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ int CreatureFunctions::luaCreatureIsImmune(lua_State* L) {
}

int CreatureFunctions::luaCreatureRemove(lua_State* L) {
// creature:remove()
// creature:remove([forced = true])
Creature** creaturePtr = getRawUserdata<Creature>(L, 1);
if (!creaturePtr) {
lua_pushnil(L);
Expand All @@ -702,8 +702,13 @@ int CreatureFunctions::luaCreatureRemove(lua_State* L) {
}

Player* player = creature->getPlayer();
bool forced = getBoolean(L, 2, true);
if (player) {
player->kickPlayer(true);
if (forced) {
player->removePlayer(true);
} else {
player->removePlayer(true, false);
}
} else {
g_game.removeCreature(creature);
}
Expand Down

0 comments on commit e6abcc8

Please sign in to comment.