Advertisement
Guest User

Untitled

a guest
May 12th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17.  
  18. #ifndef __IOLOGINDATA__
  19. #define __IOLOGINDATA__
  20. #include "otsystem.h"
  21. #include "database.h"
  22.  
  23. #include "creature.h"
  24. #include "player.h"
  25. #include "account.h"
  26. #include "group.h"
  27.  
  28. enum DeleteCharacter_t
  29. {
  30. DELETE_INTERNAL,
  31. DELETE_LEADER,
  32. DELETE_HOUSE,
  33. DELETE_ONLINE,
  34. DELETE_SUCCESS
  35. };
  36.  
  37. typedef std::pair<int32_t, Item*> itemBlock;
  38. typedef std::list<itemBlock> ItemBlockList;
  39.  
  40. class IOLoginData
  41. {
  42. public:
  43. virtual ~IOLoginData() {}
  44. static IOLoginData* getInstance()
  45. {
  46. static IOLoginData instance;
  47. return &instance;
  48. }
  49.  
  50. Account loadAccount(uint32_t accountId, bool preLoad = false);
  51. bool saveAccount(Account account);
  52.  
  53. bool getAccountId(const std::string& name, uint32_t& number);
  54. bool getAccountName(uint32_t number, std::string& name);
  55.  
  56. bool hasFlag(uint32_t accountId, PlayerFlags value);
  57. bool hasCustomFlag(uint32_t accountId, PlayerCustomFlags value);
  58. bool hasFlag(PlayerFlags value, const std::string& accName);
  59. bool hasCustomFlag(PlayerCustomFlags value, const std::string& accName);
  60.  
  61. bool accountIdExists(uint32_t accountId);
  62. bool accountNameExists(const std::string& name);
  63.  
  64. bool getPassword(uint32_t accountId, std::string& password, std::string& salt, std::string name = "");
  65. bool setPassword(uint32_t accountId, std::string newPassword);
  66. bool validRecoveryKey(uint32_t accountId, std::string recoveryKey);
  67. bool setRecoveryKey(uint32_t accountId, std::string newRecoveryKey);
  68.  
  69. uint64_t createAccount(std::string name, std::string password);
  70. void removePremium(Account account);
  71.  
  72. const Group* getPlayerGroupByAccount(uint32_t accountId);
  73.  
  74. bool loadPlayer(Player* player, const std::string& name, bool preLoad = false);
  75. bool savePlayer(Player* player, bool preSave = true, bool shallow = false);
  76.  
  77. bool playerDeath(Player* player, const DeathList& dl);
  78. bool playerMail(Creature* actor, std::string name, uint32_t townId, Item* item);
  79.  
  80. bool hasFlag(const std::string& name, PlayerFlags value);
  81. bool hasCustomFlag(const std::string& name, PlayerCustomFlags value);
  82. bool hasFlag(PlayerFlags value, uint32_t guid);
  83. bool hasCustomFlag(PlayerCustomFlags value, uint32_t guid);
  84.  
  85. bool isPremium(uint32_t guid);
  86.  
  87. bool playerExists(uint32_t guid, bool multiworld = false, bool checkCache = true);
  88. bool playerExists(std::string& name, bool multiworld = false, bool checkCache = true);
  89. bool getNameByGuid(uint32_t guid, std::string& name, bool multiworld = false);
  90. bool getGuidByName(uint32_t& guid, std::string& name, bool multiworld = false);
  91. bool getGuidByNameEx(uint32_t& guid, bool& specialVip, std::string& name);
  92.  
  93. bool changeName(uint32_t guid, std::string newName, std::string oldName);
  94. bool createCharacter(uint32_t accountId, std::string characterName, int32_t vocationId, uint16_t sex);
  95. DeleteCharacter_t deleteCharacter(uint32_t accountId, const std::string characterName);
  96.  
  97. uint32_t getLevel(uint32_t guid) const;
  98. uint32_t getLastIP(uint32_t guid) const;
  99.  
  100. uint32_t getLastIPByName(const std::string& name) const;
  101. uint32_t getAccountIdByName(const std::string& name) const;
  102. uint32_t getCheckPlayerLevel(const std::string& name) const;
  103.  
  104. bool getUnjustifiedDates(uint32_t guid, std::vector<time_t>& dateList, time_t _time);
  105. bool getDefaultTownByName(const std::string& name, uint32_t& townId);
  106.  
  107. bool updatePremiumDays();
  108. bool updateOnlineStatus(uint32_t guid, bool login);
  109. bool resetGuildInformation(uint32_t guid);
  110.  
  111. protected:
  112. IOLoginData() {}
  113. struct StringCompareCase
  114. {
  115. bool operator()(const std::string& l, const std::string& r) const
  116. {
  117. return strcasecmp(l.c_str(), r.c_str()) < 0;
  118. }
  119. };
  120.  
  121. typedef std::map<std::string, uint32_t, StringCompareCase> GuidCacheMap;
  122. GuidCacheMap guidCacheMap;
  123.  
  124. typedef std::map<uint32_t, std::string> NameCacheMap;
  125. NameCacheMap nameCacheMap;
  126.  
  127. typedef std::map<int32_t, std::pair<Item*, int32_t> > ItemMap;
  128.  
  129. bool saveItems(const Player* player, const ItemBlockList& itemList, DBInsert& query_insert);
  130. void loadItems(ItemMap& itemMap, DBResult* result);
  131.  
  132. bool storeNameByGuid(uint32_t guid);
  133. };
  134. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement