NLMISC::CEntityIdTranslator Class Reference

#include <eid_translator.h>


Public Member Functions

void checkEntity (const CEntityId &eid, const ucstring &entityName, uint32 uid, const std::string &userName)
bool entityNameExists (const ucstring &entityName, bool acceptBlanks=false)
void getByEntity (const ucstring &entityName, std::vector< NLMISC::CEntityId > &res, bool exact)
CEntityId getByEntity (const ucstring &entityName)
ucstring getByEntity (const NLMISC::CEntityId &eid)
void getByUser (const std::string &userName, std::vector< NLMISC::CEntityId > &res, bool exact=true)
void getByUser (uint32 uid, std::vector< NLMISC::CEntityId > &res)
void getEntityIdInfo (const CEntityId &eid, ucstring &entityName, sint8 &entitySlot, uint32 &uid, std::string &userName, bool &online)
uint32 getEntityNameStringId (const CEntityId &eid)
const std::map< NLMISC::CEntityId,
CEntity > & 
getRegisteredEntities ()
uint32 getUId (const std::string &userName)
std::string getUserName (uint32 uid)
bool isEntityOnline (const CEntityId &eid)
bool isValidEntityName (const ucstring &entityName, NLMISC::CLog *log=NLMISC::InfoLog, bool acceptBlanks=false)
void load (const std::string &fileName, const std::string &invalidEntityNamesFilename)
void registerEntity (const CEntityId &eid, const ucstring &entityName, sint8 entitySlot, uint32 uid, const std::string &userName)
bool setEntityNameStringId (const ucstring &entityName, uint32 stringId)
void setEntityOnline (const CEntityId &eid, bool online)
void unregisterEntity (const CEntityId &eid)

Static Public Member Functions

CEntityIdTranslatorgetInstance ()

Data Fields

uint FileVersion

Static Public Attributes

const uint Version = 1

Private Types

typedef std::map< NLMISC::CEntityId,
CEntity >::iterator 
reit

Private Member Functions

 CEntityIdTranslator ()
std::string getRegisterableString (const ucstring &entityName, bool removeBlanks=false)
void save ()

Private Attributes

std::string FileName
std::vector< std::string > InvalidEntityNames
std::map< NLMISC::CEntityId,
CEntity
RegisteredEntities

Static Private Attributes

CEntityIdTranslatorInstance = NULL

Friends

void cbInvalidEntityNamesFilename (const std::string &filename)
struct entityNameValidClass


Member Typedef Documentation

typedef std::map<NLMISC::CEntityId, CEntity>::iterator NLMISC::CEntityIdTranslator::reit [private]
 

Definition at line 120 of file eid_translator.h.

Referenced by entityNameExists(), getByEntity(), getByUser(), getEntityIdInfo(), getEntityNameStringId(), getUId(), getUserName(), isEntityOnline(), setEntityNameStringId(), setEntityOnline(), and unregisterEntity().


Constructor & Destructor Documentation

NLMISC::CEntityIdTranslator::CEntityIdTranslator  )  [inline, private]
 

Definition at line 125 of file eid_translator.h.

00125 { }


Member Function Documentation

void NLMISC::CEntityIdTranslator::checkEntity const CEntityId eid,
const ucstring entityName,
uint32  uid,
const std::string &  userName
 

Definition at line 313 of file eid_translator.cpp.

References entityNameExists(), getByEntity(), nlinfo, nlwarning, RegisteredEntities, save(), NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), NLMISC::toString(), ucstring::toString(), NLMISC::CEntityId::toString(), and uint32.

