1. /*
  2. *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
  3. *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
  4. *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
  5. *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
  6. * http://emudevs.com
  7. */
  8. #include "VotePoints.h"
  9. VotePointSystem::VotePointSystem() { }
  10. VotePointSystem::~VotePointSystem() { }
  11. VotePointSystemMgr::VotePointSystemMgr() { }
  12. VotePointSystemMgr::~VotePointSystemMgr()
  13. {
  14. for (VotePointList::iterator itr = _voteList.begin(); itr != _voteList.end(); ++itr)
  15. delete itr->second;
  16. _voteList.clear();
  17. }
  18. bool VotePointSystem::LoadFromDB(Field * fields)
  19. {
  20. uint8 index = 0;
  21. accountId = fields[index].GetUInt32();
  22. votePoints = fields[++index].GetUInt32();
  23. return true;
  24. }
  25. void VotePointSystem::SaveToDB(SQLTransaction& trans) const
  26. {
  27. uint8 index = 0;
  28. PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_POINTS);
  29. PreparedStatement* _stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_POINTS);
  30. stmt->setUInt32(0, accountId);
  31. PreparedQueryResult result = LoginDatabase.Query(stmt);
  32. uint32 _votePoints;
  33. if (result)
  34. {
  35. do
  36. {
  37. Field* fields = result->Fetch();
  38. _votePoints = fields[0].GetUInt32();
  39. if (_votePoints < 0 || _votePoints < votePoints)
  40. return;
  41. else
  42. _votePoints -= votePoints;
  43. } while (result->NextRow());
  44. }
  45. _stmt->setUInt32(index, _votePoints);
  46. _stmt->setUInt32(index++, accountId);
  47. CharacterDatabase.Execute(_stmt);
  48. }
  49. void VotePointSystemMgr::LoadVoteSystem()
  50. {
  51. uint32 oldMSTime = getMSTime();
  52. for (VotePointList::const_iterator itr = _voteList.begin(); itr != _voteList.end(); ++itr)
  53. delete itr->second;
  54. _voteList.clear();
  55. PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_LOAD_POINTS);
  56. PreparedQueryResult result = LoginDatabase.Query(stmt);
  57. if (!result)
  58. {
  59. TC_LOG_ERROR("server.loading", ">> Loaded 0 Account Vote Points Data");
  60. return;
  61. }
  62. uint32 count = 0;
  63. do
  64. {
  65. Field* fields = result->Fetch();
  66. VotePointSystem* voteSystem = new VotePointSystem;
  67. if (!voteSystem->LoadFromDB(fields))
  68. {
  69. delete voteSystem;
  70. continue;
  71. }
  72. _voteList[voteSystem->GetAccountId()] = voteSystem;
  73. ++count;
  74. } while (result->NextRow());
  75. TC_LOG_INFO("server.loading", ">> Loaded %u Player Vote Data in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
  76. }
  77. void VotePointSystemMgr::SaveToList(VotePointSystem* voteSystem)
  78. {
  79. _voteList[voteSystem->GetAccountId()] = voteSystem;
  80. SQLTransaction trans = SQLTransaction(NULL);
  81. voteSystem->SaveToDB(trans);
  82. }

Vote.cpp Source file