diff --git a/common/utilities/config_utility.cpp b/common/utilities/config_utility.cpp index 93187b4..e6f9f39 100644 --- a/common/utilities/config_utility.cpp +++ b/common/utilities/config_utility.cpp @@ -41,12 +41,14 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { table_t redirectedFile; table_t cmdLineParams; char key[256], val[256]; + bool redirectUsed = false; //reading from the command line for (int i = 1; i < argc; ++i) { //read from a specified config file if (!strncmp(argv[i], "-config=", 8)) { redirectedFile = Read(argv[i] + 8); + redirectUsed = true; continue; } @@ -70,6 +72,9 @@ void ConfigUtility::Load(std::string fname, int argc, char* argv[]) { } //finally, construct the final config table + if (!redirectUsed) { + redirectedFile = Read(fname); + } configMap.insert(cmdLineParams.begin(), cmdLineParams.end()); configMap.insert(redirectedFile.begin(), redirectedFile.end()); } diff --git a/rsc/scripts/setup_server.sql b/rsc/scripts/setup_server.sql index 88d0a82..2484a04 100644 --- a/rsc/scripts/setup_server.sql +++ b/rsc/scripts/setup_server.sql @@ -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 ( uid INTEGER PRIMARY KEY AUTOINCREMENT, username varchar(100) UNIQUE, --TODO: server-client security --- password varchar(100), +-- passhash varchar(100), +-- passsalt varchar(100), blacklisted BIT DEFAULT 0, whitelisted BIT DEFAULT 1, mod BIT DEFAULT 0, @@ -22,12 +19,30 @@ CREATE TABLE IF NOT EXISTS Characters ( avatar varchar(100), birth timestamp NOT NULL DEFAULT (datetime()), - --position + --position in the world roomIndex INTEGER DEFAULT 0, originX INTEGER DEFAULT 0, originY INTEGER DEFAULT 0, --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, exp INTEGER DEFAULT 0, maxHP INTEGER DEFAULT 0, @@ -41,28 +56,29 @@ CREATE TABLE IF NOT EXISTS Characters ( speed INTEGER DEFAULT 0, accuracy REAL DEFAULT 0.0, evasion 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. + luck REAL DEFAULT 0.0 ); CREATE TABLE IF NOT EXISTS InventoryItems ( --metadata uid INTEGER PRIMARY KEY AUTOINCREMENT, - itemID INTEGER, --type + owner INTEGER REFERENCES Characters(uid), + itemType INTEGER, + + --unique information stackSize INTEGER DEFAULT 0, - owner INTEGER REFERENCES Characters(uid) + durability INTEGER DEFAULT 0, + stats INTEGER REFERENCES StatisticSets(uid) ); CREATE TABLE IF NOT EXISTS WornEquipment ( --metadata uid INTEGER PRIMARY KEY AUTOINCREMENT, - itemID INTEGER, --type - owner INTEGER REFERENCES Characters(uid) - --hold all equipment info - --stat mods, special effects, etc. -); \ No newline at end of file + owner INTEGER REFERENCES Characters(uid), + itemType INTEGER, + + --unique information + durability INTEGER DEFAULT 0, + stats INTEGER REFERENCES StatisticSets(uid) + --TODO: attached script? +); diff --git a/server/characters/character_manager.cpp b/server/characters/character_manager.cpp index f24378f..4d2078a 100644 --- a/server/characters/character_manager.cpp +++ b/server/characters/character_manager.cpp @@ -31,27 +31,7 @@ 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 " - "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* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET roomIndex = ?2, originX = ?3, originY = ?4 WHERE uid = ?1;"; 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.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... //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, 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... //check for binding errors diff --git a/todo.txt b/todo.txt index bef95f3..e4c83ea 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,5 @@ TODO: Get the rooms working, even if only via hotkeys 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: 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: Time delay for requesting region packets -TODO: command line parameters overriding config.cfg settings TODO: A proper logging system