00314 {
00315         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00316         CEntityId reid(eid);
00317         reid.setCreatorId(0);
00318         reid.setDynamicId(0);
00319 
00320         map<CEntityId, CEntityIdTranslator::CEntity>::iterator it = RegisteredEntities.find (reid);
00321         bool needSave = false;
00322         
00323         nlinfo ("EIT: Checking EId %s EntityName '%s' UId %d UserName '%s'", reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00324         
00325         if (it == RegisteredEntities.end ())
00326         {
00327                 nlwarning ("EIT: Check failed because EId is not in the CEntityIdTranslator map for EId %s EntityName '%s' UId %d UserName '%s'", reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00328                 
00329                 if (entityNameExists(entityName))
00330                 {
00331                         nlwarning ("EIT: Check failed because entity name already exist (%s) for EId %s EntityName '%s' UId %d UserName '%s'", getByEntity(entityName).toString().c_str(), reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00332                 }
00333         }
00334         else
00335         {
00336                 if ((*it).second.EntityName != entityName)
00337                 {
00338                         nlwarning ("EIT: Check failed because entity name not identical (%s) in the CEntityIdTranslator map for EId %s EntityName '%s' UId %d UserName '%s'", (*it).second.EntityName.toString().c_str(), reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00339                         if(!entityName.empty())
00340                         {
00341                                 (*it).second.EntityName = entityName;
00342                                 needSave = true;
00343                         }
00344                 }
00345                 if ((*it).second.UId != uid)
00346                 {
00347                         nlwarning ("EIT: Check failed because uid not identical (%d) in the CEntityIdTranslator map for EId %s EntityName '%s' UId %d UserName '%s'", (*it).second.UId, reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00348                         if (uid != 0)
00349                         {
00350                                 (*it).second.UId = uid;
00351                                 needSave = true;
00352                         }
00353                 }
00354                 if ((*it).second.UserName != userName)
00355                 {
00356                         nlwarning ("EIT: Check failed because user name not identical (%s) in the CEntityIdTranslator map for EId %s EntityName '%s' UId %d UserName '%s'", (*it).second.UserName.c_str(), reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00357                         if(!userName.empty())
00358                         {
00359                                 (*it).second.UserName = userName;
00360                                 needSave = true;
00361                         }
00362                 }
00363         }
00364         
00365         if (needSave)
00366                 save ();
00367 }

bool NLMISC::CEntityIdTranslator::entityNameExists const ucstring entityName,
bool  acceptBlanks = false
 

Definition at line 249 of file eid_translator.cpp.

References getRegisterableString(), isValidEntityName(), RegisteredEntities, and reit.

Referenced by checkEntity(), NLMISC::NLMISC_COMMAND(), and registerEntity().

00250 {
00251         // if bad name, don't accept it
00252         if (!isValidEntityName (entityName,NLMISC::InfoLog,acceptBlanks)) return true;
00253 
00254         // Names are stored in case dependant, so we have to test them without case.
00255         string registerable = getRegisterableString (entityName);
00256 
00257         for (reit it = RegisteredEntities.begin(); it != RegisteredEntities.end(); it++)
00258         {
00259                 if (getRegisterableString ((*it).second.EntityName) == registerable)
00260                 {
00261                         return true;
00262                 }
00263         }
00264         return false;
00265 }

void NLMISC::CEntityIdTranslator::getByEntity const ucstring entityName,
std::vector< NLMISC::CEntityId > &  res,
bool  exact
 

Definition at line 154 of file eid_translator.cpp.

References RegisteredEntities, reit, res, NLMISC::strlwr(), and ucstring::toString().

00155 {
00156         string lowerName = strlwr (entityName.toString());
00157 
00158         for (reit it = RegisteredEntities.begin(); it != RegisteredEntities.end(); ++it)
00159         {
00160                 if (exact)
00161                 {
00162                         if (strlwr((*it).second.EntityName.toString()) == lowerName)
00163                         {
00164                                 res.push_back((*it).first);
00165                         }
00166                 }
00167                 else
00168                 {
00169                         if (strlwr((*it).second.EntityName.toString()).find(lowerName) != string::npos)
00170                         {
00171                                 res.push_back((*it).first);
00172                         }
00173                 }
00174         }
00175 }

CEntityId NLMISC::CEntityIdTranslator::getByEntity const ucstring entityName  ) 
 

Definition at line 144 of file eid_translator.cpp.

References getByEntity(), and res.

00145 {
00146         vector<CEntityId> res;
00147         getByEntity (entityName, res, true);
00148         if (res.empty())
00149                 return CEntityId::Unknown;
00150         else
00151                 return res[0];
00152 }

ucstring NLMISC::CEntityIdTranslator::getByEntity const NLMISC::CEntityId eid  ) 
 

Definition at line 126 of file eid_translator.cpp.

References RegisteredEntities, reit, NLMISC::CEntityId::setCreatorId(), and NLMISC::CEntityId::setDynamicId().

Referenced by checkEntity(), getByEntity(), and NLMISC::NLMISC_COMMAND().

00127 {
00128         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00129         CEntityId reid(eid);
00130         reid.setCreatorId(0);
00131         reid.setDynamicId(0);
00132 
00133         reit it = RegisteredEntities.find (reid);
00134         if (it == RegisteredEntities.end ())
00135         {
00136                 return ucstring("");
00137         }
00138         else
00139         {
00140                 return (*it).second.EntityName;
00141         }
00142 }

void NLMISC::CEntityIdTranslator::getByUser const std::string &  userName,
std::vector< NLMISC::CEntityId > &  res,
bool  exact = true
 

Definition at line 103 of file eid_translator.cpp.

References RegisteredEntities, reit, res, and NLMISC::strlwr().

00104 {
00105         string lowerName = strlwr (userName);
00106         
00107         for (reit it = RegisteredEntities.begin(); it != RegisteredEntities.end(); it++)
00108         {
00109                 if (exact)
00110                 {
00111                         if (strlwr((*it).second.UserName) == lowerName)
00112                         {
00113                                 res.push_back((*it).first);
00114                         }
00115                 }
00116                 else
00117                 {
00118                         if (strlwr((*it).second.UserName).find(lowerName) != string::npos)
00119                         {
00120                                 res.push_back((*it).first);
00121                         }
00122                 }
00123         }
00124 }

void NLMISC::CEntityIdTranslator::getByUser uint32  uid,
std::vector< NLMISC::CEntityId > &  res
 

Definition at line 92 of file eid_translator.cpp.

References RegisteredEntities, reit, res, and uint32.

Referenced by NLMISC::NLMISC_COMMAND().

00093 {
00094         for (reit it = RegisteredEntities.begin(); it != RegisteredEntities.end(); it++)
00095         {
00096                 if ((*it).second.UId == uid)
00097                 {
00098                         res.push_back((*it).first);
00099                 }
00100         }
00101 }

void NLMISC::CEntityIdTranslator::getEntityIdInfo const CEntityId eid,
ucstring entityName,
sint8 entitySlot,
uint32 uid,
std::string &  userName,
bool &  online
 

Definition at line 493 of file eid_translator.cpp.

References nlwarning, RegisteredEntities, reit, NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), sint8, NLMISC::CEntityId::toString(), and uint32.

Referenced by NLMISC::NLMISC_COMMAND().

00494 {
00495         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00496         CEntityId reid(eid);
00497         reid.setCreatorId(0);
00498         reid.setDynamicId(0);
00499 
00500         reit it = RegisteredEntities.find (reid);
00501         if (it == RegisteredEntities.end ())
00502         {
00503                 nlwarning ("EIT: %s is not registered in CEntityIdTranslator", reid.toString().c_str());
00504                 entityName = "";
00505                 entitySlot = -1;
00506                 uid = ~0;
00507                 userName = "";
00508                 online = false;
00509         }
00510         else
00511         {
00512                 entityName = (*it).second.EntityName;
00513                 entitySlot = (*it).second.EntitySlot;
00514                 uid = (*it).second.UId;
00515                 userName = (*it).second.UserName;
00516                 online = (*it).second.Online;
00517         }
00518 }

uint32 NLMISC::CEntityIdTranslator::getEntityNameStringId const CEntityId eid  ) 
 

Definition at line 535 of file eid_translator.cpp.

References RegisteredEntities, reit, NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), and uint32.

00536 {
00537         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00538         CEntityId reid(eid);
00539         reid.setCreatorId(0);
00540         reid.setDynamicId(0);
00541         
00542         const reit it = RegisteredEntities.find (reid);
00543         if (it == RegisteredEntities.end ())
00544         {
00545                 return 0;
00546         }
00547         else
00548         {
00549                 return (*it).second.EntityNameStringId;
00550         }
00551 }

CEntityIdTranslator * NLMISC::CEntityIdTranslator::getInstance  )  [static]
 

