aboutsummaryrefslogtreecommitdiff
path: root/src/client
ModeNameSize
-rw-r--r--CMakeLists.txt2526logplain
-rw-r--r--activeobjectmgr.cpp2910logplain
-rw-r--r--activeobjectmgr.h1332logplain
-rw-r--r--camera.cpp23686logplain
-rw-r--r--camera.h6805logplain
-rw-r--r--client.cpp52874logplain
-rw-r--r--client.h18880logplain
-rw-r--r--clientenvironment.cpp13454logplain
-rw-r--r--clientenvironment.h4183logplain
-rw-r--r--clientevent.h2829logplain
-rw-r--r--clientlauncher.cpp18670logplain
-rw-r--r--clientlauncher.h1598logplain
-rw-r--r--clientmap.cpp28927logplain
-rw-r--r--clientmap.h5464logplain
-rw-r--r--clientmedia.cpp22833logplain
-rw-r--r--clientmedia.h7388logplain
-rw-r--r--clientobject.cpp1694logplain
-rw-r--r--clientobject.h3559logplain
-rw-r--r--clientsimpleobject.h1052logplain
-rw-r--r--clouds.cpp11506logplain
-rw-r--r--clouds.h3075logplain
-rw-r--r--content_cao.cpp59761logplain
-rw-r--r--content_cao.h7504logplain
-rw-r--r--content_cso.cpp2574logplain
-rw-r--r--content_cso.h982logplain
-rw-r--r--content_mapblock.cpp49238logplain
-rw-r--r--content_mapblock.h4911logplain
-rw-r--r--event_manager.h2257logplain
-rw-r--r--filecache.cpp2445logplain
-rw-r--r--filecache.h1355logplain
-rw-r--r--fontengine.cpp7774logplain
-rw-r--r--fontengine.h4643logplain
-rw-r--r--game.cpp128731logplain
-rw-r--r--game.h1434logplain
-rw-r--r--gameui.cpp10380logplain
-rw-r--r--gameui.h3903logplain
-rw-r--r--guiscalingfilter.cpp7789logplain
-rw-r--r--guiscalingfilter.h2403logplain
-rw-r--r--hud.cpp40324logplain
-rw-r--r--hud.h4638logplain
-rw-r--r--imagefilters.cpp7626logplain
-rw-r--r--imagefilters.h1948logplain
-rw-r--r--inputhandler.cpp8826logplain
-rw-r--r--inputhandler.h9790logplain
-rw-r--r--joystick_controller.cpp9734logplain
-rw-r--r--joystick_controller.h3782logplain
-rw-r--r--keycode.cpp10185logplain
-rw-r--r--keycode.h1776logplain
-rw-r--r--keys.h1941logplain
-rw-r--r--localplayer.cpp34250logplain
-rw-r--r--localplayer.h6517logplain
-rw-r--r--mapblock_mesh.cpp42788logplain
-rw-r--r--mapblock_mesh.h8941logplain
-rw-r--r--mesh.cpp15990logplain
-rw-r--r--mesh.h4022logplain
-rw-r--r--mesh_generator_thread.cpp8113logplain
-rw-r--r--mesh_generator_thread.h3355logplain
d---------meshgen80logplain
-rw-r--r--minimap.cpp21225logplain
-rw-r--r--minimap.h4620logplain
-rw-r--r--particles.cpp15966logplain
-rw-r--r--particles.h4695logplain
d---------render612logplain
-rw-r--r--renderingengine.cpp19084logplain
-rw-r--r--renderingengine.h3636logplain
-rw-r--r--shader.cpp25186logplain
-rw-r--r--shader.h4401logplain
d---------shadows394logplain
-rw-r--r--sky.cpp32324logplain
-rw-r--r--sky.h7886logplain
-rw-r--r--sound.cpp880logplain
-rw-r--r--sound.h3597logplain
-rw-r--r--sound_openal.cpp18555logplain
-rw-r--r--sound_openal.h1114logplain
-rw-r--r--tile.cpp66649logplain
-rw-r--r--tile.h9623logplain
-rw-r--r--wieldmesh.cpp24490logplain
-rw-r--r--wieldmesh.h4198logplain
pt">(sqlite3_exec(m_database, query_str.c_str(), NULL, NULL, NULL), "Failed to modify sqlite3 synchronous mode"); SQLOK(sqlite3_exec(m_database, "PRAGMA foreign_keys = ON", NULL, NULL, NULL), "Failed to enable sqlite3 foreign key support"); } void Database_SQLite3::verifyDatabase() { if (m_initialized) return; openDatabase(); PREPARE_STATEMENT(begin, "BEGIN;"); PREPARE_STATEMENT(end, "COMMIT;"); initStatements(); m_initialized = true; } Database_SQLite3::~Database_SQLite3() { FINALIZE_STATEMENT(m_stmt_begin) FINALIZE_STATEMENT(m_stmt_end) SQLOK_ERRSTREAM(sqlite3_close(m_database), "Failed to close database"); } /* * Map database */ MapDatabaseSQLite3::MapDatabaseSQLite3(const std::string &savedir): Database_SQLite3(savedir, "map"), MapDatabase() { } MapDatabaseSQLite3::~MapDatabaseSQLite3() { FINALIZE_STATEMENT(m_stmt_read) FINALIZE_STATEMENT(m_stmt_write) FINALIZE_STATEMENT(m_stmt_list) FINALIZE_STATEMENT(m_stmt_delete) } void MapDatabaseSQLite3::createDatabase() { assert(m_database); // Pre-condition SQLOK(sqlite3_exec(m_database, "CREATE TABLE IF NOT EXISTS `blocks` (\n" " `pos` INT PRIMARY KEY,\n" " `data` BLOB\n" ");\n", NULL, NULL, NULL), "Failed to create database table"); } void MapDatabaseSQLite3::initStatements() { PREPARE_STATEMENT(read, "SELECT `data` FROM `blocks` WHERE `pos` = ? LIMIT 1"); #ifdef __ANDROID__ PREPARE_STATEMENT(write, "INSERT INTO `blocks` (`pos`, `data`) VALUES (?, ?)"); #else PREPARE_STATEMENT(write, "REPLACE INTO `blocks` (`pos`, `data`) VALUES (?, ?)"); #endif PREPARE_STATEMENT(delete, "DELETE FROM `blocks` WHERE `pos` = ?"); PREPARE_STATEMENT(list, "SELECT `pos` FROM `blocks`"); verbosestream << "ServerMap: SQLite3 database opened." << std::endl; } inline void MapDatabaseSQLite3::bindPos(sqlite3_stmt *stmt, const v3s16 &pos, int index) { SQLOK(sqlite3_bind_int64(stmt, index, getBlockAsInteger(pos)), "Internal error: failed to bind query at " __FILE__ ":" TOSTRING(__LINE__)); } bool MapDatabaseSQLite3::deleteBlock(const v3s16 &pos) { verifyDatabase(); bindPos(m_stmt_delete, pos); bool good = sqlite3_step(m_stmt_delete) == SQLITE_DONE; sqlite3_reset(m_stmt_delete); if (!good) { warningstream << "deleteBlock: Block failed to delete " << PP(pos) << ": " << sqlite3_errmsg(m_database) << std::endl; } return good; } bool MapDatabaseSQLite3::saveBlock(const v3s16 &pos, const std::string &data) { verifyDatabase(); #ifdef __ANDROID__ /** * Note: For some unknown reason SQLite3 fails to REPLACE blocks on Android, * deleting them and then inserting works. */ bindPos(m_stmt_read, pos); if (sqlite3_step(m_stmt_read) == SQLITE_ROW) { deleteBlock(pos); } sqlite3_reset(m_stmt_read); #endif bindPos(m_stmt_write, pos); SQLOK(sqlite3_bind_blob(m_stmt_write, 2, data.data(), data.size(), NULL), "Internal error: failed to bind query at " __FILE__ ":" TOSTRING(__LINE__)); SQLRES(sqlite3_step(m_stmt_write), SQLITE_DONE, "Failed to save block") sqlite3_reset(m_stmt_write); return true; } void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) { verifyDatabase(); bindPos(m_stmt_read, pos); if (sqlite3_step(m_stmt_read) != SQLITE_ROW) { sqlite3_reset(m_stmt_read); return; } const char *data = (const char *) sqlite3_column_blob(m_stmt_read, 0); size_t len = sqlite3_column_bytes(m_stmt_read, 0); *block = (data) ? std::string(data, len) : ""; sqlite3_step(m_stmt_read); // We should never get more than 1 row, so ok to reset sqlite3_reset(m_stmt_read); } void MapDatabaseSQLite3::listAllLoadableBlocks(std::vector<v3s16> &dst) { verifyDatabase(); while (sqlite3_step(m_stmt_list) == SQLITE_ROW) dst.push_back(getIntegerAsBlock(sqlite3_column_int64(m_stmt_list, 0))); sqlite3_reset(m_stmt_list); } /* * Player Database */ PlayerDatabaseSQLite3::PlayerDatabaseSQLite3(const std::string &savedir): Database_SQLite3(savedir, "players"), PlayerDatabase() { } PlayerDatabaseSQLite3::~PlayerDatabaseSQLite3() { FINALIZE_STATEMENT(m_stmt_player_load) FINALIZE_STATEMENT(m_stmt_player_add) FINALIZE_STATEMENT(m_stmt_player_update) FINALIZE_STATEMENT(m_stmt_player_remove) FINALIZE_STATEMENT(m_stmt_player_list) FINALIZE_STATEMENT(m_stmt_player_add_inventory) FINALIZE_STATEMENT(m_stmt_player_add_inventory_items) FINALIZE_STATEMENT(m_stmt_player_remove_inventory) FINALIZE_STATEMENT(m_stmt_player_remove_inventory_items) FINALIZE_STATEMENT(m_stmt_player_load_inventory) FINALIZE_STATEMENT(m_stmt_player_load_inventory_items) FINALIZE_STATEMENT(m_stmt_player_metadata_load) FINALIZE_STATEMENT(m_stmt_player_metadata_add) FINALIZE_STATEMENT(m_stmt_player_metadata_remove) }; void PlayerDatabaseSQLite3::createDatabase() { assert(m_database); // Pre-condition SQLOK(sqlite3_exec(m_database, "CREATE TABLE IF NOT EXISTS `player` (" "`name` VARCHAR(50) NOT NULL," "`pitch` NUMERIC(11, 4) NOT NULL," "`yaw` NUMERIC(11, 4) NOT NULL," "`posX` NUMERIC(11, 4) NOT NULL," "`posY` NUMERIC(11, 4) NOT NULL," "`posZ` NUMERIC(11, 4) NOT NULL," "`hp` INT NOT NULL," "`breath` INT NOT NULL," "`creation_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," "`modification_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," "PRIMARY KEY (`name`));", NULL, NULL, NULL), "Failed to create player table"); SQLOK(sqlite3_exec(m_database, "CREATE TABLE IF NOT EXISTS `player_metadata` (" " `player` VARCHAR(50) NOT NULL," " `metadata` VARCHAR(256) NOT NULL," " `value` TEXT," " PRIMARY KEY(`player`, `metadata`)," " FOREIGN KEY (`player`) REFERENCES player (`name`) ON DELETE CASCADE );", NULL, NULL, NULL), "Failed to create player metadata table"); SQLOK(sqlite3_exec(m_database, "CREATE TABLE IF NOT EXISTS `player_inventories` (" " `player` VARCHAR(50) NOT NULL," " `inv_id` INT NOT NULL," " `inv_width` INT NOT NULL," " `inv_name` TEXT NOT NULL DEFAULT ''," " `inv_size` INT NOT NULL," " PRIMARY KEY(player, inv_id)," " FOREIGN KEY (`player`) REFERENCES player (`name`) ON DELETE CASCADE );", NULL, NULL, NULL), "Failed to create player inventory table"); SQLOK(sqlite3_exec(m_database, "CREATE TABLE `player_inventory_items` (" " `player` VARCHAR(50) NOT NULL," " `inv_id` INT NOT NULL," " `slot_id` INT NOT NULL," " `item` TEXT NOT NULL DEFAULT ''," " PRIMARY KEY(player, inv_id, slot_id)," " FOREIGN KEY (`player`) REFERENCES player (`name`) ON DELETE CASCADE );", NULL, NULL, NULL), "Failed to create player inventory items table"); } void PlayerDatabaseSQLite3::initStatements() { PREPARE_STATEMENT(player_load, "SELECT `pitch`, `yaw`, `posX`, `posY`, `posZ`, `hp`, " "`breath`" "FROM `player` WHERE `name` = ?") PREPARE_STATEMENT(player_add, "INSERT INTO `player` (`name`, `pitch`, `yaw`, `posX`, " "`posY`, `posZ`, `hp`, `breath`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)") PREPARE_STATEMENT(player_update, "UPDATE `player` SET `pitch` = ?, `yaw` = ?, " "`posX` = ?, `posY` = ?, `posZ` = ?, `hp` = ?, `breath` = ?, " "`modification_date` = CURRENT_TIMESTAMP WHERE `name` = ?") PREPARE_STATEMENT(player_remove, "DELETE FROM `player` WHERE `name` = ?") PREPARE_STATEMENT(player_list, "SELECT `name` FROM `player`") PREPARE_STATEMENT(player_add_inventory, "INSERT INTO `player_inventories` " "(`player`, `inv_id`, `inv_width`, `inv_name`, `inv_size`) VALUES (?, ?, ?, ?, ?)") PREPARE_STATEMENT(player_add_inventory_items, "INSERT INTO `player_inventory_items` " "(`player`, `inv_id`, `slot_id`, `item`) VALUES (?, ?, ?, ?)") PREPARE_STATEMENT(player_remove_inventory, "DELETE FROM `player_inventories` " "WHERE `player` = ?") PREPARE_STATEMENT(player_remove_inventory_items, "DELETE FROM `player_inventory_items` " "WHERE `player` = ?") PREPARE_STATEMENT(player_load_inventory, "SELECT `inv_id`, `inv_width`, `inv_name`, " "`inv_size` FROM `player_inventories` WHERE `player` = ? ORDER BY inv_id") PREPARE_STATEMENT(player_load_inventory_items, "SELECT `slot_id`, `item` " "FROM `player_inventory_items` WHERE `player` = ? AND `inv_id` = ?") PREPARE_STATEMENT(player_metadata_load, "SELECT `metadata`, `value` FROM " "`player_metadata` WHERE `player` = ?") PREPARE_STATEMENT(player_metadata_add, "INSERT INTO `player_metadata` " "(`player`, `metadata`, `value`) VALUES (?, ?, ?)") PREPARE_STATEMENT(player_metadata_remove, "DELETE FROM `player_metadata` " "WHERE `player` = ?") verbosestream << "ServerEnvironment: SQLite3 database opened (players)." << std::endl; } bool PlayerDatabaseSQLite3::playerDataExists(const std::string &name) { verifyDatabase(); str_to_sqlite(m_stmt_player_load, 1, name); bool res = (sqlite3_step(m_stmt_player_load) == SQLITE_ROW); sqlite3_reset(m_stmt_player_load); return res; } void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player) { PlayerSAO* sao = player->getPlayerSAO(); sanity_check(sao); const v3f &pos = sao->getBasePosition(); // Begin save in brace is mandatory if (!playerDataExists(player->getName())) { beginSave(); str_to_sqlite(m_stmt_player_add, 1, player->getName()); double_to_sqlite(m_stmt_player_add, 2, sao->getPitch()); double_to_sqlite(m_stmt_player_add, 3, sao->getYaw()); double_to_sqlite(m_stmt_player_add, 4, pos.X); double_to_sqlite(m_stmt_player_add, 5, pos.Y); double_to_sqlite(m_stmt_player_add, 6, pos.Z); int64_to_sqlite(m_stmt_player_add, 7, sao->getHP()); int64_to_sqlite(m_stmt_player_add, 8, sao->getBreath()); sqlite3_vrfy(sqlite3_step(m_stmt_player_add), SQLITE_DONE); sqlite3_reset(m_stmt_player_add); } else { beginSave(); double_to_sqlite(m_stmt_player_update, 1, sao->getPitch()); double_to_sqlite(m_stmt_player_update, 2, sao->getYaw()); double_to_sqlite(m_stmt_player_update, 3, pos.X); double_to_sqlite(m_stmt_player_update, 4, pos.Y); double_to_sqlite(m_stmt_player_update, 5, pos.Z); int64_to_sqlite(m_stmt_player_update, 6, sao->getHP()); int64_to_sqlite(m_stmt_player_update, 7, sao->getBreath()); str_to_sqlite(m_stmt_player_update, 8, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_update), SQLITE_DONE); sqlite3_reset(m_stmt_player_update); } // Write player inventories str_to_sqlite(m_stmt_player_remove_inventory, 1, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_remove_inventory), SQLITE_DONE); sqlite3_reset(m_stmt_player_remove_inventory); str_to_sqlite(m_stmt_player_remove_inventory_items, 1, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_remove_inventory_items), SQLITE_DONE); sqlite3_reset(m_stmt_player_remove_inventory_items); std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists(); for (u16 i = 0; i < inventory_lists.size(); i++) { const InventoryList* list = inventory_lists[i]; str_to_sqlite(m_stmt_player_add_inventory, 1, player->getName()); int_to_sqlite(m_stmt_player_add_inventory, 2, i); int_to_sqlite(m_stmt_player_add_inventory, 3, list->getWidth()); str_to_sqlite(m_stmt_player_add_inventory, 4, list->getName()); int_to_sqlite(m_stmt_player_add_inventory, 5, list->getSize()); sqlite3_vrfy(sqlite3_step(m_stmt_player_add_inventory), SQLITE_DONE); sqlite3_reset(m_stmt_player_add_inventory); for (u32 j = 0; j < list->getSize(); j++) { std::ostringstream os; list->getItem(j).serialize(os); std::string itemStr = os.str(); str_to_sqlite(m_stmt_player_add_inventory_items, 1, player->getName()); int_to_sqlite(m_stmt_player_add_inventory_items, 2, i); int_to_sqlite(m_stmt_player_add_inventory_items, 3, j); str_to_sqlite(m_stmt_player_add_inventory_items, 4, itemStr); sqlite3_vrfy(sqlite3_step(m_stmt_player_add_inventory_items), SQLITE_DONE); sqlite3_reset(m_stmt_player_add_inventory_items); } } str_to_sqlite(m_stmt_player_metadata_remove, 1, player->getName()); sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_remove), SQLITE_DONE); sqlite3_reset(m_stmt_player_metadata_remove); const StringMap &attrs = sao->getMeta().getStrings(); for (const auto &attr : attrs) {