diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/auctionmanager.cpp | 91 | ||||
-rw-r--r-- | src/auctionmanager.h | 60 | ||||
-rw-r--r-- | src/client.cpp | 2 | ||||
-rw-r--r-- | src/commands.cpp | 7 | ||||
-rw-r--r-- | src/commands.h | 2 | ||||
-rw-r--r-- | src/game.cpp | 10 | ||||
-rw-r--r-- | src/gui/setup_other.cpp | 3 | ||||
-rw-r--r-- | src/gui/shopwindow.cpp | 28 | ||||
-rw-r--r-- | src/gui/shopwindow.h | 2 |
11 files changed, 209 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e1f1be3e..8c99c7b94 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -520,6 +520,8 @@ SET(SRCS animationdelayload.h animationparticle.cpp animationparticle.h + auctionmanager.cpp + auctionmanager.h avatar.cpp avatar.h being.cpp diff --git a/src/Makefile.am b/src/Makefile.am index ee43ad9a4..1ba390bb1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -523,6 +523,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ animationdelayload.h \ animationparticle.cpp \ animationparticle.h \ + auctionmanager.cpp \ + auctionmanager.h \ avatar.cpp \ avatar.h \ being.cpp \ diff --git a/src/auctionmanager.cpp b/src/auctionmanager.cpp new file mode 100644 index 000000000..348866e19 --- /dev/null +++ b/src/auctionmanager.cpp @@ -0,0 +1,91 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "auctionmanager.h" + +#include "actorspritemanager.h" +#include "client.h" +#include "configuration.h" +#include "localplayer.h" + +#include "net/chathandler.h" +#include "net/net.h" + +#include "utils/gettext.h" + +#include "debug.h" + +bool AuctionManager::mEnableAuctionBot = false; + +AuctionManager::AuctionManager() +{ +} + +AuctionManager::~AuctionManager() +{ +} + +void AuctionManager::init() +{ + if (auctionManager) + return; + + int val = serverConfig.getValue("enableAuctionBot", -1); + if (val == -1) + { + if (Client::isTmw()) + val = 1; + else + val = 0; + serverConfig.setValue("enableAuctionBot", val); + } + mEnableAuctionBot = (val != 0); + if (mEnableAuctionBot) + auctionManager = new AuctionManager(); +} + +void AuctionManager::send(const std::string &msg) +{ + if (Net::getChatHandler()) + Net::getChatHandler()->privateMessage("AuctionBot", msg); +} + +/* +bool AuctionManager::processAuctionMessage(const std::string &msg) +{ + if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + return false; +} +*/ + +void AuctionManager::clear() +{ +} + +void AuctionManager::reload() +{ +} + +void AuctionManager::sendMail(const std::string &mail) +{ + if (Net::getChatHandler()) + Net::getChatHandler()->privateMessage("AuctionBot", "!mail " + mail); +} diff --git a/src/auctionmanager.h b/src/auctionmanager.h new file mode 100644 index 000000000..d82f1beb0 --- /dev/null +++ b/src/auctionmanager.h @@ -0,0 +1,60 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef AUCTIONMANAGER_H +#define AUCTIONMANAGER_H + +#include "utils/dtor.h" + +#include <map> +#include <string> +#include <vector> + +#include "localconsts.h" + +class AuctionManager final +{ + public: + AuctionManager(); + + A_DELETE_COPY(AuctionManager) + + ~AuctionManager(); + + static void init(); + + static void send(const std::string &msg); + + static bool getEnableAuctionBot() A_WARN_UNUSED + { return mEnableAuctionBot; } + + void clear(); + + void reload(); + + static void sendMail(const std::string &mail); + + private: + static bool mEnableAuctionBot; +}; + +extern AuctionManager *auctionManager; + +#endif // AUCTIONMANAGER_H diff --git a/src/client.cpp b/src/client.cpp index 57987e82b..ccd00344a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -24,6 +24,7 @@ #include "client.h" +#include "auctionmanager.h" #include "chatlogger.h" #include "configuration.h" #include "depricatedevent.h" @@ -1074,6 +1075,7 @@ int Client::gameExec() #endif GuildManager::init(); + AuctionManager::init(); if (!mConfigAutoSaved) { diff --git a/src/commands.cpp b/src/commands.cpp index 1beba22d5..7dbafd0f1 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -22,6 +22,7 @@ #include "commandhandler.h" +#include "auctionmanager.h" #include "actorspritemanager.h" #include "client.h" #include "configuration.h" @@ -699,6 +700,12 @@ impHandler1(hack) Net::getChatHandler()->sendRaw(args); } +impHandler1(mail) +{ + if (auctionManager && auctionManager->getEnableAuctionBot()) + auctionManager->sendMail(args); +} + impHandler0(priceLoad) { if (shopWindow) diff --git a/src/commands.h b/src/commands.h index 5eb189718..350f80469 100644 --- a/src/commands.h +++ b/src/commands.h @@ -84,6 +84,7 @@ namespace Commands decHandler(imitation); decHandler(heal); decHandler(navigate); + decHandler(mail); decHandler(hack); decHandler(priceLoad); decHandler(priceSave); @@ -160,6 +161,7 @@ static const CommandInfo commands[] = {"heal", &Commands::heal}, {"navigate", &Commands::navigate}, {"imitation", &Commands::imitation}, + {"mail", &Commands::mail}, {"trade", &Commands::trade}, {"priceload", &Commands::priceLoad}, {"pricesave", &Commands::priceSave}, diff --git a/src/game.cpp b/src/game.cpp index da60f114b..7c5138c7d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -25,6 +25,7 @@ #include "main.h" #include "actorspritemanager.h" +#include "auctionmanager.h" #include "animatedsprite.h" #include "client.h" #include "commandhandler.h" @@ -151,6 +152,7 @@ EffectManager *effectManager = nullptr; SpellManager *spellManager = nullptr; Viewport *viewport = nullptr; /**< Viewport on the map. */ GuildManager *guildManager = nullptr; +AuctionManager *auctionManager = nullptr; ChatTab *localChatTab = nullptr; ChatTab *debugChatTab = nullptr; @@ -172,6 +174,7 @@ static void initEngines() actorSpriteManager = new ActorSpriteManager; commandHandler = new CommandHandler; effectManager = new EffectManager; + AuctionManager::init(); GuildManager::init(); particleEngine = new Particle(nullptr); @@ -328,6 +331,9 @@ static void destroyGuiWindows() if (whoIsOnline) whoIsOnline->setAllowUpdate(false); + if (auctionManager) + auctionManager->clear(); + if (guildManager) guildManager->clear(); @@ -369,6 +375,9 @@ static void destroyGuiWindows() DepricatedEvent::trigger(CHANNEL_GAME, DepricatedEvent(EVENT_GUIWINDOWSUNLOADED)); + if (auctionManager && AuctionManager::getEnableAuctionBot()) + auctionManager->reload(); + if (guildManager && GuildManager::getEnableGuildBot()) guildManager->reload(); } @@ -460,6 +469,7 @@ Game::~Game() del_0(mCurrentMap) del_0(spellManager) del_0(spellShortcut) + del_0(auctionManager) del_0(guildManager) #ifdef USE_MUMBLE del_0(mumbleManager) diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 4404a26e9..c4ce2a500 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -201,6 +201,9 @@ Setup_Other::Setup_Other(const Widget2 *const widget) : new SetupItemLabel(_("Bots support"), "", this); + new SetupItemCheckBox(_("Enable auction bot support"), "", + "enableAuctionBot", this, "enableAuctionBotEvent", false); + new SetupItemCheckBox(_("Enable guild bot support and disable native " "guild support"), "", "enableGuildBot", this, "enableGuildBotEvent", false); diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index ffe347099..17f9edc5b 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -39,6 +39,7 @@ #include "gui/widgets/tradetab.h" #include "actorspritemanager.h" +#include "auctionmanager.h" #include "client.h" #include "configuration.h" #include "confirmdialog.h" @@ -88,10 +89,12 @@ ShopWindow::ShopWindow(): mBuyAddButton(new Button(this, _("Add"), "add buy", this)), mBuyDeleteButton(new Button(this, _("Delete"), "delete buy", this)), mBuyAnnounceButton(new Button(this, _("Announce"), "announce buy", this)), + mBuyAuctionButton(nullptr), mSellAddButton(new Button(this, _("Add"), "add sell", this)), mSellDeleteButton(new Button(this, _("Delete"), "delete sell", this)), mSellAnnounceButton(new Button(this, _("Announce"), "announce sell", this)), + mSellAuctionButton(nullptr), mAnnounceLinks(new CheckBox(this, _("Show links in announce"), false, this, "link announce")), mSelectedItem(-1), @@ -142,6 +145,21 @@ ShopWindow::ShopWindow(): placer(0, 7, mAnnounceLinks, 8); placer(15, 7, mCloseButton); + if (auctionManager && auctionManager->getEnableAuctionBot()) + { + mBuyAuctionButton = new Button(this, + _("Auction"), "auction buy", this); + mSellAuctionButton = new Button(this, + _("Auction"), "auction sell", this); + placer(4, 6, mBuyAuctionButton); + placer(12, 6, mSellAuctionButton); + } + else + { + mBuyAuctionButton = nullptr; + mSellAuctionButton = nullptr; + } + Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); @@ -214,6 +232,16 @@ void ShopWindow::action(const gcn::ActionEvent &event) { announce(mSellShopItems, SELL); } + else if (eventId == "auction buy" && mBuyShopItems + && mBuyShopItems->getNumberOfElements() > 0) + { + Net::getChatHandler()->privateMessage("AuctionBot", "!pull4144 seek"); + } + else if (eventId == "auction sell" && mSellShopItems + && mSellShopItems->getNumberOfElements() > 0) + { + Net::getChatHandler()->privateMessage("AuctionBot", "!pull4144 offer"); + } if (mSelectedItem < 1) return; diff --git a/src/gui/shopwindow.h b/src/gui/shopwindow.h index 383016029..9b7e64572 100644 --- a/src/gui/shopwindow.h +++ b/src/gui/shopwindow.h @@ -155,9 +155,11 @@ class ShopWindow final : public Window, public gcn::ActionListener, Button *mBuyAddButton; Button *mBuyDeleteButton; Button *mBuyAnnounceButton; + Button *mBuyAuctionButton; Button *mSellAddButton; Button *mSellDeleteButton; Button *mSellAnnounceButton; + Button *mSellAuctionButton; CheckBox *mAnnounceLinks; int mSelectedItem; |