Definition at line 83 of file eid_translator.cpp.

00084 {
00085         if(Instance == NULL)
00086         {
00087                 Instance = new CEntityIdTranslator;
00088         }
00089         return Instance;
00090 }

std::string NLMISC::CEntityIdTranslator::getRegisterableString const ucstring entityName,
bool  removeBlanks = false
[private]
 

Definition at line 590 of file eid_translator.cpp.

References NLMISC::strlwr(), ucstring::toString(), and uint.

Referenced by entityNameExists(), and isValidEntityName().

00591 {
00592         string ret = strlwr( entityName.toString() );
00593         uint pos = ret.find( 0x20 );
00594         while( pos != string::npos )
00595         {
00596                 ret.erase( pos,1 );
00597                 pos = ret.find( 0x20 );
00598         }
00599         return ret;
00600 }

const std::map<NLMISC::CEntityId, CEntity>& NLMISC::CEntityIdTranslator::getRegisteredEntities  )  [inline]
 

Definition at line 112 of file eid_translator.h.

References RegisteredEntities.

Referenced by NLMISC::NLMISC_COMMAND().

00112 { return RegisteredEntities; }

uint32 NLMISC::CEntityIdTranslator::getUId const std::string &  userName  ) 
 

Definition at line 467 of file eid_translator.cpp.

