SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Plugin Development (https://forum.sa-mp.com/forumdisplay.php?f=18)
-   -   [Plugin] samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust! (https://forum.sa-mp.com/showthread.php?t=666687)

Misiek 20/05/2019 08:04 AM

samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Briefly
Developed for net4game.com (RolePlay), this SA-MP plugin provides precise timers for the server. It is written in Rust, a memory-safe language.

Why rewrite timers?
I had a lot of safety concerns with some of the existing solutions. They weren't written with data integrity, memory safety or preventing server crashes in mind and seemed to have quite a few bugs. As privacy and safety is our primary concern at net4game, I wrote this in Rust, which combines high-level ergonomics with the performance of a low-level language. ⚡

Please check out the code to see the benefits. You might like Rust a lot. The code is much simpler than C++ equivalents, especially the ones which still use *char, free() and delete[] instead of modern C++ idioms such as std::unique_ptr, but as Rust has no runtime, there is no overhead 😉

We would like your help! 💃
Oh, and if you enjoy working on servers, we are looking for a team to help our international expansion. 🎉 net4game has been around for a decade as the biggest Polish server. We introduced a lot of innovations over the years and we are almost ready to become international. Shoot me an e-mail at bm+code@net4game.com if you're interested.

Downloads on GitHub
Also available on sampctl:
Code:

bmisiak/samp-precise-timers

cSharp 20/05/2019 09:09 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
<3

The message you have entered is too short. Please lengthen your message to at least 4 characters.

Mobtiesgangsa 21/05/2019 12:23 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Great respect for u polish developers for presenting such a unique plugin, as soon as reach my destination I might give a try, BTW great introduction of your release +rep:

Chaprnks 21/05/2019 04:27 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Do you know if this is compatible with y_timers?

Misiek 21/05/2019 06:06 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by Chaprnks (Post 4099452)
Do you know if this is compatible with y_timers?

Yeah, it is fully compatible with y_timers. The plugin defines two new natives:
Code:

/*
    # SetPreciseTimer returns timer_number, or 0 on failure.
        interval: miliseconds before the callback is triggered.
        repeat:  true/false. If false, the callback will only be called once.

    # Examples:
    SetPreciseTimer("EveryMinute",60000,true);
    SetPreciseTimer("EverySecond",1000,true,"ds",playerid,"Hello");
    new array[2] = {42,2}; SetPreciseTimer("AfterFiveSecs",5000,false,"dsaA",playerid,"world",array,sizeof(array));
*/
native SetPreciseTimer(const callback_name[], const interval, const repeat, const types_of_arguments[]="", {Float,_}:...);

/*
    Returns 1 if the timer existed or 0 on failure.
*/
native DeletePreciseTimer(const timer_number);

The argument syntax is compatible with SetTimerEx.

Quote:

Originally Posted by Mobtiesgangsa (Post 4099423)
Great respect for u polish developers for presenting such a unique plugin, as soon as reach my destination I might give a try, BTW great introduction of your release +rep:

Thank you. I tried to make the code easy to understand. Give it a go, I would love to get some feedback 😊

RogueDrifter 21/05/2019 07:36 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by Misiek (Post 4099461)
Yeah, it is fully compatible with y_timers. The plugin defines two new natives:
Code:

/*
    # SetPreciseTimer returns timer_number, or 0 on failure.
        interval: miliseconds before the callback is triggered.
        repeat:  true/false. If false, the callback will only be called once.

    # Examples:
    SetPreciseTimer("EveryMinute",60000,true);
    SetPreciseTimer("EverySecond",1000,true,"ds",playerid,"Hello");
    new array[2] = {42,2}; SetPreciseTimer("AfterFiveSecs",5000,false,"dsaA",playerid,"world",array,sizeof(array));
*/
native SetPreciseTimer(const callback_name[], const interval, const repeat, const types_of_arguments[]="", {Float,_}:...);

/*
    Returns 1 if the timer existed or 0 on failure.
*/
native DeletePreciseTimer(const timer_number);

The argument syntax is compatible with SetTimerEx.


Thank you. I tried to make the code easy to understand. Give it a go, I would love to get some feedback 😊

I thought we were unable to pass strings through the settimer function, does that mean your plugin fixes it?

nickdodd25 22/05/2019 12:06 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by RogueDrifter (Post 4099472)
I thought we were unable to pass strings through the settimer function, does that mean your plugin fixes it?

Fairly certain that you can pass a string as long as it is not empty. Kind of like CallRemote/LocalFunction.

RogueDrifter 22/05/2019 12:20 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by nickdodd25 (Post 4099509)
Fairly certain that you can pass a string as long as it is not empty. Kind of like CallRemote/LocalFunction.

https://wiki.sa-mp.com/wiki/SetTimerEx

Quote:

Originally Posted by Wiki.sa-mp
Specifier Meaning
i Integer.
d Integer.
a Array. The next parameter must be an integer ("i") with the array's size. [CURRENTLY UNUSABLE]
s String. [CURRENTLY UNUSABLE]
f Float.
b Boolean (true/false).

Are you sure?

MisterTickle 22/05/2019 08:11 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Going to go ahead and implement this. Good job.

nickdodd25 22/05/2019 09:35 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by RogueDrifter (Post 4099512)


Ah.... just tested it and you would be correct. I just get random chars instead of the string i passed. I thought the issue was similar to the empty string issue. Guess not. :picard:

MouadJhon 22/05/2019 09:51 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Looks Good

MisterTickle 23/05/2019 02:01 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
This doesn't seem to work for me for some reason. It breaks object and actor deleting and I'm unsure. I've converted all my timers over, but the error doesn't tel me the particular timer causing a problem.

[03:40:54] samp-precise-timers error: The amount of callback arguments passed (1) does not match the length of the list of types (4).
[03:40:54] [sampgdk:warning] Native function not found: DestroyPlayerObject
[03:40:55] [sampgdk:warning] Native function not found: DestroyActor
[03:40:57] [sampgdk:warning] Native function not found: StopPlayerObject

RogueDrifter 23/05/2019 02:22 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by nickdodd25 (Post 4099595)
Ah.... just tested it and you would be correct. I just get random chars instead of the string i passed. I thought the issue was similar to the empty string issue. Guess not. :picard:

Nope, i mean it is fixable by creating a variable string with an array holding max value of the parameters passed through the timer, something you would see in a script fixing the BanEx function, like so:
pawn Code:
#define MAX_BAN_REASON_LENGTH 120
#define KICKBAN_FIX_WAIT 250// In ms

static
    FIX_BanReason[MAX_PLAYERS][MAX_BAN_REASON_LENGTH ];

hook BanEx(playerid, const reason[])    
{
    if(playerid < 0 || playerid > MAX_PLAYERS) return 0;
    if(!IsPlayerConnected(playerid)) return 0;

    format(FIX_BanReason[playerid], MAX_BAN_REASON_LENGTH, "%s", reason);
    SetTimerEx("kickban_FIX", KICKBAN_FIX_WAIT, false, "i", playerid);
    return 1;
}

forward kickban_FIX(playerid);
public kickban_FIX(playerid)
{
    BanEx(playerid, FIX_BanReason[playerid]);
    return 1;
}

But then again I'm not sure if this guy's plugin fixes the issue or not so we await his reply.

Misiek 23/05/2019 09:46 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by RogueDrifter (Post 4099472)
I thought we were unable to pass strings through the settimer function, does that mean your plugin fixes it?

Yes. This plugin handles strings correctly (as noted on GitHub), no need to worry.

Quote:

Originally Posted by kocurek (Post 4099541)
great plugin!
but, will you add IsValidPreciseTimer and SetPreciseTimerInterval?

I will add SetPreciseTimerInterval.

IsValidTimer, however, is a little misleading in other plugins. They don't actually guarantee that the timer in a given slot is still the same timer as when assigned. For example:
Code:

new TimerVariable;
public OnGameModeInit() {
    TimerVariable = SetTimer("Timer1",3000,1);
}

public OnPlayerConnect(playerid) {
    TimerVariable = SetTimer("Timer2",1000,1); //timer id accidentally assigned to the same variable
}

public OnGameModeExit() {
    printf("TimerVariable's timer %d is valid, but points to a new timer: %d",TimerVariable, IsValidTimer(TimerVariable));
}

As you can see, TimerVariable is technically valid, but probably not what was intended, because it now points to a completely different timer.

A proper implementation would use versioned timer ids.

Quote:

Originally Posted by MisterTickle (Post 4099583)
Going to go ahead and implement this. Good job.

Thanks! Let me know how that goes!

Misiek 23/05/2019 09:51 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by MisterTickle (Post 4099616)
This doesn't seem to work for me for some reason. It breaks object and actor deleting and I'm unsure. I've converted all my timers over, but the error doesn't tel me the particular timer causing a problem.

[03:40:54] samp-precise-timers error: The amount of callback arguments passed (1) does not match the length of the list of types (4).
[03:40:54] [sampgdk:warning] Native function not found: DestroyPlayerObject
[03:40:55] [sampgdk:warning] Native function not found: DestroyActor
[03:40:57] [sampgdk:warning] Native function not found: StopPlayerObject

This plugin doesn't have much of a way to affect those functions - it doesn't hook anything, just adds new natives. It seems somewhere in your code you defined a timer with a wrong amount of argument letters. I'll add the name of the callback to the warning so you can know which one is being problematic.

Uberanwar 25/08/2019 12:40 PM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
I have this issue - [20:24:20] Loading plugin: samp-precise-timers.so
[20:24:20] Failed (/lib/libc.so.6: version `GLIBC_2.18' not found (required by plugins/samp-precise-timers.so))

I use CentOS 7.5

B3x7K 26/08/2019 11:04 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by Uberanwar (Post 4111228)
I have this issue - [20:24:20] Loading plugin: samp-precise-timers.so
[20:24:20] Failed (/lib/libc.so.6: version `GLIBC_2.18' not found (required by plugins/samp-precise-timers.so))

I use CentOS 7.5

Code:

yum install glibc-static

B3x7K 26/08/2019 11:07 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by Misiek (Post 4099648)
This plugin doesn't have much of a way to affect those functions - it doesn't hook anything, just adds new natives. It seems somewhere in your code you defined a timer with a wrong amount of argument letters. I'll add the name of the callback to the warning so you can know which one is being problematic.

I think maybe sampgdk rust made the error :\
But, i'm not sure though because i just guessing...

FelipeSantos 05/09/2019 05:44 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Thank you!
I spent like 4 hours trying to make y_timers to work, but I was getting "heapspace too low [...]". I was looking for a plugin due to "CURRENTLY UNUSABLE" on SetTimerEx when using strings and arrays and a more accurate timer.
One more time, thank you for sharing it with us.

Uberanwar 06/09/2019 08:44 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
Quote:

Originally Posted by B3x7K (Post 4111337)
Code:

yum install glibc-static

I still have the issue. [16:45:14] Failed (/lib/libc.so.6: version `GLIBC_2.18' not found (required by plugins/samp-precise-timers.so)). Can you make it compatible with GLIBC_2.17?

Chaprnks 14/09/2019 05:22 AM

Re: samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust!
 
https://i.vgy.me/reFA0A.png

I get this warning only when the timers plugin is enabled. Maybe SAMPGDK is out of date?


All times are GMT. The time now is 09:48 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.