fully implemented the sign with the new framework
authorPerttu Ahola <celeron55@gmail.com>
Mon, 4 Apr 2011 02:12:33 +0000 (05:12 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 4 Apr 2011 02:12:33 +0000 (05:12 +0300)
src/client.cpp
src/client.h
src/clientserver.h
src/main.cpp
src/mapblock.cpp
src/mapnode.cpp
src/serialization.h
src/server.cpp

index 009591c414eea9ef8a0e71a7235d656ed6bb625b..2fb14cb6810cb50b909e3a6a4aefbfc1c87a27c1 100644 (file)
@@ -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);
index 3915282865e0365609550a42a7530f42445d74f3..fdb98d28d5b485dbe218369c9e71c560361ad693 100644 (file)
@@ -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);
        
index 52b4e520eabe010aa97472c2172895ee1b7f0c54..7baa79fa64fa18453bafd8ea2aeda0db2bb30a24 100644 (file)
@@ -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)
index 4b968865fc7de245883fd23e328ac06c3e96d3d5..c9099f69bf6d0fd5420b174efd2b311f3412e21e 100644 (file)
@@ -578,6 +578,25 @@ struct TextDestChat : public TextDest
        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
@@ -2829,6 +2848,8 @@ int main(int argc, char *argv[])
                        {\r
                                infotext = narrow_to_wide(meta->infoText());\r
                        }\r
+                       \r
+                       //MapNode node = client.getNode(nodepos);\r
 \r
                        /*\r
                                Handle digging\r
@@ -2956,7 +2977,31 @@ int main(int argc, char *argv[])
                        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
index e895f7749b194c56af6508e9cb22c412f3df8c01..c14fbd04e1457a9b328cc8939e20f0a89083820a 100644 (file)
@@ -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);
+               }
        }
        
        /*
index c8a7e504cd20741d1fa7f49120677dc551c5c10a..cb8bf7c42edc7cf6b6813540513514d4c7f19ea2 100644 (file)
@@ -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");
        
 }
 
index e84ceee3e0d631582356f020195d314862f7ac4a..fed5bb5223fb77a923e675dd2a0c96bf1a1ab23d 100644 (file)
@@ -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
 
index b3ce9c13aeeef720b876219bf11227d0516b75dd..44c26dbc351ece4894a38494ee56abfa484d4979 100644 (file)
@@ -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,