interdev

Untitled

Jun 10th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.33 KB | None | 0 0
  1. diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
  2. index 96192b2..6125236 100644
  3. --- a/src/server/game/Achievements/AchievementMgr.cpp
  4. +++ b/src/server/game/Achievements/AchievementMgr.cpp
  5. @@ -526,7 +526,8 @@ void AchievementMgr<Player>::SaveToDB(SQLTransaction& charTrans, SQLTransaction&
  6.  
  7.      if (!m_completedAchievements.empty())
  8.      {
  9. -        bool needExecute = false;
  10. +        bool needCharacterExecute = false;
  11. +        bool needAccountExecute = false;
  12.  
  13.          std::ostringstream ssAccDel;
  14.          std::ostringstream ssAccIns;
  15. @@ -543,38 +544,58 @@ void AchievementMgr<Player>::SaveToDB(SQLTransaction& charTrans, SQLTransaction&
  16.              if (!completionData.changed)
  17.                  continue;
  18.  
  19. +            AchievementEntry const* ach = sAchievementMgr->GetAchievement(achievementId);
  20. +            if (!ach)
  21. +                continue;
  22. +
  23. +            bool isAccountAchievement = ach->flags & ACHIEVEMENT_FLAG_ACCOUNT;
  24.              bool const mustSaveForCharacter = completionData.completedByThisCharacter;
  25. -            if (!needExecute)
  26. +            if (!needAccountExecute)
  27.              {
  28. -                // First new/changed record prefix
  29. -                ssAccDel << "DELETE FROM account_achievement WHERE account = " << accountId << " AND achievement IN (";
  30. -                ssAccIns << "INSERT INTO account_achievement (account, first_guid, achievement, date) VALUES ";
  31. +                if (isAccountAchievement)
  32. +                {
  33. +                    // First new/changed record prefix
  34. +                    ssAccDel << "DELETE FROM account_achievement WHERE account = " << accountId << " AND achievement IN (";
  35. +                    ssAccIns << "INSERT INTO account_achievement (account, first_guid, achievement, date) VALUES ";
  36. +                    needAccountExecute = true;
  37. +                }
  38. +            }
  39. +            else
  40. +            {
  41. +                if (isAccountAchievement)
  42. +                {
  43. +                    // Next new/changed record prefix
  44. +                    ssAccDel << ',';
  45. +                    ssAccIns << ',';
  46. +                }
  47. +            }
  48.  
  49. -                if (mustSaveForCharacter)
  50. +            if (!needCharacterExecute)
  51. +            {
  52. +                if (mustSaveForCharacter || !isAccountAchievement)
  53.                  {
  54.                      ssCharDel << "DELETE FROM character_achievement WHERE guid = " << guidLow << " AND achievement IN (";
  55.                      ssCharIns << "INSERT INTO character_achievement (guid, achievement) VALUES ";
  56. +                    needCharacterExecute = true;
  57.                  }
  58. -                needExecute = true;
  59.              }
  60.              else
  61.              {
  62. -                // Next new/changed record prefix
  63. -                ssAccDel << ',';
  64. -                ssAccIns << ',';
  65. -
  66. -                if (mustSaveForCharacter)
  67. +                if (mustSaveForCharacter || !isAccountAchievement)
  68.                  {
  69.                      ssCharDel << ',';
  70.                      ssCharIns << ',';
  71.                  }
  72.              }
  73.  
  74. -            // New/changed record data
  75. -            ssAccDel << achievementId;
  76. -            ssAccIns << '(' << accountId << ',' << completionData.first_guid << ',' << achievementId << ',' << completionData.date << ')';
  77. +            if (isAccountAchievement)
  78. +            {
  79. +                // New/changed record data
  80. +                ssAccDel << achievementId;
  81. +                ssAccIns << '(' << accountId << ',' << completionData.first_guid << ',' << achievementId << ',' << completionData.date << ')';
  82. +            }
  83.  
  84. -            if (mustSaveForCharacter)
  85. +            if (mustSaveForCharacter || !isAccountAchievement)
  86.              {
  87.                  ssCharDel << achievementId;
  88.                  ssCharIns << '(' << guidLow << ',' << achievementId << ')';
  89. @@ -584,13 +605,18 @@ void AchievementMgr<Player>::SaveToDB(SQLTransaction& charTrans, SQLTransaction&
  90.              completionData.changed = false;
  91.          }
  92.  
  93. -        if (needExecute)
  94. +        if (needAccountExecute)
  95.          {
  96.              ssAccDel << ')';
  97. -            ssCharDel << ')';
  98.  
  99.              authTrans->Append(ssAccDel.str().c_str());
  100.              authTrans->Append(ssAccIns.str().c_str());
  101. +        }
  102. +
  103. +        if (needCharacterExecute)
  104. +        {
  105. +            ssCharDel << ')';
  106. +
  107.              charTrans->Append(ssCharDel.str().c_str());
  108.              charTrans->Append(ssCharIns.str().c_str());
  109.          }
  110. @@ -901,9 +927,9 @@ void AchievementMgr<Player>::LoadFromDB(PreparedQueryResult achievementResult, P
  111.                  continue;
  112.  
  113.              // Achievement in character_achievement but not in account_achievement, there is a problem.
  114. -            if (m_completedAchievements.find(achievementid) == m_completedAchievements.end())
  115. +            if (m_completedAchievements.find(achievementid) == m_completedAchievements.end() && achievement->flags & ACHIEVEMENT_FLAG_ACCOUNT)
  116.              {
  117. -                TC_LOG_ERROR("achievement", "Achievement '%u' in character_achievement but not in account_achievement, there is a problem.", achievementid);
  118. +                TC_LOG_ERROR("achievement", "Account-wide achievement '%u' in character_achievement but not in account_achievement, there is a problem.", achievementid);
  119.                  continue;
  120.              }
Add Comment
Please, Sign In to add comment