OpenFusion/src/Database.hpp

180 lines
4.9 KiB
C++
Raw Normal View History

#pragma once
#include "CNStructs.hpp"
#include "Player.hpp"
#include <string>
#include <vector>
namespace Database {
#pragma region DatabaseStructs
struct Account {
2020-09-02 15:53:39 +00:00
int AccountID;
std::string Login;
std::string Password;
int Selected;
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
uint64_t Created;
uint64_t LastLogin;
2020-09-02 15:53:39 +00:00
};
struct Inventory {
2020-09-07 00:16:44 +00:00
int playerId;
int slot;
int16_t Type;
int16_t id;
int32_t Opt;
int32_t TimeLimit;
};
struct Nano {
int playerId;
int16_t iID;
int16_t iSkillID;
int16_t iStamina;
2020-09-02 15:53:39 +00:00
};
struct DbPlayer {
2020-09-02 15:53:39 +00:00
int PlayerID;
int AccountID;
short int slot;
std::string FirstName;
std::string LastName;
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
uint64_t Created;
uint64_t LastLogin;
2020-09-07 00:16:44 +00:00
short int Level;
int Nano1;
int Nano2;
int Nano3;
2020-09-02 15:53:39 +00:00
short int AppearanceFlag;
short int Body;
short int Class;
short int EyeColor;
short int FaceStyle;
short int Gender;
int HP;
short int HairColor;
short int HairStyle;
short int Height;
2020-09-02 15:53:39 +00:00
short int NameCheck;
short int PayZoneFlag;
short int SkinColor;
bool TutorialFlag;
int AccountLevel;
2020-09-02 15:53:39 +00:00
int FusionMatter;
int Taros;
int x_coordinates;
int y_coordinates;
int z_coordinates;
int angle;
short int PCState;
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
int BatteryW;
int BatteryN;
int16_t Mentor;
2020-09-13 18:45:51 +00:00
std::vector<char> QuestFlag;
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
int32_t CurrentMissionID;
int32_t WarpLocationFlag;
int64_t SkywayLocationFlag1;
int64_t SkywayLocationFlag2;
};
struct DbQuest {
int PlayerId;
int32_t TaskId;
int RemainingNPCCount1;
int RemainingNPCCount2;
int RemainingNPCCount3;
2020-09-02 15:53:39 +00:00
};
2020-11-08 17:42:27 +00:00
struct Buddyship {
int PlayerAId;
int PlayerBId;
int16_t Status;
};
struct EmailData {
int PlayerId;
int MsgIndex;
int32_t ReadFlag;
int32_t ItemFlag;
int SenderId;
std::string SenderFirstName;
std::string SenderLastName;
std::string SubjectLine;
std::string MsgBody;
int Taros;
uint64_t SendTime;
uint64_t DeleteTime;
};
struct EmailItem {
int PlayerId;
int MsgIndex;
int Slot;
int16_t Type;
int16_t Id;
int32_t Opt;
int32_t TimeLimit;
};
#pragma endregion DatabaseStructs
// handles migrations
2020-09-02 15:53:39 +00:00
void open();
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
int getAccountsCount();
int getPlayersCount();
// returns ID
2020-09-02 15:53:39 +00:00
int addAccount(std::string login, std::string password);
void updateSelected(int accountId, int playerId);
std::unique_ptr<Account> findAccount(std::string login);
bool isNameFree(sP_CL2LS_REQ_CHECK_CHAR_NAME* nameCheck);
// called after chosing name, returns ID
2020-09-02 15:53:39 +00:00
int createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID);
// called after finishing creation
2020-09-02 15:53:39 +00:00
void finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character);
// called after tutorial
2020-09-02 15:53:39 +00:00
void finishTutorial(int PlayerID);
// returns slot number
int deleteCharacter(int characterID, int userID);
2020-09-02 15:53:39 +00:00
std::vector <Player> getCharacters(int userID);
// accepting/declining custom name
enum class CustomName {
APPROVE = 1,
DISAPPROVE = 2
2020-09-02 15:53:39 +00:00
};
void evaluateCustomName(int characterID, CustomName decision);
2020-09-02 15:53:39 +00:00
void changeName(sP_CL2LS_REQ_CHANGE_CHAR_NAME* save);
// parsing DbPlayer
DbPlayer playerToDb(Player *player);
2020-09-02 15:53:39 +00:00
Player DbToPlayer(DbPlayer player);
// getting players
2020-09-02 15:53:39 +00:00
DbPlayer getDbPlayerById(int id);
2020-09-07 00:16:44 +00:00
Player getPlayer(int id);
void updatePlayer(Player *player);
void updateInventory(Player *player);
void updateNanos(Player *player);
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
void updateQuests(Player* player);
2020-11-08 17:42:27 +00:00
void updateBuddies(Player* player);
2020-09-07 00:16:44 +00:00
void getInventory(Player* player);
void removeExpiredVehicles(Player* player);
2020-09-07 00:16:44 +00:00
void getNanos(Player* player);
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
void getQuests(Player* player);
2020-11-08 17:42:27 +00:00
void getBuddies(Player* player);
int getNumBuddies(Player* player);
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
// parsing blobs
Database saving update (#104) * implemented saving BatteryN and BatteryW * implemented saving mentor * moved int64->blob parsing to a separate function * moved parsing blob->int64 to a separate function * added functions for parsing int32->blob and vice versa * added functions for parsing int16->blob and vice versa * WIP saving quest items and active tasks * Quest items are stored in inventory table instead of blob * added sanity check for missionId * saving active missions works * removed unneccesary include * implemented saving warplocationflag, skywaylocationflag and currentmissionid in database * INFO DB message now shows how many accounts and player characters are in the database * fixed dbsaveinterval being in [login] instead of [shard] * fixed mission quit: - fixed wrong json name, causing qitems not deleting properly - quitting mission now resets npc kill count * adjusted saving active missions * removed blob parsing functions that ended up being unused * removed accidentaly added include * removed sending PCStyle2 on Player Enter * added a sanity check in itemMoveHandler * removed MapNum from PCLoad, as client doesn't even read it * set BuddyWarpCooldown to 60s on PCLoad * fixed a bug causing EXIT DUPLICATE not working * added creation and last login timestamps to accounts and players * added a sanity check for P_CL2LS_REQ_PC_EXIT_DUPLICATE * implemented web api support, toggled by new setting (off by default) * add usewebapi to config Co-authored-by: Gent <gentsemaj@live.com>
2020-09-21 19:43:53 +00:00
void appendBlob(std::vector<char>*blob, int64_t input);
int64_t blobToInt64(std::vector<char>::iterator it);
// buddies
void addBuddyship(int playerA, int playerB);
void removeBuddyship(int playerA, int playerB);
// email
int getUnreadEmailCount(int playerID);
std::vector<EmailData> getEmails(int playerID, int page);
EmailData getEmail(int playerID, int index);
sItemBase* getEmailAttachments(int playerID, int index);
void updateEmailContent(EmailData* data);
void deleteEmailAttachments(int playerID, int index, int slot);
void deleteEmails(int playerID, int64_t* indices);
int getNextEmailIndex(int playerID);
void sendEmail(EmailData* data, std::vector<sItemBase> attachments);
}