diff --git a/lib/serializer/Connection.cpp b/lib/serializer/Connection.cpp index 8767207a1..e3960a799 100644 --- a/lib/serializer/Connection.cpp +++ b/lib/serializer/Connection.cpp @@ -278,7 +278,9 @@ void CConnection::enableSmartVectorMemberSerializatoin() CSerializer::smartVectorMembersSerialization = true; } -std::ostream & operator<<(std::ostream &str, const CConnection &cpc) - { - return str << "Connection with " << cpc.name << " (ID: " << cpc.connectionID << /*", " << (cpc.host ? "host" : "guest") <<*/ ")"; - } +std::string CConnection::toString() const +{ + boost::format fmt("Connection with %s (ID: %d)"); + fmt % name % connectionID; + return fmt.str(); +} diff --git a/lib/serializer/Connection.h b/lib/serializer/Connection.h index 01eb52f58..1758c0168 100644 --- a/lib/serializer/Connection.h +++ b/lib/serializer/Connection.h @@ -90,6 +90,8 @@ public: void prepareForSendingHeroes(); //disables sending vectorized, enables smart pointer serialization, clears saved/loaded ptr cache void enterPregameConnectionMode(); + std::string toString() const; + template CConnection & operator>>(T &t) { @@ -104,5 +106,3 @@ public: return * this; } }; - -DLL_LINKAGE std::ostream &operator<<(std::ostream &str, const CConnection &cpc); diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 8722f9b92..0fca27ed0 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -78,7 +78,7 @@ void CPregameServer::handleConnection(CConnection *cpc) CPackForSelectionScreen *cpfs = nullptr; *cpc >> cpfs; - logNetwork->infoStream() << "Got package to announce " << typeid(*cpfs).name() << " from " << *cpc; + logNetwork->info("Got package to announce %s from %s", typeid(*cpfs).name(), cpc->toString()); boost::unique_lock queueLock(mx); bool quitting = dynamic_ptr_cast(cpfs), @@ -110,7 +110,7 @@ void CPregameServer::handleConnection(CConnection *cpc) catch (const std::exception& e) { boost::unique_lock queueLock(mx); - logNetwork->errorStream() << *cpc << " dies... \nWhat happened: " << e.what(); + logNetwork->error("%s dies... \nWhat happened: %s", cpc->toString(), e.what()); } boost::unique_lock queueLock(mx); @@ -132,7 +132,7 @@ void CPregameServer::handleConnection(CConnection *cpc) } } - logNetwork->infoStream() << "Thread listening for " << *cpc << " ended"; + logNetwork->info("Thread listening for %s ended", cpc->toString()); listeningThreads--; vstd::clear_pointer(cpc->handler); } @@ -262,7 +262,7 @@ void CPregameServer::sendPack(CConnection * pc, const CPackForSelectionScreen & { if(!pc->sendStop) { - logNetwork->infoStream() << "\tSending pack of type " << typeid(pack).name() << " to " << *pc; + logNetwork->info("\tSending pack of type %s to %s", typeid(pack).name(), pc->toString()); *pc << &pack; } @@ -455,7 +455,7 @@ void CVCMIServer::start() acc.join(); if (error) { - logNetwork->warnStream()<<"Got connection but there is an error " << error; + logNetwork->warn("Got connection but there is an error %s", error.message()); return; } logNetwork->info("We've accepted someone... ");