summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-04-04 05:12:33 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-04-04 05:12:33 +0300
commitfa736e138c2eb04f50bcc0431fc5a0435bf34bc6 (patch)
treeec56483bbb6196b5959d9c43a16e04f3b26e227b /src
parentfa08294d09a46b603e9ff5e034010c0a7986c61a (diff)
downloadminetest-fa736e138c2eb04f50bcc0431fc5a0435bf34bc6.tar.gz
minetest-fa736e138c2eb04f50bcc0431fc5a0435bf34bc6.tar.bz2
minetest-fa736e138c2eb04f50bcc0431fc5a0435bf34bc6.zip
fully implemented the sign with the new framework
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp34
-rw-r--r--src/client.h1
-rw-r--r--src/clientserver.h8
-rw-r--r--src/main.cpp47
-rw-r--r--src/mapblock.cpp19
-rw-r--r--src/mapnode.cpp2
-rw-r--r--src/serialization.h3
-rw-r--r--src/server.cpp52
8 files changed, 158 insertions, 8 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 009591c41..2fb14cb68 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1630,6 +1630,40 @@ void Client::sendSignText(v3s16 blockpos, s16 id, std::string text)
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);
diff --git a/src/client.h b/src/client.h
index 391528286..fdb98d28d 100644
--- a/src/client.h
+++ b/src/client.h
@@ -277,6 +277,7 @@ public:
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);
diff --git a/src/clientserver.h b/src/clientserver.h
index 52b4e520e..7baa79fa6 100644
--- a/src/clientserver.h
+++ b/src/clientserver.h
@@ -241,6 +241,14 @@ enum ToServerCommand
wstring message
*/
+ TOSERVER_SIGNNODETEXT = 0x33,
+ /*
+ u16 command
+ v3s16 p
+ u16 textlen
+ textdata
+ */
+
};
inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
diff --git a/src/main.cpp b/src/main.cpp
index 4b968865f..c9099f69b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -578,6 +578,25 @@ struct TextDestChat : public TextDest
Client *m_client;
};
+struct TextDestSignNode : public TextDest
+{
+ TextDestSignNode(v3s16 p, Client *client)
+ {
+ m_p = p;
+ m_client = client;
+ }
+ void gotText(std::wstring text)
+ {
+ std::string ntext = wide_to_narrow(text);
+ dstream<<"Changing text of a sign node: "
+ <<ntext<<std::endl;
+ m_client->sendSignNodeText(m_p, ntext);
+ }
+
+ v3s16 m_p;
+ Client *m_client;
+};
+
class MyEventReceiver : public IEventReceiver
{
public:
@@ -2829,6 +2848,8 @@ int main(int argc, char *argv[])
{
infotext = narrow_to_wide(meta->infoText());
}
+
+ //MapNode node = client.getNode(nodepos);
/*
Handle digging
@@ -2956,7 +2977,31 @@ int main(int argc, char *argv[])
if(g_input->getRightClicked())
{
std::cout<<DTIME<<"Ground right-clicked"<<std::endl;
- client.groundAction(1, nodepos, neighbourpos, g_selected_item);
+
+ if(meta && meta->typeId() == CONTENT_SIGN_WALL)
+ {
+ dstream<<"Sign node right-clicked"<<std::endl;
+
+ if(random_input == false)
+ {
+ // Get a new text for it
+
+ TextDest *dest = new TextDestSignNode(nodepos, &client);
+
+ SignNodeMetadata *signmeta = (SignNodeMetadata*)meta;
+
+ std::wstring wtext =
+ narrow_to_wide(signmeta->getText());
+
+ (new GUITextInputMenu(guienv, guiroot, -1,
+ &g_menumgr, dest,
+ wtext))->drop();
+ }
+ }
+ else
+ {
+ client.groundAction(1, nodepos, neighbourpos, g_selected_item);
+ }
}
nodepos_old = nodepos;
diff --git a/src/mapblock.cpp b/src/mapblock.cpp
index e895f7749..c14fbd04e 100644
--- a/src/mapblock.cpp
+++ b/src/mapblock.cpp
@@ -1878,8 +1878,6 @@ void MapBlock::serialize(std::ostream &os, u8 version)
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;
@@ -1913,6 +1911,14 @@ void MapBlock::serialize(std::ostream &os, u8 version)
*/
compress(databuf, os, version);
+
+ /*
+ NodeMetadata
+ */
+ if(version >= 14)
+ {
+ m_node_metadata.serialize(os);
+ }
}
}
@@ -2002,7 +2008,6 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
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);
@@ -2027,6 +2032,14 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
{
data[i].param2 = s[i+nodecount*2];
}
+
+ /*
+ NodeMetadata
+ */
+ if(version >= 14)
+ {
+ m_node_metadata.deSerialize(is);
+ }
}
/*
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index c8a7e504c..cb8bf7c42 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -307,7 +307,7 @@ void init_mapnode()
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");
}
diff --git a/src/serialization.h b/src/serialization.h
index e84ceee3e..fed5bb522 100644
--- a/src/serialization.h
+++ b/src/serialization.h
@@ -46,11 +46,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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
diff --git a/src/server.cpp b/src/server.cpp
index b3ce9c13a..44c26dbc3 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1221,6 +1221,8 @@ void Server::AsyncRunStep()
{
//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);
}
}
@@ -2395,6 +2397,52 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
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
@@ -3376,12 +3424,12 @@ void setCreativeInventory(Player *player)
}
#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,