mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Survive client<->server ABI mismatch
This commit is contained in:
parent
a15b8f4c99
commit
eac5aab396
@ -653,20 +653,26 @@ void CClient::serialize(CISer & h, const int version, const std::set<PlayerColor
|
||||
|
||||
void CClient::handlePack( CPack * pack )
|
||||
{
|
||||
if (pack == nullptr)
|
||||
{
|
||||
logNetwork->errorStream() << "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<boost::recursive_mutex> 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;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ CPack * CConnection::retreivePack()
|
||||
boost::unique_lock<boost::mutex> 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;
|
||||
}
|
||||
|
||||
|
@ -1107,7 +1107,7 @@ public:
|
||||
};
|
||||
|
||||
bool saving;
|
||||
std::map<ui16,CBasicPointerLoader*> loaders; // typeID => CPointerSaver<serializer,type>
|
||||
std::map<ui16, CBasicPointerLoader*> loaders; // typeID => CPointerSaver<serializer,type>
|
||||
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<T>(typeList.castRaw((void*)data, typeInfo, &typeid(typename boost::remove_const<typename boost::remove_pointer<T>::type>::type)));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 <typename Handler> 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); }
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
std::ostream & operator<<(std::ostream & out, const CPack * pack)
|
||||
{
|
||||
return out << pack->toString();
|
||||
return out << (pack? pack->toString() : "<nullptr>");
|
||||
}
|
||||
|
||||
DLL_LINKAGE void SetResource::applyGs( CGameState *gs )
|
||||
|
@ -965,9 +965,9 @@ void CGameHandler::handleConnection(std::set<PlayerColor> 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());
|
||||
|
Loading…
Reference in New Issue
Block a user