References RegisteredEntities, reit, and uint32.

Referenced by NLMISC::NLMISC_COMMAND().

00468 {
00469         const reit itEnd = RegisteredEntities.end();
00470         for (reit it = RegisteredEntities.begin(); it != itEnd ; ++it)
00471         {
00472                 if ((*it).second.UserName == userName)
00473                 {
00474                         return (*it).second.UId;
00475                 }
00476         }
00477         return 0;
00478 }

string NLMISC::CEntityIdTranslator::getUserName uint32  uid  ) 
 

Definition at line 480 of file eid_translator.cpp.

References RegisteredEntities, reit, and uint32.

Referenced by NLMISC::NLMISC_COMMAND().

00481 {
00482         const reit itEnd = RegisteredEntities.end();
00483         for (reit it = RegisteredEntities.begin(); it != itEnd ; ++it)
00484         {
00485                 if ((*it).second.UId == uid)
00486                 {
00487                         return (*it).second.UserName;
00488                 }
00489         }
00490         return 0;
00491 }

bool NLMISC::CEntityIdTranslator::isEntityOnline const CEntityId eid  ) 
 

Definition at line 571 of file eid_translator.cpp.

References nlwarning, RegisteredEntities, reit, NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), and NLMISC::CEntityId::toString().

00572 {
00573         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00574         CEntityId reid(eid);
00575         reid.setCreatorId(0);
00576         reid.setDynamicId(0);
00577 
00578         reit it = RegisteredEntities.find (reid);
00579         if (it == RegisteredEntities.end ())
00580         {
00581                 nlwarning ("EIT: %s is not registered in CEntityIdTranslator", reid.toString().c_str());
00582                 return false;
00583         }
00584         else
00585         {
00586                 return (*it).second.Online;
00587         }
00588 }

bool NLMISC::CEntityIdTranslator::isValidEntityName const ucstring entityName,
NLMISC::CLog log = NLMISC::InfoLog,
bool  acceptBlanks = false
 

Definition at line 177 of file eid_translator.cpp.

References NLMISC::CLog::displayNL(), getRegisterableString(), InvalidEntityNames, NLMISC::testWildCard(), ucstring::toString(), uint, and uint16.

Referenced by entityNameExists(), and NLMISC::NLMISC_COMMAND().

