diff --git a/client/Client.cpp b/client/Client.cpp index 99d4746ed..9fe03f408 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -653,20 +653,26 @@ void CClient::serialize(CISer & h, const int version, const std::seterrorStream() << "Dropping nullptr CPack! You should check whether client and server ABI matches."; + return; + } CBaseForCLApply *apply = applier->apps[typeList.getTypeID(pack)]; //find the applier if(apply) { boost::unique_lock guiLock(*LOCPLINT->pim); - apply->applyOnClBefore(this,pack); + apply->applyOnClBefore(this, pack); logNetwork->traceStream() << "\tMade first apply on cl"; gs->apply(pack); logNetwork->traceStream() << "\tApplied on gs"; - apply->applyOnClAfter(this,pack); + apply->applyOnClAfter(this, pack); logNetwork->traceStream() << "\tMade second apply on cl"; } else { - logNetwork->errorStream() << "Message cannot be applied, cannot find applier! TypeID " << typeList.getTypeID(pack); + logNetwork->errorStream() << "Message cannot be applied, cannot find applier! type " + << pack->type << " - " << typeList.getTypeInfo(pack)->name(); } delete pack; } diff --git a/lib/Connection.cpp b/lib/Connection.cpp index d0907d827..7955b1c1b 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -225,7 +225,7 @@ CPack * CConnection::retreivePack() boost::unique_lock lock(*rmx); logNetwork->traceStream() << "Listening... "; iser >> ret; - logNetwork->traceStream() << "\treceived server message of type " << typeid(*ret).name() << ", data: " << ret; + logNetwork->traceStream() << "\treceived server message of type " << (ret? typeid(*ret).name() : "nullptr") << ", data: " << ret; return ret; } diff --git a/lib/Connection.h b/lib/Connection.h index 95040a7a4..94af6a952 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -1107,7 +1107,7 @@ public: }; bool saving; - std::map loaders; // typeID => CPointerSaver + std::map loaders; // typeID => CPointerSaver si32 fileVersion; bool reverseEndianess; //if source has different endianness than us, we reverse bytes @@ -1308,7 +1308,14 @@ public: } else { - auto typeInfo = loaders[tid]->loadPtr(*this,&data, pid); + auto loader = loaders[tid]; + if (loader == nullptr) + { + logGlobal->errorStream() << "loadPointerHlp " << tid << " " << pid << " - no loader exists"; + data = nullptr; + return; + } + auto typeInfo = loader->loadPtr(*this, &data, pid); data = reinterpret_cast(typeList.castRaw((void*)data, typeInfo, &typeid(typename boost::remove_const::type>::type))); } } diff --git a/lib/NetPacks.h b/lib/NetPacks.h index f700a8827..a6f0d498b 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -2188,7 +2188,7 @@ struct CenterView : public CPackForClient//515 struct CPackForSelectionScreen : public CPack { - void apply(CSelectionScreen *selScreen){}; //that functions are implemented in CPreGame.cpp + void apply(CSelectionScreen *selScreen) {} // implemented in CPreGame.cpp }; class CPregamePackToPropagate : public CPackForSelectionScreen diff --git a/lib/NetPacksBase.h b/lib/NetPacksBase.h index 72a14a158..f9242aa8d 100644 --- a/lib/NetPacksBase.h +++ b/lib/NetPacksBase.h @@ -29,12 +29,13 @@ struct DLL_LINKAGE CPack { ui16 type; - CPack(){}; - virtual ~CPack(){}; - ui16 getType() const{return type;} + CPack() {}; + virtual ~CPack() {}; + ui16 getType() const { return type; } template void serialize(Handler &h, const int version) { logNetwork->errorStream() << "CPack serialized... this should not happen!"; + assert(false && "CPack serialized"); } void applyGs(CGameState *gs) { } virtual std::string toString() const { return boost::str(boost::format("{CPack: type '%d'}") % type); } diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 3c95d2245..8599aab08 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -34,7 +34,7 @@ std::ostream & operator<<(std::ostream & out, const CPack * pack) { - return out << pack->toString(); + return out << (pack? pack->toString() : ""); } DLL_LINKAGE void SetResource::applyGs( CGameState *gs ) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index f67fac74f..fb6409708 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -965,9 +965,9 @@ void CGameHandler::handleConnection(std::set players, CConnection & } else if(apply) { - const bool result = apply->applyOnGH(this,&c,pack, player); + const bool result = apply->applyOnGH(this, &c, pack, player); if(result) - logGlobal->trace("Message successfully applied!"); + logGlobal->traceStream() << "Message " << typeid(*pack).name() << " successfully applied!"; else complain((boost::format("Got false in applying %s... that request must have been fishy!") % typeid(*pack).name()).str());