stoneharry

Untitled

May 31st, 2014
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1.     else if (first.compare("SelectTalents") == 0)
  2.     {
  3.         if (second.length() < 8)
  4.             return;
  5.         int perks[4];
  6.         std::string talents[4];
  7.         // retrieve talents
  8.         talents[0] = second.substr(0, 2);
  9.         talents[1] = second.substr(2, 2);
  10.         talents[2] = second.substr(4, 2);
  11.         talents[3] = second.substr(6, 2);
  12.         for (int i = 0; i < 4; ++i)
  13.         {
  14.             // verify them
  15.             if (!isdigit(talents[i][0]) || !isdigit(talents[i][1]))
  16.                 return;
  17.             // Set selected perk
  18.             perks[i] = atoi(talents[i].c_str());
  19.             sender->SetSelectedPerk(i, perks[i]);
  20.         }
  21.         // Save to database
  22.         QueryResult result = CharacterDatabase.PQuery("SELECT COUNT(*) FROM `character_perks` WHERE `GUID` = '%u'", sender->GetGUIDLow());
  23.         if (!result)
  24.             return;
  25.         int rows = result->Fetch()->GetInt32();
  26.         if (rows == 0)
  27.         {
  28.             CharacterDatabase.PQuery("INSERT INTO `character_perks` VALUES ('%u', '%u', '%u', '%u', '%u')",
  29.                 sender->GetGUIDLow(), perks[0], perks[1], perks[2], perks[3]);
  30.         }
  31.         else if (rows == 1)
  32.         {
  33.             CharacterDatabase.PQuery("UPDATE `character_perks` SET `perk1`='%u',`perk2`='%u',`perk3`='%u',`perk4`='%u' WHERE `GUID` = '%u'",
  34.                 perks[0], perks[1], perks[2], perks[3], sender->GetGUIDLow());
  35.         }
  36.         else
  37.         {
  38.             TC_LOG_INFO("server.error", "[ERROR]: Character %s has multiple perk records in the database.", sender->GetName());
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment