CFrameActionsRecorder(CDynamicMapClient &dmc) : _DMC(dmc), _Flushing(false) { _FrameActions.newSingleAction(ucstring()); }
//*************************************************************** void CAutoGroup::group(CObject *newEntityDesc, const NLMISC::CVectorD &createPosition) { //H_AUTO(R2_CAutoGroup_group) CInstance *destGroup = getGroupingCandidate(); if (!destGroup || !_AutoGroupEnabled) return; _AutoGroupEnabled = false; // force user to call 'update' again clear(); // remove any activity, dialog, or event in the copy CObject *behav = newEntityDesc->findAttr("Behavior"); if (behav) { behav->setObject("Actions", new CObjectTable()); behav->setObject("Activities", new CObjectTable()); behav->setObject("ChatSequences", new CObjectTable()); newEntityDesc->setObject("ActivitiesId", new CObjectTable()); } nlassert(newEntityDesc); nlassert(destGroup); std::string targetGroupId; if (destGroup->isKindOf("NpcGrpFeature")) { // make relative to newgroup and insert CVectorD relPos = createPosition; CDisplayerVisual *vd = destGroup->getDisplayerVisual(); if (vd) { relPos = relPos - vd->getWorldPos(); } newEntityDesc->setObject("Position", buildVector(relPos)); targetGroupId = destGroup->getId(); } else { // other is a standalone entity -> create a new group std::auto_ptr<CObject> newGroup(getEditor().getDMC().newComponent("NpcGrpFeature")); if (!newGroup.get()) { nlwarning("Syntax error in r2_features_npc_group.lua."); getEditor().getDMC().getActionHistoric().endAction(); getEditor().getDMC().flushActions(); return; } ucstring readableName; CLuaState &ls = getEditor().getLua(); R2::getEditor().getEnv()["PaletteIdToGroupTranslation"][newEntityDesc->getAttr("Base")->toString()].push(); if (ls.isString(-1)) readableName.fromUtf8(ls.toString(-1)); ucstring ucGroupName = ucstring(readableName + " " + CI18N::get("uiR2EDNameGroup").toUtf8()); newGroup->set("Name", getEditor().genInstanceName(ucGroupName).toUtf8()); getEditor().getDMC().requestInsertNode(destGroup->getParentAct()->getId(), "Features", -1, "", newGroup.get()); targetGroupId = getString(newGroup.get(), "InstanceId"); // move target instance in that group (becomes the leader) getEditor().getDMC().requestMoveNode(destGroup->getId(), "", -1, targetGroupId, "Components", -1); } // move newly created entity into target group getEditor().getDMC().requestInsertNode(targetGroupId, "Components", -1, "", newEntityDesc); getEditor().getDMC().getActionHistoric().endAction(); getEditor().getDMC().flushActions(); }
afs_int32 krb_write_ticket_file(char *realm) { int fd; int count; afs_int32 code; int lifetime, kvno; char *tf_name; struct ktc_principal client, server; struct ktc_token token; if ((strlen(realm) >= sizeof(client.cell))) return KABADNAME; strcpy(server.name, KA_TGS_NAME); strcpy(server.instance, realm); lcstring(server.cell, realm, sizeof(server.cell)); code = ktc_GetToken(&server, &token, sizeof(struct ktc_token), &client); if (code) return code; /* Use the KRBTKFILE environment variable if it exists, otherwise fall * back upon /tmp/tkt(uid}. */ if ((tf_name = (char *)getenv("KRBTKFILE"))) fd = open(tf_name, O_WRONLY | O_CREAT | O_TRUNC, 0700); else { afs_asprintf(&tf_name, "%s/tkt%d", gettmpdir(), getuid()); if (tf_name == NULL) return ENOMEM; fd = open(tf_name, O_WRONLY | O_CREAT | O_TRUNC, 0700); free(tf_name); } if (fd <= 0) return errno; /* write client name as file header */ count = strlen(client.name) + 1; if (write(fd, client.name, count) != count) goto bad; count = strlen(client.instance) + 1; if (write(fd, client.instance, count) != count) goto bad; /* Write the ticket and associated data */ /* Service */ count = strlen(server.name) + 1; if (write(fd, server.name, count) != count) goto bad; /* Instance */ count = strlen(server.instance) + 1; if (write(fd, server.instance, count) != count) goto bad; /* Realm */ ucstring(server.cell, server.cell, sizeof(server.cell)); count = strlen(server.cell) + 1; if (write(fd, server.cell, count) != count) goto bad; /* Session key */ if (write(fd, (char *)&token.sessionKey, 8) != 8) goto bad; /* Lifetime */ lifetime = time_to_life(token.startTime, token.endTime); if (write(fd, (char *)&lifetime, sizeof(int)) != sizeof(int)) goto bad; /* Key vno */ kvno = token.kvno; if (write(fd, (char *)&kvno, sizeof(int)) != sizeof(int)) goto bad; /* Tkt length */ if (write(fd, (char *)&(token.ticketLen), sizeof(int)) != sizeof(int)) goto bad; /* Ticket */ count = token.ticketLen; if (write(fd, (char *)(token.ticket), count) != count) goto bad; /* Issue date */ if (write(fd, (char *)&(token.startTime), sizeof(afs_int32)) != sizeof(afs_int32)) goto bad; close(fd); return 0; bad: close(fd); return -1; }
std::string CNelLauncherConnection::checkLogin(const std::string &login, const std::string &password, const std::string &clientApp) { m_Shards.clear(); m_Login = m_Password = m_ClientApp = ""; if(ConfigFile.exists("UseDirectClient") && ConfigFile.getVar("UseDirectClient").asBool()) { ucstring pwd = ucstring(password); NLMISC::CHashKeyMD5 hk = NLMISC::getMD5((uint8*)pwd.c_str(), pwd.size()); std::string cpwd = hk.toString(); nlinfo("The crypted password is %s", cpwd.c_str()); std::string result = NLNET::CLoginClient::authenticate(ConfigFile.getVar("StartupHost").asString(), login, cpwd, clientApp); if (!result.empty()) return result; for(uint i = 0; i < NLNET::CLoginClient::ShardList.size(); ++i) { nldebug("Shard '%u' '%s' '%u'", NLNET::CLoginClient::ShardList[i].Id, NLNET::CLoginClient::ShardList[i].Name.toString().c_str(), NLNET::CLoginClient::ShardList[i].NbPlayers); m_Shards.push_back(CShard("1", true, NLNET::CLoginClient::ShardList[i].Id, NLNET::CLoginClient::ShardList[i].Name.toString(), NLNET::CLoginClient::ShardList[i].NbPlayers, "1", "1")); } m_Login = login; m_Password = password; m_ClientApp = clientApp; return ""; } if(!connect()) return "Can't connect (error code 1)"; //if(VerboseLog) nlinfo("Connected"); if(!send(ConfigFile.getVar("StartupPage").asString()+"?login="******"&password="******"&clientApplication="+clientApp)) return "Can't send (error code 2)"; //if(VerboseLog) nlinfo("Sent request login check"); std::string res; if(!receive(res)) return "Can't receive (error code 3)"; //if(VerboseLog) nlinfo("Received request login check"); if(res.empty()) return "Empty answer from server (error code 4)"; if(res[0] == '0') { // server returns an error nlwarning("server error: %s", res.substr(2).c_str()); return res.substr(2); } else if(res[0] == '1') { // server returns ok, we have the list of shard uint nbs = atoi(res.substr(2).c_str()); std::vector<std::string> lines; NLMISC::explode(res, std::string("\n"), lines, true); // if(VerboseLog) // { //nlinfo ("Exploded, with nl, %d res", lines.size()); /* for (uint i = 0; i < lines.size(); i++) { nlinfo (" > '%s'", lines[i].c_str()); }*/ // } if(lines.size() != nbs+1) { nlwarning("bad shard lines number %d != %d", lines.size(), nbs+1); nlwarning("'%s'", res.c_str()); return "bad lines numbers (error code 5)"; } for(uint i = 1; i < lines.size(); i++) { std::vector<std::string> res; NLMISC::explode(lines[i], std::string("|"), res); // if(VerboseLog) // { // nlinfo ("Exploded with '%s', %d res", "|", res.size()); /* for (uint i = 0; i < res.size(); i++) { nlinfo (" > '%s'", res[i].c_str()); }*/ // } if(res.size() != 7) { nlwarning("bad | numbers %d != %d", res.size(), 7); nlwarning("'%s'", lines[i].c_str()); return "bad pipe numbers (error code 6)"; } m_Shards.push_back(CShard(res[0], atoi(res[1].c_str())>0, atoi(res[2].c_str()), res[3], atoi(res[4].c_str()), res[5], res[6])); } } else { // server returns ??? nlwarning("%s", res.c_str()); return res; } m_Login = login; m_Password = password; m_ClientApp = clientApp; return ""; }
/* Load the config file and the related words files. Return false in case of failure. * Config file variables: * - WordsPath: where to find <filter>_words_<languageCode>.txt * - LanguageCode: language code (ex: en for English) * - Utf8: results are in UTF8, otherwise in ANSI string * - Filter: "*" for all files (default) or a name (ex: "item"). * - AdditionalFiles/AdditionalFileColumnTitles */ bool CWordsDictionary::init( const string& configFileName ) { // Read config file bool cfFound = false; CConfigFile cf; try { cf.load( configFileName ); cfFound = true; } catch ( EConfigFile& e ) { nlwarning( "WD: %s", e.what() ); } string wordsPath, languageCode, filter = "*"; vector<string> additionalFiles, additionalFileColumnTitles; bool filterAll = true, utf8 = false; if ( cfFound ) { CConfigFile::CVar *v = cf.getVarPtr( "WordsPath" ); if ( v ) { wordsPath = v->asString(); /*if ( (!wordsPath.empty()) && (wordsPath[wordsPath.size()-1]!='/') ) wordsPath += '/';*/ } v = cf.getVarPtr( "LanguageCode" ); if ( v ) languageCode = v->asString(); v = cf.getVarPtr( "Utf8" ); if ( v ) utf8 = (v->asInt() == 1); v = cf.getVarPtr( "Filter" ); if ( v ) { filter = v->asString(); filterAll = (filter == "*"); } v = cf.getVarPtr( "AdditionalFiles" ); if ( v ) { for ( uint i=0; i!=v->size(); ++i ) additionalFiles.push_back( v->asString( i ) ); v = cf.getVarPtr( "AdditionalFileColumnTitles" ); if ( v->size() != additionalFiles.size() ) { nlwarning( "AdditionalFiles and AdditionalFileColumnTitles have different size, ignoring second one" ); additionalFileColumnTitles.resize( v->size(), DefaultColTitle ); } else { for ( uint i=0; i!=v->size(); ++i ) additionalFileColumnTitles.push_back( v->asString( i ) ); } } } if ( languageCode.empty() ) languageCode = "en"; // Load all found words files const string ext = ".txt"; vector<string> fileList; CPath::getPathContent( wordsPath, false, false, true, fileList ); for ( vector<string>::const_iterator ifl=fileList.begin(); ifl!=fileList.end(); ++ifl ) { const string& filename = (*ifl); string::size_type p = string::npos; bool isAdditionalFile = false; // Test if filename is in additional file list uint iAdditionalFile; for ( iAdditionalFile=0; iAdditionalFile!=additionalFiles.size(); ++iAdditionalFile ) { if ( (p = filename.find( additionalFiles[iAdditionalFile] )) != string::npos ) { isAdditionalFile = true; break; } } // Or test if filename is a words_*.txt file string pattern = string("_words_") + languageCode + ext; if ( isAdditionalFile || ((p = filename.find( pattern )) != string::npos) ) { // Skip if a filter is specified and does not match the current file if ( (!filterAll) && (filename.find( filter+pattern ) == string::npos) ) continue; // Load file nldebug( "WD: Loading %s", filename.c_str() ); _FileList.push_back( filename ); string::size_type origSize = filename.size() - ext.size(); const string truncFilename = CFile::getFilenameWithoutExtension( filename ); const string wordType = isAdditionalFile ? "" : truncFilename.substr( 0, p - (origSize - truncFilename.size()) ); const string colTitle = isAdditionalFile ? additionalFileColumnTitles[iAdditionalFile] : DefaultColTitle; // Load Unicode Excel words file STRING_MANAGER::TWorksheet worksheet; STRING_MANAGER::loadExcelSheet( filename, worksheet ); uint ck, cw = 0; if ( worksheet.findId( ck ) && worksheet.findCol( ucstring(colTitle), cw ) ) // => { for ( std::vector<STRING_MANAGER::TWorksheet::TRow>::iterator ip = worksheet.begin(); ip!=worksheet.end(); ++ip ) { if ( ip == worksheet.begin() ) // skip first row continue; STRING_MANAGER::TWorksheet::TRow& row = *ip; _Keys.push_back( row[ck].toString() ); string word = utf8 ? row[cw].toUtf8() : row[cw].toString(); _Words.push_back( word ); } } else nlwarning( "WD: %s ID or %s not found in %s", wordType.c_str(), colTitle.c_str(), filename.c_str() ); } } if ( _Keys.empty() ) { if ( wordsPath.empty() ) nlwarning( "WD: WordsPath missing in config file %s", configFileName.c_str() ); nlwarning( "WD: %s_words_%s.txt not found", filter.c_str(), languageCode.c_str() ); return false; } else return true; }
afs_int32 ka_ParseLoginName(char *login, char name[MAXKTCNAMELEN], char inst[MAXKTCNAMELEN], char cell[MAXKTCREALMLEN]) { int login_len = strlen(login); char rc, c; int i, j; #define READNAME 1 #define READINST 2 #define READCELL 3 int reading; if (!name) return KABADARGUMENT; strcpy(name, ""); if (inst) strcpy(inst, ""); if (cell) strcpy(cell, ""); reading = READNAME; i = 0; j = 0; while (i < login_len) { rc = login[i]; c = map_char(login, &i); switch (reading) { case READNAME: if (rc == '@') { name[j] = 0; /* finish name */ reading = READCELL; /* but instance is null */ j = 0; break; } if (inst && (rc == '.')) { name[j] = 0; /* finish name */ reading = READINST; j = 0; break; } if (j >= MAXKTCNAMELEN - 1) return KABADNAME; name[j++] = c; break; case READINST: if (!inst) return KABADNAME; if (rc == '@') { inst[j] = 0; /* finish name */ reading = READCELL; j = 0; break; } if (j >= MAXKTCNAMELEN - 1) return KABADNAME; inst[j++] = c; break; case READCELL: if (!cell) return KABADNAME; if (j >= MAXKTCREALMLEN - 1) return KABADNAME; cell[j++] = c; break; } i++; } if (reading == READNAME) name[j] = 0; else if (reading == READINST) { if (inst) inst[j] = 0; else return KABADNAME; } else if (reading == READCELL) { if (cell) cell[j] = 0; else return KABADNAME; } /* the cell is really an authDomain and therefore is really a realm */ if (cell) ucstring(cell, cell, MAXKTCREALMLEN); return 0; }