Error in SmartFox::SetClientDetails

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

Moderators: Lapo, Bax, MBagnati

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

Error in SmartFox::SetClientDetails

Postby vmnikulin » 13 Aug 2014, 15:23

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 :

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 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"));
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Error in SmartFox::SetClientDetails

Postby MBagnati » 14 Aug 2014, 15:16

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");

   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>


Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 1 guest