• 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++ Error in MSVC

flaviiojr

Active Member
Joined
Jan 20, 2017
Messages
230
Solutions
13
Reaction score
39
I'm having the following errors in the log
TFS 1.3
Code:
Severity    Code    Description    Project    File    Line    Suppression State
Error    C2065    'Module_ptr': undeclared identifier    theforgottenserver
Error    C2146    syntax error: missing ';' before identifier 'module'
Error    C2065    'module': undeclared identifier    theforgottenserver
Error    C2065    'module': undeclared identifier    theforgottenserver
Error    C2227    left of '->getEventType' must point to class/struct/union/generic
Error    C2065    'module': undeclared identifier    theforgottenserver
Error    C2227    left of '->getRecvbyte' must point to class/struct/union/generic
Error    C2065    'module': undeclared identifier    theforgottenserver
Error    C2227    left of '->getEventType' must point to class/struct/union/generic
Error    C2065    'module': undeclared identifier    theforgottenserver
Error (active)    E0040    expected an identifier    theforgottenserver
Error (active)    E0757    variable "module" is not a type name
Error (active)    E0018    expected a ')'    theforgottenserver
Error    C2065    'module': undeclared identifier    theforgottenserver
Error    C2227    left of '->getRecvbyte' must point to class/struct/union/generic type  
Error (active)    E0413    no suitable conversion function from "const Module" to "Module *" exists
Error (active)    E1086    the object has type qualifiers that are not compatible with the member function "Module::getRecvbyte"

Modules.cpp
C++:
#include "otpch.h"

#include "modules.h"
#include "player.h"

Modules::Modules() :
    scriptInterface("Modules Interface")
{
    scriptInterface.initState();
}

void Modules::clear()
{
    //clear recvbyte list
    for (auto& it : recvbyteList) {
        it.second.clearEvent();
    }

    //clear lua state
    scriptInterface.reInitState();
}

LuaScriptInterface& Modules::getScriptInterface()
{
    return scriptInterface;
}

std::string Modules::getScriptBaseName() const
{
    return "modules";
}

Event_ptr Modules::getEvent(const std::string& nodeName)
{
    if (strcasecmp(nodeName.c_str(), "module") != 0) {
        return nullptr;
    }
    return Event_ptr(new Module(&scriptInterface));
}

bool Modules::registerEvent(Event_ptr event, const pugi::xml_node&)
{
    Module_ptr module{static_cast<Module*>(event.release())};
    if (module->getEventType() == MODULE_TYPE_NONE) {
        std::cout << "Error: [Modules::registerEvent] Trying to register event without type!" << std::endl;
        return false;
    }

    Module* oldModule = getEventByRecvbyte(module->getRecvbyte(), false);
    if (oldModule) {
        if (!oldModule->isLoaded() && oldModule->getEventType() == module->getEventType()) {
            oldModule->copyEvent(module.get());
        }
        return false;
    }
    else {
        auto it = recvbyteList.find(module->getRecvbyte());
        if (it != recvbyteList.end()) {
            it->second = *module;
        }
        else {
            Modules.emplace(module->getRecvbyte(), std::move(*module));
        }
        return true;
    }
}

Module* Modules::getEventByRecvbyte(uint8_t recvbyte, bool force)
{
    auto it = recvbyteList.find(recvbyte);
    if (it != recvbyteList.end()) {
        if (!force || it->second.isLoaded()) {
            return &it->second;
        }
    }
    return nullptr;
}

void Modules::executeOnRecvbyte(Player* player, NetworkMessage& msg, uint8_t byte) const
{
    for (const auto& it : recvbyteList) {
        Module* module = it.second;
        if (it.second.getEventType() == MODULE_TYPE_RECVBYTE && it.second.getRecvbyte() == byte && player->canRunModule(module->getRecvbyte())) {
            player->setModuleDelay(module->getRecvbyte(), module->getDelay());
            module->executeOnRecvbyte(player, msg);
            return;
        }
    }
}
/////////////////////////////////////

Module::Module(LuaScriptInterface* interface) :
    Event(interface), type(MODULE_TYPE_NONE), loaded(false) {}

