[Client] Ignore invalid player class IDs from packets

Additionally, clean up variables names in related code.
0.6.2
David Cernat 7 years ago
parent c6874509b6
commit ace825b99c

@ -933,6 +933,8 @@ void LocalPlayer::setCell()
void LocalPlayer::setClass() void LocalPlayer::setClass()
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_CLASS from server");
if (charClass.mId.empty()) // custom class if (charClass.mId.empty()) // custom class
{ {
charClass.mData.mIsPlayable = 0x1; charClass.mData.mIsPlayable = 0x1;
@ -941,12 +943,15 @@ void LocalPlayer::setClass()
} }
else else
{ {
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(charClass.mId); const ESM::Class *existingCharClass = MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().search(charClass.mId);
const ESM::Class *existingCharClass = MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find(charClass.mId);
if (existingCharClass) if (existingCharClass)
{
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(charClass.mId);
MWBase::Environment::get().getWindowManager()->setPlayerClass(charClass); MWBase::Environment::get().getWindowManager()->setPlayerClass(charClass);
}
else
LOG_APPEND(Log::LOG_INFO, "- Ignored invalid default class %s", charClass.mId.c_str());
} }
} }
@ -1175,18 +1180,18 @@ void LocalPlayer::setShapeshift()
void LocalPlayer::sendClass() void LocalPlayer::sendClass()
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
const ESM::NPC *cpl = world->getPlayerPtr().get<ESM::NPC>()->mBase; const ESM::NPC *npcBase = world->getPlayerPtr().get<ESM::NPC>()->mBase;
const ESM::Class *cls = world->getStore().get<ESM::Class>().find(cpl->mClass); const ESM::Class *esmClass = world->getStore().get<ESM::Class>().find(npcBase->mClass);
if (cpl->mClass.find("$dynamic") != string::npos) // custom class if (npcBase->mClass.find("$dynamic") != string::npos) // custom class
{ {
charClass.mId = ""; charClass.mId = "";
charClass.mName = cls->mName; charClass.mName = esmClass->mName;
charClass.mDescription = cls->mDescription; charClass.mDescription = esmClass->mDescription;
charClass.mData = cls->mData; charClass.mData = esmClass->mData;
} }
else else
charClass.mId = cls->mId; charClass.mId = esmClass->mId;
getNetworking()->getPlayerPacket(ID_PLAYER_CHARCLASS)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_CHARCLASS)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_CHARCLASS)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_CHARCLASS)->Send();

Loading…
Cancel
Save