SA-MP Forums Archive
[Plugin] samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] samp-precise-timers ⌚: A timer plugin written in the memory-safe Rust language. Check it out, you might like Rust! (/showthread.php?tid=666687)



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

samp-precise-timers ⌚
github.com/bmisiak/samp-precise-timers

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



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

<3

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


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

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:


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

Do you know if this is compatible with y_timers?


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

Quote:
Originally Posted by Chaprnks
View Post
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
View Post
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 😊


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

Quote:
Originally Posted by Misiek
View Post
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?


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

Quote:
Originally Posted by RogueDrifter
View Post
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.


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

Quote:
Originally Posted by nickdodd25
View Post
Fairly certain that you can pass a string as long as it is not empty. Kind of like CallRemote/LocalFunction.
https://sampwiki.blast.hk/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?


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

Going to go ahead and implement this. Good job.


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

Quote:
Originally Posted by RogueDrifter
View Post
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.


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



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


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

Hi everyone!
Thanks for the reports!

samp-precise-timers ⌚v2.0.2 release
This SA-MP plugin provides precise timers for the server. It is written in Rust, a memory-safe language.

Fix for `Native function not found`
As was discovered in issue #7, sampgdk (used by other plugins) makes certain assumptions about pointer lifetimes. This caused an incompatibility between samp-rs and sampgdk. The plugin now uses a newer samp-rs which contains a workaround, so using samp-precise-timers in tandem with certain other plugins will no longer cause `Native function not found` to appear.

CentOS 7 support
CentOS 7 ships with an old version of a library called `glibc`. The plugin will no longer depend on the newer version 2.18 and should now work just fine on CentOS.

https://github.com/bmisiak/samp-precise-timers


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

Quote:
Originally Posted by Misiek
View Post
Hi everyone!
Thanks for the reports!

samp-precise-timers ⌚v2.0.2 release
This SA-MP plugin provides precise timers for the server. It is written in Rust, a memory-safe language.

Fix for `Native function not found`
As was discovered in issue #7, sampgdk (used by other plugins) makes certain assumptions about pointer lifetimes. This caused an incompatibility between samp-rs and sampgdk. The plugin now uses a newer samp-rs which contains a workaround, so using samp-precise-timers in tandem with certain other plugins will no longer cause `Native function not found` to appear.

CentOS 7 support
CentOS 7 ships with an old version of a library called `glibc`. The plugin will no longer depend on the newer version 2.18 and should now work just fine on CentOS.

https://github.com/bmisiak/samp-precise-timers
EDIT: Evidentally not with it today; I'm going to try this!


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

So we just have to change SetTimer(also SetTimerEx) to SetPreciseTimer and KillTimer to DeletePreciseTimer?


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

Quote:
Originally Posted by Fairuz
View Post
So we just have to change SetTimer(also SetTimerEx) to SetPreciseTimer and KillTimer to DeletePreciseTimer?
Yes that simple


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

It would be better with these functions:

Code:
IsValidPreciseTimer
KillAllPreciceTimers



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

Quote:
Originally Posted by Unrea1
View Post
It would be better with these functions:

Code:
IsValidPreciseTimer
KillAllPreciceTimers
I've been using this plugin on my test server and I agree with the IsValid function, it is needed.


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

Quote:
Originally Posted by Unrea1
View Post
It would be better with these functions:

Code:
IsValidPreciseTimer
KillAllPreciceTimers
Hey, thanks for the suggestion. I could add it, but also, I would love to get a second contributor. If anyone is feeling like they'd like to give it a try and add it, hit me up! I'd love to help with any roadblocks you encounter. It will be very similar to the code for DeletePreciseTimer.


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

Quote:
Originally Posted by Misiek
View Post
Hey, thanks for the suggestion. I could add it, but also, I would love to get a second contributor. If anyone is feeling like they'd like to give it a try and add it, hit me up! I'd love to help with any roadblocks you encounter. It will be very similar to the code for DeletePreciseTimer.
I tried to use this plugin on a test server however sometimes it doesn't call the functions, all the calls seem to stop randomly.