2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2013-05-25 00:51:02 +02:00
|
|
|
#include "cpp_api/s_base.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "cpp_api/s_entity.h"
|
2013-05-25 00:51:02 +02:00
|
|
|
#include "cpp_api/s_env.h"
|
|
|
|
#include "cpp_api/s_inventory.h"
|
2017-09-26 00:11:20 +02:00
|
|
|
#include "cpp_api/s_modchannels.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "cpp_api/s_node.h"
|
|
|
|
#include "cpp_api/s_player.h"
|
|
|
|
#include "cpp_api/s_server.h"
|
2014-09-05 20:08:51 -04:00
|
|
|
#include "cpp_api/s_security.h"
|
2022-05-02 20:55:04 +02:00
|
|
|
#include "cpp_api/s_async.h"
|
|
|
|
|
|
|
|
struct PackedValue;
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-01-21 15:02:08 +01:00
|
|
|
/* Scripting <-> Server Game Interface */
|
2013-05-25 00:51:02 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2017-01-21 15:02:08 +01:00
|
|
|
class ServerScripting:
|
2014-09-05 20:08:51 -04:00
|
|
|
virtual public ScriptApiBase,
|
|
|
|
public ScriptApiDetached,
|
|
|
|
public ScriptApiEntity,
|
|
|
|
public ScriptApiEnv,
|
2017-09-26 00:11:20 +02:00
|
|
|
public ScriptApiModChannels,
|
2014-09-05 20:08:51 -04:00
|
|
|
public ScriptApiNode,
|
|
|
|
public ScriptApiPlayer,
|
|
|
|
public ScriptApiServer,
|
|
|
|
public ScriptApiSecurity
|
2013-05-25 00:51:02 +02:00
|
|
|
{
|
|
|
|
public:
|
2017-01-21 15:02:08 +01:00
|
|
|
ServerScripting(Server* server);
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2024-03-03 19:51:49 +01:00
|
|
|
void loadBuiltin();
|
2013-08-11 04:09:45 +02:00
|
|
|
// use ScriptApiBase::loadMod() to load mods
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2022-12-30 15:04:46 +01:00
|
|
|
// Save globals that are copied into other Lua envs
|
|
|
|
void saveGlobals();
|
|
|
|
|
2022-05-02 20:55:04 +02:00
|
|
|
// Initialize async engine, call this AFTER loading all mods
|
|
|
|
void initAsync();
|
|
|
|
|
|
|
|
// Global step handler to collect async results
|
|
|
|
void stepAsync();
|
|
|
|
|
|
|
|
// Pass job to async threads
|
|
|
|
u32 queueAsync(std::string &&serialized_func,
|
|
|
|
PackedValue *param, const std::string &mod_origin);
|
|
|
|
|
2024-11-03 14:24:35 +01:00
|
|
|
protected:
|
|
|
|
// from ScriptApiSecurity:
|
|
|
|
bool checkPathInternal(const std::string &abs_path, bool write_required,
|
|
|
|
bool *write_allowed) override {
|
|
|
|
return ScriptApiSecurity::checkPathWithGamedef(getStack(),
|
|
|
|
abs_path, write_required, write_allowed);
|
|
|
|
}
|
|
|
|
bool modNamesAreTrusted() override { return true; }
|
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
private:
|
2013-08-11 04:09:45 +02:00
|
|
|
void InitializeModApi(lua_State *L, int top);
|
2022-05-02 20:55:04 +02:00
|
|
|
|
|
|
|
static void InitializeAsync(lua_State *L, int top);
|
|
|
|
|
|
|
|
AsyncEngine asyncEngine;
|
2013-05-25 00:51:02 +02:00
|
|
|
};
|