summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-02-07 16:18:13 +0300
committerAndrei Karas <akaras@inbox.ru>2016-02-07 16:18:13 +0300
commit9fe21fcd8883b37bdc30224822e6e42afb35b8f0 (patch)
tree798117abd4dc7e610997d59d530a96ddc1509f53 /src/net
parent4429cb14e9e187edef27aba692a4266733f79c17 (diff)
downloadplus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.gz
plus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.bz2
plus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.tar.xz
plus-9fe21fcd8883b37bdc30224822e6e42afb35b8f0.zip
Replace most static_cast<Type> to shorter versions from defines.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/download.cpp10
-rw-r--r--src/net/ea/guildrecv.cpp4
-rw-r--r--src/net/ea/inventoryrecv.cpp2
-rw-r--r--src/net/ea/loginhandler.cpp2
-rw-r--r--src/net/ea/loginrecv.cpp4
-rw-r--r--src/net/ea/network.cpp14
-rw-r--r--src/net/ea/npcrecv.cpp2
-rw-r--r--src/net/eathena/adminhandler.cpp22
-rw-r--r--src/net/eathena/auctionhandler.cpp6
-rw-r--r--src/net/eathena/bankrecv.cpp6
-rw-r--r--src/net/eathena/battlegroundhandler.cpp4
-rw-r--r--src/net/eathena/beinghandler.cpp2
-rw-r--r--src/net/eathena/beingrecv.cpp62
-rw-r--r--src/net/eathena/buyingstorehandler.cpp12
-rw-r--r--src/net/eathena/cashshophandler.cpp6
-rw-r--r--src/net/eathena/charserverhandler.cpp16
-rw-r--r--src/net/eathena/charserverrecv.cpp6
-rw-r--r--src/net/eathena/chathandler.cpp44
-rw-r--r--src/net/eathena/generalrecv.cpp2
-rw-r--r--src/net/eathena/guildhandler.cpp8
-rw-r--r--src/net/eathena/guildrecv.cpp4
-rw-r--r--src/net/eathena/homunculushandler.cpp10
-rw-r--r--src/net/eathena/inventoryhandler.cpp26
-rw-r--r--src/net/eathena/inventoryrecv.cpp2
-rw-r--r--src/net/eathena/itemrecv.cpp16
-rw-r--r--src/net/eathena/mailhandler.cpp12
-rw-r--r--src/net/eathena/markethandler.cpp16
-rw-r--r--src/net/eathena/mercenaryhandler.cpp10
-rw-r--r--src/net/eathena/messagein.cpp24
-rw-r--r--src/net/eathena/messageout.cpp36
-rw-r--r--src/net/eathena/network.cpp4
-rw-r--r--src/net/eathena/npchandler.cpp48
-rw-r--r--src/net/eathena/partyhandler.cpp16
-rw-r--r--src/net/eathena/pethandler.cpp4
-rw-r--r--src/net/eathena/playerhandler.cpp18
-rw-r--r--src/net/eathena/playerrecv.cpp2
-rw-r--r--src/net/eathena/questhandler.cpp2
-rw-r--r--src/net/eathena/searchstorehandler.cpp6
-rw-r--r--src/net/eathena/skillhandler.cpp22
-rw-r--r--src/net/eathena/skillrecv.cpp10
-rw-r--r--src/net/eathena/tradehandler.cpp4
-rw-r--r--src/net/eathena/vendinghandler.cpp16
-rw-r--r--src/net/ipc.cpp2
-rw-r--r--src/net/messagein.cpp76
-rw-r--r--src/net/messageout.cpp22
-rw-r--r--src/net/messageout.h2
-rw-r--r--src/net/packetlimiter.cpp116
-rw-r--r--src/net/tmwa/adminhandler.cpp8
-rw-r--r--src/net/tmwa/beingrecv.cpp70
-rw-r--r--src/net/tmwa/charserverhandler.cpp10
-rw-r--r--src/net/tmwa/charserverrecv.cpp4
-rw-r--r--src/net/tmwa/chathandler.cpp22
-rw-r--r--src/net/tmwa/chatrecv.cpp2
-rw-r--r--src/net/tmwa/generalrecv.cpp2
-rw-r--r--src/net/tmwa/guildhandler.cpp4
-rw-r--r--src/net/tmwa/guildrecv.cpp2
-rw-r--r--src/net/tmwa/inventoryhandler.cpp16
-rw-r--r--src/net/tmwa/inventoryrecv.cpp4
-rw-r--r--src/net/tmwa/itemrecv.cpp8
-rw-r--r--src/net/tmwa/messagein.cpp24
-rw-r--r--src/net/tmwa/messageout.cpp34
-rw-r--r--src/net/tmwa/network.cpp4
-rw-r--r--src/net/tmwa/npchandler.cpp12
-rw-r--r--src/net/tmwa/partyhandler.cpp12
-rw-r--r--src/net/tmwa/pethandler.cpp4
-rw-r--r--src/net/tmwa/playerhandler.cpp8
-rw-r--r--src/net/tmwa/skillhandler.cpp22
-rw-r--r--src/net/tmwa/skillrecv.cpp12
-rw-r--r--src/net/tmwa/tradehandler.cpp4
-rw-r--r--src/net/updatetypeoperators.cpp6
70 files changed, 527 insertions, 527 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp
index dd3b9eaeb..209b6085e 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -144,7 +144,7 @@ unsigned long Download::fadler32(FILE *const file)
rewind(file);
// Calculate Adler-32 checksum
- char *const buffer = new char[static_cast<size_t>(fileSize)];
+ char *const buffer = new char[CAST_SIZE(fileSize)];
const uInt read = static_cast<uInt>(fread(buffer, 1, fileSize, file));
unsigned long adler = adler32(0L, Z_NULL, 0);
adler = adler32(static_cast<uInt>(adler),
@@ -242,13 +242,13 @@ int Download::downloadProgress(void *clientp, double dltotal, double dlnow,
if (d->mOptions.cancel)
{
return d->mUpdateFunction(d->mPtr, DownloadStatus::Cancelled,
- static_cast<size_t>(dltotal),
- static_cast<size_t>(dlnow));
+ CAST_SIZE(dltotal),
+ CAST_SIZE(dlnow));
}
return d->mUpdateFunction(d->mPtr, DownloadStatus::Idle,
- static_cast<size_t>(dltotal),
- static_cast<size_t>(dlnow));
+ CAST_SIZE(dltotal),
+ CAST_SIZE(dlnow));
}
int Download::downloadThread(void *ptr)
diff --git a/src/net/ea/guildrecv.cpp b/src/net/ea/guildrecv.cpp
index af215876c..f952ae2d2 100644
--- a/src/net/ea/guildrecv.cpp
+++ b/src/net/ea/guildrecv.cpp
@@ -141,7 +141,7 @@ void GuildRecv::processGuildBasicInfo(Net::MessageIn &msg)
castle.c_str()), ChatMsgType::BY_SERVER);
}
- Guild *const g = Guild::getGuild(static_cast<int16_t>(guildId));
+ Guild *const g = Guild::getGuild(CAST_S16(guildId));
if (!g)
return;
g->setName(name);
@@ -200,7 +200,7 @@ void GuildRecv::processGuildMemberList(Net::MessageIn &msg)
m->setOnline(online);
m->setID(id);
m->setCharId(charId);
- m->setGender(Being::intToGender(static_cast<uint8_t>(gender)));
+ m->setGender(Being::intToGender(CAST_U8(gender)));
m->setLevel(level);
m->setExp(exp);
m->setPos(pos);
diff --git a/src/net/ea/inventoryrecv.cpp b/src/net/ea/inventoryrecv.cpp
index d1f43d0bb..f1593bf51 100644
--- a/src/net/ea/inventoryrecv.cpp
+++ b/src/net/ea/inventoryrecv.cpp
@@ -232,7 +232,7 @@ int InventoryRecv::getSlot(const int eAthenaSlot)
mask <<= 1;
position++;
}
- return static_cast<int>(EQUIP_POINTS[position]);
+ return CAST_S32(EQUIP_POINTS[position]);
}
} // namespace Ea
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index 3119b0ab6..20034f9f8 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -76,7 +76,7 @@ void LoginHandler::loginAccount(LoginData *const loginData1) const
void LoginHandler::chooseServer(const unsigned int server,
const bool persistentIp) const
{
- if (static_cast<size_t>(server) >= LoginRecv::mWorlds.size() ||
+ if (CAST_SIZE(server) >= LoginRecv::mWorlds.size() ||
!LoginRecv::mWorlds[server])
{
return;
diff --git a/src/net/ea/loginrecv.cpp b/src/net/ea/loginrecv.cpp
index 4b25c80d6..84899476b 100644
--- a/src/net/ea/loginrecv.cpp
+++ b/src/net/ea/loginrecv.cpp
@@ -82,7 +82,7 @@ void LoginRecv::processLoginData(Net::MessageIn &msg)
msg.readInt16("unused");
// reserve bits for future usage
- mToken.sex = Being::intToGender(static_cast<uint8_t>(
+ mToken.sex = Being::intToGender(CAST_U8(
msg.readUInt8("gender") & 3U));
for (int i = 0; i < worldCount; i++)
@@ -109,7 +109,7 @@ void LoginRecv::processLoginData(Net::MessageIn &msg)
void LoginRecv::processLoginError(Net::MessageIn &msg)
{
const uint8_t code = msg.readUInt8("error");
- logger->log("Login::error code: %u", static_cast<unsigned int>(code));
+ logger->log("Login::error code: %u", CAST_U32(code));
std::string date = msg.readString(20, "date");
switch (code)
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index 66115b789..9efc807c7 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -165,7 +165,7 @@ void Network::flush()
toString(mOutSize)).append(" bytes"));
}
*/
- if (ret < static_cast<int>(mOutSize))
+ if (ret < CAST_S32(mOutSize))
{
SDL_mutexV(mMutexOut);
setError("Error in TcpNet::send(): " +
@@ -188,7 +188,7 @@ void Network::skip(const int len)
if (mInSize >= mToSkip)
{
mInSize -= mToSkip;
- memmove(mInBuffer, mInBuffer + static_cast<size_t>(mToSkip), mInSize);
+ memmove(mInBuffer, mInBuffer + CAST_SIZE(mToSkip), mInSize);
mToSkip = 0;
}
else
@@ -258,7 +258,7 @@ void Network::receive()
while (mState == CONNECTED)
{
const int numReady = TcpNet::checkSockets(
- set, (static_cast<uint32_t>(500)));
+ set, (CAST_U32(500)));
switch (numReady)
{
case -1:
@@ -280,7 +280,7 @@ void Network::receive()
}
const int ret = TcpNet::recv(mSocket,
- mInBuffer + static_cast<size_t>(mInSize),
+ mInBuffer + CAST_SIZE(mInSize),
BUFFER_SIZE - mInSize);
if (!ret)
@@ -305,7 +305,7 @@ void Network::receive()
{
mInSize -= mToSkip;
memmove(mInBuffer,
- mInBuffer + static_cast<size_t>(mToSkip),
+ mInBuffer + CAST_SIZE(mToSkip),
mInSize);
mToSkip = 0;
}
@@ -348,10 +348,10 @@ uint16_t Network::readWord(const int pos) const
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return SDL_Swap16(*reinterpret_cast<uint16_t*>(
- mInBuffer + static_cast<size_t>(pos)));
+ mInBuffer + CAST_SIZE(pos)));
#else
return (*reinterpret_cast<uint16_t*>(
- mInBuffer + static_cast<size_t>(pos)));
+ mInBuffer + CAST_SIZE(pos)));
#endif
}
diff --git a/src/net/ea/npcrecv.cpp b/src/net/ea/npcrecv.cpp
index c447fd5c5..89bacfd2d 100644
--- a/src/net/ea/npcrecv.cpp
+++ b/src/net/ea/npcrecv.cpp
@@ -173,7 +173,7 @@ void NpcRecv::processNpcCommand(Net::MessageIn &msg)
{
mDialog->setAvatarDirection(
Net::MessageIn::fromServerDirection(
- static_cast<uint8_t>(id)));
+ CAST_U8(id)));
}
break;
case 8: // set avatar action
diff --git a/src/net/eathena/adminhandler.cpp b/src/net/eathena/adminhandler.cpp
index 14afde54c..6c7914a32 100644
--- a/src/net/eathena/adminhandler.cpp
+++ b/src/net/eathena/adminhandler.cpp
@@ -45,15 +45,15 @@ AdminHandler::AdminHandler() :
void AdminHandler::announce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::localAnnounce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_LOCAL_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::hide(const bool h A_UNUSED) const
@@ -77,8 +77,8 @@ void AdminHandler::warp(const std::string &map, const int x, const int y) const
{
createOutPacket(CMSG_PLAYER_MAPMOVE);
outMsg.writeString(map, 16, "map");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void AdminHandler::resetStats() const
@@ -114,8 +114,8 @@ void AdminHandler::mute(const Being *const being,
createOutPacket(CMSG_ADMIN_MUTE);
outMsg.writeBeingId(being->getId(), "account id");
- outMsg.writeInt8(static_cast<int8_t>(type), "type");
- outMsg.writeInt16(static_cast<int16_t>(limit), "value");
+ outMsg.writeInt8(CAST_S8(type), "type");
+ outMsg.writeInt16(CAST_S16(limit), "value");
}
void AdminHandler::muteName(const std::string &name) const
@@ -137,9 +137,9 @@ void AdminHandler::setTileType(const int x, const int y,
const int type) const
{
createOutPacket(CMSG_ADMIN_SET_TILE_TYPE);
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
+ outMsg.writeInt16(CAST_S16(type), "type");
}
void AdminHandler::unequipAll(const Being *const being) const
diff --git a/src/net/eathena/auctionhandler.cpp b/src/net/eathena/auctionhandler.cpp
index fdd5e901f..fb9731c95 100644
--- a/src/net/eathena/auctionhandler.cpp
+++ b/src/net/eathena/auctionhandler.cpp
@@ -51,7 +51,7 @@ void AuctionHandler::setItem(const Item *const item,
if (!item)
return;
createOutPacket(CMSG_AUCTION_SET_ITEM);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(amount, "amount"); // always 1
}
@@ -92,10 +92,10 @@ void AuctionHandler::search(const AuctionSearchTypeT type,
const int page) const
{
createOutPacket(CMSG_AUCTION_SEARCH);
- outMsg.writeInt16(static_cast<int16_t>(type), "search type");
+ outMsg.writeInt16(CAST_S16(type), "search type");
outMsg.writeInt32(auctionId, "auction id");
outMsg.writeString(text, 24, "search text");
- outMsg.writeInt16(static_cast<int16_t>(page), "page");
+ outMsg.writeInt16(CAST_S16(page), "page");
}
void AuctionHandler::buy() const
diff --git a/src/net/eathena/bankrecv.cpp b/src/net/eathena/bankrecv.cpp
index 6a0670229..bea7a01df 100644
--- a/src/net/eathena/bankrecv.cpp
+++ b/src/net/eathena/bankrecv.cpp
@@ -35,7 +35,7 @@ namespace EAthena
void BankRecv::processBankStatus(Net::MessageIn &msg)
{
- const int money = static_cast<int>(msg.readInt64("money"));
+ const int money = CAST_S32(msg.readInt64("money"));
msg.readInt16("reason");
BankListener::distributeEvent(money);
}
@@ -43,7 +43,7 @@ void BankRecv::processBankStatus(Net::MessageIn &msg)
void BankRecv::processBankDeposit(Net::MessageIn &msg)
{
const int reason = msg.readInt16("reason");
- const int money = static_cast<int>(msg.readInt64("money"));
+ const int money = CAST_S32(msg.readInt64("money"));
msg.readInt32("balance");
BankListener::distributeEvent(money);
if (reason)
@@ -53,7 +53,7 @@ void BankRecv::processBankDeposit(Net::MessageIn &msg)
void BankRecv::processBankWithdraw(Net::MessageIn &msg)
{
const int reason = msg.readInt16("reason");
- const int money = static_cast<int>(msg.readInt64("money"));
+ const int money = CAST_S32(msg.readInt64("money"));
msg.readInt32("balance");
BankListener::distributeEvent(money);
if (reason)
diff --git a/src/net/eathena/battlegroundhandler.cpp b/src/net/eathena/battlegroundhandler.cpp
index fa3c2d337..723ab3bfe 100644
--- a/src/net/eathena/battlegroundhandler.cpp
+++ b/src/net/eathena/battlegroundhandler.cpp
@@ -39,7 +39,7 @@ void BattleGroundHandler::registerBg(const BattleGroundTypeT &type,
const std::string &name) const
{
createOutPacket(CMSG_BATTLE_REGISTER);
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(type), "type");
outMsg.writeString(name, 24, "bg name");
}
@@ -54,7 +54,7 @@ void BattleGroundHandler::beginAck(const bool result,
const std::string &gameName) const
{
createOutPacket(CMSG_BATTLE_BEGIN_ACK);
- outMsg.writeInt8(static_cast<int8_t>(result ? 1 : 0), "result");
+ outMsg.writeInt8(CAST_S8(result ? 1 : 0), "result");
outMsg.writeString(bgName, 24, "bg name");
outMsg.writeString(gameName, 24, "game name");
}
diff --git a/src/net/eathena/beinghandler.cpp b/src/net/eathena/beinghandler.cpp
index bfb72e911..143d7dc9e 100644
--- a/src/net/eathena/beinghandler.cpp
+++ b/src/net/eathena/beinghandler.cpp
@@ -69,7 +69,7 @@ void BeingHandler::undress(Being *const being) const
void BeingHandler::requestRanks(const RankT rank) const
{
createOutPacket(CMSG_REQUEST_RANKS);
- outMsg.writeInt16(static_cast<int16_t>(rank), "type");
+ outMsg.writeInt16(CAST_S16(rank), "type");
}
void BeingHandler::viewPlayerEquipment(const Being *const being)
diff --git a/src/net/eathena/beingrecv.cpp b/src/net/eathena/beingrecv.cpp
index 816b8913b..88db63c8f 100644
--- a/src/net/eathena/beingrecv.cpp
+++ b/src/net/eathena/beingrecv.cpp
@@ -189,7 +189,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg,
fromInt(id, ItemColor)));
break;
case 7: // Clothes color. Now used as look
- dstBeing->setLook(static_cast<uint8_t>(id));
+ dstBeing->setLook(CAST_U8(id));
break;
case 8: // eAthena LOOK_SHIELD
dstBeing->setSprite(SPRITE_FLOOR, id, color, itemColor);
@@ -271,7 +271,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
const uint16_t stunMode = msg.readInt16("opt1");
// probably wrong effect usage
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
const int16_t job = msg.readInt16("class");
Being *dstBeing = actorManager->findBeing(id);
@@ -324,7 +324,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
localPlayer->checkNewName(dstBeing);
const int hairStyle = msg.readInt16("hair style");
- const uint32_t weapon = static_cast<uint32_t>(msg.readInt32("weapon"));
+ const uint32_t weapon = CAST_U32(msg.readInt32("weapon"));
const uint16_t headBottom = msg.readInt16("head bottom");
const uint16_t headTop = msg.readInt16("head top");
@@ -339,10 +339,10 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
msg.readInt32("guild id");
msg.readInt16("guild emblem");
dstBeing->setManner(msg.readInt16("manner"));
- dstBeing->setStatusEffectBlock(32, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(32, CAST_U16(
msg.readInt32("opt3")));
dstBeing->setKarma(msg.readUInt8("karma"));
- uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender") & 3);
+ uint8_t gender = CAST_U8(msg.readUInt8("gender") & 3);
if (dstBeing->getType() == ActorType::Player)
{
@@ -390,7 +390,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
dstBeing->setDirection(dir);
- const int level = static_cast<int>(msg.readInt16("level"));
+ const int level = CAST_S32(msg.readInt16("level"));
if (level)
dstBeing->setLevel(level);
msg.readInt16("font");
@@ -405,9 +405,9 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
msg.readInt16("body2");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffffU));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffffU));
}
@@ -443,7 +443,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
// msg.readInt16("body state");
// msg.readInt16("health state");
// }
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
const int16_t job = msg.readInt16("class");
Being *dstBeing = actorManager->findBeing(id);
@@ -488,7 +488,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
localPlayer->checkNewName(dstBeing);
const int hairStyle = msg.readInt16("hair style");
- const uint32_t weapon = static_cast<uint32_t>(msg.readInt32("weapon"));
+ const uint32_t weapon = CAST_U32(msg.readInt32("weapon"));
const uint16_t headBottom = msg.readInt16("head bottom");
msg.readInt32("tick");
@@ -505,10 +505,10 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
msg.readInt32("guild id");
msg.readInt16("guild emblem");
dstBeing->setManner(msg.readInt16("manner"));
- dstBeing->setStatusEffectBlock(32, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(32, CAST_U16(
msg.readInt32("opt3")));
dstBeing->setKarma(msg.readUInt8("karma"));
- uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender") & 3);
+ uint8_t gender = CAST_U8(msg.readUInt8("gender") & 3);
if (dstBeing->getType() == ActorType::Player)
{
@@ -568,7 +568,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
if (d && dstBeing->getDirection() != d)
dstBeing->setDirection(d);
- const int level = static_cast<int>(msg.readInt16("level"));
+ const int level = CAST_S32(msg.readInt16("level"));
if (level)
dstBeing->setLevel(level);
msg.readInt16("font");
@@ -583,9 +583,9 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
msg.readInt16("body2");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffffU));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffffU));
}
@@ -617,7 +617,7 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
// msg.readInt16("body state");
// msg.readInt16("health state");
// }
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
const int16_t job = msg.readInt16("class");
Being *dstBeing = actorManager->findBeing(id);
@@ -662,7 +662,7 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
localPlayer->checkNewName(dstBeing);
const int hairStyle = msg.readInt16("hair style");
- const uint32_t weapon = static_cast<uint32_t>(msg.readInt32("weapon"));
+ const uint32_t weapon = CAST_U32(msg.readInt32("weapon"));
const uint16_t headBottom = msg.readInt16("head bottom");
const uint16_t headTop = msg.readInt16("head top");
@@ -676,10 +676,10 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
msg.readInt32("guild id");
msg.readInt16("guild emblem");
dstBeing->setManner(msg.readInt16("manner"));
- dstBeing->setStatusEffectBlock(32, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(32, CAST_U16(
msg.readInt32("opt3")));
dstBeing->setKarma(msg.readUInt8("karma"));
- uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender") & 3);
+ uint8_t gender = CAST_U8(msg.readUInt8("gender") & 3);
if (dstBeing->getType() == ActorType::Player)
{
@@ -726,7 +726,7 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
dstBeing->setDirection(dir);
- const int level = static_cast<int>(msg.readInt16("level"));
+ const int level = CAST_S32(msg.readInt16("level"));
if (level)
dstBeing->setLevel(level);
msg.readInt16("font");
@@ -741,9 +741,9 @@ void BeingRecv::processBeingSpawn(Net::MessageIn &msg)
msg.readInt16("body2");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffffU));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffffU));
}
@@ -755,7 +755,7 @@ void BeingRecv::processMapTypeProperty(Net::MessageIn &msg)
{
// +++ need get other flags from here
MapTypeProperty2 props;
- props.data = static_cast<uint32_t>(flags);
+ props.data = CAST_U32(flags);
Game *const game = Game::instance();
if (!game)
return;
@@ -1103,7 +1103,7 @@ void BeingRecv::processBeingChangeDirection(Net::MessageIn &msg)
msg.readInt16("head direction");
const uint8_t dir = Net::MessageIn::fromServerDirection(
- static_cast<uint8_t>(msg.readUInt8("player direction") & 0x0FU));
+ CAST_U8(msg.readUInt8("player direction") & 0x0FU));
if (!dstBeing)
{
@@ -1207,13 +1207,13 @@ void BeingRecv::processPlaterStatusChange(Net::MessageIn &msg)
const uint16_t stunMode = msg.readInt16("stun mode");
uint32_t statusEffects = msg.readInt16("status effect");
- statusEffects |= (static_cast<uint32_t>(msg.readInt32("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt32("option"))) << 16;
dstBeing->setKarma(msg.readUInt8("karma"));
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerStop")
}
@@ -1234,9 +1234,9 @@ void BeingRecv::processPlaterStatusChange2(Net::MessageIn &msg)
dstBeing->setLevel(msg.readInt32("level"));
msg.readInt32("showEFST");
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
}
@@ -1698,14 +1698,14 @@ Being *BeingRecv::createBeing2(Net::MessageIn &msg,
case BeingType::ITEM:
case BeingType::ELEMENTAL:
logger->log("not supported object type: %d, job: %d",
- static_cast<int>(beingType), static_cast<int>(job));
+ CAST_S32(beingType), CAST_S32(job));
break;
case BeingType::CHAT:
default:
UNIMPLIMENTEDPACKET;
type = ActorType::Monster;
logger->log("not supported object type: %d, job: %d",
- static_cast<int>(beingType), static_cast<int>(job));
+ CAST_S32(beingType), CAST_S32(job));
break;
}
if (job == 45 && beingType == BeingType::NPC_EVENT)
diff --git a/src/net/eathena/buyingstorehandler.cpp b/src/net/eathena/buyingstorehandler.cpp
index a850a8785..5fcc9c4aa 100644
--- a/src/net/eathena/buyingstorehandler.cpp
+++ b/src/net/eathena/buyingstorehandler.cpp
@@ -48,15 +48,15 @@ void BuyingStoreHandler::create(const std::string &name,
std::vector<ShopItem*> &items) const
{
createOutPacket(CMSG_BUYINGSTORE_CREATE);
- outMsg.writeInt16(static_cast<int16_t>(89 + items.size() * 8), "len");
+ outMsg.writeInt16(CAST_S16(89 + items.size() * 8), "len");
outMsg.writeInt32(maxMoney, "limit money");
outMsg.writeInt8(flag, "flag");
outMsg.writeString(name, 80, "store name");
FOR_EACH (std::vector<ShopItem*>::const_iterator, it, items)
{
const ShopItem *const item = *it;
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
- outMsg.writeInt16(static_cast<int16_t>(item->getQuantity()), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
+ outMsg.writeInt16(CAST_S16(item->getQuantity()), "amount");
outMsg.writeInt32(item->getPrice(), "price");
}
}
@@ -87,11 +87,11 @@ void BuyingStoreHandler::sell(const Being *const being,
outMsg.writeInt16(18, "len");
outMsg.writeBeingId(being->getId(), "account id");
outMsg.writeInt32(storeId, "store id");
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET),
"index");
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
} // namespace EAthena
diff --git a/src/net/eathena/cashshophandler.cpp b/src/net/eathena/cashshophandler.cpp
index 53b9d90e2..026297673 100644
--- a/src/net/eathena/cashshophandler.cpp
+++ b/src/net/eathena/cashshophandler.cpp
@@ -46,8 +46,8 @@ void CashShopHandler::buyItem(const int points,
outMsg.writeInt16(10 + 4, "len");
outMsg.writeInt32(points, "points");
outMsg.writeInt16(1, "count");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void CashShopHandler::buyItems(std::vector<ShopItem*> &items A_UNUSED) const
@@ -68,7 +68,7 @@ void CashShopHandler::requestPoints() const
void CashShopHandler::requestTab(const int tab) const
{
createOutPacket(CMSG_NPC_CASH_SHOP_REQUEST_TAB);
- outMsg.writeInt16(static_cast<int16_t>(tab), "tab");
+ outMsg.writeInt16(CAST_S16(tab), "tab");
}
void CashShopHandler::schedule() const
diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp
index 37e2e72ea..ce84840ca 100644
--- a/src/net/eathena/charserverhandler.cpp
+++ b/src/net/eathena/charserverhandler.cpp
@@ -66,7 +66,7 @@ void CharServerHandler::chooseCharacter(Net::Character *const character)
mCharSelectDialog = nullptr;
createOutPacket(CMSG_CHAR_SELECT);
- outMsg.writeInt8(static_cast<unsigned char>(
+ outMsg.writeInt8(CAST_U8(
mSelectedCharacter->slot), "slot");
}
@@ -81,11 +81,11 @@ void CharServerHandler::newCharacter(const std::string &name, const int slot,
createOutPacket(CMSG_CHAR_CREATE);
outMsg.writeString(name, 24, "login");
- outMsg.writeInt8(static_cast<unsigned char>(slot), "slot");
- outMsg.writeInt16(static_cast<int16_t>(hairColor), "hair color");
- outMsg.writeInt16(static_cast<int16_t>(hairstyle), "hair style");
+ outMsg.writeInt8(CAST_U8(slot), "slot");
+ outMsg.writeInt16(CAST_S16(hairColor), "hair color");
+ outMsg.writeInt16(CAST_S16(hairstyle), "hair style");
if (serverFeatures->haveRaceSelection())
- outMsg.writeInt16(static_cast<int16_t>(race), "race");
+ outMsg.writeInt16(CAST_S16(race), "race");
if (serverFeatures->haveCreateCharGender())
{
uint8_t sex = 0;
@@ -96,7 +96,7 @@ void CharServerHandler::newCharacter(const std::string &name, const int slot,
outMsg.writeInt8(sex, "gender");
}
if (serverFeatures->haveLookSelection())
- outMsg.writeInt16(static_cast<int16_t>(look), "look");
+ outMsg.writeInt16(CAST_S16(look), "look");
}
void CharServerHandler::deleteCharacter(Net::Character *const character,
@@ -180,8 +180,8 @@ void CharServerHandler::renameCharacter(const BeingId id,
void CharServerHandler::changeSlot(const int oldSlot, const int newSlot)
{
createOutPacket(CMSG_CHAR_CHANGE_SLOT);
- outMsg.writeInt16(static_cast<int16_t>(oldSlot), "old slot");
- outMsg.writeInt16(static_cast<int16_t>(newSlot), "new slot");
+ outMsg.writeInt16(CAST_S16(oldSlot), "old slot");
+ outMsg.writeInt16(CAST_S16(newSlot), "new slot");
outMsg.writeInt16(0, "unused");
}
diff --git a/src/net/eathena/charserverrecv.cpp b/src/net/eathena/charserverrecv.cpp
index e2b7567e3..03ca40aaa 100644
--- a/src/net/eathena/charserverrecv.cpp
+++ b/src/net/eathena/charserverrecv.cpp
@@ -166,7 +166,7 @@ void CharServerRecv::readPlayerData(Net::MessageIn &msg,
msg.readInt32("slot change");
tempPlayer->setRename(msg.readInt32("rename (inverse)"));
- const uint8_t gender = static_cast<uint8_t>(msg.readUInt8("gender"));
+ const uint8_t gender = CAST_U8(msg.readUInt8("gender"));
if (gender != 99)
tempPlayer->setGender(Being::intToGender(gender));
}
@@ -177,7 +177,7 @@ void CharServerRecv::processCharLogin(Net::MessageIn &msg)
const int slots = msg.readInt8("MAX_CHARS");
msg.readInt8("sd->char_slots");
msg.readInt8("MAX_CHARS");
- loginData.characterSlots = static_cast<uint16_t>(slots);
+ loginData.characterSlots = CAST_U16(slots);
msg.skip(20, "unused 0");
@@ -290,7 +290,7 @@ void CharServerRecv::processPincodeStatus(Net::MessageIn &msg)
{
mPinSeed = msg.readInt32("pincode seed");
mPinAccountId = msg.readBeingId("account id");
- const uint16_t state = static_cast<uint16_t>(msg.readInt16("state"));
+ const uint16_t state = CAST_U16(msg.readInt16("state"));
switch (state)
{
case 0: // pin ok
diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp
index 236fd5895..353a82b0e 100644
--- a/src/net/eathena/chathandler.cpp
+++ b/src/net/eathena/chathandler.cpp
@@ -60,24 +60,24 @@ void ChatHandler::talk(const std::string &restrict text,
createOutPacket(CMSG_CHAT_MESSAGE);
// Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length() + 1), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
}
void ChatHandler::talkRaw(const std::string &mes) const
{
createOutPacket(CMSG_CHAT_MESSAGE);
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length()), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length()), "message");
}
void ChatHandler::privateMessage(const std::string &restrict recipient,
const std::string &restrict text)
{
createOutPacket(CMSG_CHAT_WHISPER);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 28 + 1), "len");
+ outMsg.writeInt16(CAST_S16(text.length() + 28 + 1), "len");
outMsg.writeString(recipient, 24, "recipient nick");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
outMsg.writeInt8(0, "null char");
Ea::ChatRecv::mSentWhispers.push(recipient);
}
@@ -107,7 +107,7 @@ void ChatHandler::sendRaw(const std::string &args) const
{
str = line.substr(0, pos);
- const int16_t id = static_cast<int16_t>(parseNumber(str));
+ const int16_t id = CAST_S16(parseNumber(str));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
line = line.substr(pos + 1);
@@ -115,7 +115,7 @@ void ChatHandler::sendRaw(const std::string &args) const
}
else
{
- const int16_t id = static_cast<int16_t>(parseNumber(line));
+ const int16_t id = CAST_S16(parseNumber(line));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
delete outMsg;
@@ -145,17 +145,17 @@ void ChatHandler::processRaw(MessageOut &restrict outMsg,
{
case 'b':
{
- outMsg.writeInt8(static_cast<unsigned char>(i), "raw");
+ outMsg.writeInt8(CAST_U8(i), "raw");
break;
}
case 'w':
{
- outMsg.writeInt16(static_cast<int16_t>(i), "raw");
+ outMsg.writeInt16(CAST_S16(i), "raw");
break;
}
case 'l':
{
- outMsg.writeInt32(static_cast<int32_t>(i), "raw");
+ outMsg.writeInt32(CAST_S32(i), "raw");
break;
}
default:
@@ -201,10 +201,10 @@ void ChatHandler::createChatRoom(const std::string &title,
const bool isPublic)
{
createOutPacket(CMSG_CREAYE_CHAT_ROOM);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
7 + 8 + 36), "len");
- outMsg.writeInt16(static_cast<int16_t>(limit), "limit");
- outMsg.writeInt8(static_cast<int8_t>(isPublic ? 1 : 0), "public");
+ outMsg.writeInt16(CAST_S16(limit), "limit");
+ outMsg.writeInt8(CAST_S8(isPublic ? 1 : 0), "public");
outMsg.writeString(password, 8, "password");
outMsg.writeString(title, 36, "title");
ChatRecv::mChatRoom = title;
@@ -220,8 +220,8 @@ void ChatHandler::battleTalk(const std::string &text) const
createOutPacket(CMSG_BATTLE_CHAT_MESSAGE);
// Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length() + 1), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
}
void ChatHandler::joinChat(const ChatObject *const chat,
@@ -268,8 +268,8 @@ void ChatHandler::talkPet(const std::string &restrict text,
const size_t sz = msg.size();
createOutPacket(CMSG_PET_TALK);
- outMsg.writeInt16(static_cast<int16_t>(sz + 4 + 1), "len");
- outMsg.writeString(msg, static_cast<int>(sz), "message");
+ outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
+ outMsg.writeString(msg, CAST_S32(sz), "message");
outMsg.writeInt8(0, "zero byte");
}
@@ -284,10 +284,10 @@ void ChatHandler::setChatRoomOptions(const int limit,
const std::string &title) const
{
createOutPacket(CMSG_SET_CHAT_ROOM_OPTIONS);
- const int sz = static_cast<int>(title.size());
- outMsg.writeInt16(static_cast<int16_t>(15 + sz), "len");
- outMsg.writeInt16(static_cast<int16_t>(limit), "limit");
- outMsg.writeInt8(static_cast<int8_t>(isPublic ? 1 : 0), "type");
+ const int sz = CAST_S32(title.size());
+ outMsg.writeInt16(CAST_S16(15 + sz), "len");
+ outMsg.writeInt16(CAST_S16(limit), "limit");
+ outMsg.writeInt8(CAST_S8(isPublic ? 1 : 0), "type");
outMsg.writeString(password, 8, "password");
outMsg.writeString(title, sz, "title");
}
diff --git a/src/net/eathena/generalrecv.cpp b/src/net/eathena/generalrecv.cpp
index 48e079d09..1bba1cc3e 100644
--- a/src/net/eathena/generalrecv.cpp
+++ b/src/net/eathena/generalrecv.cpp
@@ -40,7 +40,7 @@ ServerInfo mapServer;
void GeneralRecv::processConnectionProblem(Net::MessageIn &msg)
{
const uint8_t code = msg.readUInt8("flag");
- logger->log("Connection problem: %u", static_cast<unsigned int>(code));
+ logger->log("Connection problem: %u", CAST_U32(code));
switch (code)
{
diff --git a/src/net/eathena/guildhandler.cpp b/src/net/eathena/guildhandler.cpp
index 99cf1f3f9..bc4d70f57 100644
--- a/src/net/eathena/guildhandler.cpp
+++ b/src/net/eathena/guildhandler.cpp
@@ -125,8 +125,8 @@ void GuildHandler::chat(const std::string &text) const
const std::string str = std::string(localPlayer->getName()).append(
" : ").append(text);
createOutPacket(CMSG_GUILD_MESSAGE);
- outMsg.writeInt16(static_cast<uint16_t>(str.size() + 4 + 1), "len");
- outMsg.writeString(str, static_cast<int>(str.length()), "message");
+ outMsg.writeInt16(CAST_U16(str.size() + 4 + 1), "len");
+ outMsg.writeString(str, CAST_S32(str.length()), "message");
outMsg.writeInt8(0, "zero byte");
}
@@ -245,8 +245,8 @@ void GuildHandler::changeEmblem(std::string emblem) const
createOutPacket(CMSG_GUILD_CHANGE_EMBLEM);
if (emblem.size() > 200)
emblem = emblem.substr(0, 200);
- const int sz = static_cast<int>(emblem.size());
- outMsg.writeInt16(static_cast<int16_t>(sz + 4), "len");
+ const int sz = CAST_S32(emblem.size());
+ outMsg.writeInt16(CAST_S16(sz + 4), "len");
outMsg.writeString(emblem, sz, "emblem");
}
diff --git a/src/net/eathena/guildrecv.cpp b/src/net/eathena/guildrecv.cpp
index d8c0193fb..7adfdfb27 100644
--- a/src/net/eathena/guildrecv.cpp
+++ b/src/net/eathena/guildrecv.cpp
@@ -68,7 +68,7 @@ void GuildRecv::processGuildPositionInfo(Net::MessageIn &msg)
msg.readInt32("unused");
std::string guildName = msg.readString(24, "guild name");
- Guild *const g = Guild::getGuild(static_cast<int16_t>(guildId));
+ Guild *const g = Guild::getGuild(CAST_S16(guildId));
if (!g)
return;
@@ -98,7 +98,7 @@ void GuildRecv::processGuildMemberLogin(Net::MessageIn &msg)
const BeingId accountId = msg.readBeingId("account id");
const int charId = msg.readInt32("char id");
const int online = msg.readInt32("flag");
- const GenderT gender = Being::intToGender(static_cast<uint8_t>(
+ const GenderT gender = Being::intToGender(CAST_U8(
msg.readInt16("sex")));
msg.readInt16("hair");
msg.readInt16("hair color");
diff --git a/src/net/eathena/homunculushandler.cpp b/src/net/eathena/homunculushandler.cpp
index 26b7ed618..9837eccb5 100644
--- a/src/net/eathena/homunculushandler.cpp
+++ b/src/net/eathena/homunculushandler.cpp
@@ -61,8 +61,8 @@ void HomunculusHandler::move(const int x, const int y) const
return;
createOutPacket(CMSG_HOMMERC_MOVE_TO);
outMsg.writeBeingId(id, "homunculus id");
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
0U, "position");
}
@@ -75,7 +75,7 @@ void HomunculusHandler::attack(const BeingId targetId,
createOutPacket(CMSG_HOMMERC_ATTACK);
outMsg.writeBeingId(id, "homunculus id");
outMsg.writeBeingId(targetId, "target id");
- outMsg.writeInt8(static_cast<int8_t>(keep == Keep_true ? 1 : 0), "keep");
+ outMsg.writeInt8(CAST_S8(keep == Keep_true ? 1 : 0), "keep");
}
void HomunculusHandler::feed() const
@@ -104,8 +104,8 @@ void HomunculusHandler::talk(const std::string &restrict text) const
const size_t sz = msg.size();
createOutPacket(CMSG_HOMMERC_TALK);
- outMsg.writeInt16(static_cast<int16_t>(sz + 4 + 1), "len");
- outMsg.writeString(msg, static_cast<int>(sz), "message");
+ outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
+ outMsg.writeString(msg, CAST_S32(sz), "message");
outMsg.writeInt8(0, "zero byte");
}
diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp
index fa2905c28..ce87e5660 100644
--- a/src/net/eathena/inventoryhandler.cpp
+++ b/src/net/eathena/inventoryhandler.cpp
@@ -80,7 +80,7 @@ void InventoryHandler::equipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_EQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
// here we set flag for any slots,
// probably better set to slot from item properties
@@ -93,7 +93,7 @@ void InventoryHandler::unequipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
}
@@ -103,7 +103,7 @@ void InventoryHandler::useItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_USE);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(item->getId(), "unused");
}
@@ -114,9 +114,9 @@ void InventoryHandler::dropItem(const Item *const item, const int amount) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_DROP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void InventoryHandler::closeStorage() const
@@ -157,7 +157,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source,
if (packet)
{
createOutPacket(packet);
- outMsg.writeInt16(static_cast<int16_t>(slot + offset), "index");
+ outMsg.writeInt16(CAST_S16(slot + offset), "index");
outMsg.writeInt32(amount, "amount");
}
}
@@ -169,7 +169,7 @@ void InventoryHandler::useCard(const Item *const item)
mItemIndex = item->getInvIndex();
createOutPacket(CMSG_PLAYER_USE_CARD);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
mItemIndex + INVENTORY_OFFSET), "index");
}
@@ -177,9 +177,9 @@ void InventoryHandler::insertCard(const int cardIndex,
const int itemIndex) const
{
createOutPacket(CMSG_PLAYER_INSERT_CARD);
- outMsg.writeInt16(static_cast<int16_t>(cardIndex + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(cardIndex + INVENTORY_OFFSET),
"card index");
- outMsg.writeInt16(static_cast<int16_t>(itemIndex + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(itemIndex + INVENTORY_OFFSET),
"item index");
}
@@ -189,7 +189,7 @@ void InventoryHandler::favoriteItem(const Item *const item,
if (!item)
return;
createOutPacket(CMSG_PLAYER_FAVORITE_ITEM);
- outMsg.writeInt16(static_cast<int16_t>(item->getInvIndex()
+ outMsg.writeInt16(CAST_S16(item->getInvIndex()
+ INVENTORY_OFFSET),
"item index");
outMsg.writeInt8(favorite, "favorite flag");
@@ -200,7 +200,7 @@ void InventoryHandler::selectEgg(const Item *const item) const
if (!item)
return;
createOutPacket(CMSG_PET_SELECT_EGG);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
menu = MenuType::Unknown;
}
@@ -210,7 +210,7 @@ int InventoryHandler::convertFromServerSlot(const int serverSlot) const
if (serverSlot < 0 || serverSlot > 15)
return 0;
- return static_cast<int>(EQUIP_CONVERT[serverSlot]);
+ return CAST_S32(EQUIP_CONVERT[serverSlot]);
}
void InventoryHandler::selectCart(const BeingId accountId,
@@ -224,7 +224,7 @@ void InventoryHandler::selectCart(const BeingId accountId,
void InventoryHandler::identifyItem(const Item *const item) const
{
createOutPacket(CMSG_QUICK_IDENTIFY_ITEM);
- outMsg.writeInt16(static_cast<int16_t>(item->getInvIndex()),
+ outMsg.writeInt16(CAST_S16(item->getInvIndex()),
"item index");
}
diff --git a/src/net/eathena/inventoryrecv.cpp b/src/net/eathena/inventoryrecv.cpp
index fcaada26a..d3b969143 100644
--- a/src/net/eathena/inventoryrecv.cpp
+++ b/src/net/eathena/inventoryrecv.cpp
@@ -97,7 +97,7 @@ void InventoryRecv::processPlayerEquipment(Net::MessageIn &msg)
const int itemType = msg.readUInt8("item type");
msg.readInt32("location");
const int equipType = msg.readInt32("wear state");
- const uint8_t refine = static_cast<uint8_t>(msg.readInt8("refine"));
+ const uint8_t refine = CAST_U8(msg.readInt8("refine"));
int cards[maxCards];
for (int f = 0; f < maxCards; f++)
cards[f] = msg.readInt16("card");
diff --git a/src/net/eathena/itemrecv.cpp b/src/net/eathena/itemrecv.cpp
index 79892ebf7..822b4684d 100644
--- a/src/net/eathena/itemrecv.cpp
+++ b/src/net/eathena/itemrecv.cpp
@@ -44,8 +44,8 @@ void ItemRecv::processItemDropped(Net::MessageIn &msg)
msg.readUInt8("identify"), Identified);
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
- const int subX = static_cast<int>(msg.readInt8("subx"));
- const int subY = static_cast<int>(msg.readInt8("suby"));
+ const int subX = CAST_S32(msg.readInt8("subx"));
+ const int subY = CAST_S32(msg.readInt8("suby"));
const int amount = msg.readInt16("count");
if (actorManager)
@@ -79,8 +79,8 @@ void ItemRecv::processItemDropped2(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("subx"));
- const int subY = static_cast<int>(msg.readInt8("suby"));
+ const int subX = CAST_S32(msg.readInt8("subx"));
+ const int subY = CAST_S32(msg.readInt8("suby"));
if (actorManager)
{
@@ -119,8 +119,8 @@ void ItemRecv::processItemVisible(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
if (actorManager)
{
@@ -153,8 +153,8 @@ void ItemRecv::processItemVisible2(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
if (actorManager)
{
diff --git a/src/net/eathena/mailhandler.cpp b/src/net/eathena/mailhandler.cpp
index d1ab80005..7bcc53088 100644
--- a/src/net/eathena/mailhandler.cpp
+++ b/src/net/eathena/mailhandler.cpp
@@ -70,21 +70,21 @@ void MailHandler::returnMessage(const int msgId) const
void MailHandler::setAttach(const int index, const int amount) const
{
createOutPacket(CMSG_MAIL_SET_ATTACH);
- outMsg.writeInt16(static_cast<int16_t>(index + INVENTORY_OFFSET), "index");
+ outMsg.writeInt16(CAST_S16(index + INVENTORY_OFFSET), "index");
outMsg.writeInt32(amount, "amount");
}
void MailHandler::setAttachMoney(const int money) const
{
createOutPacket(CMSG_MAIL_SET_ATTACH);
- outMsg.writeInt16(static_cast<int16_t>(0), "index");
+ outMsg.writeInt16(CAST_S16(0), "index");
outMsg.writeInt32(money, "money");
}
void MailHandler::resetAttach(const int flag) const
{
createOutPacket(CMSG_MAIL_RESET_ATTACH);
- outMsg.writeInt16(static_cast<int16_t>(flag), "flag");
+ outMsg.writeInt16(CAST_S16(flag), "flag");
}
void MailHandler::send(const std::string &name,
@@ -93,13 +93,13 @@ void MailHandler::send(const std::string &name,
{
if (message.size() > 255)
message = message.substr(0, 255);
- const int sz = static_cast<int>(message.size());
+ const int sz = CAST_S32(message.size());
createOutPacket(CMSG_MAIL_SEND);
- outMsg.writeInt16(static_cast<int16_t>(69 + sz), "len");
+ outMsg.writeInt16(CAST_S16(69 + sz), "len");
outMsg.writeString(name, 24, "name");
outMsg.writeString(title, 40, "title");
- outMsg.writeInt8(static_cast<int8_t>(sz), "message size");
+ outMsg.writeInt8(CAST_S8(sz), "message size");
outMsg.writeString(message, sz, "message");
}
diff --git a/src/net/eathena/markethandler.cpp b/src/net/eathena/markethandler.cpp
index de0e31345..b055d574a 100644
--- a/src/net/eathena/markethandler.cpp
+++ b/src/net/eathena/markethandler.cpp
@@ -56,11 +56,11 @@ void MarketHandler::buyItem(const int itemId,
cnt = 100;
createOutPacket(CMSG_NPC_MARKET_BUY);
- outMsg.writeInt16(static_cast<int16_t>(4 + 6 * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + 6 * cnt), "len");
for (int f = 0; f < cnt; f ++)
{
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
- outMsg.writeInt32(static_cast<int16_t>(amount2), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
+ outMsg.writeInt32(CAST_S16(amount2), "amount");
}
}
@@ -86,7 +86,7 @@ void MarketHandler::buyItems(std::vector<ShopItem*> &items) const
return;
createOutPacket(CMSG_NPC_MARKET_BUY);
- outMsg.writeInt16(static_cast<int16_t>(4 + pairSize * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
FOR_EACH (std::vector<ShopItem*>::iterator, it, items)
{
ShopItem *const item = *it;
@@ -101,15 +101,15 @@ void MarketHandler::buyItems(std::vector<ShopItem*> &items) const
{
for (int f = 0; f < usedQuantity; f ++)
{
- outMsg.writeInt16(static_cast<int16_t>(item->getId()),
+ outMsg.writeInt16(CAST_S16(item->getId()),
"item id");
- outMsg.writeInt32(static_cast<int16_t>(1), "amount");
+ outMsg.writeInt32(CAST_S16(1), "amount");
}
}
else
{
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
- outMsg.writeInt32(static_cast<int16_t>(usedQuantity), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
+ outMsg.writeInt32(CAST_S16(usedQuantity), "amount");
}
}
}
diff --git a/src/net/eathena/mercenaryhandler.cpp b/src/net/eathena/mercenaryhandler.cpp
index a14eac0ac..84eb5671c 100644
--- a/src/net/eathena/mercenaryhandler.cpp
+++ b/src/net/eathena/mercenaryhandler.cpp
@@ -61,8 +61,8 @@ void MercenaryHandler::move(const int x, const int y) const
return;
createOutPacket(CMSG_HOMMERC_MOVE_TO);
outMsg.writeBeingId(id, "mercenary id");
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
0U, "position");
}
@@ -75,7 +75,7 @@ void MercenaryHandler::attack(const BeingId targetId,
createOutPacket(CMSG_HOMMERC_ATTACK);
outMsg.writeBeingId(id, "mercenary id");
outMsg.writeBeingId(targetId, "target id");
- outMsg.writeInt8(static_cast<int8_t>(keep == Keep_true ? 1 : 0), "keep");
+ outMsg.writeInt8(CAST_S8(keep == Keep_true ? 1 : 0), "keep");
}
void MercenaryHandler::talk(const std::string &restrict text) const
@@ -90,8 +90,8 @@ void MercenaryHandler::talk(const std::string &restrict text) const
const size_t sz = msg.size();
createOutPacket(CMSG_HOMMERC_TALK);
- outMsg.writeInt16(static_cast<int16_t>(sz + 4 + 1), "len");
- outMsg.writeString(msg, static_cast<int>(sz), "message");
+ outMsg.writeInt16(CAST_S16(sz + 4 + 1), "len");
+ outMsg.writeString(msg, CAST_S32(sz), "message");
outMsg.writeInt8(0, "zero byte");
}
diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp
index 324666e86..fa19465a3 100644
--- a/src/net/eathena/messagein.cpp
+++ b/src/net/eathena/messagein.cpp
@@ -56,10 +56,10 @@ uint16_t MessageIn::readId()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
return value;
@@ -72,14 +72,14 @@ int16_t MessageIn::readInt16(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
- DEBUGLOG2("readInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("readInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
mPos += 2;
PacketCounters::incInBytes(2);
@@ -93,13 +93,13 @@ int32_t MessageIn::readInt32(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int32_t));
value = SDL_Swap32(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int32_t));
#endif
}
- DEBUGLOG2("readInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 4;
PacketCounters::incInBytes(4);
@@ -118,13 +118,13 @@ int64_t MessageIn::readInt64(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int64_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t));
value = SDL_Swap64(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t));
#endif
}
- DEBUGLOG2("readInt64: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt64: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 8;
PacketCounters::incInBytes(8);
diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp
index f97cc97d5..83be120e5 100644
--- a/src/net/eathena/messageout.cpp
+++ b/src/net/eathena/messageout.cpp
@@ -40,13 +40,13 @@ MessageOut::MessageOut(const int16_t id) :
mNetwork(EAthena::Network::instance())
{
mNetwork->fixSendBuffer();
- mData = mNetwork->mOutBuffer + static_cast<size_t>(mNetwork->mOutSize);
+ mData = mNetwork->mOutBuffer + CAST_SIZE(mNetwork->mOutSize);
}
void MessageOut::expand(const size_t bytes)
{
- mNetwork->mOutSize += static_cast<unsigned>(bytes);
- PacketCounters::incOutBytes(static_cast<int>(bytes));
+ mNetwork->mOutSize += CAST_U32(bytes);
+ PacketCounters::incOutBytes(CAST_S32(bytes));
}
void MessageOut::writeInt16(const int16_t value, const char *const str)
@@ -54,12 +54,12 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int16_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int16_t));
#endif
- DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("writeInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
mPos += 2;
PacketCounters::incOutBytes(2);
@@ -67,14 +67,14 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
void MessageOut::writeInt32(const int32_t value, const char *const str)
{
- DEBUGLOG2("writeInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("writeInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int32_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int32_t));
#endif
mPos += 4;
PacketCounters::incOutBytes(4);
@@ -85,9 +85,9 @@ void MessageOut::writeBeingId(const BeingId value, const char *const str)
writeInt32(toInt(value, int32_t), str);
}
-#define LOBYTE(w) (static_cast<unsigned char>(w))
-#define HIBYTE(w) (static_cast<unsigned char>(( \
-static_cast<uint16_t>(w)) >> 8))
+#define LOBYTE(w) (CAST_U8(w))
+#define HIBYTE(w) (CAST_U8(( \
+CAST_U16(w)) >> 8))
void MessageOut::writeCoordinates(const uint16_t x,
const uint16_t y,
@@ -95,11 +95,11 @@ void MessageOut::writeCoordinates(const uint16_t x,
const char *const str)
{
DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u",
- static_cast<unsigned>(x),
- static_cast<unsigned>(y),
- static_cast<unsigned>(direction)), mPos, str);
+ CAST_U32(x),
+ CAST_U32(y),
+ CAST_U32(direction)), mPos, str);
unsigned char *const data = reinterpret_cast<unsigned char*>(mData)
- + static_cast<size_t>(mPos);
+ + CAST_SIZE(mPos);
mNetwork->mOutSize += 3;
mPos += 3;
@@ -109,7 +109,7 @@ void MessageOut::writeCoordinates(const uint16_t x,
data[1] = 1;
data[2] = 2;
data[0] = HIBYTE(temp);
- data[1] = static_cast<unsigned char>(temp);
+ data[1] = CAST_U8(temp);
temp = y;
temp <<= 4;
data[1] |= HIBYTE(temp);
diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp
index 5d8bb6c24..934afe9f8 100644
--- a/src/net/eathena/network.cpp
+++ b/src/net/eathena/network.cpp
@@ -169,7 +169,7 @@ bool Network::messageReady()
{
const int msgId = readWord(0);
if (msgId >= 0 &&
- static_cast<unsigned int>(msgId) < packet_lengths_size)
+ CAST_U32(msgId) < packet_lengths_size)
{
len = mPackets[msgId].len;
}
@@ -178,7 +178,7 @@ bool Network::messageReady()
len = readWord(2);
}
- const bool ret = (mInSize >= static_cast<unsigned int>(len));
+ const bool ret = (mInSize >= CAST_U32(len));
SDL_mutexV(mMutexIn);
return ret;
diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp
index 07cce2351..7d0a65abc 100644
--- a/src/net/eathena/npchandler.cpp
+++ b/src/net/eathena/npchandler.cpp
@@ -102,9 +102,9 @@ void NpcHandler::stringInput(const BeingId npcId,
const std::string &value) const
{
createOutPacket(CMSG_NPC_STR_RESPONSE);
- outMsg.writeInt16(static_cast<int16_t>(value.length() + 9), "len");
+ outMsg.writeInt16(CAST_S16(value.length() + 9), "len");
outMsg.writeBeingId(npcId, "npc id");
- outMsg.writeString(value, static_cast<int>(value.length()), "value");
+ outMsg.writeString(value, CAST_S32(value.length()), "value");
outMsg.writeInt8(0, "null byte");
}
@@ -129,8 +129,8 @@ void NpcHandler::buyItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_BUY_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void NpcHandler::buyItems(std::vector<ShopItem*> &items) const
@@ -155,7 +155,7 @@ void NpcHandler::buyItems(std::vector<ShopItem*> &items) const
return;
createOutPacket(CMSG_NPC_BUY_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(4 + pairSize * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
FOR_EACH (std::vector<ShopItem*>::iterator, it, items)
{
ShopItem *const item = *it;
@@ -169,15 +169,15 @@ void NpcHandler::buyItems(std::vector<ShopItem*> &items) const
{
for (int f = 0; f < usedQuantity; f ++)
{
- outMsg.writeInt16(static_cast<int16_t>(1), "amount");
- outMsg.writeInt16(static_cast<int16_t>(item->getId()),
+ outMsg.writeInt16(CAST_S16(1), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()),
"item id");
}
}
else
{
- outMsg.writeInt16(static_cast<int16_t>(usedQuantity), "amount");
- outMsg.writeInt16(static_cast<int16_t>(item->getId()), "item id");
+ outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
+ outMsg.writeInt16(CAST_S16(item->getId()), "item id");
}
}
}
@@ -187,9 +187,9 @@ void NpcHandler::sellItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_SELL_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(itemId + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(itemId + INVENTORY_OFFSET),
"item index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void NpcHandler::sellItems(std::vector<ShopItem*> &items) const
@@ -207,7 +207,7 @@ void NpcHandler::sellItems(std::vector<ShopItem*> &items) const
}
createOutPacket(CMSG_NPC_SELL_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(4 + pairSize * cnt), "len");
+ outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
FOR_EACH (std::vector<ShopItem*>::iterator, it, items)
{
ShopItem *const item = *it;
@@ -216,10 +216,10 @@ void NpcHandler::sellItems(std::vector<ShopItem*> &items) const
continue;
item->increaseUsedQuantity(-usedQuantity);
item->update();
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getCurrentInvIndex() + INVENTORY_OFFSET),
"item index");
- outMsg.writeInt16(static_cast<int16_t>(usedQuantity), "amount");
+ outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
}
}
@@ -234,24 +234,24 @@ void NpcHandler::produceMix(const int nameId,
const int materialId3) const
{
createOutPacket(CMSG_NPC_PRODUCE_MIX);
- outMsg.writeInt16(static_cast<int16_t>(nameId), "name id");
- outMsg.writeInt16(static_cast<int16_t>(materialId1), "material 1");
- outMsg.writeInt16(static_cast<int16_t>(materialId2), "material 2");
- outMsg.writeInt16(static_cast<int16_t>(materialId3), "material 3");
+ outMsg.writeInt16(CAST_S16(nameId), "name id");
+ outMsg.writeInt16(CAST_S16(materialId1), "material 1");
+ outMsg.writeInt16(CAST_S16(materialId2), "material 2");
+ outMsg.writeInt16(CAST_S16(materialId3), "material 3");
}
void NpcHandler::cooking(const CookingTypeT type,
const int nameId) const
{
createOutPacket(CMSG_NPC_COOKING);
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
- outMsg.writeInt16(static_cast<int16_t>(nameId), "name id");
+ outMsg.writeInt16(CAST_S16(type), "type");
+ outMsg.writeInt16(CAST_S16(nameId), "name id");
}
void NpcHandler::repair(const int index) const
{
createOutPacket(CMSG_NPC_REPAIR);
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void NpcHandler::refine(const int index) const
@@ -263,19 +263,19 @@ void NpcHandler::refine(const int index) const
void NpcHandler::identify(const int index) const
{
createOutPacket(CMSG_NPC_IDENTIFY);
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void NpcHandler::selectArrow(const int nameId) const
{
createOutPacket(CMSG_NPC_SELECT_ARROW);
- outMsg.writeInt16(static_cast<int16_t>(nameId), "name id");
+ outMsg.writeInt16(CAST_S16(nameId), "name id");
}
void NpcHandler::selectAutoSpell(const int skillId) const
{
createOutPacket(CMSG_NPC_SELECT_AUTO_SPELL);
- outMsg.writeInt32(static_cast<int16_t>(skillId), "skill id");
+ outMsg.writeInt32(CAST_S16(skillId), "skill id");
}
BeingId NpcHandler::getNpc(Net::MessageIn &msg,
diff --git a/src/net/eathena/partyhandler.cpp b/src/net/eathena/partyhandler.cpp
index d41b7914d..3aa26b1b5 100644
--- a/src/net/eathena/partyhandler.cpp
+++ b/src/net/eathena/partyhandler.cpp
@@ -83,7 +83,7 @@ void PartyHandler::inviteResponse(const int partyId,
{
createOutPacket(CMSG_PARTY_INVITED2);
outMsg.writeInt32(partyId, "party id");
- outMsg.writeInt8(static_cast<int8_t>(accept ? 1 : 0), "accept");
+ outMsg.writeInt8(CAST_S8(accept ? 1 : 0), "accept");
}
}
@@ -125,8 +125,8 @@ void PartyHandler::chat(const std::string &text) const
const std::string mes = std::string(localPlayer->getName()).append(
" : ").append(text);
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length()), "nick : message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length()), "nick : message");
outMsg.writeInt8(0, "null char");
}
@@ -137,8 +137,8 @@ void PartyHandler::setShareExperience(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(share), "share exp");
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareItems),
+ outMsg.writeInt16(CAST_S16(share), "share exp");
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems),
"share items");
}
@@ -149,9 +149,9 @@ void PartyHandler::setShareItems(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareExp),
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareExp),
"share exp");
- outMsg.writeInt16(static_cast<int16_t>(share), "share items");
+ outMsg.writeInt16(CAST_S16(share), "share items");
}
void PartyHandler::changeLeader(const std::string &name) const
@@ -167,7 +167,7 @@ void PartyHandler::changeLeader(const std::string &name) const
void PartyHandler::allowInvite(const bool allow) const
{
createOutPacket(CMSG_PARTY_ALLOW_INVITES);
- outMsg.writeInt8(static_cast<int8_t>(allow ? 1 : 0), "allow");
+ outMsg.writeInt8(CAST_S8(allow ? 1 : 0), "allow");
}
} // namespace EAthena
diff --git a/src/net/eathena/pethandler.cpp b/src/net/eathena/pethandler.cpp
index b7a2a3b34..55f285dc1 100644
--- a/src/net/eathena/pethandler.cpp
+++ b/src/net/eathena/pethandler.cpp
@@ -46,8 +46,8 @@ void PetHandler::move(const int petId A_UNUSED,
return;
createOutPacket(CMSG_PET_MOVE_TO);
outMsg.writeInt32(0, "pet id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void PetHandler::spawn(const Being *const being A_UNUSED,
diff --git a/src/net/eathena/playerhandler.cpp b/src/net/eathena/playerhandler.cpp
index c319c6e8d..c07fa4d13 100644
--- a/src/net/eathena/playerhandler.cpp
+++ b/src/net/eathena/playerhandler.cpp
@@ -69,7 +69,7 @@ void PlayerHandler::increaseAttribute(const AttributesT attr) const
if (attr >= Attributes::STR && attr <= Attributes::LUK)
{
createOutPacket(CMSG_STAT_UPDATE_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(attr), "attribute id");
+ outMsg.writeInt16(CAST_S16(attr), "attribute id");
outMsg.writeInt8(1, "increase");
}
}
@@ -109,9 +109,9 @@ void PlayerHandler::setDestination(const int x, const int y,
const int direction) const
{
createOutPacket(CMSG_PLAYER_CHANGE_DEST);
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
- static_cast<unsigned char>(direction), "destination");
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
+ CAST_U8(direction), "destination");
}
void PlayerHandler::changeAction(const BeingActionT &action) const
@@ -165,10 +165,10 @@ void PlayerHandler::setShortcut(const int idx,
const int level) const
{
createOutPacket(CMSG_SET_SHORTCUTS);
- outMsg.writeInt16(static_cast<int16_t>(idx), "index");
- outMsg.writeInt8(static_cast<int8_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(idx), "index");
+ outMsg.writeInt8(CAST_S8(type), "type");
outMsg.writeInt32(id, "id");
- outMsg.writeInt16(static_cast<int16_t>(level), "level");
+ outMsg.writeInt16(CAST_S16(level), "level");
}
void PlayerHandler::shortcutShiftRow(const int row) const
@@ -176,7 +176,7 @@ void PlayerHandler::shortcutShiftRow(const int row) const
if (serverVersion != 0 && serverVersion < 11)
return;
createOutPacket(CMSG_SHORTCUTS_ROW_SHIFT);
- outMsg.writeInt8(static_cast<int8_t>(row), "row");
+ outMsg.writeInt8(CAST_S8(row), "row");
}
void PlayerHandler::removeOption() const
@@ -187,7 +187,7 @@ void PlayerHandler::removeOption() const
void PlayerHandler::changeCart(const int type) const
{
createOutPacket(CMSG_CHANGE_CART);
- outMsg.writeInt16(static_cast<int16_t>(type), "type");
+ outMsg.writeInt16(CAST_S16(type), "type");
}
void PlayerHandler::setMemo() const
diff --git a/src/net/eathena/playerrecv.cpp b/src/net/eathena/playerrecv.cpp
index 6aa71870a..928faf45b 100644
--- a/src/net/eathena/playerrecv.cpp
+++ b/src/net/eathena/playerrecv.cpp
@@ -389,7 +389,7 @@ void PlayerRecv::processOnlineList(Net::MessageIn &msg)
int addVal = 3;
while (buf - start + 1 < size
- && *(buf + static_cast<size_t>(addVal)))
+ && *(buf + CAST_SIZE(addVal)))
{
unsigned char status = *buf;
buf ++;
diff --git a/src/net/eathena/questhandler.cpp b/src/net/eathena/questhandler.cpp
index 35a903a31..452448101 100644
--- a/src/net/eathena/questhandler.cpp
+++ b/src/net/eathena/questhandler.cpp
@@ -39,7 +39,7 @@ void QuestHandler::setQeustActiveState(const int questId,
{
createOutPacket(CMSG_QUEST_ACTIVATE);
outMsg.writeInt32(questId, "quest id");
- outMsg.writeInt8(static_cast<int8_t>(active ? 1 : 0), "activate");
+ outMsg.writeInt8(CAST_S8(active ? 1 : 0), "activate");
}
} // namespace EAthena
diff --git a/src/net/eathena/searchstorehandler.cpp b/src/net/eathena/searchstorehandler.cpp
index 64eb824cd..93e199286 100644
--- a/src/net/eathena/searchstorehandler.cpp
+++ b/src/net/eathena/searchstorehandler.cpp
@@ -42,12 +42,12 @@ void SearchStoreHandler::search(const StoreSearchTypeT type,
{
createOutPacket(CMSG_SEARCHSTORE_SEARCH);
outMsg.writeInt16(23, "len");
- outMsg.writeInt8(static_cast<uint8_t>(type), "search type");
+ outMsg.writeInt8(CAST_U8(type), "search type");
outMsg.writeInt32(maxPrice, "max price");
outMsg.writeInt32(minPrice, "min price");
outMsg.writeInt32(1, "items count");
outMsg.writeInt32(0, "cards count");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void SearchStoreHandler::nextPage() const
@@ -67,7 +67,7 @@ void SearchStoreHandler::select(const int accountId,
createOutPacket(CMSG_SEARCHSTORE_CLICK);
outMsg.writeInt32(accountId, "account id");
outMsg.writeInt32(storeId, "store id");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
} // namespace EAthena
diff --git a/src/net/eathena/skillhandler.cpp b/src/net/eathena/skillhandler.cpp
index 9fbaab265..fb56fae4b 100644
--- a/src/net/eathena/skillhandler.cpp
+++ b/src/net/eathena/skillhandler.cpp
@@ -42,8 +42,8 @@ void SkillHandler::useBeing(const int id, const int level,
const BeingId beingId) const
{
createOutPacket(CMSG_SKILL_USE_BEING);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
outMsg.writeInt32(toInt(beingId, int), "target id");
}
@@ -51,10 +51,10 @@ void SkillHandler::usePos(const int id, const int level,
const int x, const int y) const
{
createOutPacket(CMSG_SKILL_USE_POSITION);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void SkillHandler::usePos(const int id, const int level,
@@ -62,17 +62,17 @@ void SkillHandler::usePos(const int id, const int level,
const std::string &text) const
{
createOutPacket(CMSG_SKILL_USE_POSITION_MORE);
- outMsg.writeInt16(static_cast<int16_t>(level), "level");
- outMsg.writeInt16(static_cast<int16_t>(id), "id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "level");
+ outMsg.writeInt16(CAST_S16(id), "id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
outMsg.writeString(text, 80, "text");
}
void SkillHandler::useMap(const int id, const std::string &map) const
{
createOutPacket(CMSG_SKILL_USE_MAP);
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
outMsg.writeString(map, 16, "map name");
}
diff --git a/src/net/eathena/skillrecv.cpp b/src/net/eathena/skillrecv.cpp
index 214cd88d9..d67620e4c 100644
--- a/src/net/eathena/skillrecv.cpp
+++ b/src/net/eathena/skillrecv.cpp
@@ -203,17 +203,17 @@ void SkillRecv::processSkillFailed(Net::MessageIn &msg)
const int bskill = msg.readInt32("btype");
const signed char success = msg.readUInt8("success");
const signed char reason = msg.readUInt8("reason");
- if (success != static_cast<int>(SKILL_FAILED)
- && bskill == static_cast<int>(BSKILL_EMOTE))
+ if (success != CAST_S32(SKILL_FAILED)
+ && bskill == CAST_S32(BSKILL_EMOTE))
{
logger->log("Action: %d/%d", bskill, success);
}
std::string txt;
- if (success == static_cast<int>(SKILL_FAILED) && bskill != 0)
+ if (success == CAST_S32(SKILL_FAILED) && bskill != 0)
{
- if (localPlayer && bskill == static_cast<int>(BSKILL_EMOTE)
- && reason == static_cast<int>(RFAIL_SKILLDEP))
+ if (localPlayer && bskill == CAST_S32(BSKILL_EMOTE)
+ && reason == CAST_S32(RFAIL_SKILLDEP))
{
localPlayer->stopAdvert();
}
diff --git a/src/net/eathena/tradehandler.cpp b/src/net/eathena/tradehandler.cpp
index 52ceb0d10..417d19de4 100644
--- a/src/net/eathena/tradehandler.cpp
+++ b/src/net/eathena/tradehandler.cpp
@@ -61,7 +61,7 @@ void TradeHandler::respond(const bool accept) const
PlayerInfo::setTrading(Trading_false);
createOutPacket(CMSG_TRADE_RESPONSE);
- outMsg.writeInt8(static_cast<int8_t>(accept ? 3 : 4), "accept");
+ outMsg.writeInt8(CAST_S8(accept ? 3 : 4), "accept");
}
void TradeHandler::addItem(const Item *const item, const int amount) const
@@ -72,7 +72,7 @@ void TradeHandler::addItem(const Item *const item, const int amount) const
TradeRecv::mItemIndex = item->getInvIndex();
TradeRecv::mQuantity = amount;
createOutPacket(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
TradeRecv::mItemIndex + INVENTORY_OFFSET),
"index");
outMsg.writeInt32(amount, "amount");
diff --git a/src/net/eathena/vendinghandler.cpp b/src/net/eathena/vendinghandler.cpp
index 4d0d75ca1..ce2b8d384 100644
--- a/src/net/eathena/vendinghandler.cpp
+++ b/src/net/eathena/vendinghandler.cpp
@@ -69,8 +69,8 @@ void VendingHandler::buy(const Being *const being,
createOutPacket(CMSG_VENDING_BUY);
outMsg.writeInt16(12, "len");
outMsg.writeBeingId(being->getId(), "account id");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void VendingHandler::buy2(const Being *const being,
@@ -85,8 +85,8 @@ void VendingHandler::buy2(const Being *const being,
outMsg.writeInt16(16, "len");
outMsg.writeBeingId(being->getId(), "account id");
outMsg.writeInt32(vendId, "vend id");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(index), "index");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(index), "index");
}
void VendingHandler::createShop(const std::string &name,
@@ -94,15 +94,15 @@ void VendingHandler::createShop(const std::string &name,
std::vector<ShopItem*> &items) const
{
createOutPacket(CMSG_VENDING_CREATE_SHOP);
- outMsg.writeInt16(static_cast<int16_t>(85 + items.size() * 8), "len");
+ outMsg.writeInt16(CAST_S16(85 + items.size() * 8), "len");
outMsg.writeString(name, 80, "shop name");
- outMsg.writeInt8(static_cast<int8_t>(flag ? 1 : 0), "flag");
+ outMsg.writeInt8(CAST_S8(flag ? 1 : 0), "flag");
FOR_EACH (std::vector<ShopItem*>::const_iterator, it, items)
{
const ShopItem *const item = *it;
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(item->getQuantity()), "amount");
+ outMsg.writeInt16(CAST_S16(item->getQuantity()), "amount");
outMsg.writeInt32(item->getPrice(), "price");
}
}
diff --git a/src/net/ipc.cpp b/src/net/ipc.cpp
index 79020e06d..088bd3b81 100644
--- a/src/net/ipc.cpp
+++ b/src/net/ipc.cpp
@@ -129,7 +129,7 @@ int IPC::acceptLoop(void *ptr)
ipc1->mNumReqs, req.c_str());
const char *const respc = resp.c_str();
- const int len = static_cast<int>(strlen(respc)) + 1;
+ const int len = CAST_S32(strlen(respc)) + 1;
result = TcpNet::send(sock, respc, len);
if (result < len)
{
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index def3b1e27..f012a5e2c 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -31,8 +31,8 @@
#include "debug.h"
#define MAKEWORD(low, high) \
- (static_cast<uint16_t>((static_cast<unsigned char>(low)) | \
- (static_cast<uint16_t>(static_cast<unsigned char>(high))) << 8))
+ (CAST_U16((CAST_U8(low)) | \
+ (CAST_U16(CAST_U8(high))) << 8))
namespace Net
{
@@ -56,25 +56,25 @@ MessageIn::~MessageIn()
{
logger->log("Wrong actual or planned inbound packet size!");
logger->log(" packet id: %u 0x%x",
- static_cast<unsigned int>(mId),
- static_cast<unsigned int>(mId));
+ CAST_U32(mId),
+ CAST_U32(mId));
logger->log(" planned size: %u", mLength);
logger->log(" read size: %u", mPos);
}
}
else
{
- logger->log("Zero packet size: %d", static_cast<int>(mId));
+ logger->log("Zero packet size: %d", CAST_S32(mId));
}
}
unsigned char MessageIn::readUInt8(const char *const str)
{
- unsigned char value = static_cast<unsigned char>(-1);
+ unsigned char value = CAST_U8(-1);
if (mPos < mLength)
- value = static_cast<unsigned char>(mData[mPos]);
+ value = CAST_U8(mData[mPos]);
- DEBUGLOG2("readUInt8: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readUInt8: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 1;
PacketCounters::incInBytes(1);
@@ -83,12 +83,12 @@ unsigned char MessageIn::readUInt8(const char *const str)
signed char MessageIn::readInt8(const char *const str)
{
- signed char value = static_cast<signed char>(-1);
+ signed char value = CAST_S8(-1);
if (mPos < mLength)
- value = static_cast<signed char>(mData[mPos]);
+ value = CAST_S8(mData[mPos]);
- DEBUGLOG2("readInt8: " + toStringPrint(static_cast<unsigned int>(
- static_cast<unsigned char>(value))),
+ DEBUGLOG2("readInt8: " + toStringPrint(CAST_U32(
+ CAST_U8(value))),
mPos, str);
mPos += 1;
PacketCounters::incInBytes(1);
@@ -120,7 +120,7 @@ uint8_t MessageIn::fromServerDirection(const uint8_t serverDir)
return 8;
default:
logger->log("incorrect direction: %d",
- static_cast<int>(serverDir));
+ CAST_S32(serverDir));
return 0;
}
}
@@ -132,19 +132,19 @@ void MessageIn::readCoordinates(uint16_t &restrict x,
{
if (mPos + 3 <= mLength)
{
- const char *const data = mData + static_cast<size_t>(mPos);
+ const char *const data = mData + CAST_SIZE(mPos);
uint16_t temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff);
- x = static_cast<uint16_t>(temp >> 6);
+ x = CAST_U16(temp >> 6);
temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f);
- y = static_cast<uint16_t>(temp >> 4);
+ y = CAST_U16(temp >> 4);
- const uint8_t serverDir = static_cast<uint8_t>(data[2] & 0x000f);
+ const uint8_t serverDir = CAST_U8(data[2] & 0x000f);
direction = fromServerDirection(serverDir);
DEBUGLOG2(std::string("readCoordinates: ").append(toString(
- static_cast<int>(x))).append(",").append(toString(
- static_cast<int>(y))).append(",").append(toString(
- static_cast<int>(serverDir))), mPos, str);
+ CAST_S32(x))).append(",").append(toString(
+ CAST_S32(y))).append(",").append(toString(
+ CAST_S32(serverDir))), mPos, str);
}
else
{
@@ -165,23 +165,23 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
{
if (mPos + 5 <= mLength)
{
- const char *const data = mData + static_cast<size_t>(mPos);
+ const char *const data = mData + CAST_SIZE(mPos);
uint16_t temp = MAKEWORD(data[3], data[2] & 0x000f);
- dstX = static_cast<uint16_t>(temp >> 2);
+ dstX = CAST_U16(temp >> 2);
dstY = MAKEWORD(data[4], data[3] & 0x0003);
temp = MAKEWORD(data[1], data[0]);
- srcX = static_cast<uint16_t>(temp >> 6);
+ srcX = CAST_U16(temp >> 6);
temp = MAKEWORD(data[2], data[1] & 0x003f);
- srcY = static_cast<uint16_t>(temp >> 4);
+ srcY = CAST_U16(temp >> 4);
DEBUGLOG2(std::string("readCoordinatePair: ").append(toString(
- static_cast<int>(srcX))).append(",").append(toString(
- static_cast<int>(srcY))).append(" ").append(toString(
- static_cast<int>(dstX))).append(",").append(toString(
- static_cast<int>(dstY))), mPos, str);
+ CAST_S32(srcX))).append(",").append(toString(
+ CAST_S32(srcY))).append(" ").append(toString(
+ CAST_S32(dstX))).append(",").append(toString(
+ CAST_S32(dstY))), mPos, str);
}
else
{
@@ -197,14 +197,14 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
void MessageIn::skip(const unsigned int length, const char *const str)
{
- DEBUGLOG2("skip: " + toString(static_cast<int>(length)), mPos, str);
+ DEBUGLOG2("skip: " + toString(CAST_S32(length)), mPos, str);
mPos += length;
PacketCounters::incInBytes(length);
}
void MessageIn::skipToEnd(const char *const str)
{
- const int diff = static_cast<int>(mLength - mPos);
+ const int diff = CAST_S32(mLength - mPos);
if (diff)
{
DEBUGLOG2("skip: " + toString(diff), mPos, str);
@@ -228,12 +228,12 @@ std::string MessageIn::readString(int length, const char *const dstr)
}
// Read the string
- const char *const stringBeg = mData + static_cast<size_t>(mPos);
+ const char *const stringBeg = mData + CAST_SIZE(mPos);
const char *const stringEnd
= static_cast<const char *const>(memchr(stringBeg, '\0', length));
const std::string str(stringBeg, stringEnd
- ? stringEnd - stringBeg : static_cast<size_t>(length));
+ ? stringEnd - stringBeg : CAST_SIZE(length));
DEBUGLOG2("readString: " + str, mPos, dstr);
mPos += length;
PacketCounters::incInBytes(length);
@@ -254,17 +254,17 @@ std::string MessageIn::readRawString(int length, const char *const dstr)
}
// Read the string
- const char *const stringBeg = mData + static_cast<size_t>(mPos);
+ const char *const stringBeg = mData + CAST_SIZE(mPos);
const char *const stringEnd
= static_cast<const char *const>(memchr(stringBeg, '\0', length));
std::string str(stringBeg, stringEnd
- ? stringEnd - stringBeg : static_cast<size_t>(length));
+ ? stringEnd - stringBeg : CAST_SIZE(length));
DEBUGLOG2("readString: " + str, mPos, dstr);
if (stringEnd)
{
- const size_t len2 = static_cast<size_t>(length)
+ const size_t len2 = CAST_SIZE(length)
- (stringEnd - stringBeg) - 1;
const char *const stringBeg2 = stringEnd + 1;
const char *const stringEnd2
@@ -298,9 +298,9 @@ unsigned char *MessageIn::readBytes(int length, const char *const dstr)
}
unsigned char *const buf
- = new unsigned char[static_cast<size_t>(length + 2)];
+ = new unsigned char[CAST_SIZE(length + 2)];
- memcpy(buf, mData + static_cast<size_t>(mPos), length);
+ memcpy(buf, mData + CAST_SIZE(mPos), length);
buf[length] = 0;
buf[length + 1] = 0;
mPos += length;
@@ -308,7 +308,7 @@ unsigned char *MessageIn::readBytes(int length, const char *const dstr)
#ifdef ENABLEDEBUGLOG
std::string str;
for (int f = 0; f < length; f ++)
- str.append(strprintf("%02x", static_cast<unsigned>(buf[f])));
+ str.append(strprintf("%02x", CAST_U32(buf[f])));
str += " ";
for (int f = 0; f < length; f ++)
{
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 88d7911e7..c2e96335f 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -48,8 +48,8 @@ void MessageOut::writeInt8(const int8_t value, const char *const str)
{
expand(1);
mData[mPos] = value;
- DEBUGLOG2("writeInt8: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint8_t>(value))),
+ DEBUGLOG2("writeInt8: " + toStringPrint(CAST_U32(
+ CAST_U8(value))),
mPos, str);
mPos += 1;
PacketCounters::incOutBytes(1);
@@ -59,11 +59,11 @@ void MessageOut::writeString(const std::string &string,
int length,
const char *const str)
{
- int stringLength = static_cast<int>(string.length());
+ int stringLength = CAST_S32(string.length());
if (length < 0)
{
// Write the length at the start if not fixed
- writeInt16(static_cast<int16_t>(stringLength), "len");
+ writeInt16(CAST_S16(stringLength), "len");
length = stringLength;
}
else if (length < stringLength)
@@ -74,12 +74,12 @@ void MessageOut::writeString(const std::string &string,
expand(length);
// Write the actual string
- memcpy(mData + static_cast<size_t>(mPos), string.c_str(), stringLength);
+ memcpy(mData + CAST_SIZE(mPos), string.c_str(), stringLength);
// Pad remaining space with zeros
if (length > stringLength)
{
- memset(mData + static_cast<size_t>(mPos + stringLength),
+ memset(mData + CAST_SIZE(mPos + stringLength),
'\0',
length - stringLength);
}
@@ -93,11 +93,11 @@ void MessageOut::writeStringNoLog(const std::string &string,
int length,
const char *const str)
{
- int stringLength = static_cast<int>(string.length());
+ int stringLength = CAST_S32(string.length());
if (length < 0)
{
// Write the length at the start if not fixed
- writeInt16(static_cast<int16_t>(stringLength), "len");
+ writeInt16(CAST_S16(stringLength), "len");
length = stringLength;
}
else if (length < stringLength)
@@ -108,12 +108,12 @@ void MessageOut::writeStringNoLog(const std::string &string,
expand(length);
// Write the actual string
- memcpy(mData + static_cast<size_t>(mPos), string.c_str(), stringLength);
+ memcpy(mData + CAST_SIZE(mPos), string.c_str(), stringLength);
// Pad remaining space with zeros
if (length > stringLength)
{
- memset(mData + static_cast<size_t>(mPos + stringLength),
+ memset(mData + CAST_SIZE(mPos + stringLength),
'\0',
length - stringLength);
}
@@ -164,7 +164,7 @@ unsigned char MessageOut::toServerDirection(unsigned char direction)
break;
default:
// OOPSIE! Impossible or unknown
- direction = static_cast<unsigned char>(-1);
+ direction = CAST_U8(-1);
break;
}
return direction;
diff --git a/src/net/messageout.h b/src/net/messageout.h
index 6fcb06cc3..8771f5240 100644
--- a/src/net/messageout.h
+++ b/src/net/messageout.h
@@ -30,7 +30,7 @@
#include "localconsts.h"
#define createOutPacket(name) MessageOut outMsg(name); \
- outMsg.writeInt16(static_cast<int16_t>(name), #name)
+ outMsg.writeInt16(CAST_S16(name), #name)
namespace Net
{
diff --git a/src/net/packetlimiter.cpp b/src/net/packetlimiter.cpp
index 818d75fd8..76ec8b4f4 100644
--- a/src/net/packetlimiter.cpp
+++ b/src/net/packetlimiter.cpp
@@ -39,136 +39,136 @@ struct PacketLimit final
int cntLimit;
};
-PacketLimit mPacketLimits[static_cast<size_t>(PacketType::PACKET_SIZE) + 1];
+PacketLimit mPacketLimits[CAST_SIZE(PacketType::PACKET_SIZE) + 1];
void PacketLimiter::initPacketLimiter()
{
// here i setting packet limits. but current server is broken,
// and this limits may not help.
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].timeLimit = 10 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].cnt = 0;
// 10
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].timeLimit = 10 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_PICKUP)].cnt = 0;
// 10 5
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].timeLimit = 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DROP)].cnt = 0;
// 100
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].timeLimit = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_NEXT)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].timeLimit = 100;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_INPUT)].cnt = 0;
// 50
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].timeLimit = 60;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_NPC_TALK)].cnt = 0;
// 10
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].timeLimit = 10 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_EMOTE)].cnt = 0;
// 100
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].timeLimit = 100;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_SIT)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].timeLimit = 50;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_DIRECTION)].cnt = 0;
// 2+
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].timeLimit = 2 + 10;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ATTACK)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].timeLimit = 2 + 10;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_STOPATTACK)].cnt = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].timeLimit = 1800;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_ONLINELIST)].cnt = 0;
// 300ms + 50 fix
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].timeLimit = 30 + 5;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].lastTime = 0;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].cntLimit = 1;
- mPacketLimits[static_cast<size_t>(
+ mPacketLimits[CAST_SIZE(
PacketType::PACKET_WHISPER)].cnt = 0;
if (!settings.serverConfigDir.empty())
@@ -199,7 +199,7 @@ void PacketLimiter::initPacketLimiter()
const int ver = atoi(line);
for (int f = 0;
- f < static_cast<int>(PacketType::PACKET_SIZE);
+ f < CAST_S32(PacketType::PACKET_SIZE);
f ++)
{
if (!inPacketFile.getline(line, 100))
@@ -230,7 +230,7 @@ void PacketLimiter::writePacketLimits(const std::string &packetLimitsName)
return;
}
outPacketFile << "4" << std::endl;
- for (int f = 0; f < static_cast<int>(PacketType::PACKET_SIZE); f ++)
+ for (int f = 0; f < CAST_S32(PacketType::PACKET_SIZE); f ++)
{
outPacketFile << toString(mPacketLimits[f].timeLimit)
<< std::endl;
@@ -247,7 +247,7 @@ bool PacketLimiter::checkPackets(const PacketTypeT type)
if (!serverConfig.getValueBool("enableBuggyServers", true))
return true;
- const PacketLimit &limit = mPacketLimits[static_cast<size_t>(type)];
+ const PacketLimit &limit = mPacketLimits[CAST_SIZE(type)];
const int timeLimit = limit.timeLimit;
if (!timeLimit)
@@ -284,13 +284,13 @@ bool PacketLimiter::checkPackets(const PacketTypeT type)
bool PacketLimiter::limitPackets(const PacketTypeT type)
{
- if (static_cast<int>(type) < 0 || type > PacketType::PACKET_SIZE)
+ if (CAST_S32(type) < 0 || type > PacketType::PACKET_SIZE)
return false;
if (!serverConfig.getValueBool("enableBuggyServers", true))
return true;
- PacketLimit &pack = mPacketLimits[static_cast<size_t>(type)];
+ PacketLimit &pack = mPacketLimits[CAST_SIZE(type)];
const int timeLimit = pack.timeLimit;
if (!timeLimit)
diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp
index e77b9afdb..30c2bfe84 100644
--- a/src/net/tmwa/adminhandler.cpp
+++ b/src/net/tmwa/adminhandler.cpp
@@ -47,15 +47,15 @@ AdminHandler::AdminHandler() :
void AdminHandler::announce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::localAnnounce(const std::string &text) const
{
createOutPacket(CMSG_ADMIN_LOCAL_ANNOUNCE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
}
void AdminHandler::hide(const bool h A_UNUSED) const
diff --git a/src/net/tmwa/beingrecv.cpp b/src/net/tmwa/beingrecv.cpp
index 93d4a41dc..ea921f91e 100644
--- a/src/net/tmwa/beingrecv.cpp
+++ b/src/net/tmwa/beingrecv.cpp
@@ -73,7 +73,7 @@ void BeingRecv::processBeingChangeLook(Net::MessageIn &msg)
msg.readBeingId("being id"));
const uint8_t type = msg.readUInt8("type");
- const int16_t id = static_cast<int16_t>(msg.readUInt8("id"));
+ const int16_t id = CAST_S16(msg.readUInt8("id"));
const int id2 = 1;
if (!localPlayer || !dstBeing)
@@ -138,7 +138,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg,
break;
case 1: // eAthena LOOK_HAIR
{
- const uint16_t look = static_cast<uint16_t>(id / 256);
+ const uint16_t look = CAST_U16(id / 256);
const int hair = id % 256;
dstBeing->setHairStyle(SPRITE_HAIR_COLOR, hair * -1);
dstBeing->setLook(look);
@@ -212,7 +212,7 @@ void BeingRecv::processBeingChangeLookContinue(Net::MessageIn &msg,
localPlayer->imitateOutfit(dstBeing, SPRITE_EVOL2);
break;
case 16:
- dstBeing->setLook(static_cast<uint16_t>(id));
+ dstBeing->setLook(CAST_U16(id));
break;
default:
UNIMPLIMENTEDPACKET;
@@ -234,7 +234,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
const int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("options")))
+ statusEffects |= (CAST_U32(msg.readInt16("options")))
<< 16;
const int16_t job = msg.readInt16("job");
int disguiseId = 0;
@@ -301,7 +301,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
if (guild == 0)
dstBeing->clearGuilds();
else
- dstBeing->setGuild(Guild::getGuild(static_cast<int16_t>(guild)));
+ dstBeing->setGuild(Guild::getGuild(CAST_S16(guild)));
}
msg.readInt16("emblem");
@@ -310,7 +310,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
dstBeing->setKarma(msg.readUInt8("karma"));
// reserving bit for future usage
dstBeing->setGender(Being::intToGender(
- static_cast<uint8_t>(msg.readUInt8("gender") & 3)));
+ CAST_U8(msg.readUInt8("gender") & 3)));
if (!disguiseId)
{
@@ -339,7 +339,7 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
dstBeing->setGM(true);
applyPlayerAction(msg, dstBeing, msg.readUInt8("action type"));
- const int level = static_cast<int>(msg.readUInt8("level"));
+ const int level = CAST_S32(msg.readUInt8("level"));
if (level)
dstBeing->setLevel(level);
@@ -348,9 +348,9 @@ void BeingRecv::processPlayerUpdate1(Net::MessageIn &msg)
dstBeing->setActionTime(tick_time);
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerMoveUpdate")
@@ -370,7 +370,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
const int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("options")))
+ statusEffects |= (CAST_U32(msg.readInt16("options")))
<< 16;
const int16_t job = msg.readInt16("job");
int disguiseId = 0;
@@ -436,7 +436,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
if (guild == 0)
dstBeing->clearGuilds();
else
- dstBeing->setGuild(Guild::getGuild(static_cast<int16_t>(guild)));
+ dstBeing->setGuild(Guild::getGuild(CAST_S16(guild)));
}
msg.readInt16("emblem");
@@ -445,7 +445,7 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
dstBeing->setKarma(msg.readUInt8("karma"));
// reserving bit for future usage
dstBeing->setGender(Being::intToGender(
- static_cast<uint8_t>(msg.readUInt8("gender") & 3)));
+ CAST_U8(msg.readUInt8("gender") & 3)));
if (!disguiseId)
{
@@ -474,15 +474,15 @@ void BeingRecv::processPlayerUpdate2(Net::MessageIn &msg)
dstBeing->setGM(true);
applyPlayerAction(msg, dstBeing, msg.readUInt8("action type"));
- const int level = static_cast<int>(msg.readUInt8("level"));
+ const int level = CAST_S32(msg.readUInt8("level"));
if (level)
dstBeing->setLevel(level);
dstBeing->setActionTime(tick_time);
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerMoveUpdate")
@@ -502,7 +502,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
const int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("options")))
+ statusEffects |= (CAST_U32(msg.readInt16("options")))
<< 16;
const int16_t job = msg.readInt16("job");
int disguiseId = 0;
@@ -571,7 +571,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
if (guild == 0)
dstBeing->clearGuilds();
else
- dstBeing->setGuild(Guild::getGuild(static_cast<int16_t>(guild)));
+ dstBeing->setGuild(Guild::getGuild(CAST_S16(guild)));
}
msg.readInt16("emblem");
@@ -580,7 +580,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
dstBeing->setKarma(msg.readUInt8("karma"));
// reserving bit for future usage
dstBeing->setGender(Being::intToGender(
- static_cast<uint8_t>(msg.readUInt8("gender") & 3)));
+ CAST_U8(msg.readUInt8("gender") & 3)));
if (!disguiseId)
{
@@ -612,7 +612,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
const int d = dstBeing->calcDirection(dstX, dstY);
if (d && dstBeing->getDirection() != d)
- dstBeing->setDirectionDelayed(static_cast<uint8_t>(d));
+ dstBeing->setDirectionDelayed(CAST_U8(d));
}
if (localPlayer->getCurrentAction() != BeingAction::STAND)
@@ -630,7 +630,7 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
msg.readUInt8("unused");
- const int level = static_cast<int>(msg.readUInt8("level"));
+ const int level = CAST_S32(msg.readUInt8("level"));
if (level)
dstBeing->setLevel(level);
@@ -640,9 +640,9 @@ void BeingRecv::processPlayerMove(Net::MessageIn &msg)
dstBeing->setActionTime(tick_time);
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
if (dstBeing->getType() == ActorType::Player)
@@ -671,7 +671,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt16("option"))) << 16;
const int16_t job = msg.readInt16("class");
int disguiseId = 0;
if (id == localPlayer->getId() && job >= 1000)
@@ -790,7 +790,7 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
if (serverFeatures->haveMonsterAttackRange()
&& dstBeing->getType() == ActorType::Monster)
{
- const int attackRange = static_cast<int>(
+ const int attackRange = CAST_S32(
msg.readUInt8("attack range (was karma)"));
dstBeing->setAttackRange(attackRange);
}
@@ -852,9 +852,9 @@ void BeingRecv::processBeingVisible(Net::MessageIn &msg)
msg.readUInt8("unknown");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processBeingVisibleOrMove")
}
@@ -880,7 +880,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
int16_t speed = msg.readInt16("speed");
const uint16_t stunMode = msg.readInt16("opt1");
uint32_t statusEffects = msg.readInt16("opt2");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("option"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt16("option"))) << 16;
const int16_t job = msg.readInt16("class");
int disguiseId = 0;
if (id == localPlayer->getId() && job >= 1000)
@@ -993,7 +993,7 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
if (serverFeatures->haveMonsterAttackRange()
&& dstBeing->getType() == ActorType::Monster)
{
- const int attackRange = static_cast<int>(
+ const int attackRange = CAST_S32(
msg.readUInt8("attack range (was karma)"));
dstBeing->setAttackRange(attackRange);
}
@@ -1044,9 +1044,9 @@ void BeingRecv::processBeingMove(Net::MessageIn &msg)
msg.readUInt8("unknown");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processBeingVisibleOrMove")
}
@@ -1162,7 +1162,7 @@ void BeingRecv::processBeingChangeDirection(Net::MessageIn &msg)
msg.readInt16("unused");
const uint8_t dir = Net::MessageIn::fromServerDirection(
- static_cast<uint8_t>(msg.readUInt8("direction") & 0x0FU));
+ CAST_U8(msg.readUInt8("direction") & 0x0FU));
dstBeing->setDirection(dir);
if (localPlayer)
localPlayer->imitateDirection(dstBeing, dir);
@@ -1193,13 +1193,13 @@ void BeingRecv::processPlaterStatusChange(Net::MessageIn &msg)
const uint16_t stunMode = msg.readInt16("stun mode");
uint32_t statusEffects = msg.readInt16("status effect");
- statusEffects |= (static_cast<uint32_t>(msg.readInt16("opt?"))) << 16;
+ statusEffects |= (CAST_U32(msg.readInt16("opt?"))) << 16;
msg.readUInt8("Unused?");
dstBeing->setStunMode(stunMode);
- dstBeing->setStatusEffectBlock(0, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(0, CAST_U16(
(statusEffects >> 16) & 0xffff));
- dstBeing->setStatusEffectBlock(16, static_cast<uint16_t>(
+ dstBeing->setStatusEffectBlock(16, CAST_U16(
statusEffects & 0xffff));
BLOCK_END("BeingRecv::processPlayerStop")
}
@@ -1342,7 +1342,7 @@ void BeingRecv::processPvpSet(Net::MessageIn &msg)
if (dstBeing)
{
dstBeing->setPvpRank(rank);
- dstBeing->setTeamId(static_cast<uint16_t>(teamId));
+ dstBeing->setTeamId(CAST_U16(teamId));
dstBeing->addToCache();
}
}
diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp
index af0d4ad42..d7b92be1a 100644
--- a/src/net/tmwa/charserverhandler.cpp
+++ b/src/net/tmwa/charserverhandler.cpp
@@ -65,7 +65,7 @@ void CharServerHandler::chooseCharacter(Net::Character *const character)
mCharSelectDialog = nullptr;
createOutPacket(CMSG_CHAR_SELECT);
- outMsg.writeInt8(static_cast<unsigned char>(mSelectedCharacter->slot),
+ outMsg.writeInt8(CAST_U8(mSelectedCharacter->slot),
"slot");
}
@@ -80,12 +80,12 @@ void CharServerHandler::newCharacter(const std::string &name, const int slot,
createOutPacket(CMSG_CHAR_CREATE);
outMsg.writeString(name, 24, "name");
for (int i = 0; i < 6; i++)
- outMsg.writeInt8(static_cast<unsigned char>(stats[i]), "stat");
+ outMsg.writeInt8(CAST_U8(stats[i]), "stat");
- outMsg.writeInt8(static_cast<unsigned char>(slot), "slot");
- outMsg.writeInt8(static_cast<int8_t>(hairColor), "hair color");
+ outMsg.writeInt8(CAST_U8(slot), "slot");
+ outMsg.writeInt8(CAST_S8(hairColor), "hair color");
outMsg.writeInt8(0, "unused");
- outMsg.writeInt8(static_cast<int8_t>(hairstyle), "hair style");
+ outMsg.writeInt8(CAST_S8(hairstyle), "hair style");
outMsg.writeInt8(0, "unused");
}
diff --git a/src/net/tmwa/charserverrecv.cpp b/src/net/tmwa/charserverrecv.cpp
index 1861f8276..5032e4c39 100644
--- a/src/net/tmwa/charserverrecv.cpp
+++ b/src/net/tmwa/charserverrecv.cpp
@@ -145,7 +145,7 @@ void CharServerRecv::readPlayerData(Net::MessageIn &msg,
tempPlayer->setSprite(SPRITE_HEAD_MID, misc2);
character->slot = msg.readUInt8("slot");
- const uint8_t sex = static_cast<uint8_t>(msg.readUInt8("gender"));
+ const uint8_t sex = CAST_U8(msg.readUInt8("gender"));
if (serverFeatures->haveCreateCharGender())
tempPlayer->setGender(Being::intToGender(sex));
else
@@ -159,7 +159,7 @@ void CharServerRecv::processCharLogin(Net::MessageIn &msg)
msg.readInt16("len");
const int slots = msg.readInt16("slots");
if (slots > 0 && slots < 30)
- loginData.characterSlots = static_cast<uint16_t>(slots);
+ loginData.characterSlots = CAST_U16(slots);
msg.skip(18, "unused");
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index 8ac1cf2e6..61a8054ba 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -59,24 +59,24 @@ void ChatHandler::talk(const std::string &restrict text,
createOutPacket(CMSG_CHAT_MESSAGE);
// Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4 + 1), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length() + 1), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
}
void ChatHandler::talkRaw(const std::string &mes) const
{
createOutPacket(CMSG_CHAT_MESSAGE);
- outMsg.writeInt16(static_cast<int16_t>(mes.length() + 4), "len");
- outMsg.writeString(mes, static_cast<int>(mes.length()), "message");
+ outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
+ outMsg.writeString(mes, CAST_S32(mes.length()), "message");
}
void ChatHandler::privateMessage(const std::string &restrict recipient,
const std::string &restrict text)
{
createOutPacket(CMSG_CHAT_WHISPER);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 28), "len");
+ outMsg.writeInt16(CAST_S16(text.length() + 28), "len");
outMsg.writeString(recipient, 24, "recipient nick");
- outMsg.writeString(text, static_cast<int>(text.length()), "message");
+ outMsg.writeString(text, CAST_S32(text.length()), "message");
Ea::ChatRecv::mSentWhispers.push(recipient);
}
@@ -107,7 +107,7 @@ void ChatHandler::sendRaw(const std::string &args) const
if (pos != std::string::npos)
{
str = line.substr(0, pos);
- const int16_t id = static_cast<int16_t>(parseNumber(str));
+ const int16_t id = CAST_S16(parseNumber(str));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
line = line.substr(pos + 1);
@@ -115,7 +115,7 @@ void ChatHandler::sendRaw(const std::string &args) const
}
else
{
- const int16_t id = static_cast<int16_t>(parseNumber(line));
+ const int16_t id = CAST_S16(parseNumber(line));
outMsg = new MessageOut(id);
outMsg->writeInt16(id, "packet id");
delete outMsg;
@@ -145,17 +145,17 @@ void ChatHandler::processRaw(MessageOut &restrict outMsg,
{
case 'b':
{
- outMsg.writeInt8(static_cast<unsigned char>(i), "raw");
+ outMsg.writeInt8(CAST_U8(i), "raw");
break;
}
case 'w':
{
- outMsg.writeInt16(static_cast<int16_t>(i), "raw");
+ outMsg.writeInt16(CAST_S16(i), "raw");
break;
}
case 'l':
{
- outMsg.writeInt32(static_cast<int32_t>(i), "raw");
+ outMsg.writeInt32(CAST_S32(i), "raw");
break;
}
default:
diff --git a/src/net/tmwa/chatrecv.cpp b/src/net/tmwa/chatrecv.cpp
index afa8c1573..27ca74a41 100644
--- a/src/net/tmwa/chatrecv.cpp
+++ b/src/net/tmwa/chatrecv.cpp
@@ -314,7 +314,7 @@ void ChatRecv::processBeingChat(Net::MessageIn &msg)
if (being)
sender_name = being->getName();
if (sender_name.empty())
- sender_name = "?" + toString(static_cast<int>(beingId));
+ sender_name = "?" + toString(CAST_S32(beingId));
}
else if (being &&
sender_name != being->getName() &&
diff --git a/src/net/tmwa/generalrecv.cpp b/src/net/tmwa/generalrecv.cpp
index d8b0c808b..2926f0ef5 100644
--- a/src/net/tmwa/generalrecv.cpp
+++ b/src/net/tmwa/generalrecv.cpp
@@ -40,7 +40,7 @@ ServerInfo mapServer;
void GeneralRecv::processConnectionProblem(Net::MessageIn &msg)
{
const uint8_t code = msg.readUInt8("flag");
- logger->log("Connection problem: %u", static_cast<unsigned int>(code));
+ logger->log("Connection problem: %u", CAST_U32(code));
switch (code)
{
diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp
index dce3385bf..4f0db44c7 100644
--- a/src/net/tmwa/guildhandler.cpp
+++ b/src/net/tmwa/guildhandler.cpp
@@ -124,8 +124,8 @@ void GuildHandler::chat(const std::string &text) const
const std::string str = std::string(localPlayer->getName()).append(
" : ").append(text);
createOutPacket(CMSG_GUILD_MESSAGE);
- outMsg.writeInt16(static_cast<uint16_t>(str.size() + 4), "len");
- outMsg.writeString(str, static_cast<int>(str.length()), "message");
+ outMsg.writeInt16(CAST_U16(str.size() + 4), "len");
+ outMsg.writeString(str, CAST_S32(str.length()), "message");
}
void GuildHandler::memberList() const
diff --git a/src/net/tmwa/guildrecv.cpp b/src/net/tmwa/guildrecv.cpp
index 53f8aeb71..4073dd936 100644
--- a/src/net/tmwa/guildrecv.cpp
+++ b/src/net/tmwa/guildrecv.cpp
@@ -55,7 +55,7 @@ void GuildRecv::processGuildPositionInfo(Net::MessageIn &msg)
PlayerInfo::setGuildPositionFlags(GuildPositionFlags::Invite);
- Guild *const g = Guild::getGuild(static_cast<int16_t>(guildId));
+ Guild *const g = Guild::getGuild(CAST_S16(guildId));
if (!g)
return;
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index 24d76eab7..fa71484e6 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -73,7 +73,7 @@ void InventoryHandler::equipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_EQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt16(0, "unused");
}
@@ -84,7 +84,7 @@ void InventoryHandler::unequipItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
}
@@ -94,7 +94,7 @@ void InventoryHandler::useItem(const Item *const item) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_USE);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(item->getId(), "item id");
}
@@ -105,9 +105,9 @@ void InventoryHandler::dropItem(const Item *const item, const int amount) const
return;
createOutPacket(CMSG_PLAYER_INVENTORY_DROP);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void InventoryHandler::closeStorage() const
@@ -124,7 +124,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source,
destination == InventoryType::Storage)
{
createOutPacket(CMSG_MOVE_TO_STORAGE);
- outMsg.writeInt16(static_cast<int16_t>(slot + INVENTORY_OFFSET),
+ outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET),
"index");
outMsg.writeInt32(amount, "amount");
}
@@ -132,7 +132,7 @@ void InventoryHandler::moveItem2(const InventoryTypeT source,
destination == InventoryType::Inventory)
{
createOutPacket(CMSG_MOVE_FROM_STORAGE);
- outMsg.writeInt16(static_cast<int16_t>(slot + STORAGE_OFFSET),
+ outMsg.writeInt16(CAST_S16(slot + STORAGE_OFFSET),
"index");
outMsg.writeInt32(amount, "amount");
}
@@ -161,7 +161,7 @@ int InventoryHandler::convertFromServerSlot(const int serverSlot) const
if (serverSlot < 0 || serverSlot > 13)
return 0;
- return static_cast<int>(EQUIP_CONVERT[serverSlot]);
+ return CAST_S32(EQUIP_CONVERT[serverSlot]);
}
void InventoryHandler::selectCart(const BeingId accountId A_UNUSED,
diff --git a/src/net/tmwa/inventoryrecv.cpp b/src/net/tmwa/inventoryrecv.cpp
index ce59dc274..2ba71b73d 100644
--- a/src/net/tmwa/inventoryrecv.cpp
+++ b/src/net/tmwa/inventoryrecv.cpp
@@ -380,9 +380,9 @@ void InventoryRecv::processPlayerStorageEquip(Net::MessageIn &msg)
logger->log("Index: %d, ID: %d, Type: %d, Identified: %u, "
"Qty: %d, Cards: %d, %d, %d, %d, Refine: %u",
index, itemId, itemType,
- static_cast<unsigned int>(identified), amount,
+ CAST_U32(identified), amount,
cards[0], cards[1], cards[2], cards[3],
- static_cast<unsigned int>(refine));
+ CAST_U32(refine));
}
Ea::InventoryRecv::mInventoryItems.push_back(Ea::InventoryItem(
diff --git a/src/net/tmwa/itemrecv.cpp b/src/net/tmwa/itemrecv.cpp
index b9a7d55b1..d7038942d 100644
--- a/src/net/tmwa/itemrecv.cpp
+++ b/src/net/tmwa/itemrecv.cpp
@@ -38,8 +38,8 @@ void ItemRecv::processItemDropped(Net::MessageIn &msg)
const Identified identify = fromInt(msg.readUInt8("identify"), Identified);
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
const int amount = msg.readInt16("amount");
if (actorManager)
@@ -67,8 +67,8 @@ void ItemRecv::processItemVisible(Net::MessageIn &msg)
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
const int amount = msg.readInt16("amount");
- const int subX = static_cast<int>(msg.readInt8("sub x"));
- const int subY = static_cast<int>(msg.readInt8("sub y"));
+ const int subX = CAST_S32(msg.readInt8("sub x"));
+ const int subY = CAST_S32(msg.readInt8("sub y"));
if (actorManager)
{
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 21e679b25..c8cf350e7 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -56,10 +56,10 @@ uint16_t MessageIn::readId()
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
return value;
@@ -72,14 +72,14 @@ int16_t MessageIn::readInt16(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
value = SDL_Swap16(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif
}
- DEBUGLOG2("readInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("readInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
mPos += 2;
PacketCounters::incInBytes(2);
@@ -93,13 +93,13 @@ int32_t MessageIn::readInt32(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int32_t));
value = SDL_Swap32(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int32_t));
#endif
}
- DEBUGLOG2("readInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 4;
PacketCounters::incInBytes(4);
@@ -118,13 +118,13 @@ int64_t MessageIn::readInt64(const char *const str)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int64_t swap;
- memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t));
value = SDL_Swap64(swap);
#else
- memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int64_t));
+ memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t));
#endif
}
- DEBUGLOG2("readInt64: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("readInt64: " + toStringPrint(CAST_U32(value)),
mPos, str);
mPos += 8;
PacketCounters::incInBytes(8);
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index a2c0770b7..c0ac1ef03 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -40,26 +40,26 @@ MessageOut::MessageOut(const int16_t id) :
mNetwork(TmwAthena::Network::instance())
{
mNetwork->fixSendBuffer();
- mData = mNetwork->mOutBuffer + static_cast<size_t>(mNetwork->mOutSize);
+ mData = mNetwork->mOutBuffer + CAST_SIZE(mNetwork->mOutSize);
}
void MessageOut::expand(const size_t bytes)
{
- mNetwork->mOutSize += static_cast<unsigned>(bytes);
- PacketCounters::incOutBytes(static_cast<int>(bytes));
+ mNetwork->mOutSize += CAST_U32(bytes);
+ PacketCounters::incOutBytes(CAST_S32(bytes));
}
void MessageOut::writeInt16(const int16_t value, const char *const str)
{
- DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<unsigned int>(
- static_cast<uint16_t>(value))),
+ DEBUGLOG2("writeInt16: " + toStringPrint(CAST_U32(
+ CAST_U16(value))),
mPos, str);
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int16_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int16_t));
#endif
mPos += 2;
PacketCounters::incOutBytes(2);
@@ -67,14 +67,14 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
void MessageOut::writeInt32(const int32_t value, const char *const str)
{
- DEBUGLOG2("writeInt32: " + toStringPrint(static_cast<unsigned int>(value)),
+ DEBUGLOG2("writeInt32: " + toStringPrint(CAST_U32(value)),
mPos, str);
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
- memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int32_t));
#else
- memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int32_t));
+ memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int32_t));
#endif
mPos += 4;
PacketCounters::incOutBytes(4);
@@ -85,9 +85,9 @@ void MessageOut::writeBeingId(const BeingId value, const char *const str)
writeInt32(toInt(value, int32_t), str);
}
-#define LOBYTE(w) (static_cast<unsigned char>(w))
-#define HIBYTE(w) (static_cast<unsigned char>(( \
-static_cast<uint16_t>(w)) >> 8U))
+#define LOBYTE(w) (CAST_U8(w))
+#define HIBYTE(w) (CAST_U8(( \
+CAST_U16(w)) >> 8U))
void MessageOut::writeCoordinates(const uint16_t x,
const uint16_t y,
@@ -95,10 +95,10 @@ void MessageOut::writeCoordinates(const uint16_t x,
const char *const str)
{
DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u",
- static_cast<unsigned>(x), static_cast<unsigned>(y),
- static_cast<unsigned>(direction)), mPos, str);
+ CAST_U32(x), static_cast<unsigned>(y),
+ CAST_U32(direction)), mPos, str);
unsigned char *const data = reinterpret_cast<unsigned char*>(mData)
- + static_cast<size_t>(mPos);
+ + CAST_SIZE(mPos);
mNetwork->mOutSize += 3;
mPos += 3;
@@ -108,7 +108,7 @@ void MessageOut::writeCoordinates(const uint16_t x,
data[1] = 1;
data[2] = 2;
data[0] = HIBYTE(temp);
- data[1] = static_cast<unsigned char>(temp);
+ data[1] = CAST_U8(temp);
temp = y;
temp <<= 4;
data[1] |= HIBYTE(temp);
diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp
index 9be9d34b6..03a842b65 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -156,7 +156,7 @@ bool Network::messageReady()
if (mInSize >= 2)
{
const int msgId = readWord(0);
- if (msgId >= 0 && static_cast<unsigned int>(msgId)
+ if (msgId >= 0 && CAST_U32(msgId)
< packet_lengths_size)
{
len = mPackets[msgId].len;
@@ -166,7 +166,7 @@ bool Network::messageReady()
len = readWord(2);
}
- const bool ret = (mInSize >= static_cast<unsigned int>(len));
+ const bool ret = (mInSize >= CAST_U32(len));
SDL_mutexV(mMutexIn);
return ret;
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index a3e0ef2c3..ba1c8f7a3 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -100,9 +100,9 @@ void NpcHandler::stringInput(const BeingId npcId,
const std::string &value) const
{
createOutPacket(CMSG_NPC_STR_RESPONSE);
- outMsg.writeInt16(static_cast<int16_t>(value.length() + 9), "len");
+ outMsg.writeInt16(CAST_S16(value.length() + 9), "len");
outMsg.writeBeingId(npcId, "npc id");
- outMsg.writeString(value, static_cast<int>(value.length()), "value");
+ outMsg.writeString(value, CAST_S32(value.length()), "value");
outMsg.writeInt8(0, "null byte");
}
@@ -127,8 +127,8 @@ void NpcHandler::buyItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_BUY_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
- outMsg.writeInt16(static_cast<int16_t>(itemId), "item id");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
+ outMsg.writeInt16(CAST_S16(itemId), "item id");
}
void NpcHandler::buyItems(std::vector<ShopItem*> &items A_UNUSED) const
@@ -141,9 +141,9 @@ void NpcHandler::sellItem(const BeingId beingId A_UNUSED,
{
createOutPacket(CMSG_NPC_SELL_REQUEST);
outMsg.writeInt16(8, "len");
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
itemId + INVENTORY_OFFSET), "index");
- outMsg.writeInt16(static_cast<int16_t>(amount), "amount");
+ outMsg.writeInt16(CAST_S16(amount), "amount");
}
void NpcHandler::sellItems(std::vector<ShopItem*> &items A_UNUSED) const
diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp
index 8c477e9ec..94471e4c3 100644
--- a/src/net/tmwa/partyhandler.cpp
+++ b/src/net/tmwa/partyhandler.cpp
@@ -117,8 +117,8 @@ void PartyHandler::kick(const std::string &name) const
void PartyHandler::chat(const std::string &text) const
{
createOutPacket(CMSG_PARTY_MESSAGE);
- outMsg.writeInt16(static_cast<int16_t>(text.length() + 4), "len");
- outMsg.writeString(text, static_cast<int>(text.length()), "text");
+ outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
+ outMsg.writeString(text, CAST_S32(text.length()), "text");
}
void PartyHandler::setShareExperience(const PartyShareT share) const
@@ -127,8 +127,8 @@ void PartyHandler::setShareExperience(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(share), "share exp");
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareItems),
+ outMsg.writeInt16(CAST_S16(share), "share exp");
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems),
"share items");
}
@@ -138,9 +138,9 @@ void PartyHandler::setShareItems(const PartyShareT share) const
return;
createOutPacket(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(static_cast<int16_t>(Ea::PartyRecv::mShareExp),
+ outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareExp),
"share exp");
- outMsg.writeInt16(static_cast<int16_t>(share), "share items");
+ outMsg.writeInt16(CAST_S16(share), "share items");
}
void PartyHandler::changeLeader(const std::string &name A_UNUSED) const
diff --git a/src/net/tmwa/pethandler.cpp b/src/net/tmwa/pethandler.cpp
index 427ec3ba9..1aaf0e710 100644
--- a/src/net/tmwa/pethandler.cpp
+++ b/src/net/tmwa/pethandler.cpp
@@ -60,7 +60,7 @@ void PetHandler::emote(const uint8_t emoteId, const int petId A_UNUSED)
mRandCounter = 1000;
chatHandler->talk(strprintf("\302\202\302e%dz%d",
- static_cast<int>(emoteId), mRandCounter), GENERAL_CHANNEL);
+ CAST_S32(emoteId), mRandCounter), GENERAL_CHANNEL);
}
void PetHandler::catchPet(const Being *const being A_UNUSED) const
@@ -98,7 +98,7 @@ void PetHandler::unequip() const
void PetHandler::setDirection(const unsigned char type) const
{
chatHandler->talk(strprintf("\302\202\302d%dg%d",
- static_cast<int>(type), tick_time), GENERAL_CHANNEL);
+ CAST_S32(type), tick_time), GENERAL_CHANNEL);
}
void PetHandler::startAi(const bool start) const
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index f0ea94947..8f7de1e64 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -70,7 +70,7 @@ void PlayerHandler::increaseAttribute(const AttributesT attr) const
if (attr >= Attributes::STR && attr <= Attributes::LUK)
{
createOutPacket(CMSG_STAT_UPDATE_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(attr), "attribute id");
+ outMsg.writeInt16(CAST_S16(attr), "attribute id");
outMsg.writeInt8(1, "increment");
}
}
@@ -108,9 +108,9 @@ void PlayerHandler::setDestination(const int x, const int y,
const int direction) const
{
createOutPacket(CMSG_PLAYER_CHANGE_DEST);
- outMsg.writeCoordinates(static_cast<uint16_t>(x),
- static_cast<uint16_t>(y),
- static_cast<unsigned char>(direction), "destination");
+ outMsg.writeCoordinates(CAST_U16(x),
+ CAST_U16(y),
+ CAST_U8(direction), "destination");
}
void PlayerHandler::changeAction(const BeingActionT &action) const
diff --git a/src/net/tmwa/skillhandler.cpp b/src/net/tmwa/skillhandler.cpp
index abd2fd67e..87dc0e189 100644
--- a/src/net/tmwa/skillhandler.cpp
+++ b/src/net/tmwa/skillhandler.cpp
@@ -42,8 +42,8 @@ void SkillHandler::useBeing(const int id, const int level,
const BeingId beingId) const
{
createOutPacket(CMSG_SKILL_USE_BEING);
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(level), "level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(level), "level");
outMsg.writeBeingId(beingId, "target id");
}
@@ -51,10 +51,10 @@ void SkillHandler::usePos(const int id, const int level,
const int x, const int y) const
{
createOutPacket(CMSG_SKILL_USE_POSITION);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
}
void SkillHandler::usePos(const int id, const int level,
@@ -62,17 +62,17 @@ void SkillHandler::usePos(const int id, const int level,
const std::string &text) const
{
createOutPacket(CMSG_SKILL_USE_POSITION_MORE);
- outMsg.writeInt16(static_cast<int16_t>(level), "skill level");
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
- outMsg.writeInt16(static_cast<int16_t>(x), "x");
- outMsg.writeInt16(static_cast<int16_t>(y), "y");
+ outMsg.writeInt16(CAST_S16(level), "skill level");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
+ outMsg.writeInt16(CAST_S16(x), "x");
+ outMsg.writeInt16(CAST_S16(y), "y");
outMsg.writeString(text, 80, "text");
}
void SkillHandler::useMap(const int id, const std::string &map) const
{
createOutPacket(CMSG_SKILL_USE_MAP);
- outMsg.writeInt16(static_cast<int16_t>(id), "skill id");
+ outMsg.writeInt16(CAST_S16(id), "skill id");
outMsg.writeString(map, 16, "map name");
}
diff --git a/src/net/tmwa/skillrecv.cpp b/src/net/tmwa/skillrecv.cpp
index d79f36422..df914568b 100644
--- a/src/net/tmwa/skillrecv.cpp
+++ b/src/net/tmwa/skillrecv.cpp
@@ -89,19 +89,19 @@ void SkillRecv::processSkillFailed(Net::MessageIn &msg)
msg.readInt16("btype");
const signed char success = msg.readUInt8("success");
const signed char reason = msg.readUInt8("reason");
- if (success != static_cast<int>(SKILL_FAILED)
- && bskill == static_cast<int>(BSKILL_EMOTE))
+ if (success != CAST_S32(SKILL_FAILED)
+ && bskill == CAST_S32(BSKILL_EMOTE))
{
logger->log("Action: %d/%d", bskill, success);
}
std::string txt;
- if (success == static_cast<int>(SKILL_FAILED)
- && skillId == static_cast<int>(SKILL_BASIC))
+ if (success == CAST_S32(SKILL_FAILED)
+ && skillId == CAST_S32(SKILL_BASIC))
{
if (localPlayer &&
- bskill == static_cast<int>(BSKILL_EMOTE) &&
- reason == static_cast<int>(RFAIL_SKILLDEP))
+ bskill == CAST_S32(BSKILL_EMOTE) &&
+ reason == CAST_S32(RFAIL_SKILLDEP))
{
localPlayer->stopAdvert();
}
diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp
index 40f737d22..66865740e 100644
--- a/src/net/tmwa/tradehandler.cpp
+++ b/src/net/tmwa/tradehandler.cpp
@@ -61,7 +61,7 @@ void TradeHandler::respond(const bool accept) const
PlayerInfo::setTrading(Trading_false);
createOutPacket(CMSG_TRADE_RESPONSE);
- outMsg.writeInt8(static_cast<int8_t>(accept ? 3 : 4), "accept");
+ outMsg.writeInt8(CAST_S8(accept ? 3 : 4), "accept");
}
void TradeHandler::addItem(const Item *const item, const int amount) const
@@ -70,7 +70,7 @@ void TradeHandler::addItem(const Item *const item, const int amount) const
return;
createOutPacket(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeInt16(static_cast<int16_t>(
+ outMsg.writeInt16(CAST_S16(
item->getInvIndex() + INVENTORY_OFFSET), "index");
outMsg.writeInt32(amount, "amount");
}
diff --git a/src/net/updatetypeoperators.cpp b/src/net/updatetypeoperators.cpp
index 0a2444b99..1fad95ff9 100644
--- a/src/net/updatetypeoperators.cpp
+++ b/src/net/updatetypeoperators.cpp
@@ -24,15 +24,15 @@
int operator&(const UpdateTypeT &a, const UpdateTypeT &b)
{
- return static_cast<int>(a) & static_cast<int>(b);
+ return CAST_S32(a) & CAST_S32(b);
}
int operator|(const UpdateTypeT &a, const UpdateTypeT &b)
{
- return static_cast<int>(a) | static_cast<int>(b);
+ return CAST_S32(a) | CAST_S32(b);
}
int operator|(const int &a, const UpdateTypeT &b)
{
- return a | static_cast<int>(b);
+ return a | CAST_S32(b);
}