1/**
2 * The Forgotten Server - a free and open-source MMORPG server emulator
3 * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifndef FS_IOLOGINDATA_H_28B0440BEC594654AC0F4E1A5E42B2EF
21#define FS_IOLOGINDATA_H_28B0440BEC594654AC0F4E1A5E42B2EF
22
23#include "account.h"
24#include "player.h"
25#include "database.h"
26
27using ItemBlockList = std::list<std::pair<int32_t, Item*>>;
28
29class IOLoginData
30{
31 public:
32 static Account loadAccount(uint32_t accno);
33 static bool saveAccount(const Account& acc);
34
35 static bool loginserverAuthentication(const std::string& name, const std::string& password, Account& account);
36 static uint32_t gameworldAuthentication(const std::string& accountName, const std::string& password, std::string& characterName, std::string& token, uint32_t tokenTime);
37 static uint32_t getAccountIdByPlayerName(const std::string& playerName);
38
39 static AccountType_t getAccountType(uint32_t accountId);
40 static void setAccountType(uint32_t accountId, AccountType_t accountType);
41 static void updateOnlineStatus(uint32_t guid, bool login);
42 static bool preloadPlayer(Player* player, const std::string& name);
43
44 static bool loadPlayerById(Player* player, uint32_t id);
45 static bool loadPlayerByName(Player* player, const std::string& name);
46 static bool loadPlayer(Player* player, DBResult_ptr result);
47 static bool savePlayer(Player* player);
48 static uint32_t getGuidByName(const std::string& name);
49 static bool getGuidByNameEx(uint32_t& guid, bool& specialVip, std::string& name);
50 static std::string getNameByGuid(uint32_t guid);
51 static bool formatPlayerName(std::string& name);
52 static void increaseBankBalance(uint32_t guid, uint64_t bankBalance);
53 static bool hasBiddedOnHouse(uint32_t guid);
54
55 static std::forward_list<VIPEntry> getVIPEntries(uint32_t accountId);
56 static void addVIPEntry(uint32_t accountId, uint32_t guid, const std::string& description, uint32_t icon, bool notify);
57 static void editVIPEntry(uint32_t accountId, uint32_t guid, const std::string& description, uint32_t icon, bool notify);
58 static void removeVIPEntry(uint32_t accountId, uint32_t guid);
59
60 static void addPremiumDays(uint32_t accountId, int32_t addDays);
61 static void removePremiumDays(uint32_t accountId, int32_t removeDays);
62
63 private:
64 using ItemMap = std::map<uint32_t, std::pair<Item*, uint32_t>>;
65
66 static void loadItems(ItemMap& itemMap, DBResult_ptr result);
67 static bool saveItems(const Player* player, const ItemBlockList& itemList, DBInsert& query_insert, PropWriteStream& propWriteStream);
68};
69
70#endif
71