Updated database control, character stats are saving
Just for the record, I don't like the way SAVE_CHARACTER is expanded like that.
This commit is contained in:
@@ -29,6 +29,8 @@ struct AccountData {
|
||||
//TODO: password
|
||||
bool blackListed = false;
|
||||
bool whiteListed = true;
|
||||
bool mod = false;
|
||||
bool admin = false;
|
||||
|
||||
int clientIndex;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ struct CharacterData {
|
||||
int mapIndex = 0;
|
||||
Vector2 origin = {0.0,0.0};
|
||||
Vector2 motion = {0.0,0.0};
|
||||
Vector2 bounds = {0.0,0.0};
|
||||
|
||||
//base statistics
|
||||
Statistics stats;
|
||||
@@ -69,7 +70,6 @@ struct CharacterData {
|
||||
#ifdef GRAPHICS
|
||||
SpriteSheet sprite;
|
||||
#endif
|
||||
Vector2 bounds = {0.0,0.0};
|
||||
bool inCombat = false;
|
||||
int atbGauge = 0;
|
||||
//TODO: stored command
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
--TODO: why is the database setup script scripted, while accessing, etc. hardcoded?
|
||||
--there should be a way to control the database more directly
|
||||
--TODO: move this script into a hardocded Init() method?
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Accounts (
|
||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username varchar(100) UNIQUE,
|
||||
@@ -5,7 +9,8 @@ CREATE TABLE IF NOT EXISTS Accounts (
|
||||
-- password varchar(100),
|
||||
blacklisted BIT DEFAULT 0,
|
||||
whitelisted BIT DEFAULT 1,
|
||||
administrator BIT DEFAULT 0
|
||||
mod BIT DEFAULT 0,
|
||||
admin BIT DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Characters (
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
static const char* CREATE_USER_ACCOUNT = "INSERT INTO Accounts (username) VALUES (?);";
|
||||
static const char* LOAD_USER_ACCOUNT = "SELECT * FROM Accounts WHERE username = ?;";
|
||||
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL Accounts SET blacklisted = ?2, whitelisted = ?3 WHERE uid = ?1;";
|
||||
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL Accounts SET blacklisted = ?2, whitelisted = ?3, mod = ?4, admin = ?5 WHERE uid = ?1;";
|
||||
static const char* DELETE_USER_ACCOUNT = "DELETE FROM Accounts WHERE uid = ?;";
|
||||
|
||||
//-------------------------
|
||||
@@ -98,6 +98,8 @@ int ServerApplication::LoadUserAccount(std::string username, int clientIndex) {
|
||||
newAccount.username = reinterpret_cast<const char*>(sqlite3_column_text(statement, 1));
|
||||
newAccount.blackListed = sqlite3_column_int(statement, 2);
|
||||
newAccount.whiteListed = sqlite3_column_int(statement, 3);
|
||||
newAccount.mod = sqlite3_column_int(statement, 4);
|
||||
newAccount.admin = sqlite3_column_int(statement, 5);
|
||||
newAccount.clientIndex = clientIndex;
|
||||
|
||||
//finish the routine
|
||||
@@ -137,6 +139,8 @@ int ServerApplication::SaveUserAccount(int uid) {
|
||||
ret |= sqlite3_bind_int(statement, 1, uid) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 2, account.blackListed) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 3, account.whiteListed) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 4, account.mod) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 5, account.admin) != SQLITE_OK;
|
||||
|
||||
//check for binding errors
|
||||
if (ret) {
|
||||
@@ -165,7 +169,7 @@ void ServerApplication::UnloadUserAccount(int uid) {
|
||||
|
||||
void ServerApplication::DeleteUserAccount(int uid) {
|
||||
//delete a user account from the database, and remove it from memory
|
||||
//NOTE: the associated characters are unloaded externally
|
||||
//NOTE: the associated characters should be deleted externally
|
||||
sqlite3_stmt* statement = nullptr;
|
||||
|
||||
//prep
|
||||
|
||||
@@ -29,17 +29,37 @@
|
||||
//Define the queries
|
||||
//-------------------------
|
||||
|
||||
//TODO: save and load the statistics
|
||||
static const char* CREATE_CHARACTER = "INSERT INTO Characters (owner, handle, avatar) VALUES (?, ?, ?);";
|
||||
static const char* LOAD_CHARACTER = "SELECT * FROM Characters WHERE handle = ?;";
|
||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET mapIndex = ?2, originX = ?3, originY = ?4 WHERE uid = ?1;";
|
||||
|
||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET "
|
||||
"mapIndex = ?2,"
|
||||
"originX = ?3,"
|
||||
"originY = ?4,"
|
||||
"level = ?5,"
|
||||
"exp = ?6,"
|
||||
"maxHP = ?7,"
|
||||
"health = ?8,"
|
||||
"maxMP = ?9,"
|
||||
"mana = ?10,"
|
||||
"attack = ?11,"
|
||||
"defence = ?12,"
|
||||
"intelligence = ?13,"
|
||||
"resistance = ?14,"
|
||||
"speed = ?15,"
|
||||
"accuracy = ?16,"
|
||||
"evasion = ?17,"
|
||||
"luck = ?18"
|
||||
" WHERE uid = ?1;";
|
||||
|
||||
static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
||||
|
||||
//-------------------------
|
||||
//Define the methods
|
||||
//-------------------------
|
||||
|
||||
//TODO: default stats as a parameter
|
||||
//TODO: should statistics be stored separately?
|
||||
//TODO: default stats as a parameter? This would be good for differing beggining states or multiple classes
|
||||
int ServerApplication::CreateCharacter(int owner, std::string handle, std::string avatar) {
|
||||
//Create the character, failing if it exists
|
||||
sqlite3_stmt* statement = nullptr;
|
||||
@@ -139,6 +159,9 @@ int ServerApplication::LoadCharacter(int owner, std::string handle, std::string
|
||||
newChar.stats.luck = sqlite3_column_double(statement, 21);
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
//finish the routine
|
||||
sqlite3_finalize(statement);
|
||||
@@ -178,7 +201,27 @@ int ServerApplication::SaveCharacter(int uid) {
|
||||
ret |= sqlite3_bind_int(statement, 2, character.mapIndex) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK;
|
||||
//TODO: stats, etc.
|
||||
|
||||
//statistics
|
||||
ret |= sqlite3_bind_int(statement, 5, character.stats.level) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 6, character.stats.exp) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 7, character.stats.maxHP) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 8, character.stats.health) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 9, character.stats.maxMP) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 10, character.stats.mana) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 11, character.stats.attack) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 12, character.stats.defence) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 13, character.stats.intelligence) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 14, character.stats.resistance) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 15, character.stats.speed) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 16, character.stats.accuracy) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 17, character.stats.evasion) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 18, character.stats.luck) != SQLITE_OK;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
//check for binding errors
|
||||
if (ret) {
|
||||
|
||||
Reference in New Issue
Block a user