Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+GNU Lesser General Public License for more details.
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "client.h"
-#include "utility.h"
#include <iostream>
#include "clientserver.h"
#include "jmutexautolock.h"
#include "clientmap.h"
#include "filecache.h"
#include "sound.h"
-#include "utility_string.h"
+#include "util/string.h"
#include "hex.h"
static std::string getMediaCacheDir()
sleep_ms(100);
delete m_inventory_from_server;
+
+ // Delete detached inventories
+ {
+ for(std::map<std::string, Inventory*>::iterator
+ i = m_detached_inventories.begin();
+ i != m_detached_inventories.end(); i++){
+ delete i->second;
+ }
+ }
}
void Client::connect(Address address)
}
infostream<<std::endl;
}
+ else if(command == TOCLIENT_INVENTORY_FORMSPEC)
+ {
+ std::string datastring((char*)&data[2], datasize-2);
+ std::istringstream is(datastring, std::ios_base::binary);
+
+ // Store formspec in LocalPlayer
+ Player *player = m_env.getLocalPlayer();
+ assert(player != NULL);
+ player->inventory_formspec = deSerializeLongString(is);
+ }
+ else if(command == TOCLIENT_DETACHED_INVENTORY)
+ {
+ std::string datastring((char*)&data[2], datasize-2);
+ std::istringstream is(datastring, std::ios_base::binary);
+
+ std::string name = deSerializeString(is);
+
+ infostream<<"Client: Detached inventory update: \""<<name<<"\""<<std::endl;
+
+ Inventory *inv = NULL;
+ if(m_detached_inventories.count(name) > 0)
+ inv = m_detached_inventories[name];
+ else{
+ inv = new Inventory(m_itemdef);
+ m_detached_inventories[name] = inv;
+ }
+ inv->deSerialize(is);
+ }
else
{
infostream<<"Client: Ignoring unknown command "
Send(0, data, true);
}
-void Client::sendSignNodeText(v3s16 p, std::string text)
+void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
+ const std::map<std::string, std::string> &fields)
{
- /*
- 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);
+ writeU16(os, TOSERVER_NODEMETA_FIELDS);
+ writeV3S16(os, p);
+ os<<serializeString(formname);
+ writeU16(os, fields.size());
+ for(std::map<std::string, std::string>::const_iterator
+ i = fields.begin(); i != fields.end(); i++){
+ const std::string &name = i->first;
+ const std::string &value = i->second;
+ os<<serializeString(name);
+ os<<serializeLongString(value);
+ }
- // 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(0, data, true);
}
+void Client::sendInventoryFields(const std::string &formname,
+ const std::map<std::string, std::string> &fields)
+{
+ std::ostringstream os(std::ios_base::binary);
+
+ writeU16(os, TOSERVER_INVENTORY_FIELDS);
+ os<<serializeString(formname);
+ writeU16(os, fields.size());
+ for(std::map<std::string, std::string>::const_iterator
+ i = fields.begin(); i != fields.end(); i++){
+ const std::string &name = i->first;
+ const std::string &value = i->second;
+ os<<serializeString(name);
+ os<<serializeLongString(value);
+ }
+
+ // 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);
return meta->getInventory();
}
break;
+ case InventoryLocation::DETACHED:
+ {
+ if(m_detached_inventories.count(loc.name) == 0)
+ return NULL;
+ return m_detached_inventories[loc.name];
+ }
+ break;
default:
assert(0);
}