Error in SmartFox::SetClientDetails

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

vmnikulin
Posts: 26
Joined: 17 Feb 2012, 12:48

Error in SmartFox::SetClientDetails

Postby vmnikulin » 13 Aug 2014, 15:23

Hi!
This is code from SmartFox.cpp:

Code: Select all

   clientDetails = boost::shared_ptr<string>(new string(platformId != NULL ? platformId->replace(platformId->begin(), platformId->end(), CLIENT_TYPE_SEPARATOR, ' ') : ""));
   *clientDetails += CLIENT_TYPE_SEPARATOR;
   clientDetails->append(version != NULL ? version->replace(version->begin(), version->end(), CLIENT_TYPE_SEPARATOR, ' ') : "");

And this is quote from documentation http://www.cplusplus.com/reference/string/string/replace/ :

Code: Select all

fill (5) string& replace (iterator i1, iterator i2, size_t n, char c);
(5) fill Replaces the portion of the string by n consecutive copies of character c.

As you can see, method replace (iterator i1, iterator i2, size_t n, char c) has "fill" semantics, so after execution clientDetails is white-space string delimited by CLIENT_TYPE_SEPARATOR. And I doubt that this behaviour is expected.
Further, I think that this code is copy-paste from C# version, because documentation http://docs2x.smartfoxserver.com/api-docs/cpp-doc/class_sfs2_x_1_1_smart_fox.html#ad2d91706f3ce9ccafbba9fb352bcfe70 contains "Unity":
By default the generic "Unity" label is used as platform, without specifying the version.

but in SmartFox.cpp:

Code: Select all

clientDetails = boost::shared_ptr<string>(new string("C++ API"));
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Error in SmartFox::SetClientDetails

Postby MBagnati » 14 Aug 2014, 15:16

Hi,
Please replace SmartFox::SetClientDetails method contained into SmartFox.cpp with this code:

Code: Select all


void SmartFox::SetClientDetails(boost::shared_ptr<string> platformId, boost::shared_ptr<string> version)
{
   if (IsConnected())
   {
      boost::shared_ptr<vector<string> > logMessages (new vector<string>());
      logMessages->push_back("SetClientDetails must be called before the connection is started");
      log->Warn(logMessages);
      return;
   }

   string separator(&CLIENT_TYPE_SEPARATOR);

   clientDetails = boost::shared_ptr<string>(new string(platformId != NULL ? boost::replace_all_copy(*platformId, separator, " ") : ""));
   *clientDetails += CLIENT_TYPE_SEPARATOR;
   clientDetails->append(version != NULL ? boost::replace_all_copy(*version, separator, " ") : "");
}



and add this statement at the begin of SmartFox.cpp

Code: Select all

#include <boost/algorithm/string/replace.hpp>


Thanks

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 1 guest