Advertisement
EmuDevs

EmuDevs: TrinityCore - Vote Point System (SOURCE FILE)

Sep 1st, 2013
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. /*
  2.  *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
  3.  *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
  4.  *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
  5.  *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
  6.  *            http://emudevs.com
  7. */
  8. #include "VotePoints.h"
  9.  
  10. VotePointSystem::VotePointSystem() { }
  11.  
  12. VotePointSystem::~VotePointSystem() { }
  13.  
  14. VotePointSystemMgr::VotePointSystemMgr() { }
  15.  
  16. VotePointSystemMgr::~VotePointSystemMgr()
  17. {
  18.     for (VotePointList::iterator itr = _voteList.begin(); itr != _voteList.end(); ++itr)
  19.     delete itr->second;
  20.     _voteList.clear();
  21. }
  22.  
  23. bool VotePointSystem::LoadFromDB(Field * fields)
  24. {
  25.     uint8 index = 0;
  26.     accountId = fields[index].GetUInt32();
  27.     votePoints = fields[++index].GetUInt32();
  28.     return true;
  29. }
  30.  
  31. void VotePointSystem::SaveToDB(SQLTransaction& trans) const
  32. {
  33.     uint8 index = 0;
  34.     PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_POINTS);
  35.     PreparedStatement* _stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_POINTS);
  36.     stmt->setUInt32(0, accountId);
  37.     PreparedQueryResult result = LoginDatabase.Query(stmt);
  38.  
  39.     uint32 _votePoints;
  40.     if(result)
  41.     {
  42.         do
  43.         {
  44.             Field* fields = result->Fetch();
  45.             _votePoints = fields[0].GetUInt32();
  46.             if(_votePoints < 0 || _votePoints < votePoints)
  47.                 return;
  48.             else
  49.                 _votePoints -= votePoints;
  50.         }while(result->NextRow());
  51.     }
  52.     _stmt->setUInt32(index, _votePoints);
  53.     _stmt->setUInt32(index++, accountId);
  54.     CharacterDatabase.Execute(_stmt);
  55. }
  56.  
  57. void VotePointSystemMgr::LoadVoteSystem()
  58. {
  59.     uint32 oldMSTime = getMSTime();
  60.  
  61.     for (VotePointList::const_iterator itr = _voteList.begin(); itr != _voteList.end(); ++itr)
  62.         delete itr->second;
  63.     _voteList.clear();
  64.  
  65.     PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_LOAD_POINTS);
  66.     PreparedQueryResult result = LoginDatabase.Query(stmt);
  67.     if(!result)
  68.     {
  69.         sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 Account Vote Points Data");
  70.         return;
  71.     }
  72.  
  73.     uint32 count = 0;
  74.     do
  75.     {
  76.         Field* fields = result->Fetch();
  77.         VotePointSystem* voteSystem = new VotePointSystem;
  78.         if(!voteSystem->LoadFromDB(fields))
  79.         {
  80.             delete voteSystem;
  81.             continue;
  82.         }
  83.         _voteList[voteSystem->GetAccountId()] = voteSystem;
  84.         ++count;
  85.     }while(result->NextRow());
  86.     sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u Player Vote Data in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
  87. }
  88.  
  89. void VotePointSystemMgr::SaveToList(VotePointSystem* voteSystem)
  90. {
  91.    _voteList[voteSystem->GetAccountId()] = voteSystem;
  92.     SQLTransaction trans = SQLTransaction(NULL);
  93.     voteSystem->SaveToDB(trans);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement