void writeData(const QString& filename, const QString& defaultFilename, const AttributeMap& data, writeMode mode) throw(ParseError, Exception) { FNTRACE("ini", "", "writeData", QString("%1, %2, %3 rows of data, %4") .arg(filename).arg(defaultFilename).arg(data.size()).arg(mode)); QFile file(filename); if (!file.exists()) ETHROW(Exception(QString("File %1 does not exist.").arg(filename))); if (mode == preserve || mode == full) { QByteArray buf; QTextStream out(&buf); if (mode == full) { QFile defini(defaultFilename); writePreserving(defini, out, data); } else { writePreserving(file, out, data); } out.setDevice(0); if (file.isOpen()) file.close(); if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate) || !file.isWritable()) ETHROW(Exception(QString("Unable to open %1 for writing.").arg(filename))); //file.resize(0); //if (!file.isOpen() || !file.isWritable()) // ETHROW(Exception(QString("%1 not writeable after resize.").arg(filename))); //file.close(); /*if (!file.isOpen() || !file.isWritable()) ETHROW(Exception(QString("%1 not writeable after closeing.").arg(filename)));*/ //if (!file.open(QIODevice::ReadWrite | QIODevice::Text) || !file.isWritable()) // ETHROW(Exception(QString("Unable to open %1 for writing.").arg(filename))); /*file.seek(0); if (!file.isOpen() || !file.isWritable()) ETHROW(Exception(QString("%1 not writeable after seek.").arg(filename)));*/ out.setDevice(&file); if (!file.isOpen() || !file.isWritable()) ETHROW(Exception(QString("%1 not writeable after stream-association.").arg(filename))); out << buf << flush; } else writeSparse(file, data); }
vector<AttributeMap> Ldap::search(string base, int scope, string filter, const StringList& attribs) { if(bound == false) { return vector<AttributeMap>(); } LDAPSearchResults* lr = lc->search(base, scope, filter,attribs, false); LDAPEntry* le; const LDAPAttribute* la; StringList s; vector<AttributeMap> result; AttributeMap temp; int i = 0; while( (le = lr->getNext()) ) { for(StringList::const_iterator it =attribs.begin(); it!=attribs.end(); it++) { //cout << endl << "Name: " << *it << " |"; la = le->getAttributeByName(*it); if(la == NULL) continue; s = la->getValues(); for(StringList::const_iterator st = s.begin(); st != s.end(); st ++) { // concatenates multivalues with | temp[*it] += (i>0?"|"+*st:*st); i++; } i=0; } //cout << endl; if(temp.size() > 0) { result.push_back(temp); temp.clear(); } } return result; }
void readData(const QString& filename, AttributeMap& data) throw(ParseError, Exception) { FNTRACE("ini", "", "readData", QString("%1, %2 rows of data").arg(filename).arg(data.size())); QFile file(filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) ETHROW(Exception(QString("Unable to open %1 for reading.").arg(filename))); QByteArray line; size_t lineNumber = 0; while (!file.atEnd()) { line = file.readLine(); ++lineNumber; // trim comments and whitespace if (line.isEmpty()) continue; if (line.contains(COMMENT_BEGIN)) line.truncate(line.indexOf(COMMENT_BEGIN)); if (line.isEmpty()) continue; line = line.trimmed(); if (line.isEmpty()) continue; // name=value pair? else if (line.contains(ASSIGNER)) { QString name = line.left(line.indexOf(ASSIGNER)); name = name.trimmed(); if (name.isEmpty()) ETHROW(ParseError(filename, lineNumber, "Empty name left of assigner.")); QString value = line.right(line.length() - line.indexOf(ASSIGNER) - 1); value = value.trimmed(); data[name] = value; } else ETHROW(ParseError(filename, lineNumber, "Unknown non-empty line.")); } }
void writePreserving(QFile& inFile, QTextStream& out, const AttributeMap& data) { FNTRACE("ini", "", "writePreserving", QString("in, out, %1 rows of data").arg(data.size())); int i, j; QChar c; QString name; size_t lineNumber = 0; QString line; typedef QSet<AttributeMap::key_type> KeySet; KeySet unwrittenKeys = KeySet::fromList(data.keys()); if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text)) ETHROW(Exception(QString("Unable to open %1 for reading.").arg(inFile.fileName()))); QTextStream in(&inFile); while (!(line = in.readLine()).isNull()) { ++lineNumber; //std::cout << lineNumber << ": " << line.toStdString() << ":\n"; for (i = 0; line[i].isSpace(); ++i) { out << line[i]; } if (line[i].isNull()) { out << '\n'; continue; } else if (line[i] == COMMENT_BEGIN) { out << line.mid(i) << '\n'; continue; } for (j = i; !(c = line[i]).isNull() && c!=COMMENT_BEGIN && c!=ASSIGNER; ++i) ; //std::cout << "non-empty, "; if (c != ASSIGNER) // non-empty line that isn't assignment -> invalid ETHROW(ParseError(inFile.fileName(), lineNumber, "Unknown non-empty line.")); for (--i; line[i].isSpace(); --i) ; // last character of name name = line.mid(j, i - j + 1); //std::cout << "name: " << name.toStdString() << ' '; for ( ; line[j]!=ASSIGNER; ++j) out << line[j]; out << ASSIGNER; i = j + 1; for ( ; line[i].isSpace(); ++i) out << line[i]; if (data.contains(name)) { //std::cout << "known "; out << data.value(name); unwrittenKeys.remove(name); for (j = i; !line[i].isNull() && line[i]!=COMMENT_BEGIN; ++i) ; // EOL || comment for (--i; line[i].isSpace(); --i) ; // last character of value ++i; // first character after value } out << line.mid(i) << '\n'; //std::cout << '\n'; } if (unwrittenKeys.size()) { out << '\n' << COMMENT_BEGIN << "Following lines were generated by Ds1edit Loader:\n"; for (KeySet::iterator key = unwrittenKeys.begin(); key != unwrittenKeys.end(); ++key) out << (*key) << ' ' << ASSIGNER << ' ' << data.value(*key) << '\n'; } //in.resize(in.pos()+1); inFile.close(); }
void writeSparse(QFile& file, const AttributeMap& data) { FNTRACE("ini", "", "writeSparse", QString("file %1, %2 rows of data").arg(file.fileName()).arg(data.size())); if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) ETHROW(Exception(QString("Unable to open %1 for writing.").arg(file.fileName()))); file.resize(0); QTextStream fout(&file); int max_key_length = 0; for (AttributeMap::const_iterator iter = data.begin(); iter != data.end(); ++iter) { if (iter.key().length() > max_key_length) max_key_length = iter.key().length(); } for (AttributeMap::const_iterator iter = data.begin(); iter != data.end(); ++iter) { fout << iter.key(); for (int i = iter.key().length(); i < max_key_length; ++i) fout << ' '; fout << " = " << iter.value() << "\n"; } }
void ManufacturingSchematic::sendAttributes(PlayerObject* playerObject) { if(playerObject->getConnectionState() != PlayerConnState_Connected) return; TangibleObject* tItem = this->getItem(); if(!tItem) return; AttributeMap::iterator mapIt; AttributeMap* iAttributeMap = tItem->getAttributeMap(); AttributeOrderList* iAttributeOrderList = tItem->getAttributeOrder(); AttributeMap* rAttributeMap = getAttributeMap(); AttributeOrderList* rAttributeOrderList = getAttributeOrder(); //DraftSchematic* draftSchematic = gSchematicManager->getSchematicBySlotId(mDynamicInt32); //DraftSlots* draftSlots = draftSchematic->getDraftSlots(); Message* newMessage; string value,aStr; BStringVector dataElements; //uint32 amountSlots = draftSlots->size(); //uint8 i = 0; gMessageFactory->StartMessage(); gMessageFactory->addUint32(opAttributeListMessage); gMessageFactory->addUint64(mId); //add slots and resource/item requirements gMessageFactory->addUint32(iAttributeMap->size()+ rAttributeMap->size()+1); AttributeOrderList::iterator orderIt = rAttributeOrderList->begin(); while(orderIt != rAttributeOrderList->end()) { mapIt = rAttributeMap->find(*orderIt); gMessageFactory->addString(gWorldManager->getAttributeKey((*mapIt).first)); value = (*mapIt).second.c_str(); value.convert(BSTRType_Unicode16); gMessageFactory->addString(value); ++orderIt; } //attributes .... gMessageFactory->addString(BString("manf_attribs")); aStr = "\\#"SOE_RED" --------------"; aStr.convert(BSTRType_Unicode16); gMessageFactory->addString(aStr); orderIt = iAttributeOrderList->begin(); while(orderIt != iAttributeOrderList->end()) { mapIt = iAttributeMap->find(*orderIt); gMessageFactory->addString(gWorldManager->getAttributeKey((*mapIt).first)); value = (*mapIt).second.c_str(); value.convert(BSTRType_Unicode16); gMessageFactory->addString(value); ++orderIt; } //gMessageFactory->addUint32(0xffffffff); newMessage = gMessageFactory->EndMessage(); (playerObject->getClient())->SendChannelAUnreliable(newMessage, playerObject->getAccountId(),CR_Client,9); }
void FactoryCrate::sendAttributes(PlayerObject* playerObject) { if(!(playerObject->isConnected())) return; AttributeMap* iAttributeMap = this->getLinkedObject()->getAttributeMap(); AttributeOrderList* iAttributeOrderList = this->getLinkedObject()->getAttributeOrder(); Message* newMessage; gMessageFactory->StartMessage(); gMessageFactory->addUint32(opAttributeListMessage); gMessageFactory->addUint64(mId); gMessageFactory->addUint32(2 + mAttributeMap.size()+iAttributeMap->size()); BString tmpValueStr = BString(BSTRType_Unicode16,64); BString value,aStr; tmpValueStr.setLength(swprintf(tmpValueStr.getUnicode16(),50,L"%u/%u",mMaxCondition - mDamage,mMaxCondition)); gMessageFactory->addString(BString("condition")); gMessageFactory->addString(tmpValueStr); AttributeMap::iterator mapIt; AttributeOrderList::iterator orderIt = mAttributeOrderList.begin(); while(orderIt != mAttributeOrderList.end()) { mapIt = mAttributeMap.find(*orderIt); gMessageFactory->addString(gWorldManager->getAttributeKey((*mapIt).first)); value = (*mapIt).second.c_str(); value.convert(BSTRType_Unicode16); gMessageFactory->addString(value); ++orderIt; } gMessageFactory->addString(BString("factory_attribs")); aStr = "\\#"SOE_RED" --------------"; aStr.convert(BSTRType_Unicode16); gMessageFactory->addString(aStr); orderIt = iAttributeOrderList->begin(); while(orderIt != iAttributeOrderList->end()) { mapIt = iAttributeMap->find(*orderIt); gMessageFactory->addString(gWorldManager->getAttributeKey((*mapIt).first)); value = (*mapIt).second.c_str(); value.convert(BSTRType_Unicode16); gMessageFactory->addString(value); ++orderIt; } newMessage = gMessageFactory->EndMessage(); (playerObject->getClient())->SendChannelAUnreliable(newMessage, playerObject->getAccountId(), CR_Client, 9); }
bool MessageLib::sendBaselinesMSCO_3(ManufacturingSchematic* manSchem,PlayerObject* playerObject,bool sendAttributes) { if(!(playerObject->isConnected())) return(false); Message* message; Message* part; DraftSchematic* draftSchematic = gSchematicManager->getSchematicBySlotId(manSchem->getDynamicInt32()); AttributeMap* attributes = manSchem->getAttributeMap(); AttributeMap::iterator it = attributes->begin(); uint32 attByteCount = 0; if(sendAttributes) { while(it != attributes->end()) { attByteCount += 21 + gWorldManager->getAttributeKey((*it).first).getLength(); ++it; } } if(!draftSchematic) return(false); string convPlayerName = playerObject->getFirstName(); string convCustomName = manSchem->getCustomName(); convPlayerName.convert(BSTRType_Unicode16); convCustomName.convert(BSTRType_Unicode16); mMessageFactory->StartMessage(); //object count mMessageFactory->addUint16(13); //0 mMessageFactory->addFloat(static_cast<float>(draftSchematic->getComplexity())); //1 mMessageFactory->addString(manSchem->getNameFile()); mMessageFactory->addUint32(0); mMessageFactory->addString(manSchem->getName()); //2 mMessageFactory->addString(convCustomName); //3 = volume mMessageFactory->addUint32(1); //4 = schematic quantity used with schematics with limited uses mMessageFactory->addUint32(1); //5 // send attributes on baseline so that they are shown on assembly //cave review update counter if(sendAttributes) { manSchem->mAttributesUpdateCounter = attributes->size(); mMessageFactory->addUint32(attributes->size()); mMessageFactory->addUint32(manSchem->mAttributesUpdateCounter); it = attributes->begin(); while(it != attributes->end()) { mMessageFactory->addUint8(0); mMessageFactory->addString(BString("crafting")); mMessageFactory->addUint32(0); mMessageFactory->addString(gWorldManager->getAttributeKey((*it).first)); //=============================0 // see whether the attribute has any component values which need adding in the preview if(manSchem->hasPPAttribute(gWorldManager->getAttributeKey((*it).first))) { float attributeValue = boost::lexical_cast<float,std::string>((*it).second); float attributeAddValue = manSchem->getPPAttribute<float>(gWorldManager->getAttributeKey((*it).first)); gLogger->logMsgF("MessageLib::sendBaselinesMSCO_3 Attribute Add Value",MSG_NORMAL); gLogger->logMsgF("MessageLib::sendBaselinesMSCO_3 we will add %f to %S",MSG_NORMAL,attributeAddValue,gWorldManager->getAttributeKey((*it).first).getAnsi()); mMessageFactory->addFloat(attributeValue+attributeAddValue); } else mMessageFactory->addFloat(boost::lexical_cast<float,std::string>((*it).second)); ++it; } } else { mMessageFactory->addUint32(0); mMessageFactory->addUint32(0); } //6 creators name mMessageFactory->addString(convPlayerName); //7 complexity mMessageFactory->addUint32(static_cast<uint32>(manSchem->getComplexity())); // schematic data size mMessageFactory->addUint32(1); part = mMessageFactory->EndMessage(); mMessageFactory->StartMessage(); mMessageFactory->addUint32(opBaselinesMessage); mMessageFactory->addUint64(manSchem->getId()); mMessageFactory->addUint32(opMSCO); mMessageFactory->addUint8(3); mMessageFactory->addUint32(part->getSize()); mMessageFactory->addData(part->getData(),part->getSize()); message = mMessageFactory->EndMessage(); part->setPendingDelete(true); (playerObject->getClient())->SendChannelA(message,playerObject->getAccountId(),CR_Client,5); return(true); }
bool MessageLib::sendDeltasMSCO_3(ManufacturingSchematic* manSchem,PlayerObject* playerObject) { if(!(playerObject->isConnected())) return(false); Message* newMessage; AttributeMap* attributes = manSchem->getAttributeMap(); AttributeMap::iterator it = attributes->begin(); uint32 attByteCount = 0; // attributes we update here are the attrivutes the final object will have on completion while(it != attributes->end()) { attByteCount += 21 + gWorldManager->getAttributeKey((*it).first).getLength(); ++it; } mMessageFactory->StartMessage(); mMessageFactory->addUint32(opDeltasMessage); mMessageFactory->addUint64(manSchem->getId()); mMessageFactory->addUint32(opMSCO); mMessageFactory->addUint8(3); mMessageFactory->addUint32(12 + attByteCount); mMessageFactory->addUint16(1); mMessageFactory->addUint16(5); mMessageFactory->addUint32(attributes->size()); mMessageFactory->addUint32(++manSchem->mAttributesUpdateCounter); it = attributes->begin(); while(it != attributes->end()) { mMessageFactory->addUint8(2); mMessageFactory->addString(BString("crafting")); mMessageFactory->addUint32(0); mMessageFactory->addString(gWorldManager->getAttributeKey((*it).first)); if(manSchem->hasPPAttribute(gWorldManager->getAttributeKey((*it).first))) { float attributeValue = boost::lexical_cast<float,std::string>((*it).second); float attributeAddValue = manSchem->getPPAttribute<float>(gWorldManager->getAttributeKey((*it).first)); mMessageFactory->addFloat(attributeValue+attributeAddValue); } else mMessageFactory->addFloat(boost::lexical_cast<float,std::string>((*it).second)); //mMessageFactory->addFloat(boost::lexical_cast<float,std::string>((*it).second)); ++it; } newMessage = mMessageFactory->EndMessage(); (playerObject->getClient())->SendChannelA(newMessage,playerObject->getAccountId(),CR_Client,5); return(true); }