00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _TMWSERV_DALSTORAGE_H_
00022 #define _TMWSERV_DALSTORAGE_H_
00023
00024 #include <list>
00025 #include <map>
00026 #include <vector>
00027
00028 #include "../dal/dataprovider.h"
00029
00030 #include "../common/transaction.hpp"
00031
00032 class Account;
00033 class Character;
00034 class ChatChannel;
00035 class Guild;
00036 class Letter;
00037 class Post;
00038
00042 class DALStorage
00043 {
00044 public:
00048 DALStorage();
00049
00050
00054 ~DALStorage();
00055
00056
00060 void open();
00061
00062
00066 void close();
00067
00068
00076 Account *getAccount(const std::string& userName);
00077
00085 Account *getAccount(int accountID);
00086
00095 Character *getCharacter(int id, Account *owner);
00096
00104 Character *getCharacter(const std::string &name);
00105
00111 void
00112 addAccount(Account *account);
00113
00119 void delAccount(Account *account);
00120
00126 void updateLastLogin(const Account *account);
00127
00137 void updateCharacterPoints(const int CharId, const int CharPoints,
00138 const int CorrPoints, const int AttribId, const int AttribValue );
00139
00146 void updateExperience(const int CharId, const int SkillId,
00147 const int SkillValue);
00148
00155 void banCharacter(int id, int duration);
00156
00164 void delCharacter(int charId, bool startTransaction) const;
00165
00174 void delCharacter(Character *character, bool startTransaction) const;
00175
00179 void checkBannedAccounts();
00180
00185 bool doesUserNameExist(const std::string &name);
00186
00191 bool doesEmailAddressExist(const std::string &email);
00192
00197 bool doesCharacterNameExist(const std::string &name);
00198
00210 bool
00211 updateCharacter(Character *ptr,
00212 bool startTransaction = true);
00213
00222 void
00223 flushSkill(const Character* const character, const int skill_id );
00224
00229 void
00230 addGuild(Guild* guild);
00231
00236 void
00237 removeGuild(Guild* guild);
00238
00243 void
00244 addGuildMember(int guild_id, int memberId);
00245
00249 void
00250 removeGuildMember(int guildId, int memberId);
00251
00255 void
00256 setMemberRights(int guildId, int memberId, int rights);
00257
00263 std::list<Guild*>
00264 getGuildList();
00265
00271 void flushAll();
00272 void flush(Account *);
00273
00277 std::string getQuestVar(int id, const std::string &);
00278
00282 void setQuestVar(int id, const std::string &, const std::string &);
00283
00290 std::string getWorldStateVar(const std::string &name, int map_id = -1);
00291
00298 void setWorldStateVar(const std::string &name, const std::string &value);
00299
00307 void setWorldStateVar(const std::string &name, int map_id,
00308 const std::string &value);
00309
00316 void setAccountLevel(int id, int level);
00317
00324 void setPlayerLevel(int id, int level);
00325
00331 void storeLetter(Letter *letter);
00332
00338 Post* getStoredPost(int playerId);
00339
00344 void deletePost(Letter* letter);
00345
00353 void addAuctionItem(unsigned int itemId, int playerId, unsigned int gold);
00354
00360 unsigned int getItemDatabaseVersion(void) const
00361 { return mItemDbVersion; }
00362
00369 void setOnlineStatus(int charId, bool online);
00370
00374 void addTransaction(const Transaction &trans);
00375
00381 std::vector<Transaction> getTransactions(unsigned int num);
00382 std::vector<Transaction> getTransactions(time_t date);
00383
00384 private:
00388 DALStorage(const DALStorage& rhs);
00389
00390
00394 DALStorage&
00395 operator=(const DALStorage& rhs);
00396
00404 Account *getAccountBySQL(const std::string &query);
00405
00406
00415 Character *getCharacterBySQL(const std::string &query, Account *owner);
00416
00425 void SyncDatabase(void);
00426
00427 dal::DataProvider *mDb;
00428 unsigned int mItemDbVersion;
00429 };
00430
00431 extern DALStorage *storage;
00432
00433 #endif // _TMWSERV_DALSTORAGE_H_