Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool SqlCharDataSource::updateCharacter( int characterId, int serverId, const FieldsType& fields )
- {
- map<string,string> sqlFields;
- for (auto it=fields.begin();it!=fields.end();++it)
- {
- const string& name = it->first;
- const Sqf::Value& val = it->second;
- //arrays
- if (name == "Worldspace" || name == "Inventory" || name == "Backpack" || name == "Medical" || name == "CurrentState")
- sqlFields[name] = "'"+getDB()->escape(lexical_cast<string>(val))+"'";
- //booleans
- else if (name == "JustAte" || name == "JustDrank")
- {
- if (boost::get<bool>(val))
- {
- string newName = "LastAte";
- if (name == "JustDrank")
- newName = "LastDrank";
- sqlFields[newName] = "CURRENT_TIMESTAMP";
- }
- }
- //addition integeroids
- else if (name == "KillsZ" || name == "HeadshotsZ" || name == "DistanceFoot" || name == "Duration" ||
- name == "KillsH" || name == "KillsB" || name == "Humanity")
- {
- int integeroid = static_cast<int>(Sqf::GetDouble(val));
- char intSign = '+';
- if (integeroid < 0)
- {
- intSign = '-';
- integeroid = abs(integeroid);
- }
- if (integeroid > 0)
- sqlFields[name] = "(`"+name+"` "+intSign+" "+lexical_cast<string>(integeroid)+")";
- }
- //strings
- else if (name == "Model")
- sqlFields[name] = "'"+getDB()->escape(boost::get<string>(val))+"'";
- }
- if (sqlFields.size() > 0)
- {
- string query = "UPDATE `Character_DATA` SET ";
- for (auto it = sqlFields.begin(); it != sqlFields.end();)
- {
- string fieldName = it->first;
- if (fieldName == "Worldspace")
- fieldName = _wsFieldName;
- query += "`" + fieldName + "` = " + it->second;
- ++it;
- if (it != sqlFields.end())
- query += " , ";
- }
- query += ", `InstanceID` = " + lexical_cast<string>(serverId)+" WHERE `CharacterID` = " + lexical_cast<string>(characterId);
- bool exRes = getDB()->execute(query.c_str());
- poco_assert(exRes == true);
- return exRes;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment