• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Classic spell casting, crash server

ForgottenNot

Member
Joined
Feb 10, 2023
Messages
192
Reaction score
19
ExUrA will work(and all others)
Ex Ura will work(and all others)
Utevo lux "blabla works

the problem is that certain spells were quotes are not being used, are crashing the server. ex: exani hur up or utevo res orc
if we use quotes everything is okey. is there a way to add param monster name
in xml do we have this
Lua:
params="1"
is there a way to add a parameter so if params="1" in spells.xml it will add quotes automatically
if (instantSpell->getHasParam() && !param.empty()) {
words += " \"" + param + "\"";
}

or add monstername parameter + up word something like that
spells.cpp
Code:
TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
{
    std::string str_words = words;

    //strip trailing spaces
    trimString(str_words);

    InstantSpell* instantSpell = getInstantSpell(str_words);
    if (!instantSpell) {
        return TALKACTION_CONTINUE;
    }

    std::string param;

    if (instantSpell->getHasParam()) {
        size_t spellLen = instantSpell->getWords().length();
        size_t paramLen = str_words.length() - spellLen;
        std::string paramText = str_words.substr(spellLen, paramLen);
        if (!paramText.empty() && paramText.front() == ' ') {
            size_t loc1 = paramText.find('"', 1);
            if (loc1 != std::string::npos) {
                size_t loc2 = paramText.find('"', loc1 + 1);
                if (loc2 == std::string::npos) {
                    loc2 = paramText.length();
                } else if (paramText.find_last_not_of(' ') != loc2) {
                    return TALKACTION_CONTINUE;
                }

                param = paramText.substr(loc1 + 1, loc2 - loc1 - 1);
            } else {
                trimString(paramText);
                loc1 = paramText.find(' ', 0);
                if (loc1 == std::string::npos) {
                    param = paramText;
                } else {
                    return TALKACTION_CONTINUE;
                }
            }
        }
    }

    if (instantSpell->playerCastInstant(player, param)) {
        words = instantSpell->getWords();
        //words = words /*instantSpell->getWords()*/;
        if (instantSpell->getHasParam() && !param.empty()) {
            words += " \"" + param + "\"";
    }
        //words = instantSpell->getWords();
        //words = words /*instantSpell->getWords()*/;
    //    if (instantSpell->getHasParam() && !param.empty()) {
        //    words += " \"" + param + "\"";
        //}
        return TALKACTION_BREAK;
    }

    return TALKACTION_FAILED;
}
Code:
InstantSpell* Spells::getInstantSpell(const std::string& words)
{
    InstantSpell* result = nullptr;

    for (auto& it : instants) {
        const std::string& instantSpellWords = it.second.getWords();
        size_t spellLen = instantSpellWords.length();
        if (caseInsensitiveStartsWith(words, instantSpellWords)) {
            if (!result || spellLen > result->getWords().size()) {
                result = &it.second;
                if (words.length() == spellLen) {
                    break;
                }
            }
        }
    }

    /*if (result) {
        const std::string& resultWords = result->getWords();
        if (words.length() > resultWords.length()) {
            if (!result->getHasParam()) {
                return nullptr;
            }*/
    if (result && words.length() > result->getWords().length())
    {
        std::string param = words.substr(result->getWords().length(), words.length());
        if (param[0] != ' ' || (param.length() > 1 && (!result->getHasParam() || param.find(' ', 1) != std::string::npos) && param[1] != '"'))
            return nullptr;
    }


            //size_t spellLen = resultWords.length();
           //size_t spellLen = words.length();
            //size_t paramLen = words.length() - spellLen;
            //if (paramLen < 2 || words[spellLen] != ' ') {
                //return nullptr;
            //}
        //}
        return result;
    //}
    return nullptr;
}
 
ExUrA will work(and all others)
Ex Ura will work(and all others)
Utevo lux "blabla works

the problem is that certain spells were quotes are not being used, are crashing the server. ex: exani hur up or utevo res orc
if we use quotes everything is okey. is there a way to add param monster name
in xml do we have this
Lua:
params="1"
is there a way to add a parameter so if params="1" in spells.xml it will add quotes automatically
if (instantSpell->getHasParam() && !param.empty()) {
words += " \"" + param + "\"";
}

or add monstername parameter + up word something like that
spells.cpp
Code:
TalkActionResult_t Spells::playerSaySpell(Player* player, std::string& words)
{
    std::string str_words = words;

    //strip trailing spaces
    trimString(str_words);

    InstantSpell* instantSpell = getInstantSpell(str_words);
    if (!instantSpell) {
        return TALKACTION_CONTINUE;
    }

    std::string param;

    if (instantSpell->getHasParam()) {
        size_t spellLen = instantSpell->getWords().length();
        size_t paramLen = str_words.length() - spellLen;
        std::string paramText = str_words.substr(spellLen, paramLen);
        if (!paramText.empty() && paramText.front() == ' ') {
            size_t loc1 = paramText.find('"', 1);
            if (loc1 != std::string::npos) {
                size_t loc2 = paramText.find('"', loc1 + 1);
                if (loc2 == std::string::npos) {
                    loc2 = paramText.length();
                } else if (paramText.find_last_not_of(' ') != loc2) {
                    return TALKACTION_CONTINUE;
                }

                param = paramText.substr(loc1 + 1, loc2 - loc1 - 1);
            } else {
                trimString(paramText);
                loc1 = paramText.find(' ', 0);
                if (loc1 == std::string::npos) {
                    param = paramText;
                } else {
                    return TALKACTION_CONTINUE;
                }
            }
        }
    }

    if (instantSpell->playerCastInstant(player, param)) {
        words = instantSpell->getWords();
        //words = words /*instantSpell->getWords()*/;
        if (instantSpell->getHasParam() && !param.empty()) {
            words += " \"" + param + "\"";
    }
        //words = instantSpell->getWords();
        //words = words /*instantSpell->getWords()*/;
    //    if (instantSpell->getHasParam() && !param.empty()) {
        //    words += " \"" + param + "\"";
        //}
        return TALKACTION_BREAK;
    }

    return TALKACTION_FAILED;
}
Code:
InstantSpell* Spells::getInstantSpell(const std::string& words)
{
    InstantSpell* result = nullptr;

    for (auto& it : instants) {
        const std::string& instantSpellWords = it.second.getWords();
        size_t spellLen = instantSpellWords.length();
        if (caseInsensitiveStartsWith(words, instantSpellWords)) {
            if (!result || spellLen > result->getWords().size()) {
                result = &it.second;
                if (words.length() == spellLen) {
                    break;
                }
            }
        }
    }

    /*if (result) {
        const std::string& resultWords = result->getWords();
        if (words.length() > resultWords.length()) {
            if (!result->getHasParam()) {
                return nullptr;
            }*/
    if (result && words.length() > result->getWords().length())
    {
        std::string param = words.substr(result->getWords().length(), words.length());
        if (param[0] != ' ' || (param.length() > 1 && (!result->getHasParam() || param.find(' ', 1) != std::string::npos) && param[1] != '"'))
            return nullptr;
    }


            //size_t spellLen = resultWords.length();
           //size_t spellLen = words.length();
            //size_t paramLen = words.length() - spellLen;
            //if (paramLen < 2 || words[spellLen] != ' ') {
                //return nullptr;
            //}
        //}
        return result;
    //}
    return nullptr;
}
if you have a problem, there's no point in adding other things, it would take us ages to make it work without having the specific knowledge, while those who know a lot about it would take minutes maybe, that's why I paused on this problem and went to see other things to not stay all day on it

I can't even say that what I added was the right way to do it.
 
Back
Top