Changed: #142 Replace atoi and sscanf by fromString when it's possible

This commit is contained in:
kervala 2010-10-23 15:06:17 +02:00
parent c0c583b316
commit f8889fcec8
32 changed files with 266 additions and 121 deletions

View file

@ -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)

View file

@ -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:

View file

@ -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;

View file

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

View file

@ -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;
}

View file

@ -865,7 +865,8 @@ NLMISC_COMMAND (sdbDisplayNodes, "display nodes of SDB", "<shard_id> <path> [<re
if (args.size() < 2 || args.size() > 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)

View file

@ -3892,8 +3892,9 @@ NLMISC_COMMAND( changeWeightOfProperty, "Change the weight of a property", "<pro
{
if ( args.size() == 2 )
{
sint32 weight = atoi( args[1].c_str() );
MSInstance->changeWeightOfProperty( args[0], weight );
sint32 weight;
NLMISC::fromString(args[1], weight);
MSInstance->changeWeightOfProperty(args[0], weight);
return true;
}
else return false;

View file

@ -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

View file

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

View file

@ -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<logmsg.size() && logmsg[i]>='0' && logmsg[i]<='9')
++i;

View file

@ -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;

View file

@ -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')

View file

@ -396,7 +396,8 @@ NLMISC_CATEGORISED_COMMAND(Stats,jobsPromote,"pause execution of jobs","<jobId>"
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,"","<line_number>")
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,"","<infoExtractorName> [<args>]")

View file

@ -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", "<databaseI
if (args.size() != 1)
return false;
return CDbManager::createDatabase(atoi(args[0].c_str()), &log) != NULL;
TDatabaseId databaseId;
NLMISC::fromString(args[0], databaseId);
return CDbManager::createDatabase(databaseId, &log) != NULL;
}
//
@ -862,7 +865,9 @@ NLMISC_COMMAND(deleteDatabase, "delete a database using a given id", "<databaseI
if (args.size() != 1)
return false;
return CDbManager::deleteDatabase(atoi(args[0].c_str()), &log);
TDatabaseId databaseId;
NLMISC::fromString(args[0], databaseId);
return CDbManager::deleteDatabase(databaseId, &log);
}
//
@ -871,7 +876,9 @@ NLMISC_COMMAND(loadDatabase, "load a database using a given id", "<databaseId>")
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", "<databaseId>")
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", "<databaseId> <tableName>")
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", "<data
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];
CDatabase* database = CDbManager::getDatabase(databaseId);
@ -941,7 +953,9 @@ NLMISC_COMMAND(displayRow, "display row values", "<databaseId> [<tableName> <row
if (args.size() != 2 && args.size() != 3)
return false;
TDatabaseId databaseId = atoi(args[0].c_str());
TDatabaseId databaseId;
NLMISC::fromString(args[0], databaseId);
CDatabase* database = CDbManager::getDatabase(databaseId);
if (database == NULL)
return false;
@ -956,7 +970,7 @@ NLMISC_COMMAND(displayRow, "display row values", "<databaseId> [<tableName> <row
{
RY_PDS::TTableIndex tableIndex = (RY_PDS::TTableIndex)ctable->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", "<databaseId> [<tableName> <row
return true;
}
//
NLMISC_COMMAND(allocRow, "allocate a row in a table of a given database", "<databaseId> <tableName> <rowId>")
{
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", "<databaseId> <tableName> <rowI
if (args.size() != 6)
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 = (RY_PDS::TRowIndex)atoi(args[2].c_str());
RY_PDS::TColumnIndex colId = (RY_PDS::TColumnIndex)atoi(args[3].c_str());
RY_PDS::TRowIndex rowId;
NLMISC::fromString(args[2], rowId);
RY_PDS::TColumnIndex colId;
NLMISC::fromString(args[3], colId);
const std::string& type = args[4];
const std::string& value = args[5];
@ -1151,7 +1179,8 @@ NLMISC_COMMAND(get, "get a value in table", "<locatepath>")
// 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", "<da
if (args.size() < 3 || args.size() > 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", "<da
sint expandDepth = -1;
if (args.size() == 4)
{
expandDepth = atoi(args[3].c_str());
NLMISC::fromString(args[3], expandDepth);
}
database->dumpToXml(index, oxml, expandDepth);

View file

@ -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;

View file

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

View file

@ -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;
}
}

View file

@ -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)
{

View file

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

View file

@ -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","<file_n
switch (args.size())
{
case 3:
count= atoi(args[2].c_str());
NLMISC::fromString(args[2], count);
if (count<1||args[2]!=NLMISC::toString("%u",count))
return false;
case 2:
firstLine= atoi(args[1].c_str());
NLMISC::fromString(args[1], firstLine);
if (firstLine<1||args[1]!=NLMISC::toString("%u",firstLine))
return false;
@ -543,12 +544,12 @@ NLMISC_CATEGORISED_COMMAND(utils,viewBinFile,"view a binary file segment","<file
switch (args.size())
{
case 3:
count= atoi(args[2].c_str());
NLMISC::fromString(args[2], count);
if (count<1||args[2]!=NLMISC::toString("%u",count))
return false;
case 2:
start= atoi(args[1].c_str());
NLMISC::fromString(args[1], start);
if (args[1]!=NLMISC::toString("%u",start))
return false;
@ -698,7 +699,9 @@ NLMISC_CATEGORISED_COMMAND(utils,txtEditMergeFile,"load a text file into ram","<
}
// get the insert location and make sure it's valid
uint32 insertPosition= atoi(args[0].c_str()); if (insertPosition<1|| args[0]!=NLMISC::toString("%u",insertPosition)) return false;
uint32 insertPosition;
NLMISC::fromString(args[0], insertPosition);
if (insertPosition<1|| args[0]!=NLMISC::toString("%u",insertPosition)) return false;
if (insertPosition>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;

View file

@ -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);
}

View file

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

View file

@ -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 '"<<lp->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);

View file

@ -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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 "<<i+1<<" found in guild 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 shardId in guild names file line "<<i+1<<" : '"<<line<<"'", continue);
BOMB_IF (i2==0, "Invalid guildId in guild names file line "<<i+1<<" : '"<<line<<"'", continue);
TName name = words[0];

View file

@ -319,7 +319,8 @@ namespace RSMGR
session->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

View file

@ -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;
}

View file

@ -1176,7 +1176,14 @@ NLMISC_COMMAND( deleteFileBS, "delete file via BS", "<file name to be deleted> [
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;
}