diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-12 02:02:05 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-12 02:02:05 +0300 |
commit | f457675ecfd704c99e84fe14f0a1dd49a69a9c76 (patch) | |
tree | 615a7d18d4302cc82e7d3f711006e445ed237eb7 | |
parent | 8f0a7cbb675ede13658bcc10b045d46fda9c93da (diff) | |
download | manaverse-f457675ecfd704c99e84fe14f0a1dd49a69a9c76.tar.gz manaverse-f457675ecfd704c99e84fe14f0a1dd49a69a9c76.tar.bz2 manaverse-f457675ecfd704c99e84fe14f0a1dd49a69a9c76.tar.xz manaverse-f457675ecfd704c99e84fe14f0a1dd49a69a9c76.zip |
Add missing checks to some files.
-rw-r--r-- | src/actorsprite.cpp | 3 | ||||
-rw-r--r-- | src/actorspritemanager.cpp | 65 | ||||
-rw-r--r-- | src/animatedsprite.cpp | 4 | ||||
-rw-r--r-- | src/auctionmanager.cpp | 6 | ||||
-rw-r--r-- | src/being.cpp | 47 | ||||
-rw-r--r-- | src/client.cpp | 48 | ||||
-rw-r--r-- | src/commandhandler.cpp | 110 |
7 files changed, 102 insertions, 181 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 082ceda14..e90536b2d 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -70,7 +70,8 @@ ActorSprite::~ActorSprite() for (ActorSpriteListenerIterator iter = mActorSpriteListeners.begin(), e = mActorSpriteListeners.end(); iter != e; ++iter) { - (*iter)->actorSpriteDestroyed(*this); + if (*iter) + (*iter)->actorSpriteDestroyed(*this); } } diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 3acb63dc3..03418a857 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -305,6 +305,9 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y, for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -355,6 +358,9 @@ void ActorSpriteManager::findBeingsByPixel(std::vector<Being*> &beings, for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -386,6 +392,9 @@ Being *ActorSpriteManager::findPortalByTile(int x, int y) const for_actors { + if (!*it) + continue; + if ((*it)->getType() != ActorSprite::PORTAL) continue; @@ -402,6 +411,9 @@ FloorItem *ActorSpriteManager::findItem(int id) const { for_actors { + if (!*it) + continue; + if ((*it)->getId() == id && (*it)->getType() == ActorSprite::FLOOR_ITEM) { @@ -416,6 +428,9 @@ FloorItem *ActorSpriteManager::findItem(int x, int y) const { for_actors { + if (!*it) + continue; + if ((*it)->getTileX() == x && (*it)->getTileY() == y && (*it)->getType() == ActorSprite::FLOOR_ITEM) { @@ -437,6 +452,9 @@ bool ActorSpriteManager::pickUpAll(int x1, int y1, int x2, int y2, { for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2) && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2)) @@ -452,6 +470,9 @@ bool ActorSpriteManager::pickUpAll(int x1, int y1, int x2, int y2, unsigned cnt = 65535; for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2) && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2)) @@ -487,6 +508,9 @@ bool ActorSpriteManager::pickUpNearest(int x, int y, int maxdist) for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM) { FloorItem *item = static_cast<FloorItem*>(*it); @@ -514,6 +538,9 @@ Being *ActorSpriteManager::findBeingByName(const std::string &name, { for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -545,6 +572,9 @@ Being *ActorSpriteManager::findNearestByName(const std::string &name, for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -583,7 +613,10 @@ const ActorSprites &ActorSpriteManager::getAll() const void ActorSpriteManager::logic() { for_actors - (*it)->logic(); + { + if (*it) + (*it)->logic(); + } if (mDeleteActors.empty()) return; @@ -591,6 +624,9 @@ void ActorSpriteManager::logic() for (it = mDeleteActors.begin(), it_end = mDeleteActors.end(); it != it_end; ++it) { + if (!*it) + continue; + if ((*it) && (*it)->getType() == Being::PLAYER) { Being *being = static_cast<Being*>(*it); @@ -721,6 +757,9 @@ Being *ActorSpriteManager::findNearestLivingBeing(Being *aroundBeing, i_end = mActors.end(); i != i_end; ++i) { + if (!*i) + continue; + if ((*i)->getType() == ActorSprite::FLOOR_ITEM || (*i)->getType() == ActorSprite::PORTAL) { @@ -803,6 +842,9 @@ Being *ActorSpriteManager::findNearestLivingBeing(Being *aroundBeing, i_end = mActors.end(); i != i_end; ++i) { + if (!*i) + continue; + if ((*i)->getType() == ActorSprite::FLOOR_ITEM || (*i)->getType() == ActorSprite::PORTAL) { @@ -1057,6 +1099,9 @@ void ActorSpriteManager::printBeingsToChat(ActorSprites beings, std::set<ActorSprite*>::const_iterator it; for (it = beings.begin(); it != beings.end(); ++it) { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM) continue; @@ -1082,6 +1127,9 @@ void ActorSpriteManager::printBeingsToChat(std::vector<Being*> beings, std::vector<Being*>::const_iterator i; for (i = beings.begin(); i != beings.end(); ++i) { + if (!*i) + continue; + const Being *being = *i; debugChatTab->chatLog(being->getName() @@ -1099,6 +1147,9 @@ void ActorSpriteManager::getPlayerNames(std::vector<std::string> &names, for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -1121,6 +1172,9 @@ void ActorSpriteManager::getMobNames(std::vector<std::string> &names) for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -1137,6 +1191,9 @@ void ActorSpriteManager::updatePlayerNames() { for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -1154,6 +1211,9 @@ void ActorSpriteManager::updatePlayerColors() { for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { @@ -1170,6 +1230,9 @@ void ActorSpriteManager::updatePlayerGuild() { for_actors { + if (!*it) + continue; + if ((*it)->getType() == ActorSprite::FLOOR_ITEM || (*it)->getType() == ActorSprite::PORTAL) { diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 27be02e36..fedcd8de2 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -154,8 +154,8 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time) mFrameIndex = 0; mFrame = mAnimation->getFrame(mFrameIndex); - - if (mFrame->type == Frame::LABEL && !mFrame->nextAction.empty()) + if (!mFrame || (mFrame->type == Frame::LABEL + && !mFrame->nextAction.empty())) { fail = true; } diff --git a/src/auctionmanager.cpp b/src/auctionmanager.cpp index b360279ba..900d47e29 100644 --- a/src/auctionmanager.cpp +++ b/src/auctionmanager.cpp @@ -64,7 +64,8 @@ void AuctionManager::init() void AuctionManager::send(std::string msg) { - Net::getChatHandler()->privateMessage("AuctionBot", msg); + if (Net::getChatHandler()) + Net::getChatHandler()->privateMessage("AuctionBot", msg); } bool AuctionManager::processAuctionMessage(std::string msg) @@ -85,5 +86,6 @@ void AuctionManager::reload() void AuctionManager::sendMail(std::string mail) { - Net::getChatHandler()->privateMessage("AuctionBot", "!mail " + mail); + if (Net::getChatHandler()) + Net::getChatHandler()->privateMessage("AuctionBot", "!mail " + mail); } diff --git a/src/being.cpp b/src/being.cpp index da83f1f73..73e1819a0 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -395,21 +395,18 @@ void Being::setPosition(const Vector &pos) void Being::setDestination(int dstX, int dstY) { + // We can't calculate anything without a map anyway. + if (!mMap) + return; + #ifdef MANASERV_SUPPORT if (Net::getNetworkType() != ServerInfo::MANASERV) #endif { - if (mMap) - setPath(mMap->findPath(mX, mY, dstX, dstY, getWalkMask())); + setPath(mMap->findPath(mX, mY, dstX, dstY, getWalkMask())); return; } - // Manaserv's part: - - // We can't calculate anything without a map anyway. - if (!mMap) - return; - // Don't handle flawed destinations from server... if (dstX == 0 || dstY == 0) return; @@ -765,7 +762,6 @@ void Being::setGuildName(const std::string &name) void Being::setGuildPos(const std::string &pos A_UNUSED) { -// logger->log("Got guild position \"%s\" for being %s(%i)", pos.c_str(), mName.c_str(), mId); } void Being::addGuild(Guild *guild) @@ -774,7 +770,6 @@ void Being::addGuild(Guild *guild) return; mGuilds[guild->getId()] = guild; -// guild->addMember(mId, 0, mName); if (this == player_node && socialWindow) socialWindow->addTab(guild); @@ -891,10 +886,10 @@ void Being::updateGuild() void Being::setGuild(Guild *guild) { - if (guild == getGuild()) + Guild *old = getGuild(); + if (guild == old) return; - Guild *old = getGuild(); clearGuilds(); addGuild(guild); @@ -1119,7 +1114,6 @@ Uint8 Being::calcDirection(int dstX, int dstY) const return dir; } -/** TODO: Used by eAthena only */ void Being::nextTile() { if (mPath.empty()) @@ -1135,7 +1129,7 @@ void Being::nextTile() if (dir) setDirection(static_cast<Uint8>(dir)); - if (!mMap->getWalk(pos.x, pos.y, getWalkMask())) + if (!mMap || !mMap->getWalk(pos.x, pos.y, getWalkMask())) { setAction(STAND); return; @@ -1372,7 +1366,10 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) const int emotionIndex = mEmotion - 1; if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast()) - EmoteDB::getAnimation(emotionIndex)->draw(graphics, px, py); + { + if (EmoteDB::getAnimation(emotionIndex)) + EmoteDB::getAnimation(emotionIndex)->draw(graphics, px, py); + } } void Being::drawSpeech(int offsetX, int offsetY) @@ -1411,11 +1408,9 @@ void Being::drawSpeech(int offsetX, int offsetY) if (!mText && userPalette) { - mText = new Text(mSpeech, - getPixelX(), getPixelY() - getHeight(), - gcn::Graphics::CENTER, - &userPalette->getColor(UserPalette::PARTICLE), - true); + mText = new Text(mSpeech, getPixelX(), getPixelY() - getHeight(), + gcn::Graphics::CENTER, &userPalette->getColor(UserPalette::PARTICLE), + true); } } else if (speech == NO_SPEECH) @@ -1743,7 +1738,7 @@ void Being::load() while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != paths.getStringValue("spriteErrorFile")) { - hairstyles++; + hairstyles ++; } mNumberOfHairstyles = hairstyles; @@ -1866,6 +1861,9 @@ BeingCacheEntry* Being::getCacheEntry(int id) for (std::list<BeingCacheEntry*>::iterator i = beingInfoCache.begin(); i != beingInfoCache.end(); ++i) { + if (!*i) + continue; + if (id == (*i)->getId()) { // Raise priority: move it to front @@ -1979,8 +1977,7 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const graphics->setColor(userPalette-> getColorWithAlpha(UserPalette::PORTAL_HIGHLIGHT)); - graphics->fillRectangle(gcn::Rectangle( - x, y, 32, 32)); + graphics->fillRectangle(gcn::Rectangle(x, y, 32, 32)); if (mDrawHotKeys && !mName.empty()) { @@ -2011,7 +2008,7 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const { // show hp bar here int maxHP = mMaxHP; - if (!maxHP) + if (!maxHP && mInfo) maxHP = mInfo->getMaxHP(); drawHpBar(graphics, maxHP, mHP, mDamageTaken, @@ -2451,7 +2448,7 @@ void Being::saveComment(const std::string &name, return; } dir += stringToHexPath(name); - logger->log("save to: %s", dir.c_str()); +// logger->log("save to: %s", dir.c_str()); ResourceManager *resman = ResourceManager::getInstance(); resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); } diff --git a/src/client.cpp b/src/client.cpp index be1c00197..bdba75aa8 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -844,12 +844,10 @@ int Client::exec() if (mState != mOldState) { - { - Mana::Event evt(EVENT_STATECHANGE); - evt.setInt("oldState", mOldState); - evt.setInt("newState", mState); - Mana::Event::trigger(CHANNEL_CLIENT, evt); - } + Mana::Event evt(EVENT_STATECHANGE); + evt.setInt("oldState", mOldState); + evt.setInt("newState", mState); + Mana::Event::trigger(CHANNEL_CLIENT, evt); if (mOldState == STATE_GAME) { @@ -1190,8 +1188,7 @@ int Client::exec() case STATE_CHANGEPASSWORD_ATTEMPT: logger->log1("State: CHANGE PASSWORD ATTEMPT"); Net::getLoginHandler()->changePassword(loginData.username, - loginData.password, - loginData.newPassword); + loginData.password, loginData.newPassword); break; case STATE_CHANGEPASSWORD_SUCCESS: @@ -1458,37 +1455,6 @@ void Client::initHomeDir() logger->error(strprintf(_("%s doesn't exist and can't be created! " "Exiting."), mConfigDir.c_str())); } - -/* - struct stat statbuf; - std::string newConfigFile = mConfigDir + "/config.xml"; - if (stat(newConfigFile.c_str(), &statbuf)) - { - std::string oldConfigFile = std::string(PHYSFS_getUserDir()) + - "/.mana/config.xml"; - if (mRootDir.empty() && !stat(oldConfigFile.c_str(), &statbuf) - && S_ISREG(statbuf.st_mode)) - { - std::ifstream oldConfig; - std::ofstream newConfig; - logger->log1("Copying old TMW settings."); - - oldConfig.open(oldConfigFile.c_str(), std::ios::binary); - newConfig.open(newConfigFile.c_str(), std::ios::binary); - - if (!oldConfig.is_open() || !newConfig.is_open()) - { - logger->log1("Unable to copy old settings."); - } - else - { - newConfig << oldConfig.rdbuf(); - newConfig.close(); - oldConfig.close(); - } - } - } -*/ } /** @@ -2191,8 +2157,8 @@ void Client::closeDialogs() bool Client::isTmw() { if (getServerName() == "server.themanaworld.org" - || Client::getServerName() == "themanaworld.org" - || Client::getServerName() == "81.161.192.4") + || getServerName() == "themanaworld.org" + || getServerName() == "81.161.192.4") { return true; } diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 5de5eb2cf..189485461 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -87,221 +87,113 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab) args = trim(args); if (command == "closeall") - { handleCloseAll(args, tab); - } else if (type == "ignoreall") - { handleIgnoreAll(args, tab); - } else if (type == "help") // Do help before tabs so they can't override it - { handleHelp(args, tab); - } else if (type == "announce") - { handleAnnounce(args, tab); - } else if (type == "where") - { handleWhere(args, tab); - } else if (type == "who") - { handleWho(args, tab); - } else if (type == "msg" || type == "whisper" || type == "w") - { handleMsg(args, tab); - } else if (type == "query" || type == "q") - { handleQuery(args, tab); - } else if (type == "ignore") - { handleIgnore(args, tab); - } else if (type == "unignore") - { handleUnignore(args, tab); - } else if (type == "friend" || type == "befriend") - { handleFriend(args, tab); - } else if (type == "disregard") - { handleDisregard(args, tab); - } else if (type == "neutral") - { handleNeutral(args, tab); - } else if (type == "erase") - { handleErase(args, tab); - } else if (type == "join") - { handleJoin(args, tab); - } else if (type == "list") - { handleListChannels(args, tab); - } else if (type == "clear") - { handleClear(args, tab); - } else if (type == "createparty") - { handleCreateParty(args, tab); - } else if (type == "createguild") - { handleCreateGuild(args, tab); - } else if (type == "party") - { handleParty(args, tab); - } else if (type == "me") - { handleMe(args, tab); - } else if (type == "toggle") - { handleToggle(args, tab); - } else if (type == "present") - { handlePresent(args, tab); - } else if (type == "quit") - { handleQuit(args, tab); - } else if (type == "all") - { handleShowAll(args, tab); - } else if (type == "move") - { handleMove(args, tab); - } else if (type == "target") - { handleTarget(args, tab); - } else if (type == "outfit") - { handleOutfit(args, tab); - } else if (type == "emote") - { handleEmote(args, tab); - } else if (type == "away") - { handleAway(args, tab); - } else if (type == "follow") - { handleFollow(args, tab); - } else if (type == "heal") - { handleHeal(args, tab); - } else if (type == "navigate") - { handleNavigate(args, tab); - } else if (type == "imitation") - { handleImitation(args, tab); - } else if (type == "mail") - { handleMail(args, tab); - } else if (type == "trade") - { handleTrade(args, tab); - } else if (type == "priceload") - { handlePriceLoad(args, tab); - } else if (type == "pricesave") - { handlePriceSave(args, tab); - } else if (type == "cacheinfo") - { handleCacheInfo(args, tab); - } else if (type == "disconnect") - { handleDisconnect(args, tab); - } else if (type == "undress") - { handleUndress(args, tab); - } else if (type == "attack") - { handleAttack(args, tab); - } else if (type == "dirs") - { handleDirs(args, tab); - } else if (type == "info") - { handleInfo(args, tab); - } else if (type == "wait") - { handleWait(args, tab); - } else if (type == "uptime") - { handleUptime(args, tab); - } else if (type == "addpriorityattack") - { handleAddPriorityAttack(args, tab); - } else if (type == "addattack") - { handleAddAttack(args, tab); - } else if (type == "removeattack" || type == "removeignoreattack") - { handleRemoveAttack(args, tab); - } else if (type == "addignoreattack") - { handleAddIgnoreAttack(args, tab); - } else if (type == "dump") - { handleDump(args, tab); - } else if (tab->handleCommand(type, args)) - { - // Nothing to do - } + ; else if (type == "hack") - { handleHack(args, tab); - } else - { tab->chatLog(_("Unknown command.")); - } } char CommandHandler::parseBoolean(const std::string &value) |