From acc647ed2767df17c856931f721c88deef9765c8 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Tue, 13 Sep 2011 19:11:56 +0200 Subject: Renamed Map::DebugFlags enumerators Their name is a bit more clear with DEBUG prefix rather than MAP prefix. They're already scoped in the Map class anyway. MAP_NORMAL was changed to DEBUG_NONE to represent no debug flags. Acked-by: Bertram --- src/gui/debugwindow.cpp | 18 +++++++++--------- src/gui/viewport.cpp | 10 +++++----- src/map.cpp | 14 +++++++------- src/map.h | 26 +++++++++++++------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index f1b24a49..06d50d5c 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -181,23 +181,23 @@ public: int flags = 0; if (mGrid->isSelected()) - flags |= Map::MAP_GRID; + flags |= Map::DEBUG_GRID; if (mCollisionTiles->isSelected()) - flags |= Map::MAP_COLLISION_TILES; + flags |= Map::DEBUG_COLLISION_TILES; if (mBeingCollisionRadius->isSelected()) - flags |= Map::MAP_BEING_COLLISION_RADIUS; + flags |= Map::DEBUG_BEING_COLLISION_RADIUS; if (mBeingPosition->isSelected()) - flags |= Map::MAP_BEING_POSITION; + flags |= Map::DEBUG_BEING_POSITION; if (mBeingPath->isSelected()) - flags |= Map::MAP_BEING_PATH; + flags |= Map::DEBUG_BEING_PATH; if (mMousePath->isSelected()) - flags |= Map::MAP_MOUSE_PATH; + flags |= Map::DEBUG_MOUSE_PATH; if (mSpecial1->isSelected()) - flags |= Map::MAP_SPECIAL1; + flags |= Map::DEBUG_SPECIAL1; if (mSpecial2->isSelected()) - flags |= Map::MAP_SPECIAL2; + flags |= Map::DEBUG_SPECIAL2; if (mSpecial3->isSelected()) - flags |= Map::MAP_SPECIAL3; + flags |= Map::DEBUG_SPECIAL3; viewport->setShowDebugPath(flags); } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 0353fd44..5e519879 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -201,7 +201,7 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) if (mDebugFlags) { - if (mDebugFlags & (Map::MAP_GRID | Map::MAP_COLLISION_TILES)) + if (mDebugFlags & (Map::DEBUG_GRID | Map::DEBUG_COLLISION_TILES)) { mMap->drawCollision(graphics, (int) mPixelViewX, (int) mPixelViewY, mDebugFlags); @@ -294,7 +294,7 @@ void Viewport::_followMouse() void Viewport::_drawDebugPath(Graphics *graphics) { - if (mDebugFlags & Map::MAP_MOUSE_PATH) + if (mDebugFlags & Map::DEBUG_MOUSE_PATH) { // Get the current mouse position SDL_GetMouseState(&mMouseX, &mMouseY); @@ -359,7 +359,7 @@ void Viewport::_drawDebugPath(Graphics *graphics) const Vector &beingPos = being->getPosition(); graphics->setColor(gcn::Color(128, 128, 0, 150)); - if (mDebugFlags & Map::MAP_BEING_COLLISION_RADIUS) + if (mDebugFlags & Map::DEBUG_BEING_COLLISION_RADIUS) { const int radius = being->getCollisionRadius(); graphics->fillRectangle(gcn::Rectangle( @@ -370,10 +370,10 @@ void Viewport::_drawDebugPath(Graphics *graphics) radius * 2, radius * 2)); } - if (mDebugFlags & Map::MAP_BEING_PATH) + if (mDebugFlags & Map::DEBUG_BEING_PATH) _drawPath(graphics, being->getPath(), gcn::Color(0, 0, 255, 150)); - if (mDebugFlags & Map::MAP_BEING_POSITION) + if (mDebugFlags & Map::DEBUG_BEING_POSITION) { // Draw the absolute x, y position using a cross. graphics->setColor(gcn::Color(0, 0, 255, 255)); diff --git a/src/map.cpp b/src/map.cpp index 3e5e8e12..525f5a20 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -158,7 +158,7 @@ void MapLayer::draw(Graphics *graphics, } } - if (!(debugFlags & Map::MAP_SPECIAL3)) + if (!(debugFlags & Map::DEBUG_SPECIAL3)) { const int py0 = pixelY + dy; @@ -169,7 +169,7 @@ void MapLayer::draw(Graphics *graphics, { const int px = (x * mMap->getTileWidth()) + dx; const int py = py0 - img->getHeight(); - if (!(debugFlags & (Map::MAP_SPECIAL1 | Map::MAP_SPECIAL2)) + if (!(debugFlags & (Map::DEBUG_SPECIAL1 | Map::DEBUG_SPECIAL2)) || img->getHeight() <= mMap->getTileHeight()) { int width = 0; @@ -222,7 +222,7 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): mTileWidth(tileWidth), mTileHeight(tileHeight), mMaxTileHeight(tileHeight), mMaxTileWidth(tileWidth), - mDebugFlags(MAP_NORMAL), + mDebugFlags(DEBUG_NONE), mOnClosedList(1), mOnOpenList(2), mLastScrollX(0.0f), mLastScrollY(0.0f) { @@ -370,7 +370,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) bool overFringe = false; - if (mDebugFlags & MAP_SPECIAL3) + if (mDebugFlags & DEBUG_SPECIAL3) { for (; layeri != mLayers.end(); ++layeri) { @@ -387,7 +387,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) { for (; layeri != mLayers.end() && !overFringe; ++layeri) { - if ((*layeri)->isFringeLayer() && (mDebugFlags & MAP_SPECIAL2)) + if ((*layeri)->isFringeLayer() && (mDebugFlags & DEBUG_SPECIAL2)) overFringe = true; (*layeri)->draw(graphics, @@ -443,7 +443,7 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY, { graphics->setColor(gcn::Color(0, 0, 0, 64)); - if (debugFlags & MAP_GRID) + if (debugFlags & DEBUG_GRID) { graphics->drawRectangle(gcn::Rectangle( x * mTileWidth - scrollX, @@ -451,7 +451,7 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY, mTileWidth + 1, mTileHeight + 1)); } - if (!(debugFlags & MAP_COLLISION_TILES)) + if (!(debugFlags & DEBUG_COLLISION_TILES)) continue; if (!getWalk(x, y, BLOCKMASK_WALL)) diff --git a/src/map.h b/src/map.h index 19cd0e9d..21450c35 100644 --- a/src/map.h +++ b/src/map.h @@ -123,7 +123,7 @@ class MapLayer int endX, int endY, int scrollX, int scrollY, const Actors &actors, - int mDebugFlags) const; + int debugFlags) const; bool isFringeLayer() { return mIsFringeLayer; } @@ -162,16 +162,16 @@ class Map : public Properties enum DebugFlags { - MAP_NORMAL = 0x0, - MAP_GRID = 0x1, - MAP_COLLISION_TILES = 0x2, - MAP_BEING_COLLISION_RADIUS = 0x4, - MAP_BEING_POSITION = 0x8, - MAP_BEING_PATH = 0x10, - MAP_MOUSE_PATH = 0x20, - MAP_SPECIAL1 = 0x40, - MAP_SPECIAL2 = 0x80, - MAP_SPECIAL3 = 0x100 + DEBUG_NONE = 0x0, + DEBUG_GRID = 0x1, + DEBUG_COLLISION_TILES = 0x2, + DEBUG_BEING_COLLISION_RADIUS = 0x4, + DEBUG_BEING_POSITION = 0x8, + DEBUG_BEING_PATH = 0x10, + DEBUG_MOUSE_PATH = 0x20, + DEBUG_SPECIAL1 = 0x40, + DEBUG_SPECIAL2 = 0x80, + DEBUG_SPECIAL3 = 0x100 }; /** @@ -324,9 +324,9 @@ class Map : public Properties void addAnimation(int gid, TileAnimation *animation) { mTileAnimations[gid] = animation; } - void setDebugFlags(int n) {mDebugFlags = n;} + void setDebugFlags(int flags) { mDebugFlags = flags; } - int getDebugFlags() const {return mDebugFlags;} + int getDebugFlags() const { return mDebugFlags; } /** * Gets the tile animation for a specific gid -- cgit v1.2.3-70-g09d2 From 421cfc174dca220ad092759f013fa413efb07294 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 1 Jul 2011 22:57:29 +0200 Subject: Made the delay between to keyboard move calls functional. It has been fixed and be made adapted to the being movement speed. Now, for instance, the client sends 3x times less move calls to the tA server, and roughly 20x times for the Manaserv's one. Resolves: Mana-Mantis #346. Reviewed-by: o11c. --- src/being.h | 2 +- src/localplayer.cpp | 15 +++++++++------ src/localplayer.h | 9 +++++++++ src/net/manaserv/playerhandler.cpp | 8 ++++++++ src/net/manaserv/playerhandler.h | 2 ++ src/net/playerhandler.h | 8 +++++++- src/net/tmwa/playerhandler.cpp | 6 ++++++ src/net/tmwa/playerhandler.h | 2 ++ 8 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/being.h b/src/being.h index 1cf713fa..c6fd63ed 100644 --- a/src/being.h +++ b/src/being.h @@ -319,7 +319,7 @@ class Being : public ActorSprite, public EventListener * in ticks per tile for eAthena, * in tiles per second for Manaserv (0.1 precision). */ - void setMoveSpeed(const Vector &speed); + virtual void setMoveSpeed(const Vector &speed); /** * Gets the original Move speed. diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 1a7f20e1..78395438 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -58,11 +58,6 @@ #include -// This is the minimal delay between to permitted -// setDestination() calls using the keyboard. -// TODO: This can fine tuned later on when running is added... -const short walkingKeyboardDelay = 1000; - #define AWAY_LIMIT_TIMER 60 LocalPlayer *player_node = NULL; @@ -79,6 +74,7 @@ LocalPlayer::LocalPlayer(int id, int subtype): mWalkingDir(0), mPathSetByMouse(false), mLocalWalkTime(-1), + mKeyboardMoveDelay(500), mMessageTime(0), mShowIp(false), mAwayDialog(0), @@ -741,8 +737,9 @@ void LocalPlayer::setWalkingDir(int dir) // If the delay to send another walk message to the server hasn't expired, // don't do anything or we could get disconnected for spamming the server - if (get_elapsed_time(mLocalWalkTime) < walkingKeyboardDelay) + if (get_elapsed_time(mLocalWalkTime) < mKeyboardMoveDelay) return; + mLocalWalkTime = tick_time; mWalkingDir = dir; @@ -808,6 +805,12 @@ void LocalPlayer::stopWalking(bool sendToServer) clearPath(); } +void LocalPlayer::setMoveSpeed(const Vector& speed) +{ + Being::setMoveSpeed(speed); + mKeyboardMoveDelay = Net::getPlayerHandler()->getKeyboardMoveDelay(speed); +} + void LocalPlayer::toggleSit() { if (mLastAction != -1) diff --git a/src/localplayer.h b/src/localplayer.h index ab309d8f..ae27e51e 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -147,6 +147,8 @@ class LocalPlayer : public Being */ void setTarget(Being *target); + void setMoveSpeed(const Vector &speed); + /** * Sets a new destination for this being to walk to. */ @@ -253,6 +255,13 @@ class LocalPlayer : public Being int mLocalWalkTime; /**< Timestamp used to control keyboard walk messages flooding */ + /** + * The delay between two permitted setDestination() call using + * the keyboard. + * It's set in milliseconds per tile. + */ + int mKeyboardMoveDelay; + typedef std::pair MessagePair; /** Queued messages*/ std::list mMessages; diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index a114da3d..d7c3dab6 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -442,4 +442,12 @@ Vector PlayerHandler::getPixelsPerTickMoveSpeed(const Vector &speed, Map *map) return speedInTicks; } +int PlayerHandler::getKeyboardMoveDelay(const Vector& speed) +{ + int maxSpeed = std::max(speed.x, speed.y); + if (maxSpeed <= 0) + maxSpeed = 2; + return 1000 / maxSpeed; +} + } // namespace ManaServ diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h index 3e3f8aad..0edb4354 100644 --- a/src/net/manaserv/playerhandler.h +++ b/src/net/manaserv/playerhandler.h @@ -69,6 +69,8 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler Vector getPixelsPerTickMoveSpeed(const Vector &speed, Map *map = 0); + int getKeyboardMoveDelay(const Vector& speed); + bool usePixelPrecision() { return true; } diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index f9396caf..b52b6315 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -71,11 +71,17 @@ class PlayerHandler virtual Vector getDefaultMoveSpeed() const = 0; /** - * Convert the original speed in pixel per tick for internal use. + * Convert the original server-dependant speed for internal use. */ virtual Vector getPixelsPerTickMoveSpeed(const Vector &speed, Map *map = 0) = 0; + /** + * Convert the original speed into the keyboard move delay. + * The delay is set in milliseconds per tiles. + */ + virtual int getKeyboardMoveDelay(const Vector& speed) = 0; + /** * Tells whether the client has to use pixel paths. * Return false when tiles-center positions only are to be used. diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index f30baecd..dd228f11 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -22,6 +22,7 @@ #include "net/tmwa/playerhandler.h" #include "net/tmwa/beinghandler.h" +#include "client.h" #include "configuration.h" #include "game.h" #include "localplayer.h" @@ -661,4 +662,9 @@ Vector PlayerHandler::getPixelsPerTickMoveSpeed(const Vector &speed, Map *map) return speedInTicks; } +int PlayerHandler::getKeyboardMoveDelay(const Vector& speed) +{ + return std::min(speed.x, speed.y) * MILLISECONDS_IN_A_TICK; +} + } // namespace TmwAthena diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index 63812f47..3e22be22 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -62,6 +62,8 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler Vector getPixelsPerTickMoveSpeed(const Vector &speed, Map *map = 0); + int getKeyboardMoveDelay(const Vector& speed); + bool usePixelPrecision() { return false; } }; -- cgit v1.2.3-70-g09d2 From 0d6c98b33612b548b400e2bd396933936327f6de Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 14 Sep 2011 13:25:41 -0700 Subject: Instead of SDL_mutex, use Mutex wrapper and MutexLocker for safety MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Thorbjørn Lindeijer --- src/net/tmwa/network.cpp | 31 +++++++++---------------------- src/net/tmwa/network.h | 4 +++- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 4d2073a0..44559170 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -111,7 +111,6 @@ Network::Network(): { SDLNet_Init(); - mMutex = SDL_CreateMutex(); mInstance = this; } @@ -122,7 +121,6 @@ Network::~Network() if (mState != IDLE && mState != NET_ERROR) disconnect(); - SDL_DestroyMutex(mMutex); mInstance = 0; delete[] mInBuffer; @@ -246,8 +244,7 @@ void Network::flush() int ret; - - SDL_mutexP(mMutex); + MutexLocker lock(&mMutex); ret = SDLNet_TCP_Send(mSocket, mOutBuffer, mOutSize); if (ret < (int)mOutSize) { @@ -255,18 +252,14 @@ void Network::flush() std::string(SDLNet_GetError())); } mOutSize = 0; - SDL_mutexV(mMutex); } void Network::skip(int len) { - SDL_mutexP(mMutex); + MutexLocker lock(&mMutex); mToSkip += len; if (!mInSize) - { - SDL_mutexV(mMutex); return; - } if (mInSize >= mToSkip) { @@ -279,14 +272,13 @@ void Network::skip(int len) mToSkip -= mInSize; mInSize = 0; } - SDL_mutexV(mMutex); } bool Network::messageReady() { int len = -1, msgId; - SDL_mutexP(mMutex); + MutexLocker lock(&mMutex); if (mInSize >= 2) { msgId = readWord(0); @@ -300,10 +292,7 @@ bool Network::messageReady() } - bool ret = (mInSize >= static_cast(len)); - SDL_mutexV(mMutex); - - return ret; + return mInSize >= static_cast(len); } MessageIn Network::getNextMessage() @@ -314,7 +303,7 @@ MessageIn Network::getNextMessage() break; } - SDL_mutexP(mMutex); + MutexLocker lock(&mMutex); int msgId = readWord(0); int len; if (msgId == SMSG_SERVER_VERSION_RESPONSE) @@ -329,10 +318,7 @@ MessageIn Network::getNextMessage() logger->log("Received packet 0x%x of length %d", msgId, len); #endif - MessageIn msg(mInBuffer, len); - SDL_mutexV(mMutex); - - return msg; + return MessageIn(mInBuffer, len); } bool Network::realConnect() @@ -399,8 +385,9 @@ void Network::receive() break; case 1: + { // Receive data from the socket - SDL_mutexP(mMutex); + MutexLocker lock(&mMutex); ret = SDLNet_TCP_Recv(mSocket, mInBuffer + mInSize, BUFFER_SIZE - mInSize); if (!ret) @@ -432,8 +419,8 @@ void Network::receive() } } } - SDL_mutexV(mMutex); break; + } default: // more than one socket is ready.. diff --git a/src/net/tmwa/network.h b/src/net/tmwa/network.h index 2c19c218..b82d07b3 100644 --- a/src/net/tmwa/network.h +++ b/src/net/tmwa/network.h @@ -22,6 +22,8 @@ #ifndef NET_TA_NETWORK_H #define NET_TA_NETWORK_H +#include "utils/mutex.h" + #include "net/serverinfo.h" #include "net/tmwa/messagehandler.h" @@ -116,7 +118,7 @@ class Network std::string mError; SDL_Thread *mWorkerThread; - SDL_mutex *mMutex; + Mutex mMutex; typedef std::map MessageHandlers; typedef MessageHandlers::iterator MessageHandlerIterator; -- cgit v1.2.3-70-g09d2 From 74594b897097b6dc61b7525b4389e15be5771dad Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 14 Sep 2011 13:54:32 -0700 Subject: Prevent copying of MutexLocker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a bug here, which wouldn't surface if the copy was elided. Fixed by using a move constructor. Reviewed-by: Thorbjørn Lindeijer --- src/utils/mutex.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/mutex.h b/src/utils/mutex.h index f98bcdfe..92bbd614 100644 --- a/src/utils/mutex.h +++ b/src/utils/mutex.h @@ -53,9 +53,13 @@ class MutexLocker { public: MutexLocker(Mutex *mutex); + MutexLocker(MutexLocker&&); ~MutexLocker(); private: + MutexLocker(const MutexLocker&); // prevent copying + MutexLocker& operator=(const MutexLocker&); + Mutex *mMutex; }; @@ -89,9 +93,15 @@ inline MutexLocker::MutexLocker(Mutex *mutex): mMutex->lock(); } +inline MutexLocker::MutexLocker(MutexLocker&& rhs): + mMutex(rhs.mMutex) +{ + rhs.mMutex = NULL; +} inline MutexLocker::~MutexLocker() { - mMutex->unlock(); + if (mMutex) + mMutex->unlock(); } #endif // MUTEX_H -- cgit v1.2.3-70-g09d2 From 1c15e85d062b8bf2d83a2c28652de652ca915694 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 14 Sep 2011 14:15:48 -0700 Subject: Improve handling of packet lengths. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use a symbol, VAR, instead of -1 for variable-length packets. * Also change it's value to 1, so the length can be properly unsigned. Note: A packet can't actually have length 1, since packet ID is 2 bytes. * Use correct type (uint16_t) for packet id and length in more places. * Avoid reading beyond the length of the array. * Immediately parse variable length packets with length 4 (i.e. no body) instead of waiting for another byte to arrive first. Reviewed-by: Thorbjørn Lindeijer --- src/net/tmwa/network.cpp | 88 +++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 44559170..2660eb50 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -37,7 +37,10 @@ /** Warning: buffers and other variables are shared, so there can be only one connection active at a time */ -short packet_lengths[] = { +// indicator for a variable-length packet +const uint16_t VAR = 1; + +uint16_t packet_lengths[0x220] = { 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -45,38 +48,38 @@ short packet_lengths[] = { // #0x0040 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 50, 3, -1, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2, - 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6, + 0, 50, 3,VAR, 55, 17, 3, 37, 46,VAR, 23,VAR, 3,108, 3, 2, + 3, 28, 19, 11, 3,VAR, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6, // #0x0080 - 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23, -1, -1, -1, 0, - 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6, - 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6, - 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3, + 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23,VAR,VAR,VAR, 0, + 7, 22, 28, 2, 6, 30,VAR,VAR, 3,VAR,VAR, 5, 9, 17, 17, 6, + 23, 6, 6,VAR,VAR,VAR,VAR, 8, 7, 6, 7, 4, 7, 0,VAR, 6, + 8, 8, 3, 3,VAR, 6, 6,VAR, 7, 6, 2, 5, 6, 44, 5, 3, // #0x00C0 - 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 6, 2, 27, - 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1, + 7, 2, 6, 8, 6, 7,VAR,VAR,VAR,VAR, 3, 3, 6, 6, 2, 27, + 3, 4, 4, 2,VAR,VAR, 3,VAR, 6, 14, 3,VAR, 28, 29,VAR,VAR, 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2, - 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10, + 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3,VAR, 6, 27, 30, 10, // #0x0100 - 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1, + 2, 6, 6, 30, 79, 31, 10, 10,VAR,VAR, 4, 6, 6, 2, 11,VAR, 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16, - 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1, - 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26, + 6, 14,VAR,VAR, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2,VAR, + 6, 86, 6,VAR,VAR, 7,VAR, 6, 3, 16, 4, 4, 4, 6, 24, 26, // #0x0140 - 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6, - 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42, - -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182, - 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1, + 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27,VAR, 2, 6, 6, + 110, 6,VAR,VAR,VAR,VAR,VAR, 6,VAR, 54, 66, 54, 90, 42, 6, 42, + VAR,VAR,VAR,VAR,VAR, 30,VAR, 3, 14, 3, 30, 10, 43, 14,186,182, + 14, 30, 10, 3,VAR, 6,106,VAR, 4, 5, 4,VAR, 6, 7,VAR,VAR, // #0x0180 - 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6, + 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29,VAR, 10, 6, 90, 86, 24, 6, 30, 102, 9, 4, 8, 4, 14, 10, 4, 6, 2, 6, - 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4, - 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3, + 3, 3, 35, 5, 11, 26,VAR, 4, 4, 6, 10, 12, 6,VAR, 4, 4, + 11, 7,VAR, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3, // #0x01C0 - 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 0, 9, 9, 29, 6, 28, - 8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6, - 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1, - -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, + 2, 14, 10,VAR, 22, 22, 4, 2, 13, 97, 0, 9, 9, 29, 6, 28, + 8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2,VAR, 47, 33, 6, + 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2,VAR,VAR, + VAR,VAR, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56,VAR, 4, 5, 10, // #0x0200 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -276,23 +279,24 @@ void Network::skip(int len) bool Network::messageReady() { - int len = -1, msgId; - MutexLocker lock(&mMutex); - if (mInSize >= 2) - { - msgId = readWord(0); - if (msgId == SMSG_SERVER_VERSION_RESPONSE) - len = 10; - else - len = packet_lengths[msgId]; - - if (len == -1 && mInSize > 4) - len = readWord(2); + if (mInSize < 2) + return false; + uint16_t msgId = readWord(0); + uint16_t len = 0; + // TODO don't hard-code this single case + if (msgId == SMSG_SERVER_VERSION_RESPONSE) + len = 10; + else if (msgId < 0x220) + len = packet_lengths[msgId]; + if (len == VAR) + { + if (mInSize < 4) + return false; + len = readWord(2); } - - return mInSize >= static_cast(len); + return mInSize >= len; } MessageIn Network::getNextMessage() @@ -304,14 +308,14 @@ MessageIn Network::getNextMessage() } MutexLocker lock(&mMutex); - int msgId = readWord(0); - int len; + uint16_t msgId = readWord(0); + uint16_t len = 0; if (msgId == SMSG_SERVER_VERSION_RESPONSE) len = 10; - else + else if (msgId < 0x220) len = packet_lengths[msgId]; - if (len == -1) + if (len == VAR) len = readWord(2); #ifdef DEBUG -- cgit v1.2.3-70-g09d2 From d6449162225eeeed3f68fb443dcecfdaa235f3be Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 18 Aug 2011 07:40:43 +0800 Subject: Got rid of the superfluous definition of the slot number for tA. --- src/equipment.h | 2 -- src/net/tmwa/inventoryhandler.h | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/equipment.h b/src/equipment.h index 2ef970ea..67317d39 100644 --- a/src/equipment.h +++ b/src/equipment.h @@ -22,8 +22,6 @@ #ifndef EQUIPMENT_H #define EQUIPMENT_H -#define EQUIPMENT_SIZE 11 - class Item; class Equipment diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 218723e6..bbb734e7 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -34,6 +34,8 @@ #include "net/tmwa/messagehandler.h" +#include "resources/iteminfo.h" + #include namespace TmwAthena { @@ -54,7 +56,7 @@ class EquipBackend : public Equipment::Backend void clear() { - for (int i = 0; i < EQUIPMENT_SIZE; i++) + for (int i = 0; i < EQUIP_VECTOR_END; i++) { if (mEquipment[i] != -1) { @@ -83,7 +85,7 @@ class EquipBackend : public Equipment::Backend } private: - int mEquipment[EQUIPMENT_SIZE]; + int mEquipment[EQUIP_VECTOR_END]; }; /** -- cgit v1.2.3-70-g09d2