From 3c0cb0e058324ee1d3116017f14387e9a6004442 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 3 Jun 2011 11:19:20 -0600 Subject: Replace SDL_types.h with cstdint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This required moving to C++0x, so it does that too, and fixes a few errors with that. Reviewed-by: Thorbjørn Lindeijer --- src/net/download.cpp | 4 ++-- src/net/download.h | 8 +++----- src/net/manaserv/effecthandler.cpp | 6 +++--- src/net/manaserv/itemhandler.cpp | 2 +- src/net/manaserv/messagein.cpp | 9 +++++---- src/net/manaserv/messagein.h | 4 ++-- src/net/manaserv/messageout.cpp | 7 +++---- src/net/manaserv/messageout.h | 6 +++--- src/net/manaserv/network.cpp | 4 ++-- src/net/manaserv/npchandler.cpp | 2 +- src/net/messagehandler.h | 4 +--- src/net/messagein.cpp | 20 +++++++++++--------- src/net/messagein.h | 30 ++++++++++++++++++++---------- src/net/messageout.cpp | 5 ++--- src/net/messageout.h | 24 +++++++++++++++++------- src/net/tmwa/adminhandler.cpp | 2 +- src/net/tmwa/chathandler.cpp | 2 +- src/net/tmwa/inventoryhandler.cpp | 2 -- src/net/tmwa/itemhandler.cpp | 2 +- src/net/tmwa/messagehandler.h | 2 -- src/net/tmwa/messagein.cpp | 11 ++++------- src/net/tmwa/messagein.h | 5 ++--- src/net/tmwa/messageout.cpp | 10 +++++----- src/net/tmwa/messageout.h | 13 +++++-------- src/net/tmwa/npchandler.cpp | 4 +--- 25 files changed, 96 insertions(+), 92 deletions(-) (limited to 'src/net') diff --git a/src/net/download.cpp b/src/net/download.cpp index 83ab180f..10ee2b0c 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -100,7 +100,7 @@ void Download::noCache() addHeader("Cache-Control: no-cache"); } -void Download::setFile(const std::string &filename, Sint64 adler32) +void Download::setFile(const std::string &filename, int64_t adler32) { mOptions.memoryWrite = false; mFileName = filename; @@ -276,7 +276,7 @@ int Download::downloadThread(void *ptr) // Remove the corrupted file ::remove(d->mFileName.c_str()); - logger->log("Checksum for file %s failed: (%lx/%lx)", + logger->log("Checksum for file %s failed: (%lx/%llx)", d->mFileName.c_str(), adler, d->mAdler); attempts++; diff --git a/src/net/download.h b/src/net/download.h index 216f6ff2..cf7335d4 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -18,9 +18,7 @@ * along with this program. If not, see . */ -#include - -#include +#include #include #ifndef NET_DOWNLOAD_H @@ -62,7 +60,7 @@ class Download */ void noCache(); - void setFile(const std::string &filename, Sint64 adler32 = -1); + void setFile(const std::string &filename, int64_t adler32 = -1); void setWriteFunction(WriteFunction write); @@ -95,7 +93,7 @@ class Download } mOptions; std::string mFileName; WriteFunction mWriteFunction; - unsigned long mAdler; + int64_t mAdler; DownloadUpdate mUpdateFunction; SDL_Thread *mThread; CURL *mCurl; diff --git a/src/net/manaserv/effecthandler.cpp b/src/net/manaserv/effecthandler.cpp index 7051bedd..cc732794 100644 --- a/src/net/manaserv/effecthandler.cpp +++ b/src/net/manaserv/effecthandler.cpp @@ -35,7 +35,7 @@ namespace ManaServ { EffectHandler::EffectHandler() { - static const Uint16 _messages[] = { + static const uint16_t _messages[] = { GPMSG_CREATE_EFFECT_POS, GPMSG_CREATE_EFFECT_BEING, GPMSG_SHAKE, @@ -65,8 +65,8 @@ void EffectHandler::handleMessage(Net::MessageIn &msg) void EffectHandler::handleCreateEffectPos(Net::MessageIn &msg) { int id = msg.readInt16(); - Uint16 x = msg.readInt16(); - Uint16 y = msg.readInt16(); + uint16_t x = msg.readInt16(); + uint16_t y = msg.readInt16(); effectManager->trigger(id, x, y); } diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp index d8365d79..2b8f631f 100644 --- a/src/net/manaserv/itemhandler.cpp +++ b/src/net/manaserv/itemhandler.cpp @@ -32,7 +32,7 @@ namespace ManaServ { ItemHandler::ItemHandler() { - static const Uint16 _messages[] = { + static const uint16_t _messages[] = { GPMSG_ITEMS, GPMSG_ITEM_APPEAR, 0 diff --git a/src/net/manaserv/messagein.cpp b/src/net/manaserv/messagein.cpp index 128dd14f..58e6e59a 100644 --- a/src/net/manaserv/messagein.cpp +++ b/src/net/manaserv/messagein.cpp @@ -21,6 +21,7 @@ #include "net/manaserv/messagein.h" +#include #include namespace ManaServ { @@ -32,9 +33,9 @@ MessageIn::MessageIn(const char *data, unsigned int length): mId = readInt16(); } -Uint16 MessageIn::readInt16() +uint16_t MessageIn::readInt16() { - Uint16 value = 0; + uint16_t value = 0; if (mPos + 2 <= mLength) { uint16_t t; @@ -45,9 +46,9 @@ Uint16 MessageIn::readInt16() return value; } -Uint32 MessageIn::readInt32() +uint32_t MessageIn::readInt32() { - Uint32 value = 0; + uint32_t value = 0; if (mPos + 4 <= mLength) { uint32_t t; diff --git a/src/net/manaserv/messagein.h b/src/net/manaserv/messagein.h index ed6510eb..d165ac4d 100644 --- a/src/net/manaserv/messagein.h +++ b/src/net/manaserv/messagein.h @@ -36,8 +36,8 @@ class MessageIn : public Net::MessageIn public: MessageIn(const char *data, unsigned int length); - Uint16 readInt16(); /**< Reads a short. */ - Uint32 readInt32(); /**< Reads a "long". */ + uint16_t readInt16(); + uint32_t readInt32(); }; } diff --git a/src/net/manaserv/messageout.cpp b/src/net/manaserv/messageout.cpp index 695b1b39..d332a507 100644 --- a/src/net/manaserv/messageout.cpp +++ b/src/net/manaserv/messageout.cpp @@ -24,11 +24,10 @@ #include #include -#include namespace ManaServ { -MessageOut::MessageOut(Uint16 id): +MessageOut::MessageOut(uint16_t id): Net::MessageOut(id) { writeInt16(id); @@ -45,7 +44,7 @@ void MessageOut::expand(size_t bytes) mDataSize = mPos + bytes; } -void MessageOut::writeInt16(Uint16 value) +void MessageOut::writeInt16(uint16_t value) { expand(2); uint16_t t = ENET_HOST_TO_NET_16(value); @@ -53,7 +52,7 @@ void MessageOut::writeInt16(Uint16 value) mPos += 2; } -void MessageOut::writeInt32(Uint32 value) +void MessageOut::writeInt32(uint32_t value) { expand(4); uint32_t t = ENET_HOST_TO_NET_32(value); diff --git a/src/net/manaserv/messageout.h b/src/net/manaserv/messageout.h index a22ea824..db7c4780 100644 --- a/src/net/manaserv/messageout.h +++ b/src/net/manaserv/messageout.h @@ -29,12 +29,12 @@ namespace ManaServ { class MessageOut : public Net::MessageOut { public: - MessageOut(Uint16 id); + MessageOut(uint16_t id); ~MessageOut(); - void writeInt16(Uint16 value); /**< Writes a short. */ - void writeInt32(Uint32 value); /**< Writes a "long". */ + void writeInt16(uint16_t value); + void writeInt32(uint32_t value); protected: /** diff --git a/src/net/manaserv/network.cpp b/src/net/manaserv/network.cpp index 03bd7b28..543aaa00 100644 --- a/src/net/manaserv/network.cpp +++ b/src/net/manaserv/network.cpp @@ -89,7 +89,7 @@ Connection *getConnection() void registerHandler(MessageHandler *handler) { - for (const Uint16 *i = handler->handledMessages; *i; i++) + for (const uint16_t *i = handler->handledMessages; *i; i++) { mMessageHandlers[*i] = handler; } @@ -97,7 +97,7 @@ void registerHandler(MessageHandler *handler) void unregisterHandler(MessageHandler *handler) { - for (const Uint16 *i = handler->handledMessages; *i; i++) + for (const uint16_t *i = handler->handledMessages; *i; i++) { mMessageHandlers.erase(*i); } diff --git a/src/net/manaserv/npchandler.cpp b/src/net/manaserv/npchandler.cpp index 1c89f39f..2cec8ce8 100644 --- a/src/net/manaserv/npchandler.cpp +++ b/src/net/manaserv/npchandler.cpp @@ -39,7 +39,7 @@ extern Connection *gameServerConnection; NpcHandler::NpcHandler() { - static const Uint16 _messages[] = { + static const uint16_t _messages[] = { GPMSG_NPC_CHOICE, GPMSG_NPC_POST, GPMSG_NPC_MESSAGE, diff --git a/src/net/messagehandler.h b/src/net/messagehandler.h index a74dab61..f9f1fd89 100644 --- a/src/net/messagehandler.h +++ b/src/net/messagehandler.h @@ -24,8 +24,6 @@ #include "net/messagein.h" -#include - #include namespace Net { @@ -36,7 +34,7 @@ namespace Net { class MessageHandler { public: - const Uint16 *handledMessages; + const uint16_t *handledMessages; virtual void handleMessage(MessageIn &msg) = 0; diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index d9392379..ef9a36f3 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -25,6 +25,8 @@ ((unsigned short)(((unsigned char)(low)) | \ ((unsigned short)((unsigned char)(high))) << 8)) +#include + namespace Net { MessageIn::MessageIn(const char *data, unsigned int length): @@ -34,9 +36,9 @@ MessageIn::MessageIn(const char *data, unsigned int length): { } -Uint8 MessageIn::readInt8() +uint8_t MessageIn::readInt8() { - Uint8 value = 0; + uint8_t value = 0; if (mPos < mLength) { value = mData[mPos]; @@ -45,7 +47,7 @@ Uint8 MessageIn::readInt8() return value; } -void MessageIn::readCoordinates(Uint16 &x, Uint16 &y) +void MessageIn::readCoordinates(uint16_t &x, uint16_t &y) { if (mPos + 3 <= mLength) { @@ -56,12 +58,12 @@ void MessageIn::readCoordinates(Uint16 &x, Uint16 &y) mPos += 3; } -void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) +void MessageIn::readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction) { if (mPos + 3 <= mLength) { const char *data = mData + mPos; - Sint16 temp; + uint16_t temp; temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff); x = temp >> 6; @@ -70,7 +72,7 @@ void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) direction = data[2] & 0x000f; - // Translate from eAthena format + // Translate from tmwAthena format switch (direction) { case 0: @@ -108,13 +110,13 @@ void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) mPos += 3; } -void MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY, - Uint16 &dstX, Uint16 &dstY) +void MessageIn::readCoordinatePair(uint16_t &srcX, uint16_t &srcY, + uint16_t &dstX, uint16_t &dstY) { if (mPos + 5 <= mLength) { const char *data = mData + mPos; - Sint16 temp; + uint16_t temp; temp = MAKEWORD(data[3], data[2] & 0x000f); dstX = temp >> 2; diff --git a/src/net/messagein.h b/src/net/messagein.h index 1313b8f7..31b4dbfc 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -22,8 +22,7 @@ #ifndef NET_MESSAGEIN_H #define NET_MESSAGEIN_H -#include - +#include #include namespace Net { @@ -39,7 +38,7 @@ class MessageIn /** * Returns the message ID. */ - Uint16 getId() const { return mId; } + uint16_t getId() const { return mId; } /** * Returns the message length. @@ -51,28 +50,39 @@ class MessageIn */ unsigned int getUnreadLength() const { return mLength - mPos; } - virtual Uint8 readInt8(); /**< Reads a byte. */ - virtual Uint16 readInt16() = 0; /**< Reads a short. */ - virtual Uint32 readInt32() = 0; /**< Reads a "long". */ + /** + * Reads an unsigned 8-bit integer from the message. + */ + virtual uint8_t readInt8(); + + /** + * Reads an unsigned 16-bit integer from the message. + */ + virtual uint16_t readInt16() = 0; + + /** + * Reads an unsigned 32-bit integer from the message. + */ + virtual uint32_t readInt32() = 0; /** * Reads a 3-byte block containing tile-based coordinates. Used by * manaserv. */ - virtual void readCoordinates(Uint16 &x, Uint16 &y); + virtual void readCoordinates(uint16_t &x, uint16_t &y); /** * Reads a special 3 byte block used by eAthena, containing x and y * coordinates and direction. */ - virtual void readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction); + virtual void readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction); /** * Reads a special 5 byte block used by eAthena, containing a source * and destination coordinate pair. */ - virtual void readCoordinatePair(Uint16 &srcX, Uint16 &srcY, - Uint16 &dstX, Uint16 &dstY); + virtual void readCoordinatePair(uint16_t &srcX, uint16_t &srcY, + uint16_t &dstX, uint16_t &dstY); /** * Skips a given number of bytes. diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 5663e1df..814d7094 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -22,18 +22,17 @@ #include "net/messageout.h" #include -#include namespace Net { -MessageOut::MessageOut(short id): +MessageOut::MessageOut(uint16_t id): mData(0), mDataSize(0), mPos(0) { } -void MessageOut::writeInt8(Uint8 value) +void MessageOut::writeInt8(uint8_t value) { expand(1); mData[mPos] = value; diff --git a/src/net/messageout.h b/src/net/messageout.h index e05d3bd7..cecdea9d 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -22,9 +22,8 @@ #ifndef NET_MESSAGEOUT_H #define NET_MESSAGEOUT_H -#include - -#include +#include +#include namespace Net { @@ -36,9 +35,20 @@ namespace Net { class MessageOut { public: - virtual void writeInt8(Uint8 value); /**< Writes a byte. */ - virtual void writeInt16(Uint16 value) = 0; /**< Writes a short. */ - virtual void writeInt32(Uint32 value) = 0; /**< Writes a "long". */ + /** + * Writes an unsigned 8-bit integer to the message. + */ + virtual void writeInt8(uint8_t value); + + /** + * Writes an unsigned 16-bit integer to the message. + */ + virtual void writeInt16(uint16_t value) = 0; + + /** + * Writes an unsigned 32-bit integer to the message. + */ + virtual void writeInt32(uint32_t value) = 0; /** * Writes a string. If a fixed length is not given (-1), it is stored @@ -59,7 +69,7 @@ class MessageOut virtual ~MessageOut() {} protected: - MessageOut(short id); + MessageOut(uint16_t id); /** * Expand the packet data to be able to hold more data. diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index 53e4bfd8..d18b6fc9 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -43,7 +43,7 @@ namespace TmwAthena { AdminHandler::AdminHandler() { - static const Uint16 _messages[] = + static const uint16_t _messages[] = { SMSG_ADMIN_KICK_ACK, SMSG_ADMIN_IP, diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 51974eb2..97304c28 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -44,7 +44,7 @@ namespace TmwAthena { ChatHandler::ChatHandler() { - static const Uint16 _messages[] = { + static const uint16_t _messages[] = { SMSG_BEING_CHAT, SMSG_PLAYER_CHAT, SMSG_WHISPER, diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 48f40e11..ff875e69 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -43,8 +43,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include - extern Net::InventoryHandler *inventoryHandler; namespace TmwAthena { diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp index e452ccf2..9f303617 100644 --- a/src/net/tmwa/itemhandler.cpp +++ b/src/net/tmwa/itemhandler.cpp @@ -33,7 +33,7 @@ namespace TmwAthena { ItemHandler::ItemHandler() { - static const Uint16 _messages[] = { + static const uint16_t _messages[] = { SMSG_ITEM_VISIBLE, SMSG_ITEM_DROPPED, SMSG_ITEM_REMOVE, diff --git a/src/net/tmwa/messagehandler.h b/src/net/tmwa/messagehandler.h index 0fa2e80c..e7810591 100644 --- a/src/net/tmwa/messagehandler.h +++ b/src/net/tmwa/messagehandler.h @@ -27,8 +27,6 @@ #include "net/tmwa/messageout.h" -#include - #include namespace TmwAthena { diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 1a860a25..ca2d52ab 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -21,9 +21,6 @@ #include "net/tmwa/messagein.h" -#include -#include - namespace TmwAthena { MessageIn::MessageIn(const char *data, unsigned int length): @@ -33,9 +30,9 @@ MessageIn::MessageIn(const char *data, unsigned int length): mId = readInt16(); } -Uint16 MessageIn::readInt16() +uint16_t MessageIn::readInt16() { - Uint16 value = 0; + uint16_t value = 0; if (mPos + 2 <= mLength) { value = (mData[mPos + 1] << 8) | mData[mPos]; @@ -44,9 +41,9 @@ Uint16 MessageIn::readInt16() return value; } -Uint32 MessageIn::readInt32() +uint32_t MessageIn::readInt32() { - Uint32 value = 0; + uint32_t value = 0; if (mPos + 4 <= mLength) { value = (mData[mPos + 3] << 24) | (mData[mPos + 2] << 16) | (mData[mPos + 1] << 8) | mData[mPos]; diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h index 21375257..38fbb139 100644 --- a/src/net/tmwa/messagein.h +++ b/src/net/tmwa/messagein.h @@ -24,7 +24,6 @@ #include "net/messagein.h" -#include #include namespace TmwAthena { @@ -39,8 +38,8 @@ namespace TmwAthena { public: MessageIn(const char *data, unsigned int length); - Uint16 readInt16(); /**< Reads a short. */ - Uint32 readInt32(); /**< Reads a "long". */ + uint16_t readInt16(); + uint32_t readInt32(); }; } diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 71b8f756..7c3a3c61 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -31,7 +31,7 @@ namespace TmwAthena { -MessageOut::MessageOut(Uint16 id): +MessageOut::MessageOut(uint16_t id): Net::MessageOut(id) { mNetwork = TmwAthena::Network::instance(); @@ -44,7 +44,7 @@ void MessageOut::expand(size_t bytes) mNetwork->mOutSize += bytes; } -void MessageOut::writeInt16(Uint16 value) +void MessageOut::writeInt16(uint16_t value) { expand(2); mData[mPos] = value; @@ -52,7 +52,7 @@ void MessageOut::writeInt16(Uint16 value) mPos += 2; } -void MessageOut::writeInt32(Uint32 value) +void MessageOut::writeInt32(uint32_t value) { expand(4); mData[mPos] = value; @@ -62,13 +62,13 @@ void MessageOut::writeInt32(Uint32 value) mPos += 4; } -void MessageOut::writeCoordinates(Uint16 x, Uint16 y, Uint8 direction) +void MessageOut::writeCoordinates(uint16_t x, uint16_t y, uint8_t direction) { char *data = mData + mPos; mNetwork->mOutSize += 3; mPos += 3; - Uint16 temp = x; + int16_t temp = x; temp <<= 6; data[0] = temp >> 8; data[1] = temp; diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h index 3a6f34a9..24a0a37c 100644 --- a/src/net/tmwa/messageout.h +++ b/src/net/tmwa/messageout.h @@ -24,9 +24,6 @@ #include "net/messageout.h" -#include -#include - namespace TmwAthena { class Network; @@ -39,16 +36,16 @@ class Network; class MessageOut : public Net::MessageOut { public: - MessageOut(Uint16 id); + MessageOut(uint16_t id); - void writeInt16(Uint16 value); /**< Writes a short. */ - void writeInt32(Uint32 value); /**< Writes a "long". */ + void writeInt16(uint16_t value); + void writeInt32(uint32_t value); /** * Encodes coordinates and direction in 3 bytes. */ - void writeCoordinates(Uint16 x, Uint16 y, - Uint8 direction); + void writeCoordinates(uint16_t x, uint16_t y, + uint8_t direction); private: void expand(size_t size); diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 092e3046..904fe388 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -34,8 +34,6 @@ #include "utils/stringutils.h" -#include - extern Net::NpcHandler *npcHandler; static void parseMenu(Event *event, const std::string &options) @@ -57,7 +55,7 @@ namespace TmwAthena { NpcHandler::NpcHandler() { - static const Uint16 _messages[] = { + static const uint16_t _messages[] = { SMSG_NPC_CHOICE, SMSG_NPC_MESSAGE, SMSG_NPC_NEXT, -- cgit v1.2.3-60-g2f50