summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--src/Makefile.am8
-rw-r--r--src/accounthandler.cpp6
-rw-r--r--src/accounthandler.h7
-rw-r--r--src/chathandler.cpp7
-rw-r--r--src/chathandler.h6
-rw-r--r--src/dalstoragesql.h6
-rw-r--r--src/gamehandler.cpp7
-rw-r--r--src/gamehandler.h6
-rw-r--r--src/inventory.cpp97
-rw-r--r--src/inventory.h175
-rw-r--r--src/item.cpp34
-rw-r--r--src/item.h136
-rw-r--r--src/itemhandler.cpp (renamed from src/items.cpp)14
-rw-r--r--src/itemhandler.h (renamed from src/items.h)44
15 files changed, 527 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 72b89bc1..0c0478c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-10-03 Yohann Ferreira <bertram@cegetel.net>
+
+ * src/item.cpp, src/item.h, src/inventory.h, src.inventory.cpp,
+ src/itemhandler.h, src/itemhandler.cpp, src/dalstoragesql.h,
+ src/Makefile.am: Committed itemhandler structure part rc1.
+ src/accounthandler.cpp, src/accounthandler.h, src/chathandler.h,
+ src/chathandler.cpp, src/gamehandler.h, src/gamehandler.cpp: Made the
+ server tells which server is listening on a port.
+
2006-09-09 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/map.cpp: Merged client pathfinder changes.
diff --git a/src/Makefile.am b/src/Makefile.am
index 1950aac8..40631398 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,8 +39,12 @@ tmwserv_SOURCES = main.cpp \
gameclient.cpp \
gamehandler.h \
gamehandler.cpp \
- items.h \
- items.cpp \
+ inventory.h \
+ inventory.cpp \
+ item.h \
+ item.cpp \
+ itemhandler.h \
+ itemhandler.cpp \
map.h \
map.cpp \
mapcomposite.h \
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 717f5581..2e2e4a29 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -39,6 +39,12 @@
#include "utils/logger.h"
#include "utils/stringfilter.h"
+bool
+AccountHandler::startListen(enet_uint16 port)
+{
+ LOG_INFO("Account handler started:", 0);
+ ConnectionHandler::startListen(port);
+}
NetComputer*
AccountHandler::computerConnected(ENetPeer *peer)
diff --git a/src/accounthandler.h b/src/accounthandler.h
index 6345fa87..5a1a38db 100644
--- a/src/accounthandler.h
+++ b/src/accounthandler.h
@@ -38,6 +38,13 @@ class AccountClient;
*/
class AccountHandler : public ConnectionHandler
{
+ public:
+ /**
+ * Start the handler
+ */
+ bool
+ startListen(enet_uint16 port);
+
protected:
/**
* Process account related messages.
diff --git a/src/chathandler.cpp b/src/chathandler.cpp
index 93aaa7d3..88a62b59 100644
--- a/src/chathandler.cpp
+++ b/src/chathandler.cpp
@@ -88,6 +88,13 @@ void registerChatClient(std::string const &token, std::string const &name, int l
}
}
+bool
+ChatHandler::startListen(enet_uint16 port)
+{
+ LOG_INFO("Chat handler started:", 0);
+ ConnectionHandler::startListen(port);
+}
+
void ChatHandler::removeOutdatedPending()
{
ChatPendingLogins::iterator i = pendingLogins.begin(), next;
diff --git a/src/chathandler.h b/src/chathandler.h
index 6f71733b..fb5e4a7f 100644
--- a/src/chathandler.h
+++ b/src/chathandler.h
@@ -38,6 +38,12 @@ class ChatHandler : public ConnectionHandler
public:
void process();
+ /**
+ * Start the handler
+ */
+ bool
+ startListen(enet_uint16 port);
+
protected:
/**
* Process chat related messages.
diff --git a/src/dalstoragesql.h b/src/dalstoragesql.h
index 7614445a..582b21fe 100644
--- a/src/dalstoragesql.h
+++ b/src/dalstoragesql.h
@@ -300,16 +300,22 @@ const std::string SQL_INVENTORIES_TABLE(
#if defined (MYSQL_SUPPORT)
"id SMALLINT NOT NULL,"
"owner_id INTEGER NOT NULL,"
+ "amount SMALLINT NOT NULL,"
+ "equipped TINYINT NOT NULL,"
"FOREIGN KEY (id) REFERENCES tmw_items(id),"
"FOREIGN KEY (owner_id) REFERENCES tmw_characters(id)"
#elif defined (SQLITE_SUPPORT)
"id INTEGER NOT NULL,"
"owner_id INTEGER NOT NULL,"
+ "amount INTEGER NOT NULL,"
+ "equipped INTEGER NOT NULL,"
"FOREIGN KEY (id) REFERENCES tmw_items(id),"
"FOREIGN KEY (owner_id) REFERENCES tmw_characters(id)"
#elif defined (POSTGRESQL_SUPPORT)
"id INTEGER NOT NULL,"
"owner_id INTEGER NOT NULL,"
+ "amount INTEGER NOT NULL,"
+ "equipped INTEGER NOT NULL,"
"FOREIGN KEY (id) REFERENCES tmw_items(id),"
"FOREIGN KEY (owner_id) REFERENCES tmw_characters(id)"
#endif
diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp
index a91fbbc6..42cb0c70 100644
--- a/src/gamehandler.cpp
+++ b/src/gamehandler.cpp
@@ -86,6 +86,13 @@ void registerGameClient(std::string const &token, PlayerPtr ch)
}
}
+bool
+GameHandler::startListen(enet_uint16 port)
+{
+ LOG_INFO("Game handler started:", 0);
+ ConnectionHandler::startListen(port);
+}
+
void GameHandler::removeOutdatedPending()
{
GamePendingLogins::iterator i = pendingLogins.begin();
diff --git a/src/gamehandler.h b/src/gamehandler.h
index 41d5f780..a66bd509 100644
--- a/src/gamehandler.h
+++ b/src/gamehandler.h
@@ -39,6 +39,12 @@ class GameHandler: public ConnectionHandler
void process();
/**
+ * Start the handler
+ */
+ bool
+ startListen(enet_uint16 port);
+
+ /**
* Send message to the given player.
*/
void sendTo(Player *, MessageOut &msg);
diff --git a/src/inventory.cpp b/src/inventory.cpp
new file mode 100644
index 00000000..187c641f
--- /dev/null
+++ b/src/inventory.cpp
@@ -0,0 +1,97 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: $
+ */
+
+#include "inventory.h"
+
+unsigned short
+getSlotIndex(const unsigned int itemId)
+{
+ return 0;
+}
+
+bool
+addItem(unsigned int itemId, unsigned short amount)
+{
+ return false;
+}
+
+bool
+removeItem(unsigned int itemId, unsigned short amount = 0)
+{
+ return false;
+}
+
+bool
+removeItem(unsigned short index, unsigned short amount = 0)
+{
+ return false;
+}
+
+bool
+equipItem(unsigned int itemId)
+{
+ return false;
+}
+
+bool
+unequipItem(unsigned int itemId)
+{
+ return false;
+}
+
+bool
+equipItem(unsigned short index)
+{
+ return false;
+}
+
+bool
+unequipItem(unsigned short index)
+{
+ return false;
+}
+
+
+bool
+use(unsigned short index, BeingPtr itemUser)
+{
+ return false;
+}
+
+bool
+use(unsigned int itemId, BeingPtr itemUser)
+{
+ return false;
+}
+
+bool
+useWithScript(unsigned short index, const std::string scriptFile)
+{
+ return false;
+}
+
+bool
+useWithScript(unsigned int itemId, const std::string scriptFile)
+{
+ return false;
+}
diff --git a/src/inventory.h b/src/inventory.h
new file mode 100644
index 00000000..79d54b26
--- /dev/null
+++ b/src/inventory.h
@@ -0,0 +1,175 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: items.h 2636 2006-09-02 12:03:22Z gmelquio $
+ */
+
+#ifndef INVENTORY_H
+#define INVENTORY_H
+
+#include "item.h"
+
+/**
+ * Stored Item only contains id reference to items
+ * in the order not to carry every item info for each carried items
+ * in the inventory.
+ * Also contains amount, and if equipped.
+ */
+struct StoredItem
+{
+ unsigned int itemId;
+ unsigned short amount;
+ bool equipped;
+};
+
+/**
+ * Class used to store minimal info on player's inventories
+ * to keep it fast.
+ * See Item and ItemReference to get more info on an item.
+ */
+class Inventory
+{
+ public:
+ /**
+ * ctor.
+ */
+ Inventory() {}
+
+ /**
+ * Convenience function to get index from ItemId.
+ * If more than one occurence is found, the first is given.
+ */
+ unsigned short
+ getSlotIndex(const unsigned int itemId);
+
+ /**
+ * Return StoredItem
+ */
+ StoredItem
+ getStoredItemAt(unsigned short index) const { return itemList.at(index); };
+
+ /**
+ * Return Item reference from ItemReference
+ */
+ //ItemPtr getItem(unsigned short index) const
+ //{ return itemReferencegetItem(itemList.at(index).itemId); };
+
+ /**
+ * Tells if an item is equipped
+ */
+ bool
+ isEquipped(unsigned short index) const { return itemList.at(index).equipped; };
+
+ /**
+ * Tells an item's amount
+ */
+ unsigned short
+ getItemAmount(unsigned short index) const { return itemList.at(index).amount; };
+
+ /**
+ * Return Item reference Id
+ */
+ unsigned int
+ getItemId(unsigned short index) const { return itemList.at(index).itemId; };
+
+ /**
+ * add an item with amount
+ * (creates it non-equipped if amount was 0)
+ */
+ bool
+ addItem(unsigned int itemId, unsigned short amount);
+
+ /**
+ * Remove an item searched by ItemId.
+ * Delete if amount = 0.
+ */
+ bool
+ removeItem(unsigned int itemId, unsigned short amount = 0);
+
+ /**
+ * Remove an item searched by slot index.
+ * Delete if amount = 0.
+ */
+ bool
+ removeItem(unsigned short index, unsigned short amount = 0);
+
+ /**
+ * Equip an item searched by its id.
+ */
+ bool
+ equipItem(unsigned int itemId);
+
+ /**
+ * Unequip an item searched by its id.
+ */
+ bool
+ unequipItem(unsigned int itemId);
+
+ /**
+ * Equip an item searched by its slot index.
+ */
+ bool
+ equipItem(unsigned short index);
+
+ /**
+ * Unequip an item searched by its slot index.
+ */
+ bool
+ unequipItem(unsigned short index);
+
+ /**
+ * The function called to use an item applying
+ * only the modifiers (for simple items...)
+ */
+ bool
+ use(unsigned short index, BeingPtr itemUser);
+
+ /**
+ * The function called to use an item applying
+ * only the modifiers (for simple items...)
+ */
+ bool
+ use(unsigned int itemId, BeingPtr itemUser);
+
+ /**
+ * The function called to use an item
+ * using a script (for complex actions)
+ */
+ bool
+ useWithScript(unsigned short index, const std::string scriptFile);
+
+ /**
+ * The function called to use an item
+ * using a script (for complex actions)
+ */
+ bool
+ useWithScript(unsigned int itemId, const std::string scriptFile);
+
+ private:
+ //Item type
+ std::vector<StoredItem> itemList;
+};
+
+/**
+ * Type definition for a smart pointer to Being.
+ */
+typedef utils::CountedPtr<Inventory> InventoryPtr;
+
+#endif
diff --git a/src/item.cpp b/src/item.cpp
new file mode 100644
index 00000000..b0008134
--- /dev/null
+++ b/src/item.cpp
@@ -0,0 +1,34 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: items.cpp 2512 2006-08-04 16:58:20Z b_lindeijer $
+ */
+
+#include "item.h"
+
+void Item::use(BeingPtr itemUser)
+{
+ //
+}
+
+void Item::useWithScript(const std::string scriptFile)
+{
+ //
+}
diff --git a/src/item.h b/src/item.h
new file mode 100644
index 00000000..302c4f6a
--- /dev/null
+++ b/src/item.h
@@ -0,0 +1,136 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: items.h 2636 2006-09-02 12:03:22Z gmelquio $
+ */
+
+#ifndef ITEM_H
+#define ITEM_H
+
+#include "being.h"
+
+/**
+ * Enumeration of available Item types.
+ */
+enum {
+ ITEM_USABLE = 0,
+ ITEM_EQUIPMENT_WEAPON,
+ ITEM_EQUIPMENT_BREST,
+ ITEM_EQUIPMENT_ARMS,
+ ITEM_EQUIPMENT_HEAD,
+ ITEM_EQUIPMENT_LEGS,
+ ITEM_EQUIPMENT_SHIELD,
+ ITEM_EQUIPMENT_RING,
+ ITEM_EQUIPMENT_NECKLACE
+};
+
+/**
+ * statistics modifiers.
+ * once for usables.
+ * Permanent for equipment.
+ */
+struct StatisticsModifiers
+{
+ short rawStatsMod[NB_RSTAT]; /**< Raw Stats modifiers */
+ short compStatsMod[NB_CSTAT]; /**< Computed Stats modifiers */
+ int hpMod; /**< HP modifier */
+ int mpMod; /**< MP Modifier */
+ /**< More to come */
+};
+
+
+/**
+ * Class for simple reference to item information.
+ * See WorldItem to get full featured Item Objects.
+ */
+class Item
+{
+ public:
+
+ Item(StatisticsModifiers statsModifiers,
+ unsigned short mItemType = 0,
+ unsigned int weight = 0,
+ unsigned short slot = 0,
+ unsigned int value = 0):
+ mWeight(weight),
+ mSlot(slot),
+ mValue(value),
+ mStatsModifiers(statsModifiers) {}
+
+ virtual ~Item() throw() { }
+
+ /**
+ * The function called to use an item applying
+ * only the modifiers (for simple items...)
+ */
+ void use(BeingPtr itemUser);
+
+ /**
+ * The function called to use an item
+ * using a script (for complex actions)
+ */
+ void useWithScript(const std::string scriptFile);
+
+ /**
+ * Return item Type
+ */
+ unsigned short getItemType() const { return mItemType; }
+
+ /**
+ * Return Weight of item
+ */
+ unsigned int getWeight() const { return mWeight; }
+
+ /**
+ * Return usual slot of item
+ */
+ unsigned short getSlot() const { return mSlot; }
+
+ /**
+ * Return gold value of item
+ */
+ unsigned int getGoldValue() const { return mValue; }
+
+ /**
+ * Return item's modifiers
+ */
+ StatisticsModifiers
+ getItemStatsModifiers() const { return mStatsModifiers; }
+
+ private:
+ //Item type
+ unsigned short mItemType; /**< ItemType: Usable, equipment */
+ unsigned int mWeight; /**< Weight of the item */
+ unsigned short mSlot; /**< Current slot of the item */
+ unsigned int mValue; /**< Gold value of the item */
+ StatisticsModifiers mStatsModifiers; /**< Stats Mod of the items */
+};
+
+/**
+ * Type definition for a smart pointer to Item.
+ */
+typedef utils::CountedPtr<Item> ItemPtr;
+
+/**
+ * Type definition for a list of Items.
+ */
+typedef std::vector<ItemPtr> Items;
+
+#endif
diff --git a/src/items.cpp b/src/itemhandler.cpp
index 659e24db..f1030df6 100644
--- a/src/items.cpp
+++ b/src/itemhandler.cpp
@@ -1,5 +1,5 @@
/*
- * The Mana World Server
+ * The Mana World
* Copyright 2004 The Mana World Development Team
*
* This file is part of The Mana World.
@@ -18,12 +18,12 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id$
+ * $Id: $
*/
-#include "items.h"
+#include "itemhandler.h"
+
+#include "storage.h"
+
+#include "utils/logger.h"
-void Item::use()
-{
- //
-}
diff --git a/src/items.h b/src/itemhandler.h
index 191b90a4..ff57fb44 100644
--- a/src/items.h
+++ b/src/itemhandler.h
@@ -1,5 +1,5 @@
/*
- * The Mana World Server
+ * The Mana World
* Copyright 2004 The Mana World Development Team
*
* This file is part of The Mana World.
@@ -18,47 +18,39 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id$
+ * $Id: $
*/
-#ifndef ITEMS_H
-#define ITEMS_H
+#ifndef _TMW_ITEMHANDLER_H
+#define _TMW_ITEMHANDLER_H
-#include "object.h"
+#include <item.h>
+#include <mapcomposite.h>
/**
- * Class for all types of in-game items.
+ * The Item Handler loads the item reference database
+ * and also manage everyone items interaction with other objects
+ * (including other players) and the world.
*/
-class Item : public Object
+class ItemHandler
{
public:
- /**
- * Enumeration of available Item types.
- */
- enum {
- Usable,
- Equipment
- };
-
- Item(int type):
- Object(type)
- {}
-
- virtual ~Item() throw() { }
+ ItemHandler(std::string itemReferenceFile);
/**
- * The function called to use an item
+ * Drop items on the map.
*/
- void use();
+ bool
+ drop(BeingPtr beingPtr, unsigned int itemId, unsigned short amount);
/**
- * Return type of item
+ * Pick an item on the ground
*/
- unsigned int getType() const { return type; }
+ bool
+ getItem(BeingPtr beingPtr, ItemPtr itemPtr);
private:
- //Item type
- unsigned int type;
+ std::pair<unsigned int, ItemPtr> ItemReference;
};
#endif