player2_dz

Untitled

Aug 5th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. bool SqlCharDataSource::updateCharacter( int characterId, int serverId, const FieldsType& fields )
  2. {
  3.     map<string,string> sqlFields;
  4.  
  5.     for (auto it=fields.begin();it!=fields.end();++it)
  6.     {
  7.         const string& name = it->first;
  8.         const Sqf::Value& val = it->second;
  9.  
  10.         //arrays
  11.         if (name == "Worldspace" || name == "Inventory" || name == "Backpack" || name == "Medical" || name == "CurrentState")
  12.             sqlFields[name] = "'"+getDB()->escape(lexical_cast<string>(val))+"'";
  13.         //booleans
  14.         else if (name == "JustAte" || name == "JustDrank")
  15.         {
  16.             if (boost::get<bool>(val))
  17.             {
  18.                 string newName = "LastAte";
  19.                 if (name == "JustDrank")
  20.                     newName = "LastDrank";
  21.  
  22.                 sqlFields[newName] = "CURRENT_TIMESTAMP";
  23.             }
  24.         }
  25.         //addition integeroids
  26.         else if (name == "KillsZ" || name == "HeadshotsZ" || name == "DistanceFoot" || name == "Duration" ||
  27.             name == "KillsH" || name == "KillsB" || name == "Humanity")
  28.         {
  29.             int integeroid = static_cast<int>(Sqf::GetDouble(val));
  30.             char intSign = '+';
  31.             if (integeroid < 0)
  32.             {
  33.                 intSign = '-';
  34.                 integeroid = abs(integeroid);
  35.             }
  36.  
  37.             if (integeroid > 0)
  38.                 sqlFields[name] = "(`"+name+"` "+intSign+" "+lexical_cast<string>(integeroid)+")";
  39.         }
  40.         //strings
  41.         else if (name == "Model")
  42.             sqlFields[name] = "'"+getDB()->escape(boost::get<string>(val))+"'";
  43.     }
  44.     if (sqlFields.size() > 0)
  45.     {
  46.  
  47.             string query = "UPDATE `Character_DATA` SET ";
  48.             for (auto it = sqlFields.begin(); it != sqlFields.end();)
  49.             {
  50.                 string fieldName = it->first;
  51.                 if (fieldName == "Worldspace")
  52.                     fieldName = _wsFieldName;
  53.  
  54.                 query += "`" + fieldName + "` = " + it->second;
  55.                 ++it;
  56.                 if (it != sqlFields.end())
  57.                     query += " , ";
  58.             }
  59.             query += ", `InstanceID` = " + lexical_cast<string>(serverId)+"  WHERE `CharacterID` = " + lexical_cast<string>(characterId);
  60.             bool exRes = getDB()->execute(query.c_str());
  61.             poco_assert(exRes == true);
  62.  
  63.             return exRes;
  64.     }
  65.     return true;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment