Moved the character's stats into their own database table

This will allow the to be reused elsewhere, as well as cleaning up big
blocks of code in the manager's source.

BUGFIX: The config's key-value pair overrides now work without requiring a
config file specification.
This commit is contained in:
Kayne Ruse
2014-09-28 03:10:39 +10:00
parent 59e3518dd8
commit bfcf9a1d37
4 changed files with 42 additions and 75 deletions
+5
View File
@@ -41,12 +41,14 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
table_t redirectedFile; table_t redirectedFile;
table_t cmdLineParams; table_t cmdLineParams;
char key[256], val[256]; char key[256], val[256];
bool redirectUsed = false;
//reading from the command line //reading from the command line
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
//read from a specified config file //read from a specified config file
if (!strncmp(argv[i], "-config=", 8)) { if (!strncmp(argv[i], "-config=", 8)) {
redirectedFile = Read(argv[i] + 8); redirectedFile = Read(argv[i] + 8);
redirectUsed = true;
continue; continue;
} }
@@ -70,6 +72,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
} }
//finally, construct the final config table //finally, construct the final config table
if (!redirectUsed) {
redirectedFile = Read(fname);
}
configMap.insert(cmdLineParams.begin(), cmdLineParams.end()); configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
configMap.insert(redirectedFile.begin(), redirectedFile.end()); configMap.insert(redirectedFile.begin(), redirectedFile.end());
} }
+36 -20
View File
@@ -1,12 +1,9 @@
--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 ( CREATE TABLE IF NOT EXISTS Accounts (
uid INTEGER PRIMARY KEY AUTOINCREMENT, uid INTEGER PRIMARY KEY AUTOINCREMENT,
username varchar(100) UNIQUE, username varchar(100) UNIQUE,
--TODO: server-client security --TODO: server-client security
-- password varchar(100), -- passhash varchar(100),
-- passsalt varchar(100),
blacklisted BIT DEFAULT 0, blacklisted BIT DEFAULT 0,
whitelisted BIT DEFAULT 1, whitelisted BIT DEFAULT 1,
mod BIT DEFAULT 0, mod BIT DEFAULT 0,
@@ -22,12 +19,30 @@ CREATE TABLE IF NOT EXISTS Characters (
avatar varchar(100), avatar varchar(100),
birth timestamp NOT NULL DEFAULT (datetime()), birth timestamp NOT NULL DEFAULT (datetime()),
--position --position in the world
roomIndex INTEGER DEFAULT 0, roomIndex INTEGER DEFAULT 0,
originX INTEGER DEFAULT 0, originX INTEGER DEFAULT 0,
originY INTEGER DEFAULT 0, originY INTEGER DEFAULT 0,
--statistics --statistics
baseStats INTEGER REFERENCES StatisticSets(uid),
--equipment
weapon INTEGER REFERENCES WornEquipment(uid),
helmet INTEGER REFERENCES WornEquipment(uid),
armour INTEGER REFERENCES WornEquipment(uid)
--etc.
);
-------------------------
--Utility tables
-------------------------
CREATE TABLE IF NOT EXISTS StatisticSets (
--metadata
uid INTEGER PRIMARY KEY AUTOINCREMENT,
--general use statistics
level INTEGER DEFAULT 0, level INTEGER DEFAULT 0,
exp INTEGER DEFAULT 0, exp INTEGER DEFAULT 0,
maxHP INTEGER DEFAULT 0, maxHP INTEGER DEFAULT 0,
@@ -41,28 +56,29 @@ CREATE TABLE IF NOT EXISTS Characters (
speed INTEGER DEFAULT 0, speed INTEGER DEFAULT 0,
accuracy REAL DEFAULT 0.0, accuracy REAL DEFAULT 0.0,
evasion REAL DEFAULT 0.0, evasion REAL DEFAULT 0.0,
luck REAL DEFAULT 0.0, luck REAL DEFAULT 0.0
--equipment
weapon INTEGER REFERENCES WornEquipment(uid),
helmet INTEGER REFERENCES WornEquipment(uid),
armour INTEGER REFERENCES WornEquipment(uid)
--etc.
); );
CREATE TABLE IF NOT EXISTS InventoryItems ( CREATE TABLE IF NOT EXISTS InventoryItems (
--metadata --metadata
uid INTEGER PRIMARY KEY AUTOINCREMENT, uid INTEGER PRIMARY KEY AUTOINCREMENT,
itemID INTEGER, --type owner INTEGER REFERENCES Characters(uid),
itemType INTEGER,
--unique information
stackSize INTEGER DEFAULT 0, stackSize INTEGER DEFAULT 0,
owner INTEGER REFERENCES Characters(uid) durability INTEGER DEFAULT 0,
stats INTEGER REFERENCES StatisticSets(uid)
); );
CREATE TABLE IF NOT EXISTS WornEquipment ( CREATE TABLE IF NOT EXISTS WornEquipment (
--metadata --metadata
uid INTEGER PRIMARY KEY AUTOINCREMENT, uid INTEGER PRIMARY KEY AUTOINCREMENT,
itemID INTEGER, --type owner INTEGER REFERENCES Characters(uid),
owner INTEGER REFERENCES Characters(uid) itemType INTEGER,
--hold all equipment info
--stat mods, special effects, etc. --unique information
); durability INTEGER DEFAULT 0,
stats INTEGER REFERENCES StatisticSets(uid)
--TODO: attached script?
);
+1 -53
View File
@@ -31,27 +31,7 @@
static const char* CREATE_CHARACTER = "INSERT INTO Characters (owner, handle, avatar) VALUES (?, ?, ?);"; 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* LOAD_CHARACTER = "SELECT * FROM Characters WHERE handle = ?;";
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET roomIndex = ?2, originX = ?3, originY = ?4 WHERE uid = ?1;";
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET "
"roomIndex = ?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 = ?;"; static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
//------------------------- //-------------------------
@@ -141,22 +121,6 @@ int CharacterManager::LoadCharacter(int owner, std::string handle, std::string a
newChar.origin.x = (double)sqlite3_column_int(statement, 6); newChar.origin.x = (double)sqlite3_column_int(statement, 6);
newChar.origin.y = (double)sqlite3_column_int(statement, 7); newChar.origin.y = (double)sqlite3_column_int(statement, 7);
//statistics
newChar.baseStats.level = sqlite3_column_int(statement, 8);
newChar.baseStats.exp = sqlite3_column_int(statement, 9);
newChar.baseStats.maxHP = sqlite3_column_int(statement, 10);
newChar.baseStats.health = sqlite3_column_int(statement, 11);
newChar.baseStats.maxMP = sqlite3_column_int(statement, 12);
newChar.baseStats.mana = sqlite3_column_int(statement, 13);
newChar.baseStats.attack = sqlite3_column_int(statement, 14);
newChar.baseStats.defence = sqlite3_column_int(statement, 15);
newChar.baseStats.intelligence = sqlite3_column_int(statement, 16);
newChar.baseStats.resistance = sqlite3_column_int(statement, 17);
newChar.baseStats.speed = sqlite3_column_int(statement, 18);
newChar.baseStats.accuracy = sqlite3_column_double(statement, 19);
newChar.baseStats.evasion = sqlite3_column_double(statement, 20);
newChar.baseStats.luck = sqlite3_column_double(statement, 21);
//gameplay components: equipment, items, buffs, debuffs... //gameplay components: equipment, items, buffs, debuffs...
//finish the routine //finish the routine
@@ -198,22 +162,6 @@ int CharacterManager::SaveCharacter(int uid) {
ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != 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; ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK;
//statistics
ret |= sqlite3_bind_int(statement, 5, character.baseStats.level) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 6, character.baseStats.exp) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 7, character.baseStats.maxHP) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 8, character.baseStats.health) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 9, character.baseStats.maxMP) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 10, character.baseStats.mana) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 11, character.baseStats.attack) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 12, character.baseStats.defence) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 13, character.baseStats.intelligence) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 14, character.baseStats.resistance) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 15, character.baseStats.speed) != SQLITE_OK;
ret |= sqlite3_bind_double(statement, 16, character.baseStats.accuracy) != SQLITE_OK;
ret |= sqlite3_bind_double(statement, 17, character.baseStats.evasion) != SQLITE_OK;
ret |= sqlite3_bind_double(statement, 18, character.baseStats.luck) != SQLITE_OK;
//gameplay components: equipment, items, buffs, debuffs... //gameplay components: equipment, items, buffs, debuffs...
//check for binding errors //check for binding errors
-2
View File
@@ -1,6 +1,5 @@
TODO: Get the rooms working, even if only via hotkeys TODO: Get the rooms working, even if only via hotkeys
TODO: Fix shoddy movement TODO: Fix shoddy movement
TODO: Move the statistics into their own SQL table, instead of duplicating the structure a dozen times
TODO: Remove the big "Shut Down" button TODO: Remove the big "Shut Down" button
TODO: Make a way for the server owner to control the server directly TODO: Make a way for the server owner to control the server directly
@@ -10,5 +9,4 @@ TODO: make the whole thing more fault tolerant
TODO: Authentication TODO: Authentication
TODO: Time delay for requesting region packets TODO: Time delay for requesting region packets
TODO: command line parameters overriding config.cfg settings
TODO: A proper logging system TODO: A proper logging system