plugin conflicts

Started by MEGAMIND, Oct 24, 2024, 09:02 PM

Previous topic - Next topic

MEGAMIND

Well ive been adding plugins i want and checked that few of the plugins dont like to work with eachother lets says habi's logfile maker it doesnt logs out everything, what could be the issue also theres that if i remove few plugins then the logfile maker works...!

well my plugins list

plugins squirrel04rel64 sqlatestfeatures04rel64 announce04rel64 xmlconf04rel64 ini04rel64 sqlite04rel64 sockets04rel64 hashing04rel64 mysql04rel64 rcon04rel64 vcmp-squirrel-mmdb-rel64 logfile64 appchat04rel64 webnet64

habi2

Is this happening on linux?
It has been found that vcmp server do not call a callback-function inside the plugin, if another plugin already has a function of exact name.
Since i noticed the issue, i began renaming cpp-functions inside my plugin to
RCN_OnPlayerConnect, (In Rcon plugin), DiscordSync_OnPlayerConnect in discordsync plugin etc.

If it is on windows, then we have to take a look

MEGAMIND

#2
Quote from: habi2 on Oct 25, 2024, 07:45 AMIs this happening on linux?
It has been found that vcmp server do not call a callback-function inside the plugin, if another plugin already has a function of exact name.
Since i noticed the issue, i began renaming cpp-functions inside my plugin to
RCN_OnPlayerConnect, (In Rcon plugin), DiscordSync_OnPlayerConnect in discordsync plugin etc.

If it is on windows, then we have to take a look
yeup its windows... and i reallyneed a fix for it

logfilemaker


habi2

Sorry, i have no idea.

MEGAMIND

ok so what i tried so far was that @habi2 ur plugin logfilemaker only works if plugins squirrel04rel64 logfile64 if thheres is anyother plugin with it it wont work..!

also i tested this on a blank server with default plugins but still it wont work, it will work only if as mentioned before..!

habi2

ok @MEGAMIND, i will debug its code tomorrow or so.

MEGAMIND

#6
Quote from: habi2 on Oct 25, 2024, 07:15 PMok @MEGAMIND, i will debug its code tomorrow or so.
@habi that wouldnt be neccessary anymore, after lots of debugging,lots of changing places of plugins in server.cfg, changing lots of server.exe versions, compiling the logfile with new sdk, re-coding again and again method of new logging... at a point of new code i figured it out that on win 11 version 24H2 the mechanism of running programs by windows is something different.. they are either running by cmd.exe or powershell but not the vcmp server.exe bcz when clicked the program indication doesnt show it running from same program but at running at different location, so after running my new code as admin i was able to log as many as possible data but running without admin i was able to log only 5 to 8 lines and writing text from vcmp wasnt being exported out sooo, i redownloaded the logfilemaker used the new sdk and then run the server.exe of windows using ur old code from logfilemaker it turned out perfect..!

conclusion your code is still perfect its some windows shit that microsoft is doing...!

Thanks..!

though the code ive been trying
#include "SQMain.h"
#include "SQConsts.h"
#include "SQFuncs.h"
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stdarg.h>
#include <string>
#include <fstream>
#include <thread>
#include <vector>
#include <windows.h>

using namespace std;

PluginFuncs* VCMP;
HSQUIRRELVM v;
HSQAPI sq;

// Function prototypes
void logConsoleOutput();

void OnSquirrelScriptLoad() {
    // See if we have any imports from Squirrel
    size_t size;
    int32_t sqId = VCMP->FindPlugin(const_cast<char*>("SQHost2"));
    const void** sqExports = VCMP->GetPluginExports(sqId, &size);

    if (sqExports != NULL && size > 0) {
        SquirrelImports** sqDerefFuncs = (SquirrelImports**)sqExports;
        SquirrelImports* sqFuncs = (SquirrelImports*)(*sqDerefFuncs);

        if (sqFuncs) {
            v = *(sqFuncs->GetSquirrelVM());
            sq = *(sqFuncs->GetSquirrelAPI());

            RegisterFuncslog(v);
            RegisterConsts(v);
        }
    }
    else {
        OutputError("Failed to attach to SQHost2.");
    }
}

