summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-06 00:00:54 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-06 00:05:22 +0200
commit9113afb868f6c1da5911437d3ddabdcf169cbec2 (patch)
tree4efb107417b369e8362630fd49ea10fa38210f2a /src
parent96e56ba80110b54af0ee8ebb3410bd4d9d21cdfe (diff)
downloadmana-9113afb868f6c1da5911437d3ddabdcf169cbec2.tar.gz
mana-9113afb868f6c1da5911437d3ddabdcf169cbec2.tar.bz2
mana-9113afb868f6c1da5911437d3ddabdcf169cbec2.tar.xz
mana-9113afb868f6c1da5911437d3ddabdcf169cbec2.zip
Use a namespace to keep apart implementations of network handlers
Since we'll have three "InventoryHandler" classes, etc. this shows an example of how we can compile with all of them at the same time using namespaces. We'll have: Net::InventoryHandler - the interface EAthena::InventoryHandler - the eAthena implementation TmwServ::InventoryHandler - the tmwserv implementation Maybe we'll find a better way later, but for now this works. I'm not convinced yet that using namespaces is better than just using longer class names like EAthenaInventoryHandler.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp11
-rw-r--r--src/gui/storagewindow.cpp17
-rw-r--r--src/net/ea/inventoryhandler.cpp4
-rw-r--r--src/net/ea/inventoryhandler.h4
-rw-r--r--src/net/net.cpp15
-rw-r--r--src/net/tmwserv/inventoryhandler.cpp4
-rw-r--r--src/net/tmwserv/inventoryhandler.h4
7 files changed, 42 insertions, 17 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 2f66b86f..c6031eba 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -85,6 +85,9 @@
#include "gui/storagewindow.h"
#endif
+#include "net/tmwserv/inventoryhandler.h"
+#include "net/ea/inventoryhandler.h"
+
#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/chathandler.h"
#include "net/tmwserv/itemhandler.h"
@@ -96,7 +99,6 @@
#include "net/tmwserv/buysellhandler.h"
#include "net/tmwserv/effecthandler.h"
#include "net/tmwserv/guildhandler.h"
-#include "net/tmwserv/inventoryhandler.h"
#include "net/tmwserv/partyhandler.h"
#else
#include "net/ea/gui/partytab.h"
@@ -105,7 +107,6 @@
#include "net/ea/beinghandler.h"
#include "net/ea/buysellhandler.h"
#include "net/ea/equipmenthandler.h"
-#include "net/ea/inventoryhandler.h"
#include "net/ea/itemhandler.h"
#include "net/ea/maphandler.h"
#include "net/ea/npchandler.h"
@@ -367,7 +368,11 @@ Game::Game(Network *network):
mPartyHandler(new PartyHandler),
mBuySellHandler(new BuySellHandler),
mChatHandler(new ChatHandler),
- mInventoryHandler(new InventoryHandler),
+#ifdef TMWSERV_SUPPORT
+ mInventoryHandler(new TmwServ::InventoryHandler),
+#else
+ mInventoryHandler(new EAthena::InventoryHandler),
+#endif
mItemHandler(new ItemHandler),
mNpcHandler(new NpcHandler),
mPlayerHandler(new PlayerHandler),
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
index 2828b197..22b28a8f 100644
--- a/src/gui/storagewindow.cpp
+++ b/src/gui/storagewindow.cpp
@@ -187,22 +187,19 @@ Item *StorageWindow::getSelectedItem() const
void StorageWindow::addStore(Item *item, int amount)
{
- // Net::getInventoryHandler()->moveItem(Net::InvyHandler::INVENTORY,
- inventoryHandler->moveItem(Net::InventoryHandler::INVENTORY,
- item->getInvIndex(), amount,
- Net::InventoryHandler::STORAGE);
+ Net::getInventoryHandler()->moveItem(Net::InventoryHandler::INVENTORY,
+ item->getInvIndex(), amount,
+ Net::InventoryHandler::STORAGE);
}
void StorageWindow::removeStore(Item *item, int amount)
{
- // Net::getInventoryHandler()->moveItem(Net::InvyHandler::STORAGE,
- inventoryHandler->moveItem(Net::InventoryHandler::STORAGE,
- item->getInvIndex(), amount,
- Net::InventoryHandler::INVENTORY);
+ Net::getInventoryHandler()->moveItem(Net::InventoryHandler::STORAGE,
+ item->getInvIndex(), amount,
+ Net::InventoryHandler::INVENTORY);
}
void StorageWindow::close()
{
- // Net::getInventoryHandler()->closeStorage();
- inventoryHandler->closeStorage();
+ Net::getInventoryHandler()->closeStorage();
}
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 7dfb6277..e6658bbf 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -45,6 +45,8 @@
#include <SDL_types.h>
+namespace EAthena {
+
enum { debugInventory = 1 };
InventoryHandler *inventoryHandler;
@@ -368,3 +370,5 @@ void InventoryHandler::moveItem(StorageType source, int slot, int amount,
outMsg.writeInt32(amount);
}
}
+
+} // namespace EAthena
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index bfebc9b3..391c13f4 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -26,6 +26,8 @@
#include "net/messagehandler.h"
#include "net/net.h"
+namespace EAthena {
+
class InventoryHandler : public MessageHandler, public Net::InventoryHandler
{
public:
@@ -51,6 +53,6 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler
StorageType destination);
};
-extern InventoryHandler *inventoryHandler;
+} // namespace EAthena
#endif // NET_EA_INVENTORYHANDLER_H
diff --git a/src/net/net.cpp b/src/net/net.cpp
index 39575372..8921a954 100644
--- a/src/net/net.cpp
+++ b/src/net/net.cpp
@@ -35,16 +35,21 @@
#include "net/skillhandler.h"
#include "net/tradehandler.h"
-#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/inventoryhandler.h"
+#include "net/ea/inventoryhandler.h"
+
+#ifdef TMWSERV_SUPPORT
#include "net/tmwserv/playerhandler.h"
#include "net/tmwserv/tradehandler.h"
#else
-#include "net/ea/inventoryhandler.h"
#include "net/ea/playerhandler.h"
#include "net/ea/tradehandler.h"
#endif
+namespace EAthena {
+extern InventoryHandler *inventoryHandler;
+}
+
Net::AdminHandler *Net::getAdminHandler()
{
// TODO
@@ -77,7 +82,11 @@ Net::GuildHandler *Net::getGuildHandler()
Net::InventoryHandler *Net::getInventoryHandler()
{
- return inventoryHandler;
+#ifdef TMWSERV_SUPPORT
+ return TmwServ::inventoryHandler;
+#else
+ return EAthena::inventoryHandler;
+#endif
}
Net::LoginHandler *Net::getLoginHandler()
diff --git a/src/net/tmwserv/inventoryhandler.cpp b/src/net/tmwserv/inventoryhandler.cpp
index cedeb465..f21c25a9 100644
--- a/src/net/tmwserv/inventoryhandler.cpp
+++ b/src/net/tmwserv/inventoryhandler.cpp
@@ -37,6 +37,8 @@
#include "resources/iteminfo.h"
+namespace TmwServ {
+
Net::InventoryHandler *inventoryHandler;
InventoryHandler::InventoryHandler()
@@ -123,3 +125,5 @@ void InventoryHandler::moveItem(StorageType source, int slot, int amount,
{
// TODO
}
+
+} // namespace TmwServ
diff --git a/src/net/tmwserv/inventoryhandler.h b/src/net/tmwserv/inventoryhandler.h
index 5dd788ef..38281e2a 100644
--- a/src/net/tmwserv/inventoryhandler.h
+++ b/src/net/tmwserv/inventoryhandler.h
@@ -25,6 +25,8 @@
#include "net/inventoryhandler.h"
#include "net/messagehandler.h"
+namespace TmwServ {
+
class InventoryHandler : public MessageHandler, Net::InventoryHandler
{
public:
@@ -52,4 +54,6 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler
extern Net::InventoryHandler *inventoryHandler;
+} // namespace TmwServ
+
#endif