00178 {
00179         // 3 char at least
00180         if (entityName.size() < 3)
00181         {
00182                 log->displayNL("Bad entity name '%s' (less than 3 char)", entityName.toString().c_str());
00183                 return false;
00184         }
00185 
00186         if ( acceptBlanks )
00187         {
00188                 // no blanks at the beginning or at the end
00189                 if ( entityName[0] ==(uint16)0x20 )
00190                 {
00191                         log->displayNL("Bad entity name '%s' : start with a blank", entityName.toString().c_str());
00192                         return false;
00193                 }
00194                 if ( entityName[entityName.size() - 1] ==(uint16)0x20 )
00195                 {
00196                         log->displayNL("Bad entity name '%s' : end with a blank", entityName.toString().c_str());
00197                         return false;
00198                 }
00199                 bool previousBlank = false;
00200                 for (uint i = 0; i < entityName.size(); i++)
00201                 {
00202                         if( entityName[i] == (uint16)0x20 )
00203                         {
00204                                 // don't accept consecutive blanks
00205                                 if ( previousBlank )
00206                                 {
00207                                         log->displayNL("Bad entity name '%s' consecutive blanks are not allowed", entityName.toString().c_str());
00208                                         return false;
00209                                 }
00210                                 previousBlank = true;
00211                         }
00212                         else
00213                         {
00214                                 // accept name with alphabetic and numeric value [a-zA-Z0-9]
00215                                 if (!isalnum (entityName[i]))
00216                                 {
00217                                         log->displayNL("Bad entity name '%s' (only char and num)", entityName.toString().c_str());
00218                                         return false;
00219                                 }
00220                                 previousBlank = false;
00221                         }
00222                 }
00223         }
00224         else for (uint i = 0; i < entityName.size(); i++)
00225         {
00226                 // only accept name with alphabetic and numeric value [a-zA-Z0-9]
00227                 if (!isalnum (entityName[i]))
00228                 {
00229                         log->displayNL("Bad entity name '%s' (only char and num)", entityName.toString().c_str());
00230                         return false;
00231                 }
00232         }
00233 
00234         // now check with the invalid name list
00235         string en = getRegisterableString( entityName, acceptBlanks);
00236 
00237         for (uint i = 0; i < InvalidEntityNames.size(); i++)
00238         {
00239                 if(testWildCard(en, InvalidEntityNames[i]))
00240                 {
00241                         log->displayNL("Bad entity name '%s' (match the invalid entity name pattern '%s')", entityName.toString().c_str(), InvalidEntityNames[i].c_str());
00242                         return false;
00243                 }
00244         }
00245 
00246         return true;
00247 }

void NLMISC::CEntityIdTranslator::load const std::string &  fileName,
const std::string &  invalidEntityNamesFilename
 

Definition at line 405 of file eid_translator.cpp.

References NLMISC::CFile::addFileChangeCallback(), NLMISC::cbInvalidEntityNamesFilename(), cbInvalidEntityNamesFilename, NLMISC::CIFile::close(), FileVersion, nlinfo, nlwarning, NLMISC::CIFile::open(), RegisteredEntities, NLMISC::IStream::serialCont(), and NLMISC::IStream::serialVersion().

00406 {
00407         if (fileName.empty())
00408         {
00409                 nlwarning ("EIT: Can't load empty filename for EntityIdTranslator");
00410                 return;
00411         }
00412 
00413         if (!FileName.empty())
00414         {
00415                 nlwarning ("EIT: Can't load file '%s' for EntityIdTranslator because we already load the file '%s'", fileName.c_str(), FileName.c_str());
00416                 return;
00417         }
00418         
00419         nlinfo ("EIT: CEntityIdTranslator: load '%s'", fileName.c_str());
00420 
00421         FileName = fileName;
00422 
00423         CIFile ifile;
00424         if( ifile.open(FileName) )
00425         {
00426                 FileVersion = Version;
00427                 ifile.serialVersion (FileVersion);
00428                 ifile.serialCont (RegisteredEntities);
00429 
00430                 ifile.close ();
00431         }
00432         else
00433         {
00434                 nlwarning ("EIT: Can't load filename '%s' for EntityIdTranslator", FileName.c_str());
00435         }
00436 
00437         cbInvalidEntityNamesFilename (invalidEntityNamesFilename);
00438 
00439         NLMISC::CFile::addFileChangeCallback (invalidEntityNamesFilename, cbInvalidEntityNamesFilename);
00440 }

