From f8889fcec8626b3955f3d8900268a5dc5c9cb6e1 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 23 Oct 2010 15:06:17 +0200 Subject: [PATCH] Changed: #142 Replace atoi and sscanf by fromString when it's possible --- .../server/src/logger_service/log_query.cpp | 8 +- .../server/src/logger_service/log_query.h | 12 ++- .../src/logger_service/logger_service.cpp | 7 +- .../src/mail_forum_service/hof_generator.cpp | 4 +- .../mail_forum_service/mail_forum_service.cpp | 15 +++- .../shard_stat_db_manager.cpp | 3 +- .../src/mirror_service/mirror_service.cpp | 5 +- .../src/pd_lib/db_description_parser.cpp | 2 +- code/ryzom/server/src/pd_lib/pd_lib.cpp | 3 +- code/ryzom/server/src/pd_lib/pd_messages.cpp | 3 +- code/ryzom/server/src/pd_lib/pd_utils.h | 2 +- code/ryzom/server/src/pd_lib/timestamp.cpp | 3 +- .../pd_support_service/stat_char_commands.cpp | 14 +++- .../persistant_data_service/db_manager.cpp | 83 +++++++++++++------ .../persistant_data_service/pds_database.cpp | 12 ++- .../pds_table_inline.h | 3 +- .../src/persistant_data_service/pds_type.cpp | 4 +- .../ryzom_naming_service.cpp | 5 +- .../ryzom_welcome_service.cpp | 12 ++- .../src/server_share/handy_commands.cpp | 46 ++++++---- .../server/src/server_share/mysql_wrapper.h | 7 +- .../server_share/r2_session_backup_module.cpp | 34 ++++++-- .../session_browser_server.cpp | 5 +- .../shard_unifier_service/character_sync.cpp | 12 ++- .../shard_unifier_service/chat_unifier.cpp | 3 +- .../shard_unifier_service/entity_locator.cpp | 19 +++-- .../shard_unifier_service/login_service.cpp | 9 +- .../mail_forum_notfier_fwd.cpp | 6 +- .../shard_unifier_service/name_manager.cpp | 18 ++-- .../ring_session_manager.cpp | 14 +++- .../src/tick_service/range_mirror_manager.cpp | 5 +- .../server/src/tick_service/tick_service.cpp | 9 +- 32 files changed, 266 insertions(+), 121 deletions(-) diff --git a/code/ryzom/server/src/logger_service/log_query.cpp b/code/ryzom/server/src/logger_service/log_query.cpp index d459582cc..42e292795 100644 --- a/code/ryzom/server/src/logger_service/log_query.cpp +++ b/code/ryzom/server/src/logger_service/log_query.cpp @@ -302,7 +302,10 @@ sint32 CQueryParser::parseSint(CQueryParser::iterator &it, CQueryParser::iterato if (tok.TokenType != tt_INT) throw EInvalidQuery(rew, "Invalid content for sint, must be an int value"); - return atoi(string(start, it).c_str()); + sint32 val; + NLMISC::fromString(string(start, it), val); + + return val; } @@ -427,7 +430,8 @@ LGS::TParamValue CQueryParser::parseConstant(CQueryParser::iterator &it, CQueryP { case tt_INT: { - uint32 num = uint32(atoi(constantTok.Text.c_str())); + uint32 num; + NLMISC::fromString(constantTok.Text, num); rew = it; TToken dateTag = getNextToken(it, end); switch (dateTag.TokenType) diff --git a/code/ryzom/server/src/logger_service/log_query.h b/code/ryzom/server/src/logger_service/log_query.h index e4fc8ca83..8fab1be35 100644 --- a/code/ryzom/server/src/logger_service/log_query.h +++ b/code/ryzom/server/src/logger_service/log_query.h @@ -274,11 +274,19 @@ inline LGS::TParamValue convertParam(const LGS::TParamValue &value, LGS::TSuppor switch (type.getValue()) { case LGS::TSupportedParamType::spt_uint32: - return LGS::TParamValue((uint32)atoi(value.get_string().c_str())); + { + uint32 tmp; + NLMISC::fromString(value.get_string(), tmp); + return LGS::TParamValue(tmp); + } case LGS::TSupportedParamType::spt_uint64: return LGS::TParamValue((uint64)atol(value.get_string().c_str())); case LGS::TSupportedParamType::spt_sint32: - return LGS::TParamValue((sint32)atoi(value.get_string().c_str())); + { + sint32 tmp; + NLMISC::fromString(value.get_string(), tmp); + return LGS::TParamValue(tmp); + } case LGS::TSupportedParamType::spt_float: return LGS::TParamValue((float)atof(value.get_string().c_str())); case LGS::TSupportedParamType::spt_string: diff --git a/code/ryzom/server/src/logger_service/logger_service.cpp b/code/ryzom/server/src/logger_service/logger_service.cpp index 979fde0ba..ccdbf0442 100644 --- a/code/ryzom/server/src/logger_service/logger_service.cpp +++ b/code/ryzom/server/src/logger_service/logger_service.cpp @@ -1201,8 +1201,9 @@ endQuery: return true; } - uint32 nbLogs = atoi(args[0].c_str()); - uint32 nbFiles = atoi(args[1].c_str()); + uint32 nbLogs, nbFiles; + NLMISC::fromString(args[0], nbLogs); + NLMISC::fromString(args[1], nbFiles); if (nbLogs == 0 || nbFiles == 0) { @@ -1563,7 +1564,7 @@ endQuery: uint32 now = CTime::getSecondsSince1970(); uint32 nbSec = 10; if (args.size() > 0) - nbSec = atoi(args[0].c_str()); + NLMISC::fromString(args[0], nbSec); std::string tabs; diff --git a/code/ryzom/server/src/mail_forum_service/hof_generator.cpp b/code/ryzom/server/src/mail_forum_service/hof_generator.cpp index 56bc0d58a..aa0d673b5 100644 --- a/code/ryzom/server/src/mail_forum_service/hof_generator.cpp +++ b/code/ryzom/server/src/mail_forum_service/hof_generator.cpp @@ -405,7 +405,7 @@ bool CHoFGenerator::parseHDTFile(const std::string & fileName, CParsedData & par if (sMaxRows == "*") tableVar.MaxRows = 0xffffFFFF; else - tableVar.MaxRows = uint32(atoi(sMaxRows.c_str())); + NLMISC::fromString(sMaxRows, tableVar.MaxRows); parsedData.TableVars.push_back(tableVar); i += nbParams; @@ -449,7 +449,7 @@ bool CHoFGenerator::parseHDTFile(const std::string & fileName, CParsedData & par if (sMaxRows == "*") wTableVar.MaxRows = 0xffffFFFF; else - wTableVar.MaxRows = uint32(atoi(sMaxRows.c_str())); + NLMISC::fromString(sMaxRows, wTableVar.MaxRows); string sOp = cfgVar->asString(i+4); wTableVar.Op = toWildcardOp(sOp); diff --git a/code/ryzom/server/src/mail_forum_service/mail_forum_service.cpp b/code/ryzom/server/src/mail_forum_service/mail_forum_service.cpp index 8260ae00a..dda21de4f 100644 --- a/code/ryzom/server/src/mail_forum_service/mail_forum_service.cpp +++ b/code/ryzom/server/src/mail_forum_service/mail_forum_service.cpp @@ -421,7 +421,10 @@ NLMISC_COMMAND(openSession,"open a mail/forum session for a player", "shardid us if (args.size() != 3) return false; - CMailForumService::openSession( atoi(args[0].c_str()), args[1], args[2] ); + uint32 shardId; + NLMISC::fromString(args[0], shardId); + + CMailForumService::openSession(shardId, args[1], args[2]); return true; } @@ -431,7 +434,10 @@ NLMISC_COMMAND(closeSession, "close a mail/forum session for a player", "shardid if (args.size() != 2) return false; - CMailForumService::closeSession( atoi(args[0].c_str()), args[1] ); + uint32 shardId; + NLMISC::fromString(args[0], shardId); + + CMailForumService::closeSession(shardId, args[1]); return true; } @@ -441,7 +447,10 @@ NLMISC_COMMAND(changeUserName, "change a user's name (guild or player)", "shardi if (args.size() != 3) return false; - CMailForumService::changeUserName( atoi(args[0].c_str()), args[1], args[2] ); + uint32 shardId; + NLMISC::fromString(args[0], shardId); + + CMailForumService::changeUserName( shardId, args[1], args[2] ); return true; } diff --git a/code/ryzom/server/src/mail_forum_service/shard_stat_db_manager.cpp b/code/ryzom/server/src/mail_forum_service/shard_stat_db_manager.cpp index 896e14db5..04c615e37 100644 --- a/code/ryzom/server/src/mail_forum_service/shard_stat_db_manager.cpp +++ b/code/ryzom/server/src/mail_forum_service/shard_stat_db_manager.cpp @@ -865,7 +865,8 @@ NLMISC_COMMAND (sdbDisplayNodes, "display nodes of SDB", " [ 5) return false; - uint32 shardId = atoi(args[0].c_str()); + uint32 shardId; + NLMISC::fromString(args[0], shardId); CShardStatDB * statDB = CShardStatDBManager::getInstance()->getShardStatDB(shardId); if (statDB == NULL) diff --git a/code/ryzom/server/src/mirror_service/mirror_service.cpp b/code/ryzom/server/src/mirror_service/mirror_service.cpp index 07da08172..8a0c4d5a1 100644 --- a/code/ryzom/server/src/mirror_service/mirror_service.cpp +++ b/code/ryzom/server/src/mirror_service/mirror_service.cpp @@ -3892,8 +3892,9 @@ NLMISC_COMMAND( changeWeightOfProperty, "Change the weight of a property", "changeWeightOfProperty( args[0], weight ); + sint32 weight; + NLMISC::fromString(args[1], weight); + MSInstance->changeWeightOfProperty(args[0], weight); return true; } else return false; diff --git a/code/ryzom/server/src/pd_lib/db_description_parser.cpp b/code/ryzom/server/src/pd_lib/db_description_parser.cpp index cc816bcf1..6b9830e96 100644 --- a/code/ryzom/server/src/pd_lib/db_description_parser.cpp +++ b/code/ryzom/server/src/pd_lib/db_description_parser.cpp @@ -473,7 +473,7 @@ bool CDBDescriptionParser::loadLog(xmlNodePtr node) } else { - log.Parameters[id].TypeId = atoi(logType.c_str()); + NLMISC::fromString(logType, log.Parameters[id].TypeId); } } else diff --git a/code/ryzom/server/src/pd_lib/pd_lib.cpp b/code/ryzom/server/src/pd_lib/pd_lib.cpp index d80be70e6..a25bffac1 100644 --- a/code/ryzom/server/src/pd_lib/pd_lib.cpp +++ b/code/ryzom/server/src/pd_lib/pd_lib.cpp @@ -1108,7 +1108,8 @@ NLMISC_DYNVARIABLE(uint, EnqueuedPDMessages, "Tells number of messages enqueued // if (args.size() != 2) // return false; // -// uint databaseId = atoi(args[0].c_str()); +// uint databaseId; +// NLMISC::fromString(args[0], databaseId); // string filename = args[1]; // // CPDSLib* lib = (databaseId < CPDSLib::_Libs.size() ? CPDSLib::_Libs[databaseId] : NULL); diff --git a/code/ryzom/server/src/pd_lib/pd_messages.cpp b/code/ryzom/server/src/pd_lib/pd_messages.cpp index db076950e..5d6ad7162 100644 --- a/code/ryzom/server/src/pd_lib/pd_messages.cpp +++ b/code/ryzom/server/src/pd_lib/pd_messages.cpp @@ -49,7 +49,8 @@ std::string CDbMessage::buildLogString(const CDBDescriptionParser& description) if (logmsg[i] == '$') { ++i; - uint param = atoi(logmsg.c_str()+i); + uint param; + NLMISC::fromString(logmsg.substr(i), param); while (i='0' && logmsg[i]<='9') ++i; diff --git a/code/ryzom/server/src/pd_lib/pd_utils.h b/code/ryzom/server/src/pd_lib/pd_utils.h index 886d367e5..3dcfaeda2 100644 --- a/code/ryzom/server/src/pd_lib/pd_utils.h +++ b/code/ryzom/server/src/pd_lib/pd_utils.h @@ -315,7 +315,7 @@ private: if (table == INVALID_TABLE_INDEX) return false; - row = atoi(str); + NLMISC::fromString(std::string(str), row); while (*str >= '0' && *str <= '9') ++str; diff --git a/code/ryzom/server/src/pd_lib/timestamp.cpp b/code/ryzom/server/src/pd_lib/timestamp.cpp index c2324dc19..8011c078b 100644 --- a/code/ryzom/server/src/pd_lib/timestamp.cpp +++ b/code/ryzom/server/src/pd_lib/timestamp.cpp @@ -96,7 +96,8 @@ bool CTimestamp::fromString(const char* str) if (_Time == 0) setToCurrent(); - sint dt = atoi(str); + sint dt; + NLMISC::fromString(std::string(str), dt); ++str; while (*str >= '0' && *str <= '9') diff --git a/code/ryzom/server/src/pd_support_service/stat_char_commands.cpp b/code/ryzom/server/src/pd_support_service/stat_char_commands.cpp index 7d667fedb..6deaf9b79 100644 --- a/code/ryzom/server/src/pd_support_service/stat_char_commands.cpp +++ b/code/ryzom/server/src/pd_support_service/stat_char_commands.cpp @@ -396,7 +396,8 @@ NLMISC_CATEGORISED_COMMAND(Stats,jobsPromote,"pause execution of jobs","" if (args.size()!=1) return false; - uint32 idx= atoi(args[0].c_str()); + uint32 idx; + NLMISC::fromString(args[0], idx); if ( (idx==0 && args[0]!="0") ) { nlwarning("Argument is not a valid job id - should be a number"); @@ -418,7 +419,8 @@ NLMISC_CATEGORISED_COMMAND(Stats,JobUpdatesPerUpdate,"set or display the number if (args.size()==1) { - uint32 count= atoi(args[0].c_str()); + uint32 count; + NLMISC::fromString(args[0], count); if ( (count==0 && args[0]!="0") ) { nlwarning("Argument is not a valid number"); @@ -480,7 +482,8 @@ NLMISC_CATEGORISED_COMMAND(Stats,jobsDisplayDetails,"display detailed info for t case 1: { - uint32 idx= atoi(args[0].c_str()); + uint32 idx; + NLMISC::fromString(args[0], idx); if ( (idx==0 && args[0]!="0") ) { nlwarning("Argument is not a valid job id - should be a number"); @@ -679,8 +682,11 @@ NLMISC_CATEGORISED_COMMAND(Stats,charScanScriptDeleteLine,"","") return false; } + uint32 line; + NLMISC::fromString(args[0], line); + // line numbering starts at 1 so an invalid number will be inored anyway - return TheCharScanScriptFile->deleteLine(atoi(args[0].c_str())); + return TheCharScanScriptFile->deleteLine(line); } NLMISC_CATEGORISED_COMMAND(Stats,charScanScriptAddInfoExtractor,""," []") diff --git a/code/ryzom/server/src/persistant_data_service/db_manager.cpp b/code/ryzom/server/src/persistant_data_service/db_manager.cpp index 8c0715405..efe5fe2d4 100644 --- a/code/ryzom/server/src/persistant_data_service/db_manager.cpp +++ b/code/ryzom/server/src/persistant_data_service/db_manager.cpp @@ -610,7 +610,8 @@ CTable::CDataAccessor CDbManager::locate(CLocatePath &path) if (path.end()) return CTable::CDataAccessor(); - TDatabaseId id = atoi(path.node().Name.c_str()); + TDatabaseId id; + NLMISC::fromString(path.node().Name, id); if (!path.next()) return CTable::CDataAccessor(); @@ -853,7 +854,9 @@ NLMISC_COMMAND(createDatabase, "create a database using a given id", "") if (args.size() != 1) return false; - return CDbManager::loadDatabase(atoi(args[0].c_str()), &log); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); + return CDbManager::loadDatabase(databaseId, &log); } // @@ -880,9 +887,10 @@ NLMISC_COMMAND(displayDatabase, "display database info", "") if (args.size() != 1) return false; - TDatabaseId databaseId = atoi(args[0].c_str()); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); - CDatabase* database = CDbManager::getDatabase(databaseId); + CDatabase *database = CDbManager::getDatabase(databaseId); if (database == NULL) return false; @@ -897,7 +905,9 @@ NLMISC_COMMAND(displayTable, "display table info", " ") if (args.size() != 2) return false; - TDatabaseId databaseId = atoi(args[0].c_str()); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); + const std::string& tableName = args[1]; CDatabase* database = CDbManager::getDatabase(databaseId); @@ -919,7 +929,9 @@ NLMISC_COMMAND(dumpDeltaFileContent, "duump the content of a delta file", " [ [ getId(); table = database->getNonConstTable(tableIndex); - rowId = atoi(args[2].c_str()); + NLMISC::fromString(args[2], rowId); } } else @@ -976,18 +990,18 @@ NLMISC_COMMAND(displayRow, "display row values", " [ ") { if (args.size() != 3) return false; - TDatabaseId databaseId = atoi(args[0].c_str()); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); + const std::string& tableName = args[1]; - RY_PDS::TRowIndex rowId = atoi(args[2].c_str()); + RY_PDS::TRowIndex rowId; + NLMISC::fromString(args[2], rowId); CDatabase* database = CDbManager::getDatabase(databaseId); if (database == NULL) @@ -1006,9 +1020,12 @@ NLMISC_COMMAND(deallocRow, "deallocate a row in a table of a given database", "< if (args.size() != 3) return false; - TDatabaseId databaseId = atoi(args[0].c_str()); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); + const std::string& tableName = args[1]; - RY_PDS::TRowIndex rowId = atoi(args[2].c_str()); + RY_PDS::TRowIndex rowId; + NLMISC::fromString(args[2], rowId); CDatabase* database = CDbManager::getDatabase(databaseId); @@ -1030,9 +1047,12 @@ NLMISC_COMMAND(mapRow, "map a row in a table of a given database with a 64bits k if (args.size() != 4) return false; - TDatabaseId databaseId = atoi(args[0].c_str()); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); + const std::string& tableName = args[1]; - RY_PDS::TRowIndex rowId = atoi(args[2].c_str()); + RY_PDS::TRowIndex rowId; + NLMISC::fromString(args[2], rowId); uint64 key; sscanf(args[3].c_str(), "%"NL_I64"X", &key); @@ -1055,7 +1075,8 @@ NLMISC_COMMAND(unmapRow, "unmap a row in a table of a given database with a 64bi if (args.size() != 3) return false; - TDatabaseId databaseId = atoi(args[0].c_str()); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); const std::string& tableName = args[1]; uint64 key; sscanf(args[2].c_str(), "%"NL_I64"X", &key); @@ -1079,10 +1100,17 @@ NLMISC_COMMAND(setValue, "set a value in table", " ") // if (args.size() != 1) // return false; // -// TDatabaseId databaseId = atoi(args[0].c_str()); +// TDatabaseId databaseId; +// NLMISC::fromString(args[0], databaseId); // CDatabase* database = CDbManager::getDatabase(databaseId); // // if (database == NULL) @@ -1169,7 +1198,9 @@ NLMISC_COMMAND(dumpToXml, "dump the content of an object into an xml file", " 4) return false; - TDatabaseId databaseId = atoi(args[0].c_str()); + TDatabaseId databaseId; + NLMISC::fromString(args[0], databaseId); + CDatabase* database = CDbManager::getDatabase(databaseId); if (database == NULL) @@ -1228,7 +1259,7 @@ NLMISC_COMMAND(dumpToXml, "dump the content of an object into an xml file", "dumpToXml(index, oxml, expandDepth); diff --git a/code/ryzom/server/src/persistant_data_service/pds_database.cpp b/code/ryzom/server/src/persistant_data_service/pds_database.cpp index b61a6ed9b..e87e91261 100644 --- a/code/ryzom/server/src/persistant_data_service/pds_database.cpp +++ b/code/ryzom/server/src/persistant_data_service/pds_database.cpp @@ -858,7 +858,8 @@ bool CDatabase::set(RY_PDS::TTableIndex table, RY_PDS::TRowIndex row, RY_PDS::TC case PDS_uint8: case PDS_sint8: { - uint8 data = (uint8)atoi(value.c_str()); + uint8 data; + NLMISC::fromString(value, data); return set(table, row, column, sizeof(data), &data); } break; @@ -867,7 +868,8 @@ bool CDatabase::set(RY_PDS::TTableIndex table, RY_PDS::TRowIndex row, RY_PDS::TC case PDS_uint16: case PDS_sint16: { - uint16 data = (uint16)atoi(value.c_str()); + uint16 data; + NLMISC::fromString(value, data); return set(table, row, column, sizeof(data), &data); } break; @@ -878,7 +880,8 @@ bool CDatabase::set(RY_PDS::TTableIndex table, RY_PDS::TRowIndex row, RY_PDS::TC case PDS_CSheetId: case PDS_CNodeId: { - uint32 data = (uint32)atoi(value.c_str()); + uint32 data; + NLMISC::fromString(value, data); return set(table, row, column, sizeof(data), &data); } break; @@ -924,7 +927,8 @@ bool CDatabase::set(RY_PDS::TTableIndex table, RY_PDS::TRowIndex row, RY_PDS::TC case PDS_dimension: { - uint32 data = (uint32)atoi(value.c_str()); + uint32 data; + NLMISC::fromString(value, data); return set(table, row, column, sizeof(data), &data); } break; diff --git a/code/ryzom/server/src/persistant_data_service/pds_table_inline.h b/code/ryzom/server/src/persistant_data_service/pds_table_inline.h index 38cb0a271..b76ca0478 100644 --- a/code/ryzom/server/src/persistant_data_service/pds_table_inline.h +++ b/code/ryzom/server/src/persistant_data_service/pds_table_inline.h @@ -966,7 +966,8 @@ inline CTable::CDataAccessor CTable::getAccessor(CLocatePath &path) if (path.end()) return CDataAccessor(); - RY_PDS::TRowIndex row = atoi(path.node().Name.c_str()); + RY_PDS::TRowIndex row; + NLMISC::fromString(path.node().Name, row); path.next(); const CColumn* column = getColumn(path); diff --git a/code/ryzom/server/src/persistant_data_service/pds_type.cpp b/code/ryzom/server/src/persistant_data_service/pds_type.cpp index 68aa7e7a6..7947f1932 100644 --- a/code/ryzom/server/src/persistant_data_service/pds_type.cpp +++ b/code/ryzom/server/src/persistant_data_service/pds_type.cpp @@ -179,7 +179,9 @@ TEnumValue CType::getIndexValue(const string &name, bool verbose) const } else { - return atoi(name.c_str()); + uint32 ret; + NLMISC::fromString(name, ret); + return (TEnumValue)ret; } } diff --git a/code/ryzom/server/src/ryzom_naming_service/ryzom_naming_service.cpp b/code/ryzom/server/src/ryzom_naming_service/ryzom_naming_service.cpp index aa3e79811..57fb67b69 100644 --- a/code/ryzom/server/src/ryzom_naming_service/ryzom_naming_service.cpp +++ b/code/ryzom/server/src/ryzom_naming_service/ryzom_naming_service.cpp @@ -1104,7 +1104,10 @@ NLMISC_COMMAND (kill, "kill a service and send an unregister broadcast to other // try with number - TServiceId sid(atoi(args[0].c_str())); + uint16 serviceId; + NLMISC::fromString(args[0], serviceId); + + TServiceId sid(serviceId); if(sid.get() == 0) { diff --git a/code/ryzom/server/src/ryzom_welcome_service/ryzom_welcome_service.cpp b/code/ryzom/server/src/ryzom_welcome_service/ryzom_welcome_service.cpp index bc2e366e2..3f68d26c4 100644 --- a/code/ryzom/server/src/ryzom_welcome_service/ryzom_welcome_service.cpp +++ b/code/ryzom/server/src/ryzom_welcome_service/ryzom_welcome_service.cpp @@ -825,7 +825,7 @@ void cbServiceUp (const std::string &serviceName, TServiceId sid, void *arg) if (IService::getInstance()->haveArg('S')) { // use the command line param if set - shardId = atoi(IService::getInstance()->getArg('S').c_str()); + NLMISC::fromString(IService::getInstance()->getArg('S'), shardId); } else if (IService::getInstance()->ConfigFile.exists ("ShardId")) { @@ -1076,7 +1076,7 @@ void cbLSConnection (const std::string &serviceName, TServiceId sid, void *arg) if (IService::getInstance()->haveArg('S')) { // use the command line param if set - shardId = atoi(IService::getInstance()->getArg('S').c_str()); + NLMISC::fromString(IService::getInstance()->getArg('S'), shardId); } else if (IService::getInstance()->ConfigFile.exists ("ShardId")) { @@ -1146,7 +1146,10 @@ void updateShardOpenFromFile(const std::string& filename) { char readBuffer[256]; f.getline(readBuffer, 256); - setShardOpenState((TShardOpenState)atoi(readBuffer)); + sint state; + NLMISC::fromString(std::string(readBuffer), state); + + setShardOpenState((TShardOpenState)state); nlinfo("Updated ShardOpen state to '%u' from file '%s'", ShardOpen.get(), filename.c_str()); } @@ -1261,7 +1264,8 @@ public: if (haveArg('S')) { // use the command line param if set - uint shardId = atoi(IService::getInstance()->getArg('S').c_str()); + uint shardId; + NLMISC::fromString(IService::getInstance()->getArg('S'), shardId); nlinfo("Using shard id %u from command line '%s'", shardId, IService::getInstance()->getArg('S').c_str()); anticipateShardId(shardId); diff --git a/code/ryzom/server/src/server_share/handy_commands.cpp b/code/ryzom/server/src/server_share/handy_commands.cpp index bcf36ae98..7f632b6c2 100644 --- a/code/ryzom/server/src/server_share/handy_commands.cpp +++ b/code/ryzom/server/src/server_share/handy_commands.cpp @@ -326,7 +326,8 @@ NLMISC_CATEGORISED_COMMAND(utils,thoroughFileCompare,"compare 2 files (by compar if (args.size()==3) { - uint32 size=atoi(args[2].c_str()); + uint32 size; + NLMISC::fromString(args[2], size); if (size<2) { nlwarning("The third parameter must be a value >= 2 : The following value is not valid: %s",args[2].c_str()); @@ -487,12 +488,12 @@ NLMISC_CATEGORISED_COMMAND(utils,viewTxtFile,"view a text file segment","TxtEditLines.size()+1) { nlwarning("Invalid insert position"); return false; } // read the new file and convert to lines @@ -719,8 +722,11 @@ NLMISC_CATEGORISED_COMMAND(utils,txtEditMergeFile,"load a text file into ram","< // we only want part of the new file // determine the first and last lines to extract from the new file - uint32 firstLine= atoi(args[2].c_str()); if (firstLine<1|| args[2]!=NLMISC::toString("%u",firstLine)) return false; - uint32 lastLine= atoi(args[3].c_str()); if (lastLine<1|| args[3]!=NLMISC::toString("%u",lastLine)) return false; + uint32 firstLine, lastLine; + NLMISC::fromString(args[2], firstLine); + if (firstLine<1|| args[2]!=NLMISC::toString("%u",firstLine)) return false; + NLMISC::fromString(args[3], lastLine); + if (lastLine<1|| args[3]!=NLMISC::toString("%u",lastLine)) return false; // make sure the line numbers are valid if (firstLine==0||firstLine>lastLine||lastLine>newLines.size()) @@ -841,12 +847,12 @@ NLMISC_CATEGORISED_COMMAND(utils,txtEditList,"list the lines in a loaded textfil switch (args.size()) { case 2: - count= atoi(args[1].c_str()); + NLMISC::fromString(args[1], count); if (count<1||args[1]!=NLMISC::toString("%u",count)) return false; case 1: - firstLine= atoi(args[0].c_str()); + NLMISC::fromString(args[0], firstLine); if (firstLine<1||args[0]!=NLMISC::toString("%u",firstLine)) return false; @@ -881,12 +887,12 @@ NLMISC_CATEGORISED_COMMAND(utils,txtEditDeleteLines,"delete one or more lines in switch (args.size()) { case 2: - lastLine= atoi(args[1].c_str()); + NLMISC::fromString(args[1], lastLine); if (lastLine<1||args[1]!=NLMISC::toString("%u",lastLine)) return false; case 1: - firstLine= atoi(args[0].c_str()); + NLMISC::fromString(args[0], firstLine); if (firstLine<1||args[0]!=NLMISC::toString("%u",firstLine)) return false; break; @@ -972,9 +978,13 @@ NLMISC_CATEGORISED_COMMAND(utils,txtEditCopy,"duplicate a segment of the text fi } // extract numeric values for args and verify theri validity - uint32 firstLine= atoi(args[0].c_str()); if (firstLine<1|| args[0]!=NLMISC::toString("%u",firstLine)) return false; - uint32 lastLine= atoi(args[1].c_str()); if (lastLine<1|| args[1]!=NLMISC::toString("%u",lastLine)) return false; - uint32 insertPosition= atoi(args[2].c_str()); if (insertPosition<1|| args[2]!=NLMISC::toString("%u",insertPosition)) return false; + uint32 firstLine, lastLine, insertPosition; + NLMISC::fromString(args[0], firstLine); + if (firstLine<1|| args[0]!=NLMISC::toString("%u",firstLine)) return false; + NLMISC::fromString(args[1], lastLine); + if (lastLine<1|| args[1]!=NLMISC::toString("%u",lastLine)) return false; + NLMISC::fromString(args[2], insertPosition); + if (insertPosition<1|| args[2]!=NLMISC::toString("%u",insertPosition)) return false; // make sure the line numbers are valid if (firstLine>lastLine||lastLine>TxtEditLines.size()||insertPosition>TxtEditLines.size()+1) @@ -1005,7 +1015,8 @@ NLMISC_CATEGORISED_COMMAND(utils,txtEditInsert,"insert a line into a loaded text } // extract the line number - uint32 lineNumber= atoi(args[0].c_str()); + uint32 lineNumber; + NLMISC::fromString(args[0], lineNumber); if (lineNumber<1||args[0]!=NLMISC::toString("%u",lineNumber)) return false; @@ -1042,7 +1053,8 @@ NLMISC_CATEGORISED_COMMAND(utils,txtEditSet,"change a line in a loaded text file } // extract the line number - uint32 lineNumber= atoi(args[0].c_str()); + uint32 lineNumber; + NLMISC::fromString(args[0], lineNumber); if (lineNumber<1||args[0]!=NLMISC::toString("%u",lineNumber)) return false; diff --git a/code/ryzom/server/src/server_share/mysql_wrapper.h b/code/ryzom/server/src/server_share/mysql_wrapper.h index 26fbc924b..d2fbc09d6 100644 --- a/code/ryzom/server/src/server_share/mysql_wrapper.h +++ b/code/ryzom/server/src/server_share/mysql_wrapper.h @@ -180,16 +180,17 @@ namespace MSW } void getField(uint32 fieldIndex, sint8 &value) { - value = sint8(atoi(getRawField(fieldIndex))); + NLMISC::fromString(std::string(getRawField(fieldIndex)), value); } void getField(uint32 fieldIndex, sint32 &value) { - value = sint32(atoi(getRawField(fieldIndex))); + NLMISC::fromString(std::string(getRawField(fieldIndex)), value); } void getField(uint32 fieldIndex, TSessionId &value) { - sint32 val = sint32(atoi(getRawField(fieldIndex))); + sint32 val; + NLMISC::fromString(std::string(getRawField(fieldIndex)), val); value =TSessionId(val); } diff --git a/code/ryzom/server/src/server_share/r2_session_backup_module.cpp b/code/ryzom/server/src/server_share/r2_session_backup_module.cpp index 50f837788..4bf3641de 100644 --- a/code/ryzom/server/src/server_share/r2_session_backup_module.cpp +++ b/code/ryzom/server/src/server_share/r2_session_backup_module.cpp @@ -295,7 +295,11 @@ public: { firstLoop = false; - if (tokens.size() != 2 || tokens[0] != "Version" || atoi(tokens[1].c_str()) != FileVersion) + uint32 version = 0; + if (tokens.size() > 1) + NLMISC::fromString(tokens[1], version) + + if (tokens.size() != 2 || tokens[0] != "Version" || version != FileVersion) { nlwarning("R2SBM: Obsolete File Discard '%s'", fileDescription.FileName.c_str()); return; @@ -311,7 +315,8 @@ public: } else if (tokens.size() == 2) { - TCharId charId = atoi(tokens[0].c_str()); + TCharId charId; + NLMISC::fromString(tokens[0], charId); std::string overrideAccess = tokens[1]; access[charId] = overrideAccess; @@ -370,7 +375,11 @@ public: { firstLoop = false; - if (tokens.size() != 2 || tokens[0] != "Version" || atoi(tokens[1].c_str()) != FileVersion) + uint version = 0; + if (tokens.size() > 1) + NLMISC::fromString(tokens[1], version); + + if (tokens.size() != 2 || tokens[0] != "Version" || version != FileVersion) { nlwarning("Obsolete File Discard '%s'", fileDescription.FileName.c_str()); return; @@ -386,13 +395,20 @@ public: } else if (tokens.size() == 7) { - TSessionId sessionId = (TSessionId)(uint32)atoi(tokens[0].c_str()); + uint32 sessionIdTmp; + NLMISC::fromString(tokens[0], sessionIdTmp); + TSessionId sessionId = (TSessionId)sessionIdTmp; std::string sessionType = tokens[1]; - uint32 timestamp = atoi(tokens[2].c_str()); - double positionX = atof(tokens[3].c_str()); - double positionY = atof(tokens[4].c_str()); - double orient = atof(tokens[5].c_str()); - uint8 season = atoi(tokens[6].c_str()); + uint32 timestamp; + NLMISC::fromString(tokens[2], timestamp); + double positionX; + NLMISC::fromString(tokens[3], positionX); + double positionY; + NLMISC::fromString(tokens[4], positionY); + double orient; + NLMISC::fromString(tokens[5], orient); + uint8 season; + NLMISC::fromString(tokens[6], season); sessions[sessionId] = TSessionInfos(timestamp, RSMGR::TSessionType(sessionType) ,positionX, positionY, orient, season); diff --git a/code/ryzom/server/src/session_browser_server/session_browser_server.cpp b/code/ryzom/server/src/session_browser_server/session_browser_server.cpp index 544c89655..759e6a0f6 100644 --- a/code/ryzom/server/src/session_browser_server/session_browser_server.cpp +++ b/code/ryzom/server/src/session_browser_server/session_browser_server.cpp @@ -122,7 +122,8 @@ public: const TParsedCommandLine *lp = initInfo.getParam("listenPort"); BOMB_IF(lp == NULL, "Failed to find param 'listenPort' in init param", return false); - uint16 port = atoi(lp->ParamValue.c_str()); + uint16 port; + NLMISC::fromString(lp->ParamValue, port); BOMB_IF(port == 0, "Invalid listen port '"<ParamValue<<"'", return false); // open the server @@ -883,7 +884,7 @@ public: accessType = TAccessType(s); autoInvite = (accessType == TAccessType::at_public); result2->getField(14, s); - subscriptionClosed = atoi(s.c_str()) != 0; + NLMISC::fromString(s, subscriptionClosed); result2->getField(15, nbRating); sd.setNbRating(nbRating); diff --git a/code/ryzom/server/src/shard_unifier_service/character_sync.cpp b/code/ryzom/server/src/shard_unifier_service/character_sync.cpp index bcb567ae1..a4503eebe 100644 --- a/code/ryzom/server/src/shard_unifier_service/character_sync.cpp +++ b/code/ryzom/server/src/shard_unifier_service/character_sync.cpp @@ -1370,12 +1370,14 @@ namespace CHARSYNC // } // else // { -// charId = atoi(args[0].c_str()); +// NLMISC::fromString(args[0], charId); // } // // srcUserId = charId >> 4; // -// uint32 dstUserId = atoi(args[1].c_str()); +// uint32 dstUserId; +// NLMISC::fromString(args[1], dstUserId); +// // if (dstUserId == 0) // { // // try to retrieve the user by name @@ -1476,12 +1478,14 @@ namespace CHARSYNC } else { - charId = atoi(args[0].c_str()); + NLMISC::fromString(args[0], charId); } userId = charId >> 4; - uint32 shardId = atoi(args[1].c_str()); + uint32 shardId; + NLMISC::fromString(args[1], shardId); + if (shardId == 0) { // try to retrieve the shard by name diff --git a/code/ryzom/server/src/shard_unifier_service/chat_unifier.cpp b/code/ryzom/server/src/shard_unifier_service/chat_unifier.cpp index 602c8912d..d9d6c584d 100644 --- a/code/ryzom/server/src/shard_unifier_service/chat_unifier.cpp +++ b/code/ryzom/server/src/shard_unifier_service/chat_unifier.cpp @@ -120,7 +120,8 @@ namespace CHATUNI } // ok, we have a valid client, add it to the list - uint32 shardId = atoi(shardIdParam->ParamValue.c_str()); + uint32 shardId; + NLMISC::fromString(shardIdParam->ParamValue, shardId); // check that we don't have conflict const TModuleProxyPtr *pproxy = _ChatClients.getA(shardId); diff --git a/code/ryzom/server/src/shard_unifier_service/entity_locator.cpp b/code/ryzom/server/src/shard_unifier_service/entity_locator.cpp index c04147356..06c9ff36e 100644 --- a/code/ryzom/server/src/shard_unifier_service/entity_locator.cpp +++ b/code/ryzom/server/src/shard_unifier_service/entity_locator.cpp @@ -222,7 +222,8 @@ namespace ENTITYLOC } // ok, we have a valid client, add it to the list - uint32 shardId = atoi(shardIdParam->ParamValue.c_str()); + uint32 shardId; + NLMISC::fromString(shardIdParam->ParamValue, shardId); // check that we don't have conflict TLocatorIndex::iterator locIt(_LocatorIndex.find(shardId)); @@ -736,10 +737,11 @@ namespace ENTITYLOC else { // parse a char id - charId = atoi(args[0].c_str()); + NLMISC::fromString(args[0], charId); } - uint32 shardId = atoi(args[1].c_str()); + uint32 shardId; + NLMISC::fromString(args[1], shardId); log.displayNL("Simulate character %u / %s disconnection from shard %u", charId, CEntityId(RYZOMID::player, charId).toString().c_str(), shardId); @@ -771,10 +773,11 @@ namespace ENTITYLOC else { // parse a char id - charId = atoi(args[0].c_str()); + NLMISC::fromString(args[0], charId); } - uint32 shardId = atoi(args[1].c_str()); + uint32 shardId; + NLMISC::fromString(args[1], shardId); log.displayNL("Simulate character %u / %s connection from shard %u", charId, CEntityId(RYZOMID::player, charId).toString().c_str(), shardId); @@ -796,7 +799,8 @@ namespace ENTITYLOC if (args.size() != 1) return false; - uint32 userId = atoi(args[0].c_str()); + uint32 userId; + NLMISC::fromString(args[0], userId); log.displayNL("Simulate user %u disconnection", userId); @@ -817,7 +821,8 @@ namespace ENTITYLOC if (args.size() != 1) return false; - uint32 userId = atoi(args[0].c_str()); + uint32 userId; + NLMISC::fromString(args[0], userId); log.displayNL("Simulate user %u connection", userId); diff --git a/code/ryzom/server/src/shard_unifier_service/login_service.cpp b/code/ryzom/server/src/shard_unifier_service/login_service.cpp index f51178827..bdad5e0d9 100644 --- a/code/ryzom/server/src/shard_unifier_service/login_service.cpp +++ b/code/ryzom/server/src/shard_unifier_service/login_service.cpp @@ -133,7 +133,9 @@ namespace LS } // open the web interface - openItf(atoi(webPort->ParamValue.c_str())); + uint16 port = 0; + NLMISC::fromString(webPort->ParamValue, port); + openItf(port); return true; } @@ -477,7 +479,7 @@ namespace LS if (!args.empty()) { - _LoggedUserTimeout = atoi(args[0].c_str()); + NLMISC::fromString(args[0], _LoggedUserTimeout); } // output the value @@ -500,7 +502,8 @@ namespace LS if (args.size() != 1) return false; - uint16 port = atoi(args[0].c_str()); + uint16 port; + NLMISC::fromString(args[0], port); log.displayNL("Opening web interface on port %u", port); openItf(port); diff --git a/code/ryzom/server/src/shard_unifier_service/mail_forum_notfier_fwd.cpp b/code/ryzom/server/src/shard_unifier_service/mail_forum_notfier_fwd.cpp index 1199af8a6..fba017f0a 100644 --- a/code/ryzom/server/src/shard_unifier_service/mail_forum_notfier_fwd.cpp +++ b/code/ryzom/server/src/shard_unifier_service/mail_forum_notfier_fwd.cpp @@ -122,7 +122,8 @@ namespace MFS } // open the web interface - uint16 port = atoi(portParam->ParamValue.c_str()); + uint16 port; + NLMISC::fromString(portParam->ParamValue, port); openItf(port); @@ -347,7 +348,8 @@ namespace MFS if (args.size() != 1) return false; - uint32 charId = atoi(args[0].c_str()); + uint32 charId; + NLMISC::fromString(args[0], charId); log.displayNL("Simulating new mail notification for character %u", charId); diff --git a/code/ryzom/server/src/shard_unifier_service/name_manager.cpp b/code/ryzom/server/src/shard_unifier_service/name_manager.cpp index 6e5b35ddf..4d8b9f486 100644 --- a/code/ryzom/server/src/shard_unifier_service/name_manager.cpp +++ b/code/ryzom/server/src/shard_unifier_service/name_manager.cpp @@ -905,13 +905,17 @@ bool CNameManager::loadCharacterNamesFromTxt() // BOMB_IF (line.countWords()!=3,"Invalid line found in character names file: "+line,continue); BOMB_IF (words.size()!=3 && words.size()!=4,"Invalid line found in character names file: "+line,continue); - int i1 = atoi(words[1].c_str()); - int i2 = atoi(words[2].c_str()); + sint i1, i2; + NLMISC::fromString(words[1], i1); + NLMISC::fromString(words[2], i2); + BOMB_IF (i1==0,"Invalid user id in character names file line: "+line,continue); BOMB_IF (i2>15 || (i2==0 && words[2] != "0"),"Invalid slot id in character names file line: "+line,continue); - int sessionId =0; + + sint sessionId =0; if (words.size() > 3) - sessionId = atoi(words[3].c_str()); + NLMISC::fromString(words[3], sessionId); + const TName name = words[0]; const TCharSlot charSlot = TCharSlot(i1, i2); TFullName fullname(name, sessionId); @@ -1139,8 +1143,10 @@ bool CNameManager::loadGuildsNamesFromTxt() } BOMB_IF (words.size()!=3,"Invalid line "<update(_RingDb); } - uint16 port = atoi(portParam->ParamValue.c_str()); + uint16 port; + NLMISC::fromString(portParam->ParamValue, port); openItf(port); @@ -4224,8 +4225,11 @@ endOfWelcomeUserResult: if (args.size() != 2) return false; - uint32 charId = atoi(args[0].c_str()); - uint32 sessionId = atoi(args[1].c_str()); + uint32 charId; + NLMISC::fromString(args[0], charId); + + uint32 sessionId; + NLMISC::fromString(args[1], sessionId); log.displayNL("Banning char %u from session %u", charId, sessionId); @@ -4300,7 +4304,9 @@ endOfWelcomeUserResult: if (args.size() > 3 || args.size() < 2) return false; - uint32 shardId = atoi(args[0].c_str()); + uint32 shardId; + NLMISC::fromString(args[0], shardId); + if (shardId == 0) { // try with the shard name diff --git a/code/ryzom/server/src/tick_service/range_mirror_manager.cpp b/code/ryzom/server/src/tick_service/range_mirror_manager.cpp index a64c532d1..a3421ceb8 100644 --- a/code/ryzom/server/src/tick_service/range_mirror_manager.cpp +++ b/code/ryzom/server/src/tick_service/range_mirror_manager.cpp @@ -608,7 +608,10 @@ NLMISC_COMMAND( releaseRangesForService, "RMM: Release range owned by a specifie { if ( args.size() < 1 ) return false; - RMMInstance->releaseRangesByService( NLNET::TServiceId(atoi( args[0].c_str() )) ); + uint16 serviceId; + NLMISC::fromString(args[0], serviceId); + + RMMInstance->releaseRangesByService( NLNET::TServiceId(serviceId) ); return true; } diff --git a/code/ryzom/server/src/tick_service/tick_service.cpp b/code/ryzom/server/src/tick_service/tick_service.cpp index 558f62d56..c80773f83 100644 --- a/code/ryzom/server/src/tick_service/tick_service.cpp +++ b/code/ryzom/server/src/tick_service/tick_service.cpp @@ -1176,7 +1176,14 @@ NLMISC_COMMAND( deleteFileBS, "delete file via BS", " [ if (args.size() < 1 || args.size() > 2) return false; - Bsi.deleteFile(args[0], (args.size() == 2 ? atoi(args[1].c_str()) == 1 : false)); + bool backupFile = false; + + if (args.size() == 2) + { + NLMISC::fromString(args[1], backupFile); + } + + Bsi.deleteFile(args[0], backupFile); return true; }