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

[Feature/Enhancement] - No disconnect on death #147

Merged
merged 55 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
205df46
Update iologindata.cpp
omeranha Oct 17, 2021
0b2479c
Revert "Update iologindata.cpp"
omeranha Oct 17, 2021
7c64a1b
Fix sonar warning
Costallat Oct 18, 2021
dfb3182
no disconnect on death first!
omeranha Oct 19, 2021
32b45e3
Update src/creatures/players/player.cpp
omeranha Oct 23, 2021
41b77b7
Update src/creatures/players/player.cpp
omeranha Oct 23, 2021
2ac71b3
Update src/creatures/players/player.cpp
omeranha Oct 23, 2021
d0b3c5c
Update src/creatures/players/player.cpp
omeranha Oct 23, 2021
0738c02
Update src/creatures/players/player.cpp
omeranha Oct 23, 2021
435d385
Update src/server/network/protocol/protocolgame.cpp
omeranha Oct 23, 2021
27d72d2
Update src/creatures/players/player.cpp
omeranha Oct 23, 2021
6a415af
Merge branch 'master' into omeranha-no-disconnect-on-death
omeranha Oct 23, 2021
b50f187
Merge branch 'master' into omeranha-no-disconnect-on-death
beats-dh Oct 28, 2021
5043c09
Merge branch 'master' into omeranha-no-disconnect-on-death
dudantas Nov 3, 2021
4339a29
Merge branch 'opentibiabr:master' into master
omeranha Nov 4, 2021
bce6a54
Merge branch 'opentibiabr:master' into master
omeranha Nov 26, 2021
6a1e386
Merge branch 'opentibiabr:master' into master
omeranha Dec 7, 2021
c9df206
Merge branch 'opentibiabr:master' into master
omeranha Dec 11, 2021
c503ceb
Merge branch 'opentibiabr:master' into master
omeranha Dec 16, 2021
f60c4fa
Merge branch 'opentibiabr:master' into master
omeranha Jan 3, 2022
216efd2
Merge branch 'opentibiabr:master' into master
omeranha Jan 8, 2022
be7d207
Merge branch 'opentibiabr:master' into master
omeranha Jan 11, 2022
e7268be
Merge branch 'master' into pr/147
dudantas Jan 27, 2022
9904f1e
Fix sonar bug
dudantas Jan 28, 2022
a2304b5
sonar issues
omeranha Jan 31, 2022
a884ee4
sonar fixes
omeranha Jan 31, 2022
affeb41
Merge branch 'opentibiabr:master' into master
omeranha Feb 4, 2022
68815f1
Merge branch 'opentibiabr:master' into master
omeranha Feb 7, 2022
3c89e1a
Merge branch 'opentibiabr:master' into master
omeranha Feb 9, 2022
11923f7
Merge branch 'master' into omeranha-no-disconnect-on-death
omeranha Feb 11, 2022
6ffbcc3
Merge branch 'opentibiabr:master' into master
omeranha Feb 12, 2022
05280dd
Merge branch 'opentibiabr:master' into master
omeranha Feb 14, 2022
4862c2f
Merge branch 'opentibiabr:master' into master
omeranha Feb 15, 2022
2084124
Merge branch 'opentibiabr:master' into master
omeranha Feb 16, 2022
8881c2a
Merge branch 'master' into omeranha-no-disconnect-on-death
omeranha Feb 16, 2022
1513f90
cleanup, party fix, no spam of logged in and logged out messages in c…
omeranha Feb 17, 2022
2af9d48
Fix sonar
beats-dh Feb 17, 2022
af2a9e1
refactor
omeranha Feb 19, 2022
e1d7652
Merge branch 'master' into pr/147
omeranha Feb 26, 2022
7b522b0
should fix connection lost message after some seconds in "you are dea…
omeranha Feb 26, 2022
6ddd86a
not needed
omeranha Feb 26, 2022
c5900bb
Merge branch 'master' into pr/147
omeranha Feb 28, 2022
79392db
Merge branch 'master' into pr/147
omeranha Mar 1, 2022
0362920
player death messages, test commit :)
omeranha Mar 3, 2022
eb709b1
Merge branch 'master' into pr/147
omeranha Mar 10, 2022
cafb13d
Merge branch 'master' into pr/147
omeranha Mar 11, 2022
584cdc5
Update player_death.lua
omeranha Mar 11, 2022
cc8e931
should fix cancel crash message
omeranha Mar 12, 2022
57e8b91
fix guild crash + nil blesses
omeranha Mar 12, 2022
a13afdd
Merge branch 'master' into pr/147
omeranha Mar 12, 2022
8f0327b
blessings messages in cpp, remove lua code
omeranha Mar 13, 2022
8ff5e1a
sonar and removing nil stamina
omeranha Mar 13, 2022
cc37d6d
refactor², fix chats not working and party invitations cleaning when …
omeranha Mar 14, 2022
fccd02b
whitespace
omeranha Mar 14, 2022
5ef0856
Merge branch 'master' into pr/147
omeranha Mar 21, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/analysis-sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Analysis - SonarCloud

