forked from Mirrorlandia_minetest/minetest
* squashed: [Client-sided scripting] Don't register functions that don't work. (#5091)
This commit is contained in:
parent
2efae3ffd7
commit
cb3a61f8db
@ -1584,7 +1584,7 @@ void Client::typeChatMessage(const std::wstring &message)
|
|||||||
// Show locally
|
// Show locally
|
||||||
if (message[0] == L'/')
|
if (message[0] == L'/')
|
||||||
{
|
{
|
||||||
m_chat_queue.push((std::wstring)L"issued command: " + message);
|
pushToChatQueue((std::wstring)L"issued command: " + message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1593,7 +1593,7 @@ void Client::typeChatMessage(const std::wstring &message)
|
|||||||
LocalPlayer *player = m_env.getLocalPlayer();
|
LocalPlayer *player = m_env.getLocalPlayer();
|
||||||
assert(player != NULL);
|
assert(player != NULL);
|
||||||
std::wstring name = narrow_to_wide(player->getName());
|
std::wstring name = narrow_to_wide(player->getName());
|
||||||
m_chat_queue.push((std::wstring)L"<" + name + L"> " + message);
|
pushToChatQueue((std::wstring)L"<" + name + L"> " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1867,7 +1867,7 @@ void Client::makeScreenshot(IrrlichtDevice *device)
|
|||||||
} else {
|
} else {
|
||||||
sstr << "Failed to save screenshot '" << filename << "'";
|
sstr << "Failed to save screenshot '" << filename << "'";
|
||||||
}
|
}
|
||||||
m_chat_queue.push(narrow_to_wide(sstr.str()));
|
pushToChatQueue(narrow_to_wide(sstr.str()));
|
||||||
infostream << sstr.str() << std::endl;
|
infostream << sstr.str() << std::endl;
|
||||||
image->drop();
|
image->drop();
|
||||||
}
|
}
|
||||||
|
@ -557,6 +557,11 @@ public:
|
|||||||
|
|
||||||
void makeScreenshot(IrrlichtDevice *device);
|
void makeScreenshot(IrrlichtDevice *device);
|
||||||
|
|
||||||
|
inline void pushToChatQueue(const std::wstring &input)
|
||||||
|
{
|
||||||
|
m_chat_queue.push(input);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Virtual methods from con::PeerHandler
|
// Virtual methods from con::PeerHandler
|
||||||
|
@ -142,7 +142,7 @@ void Client::handleCommand_AcceptSudoMode(NetworkPacket* pkt)
|
|||||||
}
|
}
|
||||||
void Client::handleCommand_DenySudoMode(NetworkPacket* pkt)
|
void Client::handleCommand_DenySudoMode(NetworkPacket* pkt)
|
||||||
{
|
{
|
||||||
m_chat_queue.push(L"Password change denied. Password NOT changed.");
|
pushToChatQueue(L"Password change denied. Password NOT changed.");
|
||||||
// reset everything and be sad
|
// reset everything and be sad
|
||||||
deleteAuthData();
|
deleteAuthData();
|
||||||
}
|
}
|
||||||
@ -414,7 +414,7 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt)
|
|||||||
|
|
||||||
// If chat message not consummed by client lua API
|
// If chat message not consummed by client lua API
|
||||||
if (!m_script->on_receiving_message(wide_to_utf8(message))) {
|
if (!m_script->on_receiving_message(wide_to_utf8(message))) {
|
||||||
m_chat_queue.push(message);
|
pushToChatQueue(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,6 @@ ClientScripting::ClientScripting(Client *client):
|
|||||||
|
|
||||||
void ClientScripting::InitializeModApi(lua_State *L, int top)
|
void ClientScripting::InitializeModApi(lua_State *L, int top)
|
||||||
{
|
{
|
||||||
ModApiUtil::Initialize(L, top);
|
ModApiUtil::InitializeClient(L, top);
|
||||||
ModApiClient::Initialize(L, top);
|
ModApiClient::Initialize(L, top);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,12 @@ Server *ModApiBase::getServer(lua_State *L)
|
|||||||
return getScriptApiBase(L)->getServer();
|
return getScriptApiBase(L)->getServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SERVER
|
||||||
|
Client *ModApiBase::getClient(lua_State *L)
|
||||||
|
{
|
||||||
|
return getScriptApiBase(L)->getClient();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Environment *ModApiBase::getEnv(lua_State *L)
|
Environment *ModApiBase::getEnv(lua_State *L)
|
||||||
{
|
{
|
||||||
return getScriptApiBase(L)->getEnv();
|
return getScriptApiBase(L)->getEnv();
|
||||||
|
@ -28,6 +28,10 @@ extern "C" {
|
|||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SERVER
|
||||||
|
#include "client.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
class ScriptApiBase;
|
class ScriptApiBase;
|
||||||
class Server;
|
class Server;
|
||||||
class Environment;
|
class Environment;
|
||||||
@ -38,6 +42,10 @@ class ModApiBase {
|
|||||||
public:
|
public:
|
||||||
static ScriptApiBase* getScriptApiBase(lua_State *L);
|
static ScriptApiBase* getScriptApiBase(lua_State *L);
|
||||||
static Server* getServer(lua_State *L);
|
static Server* getServer(lua_State *L);
|
||||||
|
#ifndef SERVER
|
||||||
|
static Client* getClient(lua_State *L);
|
||||||
|
#endif // !SERVER
|
||||||
|
|
||||||
static Environment* getEnv(lua_State *L);
|
static Environment* getEnv(lua_State *L);
|
||||||
static GUIEngine* getGuiEngine(lua_State *L);
|
static GUIEngine* getGuiEngine(lua_State *L);
|
||||||
// When we are not loading the mod, this function returns "."
|
// When we are not loading the mod, this function returns "."
|
||||||
|
@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "l_client.h"
|
#include "l_client.h"
|
||||||
#include "l_internal.h"
|
#include "l_internal.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
|
||||||
int ModApiClient::l_get_current_modname(lua_State *L)
|
int ModApiClient::l_get_current_modname(lua_State *L)
|
||||||
{
|
{
|
||||||
@ -27,7 +28,18 @@ int ModApiClient::l_get_current_modname(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// display_chat_message(message)
|
||||||
|
int ModApiClient::l_display_chat_message(lua_State *L)
|
||||||
|
{
|
||||||
|
NO_MAP_LOCK_REQUIRED;
|
||||||
|
|
||||||
|
std::string message = luaL_checkstring(L, 1);
|
||||||
|
getClient(L)->pushToChatQueue(utf8_to_wide(message));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void ModApiClient::Initialize(lua_State *L, int top)
|
void ModApiClient::Initialize(lua_State *L, int top)
|
||||||
{
|
{
|
||||||
API_FCT(get_current_modname);
|
API_FCT(get_current_modname);
|
||||||
|
API_FCT(display_chat_message);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class ModApiClient : public ModApiBase
|
|||||||
private:
|
private:
|
||||||
// get_current_modname()
|
// get_current_modname()
|
||||||
static int l_get_current_modname(lua_State *L);
|
static int l_get_current_modname(lua_State *L);
|
||||||
|
static int l_display_chat_message(lua_State *L);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Initialize(lua_State *L, int top);
|
static void Initialize(lua_State *L, int top);
|
||||||
|
@ -526,6 +526,32 @@ void ModApiUtil::Initialize(lua_State *L, int top)
|
|||||||
API_FCT(get_version);
|
API_FCT(get_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModApiUtil::InitializeClient(lua_State *L, int top)
|
||||||
|
{
|
||||||
|
API_FCT(log);
|
||||||
|
|
||||||
|
API_FCT(setting_set);
|
||||||
|
API_FCT(setting_get);
|
||||||
|
API_FCT(setting_setbool);
|
||||||
|
API_FCT(setting_getbool);
|
||||||
|
API_FCT(setting_save);
|
||||||
|
|
||||||
|
API_FCT(parse_json);
|
||||||
|
API_FCT(write_json);
|
||||||
|
|
||||||
|
API_FCT(is_yes);
|
||||||
|
|
||||||
|
API_FCT(get_builtin_path);
|
||||||
|
|
||||||
|
API_FCT(compress);
|
||||||
|
API_FCT(decompress);
|
||||||
|
|
||||||
|
API_FCT(encode_base64);
|
||||||
|
API_FCT(decode_base64);
|
||||||
|
|
||||||
|
API_FCT(get_version);
|
||||||
|
}
|
||||||
|
|
||||||
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
|
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
|
||||||
{
|
{
|
||||||
ASYNC_API_FCT(log);
|
ASYNC_API_FCT(log);
|
||||||
|
@ -110,6 +110,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
static void Initialize(lua_State *L, int top);
|
static void Initialize(lua_State *L, int top);
|
||||||
|
|
||||||
|
static void InitializeClient(lua_State *L, int top);
|
||||||
|
|
||||||
static void InitializeAsync(AsyncEngine& engine);
|
static void InitializeAsync(AsyncEngine& engine);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user