From ef268d79c39aa49af98d4969e9847d46cc3978f4 Mon Sep 17 00:00:00 2001 From: Zach H Date: Mon, 6 Jul 2015 00:22:31 -0400 Subject: [PATCH 1/4] prevent cheating with hashes --- common/decklist.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/common/decklist.cpp b/common/decklist.cpp index 3bf61927d..e35f8e626 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -726,12 +726,25 @@ bool DeckList::deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNod void DeckList::updateDeckHash() { QStringList cardList; - for (int i = 0; i < root->size(); i++) { + bool isValidDeckList = true; + for (int i = 0; i < root->size(); i++) + { InnerDecklistNode *node = dynamic_cast(root->at(i)); - for (int j = 0; j < node->size(); j++) { + for (int j = 0; j < node->size(); j++) + { DecklistCardNode *card = dynamic_cast(node->at(j)); for (int k = 0; k < card->getNumber(); ++k) - cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower()); + { + if (node->getName() == "main" || node->getName() == "side") // Mainboard or Sideboard + { + cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower()); + } + else if (node->getName() != "tokens") // Neither Mainboard, Sideboard, or Tokens... cheater? + { + isValidDeckList = false; + break; break; break; // Deck is invalid, end the entire check + } + } } } cardList.sort(); @@ -741,7 +754,7 @@ void DeckList::updateDeckHash() + (((quint64) (unsigned char) deckHashArray[2] << 16)) + (((quint64) (unsigned char) deckHashArray[3]) << 8) + (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(); } From 8e4f0c50af2ac2a28fc6d1b238c31a7bd18bc43e Mon Sep 17 00:00:00 2001 From: Zach H Date: Mon, 6 Jul 2015 01:31:24 -0400 Subject: [PATCH 2/4] remove breaks --- common/decklist.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/decklist.cpp b/common/decklist.cpp index e35f8e626..1287bd69d 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -741,8 +741,7 @@ void DeckList::updateDeckHash() } else if (node->getName() != "tokens") // Neither Mainboard, Sideboard, or Tokens... cheater? { - isValidDeckList = false; - break; break; break; // Deck is invalid, end the entire check + isValidDeckList = false; // Deck is invalid } } } From 9e2da24629f400435db7df4ea2a76cf07d812b6b Mon Sep 17 00:00:00 2001 From: Zach H Date: Mon, 6 Jul 2015 08:59:40 -0400 Subject: [PATCH 3/4] use QSet for zones --- common/decklist.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/decklist.cpp b/common/decklist.cpp index 1287bd69d..3c54449e2 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -727,6 +727,11 @@ void DeckList::updateDeckHash() { QStringList cardList; bool isValidDeckList = true; + static QSet 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(root->at(i)); @@ -735,11 +740,11 @@ void DeckList::updateDeckHash() DecklistCardNode *card = dynamic_cast(node->at(j)); for (int k = 0; k < card->getNumber(); ++k) { - if (node->getName() == "main" || node->getName() == "side") // Mainboard or Sideboard + if (hashZones.contains(node->getName())) // Mainboard or Sideboard { cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower()); } - else if (node->getName() != "tokens") // Neither Mainboard, Sideboard, or Tokens... cheater? + else if (!optionalZones.contains(node->getName())) // Not a valid zone -> cheater? { isValidDeckList = false; // Deck is invalid } From 339db24b56ab7a6b49c074d222a372a9633e1b69 Mon Sep 17 00:00:00 2001 From: Zach H Date: Mon, 6 Jul 2015 11:33:46 -0400 Subject: [PATCH 4/4] efficency loop --- common/decklist.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/common/decklist.cpp b/common/decklist.cpp index 3c54449e2..478ffb282 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -727,7 +727,7 @@ void DeckList::updateDeckHash() { QStringList cardList; bool isValidDeckList = true; - static QSet hashZones, optionalZones; + QSet 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 @@ -737,17 +737,15 @@ void DeckList::updateDeckHash() InnerDecklistNode *node = dynamic_cast(root->at(i)); for (int j = 0; j < node->size(); j++) { - DecklistCardNode *card = dynamic_cast(node->at(j)); - for (int k = 0; k < card->getNumber(); ++k) + if (hashZones.contains(node->getName())) // Mainboard or Sideboard { - if (hashZones.contains(node->getName())) // Mainboard or Sideboard - { + DecklistCardNode *card = dynamic_cast(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 - } + } + else if (!optionalZones.contains(node->getName())) // Not a valid zone -> cheater? + { + isValidDeckList = false; // Deck is invalid } } }