From e4f7ddb30582468a5b45996cb7d4229c4c0dddca Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 23 Oct 2010 17:39:06 +0200 Subject: [PATCH] Changed: #142 Replace atoi and sscanf by fromString when it's possible --- .../server/src/ai_share/primitive_parser.cpp | 34 +-- .../src/entities_game_service/admin.cpp | 263 ++++++++++++------ .../building_manager/building_commands.cpp | 10 +- .../building_manager/building_manager.cpp | 6 +- .../building_manager/building_unit_test.cpp | 10 +- .../building_manager/destination.cpp | 3 +- .../egs_dynamic_sheet_manager.cpp | 7 +- .../egs_sheets/egs_static_brick.cpp | 2 +- .../egs_sheets/egs_static_brick.cpp.h | 161 +++++------ .../egs_sheets/egs_static_game_item.cpp | 3 +- .../egs_sheets/egs_static_game_sheet.cpp | 68 +++-- .../egs_sheets/egs_static_world.cpp | 3 +- .../entities_game_service.cpp | 213 +++++++++----- .../entity_manager/entity_base.cpp | 6 +- .../game_item_manager/game_item.cpp | 4 +- .../game_item_manager/game_item_manager.cpp | 51 ++-- .../guild_manager/fame_manager.cpp | 9 +- .../guild_manager/guild_commands.cpp | 20 +- .../guild_manager/guild_manager.cpp | 13 +- .../entities_game_service/harvest_source.cpp | 22 +- .../inter_shard_exchange_validator.cpp | 9 +- .../mission_manager/ai_alias_translator.cpp | 3 +- .../mission_manager/mission_action.cpp | 62 +++-- .../mission_manager/mission_event.cpp | 32 +-- .../mission_manager/mission_item.cpp | 13 +- .../mission_manager/mission_parser.cpp | 5 +- .../mission_manager/mission_step_guild.cpp | 2 +- .../mission_manager/mission_step_item.cpp | 6 +- .../mission_manager/mission_step_kill.cpp | 8 +- .../mission_manager/mission_step_misc.cpp | 4 +- .../mission_manager/mission_step_queue.cpp | 2 +- .../mission_manager/mission_step_talk.cpp | 6 +- .../mission_manager/mission_template.cpp | 14 +- .../mission_manager/missions_commands.cpp | 15 +- .../modules/animation_session_manager.cpp | 3 +- .../modules/character_control.cpp | 12 +- .../modules/easter_egg.cpp | 26 +- .../modules/r2_give_item.cpp | 11 +- .../modules/r2_mission_item.cpp | 16 +- .../outpost_manager/outpost_commands.cpp | 44 +-- .../outpost_manager/outpost_manager.cpp | 6 +- .../phrase_manager/area_effect.cpp | 10 +- .../phrase_manager/available_phrases.cpp | 2 +- .../phrase_manager/chg_charac_effect.cpp | 6 +- .../phrase_manager/faber_phrase.cpp | 7 +- .../phrase_manager/fg_prospection_phrase.cpp | 4 +- .../phrase_manager/phrase_manager.cpp | 2 +- .../phrase_manager/toxic_cloud.cpp | 8 +- .../player_manager/cdb_branch.cpp | 10 +- .../player_manager/character.cpp | 11 +- 50 files changed, 766 insertions(+), 501 deletions(-) diff --git a/code/ryzom/server/src/ai_share/primitive_parser.cpp b/code/ryzom/server/src/ai_share/primitive_parser.cpp index 1ca550ce0..1e5175c7a 100644 --- a/code/ryzom/server/src/ai_share/primitive_parser.cpp +++ b/code/ryzom/server/src/ai_share/primitive_parser.cpp @@ -137,7 +137,7 @@ uint32 nodeAlias(const IPrimitive *prim, bool canFail = false) // // for legacy reasons the field may be called 'unique_id' instead of 'alias' // if (s.empty()) // prim->getPropertyByName("unique_id",s); -// alias=atoi(s.c_str()); +// alias=NLMISC::fromString(s.c_str()); // // if we haven't found a sensible alias value use the prim node address // if (alias==0 && s!="0") @@ -518,7 +518,7 @@ static CAIEventActionNode::TSmartPtr parsePrimEventAction(const CAIAliasDescript prim->getPropertyByName("action",result->Action); prim->getPropertyByName("weight",weightStr); prim->getPropertyByName("parameters",parameters); - result->Weight=atoi(weightStr.c_str()); + NLMISC::fromString(weightStr, result->Weight); result->Args=*parameters; for (uint i=0;igetNumChildren();++i) @@ -1134,7 +1134,8 @@ static void parsePrimPlaces(const CAIAliasDescriptionNode *treeNode,const IPrimi // read the radius std::string radiusString; child->getPropertyByName("radius",radiusString); - uint radius=atoi(radiusString.c_str()); + uint radius; + NLMISC::fromString(radiusString, radius); if (radius == 0) { nlwarning("Ignoring place '%s' because bad radius: '%s' (converted to int as %u)", @@ -1180,15 +1181,15 @@ static void parsePrimPlaces(const CAIAliasDescriptionNode *treeNode,const IPrimi // if (child->getPropertyByName("visit_time_min", tmpStr)) { - stayTimeMin = atoi(tmpStr.c_str()); + NLMISC::fromString(tmpStr, stayTimeMin); } if (child->getPropertyByName("visit_time_max", tmpStr)) { - stayTimeMax = atoi(tmpStr.c_str()); + NLMISC::fromString(tmpStr, stayTimeMax); } if (child->getPropertyByName("index", tmpStr)) { - index = atoi(tmpStr.c_str()); + NLMISC::fromString(tmpStr, index); } child->getPropertyByName("index_next", indexNext); if (child->getPropertyByName("flag_spawn", tmpStr)) @@ -1283,7 +1284,7 @@ static void parsePopulation(const IPrimitive *prim, std::string &sheet, uint &co sheet = s+".creature"; } - count=atoi(countStr.c_str()); + NLMISC::fromString(countStr, count); if (count<=0) { throw parsePopException(std::string("FAUNA_SPAWN_ATOM property 'count' invalid: ")+countStr); @@ -1316,7 +1317,7 @@ static void parsePrimGrpFaunaSpawn(const CAIAliasDescriptionNode *treeNode,const uint32 weight = 0; if (prim->getPropertyByName("weight",s)) { - weight=atoi(s.c_str()); + NLMISC::fromString(s, weight); if (toString(weight)!=s) { nlwarning("weight invalid value: %s"); @@ -1886,7 +1887,8 @@ static void parsePrimGrpNpc(const CAIAliasDescriptionNode *treeNode,const IPrimi } prim->getPropertyByName("count",s); - uint botCount=atoi(s.c_str()); + uint botCount; + NLMISC::fromString(s, botCount); if (foundBots && botCount != 0) { @@ -2679,7 +2681,7 @@ static void parsePrimBotTemplate(const CAIAliasDescriptionNode *aliasNode, const prim->getPropertyByName("sheet_look", lookSheet); multiLevel = true; prim->getPropertyByName("level_delta", s); - levelDelta = atoi(s.c_str()); + NLMISC::fromString(s, levelDelta); } else { @@ -2729,7 +2731,7 @@ static void parsePrimGroupTemplate(const CAIAliasDescriptionNode *aliasNode, con sint32 levelDelta = 0; prim->getPropertyByName("count", s); - botCount = atoi(s.c_str()); + NLMISC::fromString(s, botCount); prim->getPropertyByName("count_multiplied_by_sheet", s); countMultipliedBySheet = (s == "true"); @@ -2748,7 +2750,7 @@ static void parsePrimGroupTemplate(const CAIAliasDescriptionNode *aliasNode, con prim->getPropertyByName("bot_sheet_look", lookSheet); multiLevel = true; prim->getPropertyByName("level_delta", s); - levelDelta = atoi(s.c_str()); + NLMISC::fromString(s, levelDelta); } else { @@ -2773,13 +2775,13 @@ static void parsePrimGroupTemplate(const CAIAliasDescriptionNode *aliasNode, con seasons[3] = (s == "true"); prim->getPropertyByName("weight_0_25", s); - weights[0] = atoi(s.c_str()); + NLMISC::fromString(s, weights[0]); prim->getPropertyByName("weight_25_50", s); - weights[1] = atoi(s.c_str()); + NLMISC::fromString(s, weights[1]); prim->getPropertyByName("weight_50_75", s); - weights[2] = atoi(s.c_str()); + NLMISC::fromString(s, weights[2]); prim->getPropertyByName("weight_75_100", s); - weights[3] = atoi(s.c_str()); + NLMISC::fromString(s, weights[3]); vector *actParams = &EmptyStringVector; diff --git a/code/ryzom/server/src/entities_game_service/admin.cpp b/code/ryzom/server/src/entities_game_service/admin.cpp index d582ca0d3..e4b4075b6 100644 --- a/code/ryzom/server/src/entities_game_service/admin.cpp +++ b/code/ryzom/server/src/entities_game_service/admin.cpp @@ -756,7 +756,9 @@ ENTITY_VARIABLE(HP, "Hit points of a player") } else { - e->getScores()._PhysicalScores[SCORES::hit_points].Current = atoi(value.c_str()); + sint32 v; + NLMISC::fromString(value, v); + e->getScores()._PhysicalScores[SCORES::hit_points].Current = v; } } @@ -770,7 +772,9 @@ ENTITY_VARIABLE(MaxHP, "Max hit points of a player") } else { - e->getScores()._PhysicalScores[SCORES::hit_points].Max = atoi(value.c_str()); + sint32 v; + NLMISC::fromString(value, v); + e->getScores()._PhysicalScores[SCORES::hit_points].Max = v; } } @@ -888,7 +892,8 @@ ENTITY_VARIABLE(MoneyGuild, "MoneyGuild") } else { - uint32 val = atoi(value.substr(1).c_str()); + uint32 val; + NLMISC::fromString(value.substr(1), val); if(dir == 1) guild->addMoney(val); else @@ -941,11 +946,14 @@ ENTITY_VARIABLE(FactionPoint, "FactionPoint") if(dir == 0) { - c->setFactionPoint(clan, atoi(sNumber.c_str()), true); + uint32 val; + NLMISC::fromString(sNumber, val); + c->setFactionPoint(clan, val, true); } else { - uint32 val = atoi(sNumber.substr(1).c_str()); + uint32 val; + NLMISC::fromString(sNumber.substr(1), val); if(dir == 1) c->setFactionPoint(clan, c->getFactionPoint(clan)+val, true); else @@ -1142,7 +1150,9 @@ ENTITY_VARIABLE(Position, "Position of a player (in meter) ,[, if (res.size() >= 4) { // season included - c->teleportCharacter(x,y,z,true, false, 0.f, 0xFF, 0, (uint8) atoi(res[3].c_str())); + uint8 season; + NLMISC::fromString(res[3], season); + c->teleportCharacter(x,y,z,true, false, 0.f, 0xFF, 0, season); } else { @@ -1171,7 +1181,9 @@ NLMISC_COMMAND(changeMode," change_mode"," ") CEntityId id; id.fromString( args[0].c_str() ); - MBEHAV::EMode mode = MBEHAV::EMode(atoi(args[1].c_str())); + sint iMode; + NLMISC::fromString(args[1], iMode); + MBEHAV::EMode mode = MBEHAV::EMode(iMode); CEntityBase *e = 0; if( id.getType() == 0 ) @@ -1236,7 +1248,8 @@ NLMISC_COMMAND (createItemInBag, "Create an item and put it in the player bag", string sheetName = args[1]; CSheetId sheet; - uint32 sheetId = atoi(sheetName.c_str()); + uint32 sheetId; + NLMISC::fromString(sheetName, sheetId); if (sheetId != 0) { sheet = CSheetId(sheetId); @@ -1276,14 +1289,16 @@ NLMISC_COMMAND (createItemInBag, "Create an item and put it in the player bag", return false; } - sint quantity = atoi(args[2].c_str()); + sint quantity; + NLMISC::fromString(args[2], quantity); if (quantity < 1) { log.displayNL ("Quantity must be > 0"); return false; } - sint quality = atoi(args[3].c_str()); + sint quality; + NLMISC::fromString(args[3], quality); if (quality < 1) { log.displayNL ("Quality must be > 0"); @@ -1324,7 +1339,8 @@ NLMISC_COMMAND (createItemInTmpInv, "Create an item and put it in the player tem string sheetName = args[1]; CSheetId sheet; - uint32 sheetId = atoi(sheetName.c_str()); + uint32 sheetId; + NLMISC::fromString(sheetName, sheetId); if (sheetId != 0) { sheet = CSheetId(sheetId); @@ -1363,14 +1379,16 @@ NLMISC_COMMAND (createItemInTmpInv, "Create an item and put it in the player tem return false; } - sint quantity = atoi(args[2].c_str()); + sint quantity; + NLMISC::fromString(args[2], quantity); if (quantity < 1) { log.displayNL ("Quantity must be > 0"); return false; } - sint quality = atoi(args[3].c_str()); + sint quality; + NLMISC::fromString(args[3], quality); if (quality < 1) { log.displayNL ("Quality must be > 0"); @@ -1394,7 +1412,8 @@ NLMISC_COMMAND (createItemInInv, "Create items and put them in the given invento string sheetName = args[2]; CSheetId sheet; - uint32 sheetId = atoi(sheetName.c_str()); + uint32 sheetId; + NLMISC::fromString(sheetName, sheetId); if (sheetId != 0) { sheet = CSheetId(sheetId); @@ -1433,21 +1452,25 @@ NLMISC_COMMAND (createItemInInv, "Create items and put them in the given invento return false; } - sint quantity = atoi(args[3].c_str()); + sint quantity; + NLMISC::fromString(args[3], quantity); if (quantity < 1) { log.displayNL ("Quantity must be > 0"); return false; } - sint quality = atoi(args[4].c_str()); + sint quality; + NLMISC::fromString(args[4], quality); if (quality < 1) { log.displayNL ("Quality must be > 0"); return false; } - uint nbItems = min(uint(atoi(args[5].c_str())), 1000U); + uint nb; + NLMISC::fromString(args[5], nb); + uint nbItems = min(nb, 1000U); uint nbCreatedItems = 0; for (uint i = 0; i < nbItems; i++) { @@ -1479,7 +1502,7 @@ NLMISC_COMMAND(createNamedItemInBag, "create a named item in bag", " uint16 quantity; if (args.size() == 3) { - quantity = (uint16)atoi(args[2].c_str()); + NLMISC::fromString(args[2], quantity); if (quantity == 0) { log.displayNL("invalid quantity '%s'", args[2].c_str()); @@ -1528,7 +1551,8 @@ NLMISC_COMMAND (createFullArmorSet, "Create and equip player with chosen full ar const string &race = args[1]; const string &type = args[2]; - const uint16 quality = atoi(args[3].c_str()); + uint16 quality; + NLMISC::fromString(args[3], quality); const uint16 min = quality - (quality-1)%5; const string minStr = (min < 10) ? string("0") + toString(min) : toString(min); @@ -1917,7 +1941,8 @@ NLMISC_COMMAND (learnAllForagePhrases, "Learn all forage phrase, begin at specif if ( args.size() != 2 ) return false; GET_CHARACTER - uint i = atoi( args[1].c_str() ); + uint i; + NLMISC::fromString(args[1], i); uint nbSuccess = 0, nbFail = 0; const CAllRolemasterPhrases& phrases = CSheets::getSRolemasterPhrasesMap(); @@ -2171,7 +2196,8 @@ NLMISC_COMMAND(setPetAnimalSatiety,"Set the satiety of pet animal (petIndex in 0 { // Set the new satiety string result; - uint petIndex = atoi( args[1].c_str() ); + uint petIndex; + NLMISC::fromString(args[1], petIndex); float previousSatiety, maxSatiety; if ( c->getAnimalSatiety( petIndex, previousSatiety, maxSatiety ) ) { @@ -2215,7 +2241,8 @@ NLMISC_COMMAND(getPetAnimalSatiety,"Set the satiety of pet animal (petIndex in 0 if (args.size () < 2) return false; GET_CHARACTER - uint petIndex = atoi( args[1].c_str() ); + uint petIndex; + NLMISC::fromString(args[1], petIndex); if ( c ) { // Get the satiety @@ -2271,7 +2298,8 @@ NLMISC_COMMAND (addXPToSkill, "Gain experience in a given skills", " < if (args.size () < 3) return false; GET_CHARACTER - uint32 xp = atoi (args[1].c_str()); + uint32 xp; + NLMISC::fromString(args[1], xp); string skill = args[2]; @@ -2279,7 +2307,7 @@ NLMISC_COMMAND (addXPToSkill, "Gain experience in a given skills", " < if(args.size()==3) count = 1; else - count = atoi(args[3].c_str()); + NLMISC::fromString(args[3], count); count = min( count, (uint)100); @@ -2418,7 +2446,8 @@ NLMISC_COMMAND(execPhrase,"execute a sabrina phrase","= 3 ) { GET_CHARACTER - bool cyclic = atoi(args[1].c_str()) != 0; + bool cyclic; + NLMISC::fromString(args[1], cyclic); vector brickIds; for (uint i = 2 ; i < args.size() ; ++i) @@ -2443,7 +2472,8 @@ NLMISC_COMMAND(executeSabrinaPhrase,"execute a sabrina phrase, an sphrase","getEntityRowId(), c->getTargetDataSetRow(), phraseSheet, cyclic); @@ -2464,7 +2494,8 @@ NLMISC_COMMAND(memorizePhrase,"memorize a sabrina phrase","respawn( atoi(args[1].c_str() ) ); + c->respawn(idx); return true; } @@ -2582,7 +2618,9 @@ NLMISC_COMMAND(validateRespawnPoint,"Validate re-spawn point","getRespawnPoints().addRespawnPoint(atoi( args[1].c_str() )); + CCharacterRespawnPoints::TRespawnPoint respawnPoint; + NLMISC::fromString(args[1], respawnPoint); + c->getRespawnPoints().addRespawnPoint(respawnPoint); return true; } return false; @@ -2606,7 +2644,8 @@ NLMISC_COMMAND(setItemSapLoad,"set an item sap load","& items = (vector &)c->getInventory()[INVENTORIES::bag]->getChildren(); CInventoryPtr invent = c->getInventory(INVENTORIES::bag); @@ -2686,7 +2725,9 @@ NLMISC_COMMAND( summonPet, "player can summon it's pet one time only", "& pet = c->getPlayerPets(); if( index < pet.size() ) { @@ -2710,7 +2751,9 @@ NLMISC_COMMAND( allowSummonPet, "autorize player summon it's pet one time only", return false; GET_CHARACTER - uint32 index = atoi(args[1].c_str()) - 1; + uint32 index; + NLMISC::fromString(args[1], index); + --index; const std::vector< CPetAnimal >& pet = c->getPlayerPets(); if( index < pet.size() ) @@ -2775,6 +2818,7 @@ void cbClientAdmin (NLNET::CMessage& msgin, const std::string &serviceName, NLNE CEntityId eid; + CEntityId targetEid; msgin.serial (eid); bool onTarget; @@ -3491,7 +3535,9 @@ NLMISC_COMMAND( root, "root a player", "