Skip to content

Commit

Permalink
Shard crash fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yungcomputerchair committed Dec 19, 2023
1 parent b765821 commit 21d2801
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ EntityRef::EntityRef(CNSocket *s) {
EntityRef::EntityRef(int32_t i) {
id = i;

assert(NPCManager::NPCs.find(id) != NPCManager::NPCs.end());
kind = NPCManager::NPCs[id]->kind;
kind = EntityKind::INVALID;
if (NPCManager::NPCs.find(id) != NPCManager::NPCs.end())
kind = NPCManager::NPCs[id]->kind;
}

bool EntityRef::isValid() const {
Expand Down
18 changes: 18 additions & 0 deletions src/Groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ static void attachGroupData(std::vector<EntityRef>& pcs, std::vector<EntityRef>&
}

void Groups::addToGroup(Group* group, EntityRef member) {
if (group == nullptr)
return;

if (member.kind == EntityKind::PLAYER) {
Player* plr = PlayerManager::getPlayer(member.sock);
plr->group = group;
Expand Down Expand Up @@ -109,6 +112,9 @@ void Groups::addToGroup(Group* group, EntityRef member) {
}

bool Groups::removeFromGroup(Group* group, EntityRef member) {
if (group == nullptr)
return false;

if (member.kind == EntityKind::PLAYER) {
Player* plr = PlayerManager::getPlayer(member.sock);
plr->group = nullptr; // no dangling pointers here muahaahahah
Expand Down Expand Up @@ -168,6 +174,9 @@ bool Groups::removeFromGroup(Group* group, EntityRef member) {
}

void Groups::disbandGroup(Group* group) {
if (group == nullptr)
return;

// remove everyone from the group!!
bool done = false;
while(!done) {
Expand Down Expand Up @@ -252,13 +261,19 @@ static void leaveGroup(CNSocket* sock, CNPacketData* data) {
}

void Groups::sendToGroup(Group* group, void* buf, uint32_t type, size_t size) {
if (group == nullptr)
return;

auto players = group->filter(EntityKind::PLAYER);
for (EntityRef ref : players) {
ref.sock->sendPacket(buf, type, size);
}
}

void Groups::sendToGroup(Group* group, EntityRef excluded, void* buf, uint32_t type, size_t size) {
if (group == nullptr)
return;

auto players = group->filter(EntityKind::PLAYER);
for (EntityRef ref : players) {
if(ref != excluded) ref.sock->sendPacket(buf, type, size);
Expand Down Expand Up @@ -294,6 +309,9 @@ void Groups::groupTickInfo(CNSocket* sock) {

void Groups::groupKick(Group* group, EntityRef ref) {

if (group == nullptr)
return;

// if you are the group leader, destroy your own group and kick everybody
if (group->members[0] == ref) {
disbandGroup(group);
Expand Down
3 changes: 3 additions & 0 deletions src/Missions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ static void taskStart(CNSocket* sock, CNPacketData* data) {
static void taskEnd(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_PC_TASK_END* missionData = (sP_CL2FE_REQ_PC_TASK_END*)data->buf;

if (Missions::Tasks.find(missionData->iTaskNum) == Missions::Tasks.end())
return;

TaskData* task = Missions::Tasks[missionData->iTaskNum];

// handle timed mission failure
Expand Down
2 changes: 1 addition & 1 deletion src/Nanos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void Nanos::summonNano(CNSocket *sock, int slot, bool silent) {
}

static void setNanoSkill(CNSocket* sock, sP_CL2FE_REQ_NANO_TUNE* skill) {
if (skill->iNanoID >= NANO_COUNT)
if (skill == nullptr || skill->iNanoID >= NANO_COUNT || skill->iNanoID < 0)
return;

Player *plr = PlayerManager::getPlayer(sock);
Expand Down

0 comments on commit 21d2801

Please sign in to comment.