void ConfigFile::removeKey(const String &key, const String §ion) { assert(isValidName(key)); assert(isValidName(section)); Section *s = getSection(section); if (s) s->removeKey(key); }
bool ConfigFile::hasKey(const String &key, const String §ion) const { assert(isValidName(key)); assert(isValidName(section)); const Section *s = getSection(section); if (!s) return false; return s->hasKey(key); }
bool ConfigFile::getKey(const String &key, const String §ion, String &value) const { assert(isValidName(key)); assert(isValidName(section)); const Section *s = getSection(section); if (!s) return false; const KeyValue *kv = s->getKey(key); if (!kv) return false; value = kv->value; return true; }
void ConfigFile::renameSection(const String &oldName, const String &newName) { assert(isValidName(oldName)); assert(isValidName(newName)); //Section *os = getSection(oldName); Section *ns = getSection(newName); if (ns) { ns->name = newName; } // TODO: Check here whether there already is a section with the // new name. Not sure how to cope with that case, we could: // - simply remove the existing "newName" section // - error out // - merge the two sections "oldName" and "newName" }
void BaseObject::setName(const QString &name) { //Raises an error if the passed name is empty if(name.isEmpty()) throw Exception(ERR_ASG_EMPTY_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else { int count; QString aux_name=name; count=aux_name.count(QChar('\0')); if(count >=1) aux_name.chop(count); //Raises an error if the passed name is invalid if(!isValidName(aux_name)) { if(name.size() > OBJECT_NAME_MAX_LENGTH) throw Exception(ERR_ASG_LONG_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else throw Exception(ERR_ASG_INV_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); } else { aux_name.remove('\"'); this->obj_name=aux_name; } } }
PassRefPtr<CustomElementConstructor> CustomElementRegistry::registerElement(ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec) { RefPtr<CustomElementRegistry> protect(this); if (!CustomElementHelpers::isFeatureAllowed(state)) return 0; AtomicString lowerName = name.lower(); if (!isValidName(lowerName)) { ec = INVALID_CHARACTER_ERR; return 0; } ScriptValue prototypeValue; if (!options.get("prototype", prototypeValue)) { // FIXME: Implement the default value handling. // Currently default value of the "prototype" parameter, which // is HTMLSpanElement.prototype, has an ambiguity about its // behavior. The spec should be fixed before WebKit implements // it. https://www.w3.org/Bugs/Public/show_bug.cgi?id=20801 ec = INVALID_STATE_ERR; return 0; } AtomicString namespaceURI; if (!CustomElementHelpers::isValidPrototypeParameter(prototypeValue, state, namespaceURI)) { ec = INVALID_STATE_ERR; return 0; } if (m_names.contains(lowerName)) { ec = INVALID_STATE_ERR; return 0; } const QualifiedName* localNameFound = CustomElementHelpers::findLocalName(prototypeValue); QualifiedName typeName(nullAtom, lowerName, namespaceURI); QualifiedName localNameToUse = localNameFound ? *localNameFound : typeName; if (find(typeName, localNameToUse)) { ec = INVALID_STATE_ERR; return 0; } // A script execution could happen in isValidPrototypeParameter(), which kills the document. if (!document()) { ec = INVALID_STATE_ERR; return 0; } RefPtr<CustomElementConstructor> constructor = CustomElementConstructor::create(state, document(), typeName, localNameToUse, prototypeValue); if (!constructor) { ec = INVALID_STATE_ERR; return 0; } m_constructors.add(std::make_pair(constructor->typeName(), constructor->localName()), constructor); m_names.add(lowerName); return constructor; }
void CustomElementRegistry::registerElement(CustomElementConstructorBuilder* constructorBuilder, const AtomicString& userSuppliedName, ExceptionCode& ec) { RefPtr<CustomElementRegistry> protect(this); if (!constructorBuilder->isFeatureAllowed()) return; AtomicString type = userSuppliedName.lower(); if (!isValidName(type)) { ec = INVALID_CHARACTER_ERR; return; } if (!constructorBuilder->validateOptions()) { ec = INVALID_STATE_ERR; return; } QualifiedName tagName = nullQName(); if (!constructorBuilder->findTagName(type, tagName)) { ec = NAMESPACE_ERR; return; } ASSERT(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.namespaceURI() == SVGNames::svgNamespaceURI); if (m_definitions.contains(type)) { ec = INVALID_STATE_ERR; return; } RefPtr<CustomElementCallback> lifecycleCallbacks = constructorBuilder->createCallback(document()); // Consulting the constructor builder could execute script and // kill the document. if (!document()) { ec = INVALID_STATE_ERR; return; } RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create(type, tagName.localName(), tagName.namespaceURI(), lifecycleCallbacks); if (!constructorBuilder->createConstructor(document(), definition.get())) { ec = NOT_SUPPORTED_ERR; return; } m_definitions.add(definition->type(), definition); // Upgrade elements that were waiting for this definition. CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidates.takeUpgradeCandidatesFor(definition.get()); constructorBuilder->didRegisterDefinition(definition.get(), upgradeCandidates); for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCandidates.begin(); it != upgradeCandidates.end(); ++it) { (*it)->setNeedsStyleRecalc(); // :unresolved has changed enqueueReadyCallback(lifecycleCallbacks.get(), *it); } }
void ConfigFile::removeSection(const String §ion) { assert(isValidName(section)); for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { if (section.equalsIgnoreCase(i->name)) { _sections.erase(i); return; } } }
bool RObject::canAccommodateStructure (RData *new_data) { RK_TRACE (OBJECTS); RK_ASSERT (new_data->getDataLength () >= 5); RK_ASSERT (new_data->getDataType () == RData::StructureVector); if (!isValidName (new_data->getStructureVector ()[0])) return false; if (!isValidType (new_data->getStructureVector ()[1])) return false; return true; }
void ConfigFile::removeSection(const String §ion) { assert(isValidName(section)); for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { if (!scumm_stricmp(section.c_str(), i->name.c_str())) { _sections.erase(i); return; } } }
/** @param wrapperName the wrapper name that must be valid, see isValidName() @return false if the name is an illegal string. */ bool PWrapper::setName(const QString &wrapperName) { // Prevent illegal names if (!isValidName(wrapperName)) { return false; } d->m_name = wrapperName; return true; }
void ConfigFile::renameSection(const String &oldName, const String &newName) { assert(isValidName(oldName)); assert(isValidName(newName)); Section *os = getSection(oldName); const Section *ns = getSection(newName); if (os) { // HACK: For now we just print a warning, for more info see the TODO // below. if (ns) warning("ConfigFile::renameSection: Section name \"%s\" already used", newName.c_str()); else os->name = newName; } // TODO: Check here whether there already is a section with the // new name. Not sure how to cope with that case, we could: // - simply remove the existing "newName" section // - error out // - merge the two sections "oldName" and "newName" }
void ConfigFile::setKey(const String &key, const String §ion, const String &value) { assert(isValidName(key)); assert(isValidName(section)); // TODO: Verify that value is valid, too. In particular, it shouldn't // contain CR or LF... Section *s = getSection(section); if (!s) { KeyValue newKV; newKV.key = key; newKV.value = value; Section newSection; newSection.name = section; newSection.keys.push_back(newKV); _sections.push_back(newSection); } else { s->setKey(key, value); } }
void Operator::setName(const QString &name) { if(name=="") throw Exception(ERR_ASG_EMPTY_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else { if(!isValidName(name)) throw Exception(ERR_ASG_INV_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else this->obj_name=name; } }
void VolumeGroupDialog::updateOkButtonStatus() { bool enable = isValidSize(); if (dialogWidget().vgName().text().isEmpty() || !isValidName()) { enable = false; } if (dialogWidget().spinPESize().value() <= 0) { enable = false; } okButton->setEnabled(enable); }
std::string getScope(const std::string& scopedName) { if (!isValidName(scopedName)) { throw "Invalid name"; } if (!isScoped(scopedName)) { throw "Supplied name is not scoped"; } std::string result(scopedName); int pos = result.find(':', 0); return result.substr(0, pos); }
std::string getUnscopedName(const std::string& scopedName) { if (!isValidName(scopedName)) { throw "Invalid name"; } std::string result(scopedName); if (isScoped(scopedName)) { int index = scopedName.find(':', 0); result.erase(0, index + 1); } return result; }
/** * Add a new column to the database via the ColumnEditor dialog. Called when * the "Add" button is pressed. */ void DBEditor::addColumn() { QString name = ""; int type = STRING; QString defaultVal = ""; columnEditor->setName(name); columnEditor->setType(type); columnEditor->setTypeEditable(true); columnEditor->setDefaultValue(defaultVal); bool finished = false; bool aborted = false; while (!finished) { if (!columnEditor->exec()) { finished = true; aborted = true; } else { name = columnEditor->name(); type = columnEditor->type(); defaultVal = columnEditor->defaultValue(); finished = (isValidName(name) && isValidDefault(type, defaultVal)); } } int decimals = 2; CalcNode *calcRoot = columnEditor->calculation(&decimals); if (!aborted) { int size = info.GetSize(); info.Add(ceName [name.toUtf8()] + ceType [type] + ceDefault[defaultVal.toUtf8()] + ceOldIndex [-1] + ceNewIndex[size]); if (type == CALC) { calcMap.insert(name, calcRoot); decimalsMap.insert(name, decimals); columnEditor->setCalculation(0, 2); calcRoot = 0; } updateTable(); } if (calcRoot != 0) { delete calcRoot; columnEditor->setCalculation(0, 2); } }
QString GameObjectManager::uniqueName(GameObject* object, const QString& newName) { if (! object) return newName; QString name = newName; if (name.isEmpty()) name = object->name(); if (name.isEmpty()) { const GameObjectMetaType* metatype = GameObjectMetaType::metaType(object->type()); name = metatype ? metatype->toString() : ""; } while(! isValidName(object, name)) { name = Utils::incrementLastNumber(name); } return name; }
void BaseObject::setName(const QString &name) { QString aux_name=name; bool is_quoted=aux_name.contains(QRegExp("^(\")(.)+(\")$")); //Raises an error if the passed name is invalid if(!isValidName(aux_name)) { if(aux_name.isEmpty()) throw Exception(ERR_ASG_EMPTY_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); //If the name is quoted we add 2 bytes to the maximum in order to check if it exceeds the limit else if(aux_name.size() > (OBJECT_NAME_MAX_LENGTH + (is_quoted ? 2 : 0))) throw Exception(ERR_ASG_LONG_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else throw Exception(ERR_ASG_INV_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); } aux_name.remove('"'); setCodeInvalidated(this->obj_name!=aux_name); this->obj_name=aux_name; }
void LLPanelClassifiedEdit::onSaveClick() { mCanClose = false; if(!isValidName()) { notifyInvalidName(); return; } if(isNew() || isNewWithErrors()) { if(gStatusBar->getBalance() < getPriceForListing()) { LLNotificationsUtil::add("ClassifiedInsufficientFunds"); return; } mPublishFloater = LLFloaterReg::findTypedInstance<LLPublishClassifiedFloater>( "publish_classified", LLSD()); if(!mPublishFloater) { mPublishFloater = LLFloaterReg::getTypedInstance<LLPublishClassifiedFloater>( "publish_classified", LLSD()); mPublishFloater->setPublishClickedCallback(boost::bind (&LLPanelClassifiedEdit::onPublishFloaterPublishClicked, this)); } // set spinner value before it has focus or value wont be set mPublishFloater->setPrice(getPriceForListing()); mPublishFloater->openFloater(mPublishFloater->getKey()); mPublishFloater->center(); } else { doSave(); } }
void ConfigFile::load(SeekableReadStream &stream) { UString comment; ConfigDomain *domain = 0; int lineNumber = 0; int domainLineNumber = 0; while (!stream.eos()) { lineNumber++; // Read a line UString line = readStringLine(stream, kEncodingUTF8); // Parse it UString domainName; UString key, value, lineComment; parseConfigLine(line, domainName, key, value, lineComment, lineNumber); if (!domainName.empty()) { // New domain // Finish up the old domain addDomain(domain, domainLineNumber); // Check that the name is actually valid if (!isValidName(domainName)) throw Exception("\"%s\" isn't a valid domain name (line %d)", domainName.c_str(), lineNumber); // Create the new domain domain = new ConfigDomain(domainName); domain->_prologue = comment; domain->_comment = lineComment; comment.clear(); lineComment.clear(); domainLineNumber = lineNumber; } if (!key.empty()) { // New key if (!domain) throw Exception("Found a key outside a domain (line %d)", lineNumber); if (!isValidName(key)) throw Exception("\"%s\" isn't a valid key name (line %d)", key.c_str(), lineNumber); // Add collected comments to the domain if (!comment.empty()) addDomainKey(*domain, "", "", comment, lineNumber); // Add the key to the domain addDomainKey(*domain, key, value, lineComment, lineNumber); comment.clear(); lineComment.clear(); } // Collect comments, we don't yet know where those belong to. if (!lineComment.empty()) { if (!comment.empty()) comment += '\n'; comment += lineComment; } // Empty line, associate collected comments with the current domain if (domainName.empty() && key.empty() && value.empty() && lineComment.empty()) { if (!comment.empty() && !stream.eos()) { if (!domain) { // We have no domain yet, add it to the file's prologue if (!_prologue.empty()) _prologue += '\n'; _prologue += comment; } else addDomainKey(*domain, "", "", comment, lineNumber); comment.clear(); } } } // Finish up the last domain addDomain(domain, domainLineNumber); // We still have comments, those apparently belong to the bottom of the file if (!comment.empty()) _epilogue = comment; }
bool GameObjectManager::isValidName(const QString& name) const { return isValidName(0, name); }
bool ConfigFile::hasSection(const String §ion) const { assert(isValidName(section)); const Section *s = getSection(section); return s != 0; }
bool GameObjectManager::hasValidName(GameObject* object) const { if (object) return isValidName(object, object->name()); return false; }
QString BaseObject::formatName(const QString &name, bool is_operator) { int i; bool is_formated=false; QString frmt_name; QByteArray raw_name; unsigned char chr, chr1, chr2; QRegExp regexp_vect[]={ QRegExp("(\")(.)+(\")"), QRegExp("(\")(.)+(\")(\\.)(\")(.)+(\")"), QRegExp("(\")(.)+(\")(\\.)(.)+"), QRegExp("(.)+(\\.)(\")(.)+(\")"), QRegExp("(.)+(\\.)(.)+") }; /* Checks through regular expressions if the name passed to be formatted is yet formatted. The forms likely to be formatted are: 1) "OBJECT_NAME" 2) "SCHEMA_NAME"."OBJECT_NAME" 3) "SCHEMA_NAME".OBJECT_NAME 4) SCHEMA_NAME."OBJECT_NAME" 5) SCHEMA_NAME.OBJECT_NAME */ for(i=0; i < 5 && !is_formated; i++) is_formated=regexp_vect[i].exactMatch(name); /* If the name is not formatted or it symbolizes the name of an operator (which has characters invalid according to the rule and is the only exception to which its name is formatted even being invalid) or if the name is valid according with PostgreSQL rules for other types of objects */ if(!is_formated && (is_operator || isValidName(name))) { bool is_upper=false; unsigned i, qtd; raw_name.append(name); /* Checks if the name has some upper case letter. If its the case the name will be enclosed in quotes */ qtd=name.size(); is_upper=(name.indexOf('-')>=0 && !is_operator); i=0; while(i < qtd && !is_upper) { chr=raw_name[i]; if(((i + 1) < (qtd-1)) && ((chr >= 0xC2 && chr <= 0xDF) || (chr >= 0xE0 && chr <= 0xEF))) chr1=raw_name[i+1]; else chr1=0; if((i + 2) < (qtd-1) && chr >= 0xE0 && chr <= 0xEF) chr2=raw_name[i+2]; else chr2=0; if(chr1!=0 && chr2!=0) i+=3; else if(chr1!=0 && chr2==0) i+=2; else i++; //2 bytes UTF-8 character if((chr >= 0xC2 && chr <= 0xDF && chr1 >= 0x80 && chr1 <= 0xBF) || //3 bytes UTF-8 character (chr >= 0xE0 && chr <= 0xEF && chr1 >= 0x80 && chr1 <= 0xBF && chr2 >= 0x80 && chr2 <= 0xBF) || QChar(chr).isUpper()) { is_upper=true; } } if(is_upper) frmt_name="\"" + name + "\""; else frmt_name=name; } else if(is_formated) frmt_name=name; return(frmt_name); }
/*--------------------------------------------------------------------------*/ types::Function::ReturnValue sci_newfun(types::typed_list &in, int _iRetCount, types::typed_list &out) { if (in.size() != 2) { Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "newfun" , 2); return types::Function::Error; } types::InternalType* pIT1 = in[0]; types::InternalType* pIT2 = in[1]; if (pIT1->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "newfun", 1); return types::Function::Error; } types::String* pS1 = pIT1->getAs<types::String>(); if (pS1->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "newfun", 1); return types::Function::Error; } wchar_t* pwcsNewName = pS1->get(0); //check is a valid name if (isValidName(pwcsNewName) == false) { Scierror(999, _("%s: Wrong value for input argument #%d: Valid function name expected.\n"), "newfun", 1); return types::Function::Error; } if (pIT2->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "newfun", 2); return types::Function::Error; } types::String* pS2 = pIT2->getAs<types::String>(); if (pS2->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "newfun", 2); return types::Function::Error; } wchar_t* pwcsName = pS2->get(0); types::Function* pFunc = NULL; symbol::Context* pCtx = symbol::Context::getInstance(); symbol::Variable* pVar = pCtx->getOrCreate(symbol::Symbol(pwcsName)); symbol::Variable::StackVar stack; //get original function //unstack all elements and stack them in new stack ( reverse order ) while (pVar->empty() == false) { stack.push(pVar->top()); pVar->pop(); } if (stack.empty() == false) { symbol::ScopedVariable* pSV = stack.top(); if (pSV->m_iLevel == 0 && pSV->m_pIT->isFunction()) { pFunc = pSV->m_pIT->getAs<types::Function>(); } //move all elements at orginal place and order while (stack.empty() == false) { pSV = stack.top(); stack.pop(); //pSV->m_pIT->DecreaseRef(); pVar->put(pSV); } } if (pFunc == NULL) { Scierror(999, _("%s: function-name is incorrect.\n"), "newfun"); return types::Function::Error; } //new function pVar = pCtx->getOrCreate(symbol::Symbol(pwcsNewName)); if (pVar->empty()) { pVar->put(pFunc, 0); } else { //unstack all elements and stack them in new stack ( reverse order ) while (pVar->empty() == false) { stack.push(pVar->top()); pVar->pop(); } symbol::ScopedVariable* pSV = stack.top(); if (pSV->m_iLevel == 0) { stack.pop(); //clear current var and insert new one types::InternalType* pIT = pSV->m_pIT; pIT->DecreaseRef(); pIT->killMe(); } pVar->put(pFunc, 0); //move all elements at orginal place and order while (stack.empty() == false) { pSV = stack.top(); stack.pop(); //pSV->m_pIT->DecreaseRef(); pVar->put(pSV); } } return types::Function::OK; }
//*************************************************************************** Kwave::RIFFChunk::ChunkType Kwave::RIFFParser::guessType(const QByteArray &name) { if (!isValidName(name)) return Kwave::RIFFChunk::Garbage; return (m_main_chunk_names.contains(QLatin1String(name))) ? Kwave::RIFFChunk::Main : Kwave::RIFFChunk::Sub; }
bool ConfigFile::loadFromStream(SeekableReadStream &stream) { Section section; KeyValue kv; String comment; int lineno = 0; // TODO: Detect if a section occurs multiple times (or likewise, if // a key occurs multiple times inside one section). while (!stream.eos() && !stream.err()) { lineno++; // Read a line String line = stream.readLine(); if (line.size() == 0) { // Do nothing } else if (line[0] == '#' || line[0] == ';' || line.hasPrefix("//")) { // Accumulate comments here. Once we encounter either the start // of a new section, or a key-value-pair, we associate the value // of the 'comment' variable with that entity. The semicolon and // C++-style comments are used for Living Books games in Mohawk. comment += line; comment += "\n"; } else if (line[0] == '(') { // HACK: The following is a hack added by Kirben to support the // "map.ini" used in the HE SCUMM game "SPY Fox in Hold the Mustard". // // It would be nice if this hack could be restricted to that game, // but the current design of this class doesn't allow to do that // in a nice fashion (a "isMustard" parameter is *not* a nice // solution). comment += line; comment += "\n"; } else if (line[0] == '[') { // It's a new section which begins here. const char *p = line.c_str() + 1; // Get the section name, and check whether it's valid (that // is, verify that it only consists of alphanumerics, // periods, dashes and underscores). Mohawk Living Books games // can have periods in their section names. while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; if (*p == '\0') error("ConfigFile::loadFromStream: missing ] in line %d", lineno); else if (*p != ']') error("ConfigFile::loadFromStream: Invalid character '%c' occurred in section name in line %d", *p, lineno); // Previous section is finished now, store it. if (!section.name.empty()) _sections.push_back(section); section.name = String(line.c_str() + 1, p); section.keys.clear(); section.comment = comment; comment.clear(); assert(isValidName(section.name)); } else { // This line should be a line with a 'key=value' pair, or an empty one. // Skip leading whitespaces const char *t = line.c_str(); while (isspace(static_cast<unsigned char>(*t))) t++; // Skip empty lines / lines with only whitespace if (*t == 0) continue; // If no section has been set, this config file is invalid! if (section.name.empty()) { error("ConfigFile::loadFromStream: Key/value pair found outside a section in line %d", lineno); } // Split string at '=' into 'key' and 'value'. First, find the "=" delimeter. const char *p = strchr(t, '='); if (!p) error("Config file buggy: Junk found in line line %d: '%s'", lineno, t); // Extract the key/value pair kv.key = String(t, p); kv.value = String(p + 1); // Trim of spaces kv.key.trim(); kv.value.trim(); // Store comment kv.comment = comment; comment.clear(); assert(isValidName(kv.key)); section.keys.push_back(kv); } } // Save last section if (!section.name.empty()) _sections.push_back(section); return (!stream.err() || stream.eos()); }
bool Chat::talkToChannel(Player* player, MessageClasses type, const std::string& text, uint16_t channelId) { if(text.empty()) return false; ChatChannel* channel = getChannel(player, channelId); if(!channel) return false; if(!player->hasFlag(PlayerFlag_CannotBeMuted)) { if(!channel->hasFlag(CHANNELFLAG_ACTIVE)) { player->sendTextMessage(MSG_STATUS_SMALL, "You may not speak into this channel."); return true; } if(player->getLevel() < channel->getLevel()) { char buffer[100]; sprintf(buffer, "You may not speak into this channel as long as you are on level %d.", channel->getLevel()); player->sendCancel(buffer); return true; } if(channel->getConditionId() >= 0 && player->hasCondition(CONDITION_MUTED, channel->getConditionId())) { player->sendCancel(channel->getConditionMessage().c_str()); return true; } } if(isPublicChannel(channelId)) Manager::getInstance()->talk(player->getID(), channelId, type, text); if(channelId != CHANNEL_GUILD || !g_config.getBool(ConfigManager::INGAME_GUILD_MANAGEMENT) || (text[0] != '!' && text[0] != '/')) { if(channelId == CHANNEL_GUILD) { switch(player->getGuildLevel()) { case GUILDLEVEL_VICE: return channel->talk(player, MSG_CHANNEL_HIGHLIGHT, text); // SPEAK_CHANNEL_O case GUILDLEVEL_LEADER: return channel->talk(player, MSG_GAMEMASTER_CHANNEL, text); // SPEAK_CHANNEL_RN default: break; } } return channel->talk(player, type, text); } if(!player->getGuildId()) { player->sendCancel("You are not in a guild."); return true; } if(!IOGuild::getInstance()->guildExists(player->getGuildId())) { player->sendCancel("It seems like your guild does not exist anymore."); return true; } char buffer[350]; if(text.substr(1) == "disband") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { IOGuild::getInstance()->disbandGuild(player->getGuildId()); channel->talk(player, MSG_CHANNEL, "The guild has been disbanded."); } else player->sendCancel("You are not the leader of your guild."); } else if(text.substr(1, 6) == "invite") { if(player->getGuildLevel() > GUILDLEVEL_MEMBER) { if(text.length() > 7) { std::string param = text.substr(8); trimString(param); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId() == 0) { if(!paramPlayer->isGuildInvited(player->getGuildId())) { sprintf(buffer, "%s has invited you to join the guild, %s. You may join this guild by writing: !joinguild %s", player->getName().c_str(), player->getGuildName().c_str(), player->getGuildName().c_str()); paramPlayer->sendTextMessage(MSG_INFO_DESCR, buffer); sprintf(buffer, "%s has invited %s to the guild.", player->getName().c_str(), paramPlayer->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); paramPlayer->invitationsList.push_back(player->getGuildId()); } else player->sendCancel("A player with that name has already been invited to your guild."); } else player->sendCancel("A player with that name is already in a guild."); } else if(IOLoginData::getInstance()->playerExists(param)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, param); if(!IOGuild::getInstance()->hasGuild(guid)) { if(!IOGuild::getInstance()->isInvited(player->getGuildId(), guid)) { if(IOGuild::getInstance()->guildExists(player->getGuildId())) { IOGuild::getInstance()->invitePlayer(player->getGuildId(), guid); sprintf(buffer, "%s has invited %s to the guild.", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("Your guild does not exist anymore."); } else player->sendCancel("A player with that name has already been invited to your guild."); } else player->sendCancel("A player with that name is already in a guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("Invalid guildcommand parameters."); } else player->sendCancel("You don't have rights to invite players to your guild."); } else if(text.substr(1, 5) == "leave") { if(player->getGuildLevel() < GUILDLEVEL_LEADER) { #ifdef __WAR_SYSTEM__ if(!player->hasEnemy()) { #endif sprintf(buffer, "%s has left the guild.", player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); player->leaveGuild(); #ifdef __WAR_SYSTEM__ } else player->sendCancel("Your guild is currently at war, you cannot leave it right now."); #endif } else player->sendCancel("You cannot leave your guild because you are the leader of it, you have to pass the leadership to another member of your guild or disband the guild."); } else if(text.substr(1, 6) == "revoke") { if(player->getGuildLevel() > GUILDLEVEL_MEMBER) { if(text.length() > 7) { std::string param = text.substr(8); trimString(param); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId() == 0) { InvitationsList::iterator it = std::find(paramPlayer->invitationsList.begin(), paramPlayer->invitationsList.end(), player->getGuildId()); if(it != paramPlayer->invitationsList.end()) { sprintf(buffer, "%s has revoked your invite to %s guild.", player->getName().c_str(), (player->getSex(false) ? "his" : "her")); paramPlayer->sendTextMessage(MSG_INFO_DESCR, buffer); sprintf(buffer, "%s has revoked the guildinvite of %s.", player->getName().c_str(), paramPlayer->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); paramPlayer->invitationsList.erase(it); return true; } else player->sendCancel("A player with that name is not invited to your guild."); } else player->sendCancel("A player with that name is already in a guild."); } else if(IOLoginData::getInstance()->playerExists(param)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, param); if(IOGuild::getInstance()->isInvited(player->getGuildId(), guid)) { if(IOGuild::getInstance()->guildExists(player->getGuildId())) { sprintf(buffer, "%s has revoked the guildinvite of %s.", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); IOGuild::getInstance()->revokeInvite(player->getGuildId(), guid); } else player->sendCancel("It seems like your guild does not exist anymore."); } else player->sendCancel("A player with that name is not invited to your guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("Invalid guildcommand parameters."); } else player->sendCancel("You don't have rights to revoke an invite of someone in your guild."); } else if(text.substr(1, 7) == "promote" || text.substr(1, 6) == "demote" || text.substr(1, 14) == "passleadership" || text.substr(1, 4) == "kick") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { std::string param; uint32_t length = 0; if(text[2] == 'r') length = 9; else if(text[2] == 'e') length = 7; else if(text[2] == 'a') length = 16; else length = 6; if(text.length() < length) { player->sendCancel("Invalid guildcommand parameters."); return true; } param = text.substr(length); trimString(param); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId()) { if(IOGuild::getInstance()->guildExists(paramPlayer->getGuildId())) { if(player->getGuildId() == paramPlayer->getGuildId()) { if(text[2] == 'r') { if(paramPlayer->getGuildLevel() == GUILDLEVEL_MEMBER) { if(paramPlayer->isPremium()) { paramPlayer->setGuildLevel(GUILDLEVEL_VICE); sprintf(buffer, "%s has promoted %s to %s.", player->getName().c_str(), paramPlayer->getName().c_str(), paramPlayer->getRankName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("A player with that name does not have a premium account."); } else player->sendCancel("You can only promote Members to Vice-Leaders."); } else if(text[2] == 'e') { if(paramPlayer->getGuildLevel() == GUILDLEVEL_VICE) { paramPlayer->setGuildLevel(GUILDLEVEL_MEMBER); sprintf(buffer, "%s has demoted %s to %s.", player->getName().c_str(), paramPlayer->getName().c_str(), paramPlayer->getRankName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You can only demote Vice-Leaders to Members."); } else if(text[2] == 'a') { if(paramPlayer->getGuildLevel() == GUILDLEVEL_VICE) { const uint32_t levelToFormGuild = g_config.getNumber(ConfigManager::LEVEL_TO_FORM_GUILD); if(paramPlayer->getLevel() >= levelToFormGuild) { paramPlayer->setGuildLevel(GUILDLEVEL_LEADER); player->setGuildLevel(GUILDLEVEL_VICE); IOGuild::getInstance()->updateOwnerId(paramPlayer->getGuildId(), paramPlayer->getGUID()); sprintf(buffer, "%s has passed the guild leadership to %s.", player->getName().c_str(), paramPlayer->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else { sprintf(buffer, "The new guild leader has to be at least Level %d.", levelToFormGuild); player->sendCancel(buffer); } } else player->sendCancel("A player with that name is not a Vice-Leader."); } else { if(player->getGuildLevel() > paramPlayer->getGuildLevel()) { #ifdef __WAR_SYSTEM__ if(!player->hasEnemy()) { #endif sprintf(buffer, "%s has been kicked from the guild by %s.", paramPlayer->getName().c_str(), player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); paramPlayer->leaveGuild(); #ifdef __WAR_SYSTEM__ } else player->sendCancel("Your guild is currently at war, you cannot kick right now."); #endif } else player->sendCancel("You may only kick players with a guild rank below your."); } } else player->sendCancel("You are not in the same guild as a player with that name."); } else player->sendCancel("Could not find the guild of a player with that name."); } else player->sendCancel("A player with that name is not in a guild."); } else if(IOLoginData::getInstance()->playerExists(param)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, param); if(IOGuild::getInstance()->hasGuild(guid)) { if(player->getGuildId() == IOGuild::getInstance()->getGuildId(guid)) { if(text[2] == 'r') { if(IOGuild::getInstance()->getGuildLevel(guid) == GUILDLEVEL_MEMBER) { if(IOLoginData::getInstance()->isPremium(guid)) { IOGuild::getInstance()->setGuildLevel(guid, GUILDLEVEL_VICE); sprintf(buffer, "%s has promoted %s to %s.", player->getName().c_str(), param.c_str(), IOGuild::getInstance()->getRank(guid).c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("A player with that name does not have a premium account."); } else player->sendCancel("You can only promote Members to Vice-Leaders."); } else if(text[2] == 'e') { if(IOGuild::getInstance()->getGuildLevel(guid) == GUILDLEVEL_VICE) { IOGuild::getInstance()->setGuildLevel(guid, GUILDLEVEL_MEMBER); sprintf(buffer, "%s has demoted %s to %s.", player->getName().c_str(), param.c_str(), IOGuild::getInstance()->getRank(guid).c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You can only demote Vice-Leaders to Members."); } else if(text[2] == 'a') { if(IOGuild::getInstance()->getGuildLevel(guid) == GUILDLEVEL_VICE) { const uint32_t levelToFormGuild = g_config.getNumber(ConfigManager::LEVEL_TO_FORM_GUILD); if(IOLoginData::getInstance()->getLevel(guid) >= levelToFormGuild) { IOGuild::getInstance()->setGuildLevel(guid, GUILDLEVEL_LEADER); player->setGuildLevel(GUILDLEVEL_VICE); sprintf(buffer, "%s has passed the guild leadership to %s.", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else { sprintf(buffer, "The new guild leader has to be at least Level %d.", levelToFormGuild); player->sendCancel(buffer); } } else player->sendCancel("A player with that name is not a Vice-Leader."); } else { sprintf(buffer, "%s has been kicked from the guild by %s.", param.c_str(), player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); IOLoginData::getInstance()->resetGuildInformation(guid); } } } else player->sendCancel("A player with that name is not in a guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("You are not the leader of your guild."); } else if(text.substr(1, 4) == "nick" && text.length() > 5) { StringVec params = explodeString(text.substr(6), ","); if(params.size() >= 2) { std::string param1 = params[0], param2 = params[1]; trimString(param1); trimString(param2); Player* paramPlayer = NULL; if(g_game.getPlayerByNameWildcard(param1, paramPlayer) == RET_NOERROR) { if(paramPlayer->getGuildId()) { if(param2.length() > 2) { if(param2.length() < 21) { if(isValidName(param2, false)) { if(IOGuild::getInstance()->guildExists(paramPlayer->getGuildId())) { if(player->getGuildId() == paramPlayer->getGuildId()) { if(paramPlayer->getGuildLevel() < player->getGuildLevel() || (player == paramPlayer && player->getGuildLevel() > GUILDLEVEL_MEMBER)) { paramPlayer->setGuildNick(param2); if(player != paramPlayer) sprintf(buffer, "%s has set the guildnick of %s to \"%s\".", player->getName().c_str(), paramPlayer->getName().c_str(), param2.c_str()); else sprintf(buffer, "%s has set %s guildnick to \"%s\".", player->getName().c_str(), (player->getSex(false) ? "his" : "her"), param2.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You may only change the guild nick of players that have a lower rank than you."); } else player->sendCancel("A player with that name is not in your guild."); } else player->sendCancel("A player with that name's guild could not be found."); } else player->sendCancel("That guildnick is not valid."); } else player->sendCancel("That guildnick is too long, please select a shorter one."); } else player->sendCancel("That guildnick is too short, please select a longer one."); } else player->sendCancel("A player with that name is not in a guild."); } else if(IOLoginData::getInstance()->playerExists(param1)) { uint32_t guid; IOLoginData::getInstance()->getGuidByName(guid, (std::string&)param1); if(IOGuild::getInstance()->hasGuild(guid)) { if(param2.length() > 2) { if(param2.length() < 21) { if(isValidName(param2, false)) { if(IOGuild::getInstance()->guildExists(guid)) { if(player->getGuildId() == IOGuild::getInstance()->getGuildId(guid)) { if(IOGuild::getInstance()->getGuildLevel(guid) < player->getGuildLevel()) { IOGuild::getInstance()->setGuildNick(guid, param2); sprintf(buffer, "%s has set the guildnick of %s to \"%s\".", player->getName().c_str(), param1.c_str(), param2.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("You may only change the guild nick of players that have a lower rank than you."); } else player->sendCancel("A player with that name is not in your guild."); } else player->sendCancel("A player with that name's guild could not be found."); } else player->sendCancel("That guildnick is not valid."); } else player->sendCancel("That guildnick is too long, please select a shorter one."); } else player->sendCancel("That guildnick is too short, please select a longer one."); } else player->sendCancel("A player with that name is not in any guild."); } else player->sendCancel("A player with that name does not exist."); } else player->sendCancel("Invalid guildcommand parameters."); } else if(text.substr(1, 11) == "setrankname" && text.length() > 12) { StringVec params = explodeString(text.substr(13), ","); if(params.size() >= 2) { std::string param1 = params[0], param2 = params[1]; trimString(param1); trimString(param2); if(player->getGuildLevel() == GUILDLEVEL_LEADER) { if(param2.length() > 2) { if(param2.length() < 21) { if(isValidName(param2, false)) { if(IOGuild::getInstance()->getRankIdByName(player->getGuildId(), param1)) { if(!IOGuild::getInstance()->getRankIdByName(player->getGuildId(), param2)) { IOGuild::getInstance()->changeRank(player->getGuildId(), param1, param2); sprintf(buffer, "%s has renamed the guildrank: \"%s\", to: \"%s\".", player->getName().c_str(), param1.c_str(), param2.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("There is already a rank in your guild with that name."); } else player->sendCancel("There is no such rankname in your guild."); } else player->sendCancel("The new guildrank contains invalid characters."); } else player->sendCancel("The new rankname is too long."); } else player->sendCancel("The new rankname is too short."); } else player->sendCancel("You are not the leader of your guild."); } else player->sendCancel("Invalid guildcommand parameters"); } else if(text.substr(1, 7) == "setmotd") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { if(text.length() > 8) { std::string param = text.substr(9); trimString(param); if(param.length() > 2) { if(param.length() < 225) { IOGuild::getInstance()->setMotd(player->getGuildId(), param); sprintf(buffer, "%s has set the Message of the Day to: %s", player->getName().c_str(), param.c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("That motd is too long."); } else player->sendCancel("That motd is too short."); } else player->sendCancel("Invalid guildcommand parameters."); } else player->sendCancel("Only the leader of your guild can set the guild motd."); } else if(text.substr(1, 9) == "cleanmotd") { if(player->getGuildLevel() == GUILDLEVEL_LEADER) { IOGuild::getInstance()->setMotd(player->getGuildId(), ""); sprintf(buffer, "%s has cleaned the Message of the Day.", player->getName().c_str()); channel->talk(player, MSG_CHANNEL, buffer); } else player->sendCancel("Only the leader of your guild can clean the guild motd."); } else if(text.substr(1, 8) == "commands") player->sendToChannel(player, MSG_CHANNEL, "Guild commands with parameters: disband, invite[name], leave, kick[name], revoke[name], demote[name], promote[name], passleadership[name], nick[name, nick], setrankname[oldName, newName], setmotd[text] and cleanmotd.", CHANNEL_GUILD); else return false; return true; }