snprintf((char*)&data[23], PASSWORD_SIZE, "%s", m_password.c_str());
// This should be incremented in each version
- writeU16(&data[51], 3);
+ writeU16(&data[51], PROTOCOL_VERSION);
// Send as unreliable
Send(0, data, false);
event.deathscreen.camera_point_target_z = camera_point_target.Z;
m_client_event_queue.push_back(event);
}
+ else if(command == TOCLIENT_TOOLDEF)
+ {
+ infostream<<"Client: Received tool definitions"<<std::endl;
+
+ std::string datastring((char*)&data[2], datasize-2);
+ std::istringstream is(datastring, std::ios_base::binary);
+
+ // Stop threads while updating content definitions
+ m_mesh_update_thread.stop();
+
+ std::istringstream tmp_is(deSerializeLongString(is), std::ios::binary);
+ m_tooldef->deSerialize(tmp_is);
+
+ // Resume threads
+ m_mesh_update_thread.setRun(true);
+ m_mesh_update_thread.Start();
+ }
else
{
infostream<<"Client: Ignoring unknown command "
#include "utility.h"
-#define PROTOCOL_VERSION 3
+/*
+ changes by PROTOCOL_VERSION:
+
+ PROTOCOL_VERSION 3:
+ Base for writing changes here
+ PROTOCOL_VERSION 4:
+ Add TOCLIENT_TOOLDEF
+*/
+
+#define PROTOCOL_VERSION 4
#define PROTOCOL_ID 0x4f457403
u8 bool set camera point target
v3f1000 camera point target (to point the death cause or whatever)
*/
+
+ TOCLIENT_TOOLDEF = 0x38,
+ /*
+ u16 command
+ u32 length of the next item
+ serialized ToolDefManager
+ */
+
+ //TOCLIENT_CONTENT_SENDING_MODE = 0x38,
+ /*
+ u16 command
+ u8 mode (0 = off, 1 = on)
+ */
};
enum ToServerCommand
server = new Server(map_dir, configpath);
server->start(port);
}
+
+ { // Client scope
/*
Create client
gui_shuttingdowntext->remove();*/
}
+ } // Client scope (must be destructed before destructing *def and tsrc
+
delete tooldef;
delete tsrc;
+ delete nodedef;
}
Send some initialization data
*/
+ // Send tool definitions
+ SendToolDef(m_con, peer_id, m_toolmgr);
+
// Send player info to all players
SendPlayerInfos();
con.Send(peer_id, 0, data, true);
}
+void Server::SendToolDef(con::Connection &con, u16 peer_id,
+ IToolDefManager *tooldef)
+{
+ DSTACK(__FUNCTION_NAME);
+ std::ostringstream os(std::ios_base::binary);
+
+ /*
+ u16 command
+ u32 length of the next item
+ serialized ToolDefManager
+ */
+ writeU16(os, TOCLIENT_TOOLDEF);
+ std::ostringstream tmp_os(std::ios::binary);
+ tooldef->serialize(tmp_os);
+ os<<serializeLongString(tmp_os.str());
+
+ // Make data buffer
+ std::string s = os.str();
+ SharedBuffer<u8> data((u8*)s.c_str(), s.size());
+ // Send as reliable
+ con.Send(peer_id, 0, data, true);
+}
+
/*
Non-static send methods
*/
const std::wstring &reason);
static void SendDeathscreen(con::Connection &con, u16 peer_id,
bool set_camera_point_target, v3f camera_point_target);
+ static void SendToolDef(con::Connection &con, u16 peer_id,
+ IToolDefManager *tooldef);
/*
Non-static send methods
public:
virtual ~CToolDefManager()
{
- for(core::map<std::string, ToolDefinition*>::Iterator
- i = m_tool_definitions.getIterator();
- i.atEnd() == false; i++){
- delete i.getNode()->getValue();
- }
+ clear();
}
virtual const ToolDefinition* getToolDefinition(const std::string &toolname) const
{
virtual bool registerTool(std::string toolname, const ToolDefinition &def)
{
infostream<<"registerTool: registering tool \""<<toolname<<"\""<<std::endl;
- core::map<std::string, ToolDefinition*>::Node *n;
+ /*core::map<std::string, ToolDefinition*>::Node *n;
n = m_tool_definitions.find(toolname);
if(n != NULL){
errorstream<<"registerTool: registering tool \""<<toolname
<<"\" failed: name is already registered"<<std::endl;
return false;
- }
+ }*/
m_tool_definitions[toolname] = new ToolDefinition(def);
return true;
}
+ virtual void clear()
+ {
+ for(core::map<std::string, ToolDefinition*>::Iterator
+ i = m_tool_definitions.getIterator();
+ i.atEnd() == false; i++){
+ delete i.getNode()->getValue();
+ }
+ m_tool_definitions.clear();
+ }
virtual void serialize(std::ostream &os)
{
writeU8(os, 0); // version
}
virtual void deSerialize(std::istream &is)
{
+ // Clear everything
+ clear();
+ // Deserialize
int version = readU8(is);
if(version != 0) throw SerializationError(
"unsupported ToolDefManager version");
virtual std::string getImagename(const std::string &toolname) const =0;
virtual ToolDiggingProperties getDiggingProperties(
const std::string &toolname) const =0;
+
+ virtual void serialize(std::ostream &os)=0;
};
class IWritableToolDefManager : public IToolDefManager
const std::string &toolname) const =0;
virtual bool registerTool(std::string toolname, const ToolDefinition &def)=0;
+ virtual void clear()=0;
virtual void serialize(std::ostream &os)=0;
virtual void deSerialize(std::istream &is)=0;