From 5784e7765498254c9744098588c3b3676a01bd46 Mon Sep 17 00:00:00 2001 From: dongresource Date: Wed, 14 Oct 2020 23:15:02 +0200 Subject: [PATCH] Misc changes. The first two fixes were caught by infer. The Big Bug(tm) remains unfixed. * Fixed the Leech nano power * Fixed an unlikely nullptr dereference in ItemManager * /toggleai now makes mobs retreat immediately, instead of waiting for their next movement tick * Static path mobs will now stop in place instead of retreating to their spawn points when AI is disabled * Changed the misleading config option name from "chunksize" to "viewdistance", since it's actually only a third of the chunk size --- config.ini | 5 +++-- src/ChatManager.cpp | 14 +++++++++++--- src/ChunkManager.cpp | 2 +- src/ItemManager.cpp | 6 +++++- src/NanoManager.cpp | 6 +++--- src/settings.cpp | 4 ++-- src/settings.hpp | 2 +- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/config.ini b/config.ini index 86c280d..44442a4 100644 --- a/config.ini +++ b/config.ini @@ -19,8 +19,9 @@ dbsaveinterval=240 [shard] port=8002 ip=127.0.0.1 -# distance at which other players and NPCs become visible -chunksize=30000 +# distance at which other players and NPCs become visible. +# this value is used for calculating chunk size +viewdistance=30000 # time, in milliseconds, to wait before kicking a non-responsive client # default is 1 minute timeout=60000 diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 367081a..e54e13f 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -279,10 +279,18 @@ void toggleAiCommand(std::string full, std::vector& args, CNSocket* for (auto& pair : MobManager::Mobs) { pair.second->state = MobState::RETREAT; pair.second->target = nullptr; + pair.second->nextMovement = getTime(); - pair.second->roamX = pair.second->spawnX; - pair.second->roamY = pair.second->spawnY; - pair.second->roamZ = pair.second->spawnZ; + // mobs with static paths can chill where they are + if (pair.second->staticPath) { + pair.second->roamX = pair.second->appearanceData.iX; + pair.second->roamY = pair.second->appearanceData.iY; + pair.second->roamZ = pair.second->appearanceData.iZ; + } else { + pair.second->roamX = pair.second->spawnX; + pair.second->roamY = pair.second->spawnY; + pair.second->roamZ = pair.second->spawnZ; + } } } diff --git a/src/ChunkManager.cpp b/src/ChunkManager.cpp index 955efea..8e2319d 100644 --- a/src/ChunkManager.cpp +++ b/src/ChunkManager.cpp @@ -109,7 +109,7 @@ bool ChunkManager::checkChunk(std::tuple chunk) { } std::tuple ChunkManager::grabChunk(int posX, int posY, int instanceID) { - return std::make_tuple(posX / (settings::CHUNKSIZE / 3), posY / (settings::CHUNKSIZE / 3), instanceID); + return std::make_tuple(posX / (settings::VIEWDISTANCE / 3), posY / (settings::VIEWDISTANCE / 3), instanceID); } std::vector ChunkManager::grabChunks(std::tuple chunk) { diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index cac407b..37beac3 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -5,7 +5,7 @@ #include "NanoManager.hpp" #include "Player.hpp" -#include // for memset() and memcmp() +#include // for memset() #include std::map, Item> ItemManager::ItemData; @@ -911,6 +911,10 @@ void ItemManager::setItemStats(Player* plr) { for (int i = 0; i < 4; i++) { itemStatsDat = ItemManager::getItemData(plr->Equip[i].iID, plr->Equip[i].iType); + if (itemStatsDat == nullptr) { + std::cout << "[WARN] setItemStats(): getItemData() returned NULL" << std::endl; + continue; + } plr->pointDamage += itemStatsDat->pointDamage; plr->groupDamage += itemStatsDat->groupDamage; plr->defense += itemStatsDat->defense; diff --git a/src/NanoManager.cpp b/src/NanoManager.cpp index 21e6f45..99954c2 100644 --- a/src/NanoManager.cpp +++ b/src/NanoManager.cpp @@ -625,9 +625,9 @@ void activePower(CNSocket *sock, CNPacketData *data, return; pkt->iTargetCnt = otherPlr->groupCnt; - } - - resplen = sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC) + pkt->iTargetCnt * sizeof(sPAYLOAD); + resplen = sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC) + pkt->iTargetCnt * sizeof(sPAYLOAD); + } else + resplen = sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC) + pkt->iTargetCnt * sizeof(sPAYLOAD); // validate response packet if (!validOutVarPacket(sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC), pkt->iTargetCnt, sizeof(sPAYLOAD))) { diff --git a/src/settings.cpp b/src/settings.cpp index dad9ef3..cd0d06d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -12,7 +12,7 @@ int settings::DBSAVEINTERVAL = 240; int settings::SHARDPORT = 8002; std::string settings::SHARDSERVERIP = "127.0.0.1"; time_t settings::TIMEOUT = 60000; -int settings::CHUNKSIZE = 40000; +int settings::VIEWDISTANCE = 40000; bool settings::SIMULATEMOBS = true; // default spawn point is Sector V (future) @@ -47,7 +47,7 @@ void settings::init() { SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1"); DBSAVEINTERVAL = reader.GetInteger("shard", "dbsaveinterval", DBSAVEINTERVAL); TIMEOUT = reader.GetInteger("shard", "timeout", TIMEOUT); - CHUNKSIZE = reader.GetInteger("shard", "chunksize", CHUNKSIZE); + VIEWDISTANCE = reader.GetInteger("shard", "viewdistance", VIEWDISTANCE); SIMULATEMOBS = reader.GetBoolean("shard", "simulatemobs", SIMULATEMOBS); SPAWN_X = reader.GetInteger("shard", "spawnx", SPAWN_X); SPAWN_Y = reader.GetInteger("shard", "spawny", SPAWN_Y); diff --git a/src/settings.hpp b/src/settings.hpp index 915eefd..d53b969 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -8,7 +8,7 @@ namespace settings { extern int SHARDPORT; extern std::string SHARDSERVERIP; extern time_t TIMEOUT; - extern int CHUNKSIZE; + extern int VIEWDISTANCE; extern bool SIMULATEMOBS; extern int SPAWN_X; extern int SPAWN_Y;