Pycckue-Bnepeg / samp-rs

SA:MP SDK written in Rust
46 stars 11 forks source link

Plugin problems #21

Closed UserNoName000 closed 3 years ago

UserNoName000 commented 3 years ago

Hi Eva. I apologize for writing here, but there are no other ways of communication. In general, I am writing about two problems that I encountered when working with the samp-cef plugin. I'm working on changing the interfaces right now, and I ran into the only problem, it's radar. I don't understand how to make it functional with your plugin. The second problem is more serious. Working with events, I ran into the problem that if you send them often, the client plugin just shipped and stops responding. I made a speedometer and made a timer, at first it was once every 5 seconds, but it crashed the plugin. Then I did it once every 10 seconds, it also crashes. Tell me how to solve this problem? I just know what game server players are who can deliberately flood something and cause a crash. I beg you, do not ignore, do not block, but give an answer, this is my last chance to ask you a question. I tried to contact via mail, but it was useless ..

Pycckue-Bnepeg commented 3 years ago

Are you sure that you using this right? I cannot reproduce this crash or anything else.

My HTML file (all the code below is similar to example's one):

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        .box {
            position: absolute;
            top: 500px;
        }
    </style>
</head>

<body>
    <div class="box">
        <span>hp:</span><span id="hp">0</span>
        <span>max_hp:</span><span id="max_hp">0</span>
        <span>arm:</span><span id="arm">0</span>
        <span>breath:</span><span id="breath">0</span>
        <span>wanted:</span><span id="wanted">0</span>
        <span>weapon:</span><span id="weapon">0</span>
        <span>ammo:</span><span id="ammo">0</span>
        <span>max_ammo:</span><span id="max_ammo">0</span>
        <span>money:</span><span id="money">0</span>
        <span>speed:</span><span id="speed">0</span>

        <span>1:</span><span id="s1">0</span>
        <span>2:</span><span id="s2">0</span>
    </div>
    <script>
        // tell our plugin which default components we want to hide ("interface" means all components)
        // list of all components are here: https://github.com/ZOTTCE/samp-cef/blob/664179f058706d84d7757b01094e8ac9ce08b82a/cef-interface/src/components.rs#L47
        // (ammo, weapon, health, etc)
        cef.emit("game:hud:setComponentVisible", "interface", false);
        cef.emit("game:hud:setComponentVisible", "radar", false);  // how to disable a radar
        // ask the plugin to call our "game:data:playerStats" event every 50 ms. (pass false to stop it)
        cef.emit("game:data:pollPlayerStats", true, 50);

        // subscribe to an event that triggered from the plugin
        // arm = armour
        cef.on("game:data:playerStats", (hp, max_hp, arm, breath, wanted, weapon, ammo, max_ammo, money, speed) => {
            document.getElementById("hp").innerText = `${hp}`;
            document.getElementById("max_hp").innerText = `${max_hp}`;
            document.getElementById("arm").innerText = `${arm}`;
            document.getElementById("breath").innerText = `${breath}`;
            document.getElementById("wanted").innerText = `${wanted}`;
            document.getElementById("weapon").innerText = `${weapon}`;
            document.getElementById("ammo").innerText = `${ammo}`;
            document.getElementById("max_ammo").innerText = `${max_ammo}`;
            document.getElementById("money").innerText = `${money}`;
            document.getElementById("speed").innerText = `${speed}`;
        });

        cef.on("cool", (s1, s2) => {
            document.getElementById("s1").innerText = `${s1}`;
            document.getElementById("s2").innerText = `${s2}`;
        });
    </script>
</body>

</html>

This is my gamemode code:

#define INTERFACE_BROWSER_ID 0xABCDE
#define INTERFACE_BROWSER_URL "http://localhost:5000/cef2.html"

forward CefTest(playerid);
public CefTest(playerid) {
    cef_emit_event(playerid, "cool", CEFINT(random(1000)), CEFSTR("hello"));
    return 1;
}

public OnCefInitialize(player_id, success) {
    if (success == 1) {
        // it is not hidden and not focused, we should be able to see it but cannot input from mouse / keyboard to it.
        cef_create_browser(player_id, INTERFACE_BROWSER_ID, INTERFACE_BROWSER_URL, false, false);
        return;
    }

    SendClientMessage(player_id, -1, "Ahh to bad you cannot see our new cool interface ...");
}

public OnPlayerConnect(playerid)
{
    SetTimerEx("CefTest", 150, true, "i", playerid);
    return 1;
}
UserNoName000 commented 3 years ago
<PAWN CODE>
TimerFuelUpdate[playerid] = SetTimerEx( "FuelUpdate", 1000, true, "i", playerid );
public FuelUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid)) {
        cef_emit_event(playerid, "interface:set:fuel", CEFFLOAT(CarInfo[GetPlayerVehicleID(playerid)][cFuel]));
    }
    return 1;
}
<HTML CODE>
cef.on('interface:set:fuel', (value) => {
    document.getElementById('text_fuel').innerText = `${value.toFixed(1)}`;
});

Somewhere after 30 minutes, the interface freezes, only those functions are updated that are not transmitted by events but are updated in JS (money, speed). And the plugin says that it does not respond.

Can you still answer, can you use the radar through your plugin?

At first we thought that this was due to the server plugin that we compiled for cenos7, but then everything was also tested on the local server, and the same problem remained.

If I did something wrong, I can provide all the code, for example, to your mail. I don't really want to post everything here.

This is what the log shows. 09:29:56 [TRACE] (6) client::network: [client\src\network.rs:372] CEF Network: Timeout