1
0
mirror of https://github.com/minetest/minetest.git synced 2025-07-04 17:00:23 +02:00

Add TOCLIENT_SHOW_FORMSPEC to display formspecs at client from lua

This commit is contained in:
sapier
2013-01-02 19:45:04 +00:00
committed by Perttu Ahola
parent 36f03a7f4a
commit da9707950e
8 changed files with 129 additions and 2 deletions

View File

@ -3638,6 +3638,24 @@ void Server::SendChatMessage(u16 peer_id, const std::wstring &message)
// Send as reliable
m_con.Send(peer_id, 0, data, true);
}
void Server::SendShowFormspecMessage(u16 peer_id, const std::string formspec)
{
DSTACK(__FUNCTION_NAME);
std::ostringstream os(std::ios_base::binary);
u8 buf[12];
// Write command
writeU16(buf, TOCLIENT_SHOW_FORMSPEC);
os.write((char*)buf, 2);
os<<serializeLongString(formspec);
// Make data buffer
std::string s = os.str();
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
// Send as reliable
m_con.Send(peer_id, 0, data, true);
}
void Server::BroadcastChatMessage(const std::wstring &message)
{
@ -4578,6 +4596,20 @@ void Server::notifyPlayer(const char *name, const std::wstring msg)
SendChatMessage(player->peer_id, std::wstring(L"Server: -!- ")+msg);
}
bool Server::showFormspec(const char *playername, const std::string &formspec)
{
Player *player = m_env->getPlayer(playername);
if(!player)
{
infostream<<"showFormspec: couldn't find player:"<<playername<<std::endl;
return false;
}
SendShowFormspecMessage(player->peer_id,formspec);
return true;
}
void Server::notifyPlayers(const std::wstring msg)
{
BroadcastChatMessage(msg);