Merge pull request #1217 from ZeldaZach/fix_cheat

Prevent Hash Collision
This commit is contained in:
Zach 2015-07-06 23:49:48 -04:00
commit e76c109f2d

View file

@ -726,12 +726,27 @@ bool DeckList::deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNod
void DeckList::updateDeckHash() void DeckList::updateDeckHash()
{ {
QStringList cardList; QStringList cardList;
for (int i = 0; i < root->size(); i++) { bool isValidDeckList = true;
QSet<QString> hashZones, optionalZones;
hashZones << "main" << "side"; // Zones in deck to be included in hashing process
optionalZones << "tokens"; // Optional zones in deck not included in hashing process
for (int i = 0; i < root->size(); i++)
{
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i)); InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
for (int j = 0; j < node->size(); j++) { for (int j = 0; j < node->size(); j++)
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j)); {
for (int k = 0; k < card->getNumber(); ++k) if (hashZones.contains(node->getName())) // Mainboard or Sideboard
cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower()); {
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
for (int k = 0; k < card->getNumber(); ++k)
cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower());
}
else if (!optionalZones.contains(node->getName())) // Not a valid zone -> cheater?
{
isValidDeckList = false; // Deck is invalid
}
} }
} }
cardList.sort(); cardList.sort();
@ -741,7 +756,7 @@ void DeckList::updateDeckHash()
+ (((quint64) (unsigned char) deckHashArray[2] << 16)) + (((quint64) (unsigned char) deckHashArray[2] << 16))
+ (((quint64) (unsigned char) deckHashArray[3]) << 8) + (((quint64) (unsigned char) deckHashArray[3]) << 8)
+ (quint64) (unsigned char) deckHashArray[4]; + (quint64) (unsigned char) deckHashArray[4];
deckHash = QString::number(number, 32).rightJustified(8, '0'); deckHash = (isValidDeckList) ? QString::number(number, 32).rightJustified(8, '0') : "INVALID";
emit deckHashChanged(); emit deckHashChanged();
} }