diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-08-09 00:27:00 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-08-09 00:27:00 +0300 |
commit | 17a08b25c0df685e3f5c7edf1d4ab583f55ecaf9 (patch) | |
tree | 6b87b432ed5d87f1244316e18a614b326095e855 /src | |
parent | 9c46394f54db8c1b9e357ad555f3db96251a616d (diff) | |
download | manaverse-17a08b25c0df685e3f5c7edf1d4ab583f55ecaf9.tar.gz manaverse-17a08b25c0df685e3f5c7edf1d4ab583f55ecaf9.tar.bz2 manaverse-17a08b25c0df685e3f5c7edf1d4ab583f55ecaf9.tar.xz manaverse-17a08b25c0df685e3f5c7edf1d4ab583f55ecaf9.zip |
Add some missing checks to actions found by paranucker.
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/actions.cpp | 105 | ||||
-rw-r--r-- | src/actions/chat.cpp | 55 | ||||
-rw-r--r-- | src/actions/commands.cpp | 174 | ||||
-rw-r--r-- | src/actions/windows.cpp | 11 |
4 files changed, 235 insertions, 110 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index 4f78bc375..92c0029ed 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -132,6 +132,9 @@ static int uploadUpdate(void *ptr, return 0; UploadChatInfo *const info = reinterpret_cast<UploadChatInfo*>(ptr); + if (!info) + return 0; + if (status == DownloadStatus::Complete) { std::string str = Net::Download::getUploadResponse(); @@ -174,7 +177,7 @@ static void uploadFile(const std::string &str, const std::string &addStr, ChatTab *const tab) { - UploadChatInfo *const info = new UploadChatInfo(); + UploadChatInfo *const info = new UploadChatInfo; Net::Download *const upload = new Net::Download(info, "http://sprunge.us", &uploadUpdate, @@ -561,8 +564,9 @@ impHandler0(itenplz) { if (actorManager) { - if (playerHandler && playerHandler->canUseMagic() - && PlayerInfo::getAttribute(Attributes::MP) >= 3) + if (playerHandler && + playerHandler->canUseMagic() && + PlayerInfo::getAttribute(Attributes::MP) >= 3) { actorManager->itenplz(); } @@ -652,15 +656,22 @@ impHandler0(ignoreInput) impHandler(buy) { + if (!serverFeatures) + return false; const std::string args = event.args; Being *being = findBeing(args, false); if (!being && !serverFeatures->haveVending()) { - const std::set<std::string> &players = whoIsOnline->getOnlineNicks(); - if (players.find(args) != players.end()) + if (whoIsOnline) { - buySellHandler->requestSellList(args); - return true; + const std::set<std::string> &players = + whoIsOnline->getOnlineNicks(); + if (players.find(args) != players.end()) + { + if (buySellHandler) + buySellHandler->requestSellList(args); + return true; + } } return false; } @@ -673,16 +684,18 @@ impHandler(buy) if (being->getType() == ActorType::Npc) { - npcHandler->buy(being->getId()); + if (npcHandler) + npcHandler->buy(being->getId()); return true; } else if (being->getType() == ActorType::Player) { #ifdef EATHENA_SUPPORT - if (serverFeatures->haveVending()) + if (vendingHandler && serverFeatures->haveVending()) vendingHandler->open(being); else #endif + if (buySellHandler) buySellHandler->requestSellList(being->getName()); return true; } @@ -691,15 +704,23 @@ impHandler(buy) impHandler(sell) { + if (!serverFeatures) + return false; + const std::string args = event.args; Being *being = findBeing(args, false); if (!being && !serverFeatures->haveVending()) { - const std::set<std::string> &players = whoIsOnline->getOnlineNicks(); - if (players.find(args) != players.end()) + if (whoIsOnline) { - buySellHandler->requestBuyList(args); - return true; + const std::set<std::string> &players = + whoIsOnline->getOnlineNicks(); + if (players.find(args) != players.end()) + { + if (buySellHandler) + buySellHandler->requestBuyList(args); + return true; + } } return false; } @@ -712,16 +733,18 @@ impHandler(sell) if (being->getType() == ActorType::Npc) { - npcHandler->sell(being->getId()); + if (npcHandler) + npcHandler->sell(being->getId()); return true; } else if (being->getType() == ActorType::Player) { #ifdef EATHENA_SUPPORT - if (serverFeatures->haveVending()) + if (buyingStoreHandler && serverFeatures->haveVending()) buyingStoreHandler->open(being); else #endif + if (buySellHandler) buySellHandler->requestBuyList(being->getName()); return true; } @@ -911,7 +934,8 @@ impHandler0(openTrade) const Being *const being = localPlayer->getTarget(); if (being && being->getType() == ActorType::Player) { - tradeHandler->request(being); + if (tradeHandler) + tradeHandler->request(being); tradePartnerName = being->getName(); if (tradeWindow) tradeWindow->clear(); @@ -969,7 +993,8 @@ impHandler(where) impHandler0(who) { - chatHandler->who(); + if (chatHandler) + chatHandler->who(); return true; } @@ -1010,7 +1035,8 @@ impHandler(trade) being = localPlayer->getTarget(); if (being) { - tradeHandler->request(being); + if (tradeHandler) + tradeHandler->request(being); tradePartnerName = being->getName(); if (tradeWindow) tradeWindow->clear(); @@ -1082,7 +1108,8 @@ impHandler0(cacheInfo) impHandler0(disconnect) { - gameHandler->disconnect2(); + if (gameHandler) + gameHandler->disconnect2(); return true; } @@ -1096,7 +1123,7 @@ impHandler(undress) target = actorManager->findNearestByName(event.args); if (!target) target = localPlayer->getTarget(); - if (target) + if (target && beingHandler) beingHandler->undress(target); return true; } @@ -1279,13 +1306,15 @@ impHandler0(dump) impHandler0(serverIgnoreAll) { - chatHandler->ignoreAll(); + if (chatHandler) + chatHandler->ignoreAll(); return true; } impHandler0(serverUnIgnoreAll) { - chatHandler->unIgnoreAll(); + if (chatHandler) + chatHandler->unIgnoreAll(); return true; } @@ -1444,6 +1473,8 @@ impHandler0(createItems) FOR_EACH (ItemDB::ItemInfos::const_iterator, it, items) { const ItemInfo *const info = (*it).second; + if (!info) + continue; const int id = info->getId(); if (id <= 500) continue; @@ -1499,7 +1530,8 @@ impHandler(uploadLog) impHandler0(mercenaryFire) { #ifdef EATHENA_SUPPORT - mercenaryHandler->fire(); + if (mercenaryHandler) + mercenaryHandler->fire(); return true; #else return false; @@ -1547,10 +1579,13 @@ impHandler(invToStorage) return true; if (amount) { - inventoryHandler->moveItem2(InventoryType::INVENTORY, - item->getInvIndex(), - amount, - InventoryType::STORAGE); + if (inventoryHandler) + { + inventoryHandler->moveItem2(InventoryType::INVENTORY, + item->getInvIndex(), + amount, + InventoryType::STORAGE); + } } else { @@ -1570,7 +1605,8 @@ impHandler(tradeAdd) if (amount) { - tradeWindow->tradeItem(item, amount, true); + if (tradeWindow) + tradeWindow->tradeItem(item, amount, true); } else { @@ -1586,10 +1622,13 @@ impHandler(storageToInv) const int amount = getAmountFromEvent(event, item, InventoryType::STORAGE); if (amount) { - inventoryHandler->moveItem2(InventoryType::STORAGE, - item->getInvIndex(), - amount, - InventoryType::INVENTORY); + if (inventoryHandler && item) + { + inventoryHandler->moveItem2(InventoryType::STORAGE, + item->getInvIndex(), + amount, + InventoryType::INVENTORY); + } } else { @@ -1636,7 +1675,7 @@ impHandler(kick) } if (!target) target = localPlayer->getTarget(); - if (target) + if (target && adminHandler) adminHandler->kick(target->getId()); return true; } diff --git a/src/actions/chat.cpp b/src/actions/chat.cpp index 9749e30fa..f6e1d9a55 100644 --- a/src/actions/chat.cpp +++ b/src/actions/chat.cpp @@ -56,7 +56,8 @@ static void outString(ChatTab *const tab, { if (!tab) { - chatHandler->talk(def, GENERAL_CHANNEL); + if (chatHandler) + chatHandler->talk(def, GENERAL_CHANNEL); return; } @@ -64,20 +65,24 @@ static void outString(ChatTab *const tab, { case ChatTabType::PARTY: { - partyHandler->chat(str); + if (partyHandler) + partyHandler->chat(str); break; } case ChatTabType::GUILD: { - if (!localPlayer) + if (!guildHandler || !localPlayer) return; const Guild *const guild = localPlayer->getGuild(); if (guild) { if (guild->getServerGuild()) { - if (!serverFeatures->haveNativeGuilds()) + if (!serverFeatures || + !serverFeatures->haveNativeGuilds()) + { return; + } guildHandler->chat(str); } #ifdef TMWA_SUPPORT @@ -101,7 +106,8 @@ static void outString(ChatTab *const tab, case ChatTabType::DEBUG: case ChatTabType::BATTLE: case ChatTabType::LANG: - chatHandler->talk(str, GENERAL_CHANNEL); + if (chatHandler) + chatHandler->talk(str, GENERAL_CHANNEL); break; } } @@ -238,13 +244,18 @@ impHandler(msg) if (splitWhisper(event.args, recvnick, message)) { + if (!chatWindow) + return false; chatWindow->addWhisper(recvnick, message, ChatMsgType::BY_PLAYER); } else { - // TRANSLATORS: whisper send - event.tab->chatLog(_("Cannot send empty whispers!"), - ChatMsgType::BY_SERVER); + if (event.tab) + { + // TRANSLATORS: whisper send + event.tab->chatLog(_("Cannot send empty whispers!"), + ChatMsgType::BY_SERVER); + } } return true; } @@ -271,7 +282,7 @@ impHandler(msg2) std::string recvnick; std::string message; - if (splitWhisper(event.args, recvnick, message)) + if (chatHandler && splitWhisper(event.args, recvnick, message)) chatHandler->privateMessage(recvnick, message); return true; } @@ -310,7 +321,7 @@ impHandler0(clearChatTab) impHandler(createParty) { - if (!event.tab) + if (!event.tab || !partyHandler) return false; if (event.args.empty()) @@ -328,8 +339,13 @@ impHandler(createParty) impHandler(createGuild) { - if (!event.tab || !serverFeatures->haveNativeGuilds()) + if (!guildHandler || + !event.tab || + !serverFeatures || + !serverFeatures->haveNativeGuilds()) + { return false; + } if (event.args.empty()) { @@ -348,7 +364,8 @@ impHandler(party) { if (!event.args.empty()) { - partyHandler->invite(event.args); + if (partyHandler) + partyHandler->invite(event.args); } else { @@ -364,7 +381,7 @@ impHandler(party) impHandler(guild) { - if (!event.tab || !localPlayer) + if (!guildHandler || !event.tab || !localPlayer) return false; const std::string args = event.args; @@ -450,7 +467,8 @@ impHandler(kickParty) { if (!event.args.empty()) { - partyHandler->kick(event.args); + if (partyHandler) + partyHandler->kick(event.args); } else { @@ -474,10 +492,15 @@ impHandler(kickGuild) if (guild) { if (guild->getServerGuild()) - guildHandler->kick(guild->getMember(event.args), ""); + { + if (guildHandler) + guildHandler->kick(guild->getMember(event.args), ""); + } #ifdef TMWA_SUPPORT else if (guildManager) + { guildManager->kick(event.args); + } #endif } } @@ -566,7 +589,7 @@ impHandler0(chatGuildTab) impHandler(hat) { - if (!localPlayer) + if (!localPlayer || !charServerHandler) return false; const int sprite = localPlayer->getSpriteID( diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index d15402b25..8070efcc7 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -76,9 +76,12 @@ static std::string getNick(const InputEvent &event) WhisperTab *const whisper = dynamic_cast<WhisperTab* const>(event.tab); if (!whisper || whisper->getNick().empty()) { - // TRANSLATORS: change relation - event.tab->chatLog(_("Please specify a name."), - ChatMsgType::BY_SERVER); + if (event.tab) + { + // TRANSLATORS: change relation + event.tab->chatLog(_("Please specify a name."), + ChatMsgType::BY_SERVER); + } return std::string(); } args = whisper->getNick(); @@ -139,8 +142,12 @@ static void changeRelation(const InputEvent &event, impHandler(chatAnnounce) { - adminHandler->announce(event.args); - return true; + if (adminHandler) + { + adminHandler->announce(event.args); + return true; + } + return false; } impHandler(chatIgnore) @@ -510,18 +517,23 @@ impHandler(imitation) impHandler0(sendMail) { + // +++ need impliment for hercules return false; } impHandler(info) { - if (!event.tab || !localPlayer - || !serverFeatures->haveNativeGuilds()) + if (!event.tab || + !localPlayer || + !serverFeatures || + !serverFeatures->haveNativeGuilds()) { return false; } - if (event.tab->getType() == ChatTabType::GUILD) + if (event.tab && + guildHandler && + event.tab->getType() == ChatTabType::GUILD) { const Guild *const guild = localPlayer->getGuild(); if (guild) @@ -652,8 +664,10 @@ impHandler(enableHighlight) { event.tab->setAllowHighlight(true); if (chatWindow) + { chatWindow->saveState(); - return true; + return true; + } } return false; } @@ -664,8 +678,10 @@ impHandler(disableHighlight) { event.tab->setAllowHighlight(false); if (chatWindow) + { chatWindow->saveState(); - return true; + return true; + } } return false; } @@ -676,8 +692,10 @@ impHandler(dontRemoveName) { event.tab->setRemoveNames(false); if (chatWindow) + { chatWindow->saveState(); - return true; + return true; + } } return false; } @@ -688,8 +706,10 @@ impHandler(removeName) { event.tab->setRemoveNames(true); if (chatWindow) + { chatWindow->saveState(); - return true; + return true; + } } return false; } @@ -700,8 +720,10 @@ impHandler(disableAway) { event.tab->setNoAway(true); if (chatWindow) + { chatWindow->saveState(); - return true; + return true; + } } return false; } @@ -712,8 +734,10 @@ impHandler(enableAway) { event.tab->setNoAway(false); if (chatWindow) + { chatWindow->saveState(); - return true; + return true; + } } return false; } @@ -730,20 +754,32 @@ impHandler(testParticle) impHandler(talkRaw) { - chatHandler->talkRaw(event.args); - return true; + if (chatHandler) + { + chatHandler->talkRaw(event.args); + return true; + } + return false; } impHandler(gm) { - chatHandler->talk("@wgm " + event.args, GENERAL_CHANNEL); - return true; + if (chatHandler) + { + chatHandler->talk("@wgm " + event.args, GENERAL_CHANNEL); + return true; + } + return false; } impHandler(hack) { - chatHandler->sendRaw(event.args); - return true; + if (chatHandler) + { + chatHandler->sendRaw(event.args); + return true; + } + return false; } impHandler(debugSpawn) @@ -766,8 +802,12 @@ impHandler(serverIgnoreWhisper) if (args.empty()) return false; - chatHandler->ignore(args); - return true; + if (chatHandler) + { + chatHandler->ignore(args); + return true; + } + return false; } impHandler(serverUnIgnoreWhisper) @@ -776,8 +816,12 @@ impHandler(serverUnIgnoreWhisper) if (args.empty()) return false; - chatHandler->unIgnore(args); - return true; + if (chatHandler) + { + chatHandler->unIgnore(args); + return true; + } + return false; } impHandler(setHomunculusName) @@ -787,27 +831,35 @@ impHandler(setHomunculusName) if (args.empty()) return false; - homunculusHandler->setName(args); - return true; -#else - return false; + if (homunculusHandler) + { + homunculusHandler->setName(args); + return true; + } #endif + return false; } impHandler0(fireHomunculus) { #ifdef EATHENA_SUPPORT - homunculusHandler->fire(); - return true; -#else - return false; + if (homunculusHandler) + { + homunculusHandler->fire(); + return true; + } #endif + return false; } impHandler0(leaveParty) { - partyHandler->leave(); - return true; + if (partyHandler) + { + partyHandler->leave(); + return true; + } + return false; } impHandler(warp) @@ -815,38 +867,44 @@ impHandler(warp) int x = 0; int y = 0; - if (Game::instance() && parse2Int(event.args, x, y)) + if (adminHandler && + Game::instance() && + parse2Int(event.args, x, y)) { adminHandler->warp(Game::instance()->getCurrentMapName(), x, y); + return true; } - return true; + return false; } impHandler(homunTalk) { #ifdef EATHENA_SUPPORT - if (!serverFeatures->haveTalkPet()) + if (!serverFeatures || !serverFeatures->haveTalkPet()) return false; std::string args = event.args; if (findCutFirst(args, "/me ")) args = textToMe(args); - homunculusHandler->talk(args); - return true; -#else - return false; + if (homunculusHandler) + { + homunculusHandler->talk(args); + return true; + } #endif + return false; } impHandler(homunEmote) { #ifdef EATHENA_SUPPORT - if (!serverFeatures->haveTalkPet()) + if (!serverFeatures || !serverFeatures->haveTalkPet()) return false; - if (event.action >= InputAction::HOMUN_EMOTE_1 - && event.action <= InputAction::HOMUN_EMOTE_48) + if (homunculusHandler && + event.action >= InputAction::HOMUN_EMOTE_1 && + event.action <= InputAction::HOMUN_EMOTE_48) { const int emotion = event.action - InputAction::HOMUN_EMOTE_1; if (emoteShortcut) @@ -863,21 +921,23 @@ impHandler(homunEmote) impHandler(commandHomunEmote) { #ifdef EATHENA_SUPPORT - if (!serverFeatures->haveTalkPet()) + if (!serverFeatures || !serverFeatures->haveTalkPet()) return false; - homunculusHandler->emote(static_cast<uint8_t>( - atoi(event.args.c_str()))); - return true; -#else - return false; + if (homunculusHandler) + { + homunculusHandler->emote(static_cast<uint8_t>( + atoi(event.args.c_str()))); + return true; + } #endif + return false; } impHandler(createPublicChatRoom) { #ifdef EATHENA_SUPPORT - if (event.args.empty()) + if (!chatHandler || event.args.empty()) return false; chatHandler->createChatRoom(event.args, "", 100, true); return true; @@ -889,6 +949,8 @@ impHandler(createPublicChatRoom) impHandler(joinChatRoom) { #ifdef EATHENA_SUPPORT + if (!chatHandler) + return false; const std::string args = event.args; if (args.empty()) return false; @@ -905,11 +967,13 @@ impHandler(joinChatRoom) impHandler0(leaveChatRoom) { #ifdef EATHENA_SUPPORT - chatHandler->leaveChatRoom(); - return true; -#else - return false; + if (chatHandler) + { + chatHandler->leaveChatRoom(); + return true; + } #endif + return false; } impHandler(confSet) diff --git a/src/actions/windows.cpp b/src/actions/windows.cpp index bd82521d4..c98adbfb0 100644 --- a/src/actions/windows.cpp +++ b/src/actions/windows.cpp @@ -273,7 +273,7 @@ impHandler0(questsWindowShow) impHandler0(bankWindowShow) { #ifdef EATHENA_SUPPORT - if (!serverFeatures->haveBankApi()) + if (!serverFeatures || !serverFeatures->haveBankApi()) return false; showHideWindow(bankWindow); @@ -286,9 +286,10 @@ impHandler0(bankWindowShow) impHandler0(cartWindowShow) { #ifdef EATHENA_SUPPORT - if (!serverFeatures->haveCart() - || !localPlayer - || !localPlayer->getHaveCart()) + if (!serverFeatures || + !serverFeatures->haveCart() || + !localPlayer || + !localPlayer->getHaveCart()) { return false; } @@ -316,9 +317,7 @@ impHandler0(quickWindowShow) if (setupWindow) { if (setupWindow->isWindowVisible()) - { setupWindow->doCancel(); - } setupWindow->setVisible(Visible_true); setupWindow->activateTab(_("Quick")); setupWindow->requestMoveToTop(); |