on:
pull_request_target:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ void Creature::onDeath()
setMaster(nullptr);
}

if (droppedCorpse) {
if (droppedCorpse && !getPlayer()) {
g_game.removeCreature(this, false);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/creatures/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ class Creature : virtual public Thing
}
}

void setDead(bool isDead) {
dead = isDead;
}
bool isDead() const {
return dead;
}

protected:
virtual bool useCacheMap() const {
return false;
Expand Down Expand Up @@ -570,6 +577,7 @@ class Creature : virtual public Thing
bool floorChange = false;
bool canUseDefense = true;
bool moveLocked = false;
bool dead = false;

//creature script events
bool hasEventRegistered(CreatureEventType_t event) const {
Expand Down
85 changes: 85 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,91 @@ void Player::death(Creature* lastHitCreature)
onIdleStatus();
sendStats();
}
despawn();
}

bool Player::spawn()
{
setDead(false);

const Position& pos = getLoginPosition();

if (!g_game.map.placeCreature(pos, this, false, true)) {
return false;
}

SpectatorHashSet spectators;
g_game.map.getSpectators(spectators, position, false, true);
for (Creature* spectator : spectators) {
omeranha marked this conversation as resolved.
Show resolved Hide resolved
if (Player* tmpPlayer = spectator->getPlayer()) {
tmpPlayer->sendCreatureAppear(this, pos, true);
}
}

for (Creature* spectator : spectators) {
omeranha marked this conversation as resolved.
Show resolved Hide resolved
spectator->onCreatureAppear(this, true);
}

getParent()->postAddNotification(this, nullptr, 0);
g_game.addCreatureCheck(this);

addList();
return true;
}

void Player::despawn()
{
if (isDead()) {
return;
}

listWalkDir.clear();
stopEventWalk();
onWalkAborted();

// remove check
g_game.removeCreatureCheck(this);

// remove from map
Tile* tile = getTile();
omeranha marked this conversation as resolved.
Show resolved Hide resolved

std::vector<int32_t> oldStackPosVector;

SpectatorHashSet spectators;
g_game.map.getSpectators(spectators, tile->getPosition(), true);
for (Creature* spectator : spectators) {
omeranha marked this conversation as resolved.
Show resolved Hide resolved
if (Player* player = spectator->getPlayer()) {
oldStackPosVector.push_back(player->canSeeCreature(this) ? tile->getStackposOfCreature(player, this) : -1);
}
}

tile->removeCreature(this);

const Position& tilePosition = tile->getPosition();

//send to client
size_t i = 0;
for (Creature* spectator : spectators) {
omeranha marked this conversation as resolved.
Show resolved Hide resolved
if (Player* player = spectator->getPlayer()) {
player->sendRemoveTileThing(tilePosition, oldStackPosVector[i++]);
}
}

//event method
for (Creature* spectator : spectators) {
omeranha marked this conversation as resolved.
Show resolved Hide resolved
spectator->onRemoveCreature(this, false);
}

getParent()->postRemoveNotification(this, nullptr, 0);

g_game.removePlayer(this);

// show player as pending
for (const auto& it : g_game.getPlayers()) {
it.second->notifyStatusChange(this, VIPSTATUS_PENDING);
}

setDead(true);
}