bool Module::configureEvent(const pugi::xml_node& node)
{
    delay = 0;

    pugi::xml_attribute typeAttribute = node.attribute("type");
    if (!typeAttribute) {
        std::cout << "[Error - Modules::configureEvent] Missing type for module." << std::endl;
        return false;
    }

    std::string tmpStr = asLowerCaseString(typeAttribute.as_string());
    if (tmpStr == "recvbyte") {
        pugi::xml_attribute byteAttribute = node.attribute("byte");
        if (!byteAttribute) {
            std::cout << "[Error - Modules::configureEvent] Missing byte for module typed recvbyte." << std::endl;
            return false;
        }

        recvbyte = static_cast<uint8_t>(byteAttribute.as_int());
        type = MODULE_TYPE_RECVBYTE;
    }
    else {
        std::cout << "[Error - Modules::configureEvent] Invalid type for module." << std::endl;
        return false;
    }

    pugi::xml_attribute delayAttribute = node.attribute("delay");
    if (delayAttribute) {
        delay = static_cast<uint16_t>(delayAttribute.as_uint());
    }

    loaded = true;
    return true;
}

std::string Module::getScriptEventName() const
{
    switch (type) {
    case MODULE_TYPE_RECVBYTE:
        return "onRecvbyte";
    default:
        return std::string();
    }
}

void Module::copyEvent(Module* module)
{
    scriptId = module->scriptId;
    scriptInterface = module->scriptInterface;
    scripted = module->scripted;
    loaded = module->loaded;
}

void Module::clearEvent()
{
    scriptId = 0;
    scriptInterface = nullptr;
    scripted = false;
    loaded = false;
}

void Module::executeOnRecvbyte(Player* player, NetworkMessage& msg)
{
    //onAdvance(player, skill, oldLevel, newLevel)
    if (!scriptInterface->reserveScriptEnv()) {
        std::cout << "[Error - CreatureEvent::executeAdvance] Call stack overflow" << std::endl;
        return;
    }

    ScriptEnvironment* env = scriptInterface->getScriptEnv();
    env->setScriptId(scriptId, scriptInterface);

    lua_State* L = scriptInterface->getLuaState();

    scriptInterface->pushFunction(scriptId);
    LuaScriptInterface::pushUserdata<Player>(L, player);
    LuaScriptInterface::setMetatable(L, -1, "Player");

    LuaScriptInterface::pushUserdata<NetworkMessage>(L, const_cast<NetworkMessage*>(&msg));
    LuaScriptInterface::setWeakMetatable(L, -1, "NetworkMessage");

    lua_pushnumber(L, recvbyte);

    scriptInterface->callVoidFunction(3);
}

Modules.h
C++:
/**
* This file doesn't belong to theforgottenserver developers.
*/

#ifndef FS_MODULE_H_73FCAF4608CB41399D53C919316646A9
#define FS_MODULE_H_73FCAF4608CB41399D53C919316646A9

#include "luascript.h"
#include "baseevents.h"
#include "networkmessage.h"

class Module;
using Module_ptr = std::unique_ptr<Module>;

enum ModuleType_t {
    MODULE_TYPE_RECVBYTE,
    MODULE_TYPE_NONE,
};

class Module final : public Event
{
public:
    explicit Module(LuaScriptInterface* interface);

    bool configureEvent(const pugi::xml_node& node) final;

    ModuleType_t getEventType() const {
        return type;
    }
    bool isLoaded() const {
        return loaded;
    }

    void clearEvent();
    void copyEvent(Module* creatureEvent);

    //scripting
    void executeOnRecvbyte(Player* player, NetworkMessage& msg);
    //

    uint8_t getRecvbyte() {
        return recvbyte;
    }

    int16_t getDelay() {
        return delay;
    }
protected:
    std::string getScriptEventName() const final;

    ModuleType_t type;
    uint8_t recvbyte;
    int16_t delay;
    bool loaded;
};

class Modules final : public BaseEvents
{
public:
    Modules();
    ~Modules();

    // non-copyable
    Modules(const Modules&) = delete;
    Modules& operator=(const Modules&) = delete;

    void executeOnRecvbyte(Player* player, NetworkMessage& msg, uint8_t byte) const;

protected:
    LuaScriptInterface & getScriptInterface() final;
    std::string getScriptBaseName() const final;
    Event_ptr getEvent(const std::string& nodeName) final;
    bool registerEvent(Event_ptr event, const pugi::xml_node& node) final;
    Module* getEventByRecvbyte(uint8_t recvbyte, bool force);
    void clear() final;


    typedef std::map<uint8_t, Module> ModulesList;
    ModulesList recvbyteList;

    LuaScriptInterface scriptInterface;
};

#endif

after installing a commit made by @Mkalo, in a source custom, these errors appeared...
Change all event containers to store objects

Show me a way to fix these errors, because I tried it anyway, I followed the MSVC log, but I was not successful ...
I thank everyone
 
Last edited:
Back
Top