OpenFusion/src/db/Database.hpp
dongresource be6a4c0a5d Enforce minimum supported libsqlite version
The server now checks the libsqlite both at compile time and on server
startup. The version the executable was built with and the one it's
running with may be different, so long as they're both at or above the
minimum supported version. One or both version numbers are printed on
startup, depending on if they're identical or not.

The compile-time ("Built with") version depends on the sqlite3.h header
used during compilation, while the runtime ("Using") version depends on
either:

* The sqlite3.c version used during compilation, if statically linked.
  (Which may be different from the header version and still compile and run
  fine.)
* The version of the libsqlite3.so or sqlite3.dll that the server
  loaded, if dynamically linked. Version mismatches here are normal,
  especially on Unix systems with their own system libraries.

The current minimum version is 3.33.0, from 2020-08-14, as that's the
one that introduced the UPDATE-FROM syntax used during login by
Database::updateSelectedByPlayerId().

Also rearranged the prints and initialization calls in main() slightly.
2023-03-19 01:41:07 +01:00

115 lines
3.5 KiB
C++

#pragma once
#include "Player.hpp"
#include <string>
#include <vector>
#define DATABASE_VERSION 4
namespace Database {
struct Account {
int AccountID;
std::string Password;
int Selected;
time_t BannedUntil;
std::string BanReason;
};
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 RaceRanking {
int EPID;
int PlayerID;
int Score;
int RingCount;
uint64_t Time;
uint64_t Timestamp;
};
void init();
void open();
void close();
void findAccount(Account* account, std::string login);
// returns ID, 0 if something failed
int addAccount(std::string login, std::string password);
// interface for the /ban command
bool banPlayer(int playerId, std::string& reason);
bool unbanPlayer(int playerId);
void updateSelected(int accountId, int slot);
void updateSelectedByPlayerId(int accountId, int playerId);
bool validateCharacter(int characterID, int userID);
bool isNameFree(std::string firstName, std::string lastName);
bool isSlotFree(int accountId, int slotNum);
/// returns ID, 0 if something failed
int createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID);
/// returns true if query succeeded
bool finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character, int accountId);
/// returns true if query succeeded
bool finishTutorial(int playerID, int accountID);
/// returns slot number if query succeeded
int deleteCharacter(int characterID, int userID);
void getCharInfo(std::vector <sP_LS2CL_REP_CHAR_INFO>* result, int userID);
/// accepting/declining custom name
enum class CustomName {
APPROVE = 1,
DISAPPROVE = 2
};
void evaluateCustomName(int characterID, CustomName decision);
/// returns true if query succeeded
bool changeName(sP_CL2LS_REQ_CHANGE_CHAR_NAME* save, int accountId);
// getting players
void getPlayer(Player* plr, int id);
bool _updatePlayer(Player *player);
void updatePlayer(Player *player);
void commitTrade(Player *plr1, Player *plr2);
// buddies
int getNumBuddies(Player* player);
void addBuddyship(int playerA, int playerB);
void removeBuddyship(int playerA, int playerB);
// blocking
void addBlock(int playerId, int blockedPlayerId);
void removeBlock(int playerId, int blockedPlayerId);
// 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);
bool sendEmail(EmailData* data, std::vector<sItemBase> attachments, Player *sender);
// racing
RaceRanking getTopRaceRanking(int epID, int playerID);
void postRaceRanking(RaceRanking ranking);
// code items
bool isCodeRedeemed(int playerId, std::string code);
void recordCodeRedemption(int playerId, std::string code);
}