X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fprotocol.cpp;h=b24cef1f5e3f03ef067711271480c2eb1ab378cb;hb=2dfa05663dd67d4d7c68f96df0b1ab733b2063c2;hp=d862ed82f72a37d7416160307dac7b7069d749bf;hpb=3c2a877580e234df5fcbe06bf2850cd29f875e28;p=libs%2Fnet.git diff --git a/source/net/protocol.cpp b/source/net/protocol.cpp index d862ed8..b24cef1 100644 --- a/source/net/protocol.cpp +++ b/source/net/protocol.cpp @@ -1,12 +1,13 @@ #include #include +#include #include +#include #include #include "protocol.h" using namespace std; - namespace Msp { namespace Net { @@ -28,9 +29,13 @@ void Protocol::add_packet(PacketDefBase *pdef) { PacketDefBase *&ptr = packet_class_defs[pdef->get_class_id()]; if(ptr) + { + packet_id_defs.erase(ptr->get_id()); delete ptr; + } ptr = pdef; - packet_id_defs[pdef->get_id()] = pdef; + if(unsigned id = pdef->get_id()) + packet_id_defs[id] = pdef; } const Protocol::PacketDefBase &Protocol::get_packet_by_class_id(unsigned id) const @@ -63,10 +68,12 @@ unsigned Protocol::get_packet_size(const char *buf, unsigned size) const return header.length; } -unsigned Protocol::get_hash() const +UInt64 Protocol::get_hash() const { - // TODO - return 123; + string description; + for(PacketMap::const_iterator i=packet_id_defs.begin(); i!=packet_id_defs.end(); ++i) + description += format("%d:%s\n", i->first, i->second->describe()); + return hash64(description); }