Compare commits
5 Commits
bbfae0cc67
...
b480a3e9fd
Author | SHA1 | Date |
---|---|---|
|
b480a3e9fd | |
|
75bf9b75ca | |
|
766e885a1b | |
|
7423c4c11e | |
|
2cefe51d3b |
|
@ -31,6 +31,21 @@ describe("vector", function()
|
|||
end)
|
||||
end)
|
||||
|
||||
it("zero()", function()
|
||||
assert.same({x = 0, y = 0, z = 0}, vector.zero())
|
||||
assert.same(vector.new(), vector.zero())
|
||||
assert.equal(vector.new(), vector.zero())
|
||||
assert.is_true(vector.check(vector.zero()))
|
||||
end)
|
||||
|
||||
it("copy()", function()
|
||||
local v = vector.new(1, 2, 3)
|
||||
assert.same(v, vector.copy(v))
|
||||
assert.same(vector.new(v), vector.copy(v))
|
||||
assert.equal(vector.new(v), vector.copy(v))
|
||||
assert.is_true(vector.check(vector.copy(v)))
|
||||
end)
|
||||
|
||||
it("indexes", function()
|
||||
local some_vector = vector.new(24, 42, 13)
|
||||
assert.equal(24, some_vector[1])
|
||||
|
@ -114,25 +129,25 @@ describe("vector", function()
|
|||
end)
|
||||
|
||||
it("equals()", function()
|
||||
local function assertE(a, b)
|
||||
assert.is_true(vector.equals(a, b))
|
||||
end
|
||||
local function assertNE(a, b)
|
||||
assert.is_false(vector.equals(a, b))
|
||||
end
|
||||
local function assertE(a, b)
|
||||
assert.is_true(vector.equals(a, b))
|
||||
end
|
||||
local function assertNE(a, b)
|
||||
assert.is_false(vector.equals(a, b))
|
||||
end
|
||||
|
||||
assertE({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
assertE({x = -1, y = 0, z = 1}, {x = -1, y = 0, z = 1})
|
||||
assertE({x = -1, y = 0, z = 1}, vector.new(-1, 0, 1))
|
||||
local a = {x = 2, y = 4, z = -10}
|
||||
assertE(a, a)
|
||||
assertNE({x = -1, y = 0, z = 1}, a)
|
||||
assertE({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
assertE({x = -1, y = 0, z = 1}, {x = -1, y = 0, z = 1})
|
||||
assertE({x = -1, y = 0, z = 1}, vector.new(-1, 0, 1))
|
||||
local a = {x = 2, y = 4, z = -10}
|
||||
assertE(a, a)
|
||||
assertNE({x = -1, y = 0, z = 1}, a)
|
||||
|
||||
assert.equal(vector.new(1, 2, 3), vector.new(1, 2, 3))
|
||||
assert.is_true(vector.new(1, 2, 3):equals(vector.new(1, 2, 3)))
|
||||
assert.not_equal(vector.new(1, 2, 3), vector.new(1, 2, 4))
|
||||
assert.is_true(vector.new(1, 2, 3) == vector.new(1, 2, 3))
|
||||
assert.is_false(vector.new(1, 2, 3) == vector.new(1, 3, 3))
|
||||
assert.equal(vector.new(1, 2, 3), vector.new(1, 2, 3))
|
||||
assert.is_true(vector.new(1, 2, 3):equals(vector.new(1, 2, 3)))
|
||||
assert.not_equal(vector.new(1, 2, 3), vector.new(1, 2, 4))
|
||||
assert.is_true(vector.new(1, 2, 3) == vector.new(1, 2, 3))
|
||||
assert.is_false(vector.new(1, 2, 3) == vector.new(1, 3, 3))
|
||||
end)
|
||||
|
||||
it("metatable is same", function()
|
||||
|
|
|
@ -30,16 +30,28 @@ local function fast_new(x, y, z)
|
|||
end
|
||||
|
||||
function vector.new(a, b, c)
|
||||
if type(a) == "table" then
|
||||
assert(a.x and a.y and a.z, "Invalid vector passed to vector.new()")
|
||||
return fast_new(a.x, a.y, a.z)
|
||||
elseif a then
|
||||
assert(b and c, "Invalid arguments for vector.new()")
|
||||
if a and b and c then
|
||||
return fast_new(a, b, c)
|
||||
end
|
||||
|
||||
-- deprecated, use vector.copy and vector.zero directly
|
||||
if type(a) == "table" then
|
||||
return vector.copy(a)
|
||||
else
|
||||
assert(not a, "Invalid arguments for vector.new()")
|
||||
return vector.zero()
|
||||
end
|
||||
end
|
||||
|
||||
function vector.zero()
|
||||
return fast_new(0, 0, 0)
|
||||
end
|
||||
|
||||
function vector.copy(v)
|
||||
assert(v.x and v.y and v.z, "Invalid vector passed to vector.copy()")
|
||||
return fast_new(v.x, v.y, v.z)
|
||||
end
|
||||
|
||||
function vector.from_string(s, init)
|
||||
local x, y, z, np = string.match(s, "^%s*%(%s*([^%s,]+)%s*[,%s]%s*([^%s,]+)%s*[,%s]" ..
|
||||
"%s*([^%s,]+)%s*[,%s]?%s*%)()", init)
|
||||
|
|
|
@ -3271,10 +3271,13 @@ For the following functions, `v`, `v1`, `v2` are vectors,
|
|||
vectors are written like this: `(x, y, z)`:
|
||||
|
||||
* `vector.new([a[, b, c]])`:
|
||||
* Returns a vector.
|
||||
* A copy of `a` if `a` is a vector.
|
||||
* `(a, b, c)`, if all of `a`, `b`, `c` are defined numbers.
|
||||
* `(0, 0, 0)`, if no arguments are given.
|
||||
* Returns a new vector `(a, b, c)`.
|
||||
* Deprecated: `vector.new()` does the same as `vector.zero()` and
|
||||
`vector.new(v)` does the same as `vector.copy(v)`
|
||||
* `vector.zero()`:
|
||||
* Returns a new vector `(0, 0, 0)`.
|
||||
* `vector.copy(v)`:
|
||||
* Returns a copy of the vector `v`.
|
||||
* `vector.from_string(s[, init])`:
|
||||
* Returns `v, np`, where `v` is a vector read from the given string `s` and
|
||||
`np` is the next position in the string after the vector.
|
||||
|
|
|
@ -1693,13 +1693,13 @@ float Client::mediaReceiveProgress()
|
|||
return 1.0; // downloader only exists when not yet done
|
||||
}
|
||||
|
||||
typedef struct TextureUpdateArgs {
|
||||
struct TextureUpdateArgs {
|
||||
gui::IGUIEnvironment *guienv;
|
||||
u64 last_time_ms;
|
||||
u16 last_percent;
|
||||
const wchar_t* text_base;
|
||||
ITextureSource *tsrc;
|
||||
} TextureUpdateArgs;
|
||||
};
|
||||
|
||||
void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progress)
|
||||
{
|
||||
|
@ -1718,8 +1718,8 @@ void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progres
|
|||
|
||||
if (do_draw) {
|
||||
targs->last_time_ms = time_ms;
|
||||
std::basic_stringstream<wchar_t> strm;
|
||||
strm << targs->text_base << " " << targs->last_percent << "%...";
|
||||
std::wostringstream strm;
|
||||
strm << targs->text_base << L" " << targs->last_percent << L"%...";
|
||||
m_rendering_engine->draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0,
|
||||
72 + (u16) ((18. / 100.) * (double) targs->last_percent), true);
|
||||
}
|
||||
|
|
|
@ -325,6 +325,10 @@ public:
|
|||
m_access_denied = true;
|
||||
m_access_denied_reason = reason;
|
||||
}
|
||||
inline void setFatalError(const LuaError &e)
|
||||
{
|
||||
setFatalError(std::string("Lua :") + e.what());
|
||||
}
|
||||
|
||||
// Renaming accessDeniedReason to better name could be good as it's used to
|
||||
// disconnect client when CSM failed.
|
||||
|
|
|
@ -1618,7 +1618,7 @@ bool Game::getServerContent(bool *aborted)
|
|||
dtime, progress);
|
||||
delete[] text;
|
||||
} else {
|
||||
std::stringstream message;
|
||||
std::ostringstream message;
|
||||
std::fixed(message);
|
||||
message.precision(0);
|
||||
float receive = client->mediaReceiveProgress() * 100;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -647,7 +647,7 @@ MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata,
|
|||
m_server->getScriptIface()->environment_OnGenerated(
|
||||
minp, maxp, m_mapgen->blockseed);
|
||||
} catch (LuaError &e) {
|
||||
m_server->setAsyncFatalError("Lua: finishGen" + std::string(e.what()));
|
||||
m_server->setAsyncFatalError(e);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -729,7 +729,6 @@ void GUIChatConsole::middleClick(s32 col, s32 row)
|
|||
msg << gettext("Failed to open webpage");
|
||||
}
|
||||
msg << " '" << weblink << "'";
|
||||
msg.flush();
|
||||
m_chat_backend->addUnparsedMessage(utf8_to_wide(msg.str()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3933,9 +3933,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode)
|
|||
}
|
||||
|
||||
if (e != 0) {
|
||||
std::stringstream ss;
|
||||
ss << (e->getActiveTab() +1);
|
||||
fields[name] = ss.str();
|
||||
fields[name] = itos(e->getActiveTab() + 1);
|
||||
}
|
||||
} else if (s.ftype == f_CheckBox) {
|
||||
// No dynamic cast possible due to some distributions shipped
|
||||
|
@ -3961,12 +3959,10 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode)
|
|||
e = static_cast<GUIScrollBar *>(element);
|
||||
|
||||
if (e) {
|
||||
std::stringstream os;
|
||||
os << e->getPos();
|
||||
if (s.fdefault == L"Changed")
|
||||
fields[name] = "CHG:" + os.str();
|
||||
fields[name] = "CHG:" + itos(e->getPos());
|
||||
else
|
||||
fields[name] = "VAL:" + os.str();
|
||||
fields[name] = "VAL:" + itos(e->getPos());
|
||||
}
|
||||
} else if (s.ftype == f_AnimatedImage) {
|
||||
// No dynamic cast possible due to some distributions shipped
|
||||
|
|
|
@ -460,7 +460,6 @@ void InventoryList::deSerialize(std::istream &is)
|
|||
std::getline(is, line, '\n');
|
||||
|
||||
std::istringstream iss(line);
|
||||
//iss.imbue(std::locale("C"));
|
||||
|
||||
std::string name;
|
||||
std::getline(iss, name, ' ');
|
||||
|
|
|
@ -60,7 +60,7 @@ bool ItemStackMetadata::setString(const std::string &name, const std::string &va
|
|||
|
||||
void ItemStackMetadata::serialize(std::ostream &os) const
|
||||
{
|
||||
std::ostringstream os2;
|
||||
std::ostringstream os2(std::ios_base::binary);
|
||||
os2 << DESERIALIZE_START;
|
||||
for (const auto &stringvar : m_stringvars) {
|
||||
if (!stringvar.first.empty() || !stringvar.second.empty())
|
||||
|
|
|
@ -261,7 +261,7 @@ void Client::handleCommand_NodemetaChanged(NetworkPacket *pkt)
|
|||
return;
|
||||
|
||||
std::istringstream is(pkt->readLongString(), std::ios::binary);
|
||||
std::stringstream sstr;
|
||||
std::stringstream sstr(std::ios::binary | std::ios::in | std::ios::out);
|
||||
decompressZlib(is, sstr);
|
||||
|
||||
NodeMetadataList meta_updates_list(false);
|
||||
|
@ -760,12 +760,11 @@ void Client::handleCommand_NodeDef(NetworkPacket* pkt)
|
|||
|
||||
// Decompress node definitions
|
||||
std::istringstream tmp_is(pkt->readLongString(), std::ios::binary);
|
||||
std::ostringstream tmp_os;
|
||||
std::stringstream tmp_os(std::ios::binary | std::ios::in | std::ios::out);
|
||||
decompressZlib(tmp_is, tmp_os);
|
||||
|
||||
// Deserialize node definitions
|
||||
std::istringstream tmp_is2(tmp_os.str());
|
||||
m_nodedef->deSerialize(tmp_is2);
|
||||
m_nodedef->deSerialize(tmp_os);
|
||||
m_nodedef_received = true;
|
||||
}
|
||||
|
||||
|
@ -780,12 +779,11 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt)
|
|||
|
||||
// Decompress item definitions
|
||||
std::istringstream tmp_is(pkt->readLongString(), std::ios::binary);
|
||||
std::ostringstream tmp_os;
|
||||
std::stringstream tmp_os(std::ios::binary | std::ios::in | std::ios::out);
|
||||
decompressZlib(tmp_is, tmp_os);
|
||||
|
||||
// Deserialize node definitions
|
||||
std::istringstream tmp_is2(tmp_os.str());
|
||||
m_itemdef->deSerialize(tmp_is2);
|
||||
m_itemdef->deSerialize(tmp_os);
|
||||
m_itemdef_received = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,13 +113,13 @@ int NodeMetadata::countNonPrivate() const
|
|||
*/
|
||||
|
||||
void NodeMetadataList::serialize(std::ostream &os, u8 blockver, bool disk,
|
||||
bool absolute_pos) const
|
||||
bool absolute_pos, bool include_empty) const
|
||||
{
|
||||
/*
|
||||
Version 0 is a placeholder for "nothing to see here; go away."
|
||||
*/
|
||||
|
||||
u16 count = countNonEmpty();
|
||||
u16 count = include_empty ? m_data.size() : countNonEmpty();
|
||||
if (count == 0) {
|
||||
writeU8(os, 0); // version
|
||||
return;
|
||||
|
@ -134,7 +134,7 @@ void NodeMetadataList::serialize(std::ostream &os, u8 blockver, bool disk,
|
|||
i != m_data.end(); ++i) {
|
||||
v3s16 p = i->first;
|
||||
NodeMetadata *data = i->second;
|
||||
if (data->empty())
|
||||
if (!include_empty && data->empty())
|
||||
continue;
|
||||
|
||||
if (absolute_pos) {
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
~NodeMetadataList();
|
||||
|
||||
void serialize(std::ostream &os, u8 blockver, bool disk = true,
|
||||
bool absolute_pos = false) const;
|
||||
bool absolute_pos = false, bool include_empty = false) const;
|
||||
void deSerialize(std::istream &is, IItemDefManager *item_def_mgr,
|
||||
bool absolute_pos = false);
|
||||
|
||||
|
|
|
@ -76,10 +76,7 @@ static void set_vector_metatable(lua_State *L)
|
|||
|
||||
void push_float_string(lua_State *L, float value)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::string str;
|
||||
ss << value;
|
||||
str = ss.str();
|
||||
auto str = ftos(value);
|
||||
lua_pushstring(L, str.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -101,42 +101,6 @@ void script_error(lua_State *L, int pcall_result, const char *mod, const char *f
|
|||
throw LuaError(err_msg);
|
||||
}
|
||||
|
||||
// Push the list of callbacks (a lua table).
|
||||
// Then push nargs arguments.
|
||||
// Then call this function, which
|
||||
// - runs the callbacks
|
||||
// - replaces the table and arguments with the return value,
|
||||
// computed depending on mode
|
||||
void script_run_callbacks_f(lua_State *L, int nargs,
|
||||
RunCallbacksMode mode, const char *fxn)
|
||||
{
|
||||
FATAL_ERROR_IF(lua_gettop(L) < nargs + 1, "Not enough arguments");
|
||||
|
||||
// Insert error handler
|
||||
PUSH_ERROR_HANDLER(L);
|
||||
int error_handler = lua_gettop(L) - nargs - 1;
|
||||
lua_insert(L, error_handler);
|
||||
|
||||
// Insert run_callbacks between error handler and table
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "run_callbacks");
|
||||
lua_remove(L, -2);
|
||||
lua_insert(L, error_handler + 1);
|
||||
|
||||
// Insert mode after table
|
||||
lua_pushnumber(L, (int) mode);
|
||||
lua_insert(L, error_handler + 3);
|
||||
|
||||
// Stack now looks like this:
|
||||
// ... <error handler> <run_callbacks> <table> <mode> <arg#1> <arg#2> ... <arg#n>
|
||||
|
||||
int result = lua_pcall(L, nargs + 2, 1, error_handler);
|
||||
if (result != 0)
|
||||
script_error(L, result, NULL, fxn);
|
||||
|
||||
lua_remove(L, error_handler);
|
||||
}
|
||||
|
||||
static void script_log_add_source(lua_State *L, std::string &message, int stack_depth)
|
||||
{
|
||||
lua_Debug ar;
|
||||
|
|
|
@ -75,9 +75,6 @@ extern "C" {
|
|||
} \
|
||||
}
|
||||
|
||||
#define script_run_callbacks(L, nargs, mode) \
|
||||
script_run_callbacks_f((L), (nargs), (mode), __FUNCTION__)
|
||||
|
||||
// What script_run_callbacks does with the return values of callbacks.
|
||||
// Regardless of the mode, if only one callback is defined,
|
||||
// its return value is the total return value.
|
||||
|
@ -108,16 +105,17 @@ enum RunCallbacksMode
|
|||
// are converted by readParam<bool> to true or false, respectively.
|
||||
};
|
||||
|
||||
// Gets a backtrace of the current execution point
|
||||
std::string script_get_backtrace(lua_State *L);
|
||||
// Wrapper for CFunction calls that converts C++ exceptions to Lua errors
|
||||
int script_exception_wrapper(lua_State *L, lua_CFunction f);
|
||||
// Takes an error from lua_pcall and throws it as a LuaError
|
||||
void script_error(lua_State *L, int pcall_result, const char *mod, const char *fxn);
|
||||
void script_run_callbacks_f(lua_State *L, int nargs,
|
||||
RunCallbacksMode mode, const char *fxn);
|
||||
|
||||
bool script_log_unique(lua_State *L, std::string message, std::ostream &log_to,
|
||||
int stack_depth = 1);
|
||||
|
||||
enum class DeprecatedHandlingMode {
|
||||
enum DeprecatedHandlingMode {
|
||||
Ignore,
|
||||
Log,
|
||||
Error
|
||||
|
|
|
@ -128,8 +128,11 @@ protected:
|
|||
lua_State* getStack()
|
||||
{ return m_luastack; }
|
||||
|
||||
// Checks that stack size is sane
|
||||
void realityCheck();
|
||||
// Takes an error from lua_pcall and throws it as a LuaError
|
||||
void scriptError(int result, const char *fxn);
|
||||
// Dumps stack contents for debugging
|
||||
void stackDump(std::ostream &o);
|
||||
|
||||
void setGameDef(IGameDef* gamedef) { m_gamedef = gamedef; }
|
||||
|
|
|
@ -33,7 +33,11 @@ void ScriptApiClient::on_mods_loaded()
|
|||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_mods_loaded");
|
||||
// Call callbacks
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
try {
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptApiClient::on_shutdown()
|
||||
|
@ -44,7 +48,11 @@ void ScriptApiClient::on_shutdown()
|
|||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_shutdown");
|
||||
// Call callbacks
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
try {
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_sending_message(const std::string &message)
|
||||
|
@ -56,7 +64,12 @@ bool ScriptApiClient::on_sending_message(const std::string &message)
|
|||
lua_getfield(L, -1, "registered_on_sending_chat_message");
|
||||
// Call callbacks
|
||||
lua_pushstring(L, message.c_str());
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
|
@ -69,7 +82,12 @@ bool ScriptApiClient::on_receiving_message(const std::string &message)
|
|||
lua_getfield(L, -1, "registered_on_receiving_chat_message");
|
||||
// Call callbacks
|
||||
lua_pushstring(L, message.c_str());
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
|
@ -82,7 +100,11 @@ void ScriptApiClient::on_damage_taken(int32_t damage_amount)
|
|||
lua_getfield(L, -1, "registered_on_damage_taken");
|
||||
// Call callbacks
|
||||
lua_pushinteger(L, damage_amount);
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptApiClient::on_hp_modification(int32_t newhp)
|
||||
|
@ -94,7 +116,11 @@ void ScriptApiClient::on_hp_modification(int32_t newhp)
|
|||
lua_getfield(L, -1, "registered_on_hp_modification");
|
||||
// Call callbacks
|
||||
lua_pushinteger(L, newhp);
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptApiClient::on_death()
|
||||
|
@ -105,7 +131,11 @@ void ScriptApiClient::on_death()
|
|||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_death");
|
||||
// Call callbacks
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
try {
|
||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptApiClient::environment_step(float dtime)
|
||||
|
@ -120,8 +150,7 @@ void ScriptApiClient::environment_step(float dtime)
|
|||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(std::string("Client environment_step: ") + e.what() + "\n"
|
||||
+ script_get_backtrace(L));
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +175,11 @@ void ScriptApiClient::on_formspec_input(const std::string &formname,
|
|||
lua_pushlstring(L, value.c_str(), value.size());
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
|
||||
|
@ -164,7 +197,12 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
|
|||
pushnode(L, node, ndef);
|
||||
|
||||
// Call functions
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return lua_toboolean(L, -1);
|
||||
}
|
||||
|
||||
|
@ -183,7 +221,12 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)
|
|||
pushnode(L, node, ndef);
|
||||
|
||||
// Call functions
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
|
@ -200,7 +243,12 @@ bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefini
|
|||
push_item_definition(L, item);
|
||||
|
||||
// Call functions
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
|
@ -217,7 +265,12 @@ bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &poi
|
|||
push_pointed_thing(L, pointed, true);
|
||||
|
||||
// Call functions
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
|
@ -238,7 +291,12 @@ bool ScriptApiClient::on_inventory_open(Inventory *inventory)
|
|||
lua_rawset(L, -3);
|
||||
}
|
||||
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_OR);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,13 +53,7 @@ void ScriptApiEnv::environment_Step(float dtime)
|
|||
lua_getfield(L, -1, "registered_globalsteps");
|
||||
// Call callbacks
|
||||
lua_pushnumber(L, dtime);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getServer()->setAsyncFatalError(
|
||||
std::string("environment_Step: ") + e.what() + "\n"
|
||||
+ script_get_backtrace(L));
|
||||
}
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
||||
void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &type)
|
||||
|
@ -76,13 +70,7 @@ void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &t
|
|||
// Call callbacks
|
||||
objectrefGetOrCreate(L, player); // player
|
||||
lua_pushstring(L,type.c_str()); // event type
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getServer()->setAsyncFatalError(
|
||||
std::string("player_event: ") + e.what() + "\n"
|
||||
+ script_get_backtrace(L) );
|
||||
}
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
||||
void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
|
||||
|
@ -257,9 +245,8 @@ void ScriptApiEnv::on_emerge_area_completion(
|
|||
try {
|
||||
PCALL_RES(lua_pcall(L, 4, 0, error_handler));
|
||||
} catch (LuaError &e) {
|
||||
server->setAsyncFatalError(
|
||||
std::string("on_emerge_area_completion: ") + e.what() + "\n"
|
||||
+ script_get_backtrace(L));
|
||||
// Note: don't throw here, we still need to run the cleanup code below
|
||||
server->setAsyncFatalError(e);
|
||||
}
|
||||
|
||||
lua_pop(L, 1); // Pop error handler
|
||||
|
@ -300,4 +287,4 @@ void ScriptApiEnv::on_liquid_transformed(
|
|||
}
|
||||
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "inventory.h"
|
||||
#include "inventorymanager.h"
|
||||
|
||||
#define WRAP_LUAERROR(e, detail) \
|
||||
LuaError(std::string(__FUNCTION__) + ": " + (e).what() + ". " detail)
|
||||
|
||||
bool ScriptApiItem::item_OnDrop(ItemStack &item,
|
||||
ServerActiveObject *dropper, v3f pos)
|
||||
{
|
||||
|
@ -49,7 +52,7 @@ bool ScriptApiItem::item_OnDrop(ItemStack &item,
|
|||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
|
@ -81,7 +84,7 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
|
|||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
|
@ -108,7 +111,7 @@ bool ScriptApiItem::item_OnUse(ItemStack &item,
|
|||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
|
@ -133,7 +136,7 @@ bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item,
|
|||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
|
@ -165,7 +168,7 @@ bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user,
|
|||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
|
@ -197,7 +200,7 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
|
|||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
|
|
|
@ -43,7 +43,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(
|
|||
return 0;
|
||||
|
||||
// Push callback function on stack
|
||||
std::string nodename = ndef->get(node).name;
|
||||
const auto &nodename = ndef->get(node).name;
|
||||
if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_move", &ma.to_inv.p))
|
||||
return count;
|
||||
|
||||
|
@ -58,7 +58,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(
|
|||
PCALL_RES(lua_pcall(L, 7, 1, error_handler));
|
||||
if (!lua_isnumber(L, -1))
|
||||
throw LuaError("allow_metadata_inventory_move should"
|
||||
" return a number, guilty node: " + nodename);
|
||||
" return a number. node=" + nodename);
|
||||
int num = luaL_checkinteger(L, -1);
|
||||
lua_pop(L, 2); // Pop integer and error handler
|
||||
return num;
|
||||
|
@ -81,7 +81,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(
|
|||
return 0;
|
||||
|
||||
// Push callback function on stack
|
||||
std::string nodename = ndef->get(node).name;
|
||||
const auto &nodename = ndef->get(node).name;
|
||||
if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_put", &ma.to_inv.p))
|
||||
return stack.count;
|
||||
|
||||
|
@ -94,7 +94,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(
|
|||
PCALL_RES(lua_pcall(L, 5, 1, error_handler));
|
||||
if(!lua_isnumber(L, -1))
|
||||
throw LuaError("allow_metadata_inventory_put should"
|
||||
" return a number, guilty node: " + nodename);
|
||||
" return a number. node=" + nodename);
|
||||
int num = luaL_checkinteger(L, -1);
|
||||
lua_pop(L, 2); // Pop integer and error handler
|
||||
return num;
|
||||
|
@ -117,7 +117,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(
|
|||
return 0;
|
||||
|
||||
// Push callback function on stack
|
||||
std::string nodename = ndef->get(node).name;
|
||||
const auto &nodename = ndef->get(node).name;
|
||||
if (!getItemCallback(nodename.c_str(), "allow_metadata_inventory_take", &ma.from_inv.p))
|
||||
return stack.count;
|
||||
|
||||
|
@ -130,7 +130,7 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(
|
|||
PCALL_RES(lua_pcall(L, 5, 1, error_handler));
|
||||
if (!lua_isnumber(L, -1))
|
||||
throw LuaError("allow_metadata_inventory_take should"
|
||||
" return a number, guilty node: " + nodename);
|
||||
" return a number. node=" + nodename);
|
||||
int num = luaL_checkinteger(L, -1);
|
||||
lua_pop(L, 2); // Pop integer and error handler
|
||||
return num;
|
||||
|
@ -153,7 +153,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove(
|
|||
return;
|
||||
|
||||
// Push callback function on stack
|
||||
std::string nodename = ndef->get(node).name;
|
||||
const auto &nodename = ndef->get(node).name;
|
||||
if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_move", &ma.from_inv.p))
|
||||
return;
|
||||
|
||||
|
@ -186,7 +186,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut(
|
|||
return;
|
||||
|
||||
// Push callback function on stack
|
||||
std::string nodename = ndef->get(node).name;
|
||||
const auto &nodename = ndef->get(node).name;
|
||||
if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_put", &ma.to_inv.p))
|
||||
return;
|
||||
|
||||
|
@ -217,7 +217,7 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake(
|
|||
return;
|
||||
|
||||
// Push callback function on stack
|
||||
std::string nodename = ndef->get(node).name;
|
||||
const auto &nodename = ndef->get(node).name;
|
||||
if (!getItemCallback(nodename.c_str(), "on_metadata_inventory_take", &ma.from_inv.p))
|
||||
return;
|
||||
|
||||
|
|
|
@ -752,9 +752,7 @@ int ModApiMapgen::l_get_mapgen_params(lua_State *L)
|
|||
lua_setfield(L, -2, "mgname");
|
||||
|
||||
settingsmgr->getMapSetting("seed", &value);
|
||||
std::istringstream ss(value);
|
||||
u64 seed;
|
||||
ss >> seed;
|
||||
u64 seed = from_string<u64>(value);
|
||||
lua_pushinteger(L, seed);
|
||||
lua_setfield(L, -2, "seed");
|
||||
|
||||
|
|
|
@ -272,11 +272,11 @@ int ModApiUtil::l_compress(lua_State *L)
|
|||
const char *data = luaL_checklstring(L, 1, &size);
|
||||
|
||||
int level = -1;
|
||||
if (!lua_isnone(L, 3) && !lua_isnil(L, 3))
|
||||
level = readParam<float>(L, 3);
|
||||
if (!lua_isnoneornil(L, 3))
|
||||
level = readParam<int>(L, 3);
|
||||
|
||||
std::ostringstream os;
|
||||
compressZlib(std::string(data, size), os, level);
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
compressZlib(reinterpret_cast<const u8 *>(data), size, os, level);
|
||||
|
||||
std::string out = os.str();
|
||||
|
||||
|
@ -292,8 +292,8 @@ int ModApiUtil::l_decompress(lua_State *L)
|
|||
size_t size;
|
||||
const char *data = luaL_checklstring(L, 1, &size);
|
||||
|
||||
std::istringstream is(std::string(data, size));
|
||||
std::ostringstream os;
|
||||
std::istringstream is(std::string(data, size), std::ios_base::binary);
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
decompressZlib(is, os);
|
||||
|
||||
std::string out = os.str();
|
||||
|
|
|
@ -103,7 +103,13 @@ void *ServerThread::run()
|
|||
* doesn't busy wait) and will process any remaining packets.
|
||||
*/
|
||||
|
||||
m_server->AsyncRunStep(true);
|
||||
try {
|
||||
m_server->AsyncRunStep(true);
|
||||
} catch (con::ConnectionBindFailed &e) {
|
||||
m_server->setAsyncFatalError(e.what());
|
||||
} catch (LuaError &e) {
|
||||
m_server->setAsyncFatalError(e);
|
||||
}
|
||||
|
||||
while (!stopRequested()) {
|
||||
try {
|
||||
|
@ -117,8 +123,7 @@ void *ServerThread::run()
|
|||
} catch (con::ConnectionBindFailed &e) {
|
||||
m_server->setAsyncFatalError(e.what());
|
||||
} catch (LuaError &e) {
|
||||
m_server->setAsyncFatalError(
|
||||
"ServerThread::run Lua: " + std::string(e.what()));
|
||||
m_server->setAsyncFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2320,7 +2325,7 @@ void Server::sendMetadataChanged(const std::list<v3s16> &meta_updates, float far
|
|||
|
||||
// Send the meta changes
|
||||
std::ostringstream os(std::ios::binary);
|
||||
meta_updates_list.serialize(os, client->net_proto_version, false, true);
|
||||
meta_updates_list.serialize(os, client->serialization_version, false, true, true);
|
||||
std::ostringstream oss(std::ios::binary);
|
||||
compressZlib(os.str(), oss);
|
||||
|
||||
|
|
|
@ -300,6 +300,10 @@ public:
|
|||
|
||||
inline void setAsyncFatalError(const std::string &error)
|
||||
{ m_async_fatal_error.set(error); }
|
||||
inline void setAsyncFatalError(const LuaError &e)
|
||||
{
|
||||
setAsyncFatalError(std::string("Lua: ") + e.what());
|
||||
}
|
||||
|
||||
bool showFormspec(const char *name, const std::string &formspec, const std::string &formname);
|
||||
Map & getMap() { return m_env->getMap(); }
|
||||
|
|
|
@ -537,11 +537,8 @@ float Settings::getFloat(const std::string &name) const
|
|||
|
||||
u64 Settings::getU64(const std::string &name) const
|
||||
{
|
||||
u64 value = 0;
|
||||
std::string s = get(name);
|
||||
std::istringstream ss(s);
|
||||
ss >> value;
|
||||
return value;
|
||||
return from_string<u64>(s);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ void TestAreaStore::testSerialization()
|
|||
b.data = "Area BB";
|
||||
store.insertArea(&b);
|
||||
|
||||
std::ostringstream os;
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
store.serialize(os);
|
||||
std::string str = os.str();
|
||||
|
||||
|
@ -157,7 +157,7 @@ void TestAreaStore::testSerialization()
|
|||
|
||||
UASSERTEQ(const std::string &, str, str_wanted);
|
||||
|
||||
std::istringstream is(str);
|
||||
std::istringstream is(str, std::ios_base::binary);
|
||||
store.deserialize(is);
|
||||
|
||||
// deserialize() doesn't clear the store
|
||||
|
|
|
@ -248,7 +248,7 @@ std::string serializeJsonStringIfNeeded(const std::string &s)
|
|||
|
||||
std::string deSerializeJsonStringIfNeeded(std::istream &is)
|
||||
{
|
||||
std::ostringstream tmp_os;
|
||||
std::stringstream tmp_os(std::ios_base::binary | std::ios_base::in | std::ios_base::out);
|
||||
bool expect_initial_quote = true;
|
||||
bool is_json = false;
|
||||
bool was_backslash = false;
|
||||
|
@ -280,8 +280,7 @@ std::string deSerializeJsonStringIfNeeded(std::istream &is)
|
|||
expect_initial_quote = false;
|
||||
}
|
||||
if (is_json) {
|
||||
std::istringstream tmp_is(tmp_os.str(), std::ios::binary);
|
||||
return deSerializeJsonString(tmp_is);
|
||||
return deSerializeJsonString(tmp_os);
|
||||
}
|
||||
|
||||
return tmp_os.str();
|
||||
|
|
Loading…
Reference in New Issue