summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-09-02 12:03:22 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-09-02 12:03:22 +0000
commit379c0e936e090a19d295d8514cf94b4fb367eae6 (patch)
tree3297be7e5a53ed55c5db92bc80e0e65db2ee7bb3 /src
parent1140de4450b3840340df6459eb6d13cc02496e46 (diff)
downloadmanaserv-379c0e936e090a19d295d8514cf94b4fb367eae6.tar.gz
manaserv-379c0e936e090a19d295d8514cf94b4fb367eae6.tar.bz2
manaserv-379c0e936e090a19d295d8514cf94b4fb367eae6.tar.xz
manaserv-379c0e936e090a19d295d8514cf94b4fb367eae6.zip
Decorrelated moving object IDs from character database IDs. Switched to short IDs instead.
Diffstat (limited to 'src')
-rw-r--r--src/controller.cpp2
-rw-r--r--src/dalstorage.cpp9
-rw-r--r--src/defines.h9
-rw-r--r--src/gamehandler.cpp2
-rw-r--r--src/items.h4
-rw-r--r--src/object.cpp6
-rw-r--r--src/object.h36
-rw-r--r--src/player.cpp8
-rw-r--r--src/player.h18
-rw-r--r--src/state.cpp17
10 files changed, 66 insertions, 45 deletions
diff --git a/src/controller.cpp b/src/controller.cpp
index 17f15017..a73b7a5f 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -60,7 +60,7 @@ void Controller::update()
unsigned int randomY = rand() % 320 + 840;
LOG_INFO("Setting new random destination " << randomX << ","
- << randomY << " for being " << mBeing->getID(), 2);
+ << randomY << " for being " << mBeing->getPublicID(), 2);
mBeing->setDestination(randomX, randomY);
}
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index 5fabfce6..b1c4fc0c 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -629,7 +629,7 @@ void DALStorage::flush(AccountPtr const &account)
it_end = characters.end(); it != it_end; ++it) {
std::ostringstream sql3;
- if ((*it)->getID() < 0) {
+ if ((*it)->getDatabaseID() < 0) {
// insert the character
sql3 << "insert into " << CHARACTERS_TBL_NAME
<< " (user_id, name, gender, hair_style, hair_color, level, money,"
@@ -657,12 +657,13 @@ void DALStorage::flush(AccountPtr const &account)
<< " where name = \"" << (*it)->getName() << "\";";
RecordSet const &charInfo = mDb->execSql(sql2.str());
if (charInfo.isEmpty()) {
- (*it)->setID(1);
+ // FIXME: this does not make any sense to me -- silene
+ (*it)->setDatabaseID(1);
}
else
{
string_to<unsigned int> toUint;
- (*it)->setID(toUint(charInfo(0, 0)));
+ (*it)->setDatabaseID(toUint(charInfo(0, 0)));
}
} else {
sql3 << "update " << CHARACTERS_TBL_NAME
@@ -685,7 +686,7 @@ void DALStorage::flush(AccountPtr const &account)
#endif
<< " dex = " << (*it)->getRawStat(STAT_DEX) << ", "
<< " luck = " << (*it)->getRawStat(STAT_LUK)
- << " where id = " << (*it)->getID() << ";";
+ << " where id = " << (*it)->getDatabaseID() << ";";
}
mDb->execSql(sql3.str());
diff --git a/src/defines.h b/src/defines.h
index 68ce8103..8f8988d2 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -144,13 +144,14 @@ enum {
// [, S32 token, S server, W port]
PGMSG_PICKUP = 0x0110,
GPMSG_PICKUP_RESPONSE = 0x0111,
- GPMSG_BEING_ENTER = 0x0200, // B type, L being id
+ GPMSG_BEING_ENTER = 0x0200, // B type, W being id
// player: S name, B hair style, B hair color, B gender
- GPMSG_BEING_LEAVE = 0x0201, // B type, L being id
+ // monster: W type id
+ GPMSG_BEING_LEAVE = 0x0201, // W being id
PGMSG_WALK = 0x0260, // W*2 destination
- GPMSG_BEINGS_MOVE = 0x0280, // { L being id, W*2 position, W*2 destination }*
+ GPMSG_BEINGS_MOVE = 0x0280, // { W being id, W*2 position, W*2 destination }*
PGMSG_SAY = 0x02A0, // S text
- GPMSG_SAY = 0x02A1, // L being id, S text
+ GPMSG_SAY = 0x02A1, // W being id, S text
PGMSG_USE_ITEM = 0x0300, // L item id
GPMSG_USE_RESPONSE = 0x0301, // B error
PGMSG_EQUIP = 0x0302, // L item id, B slot
diff --git a/src/gamehandler.cpp b/src/gamehandler.cpp
index eeb49478..9b30299e 100644
--- a/src/gamehandler.cpp
+++ b/src/gamehandler.cpp
@@ -227,7 +227,7 @@ void GameHandler::sayAround(GameClient &computer, std::string const &text)
PlayerPtr beingPtr = computer.getCharacter();
MessageOut msg(GPMSG_SAY);
- msg.writeLong(beingPtr->getID());
+ msg.writeShort(beingPtr->getPublicID());
msg.writeString(text);
unsigned speakerMapId = beingPtr->getMapId();
diff --git a/src/items.h b/src/items.h
index 99afba3f..191b90a4 100644
--- a/src/items.h
+++ b/src/items.h
@@ -40,8 +40,8 @@ class Item : public Object
Equipment
};
- Item(int type, int id):
- Object(type, id)
+ Item(int type):
+ Object(type)
{}
virtual ~Item() throw() { }
diff --git a/src/object.cpp b/src/object.cpp
index ddbd10c7..075b22fa 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -28,12 +28,6 @@
#include "map.h"
#include "mapmanager.h"
-void Object::setID(int id)
-{
- assert(mID < 0);
- mID = id;
-}
-
void MovingObject::move()
{
unsigned mSrcX = getX(), mSrcY = getY();
diff --git a/src/object.h b/src/object.h
index 793c3a66..d57b3596 100644
--- a/src/object.h
+++ b/src/object.h
@@ -40,9 +40,8 @@ class Object
/**
* Constructor.
*/
- Object(int type, int id)
+ Object(int type)
: mType(type),
- mID(id),
mNew(true),
mNeedUpdate(false)
{}
@@ -61,20 +60,6 @@ class Object
{ return mType; }
/**
- * Get object ID.
- *
- * @return the unique ID, a negative number if none yet.
- */
- int getID() const
- { return mID; }
-
- /**
- * Set object ID.
- * The account shall not have any ID yet.
- */
- void setID(int id);
-
- /**
* Set the x coordinate.
*
* @param x the new x coordinate.
@@ -157,7 +142,6 @@ class Object
private:
int mType; /**< Object type */
- int mID; /** Object unique ID (wrt its type and its map at least) */
unsigned int mX; /**< x coordinate */
unsigned int mY; /**< y coordinate */
unsigned int mMapId; /**< id of the map being is on */
@@ -177,7 +161,7 @@ class MovingObject: public Object
* Proxy constructor.
*/
MovingObject(int type, int id)
- : Object(type, id)
+ : Object(type), mPublicID(id)
{}
/**
@@ -209,7 +193,23 @@ class MovingObject: public Object
*/
void move();
+ /**
+ * Get public ID.
+ *
+ * @return the public ID, 65535 if none yet.
+ */
+ int getPublicID() const
+ { return mPublicID; }
+
+ /**
+ * Set public ID.
+ * The object shall not have any public ID yet.
+ */
+ void setPublicID(int id)
+ { mPublicID = id; }
+
private:
+ unsigned short mPublicID; /**< Object ID sent to clients (unique with respect to the map) */
unsigned mDstX; /**< target x coordinate */
unsigned mDstY; /**< target y coordinate */
unsigned mNewX; /**< next x coordinate */
diff --git a/src/player.cpp b/src/player.cpp
index cd793d96..25e8b2ea 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -22,6 +22,14 @@
#include "player.h"
+#include <cassert>
+
+void Player::setDatabaseID(int id)
+{
+ assert(mDatabaseID == -1);
+ mDatabaseID = id;
+}
+
/**
* Update the internal status.
*/
diff --git a/src/player.h b/src/player.h
index 0dc8ae58..e812a73d 100644
--- a/src/player.h
+++ b/src/player.h
@@ -38,7 +38,8 @@ class Player : public Being
public:
Player(std::string const &name, int id = -1)
- : Being(OBJECT_PLAYER, id),
+ : Being(OBJECT_PLAYER, 65535),
+ mDatabaseID(id),
mName(name)
{}
@@ -199,10 +200,25 @@ class Player : public Being
bool
unequip(unsigned char slot);
+ /**
+ * Get database ID.
+ *
+ * @return the database ID, a negative number if none yet, or if not relevant.
+ */
+ int getDatabaseID() const
+ { return mDatabaseID; }
+
+ /**
+ * Set database ID.
+ * The object shall not have any ID yet.
+ */
+ void setDatabaseID(int id);
+
private:
Player(Player const &);
Player &operator=(Player const &);
+ int mDatabaseID; /**< Player database ID (unique with respect to its type) */
std::string mName; /**< name of the being */
Gender mGender; /**< gender of the being */
unsigned char mHairStyle; /**< Hair Style of the being */
diff --git a/src/state.cpp b/src/state.cpp
index 71c9fad0..e3f833a8 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -114,7 +114,7 @@ State::update()
int type = (*o)->getType();
MessageOut msg2(GPMSG_BEING_ENTER);
msg2.writeByte(type);
- msg2.writeLong((*o)->getID());
+ msg2.writeShort((*o)->getPublicID());
switch (type) {
case OBJECT_PLAYER:
{
@@ -137,8 +137,7 @@ State::update()
{
// o is no longer visible from p.
MessageOut msg2(GPMSG_BEING_LEAVE);
- msg2.writeByte((*o)->getType());
- msg2.writeLong((*o)->getID());
+ msg2.writeShort((*o)->getPublicID());
gameHandler->sendTo(*p, msg2);
continue;
}
@@ -151,14 +150,14 @@ State::update()
/* At this point, either o has entered p's range, either o is
moving inside p's range. Report o's movements. */
Point od = (*o)->getDestination();
- msg.writeLong((*o)->getID());
+ msg.writeShort((*o)->getPublicID());
msg.writeShort(on.x);
msg.writeShort(on.y);
msg.writeShort(od.x);
msg.writeShort(od.y);
}
- // Don't send a packet if nothing happed in p's range.
+ // Don't send a packet if nothing happened in p's range.
if (msg.getLength() > 2)
gameHandler->sendTo(*p, msg);
}
@@ -180,7 +179,10 @@ State::addObject(ObjectPtr objectPtr)
maps[mapId].objects.push_back(objectPtr);
objectPtr->setNew(true);
if (objectPtr->getType() != OBJECT_PLAYER) return;
- maps[mapId].players.push_back(PlayerPtr(objectPtr));
+ PlayerPtr ptr(objectPtr);
+ // TODO: Unique object numbering
+ ptr->setPublicID(ptr->getDatabaseID());
+ maps[mapId].players.push_back(ptr);
}
void
@@ -200,8 +202,7 @@ State::removeObject(ObjectPtr objectPtr)
if (objectPtr->getType() != OBJECT_PLAYER) return;
MessageOut msg(GPMSG_BEING_LEAVE);
- msg.writeByte(OBJECT_PLAYER);
- msg.writeLong(objectPtr->getID());
+ msg.writeShort(PlayerPtr(objectPtr)->getPublicID());
Point objectPosition = objectPtr->getXY();
Players &players = maps[mapId].players;