mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02:00
Make sure relevant std::stringstreams are set to binary
This commit is contained in:
@@ -70,11 +70,11 @@ bool Database_LevelDB::saveBlock(const v3s16 &pos, const std::string &data)
|
||||
|
||||
void Database_LevelDB::loadBlock(const v3s16 &pos, std::string *block)
|
||||
{
|
||||
std::string datastr;
|
||||
leveldb::Status status = m_database->Get(leveldb::ReadOptions(),
|
||||
i64tos(getBlockAsInteger(pos)), &datastr);
|
||||
i64tos(getBlockAsInteger(pos)), block);
|
||||
|
||||
*block = (status.ok()) ? datastr : "";
|
||||
if (!status.ok())
|
||||
block->clear();
|
||||
}
|
||||
|
||||
bool Database_LevelDB::deleteBlock(const v3s16 &pos)
|
||||
@@ -131,7 +131,7 @@ void PlayerDatabaseLevelDB::savePlayer(RemotePlayer *player)
|
||||
std::string (long) serialized_inventory
|
||||
*/
|
||||
|
||||
std::ostringstream os;
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
writeU8(os, 1);
|
||||
|
||||
PlayerSAO *sao = player->getPlayerSAO();
|
||||
@@ -142,7 +142,7 @@ void PlayerDatabaseLevelDB::savePlayer(RemotePlayer *player)
|
||||
writeF32(os, sao->getRotation().Y);
|
||||
writeU16(os, sao->getBreath());
|
||||
|
||||
StringMap stringvars = sao->getMeta().getStrings();
|
||||
const auto &stringvars = sao->getMeta().getStrings();
|
||||
writeU32(os, stringvars.size());
|
||||
for (const auto &it : stringvars) {
|
||||
os << serializeString16(it.first);
|
||||
@@ -170,7 +170,7 @@ bool PlayerDatabaseLevelDB::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
|
||||
player->getName(), &raw);
|
||||
if (!s.ok())
|
||||
return false;
|
||||
std::istringstream is(raw);
|
||||
std::istringstream is(raw, std::ios_base::binary);
|
||||
|
||||
if (readU8(is) > 1)
|
||||
return false;
|
||||
@@ -230,7 +230,7 @@ bool AuthDatabaseLevelDB::getAuth(const std::string &name, AuthEntry &res)
|
||||
leveldb::Status s = m_database->Get(leveldb::ReadOptions(), name, &raw);
|
||||
if (!s.ok())
|
||||
return false;
|
||||
std::istringstream is(raw);
|
||||
std::istringstream is(raw, std::ios_base::binary);
|
||||
|
||||
/*
|
||||
u8 version = 1
|
||||
@@ -262,7 +262,7 @@ bool AuthDatabaseLevelDB::getAuth(const std::string &name, AuthEntry &res)
|
||||
|
||||
bool AuthDatabaseLevelDB::saveAuth(const AuthEntry &authEntry)
|
||||
{
|
||||
std::ostringstream os;
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
writeU8(os, 1);
|
||||
os << serializeString16(authEntry.password);
|
||||
|
||||
|
@@ -274,10 +274,10 @@ void MapDatabasePostgreSQL::loadBlock(const v3s16 &pos, std::string *block)
|
||||
PGresult *results = execPrepared("read_block", ARRLEN(args), args,
|
||||
argLen, argFmt, false);
|
||||
|
||||
*block = "";
|
||||
|
||||
if (PQntuples(results))
|
||||
*block = std::string(PQgetvalue(results, 0, 0), PQgetlength(results, 0, 0));
|
||||
block->assign(PQgetvalue(results, 0, 0), PQgetlength(results, 0, 0));
|
||||
else
|
||||
block->clear();
|
||||
|
||||
PQclear(results);
|
||||
}
|
||||
@@ -496,6 +496,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
||||
execPrepared("remove_player_inventory_items", 1, rmvalues);
|
||||
|
||||
std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists();
|
||||
std::ostringstream oss;
|
||||
for (u16 i = 0; i < inventory_lists.size(); i++) {
|
||||
const InventoryList* list = inventory_lists[i];
|
||||
const std::string &name = list->getName();
|
||||
@@ -512,9 +513,10 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
||||
execPrepared("add_player_inventory", 5, inv_values);
|
||||
|
||||
for (u32 j = 0; j < list->getSize(); j++) {
|
||||
std::ostringstream os;
|
||||
list->getItem(j).serialize(os);
|
||||
std::string itemStr = os.str(), slotId = itos(j);
|
||||
oss.str("");
|
||||
oss.clear();
|
||||
list->getItem(j).serialize(oss);
|
||||
std::string itemStr = oss.str(), slotId = itos(j);
|
||||
|
||||
const char* invitem_values[] = {
|
||||
player->getName(),
|
||||
|
@@ -127,8 +127,7 @@ void Database_Redis::loadBlock(const v3s16 &pos, std::string *block)
|
||||
|
||||
switch (reply->type) {
|
||||
case REDIS_REPLY_STRING: {
|
||||
*block = std::string(reply->str, reply->len);
|
||||
// std::string copies the memory so this won't cause any problems
|
||||
block->assign(reply->str, reply->len);
|
||||
freeReplyObject(reply);
|
||||
return;
|
||||
}
|
||||
@@ -141,8 +140,7 @@ void Database_Redis::loadBlock(const v3s16 &pos, std::string *block)
|
||||
"Redis command 'HGET %s %s' errored: ") + errstr);
|
||||
}
|
||||
case REDIS_REPLY_NIL: {
|
||||
*block = "";
|
||||
// block not found in database
|
||||
block->clear();
|
||||
freeReplyObject(reply);
|
||||
return;
|
||||
}
|
||||
|
@@ -302,7 +302,10 @@ void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block)
|
||||
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) : "";
|
||||
if (data)
|
||||
block->assign(data, len);
|
||||
else
|
||||
block->clear();
|
||||
|
||||
sqlite3_step(m_stmt_read);
|
||||
// We should never get more than 1 row, so ok to reset
|
||||
@@ -491,6 +494,7 @@ void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player)
|
||||
sqlite3_reset(m_stmt_player_remove_inventory_items);
|
||||
|
||||
std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists();
|
||||
std::ostringstream oss;
|
||||
for (u16 i = 0; i < inventory_lists.size(); i++) {
|
||||
const InventoryList* list = inventory_lists[i];
|
||||
|
||||
@@ -503,9 +507,10 @@ void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player)
|
||||
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();
|
||||
oss.str("");
|
||||
oss.clear();
|
||||
list->getItem(j).serialize(oss);
|
||||
std::string itemStr = oss.str();
|
||||
|
||||
str_to_sqlite(m_stmt_player_add_inventory_items, 1, player->getName());
|
||||
int_to_sqlite(m_stmt_player_add_inventory_items, 2, i);
|
||||
|
Reference in New Issue
Block a user