Send(0, data, true);
}
+void Client::sendSignNodeText(v3s16 p, std::string text)
+{
+ /*
+ u16 command
+ v3s16 p
+ u16 textlen
+ textdata
+ */
+ std::ostringstream os(std::ios_base::binary);
+ u8 buf[12];
+
+ // Write command
+ writeU16(buf, TOSERVER_SIGNNODETEXT);
+ os.write((char*)buf, 2);
+
+ // Write p
+ writeV3S16(buf, p);
+ os.write((char*)buf, 6);
+
+ u16 textlen = text.size();
+ // Write text length
+ writeS16(buf, textlen);
+ os.write((char*)buf, 2);
+
+ // Write text
+ os.write((char*)text.c_str(), textlen);
+
+ // Make data buffer
+ std::string s = os.str();
+ SharedBuffer<u8> data((u8*)s.c_str(), s.size());
+ // Send as reliable
+ Send(0, data, true);
+}
+
void Client::sendInventoryAction(InventoryAction *a)
{
std::ostringstream os(std::ios_base::binary);
void clickObject(u8 button, v3s16 blockpos, s16 id, u16 item);
void sendSignText(v3s16 blockpos, s16 id, std::string text);
+ void sendSignNodeText(v3s16 p, std::string text);
void sendInventoryAction(InventoryAction *a);
void sendChatMessage(const std::wstring &message);
wstring message
*/
+ TOSERVER_SIGNNODETEXT = 0x33,
+ /*
+ u16 command
+ v3s16 p
+ u16 textlen
+ textdata
+ */
+
};
inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
Client *m_client;\r
};\r
\r
+struct TextDestSignNode : public TextDest\r
+{\r
+ TextDestSignNode(v3s16 p, Client *client)\r
+ {\r
+ m_p = p;\r
+ m_client = client;\r
+ }\r
+ void gotText(std::wstring text)\r
+ {\r
+ std::string ntext = wide_to_narrow(text);\r
+ dstream<<"Changing text of a sign node: "\r
+ <<ntext<<std::endl;\r
+ m_client->sendSignNodeText(m_p, ntext);\r
+ }\r
+\r
+ v3s16 m_p;\r
+ Client *m_client;\r
+};\r
+\r
class MyEventReceiver : public IEventReceiver\r
{\r
public:\r
{\r
infotext = narrow_to_wide(meta->infoText());\r
}\r
+ \r
+ //MapNode node = client.getNode(nodepos);\r
\r
/*\r
Handle digging\r
if(g_input->getRightClicked())\r
{\r
std::cout<<DTIME<<"Ground right-clicked"<<std::endl;\r
- client.groundAction(1, nodepos, neighbourpos, g_selected_item);\r
+ \r
+ if(meta && meta->typeId() == CONTENT_SIGN_WALL)\r
+ {\r
+ dstream<<"Sign node right-clicked"<<std::endl;\r
+ \r
+ if(random_input == false)\r
+ {\r
+ // Get a new text for it\r
+\r
+ TextDest *dest = new TextDestSignNode(nodepos, &client);\r
+\r
+ SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;\r
+ \r
+ std::wstring wtext =\r
+ narrow_to_wide(signmeta->getText());\r
+\r
+ (new GUITextInputMenu(guienv, guiroot, -1,\r
+ &g_menumgr, dest,\r
+ wtext))->drop();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ client.groundAction(1, nodepos, neighbourpos, g_selected_item);\r
+ }\r
}\r
\r
nodepos_old = nodepos;\r
flags |= 0x02;
if(m_lighting_expired)
flags |= 0x04;
- /*if(m_not_fully_generated)
- flags |= 0x08;*/
os.write((char*)&flags, 1);
u32 nodecount = MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE;
*/
compress(databuf, os, version);
+
+ /*
+ NodeMetadata
+ */
+ if(version >= 14)
+ {
+ m_node_metadata.serialize(os);
+ }
}
}
is_underground = (flags & 0x01) ? true : false;
m_day_night_differs = (flags & 0x02) ? true : false;
m_lighting_expired = (flags & 0x04) ? true : false;
- //m_not_fully_generated = (flags & 0x08) ? true : false;
// Uncompress data
std::ostringstream os(std::ios_base::binary);
{
data[i].param2 = s[i+nodecount*2];
}
+
+ /*
+ NodeMetadata
+ */
+ if(version >= 14)
+ {
+ m_node_metadata.deSerialize(is);
+ }
}
/*
f->wall_mounted = true;
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
if(f->initial_metadata == NULL)
- f->initial_metadata = new SignNodeMetadata();
+ f->initial_metadata = new SignNodeMetadata("Some sign");
}
11: (dev) zlib'd blocks, block flags
12: (dev) UnlimitedHeightmap now uses interpolated areas
13: (dev) Mapgen v2
+ 14: (dev) NodeMetadata
*/
// This represents an uninitialized or invalid format
#define SER_FMT_VER_INVALID 255
// Highest supported serialization version
-#define SER_FMT_VER_HIGHEST 13
+#define SER_FMT_VER_HIGHEST 14
// Lowest supported serialization version
#define SER_FMT_VER_LOWEST 2
{
//u16 peer_id = i.getNode()->getKey();
RemoteClient *client = i.getNode()->getValue();
+ Player *player = m_env.getPlayer(client->peer_id);
+ std::cout<<player->getName()<<" ";
client->PrintInfo(std::cout);
}
}
obj->getBlock()->setChangedFlag();
}
+ else if(command == TOSERVER_SIGNNODETEXT)
+ {
+ /*
+ u16 command
+ v3s16 p
+ u16 textlen
+ textdata
+ */
+ std::string datastring((char*)&data[2], datasize-2);
+ std::istringstream is(datastring, std::ios_base::binary);
+ u8 buf[6];
+ // Read stuff
+ is.read((char*)buf, 6);
+ v3s16 p = readV3S16(buf);
+ is.read((char*)buf, 2);
+ u16 textlen = readU16(buf);
+ std::string text;
+ for(u16 i=0; i<textlen; i++)
+ {
+ is.read((char*)buf, 1);
+ text += (char)buf[0];
+ }
+
+ NodeMetadata *meta = m_env.getMap().getNodeMetadata(p);
+ if(!meta)
+ return;
+ if(meta->typeId() != CONTENT_SIGN_WALL)
+ return;
+ SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
+ signmeta->setText(text);
+
+ v3s16 blockpos = getNodeBlockPos(p);
+ MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(blockpos);
+ if(block)
+ {
+ block->setChangedFlag();
+ }
+
+ for(core::map<u16, RemoteClient*>::Iterator
+ i = m_clients.getIterator();
+ i.atEnd()==false; i++)
+ {
+ RemoteClient *client = i.getNode()->getValue();
+ client->SetBlockNotSent(blockpos);
+ }
+ }
else if(command == TOSERVER_INVENTORY_ACTION)
{
/*// Ignore inventory changes if in creative mode
}
#endif
- // Sign
+ /*// Sign
{
InventoryItem *item = new MapBlockObjectItem("Sign Example text");
void* r = player->inventory.addItem("main", item);
assert(r == NULL);
- }
+ }*/
}
Player *Server::emergePlayer(const char *name, const char *password,