void NLMISC::CEntityIdTranslator::registerEntity const CEntityId eid,
const ucstring entityName,
sint8  entitySlot,
uint32  uid,
const std::string &  userName
 

Definition at line 267 of file eid_translator.cpp.

References entityNameExists(), nlinfo, nlwarning, RegisteredEntities, save(), NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), sint8, ucstring::toString(), NLMISC::CEntityId::toString(), and uint32.

00268 {
00269         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00270         CEntityId reid(eid);
00271         reid.setCreatorId(0);
00272         reid.setDynamicId(0);
00273 
00274         if (RegisteredEntities.find (reid) != RegisteredEntities.end ())
00275         {
00276                 nlwarning ("EIT: Can't register EId %s EntityName %s UId %d UserName %s because EId is already in the map", reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00277                 return;
00278         }
00279 
00280         if (entityNameExists(entityName))
00281         {
00282                 nlwarning ("EIT: Can't register EId %s EntityName %s UId %d UserName %s because EntityName is already in the map", reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00283                 return;
00284         }
00285         
00286         nlinfo ("EIT: Register EId %s EntityName %s UId %d UserName %s", reid.toString().c_str(), entityName.toString().c_str(), uid, userName.c_str());
00287         RegisteredEntities.insert (make_pair(reid, CEntityIdTranslator::CEntity(entityName, uid, userName, entitySlot)));
00288 
00289         save ();
00290 }

void NLMISC::CEntityIdTranslator::save  )  [private]
 

Definition at line 442 of file eid_translator.cpp.

References NLMISC::COFile::close(), FileVersion, nlinfo, nlwarning, NLMISC::COFile::open(), RegisteredEntities, NLMISC::IStream::serialCont(), and NLMISC::IStream::serialVersion().

Referenced by checkEntity(), registerEntity(), and unregisterEntity().

00443 {
00444         if (FileName.empty())
00445         {
00446                 nlwarning ("EIT: Can't save empty filename for EntityIdTranslator (you forgot to load() it before?)");
00447                 return;
00448         }
00449 
00450         nlinfo ("EIT: CEntityIdTranslator: save");
00451 
00452         COFile ofile;
00453         if( ofile.open(FileName) )
00454         {
00455                 ofile.serialVersion (Version);
00456                 FileVersion = Version;
00457                 ofile.serialCont (RegisteredEntities);
00458 
00459                 ofile.close ();
00460         }
00461         else
00462         {
00463                 nlwarning ("EIT: Can't save filename '%s' for EntityIdTranslator", FileName.c_str());
00464         }
00465 }

bool NLMISC::CEntityIdTranslator::setEntityNameStringId const ucstring entityName,
uint32  stringId
 

Definition at line 520 of file eid_translator.cpp.

References RegisteredEntities, reit, and uint32.

00521 {
00522         const reit itEnd = RegisteredEntities.end();
00523         for (reit it = RegisteredEntities.begin(); it != itEnd ; ++it)
00524         {
00525                 if ((*it).second.EntityName == entityName)
00526                 {
00527                         (*it).second.EntityNameStringId = stringId;
00528                         return true;
00529                 }
00530         }
00531 
00532         return false;
00533 }

void NLMISC::CEntityIdTranslator::setEntityOnline const CEntityId eid,
bool  online
 

Definition at line 553 of file eid_translator.cpp.

References nlwarning, RegisteredEntities, reit, NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), and NLMISC::CEntityId::toString().

00554 {
00555         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00556         CEntityId reid(eid);
00557         reid.setCreatorId(0);
00558         reid.setDynamicId(0);
00559 
00560         reit it = RegisteredEntities.find (reid);
00561         if (it == RegisteredEntities.end ())
00562         {
00563                 nlwarning ("EIT: %s is not registered in CEntityIdTranslator", reid.toString().c_str());
00564         }
00565         else
00566         {
00567                 (*it).second.Online = online;
00568         }
00569 }