bool Player::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified)
Expand Down
6 changes: 6 additions & 0 deletions src/creatures/players/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,10 @@ class Player final : public Creature, public Cylinder
void forgetInstantSpell(const std::string& spellName);
bool hasLearnedInstantSpell(const std::string& spellName) const;

int64_t getLastPong() const {
return lastPong;
}

void setScheduledSaleUpdate(bool scheduled) {
scheduledSaleUpdate = scheduled;
}
Expand Down Expand Up @@ -1876,6 +1880,8 @@ class Player final : public Creature, public Cylinder
void setNextPotionActionTask(SchedulerTask* task);

void death(Creature* lastHitCreature) override;
bool spawn();
void despawn();
bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature,
bool lastHitUnjustified, bool mostDamageUnjustified) override;
Item* getCorpse(Creature* lastHitCreature, Creature* mostDamageCreature) override;
Expand Down
8 changes: 8 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,14 @@ bool Game::removeCreature(Creature* creature, bool isLogout/* = true*/)
return false;
}

if (creature->isDead()) {
creature->removeList();
creature->setRemoved();
ReleaseCreature(creature);
removeCreatureCheck(creature);
return true;
}

Tile* tile = creature->getTile();

std::vector<int32_t> oldStackPosVector;
Expand Down
56 changes: 51 additions & 5 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,35 @@ void ProtocolGame::connect(uint32_t playerId, OperatingSystem_t operatingSystem)
acceptPackets = true;
}

void ProtocolGame::spawn()
{
//dispatcher thread
if (!player) {
return;
}

if (!player->spawn()) {
disconnect();
g_game.removeCreature(player);
return;
}

sendAddCreature(player, player->getPosition(), 0, false);
}

void ProtocolGame::despawn()
{
//dispatcher thread
if (!player) {
return;
}
//fire onLogout
g_creatureEvents->playerLogout(player);

disconnect();
g_game.removeCreature(player);
}

void ProtocolGame::logout(bool displayEffect, bool forced)
{
//dispatcher thread
Expand Down Expand Up @@ -610,16 +639,33 @@ void ProtocolGame::parsePacket(NetworkMessage& msg)

uint8_t recvbyte = msg.getByte();

// A dead player can not perform actions
if (!player || player->isRemoved() || player->getHealth() <= 0) {
if (!player || player->isRemoved()) {
omeranha marked this conversation as resolved.
Show resolved Hide resolved
if (recvbyte == 0x0F) {
// we need to make the player pointer != null in this part, game.cpp release is the first step
// login(player->getName(), player->getAccount(), player->operatingSystem);
disconnect();
}

return;
}

//a dead player can not performs actions
if (player->isDead() || player->getHealth() <= 0) {
if (recvbyte == 0x14) {
g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::despawn, getThis())));
return;
}

if (recvbyte == 0x0F) {
g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::spawn, getThis())));
return;
}

if (OTSYS_TIME() - player->getLastPong() >= 60000) {
g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::despawn, getThis())));
return;
}

if (recvbyte != 0x14) {
if (recvbyte != 0x1D && recvbyte != 0x1E) {
// keep the connection alive
return;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/server/network/protocol/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class ProtocolGame final : public Protocol
void login(const std::string &name, uint32_t accnumber, OperatingSystem_t operatingSystem);
void logout(bool displayEffect, bool forced);

void spawn();
void despawn();

void AddItem(NetworkMessage &msg, const Item *item);
void AddItem(NetworkMessage &msg, uint16_t id, uint8_t count);

Expand Down