Compare commits

...

5 Commits

Author SHA1 Message Date
luk3yx 914dbeaa0b
Add LevelDB auth database. (#9476)
* Add leveldb auth database.
2020-04-23 13:07:19 +02:00
SmallJoker ce5b0932f8
Camera: Fix shootline line offsets II (#9730) 2020-04-23 12:16:36 +02:00
Maksim 6ba44d7452
Android: add OpenGL ES 2 support (#9715)
.. and bump gradle to 3.6.3
2020-04-22 20:03:46 +02:00
HybridDog 5355cb1d87
minetest.serialize: Reversible number serialization (#9722)
* minetest.serialize: Reversible number to string conversion

The %a format is not supported in Lua 5.1.
This commit also adds two tests for number serialization.
2020-04-22 16:43:48 +02:00
HybridDog 4361bfcb4d
Fix configuration caching in log_deprecated (#9697)
* Fix configuration caching in log_deprecated

The configured variable was never set to true.
I've set the variables to thread_local because the configuration should be reloaded after reentering the world from mainmenu.
2020-04-22 00:07:12 +02:00
12 changed files with 166 additions and 31 deletions

View File

@ -63,8 +63,12 @@ task prepareAssets() {
copy {
from "${projRoot}/builtin" into "${assetsFolder}/builtin"
}
copy {
/*copy {
// ToDo: fix Minetest shaders that currently don't work with OpenGL ES
from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders"
}*/
copy {
from "../native/deps/Android/Irrlicht/shaders" into "${assetsFolder}/client/shaders/Irrlicht"
}
copy {
from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts"
@ -73,8 +77,7 @@ task prepareAssets() {
from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}"
}
/*copy {
// locales broken right now
// ToDo: fix it!
// ToDo: fix broken locales
from "${projRoot}/po" into "${assetsFolder}/po"
}*/
copy {

View File

@ -15,7 +15,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'org.ajoberstar.grgit:grgit-gradle:4.0.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -120,15 +120,8 @@ function core.serialize(x)
elseif tp == "function" then
return string.format("loadstring(%q)", string.dump(x))
elseif tp == "number" then
-- Serialize integers with string.format to prevent
-- scientific notation, which doesn't preserve
-- precision and breaks things like node position
-- hashes. Serialize floats normally.
if math.floor(x) == x then
return string.format("%d", x)
else
return tostring(x)
end
-- Serialize numbers reversibly with string.format
return string.format("%.17g", x)
elseif tp == "table" then
local vals = {}
local idx_dumped = {}

View File

@ -18,6 +18,18 @@ describe("serialize", function()
assert.same(test_in, test_out)
end)
it("handles precise numbers", function()
local test_in = 0.2695949158945771
local test_out = core.deserialize(core.serialize(test_in))
assert.same(test_in, test_out)
end)
it("handles big integers", function()
local test_in = 269594915894577
local test_out = core.deserialize(core.serialize(test_in))
assert.same(test_in, test_out)
end)
it("handles recursive structures", function()
local test_in = { hello = "world" }
test_in.foo = test_in

View File

@ -3029,7 +3029,6 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
{
LocalPlayer *player = client->getEnv().getLocalPlayer();
const v3f head_position = camera->getHeadPosition();
const v3f camera_direction = camera->getDirection();
const v3s16 camera_offset = camera->getOffset();
@ -3045,13 +3044,22 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
core::line3d<f32> shootline;
if (camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT) {
shootline = core::line3d<f32>(head_position,
head_position + camera_direction * BS * d);
} else {
switch (camera->getCameraMode()) {
case CAMERA_MODE_FIRST:
// Shoot from camera position, with bobbing
shootline.start = camera->getPosition();
break;
case CAMERA_MODE_THIRD:
// Shoot from player head, no bobbing
shootline.start = camera->getHeadPosition();
break;
case CAMERA_MODE_THIRD_FRONT:
shootline.start = camera->getHeadPosition();
// prevent player pointing anything in front-view
shootline = core::line3d<f32>(head_position, head_position);
d = 0;
break;
}
shootline.end = shootline.start + camera_direction * BS * d;
#ifdef HAVE_TOUCHSCREENGUI

View File

@ -130,12 +130,9 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
params.ZBufferBits = 24;
#ifdef __ANDROID__
// clang-format off
params.PrivateData = porting::app_global;
params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM + "media" +
DIR_DELIM + "Shaders" + DIR_DELIM).c_str();
// clang-format on
#elif ENABLE_GLES
#endif
#if ENABLE_GLES
// there is no standardized path for these on desktop
std::string rel_path = std::string("client") + DIR_DELIM
+ "shaders" + DIR_DELIM + "Irrlicht";

View File

@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "filesys.h"
#include "exceptions.h"
#include "util/serialize.h"
#include "util/string.h"
#include "leveldb/db.h"
@ -97,5 +98,100 @@ void Database_LevelDB::listAllLoadableBlocks(std::vector<v3s16> &dst)
delete it;
}
#endif // USE_LEVELDB
AuthDatabaseLevelDB::AuthDatabaseLevelDB(const std::string &savedir)
{
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options,
savedir + DIR_DELIM + "auth.db", &m_database);
ENSURE_STATUS_OK(status);
}
AuthDatabaseLevelDB::~AuthDatabaseLevelDB()
{
delete m_database;
}
bool AuthDatabaseLevelDB::getAuth(const std::string &name, AuthEntry &res)
{
std::string raw;
leveldb::Status s = m_database->Get(leveldb::ReadOptions(), name, &raw);
if (!s.ok())
return false;
std::istringstream is(raw);
/*
u8 version = 1
std::string password
u16 number of privileges
for each privilege {
std::string privilege
}
s64 last_login
*/
if (readU8(is) > 1)
return false;
res.id = 1;
res.name = name;
res.password = deSerializeString(is);
u16 privilege_count = readU16(is);
res.privileges.clear();
res.privileges.reserve(privilege_count);
for (u16 i = 0; i < privilege_count; i++) {
res.privileges.push_back(deSerializeString(is));
}
res.last_login = readS64(is);
return true;
}
bool AuthDatabaseLevelDB::saveAuth(const AuthEntry &authEntry)
{
std::ostringstream os;
writeU8(os, 1);
os << serializeString(authEntry.password);
size_t privilege_count = authEntry.privileges.size();
FATAL_ERROR_IF(privilege_count > U16_MAX,
"Unsupported number of privileges");
writeU16(os, privilege_count);
for (const std::string &privilege : authEntry.privileges) {
os << serializeString(privilege);
}
writeS64(os, authEntry.last_login);
leveldb::Status s = m_database->Put(leveldb::WriteOptions(),
authEntry.name, os.str());
return s.ok();
}
bool AuthDatabaseLevelDB::createAuth(AuthEntry &authEntry)
{
return saveAuth(authEntry);
}
bool AuthDatabaseLevelDB::deleteAuth(const std::string &name)
{
leveldb::Status s = m_database->Delete(leveldb::WriteOptions(), name);
return s.ok();
}
void AuthDatabaseLevelDB::listNames(std::vector<std::string> &res)
{
leveldb::Iterator* it = m_database->NewIterator(leveldb::ReadOptions());
res.clear();
for (it->SeekToFirst(); it->Valid(); it->Next()) {
res.emplace_back(it->key().ToString());
}
delete it;
}
void AuthDatabaseLevelDB::reload()
{
// No-op for LevelDB.
}
#endif // USE_LEVELDB

View File

@ -45,4 +45,21 @@ private:
leveldb::DB *m_database;
};
class AuthDatabaseLevelDB : public AuthDatabase
{
public:
AuthDatabaseLevelDB(const std::string &savedir);
virtual ~AuthDatabaseLevelDB();
virtual bool getAuth(const std::string &name, AuthEntry &res);
virtual bool saveAuth(const AuthEntry &authEntry);
virtual bool createAuth(AuthEntry &authEntry);
virtual bool deleteAuth(const std::string &name);
virtual void listNames(std::vector<std::string> &res);
virtual void reload();
private:
leveldb::DB *m_database;
};
#endif // USE_LEVELDB

View File

@ -157,9 +157,9 @@ static void script_log(lua_State *L, const std::string &message,
void log_deprecated(lua_State *L, const std::string &message, int stack_depth)
{
static bool configured = false;
static bool do_log = false;
static bool do_error = false;
static thread_local bool configured = false;
static thread_local bool do_log = false;
static thread_local bool do_error = false;
// Only read settings on first call
if (!configured) {
@ -167,9 +167,10 @@ void log_deprecated(lua_State *L, const std::string &message, int stack_depth)
if (value == "log") {
do_log = true;
} else if (value == "error") {
do_log = true;
do_log = true;
do_error = true;
}
configured = true;
}
if (do_log)

View File

@ -44,7 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// log([level,] text)
// Writes a line to the logger.
// The one-argument version logs to infostream.
// The one-argument version logs to LL_NONE.
// The two-argument version accepts a log level.
// Either the special case "deprecated" for deprecation notices, or any specified in
// Logger::stringToLevel(name).

View File

@ -37,7 +37,7 @@ private:
// log([level,] text)
// Writes a line to the logger.
// The one-argument version logs to infostream.
// The one-argument version logs to LL_NONE.
// The two-argument version accepts a log level.
static int l_log(lua_State *L);

View File

@ -44,6 +44,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#if USE_POSTGRESQL
#include "database/database-postgresql.h"
#endif
#if USE_LEVELDB
#include "database/database-leveldb.h"
#endif
#include "server/luaentity_sao.h"
#include "server/player_sao.h"
@ -2187,6 +2190,11 @@ AuthDatabase *ServerEnvironment::openAuthDatabase(
if (name == "files")
return new AuthDatabaseFiles(savedir);
#if USE_LEVELDB
if (name == "leveldb")
return new AuthDatabaseLevelDB(savedir);
#endif
throw BaseException(std::string("Database backend ") + name + " not supported.");
}