void NLMISC::CEntityIdTranslator::unregisterEntity const CEntityId eid  ) 
 

Definition at line 292 of file eid_translator.cpp.

References nlinfo, nlwarning, RegisteredEntities, reit, save(), NLMISC::CEntityId::setCreatorId(), NLMISC::CEntityId::setDynamicId(), and NLMISC::CEntityId::toString().

00293 {
00294         // we have to remove the crea and dyna because it can changed dynamically and will not be found in the storage array
00295         CEntityId reid(eid);
00296         reid.setCreatorId(0);
00297         reid.setDynamicId(0);
00298 
00299         reit it = RegisteredEntities.find (reid);
00300         
00301         if (it == RegisteredEntities.end ())
00302         {
00303                 nlwarning ("EIT: Can't unregister EId %s because EId is not in the map", reid.toString().c_str());
00304                 return;
00305         }
00306         
00307         nlinfo ("EIT: Unregister EId %s EntityName %s UId %d UserName %s", reid.toString().c_str(), (*it).second.EntityName.toString().c_str(), (*it).second.UId, (*it).second.UserName.c_str());
00308         RegisteredEntities.erase (reid);
00309         
00310         save ();
00311 }


Friends And Related Function Documentation

void cbInvalidEntityNamesFilename const std::string &  filename  )  [friend]
 

Definition at line 370 of file eid_translator.cpp.

Referenced by load().

00371 {
00372         CEntityIdTranslator::getInstance()->InvalidEntityNames.clear ();
00373 
00374         string fn = CPath::lookup(invalidEntityNamesFilename, false);
00375 
00376         if (fn.empty())
00377         {
00378                 nlwarning ("EIT: Can't load filename '%s' for invalid entity names filename (not found)", invalidEntityNamesFilename.c_str());
00379                 return;
00380         }
00381 
00382         FILE *fp = fopen (fn.c_str(), "r");
00383         if (fp == NULL)
00384         {
00385                 nlwarning ("EIT: Can't load filename '%s' for invalid entity names filename", fn.c_str());
00386                 return;
00387         }
00388 
00389         while (true)
00390         {
00391                 char str[512];
00392                 fgets(str, 511, fp);
00393                 if(feof(fp))
00394                         break;
00395                 if (strlen(str) > 0)
00396                 {
00397                         str[strlen(str)-1] = '\0';
00398                         CEntityIdTranslator::getInstance()->InvalidEntityNames.push_back(str);
00399                 }
00400         }
00401         
00402         fclose (fp);
00403 }

friend struct entityNameValidClass [friend]
 

Definition at line 141 of file eid_translator.h.


Field Documentation

std::string NLMISC::CEntityIdTranslator::FileName [private]
 

Definition at line 136 of file eid_translator.h.

uint NLMISC::CEntityIdTranslator::FileVersion
 

Definition at line 116 of file eid_translator.h.

Referenced by load(), and save().

CEntityIdTranslator * NLMISC::CEntityIdTranslator::Instance = NULL [static, private]
 

Definition at line 52 of file eid_translator.cpp.

std::vector<std::string> NLMISC::CEntityIdTranslator::InvalidEntityNames [private]
 

Definition at line 138 of file eid_translator.h.

Referenced by NLMISC::cbInvalidEntityNamesFilename(), and isValidEntityName().

std::map<NLMISC::CEntityId, CEntity> NLMISC::CEntityIdTranslator::RegisteredEntities [private]
 

Definition at line 122 of file eid_translator.h.

Referenced by checkEntity(), entityNameExists(), getByEntity(), getByUser(), getEntityIdInfo(), getEntityNameStringId(), getRegisteredEntities(), getUId(), getUserName(), isEntityOnline(), load(), registerEntity(), save(), setEntityNameStringId(), setEntityOnline(), and unregisterEntity().

const uint NLMISC::CEntityIdTranslator::Version = 1 [static]
 

Definition at line 55 of file eid_translator.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:08:13 2004 for NeL by doxygen 1.3.6