Skip to content
Browse files

Core/Misc: Remove some calls to const_cast

  • Loading branch information...
1 parent 0281497 commit fa5dd4bd4e58c13229bcfb8e6bf879838de47e60 @Spp- Spp- committed Jan 30, 2013
View
4 src/server/game/Battlefield/Battlefield.cpp
@@ -816,7 +816,7 @@ Creature* Battlefield::SpawnCreature(uint32 entry, Position pos, TeamId team)
Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId team)
{
//Get map object
- Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(m_MapId));
+ Map* map = sMapMgr->CreateBaseMap(m_MapId);
if (!map)
{
sLog->outError(LOG_FILTER_BATTLEFIELD, "Battlefield::SpawnCreature: Can't create creature entry: %u map not found", entry);
@@ -854,7 +854,7 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z, float o)
{
// Get map object
- Map* map = const_cast<Map*>(sMapMgr->CreateBaseMap(571)); // *vomits*
+ Map* map = sMapMgr->CreateBaseMap(571); // *vomits*
if (!map)
return 0;
View
28 src/server/game/Handlers/AddonHandler.cpp
@@ -30,32 +30,32 @@ AddonHandler::~AddonHandler()
{
}
-bool AddonHandler::BuildAddonPacket(WorldPacket* Source, WorldPacket* Target)
+bool AddonHandler::BuildAddonPacket(WorldPacket* source, WorldPacket* target)
{
ByteBuffer AddOnPacked;
uLongf AddonRealSize;
uint32 CurrentPosition;
uint32 TempValue;
// broken addon packet, can't be received from real client
- if (Source->rpos() + 4 > Source->size())
+ if (source->rpos() + 4 > source->size())
return false;
- *Source >> TempValue; // get real size of the packed structure
+ *source >> TempValue; // get real size of the packed structure
// empty addon packet, nothing process, can't be received from real client
if (!TempValue)
return false;
AddonRealSize = TempValue; // temp value because ZLIB only excepts uLongf
- CurrentPosition = Source->rpos(); // get the position of the pointer in the structure
+ CurrentPosition = source->rpos(); // get the position of the pointer in the structure
AddOnPacked.resize(AddonRealSize); // resize target for zlib action
- if (!uncompress(const_cast<uint8*>(AddOnPacked.contents()), &AddonRealSize, const_cast<uint8*>((*Source).contents() + CurrentPosition), (*Source).size() - CurrentPosition)!= Z_OK)
+ if (!uncompress(AddOnPacked.contents(), &AddonRealSize, source->contents() + CurrentPosition, source->size() - CurrentPosition)!= Z_OK)
{
- Target->Initialize(SMSG_ADDON_INFO);
+ target->Initialize(SMSG_ADDON_INFO);
uint32 addonsCount;
AddOnPacked >> addonsCount; // addons count?
@@ -81,14 +81,14 @@ bool AddonHandler::BuildAddonPacket(WorldPacket* Source, WorldPacket* Target)
sLog->outDebug(LOG_FILTER_NETWORKIO, "ADDON: Name: %s, Enabled: 0x%x, CRC: 0x%x, Unknown2: 0x%x", addonName.c_str(), enabled, crc, unk2);
uint8 state = (enabled ? 2 : 1);
- *Target << uint8(state);
+ *target << uint8(state);
uint8 unk1 = (enabled ? 1 : 0);
- *Target << uint8(unk1);
+ *target << uint8(unk1);
if (unk1)
{
uint8 unk = (crc != 0x4c1c776d); // If addon is Standard addon CRC
- *Target << uint8(unk);
+ *target << uint8(unk);
if (unk)
{
unsigned char tdata[256] =
@@ -110,26 +110,26 @@ bool AddonHandler::BuildAddonPacket(WorldPacket* Source, WorldPacket* Target)
0xC3, 0xFB, 0x1B, 0x8C, 0x29, 0xEF, 0x8E, 0xE5, 0x34, 0xCB, 0xD1, 0x2A, 0xCE, 0x79, 0xC3, 0x9A,
0x0D, 0x36, 0xEA, 0x01, 0xE0, 0xAA, 0x91, 0x20, 0x54, 0xF0, 0x72, 0xD8, 0x1E, 0xC7, 0x89, 0xD2
};
- Target->append(tdata, sizeof(tdata));
+ target->append(tdata, sizeof(tdata));
}
- *Target << uint32(0);
+ *target << uint32(0);
}
uint8 unk3 = (enabled ? 0 : 1);
- *Target << uint8(unk3);
+ *target << uint8(unk3);
if (unk3)
{
// String, 256 (null terminated?)
- *Target << uint8(0);
+ *target << uint8(0);
}
}
uint32 unk4;
AddOnPacked >> unk4;
uint32 count = 0;
- *Target << uint32(count);
+ *target << uint32(count);
if (AddOnPacked.rpos() != AddOnPacked.size())
sLog->outDebug(LOG_FILTER_NETWORKIO, "packet under read!");
View
4 src/server/game/Handlers/MiscHandler.cpp
@@ -976,7 +976,7 @@ void WorldSession::HandleUpdateAccountData(WorldPacket& recvData)
dest.resize(decompressedSize);
uLongf realSize = decompressedSize;
- if (uncompress(const_cast<uint8*>(dest.contents()), &realSize, const_cast<uint8*>(recvData.contents() + recvData.rpos()), recvData.size() - recvData.rpos()) != Z_OK)
+ if (uncompress(dest.contents(), &realSize, recvData.contents() + recvData.rpos(), recvData.size() - recvData.rpos()) != Z_OK)
{
recvData.rfinish(); // unnneded warning spam in this case
sLog->outError(LOG_FILTER_NETWORKIO, "UAD: Failed to decompress account data");
@@ -1017,7 +1017,7 @@ void WorldSession::HandleRequestAccountData(WorldPacket& recvData)
ByteBuffer dest;
dest.resize(destSize);
- if (size && compress(const_cast<uint8*>(dest.contents()), &destSize, (uint8*)adata->Data.c_str(), size) != Z_OK)
+ if (size && compress(dest.contents(), &destSize, (uint8 const*)adata->Data.c_str(), size) != Z_OK)
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "RAD: Failed to compress account data");
return;
View
2 src/server/game/Handlers/TicketHandler.cpp
@@ -69,7 +69,7 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData)
dest.resize(decompressedSize);
uLongf realSize = decompressedSize;
- if (uncompress(const_cast<uint8*>(dest.contents()), &realSize, const_cast<uint8*>(recvData.contents() + pos), recvData.size() - pos) == Z_OK)
+ if (uncompress(dest.contents(), &realSize, recvData.contents() + pos, recvData.size() - pos) == Z_OK)
{
dest >> chatLog;
ticket->SetChatLog(times, chatLog);
View
2 src/server/game/Server/Protocol/PacketLog.cpp
@@ -55,7 +55,7 @@ void PacketLog::LogPacket(WorldPacket const& packet, Direction direction)
data << uint8(direction);
for (uint32 i = 0; i < packet.size(); i++)
- data << const_cast<WorldPacket&>(packet)[i];
+ data << packet[i];
fwrite(data.contents(), 1, data.size(), _file);
fflush(_file);
View
2 src/server/game/Server/WorldSession.cpp
@@ -961,7 +961,7 @@ void WorldSession::ReadAddonsInfo(WorldPacket &data)
ByteBuffer addonInfo;
addonInfo.resize(size);
- if (uncompress(const_cast<uint8*>(addonInfo.contents()), &uSize, const_cast<uint8*>(data.contents() + pos), data.size() - pos) == Z_OK)
+ if (uncompress(addonInfo.contents(), &uSize, data.contents() + pos, data.size() - pos) == Z_OK)
{
uint32 addonsCount;
addonInfo >> addonsCount; // addons count
View
20 src/server/game/Spells/Auras/SpellAuraEffects.cpp
@@ -488,7 +488,7 @@ int32 AuraEffect::CalculateAmount(Unit* caster)
break;
}
- GetBase()->CallScriptEffectCalcAmountHandlers(const_cast<AuraEffect const*>(this), amount, m_canBeRecalculated);
+ GetBase()->CallScriptEffectCalcAmountHandlers(this, amount, m_canBeRecalculated);
amount *= GetBase()->GetStackAmount();
return amount;
}
@@ -522,7 +522,7 @@ void AuraEffect::CalculatePeriodic(Unit* caster, bool create, bool load)
break;
}
- GetBase()->CallScriptEffectCalcPeriodicHandlers(const_cast<AuraEffect const*>(this), m_isPeriodic, m_amplitude);
+ GetBase()->CallScriptEffectCalcPeriodicHandlers(this, m_isPeriodic, m_amplitude);
if (!m_isPeriodic)
return;
@@ -598,7 +598,7 @@ void AuraEffect::CalculateSpellMod()
default:
break;
}
- GetBase()->CallScriptEffectCalcSpellModHandlers(const_cast<AuraEffect const*>(this), m_spellmod);
+ GetBase()->CallScriptEffectCalcSpellModHandlers(this, m_spellmod);
}
void AuraEffect::ChangeAmount(int32 newAmount, bool mark, bool onStackOrReapply)
@@ -657,25 +657,25 @@ void AuraEffect::HandleEffect(AuraApplication * aurApp, uint8 mode, bool apply)
// call scripts helping/replacing effect handlers
bool prevented = false;
if (apply)
- prevented = GetBase()->CallScriptEffectApplyHandlers(const_cast<AuraEffect const*>(this), const_cast<AuraApplication const*>(aurApp), (AuraEffectHandleModes)mode);
+ prevented = GetBase()->CallScriptEffectApplyHandlers(this, aurApp, (AuraEffectHandleModes)mode);
else
- prevented = GetBase()->CallScriptEffectRemoveHandlers(const_cast<AuraEffect const*>(this), const_cast<AuraApplication const*>(aurApp), (AuraEffectHandleModes)mode);
+ prevented = GetBase()->CallScriptEffectRemoveHandlers(this, aurApp, (AuraEffectHandleModes)mode);
// check if script events have removed the aura or if default effect prevention was requested
if ((apply && aurApp->GetRemoveMode()) || prevented)
return;
- (*this.*AuraEffectHandler [GetAuraType()])(const_cast<AuraApplication const*>(aurApp), mode, apply);
+ (*this.*AuraEffectHandler[GetAuraType()])(aurApp, mode, apply);
// check if script events have removed the aura or if default effect prevention was requested
if (apply && aurApp->GetRemoveMode())
return;
// call scripts triggering additional events after apply/remove
if (apply)
- GetBase()->CallScriptAfterEffectApplyHandlers(const_cast<AuraEffect const*>(this), const_cast<AuraApplication const*>(aurApp), (AuraEffectHandleModes)mode);
+ GetBase()->CallScriptAfterEffectApplyHandlers(this, aurApp, (AuraEffectHandleModes)mode);
else
- GetBase()->CallScriptAfterEffectRemoveHandlers(const_cast<AuraEffect const*>(this), const_cast<AuraApplication const*>(aurApp), (AuraEffectHandleModes)mode);
+ GetBase()->CallScriptAfterEffectRemoveHandlers(this, aurApp, (AuraEffectHandleModes)mode);
}
void AuraEffect::HandleEffect(Unit* target, uint8 mode, bool apply)
@@ -980,7 +980,7 @@ void AuraEffect::PeriodicTick(AuraApplication * aurApp, Unit* caster) const
void AuraEffect::HandleProc(AuraApplication* aurApp, ProcEventInfo& eventInfo)
{
- bool prevented = GetBase()->CallScriptEffectProcHandlers(const_cast<AuraEffect const*>(this), const_cast<AuraApplication const*>(aurApp), eventInfo);
+ bool prevented = GetBase()->CallScriptEffectProcHandlers(this, aurApp, eventInfo);
if (prevented)
return;
@@ -1005,7 +1005,7 @@ void AuraEffect::HandleProc(AuraApplication* aurApp, ProcEventInfo& eventInfo)
break;
}
- GetBase()->CallScriptAfterEffectProcHandlers(const_cast<AuraEffect const*>(this), const_cast<AuraApplication const*>(aurApp), eventInfo);
+ GetBase()->CallScriptAfterEffectProcHandlers(this, aurApp, eventInfo);
}
void AuraEffect::CleanupTriggeredSpells(Unit* target)
View
4 src/server/game/Spells/Auras/SpellAuras.cpp
@@ -2048,14 +2048,14 @@ float Aura::CalcProcChance(SpellProcEntry const& procEntry, ProcEventInfo& event
void Aura::TriggerProcOnEvent(AuraApplication* aurApp, ProcEventInfo& eventInfo)
{
- CallScriptProcHandlers(const_cast<AuraApplication const*>(aurApp), eventInfo);
+ CallScriptProcHandlers(aurApp, eventInfo);
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
if (aurApp->HasEffect(i))
// OnEffectProc / AfterEffectProc hooks handled in AuraEffect::HandleProc()
GetEffect(i)->HandleProc(aurApp, eventInfo);
- CallScriptAfterProcHandlers(const_cast<AuraApplication const*>(aurApp), eventInfo);
+ CallScriptAfterProcHandlers(aurApp, eventInfo);
// Remove aura if we've used last charge to proc
if (IsUsingCharges() && !GetCharges())
View
2 src/server/game/Warden/Warden.cpp
@@ -219,7 +219,7 @@ std::string Warden::Penalty(WardenCheck* check /*= NULL*/)
void WorldSession::HandleWardenDataOpcode(WorldPacket& recvData)
{
- _warden->DecryptData(const_cast<uint8*>(recvData.contents()), recvData.size());
+ _warden->DecryptData(recvData.contents(), recvData.size());
uint8 opcode;
recvData >> opcode;
sLog->outDebug(LOG_FILTER_WARDEN, "Got packet, opcode %02X, size %u", opcode, uint32(recvData.size()));
View
2 src/server/game/Warden/WardenMac.cpp
@@ -206,7 +206,7 @@ void WardenMac::RequestData()
buff.hexlike();
// Encrypt with warden RC4 key.
- EncryptData(const_cast<uint8*>(buff.contents()), buff.size());
+ EncryptData(buff.contents(), buff.size());
WorldPacket pkt(SMSG_WARDEN_DATA, buff.size());
pkt.append(buff);
View
2 src/server/game/Warden/WardenWin.cpp
@@ -310,7 +310,7 @@ void WardenWin::RequestData()
buff.hexlike();
// Encrypt with warden RC4 key
- EncryptData(const_cast<uint8*>(buff.contents()), buff.size());
+ EncryptData(buff.contents(), buff.size());
WorldPacket pkt(SMSG_WARDEN_DATA, buff.size());
pkt.append(buff);
View
2 src/server/scripts/Kalimdor/CavernsOfTime/DarkPortal/instance_dark_portal.cpp
@@ -122,7 +122,7 @@ class instance_dark_portal : public InstanceMapScript
bool IsEncounterInProgress() const
{
- if (const_cast<instance_dark_portal_InstanceMapScript*>(this)->GetData(TYPE_MEDIVH) == IN_PROGRESS)
+ if (GetData(TYPE_MEDIVH) == IN_PROGRESS)
return true;
return false;
View
4 src/server/shared/Logging/AppenderFile.cpp
@@ -20,12 +20,12 @@
AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, const char* _filename, const char* _logDir, const char* _mode, AppenderFlags _flags, uint64 fileSize):
Appender(id, name, APPENDER_FILE, level, _flags),
+ logfile(NULL),
filename(_filename),
logDir(_logDir),
mode(_mode),
maxFileSize(fileSize),
- fileSize(0),
- logfile(NULL)
+ fileSize(0)
{
dynamicName = std::string::npos != filename.find("%s");
backup = _flags & APPENDER_FLAGS_MAKE_FILE_BACKUP;
View
2 src/server/shared/Packets/ByteBuffer.h
@@ -381,6 +381,8 @@ class ByteBuffer
return *this;
}
+ uint8 * contents() { return &_storage[0]; }
+
const uint8 *contents() const { return &_storage[0]; }
size_t size() const { return _storage.size(); }
View
3 src/server/worldserver/RemoteAccess/RASocket.cpp
@@ -388,7 +388,8 @@ void RASocket::zprint(void* callbackArg, const char * szText)
ACE_Message_Block* mb = new ACE_Message_Block(sz);
mb->copy(szText, sz);
- if (socket->putq(mb, const_cast<ACE_Time_Value*>(&ACE_Time_Value::zero)) == -1)
+ ACE_Time_Value tv = ACE_Time_Value::zero;
+ if (socket->putq(mb, &tv) == -1)
{
sLog->outDebug(LOG_FILTER_REMOTECOMMAND, "Failed to enqueue message, queue is full or closed. Error is %s", ACE_OS::strerror(errno));
mb->release();

0 comments on commit fa5dd4b

Please sign in to comment.
Something went wrong with that request. Please try again.