// Improved logging function
void logConsoleOutput() {
    HANDLE hCons = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hCons == INVALID_HANDLE_VALUE) {
        OutputError("Failed to get console handle.");
        return;
    }

    CONSOLE_SCREEN_BUFFER_INFO info;
    vector<CHAR_INFO> buffer;

    // Get the current directory to construct the log file path
    char logFilePath[MAX_PATH];
    GetCurrentDirectoryA(MAX_PATH, logFilePath);
    strcat(logFilePath, "\\log_file.txt"); // Append the log file name

    string lastLoggedOutput; // To keep track of the last logged output

    while (true) {
        if (!GetConsoleScreenBufferInfo(hCons, &info)) {
            OutputError("Failed to get console screen buffer info.");
            return;
        }

        size_t length = info.dwSize.X; // Width of the console
        size_t totalLines = info.dwSize.Y; // Height of the console

        // Prepare buffer to read the entire console output
        buffer.resize(length * totalLines);
        SMALL_RECT rect = { 0, 0, static_cast<SHORT>(length - 1), static_cast<SHORT>(totalLines - 1) };

        if (ReadConsoleOutput(hCons, buffer.data(), info.dwSize, { 0, 0 }, &rect)) {
            string currentOutput; // Current console output
            // Build the current console output string
            for (size_t i = 0; i < buffer.size(); ++i) {
                currentOutput += buffer[i].Char.AsciiChar;
                // Check if we've reached the end of the current line
                if ((i + 1) % length == 0) {
                    currentOutput += "\n"; // New line for console output
                }
            }

            // Check for new content
            if (currentOutput.length() > lastLoggedOutput.length()) {
                // Get new content since last log
                string newContent = currentOutput.substr(lastLoggedOutput.length());

                // Log new content
                ofstream myfile(logFilePath, ios::out | ios::app);
                if (myfile.is_open() && !newContent.empty()) {
                    myfile << newContent; // Write new content
                    myfile.close();
                    printf("New content written to log file: %s\n", logFilePath); // Console message
                }
                else {
                    // Enhanced error reporting
                    DWORD errorCode = GetLastError();
                    char errorMessage[256];
                    snprintf(errorMessage, sizeof(errorMessage), "Failed to open log file: %s. Error code: %lu", logFilePath, errorCode);
                    OutputError(errorMessage);
                }

                // Update the last logged output after successful write
                lastLoggedOutput = currentOutput; // Update the last logged output
            }
        }
        else {
            OutputError("Failed to read console output.");
            printf("Error code: %d\n", GetLastError());
        }

        Sleep(1000); // Check for new output every second
    }
}

uint8_t OnPluginCommand(uint32_t type, const char* text) {
    switch (type) {
    case 0x7D6E22D8:
        OnSquirrelScriptLoad();
        break;
    default:
        break;
    }
    return 1;
}

uint8_t onServerInitialise() {
    OutputMessage("Loaded Logfilemaker module by MEGAMIND");
    thread(logConsoleOutput).detach(); // Start logging in a new thread
    return 1;
}

extern "C" unsigned int VcmpPluginInit(PluginFuncs* pluginFuncs, PluginCallbacks* pluginCalls, PluginInfo* pluginInfo) {
    VCMP = pluginFuncs;

    // Plugin information
    pluginInfo->pluginVersion = 0x110;
    pluginInfo->apiMajorVersion = PLUGIN_API_MAJOR;
    pluginInfo->apiMinorVersion = PLUGIN_API_MINOR;
    strcpy(pluginInfo->name, "logfile");
    pluginCalls->OnPluginCommand = OnPluginCommand;
    pluginCalls->OnServerInitialise = onServerInitialise;
    return 1;
}
if anyone knows a fix where im wrong kinly guide thanks

also during this period i learned making functions, and some console color not by habis console color plugin but using windows itself foreground and background colors..!