Encrypt own cards which are sent at the beginning of the hand - only applicable to registered users.

This commit is contained in:
lotodore
2010-09-04 11:56:40 +00:00
parent daf99deac3
commit c2ba56aba9
89 changed files with 675 additions and 285 deletions
+36 -2
View File
@@ -1684,8 +1684,42 @@ ClientStateWaitHand::InternalHandlePacket(boost::shared_ptr<ClientThread> client
// These are the cards. Good luck.
HandStartMessage_t *netHandStart = &tmpPacket->GetMsg()->choice.handStartMessage;
int myCards[2];
myCards[0] = (int)netHandStart->yourCard1;
myCards[1] = (int)netHandStart->yourCard2;
string userPassword(client->GetContext().GetPassword());
if (netHandStart->yourCards.present == yourCards_PR_plainCards
&& userPassword.empty())
{
PlainCards_t *plainCards = &netHandStart->yourCards.choice.plainCards;
myCards[0] = (int)plainCards->plainCard1;
myCards[1] = (int)plainCards->plainCard2;
}
else if (netHandStart->yourCards.present == yourCards_PR_encryptedCards
&& !userPassword.empty())
{
EncryptedCards_t *encryptedCards = &netHandStart->yourCards.choice.encryptedCards;
string plainCards;
if (!CryptHelper::AES128Decrypt((const unsigned char *)userPassword.c_str(),
(unsigned)userPassword.size(),
encryptedCards->encryptedCards.buf,
encryptedCards->encryptedCards.size,
plainCards))
{
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
}
istringstream cardDataStream(plainCards);
unsigned tmpPlayerId, tmpGameId;
int tmpHandNum;
cardDataStream >> tmpPlayerId;
cardDataStream >> tmpGameId;
cardDataStream >> tmpHandNum;
if (tmpPlayerId != client->GetGuiPlayerId()
|| tmpGameId != client->GetGameId()
|| tmpHandNum != client->GetGame()->getCurrentHandID())
{
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
}
cardDataStream >> myCards[0];
cardDataStream >> myCards[1];
}
client->GetGame()->getSeatsList()->front()->setMyCards(myCards);
client->GetGame()->initHand();
client->GetGame()->getCurrentHand()->setSmallBlind(netHandStart->smallBlind);