• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Server] Problem with GetTickCount
#1
I made an anti flood command script for my gamemode, in which the player can only type commands every 2 seconds. Everything worked fine, until yesterday I realized that this script had bugged, any command typed by the player regardless of the time between them is classified as spam.

[Image: xr701iO.png]

So I decided to do a type of debugging, to see what value the GetTickCount was returning, and it is returning very large negative values.
[Image: Palr2LS.png]

The amazing thing about this problem is that it only occurs on my computer, on my notebook and on the gamemode host this problem does not occur everything works correctly. Does anyone have any idea what this is? Maybe some problem with some windows dll? I do not believe it is a gamemode problem, because as I mentioned in other places it works normally, only on my computer this problem occurs.

Here are the plugins / includes I use and the anti flood code snippet
PHP Code:
#include? ? <a_samp>
#define FIXES_Single 1
#define FIXES_ServerVarMsg 0
#define LOCAL_HOST true
// Redefini??es antes da Fixes
#if? ? ? defined MAX_PLAYERS
#undef? ? MAX_PLAYERS
#if LOCAL_HOST == true
#define? MAX_PLAYERS? (100)
#else
#define? MAX_PLAYERS? (30)
#endif
#endif
//
#include <fixes>
#include <crashdetect>
#include? ? <timerfix>
#include? ? <a_mysql>
#include? ? <foreach>
#include? ? <izcmd>
#include? ? <sscanf2>
#include? ? <MV_Youtube>
#include? ? <streamer>
#include? ? <callbacks>
#include? ? <mSelection>
#define AUTO_SETUP
#include? ? <gmtime>


public OnPlayerCommandReceived(playeridcmdtext[])
{
? ? if (!
IsPlayerConnected(playerid) || playerid == INVALID_PLAYER_ID)
{
return 
SendClientMessage(playeridCOLOR_INVALID"You are not connected."), false;
}
if (
GetTickCount() - timeUsedCommand[playerid] < 2000)
? ? {
return 
SendClientMessage(playeridCOLOR_GRAD1"Wait 2 seconds to retype a command!"), false;
? ? }
timeUsedCommand[playerid] = GetTickCount();
? ? return 
1;


plugins crashdetect fixchars sscanf mysql streamer timerfix gmtime SAMPSON

And this problem has occurred with any code that uses the native GetTickCount.
  Reply
#2
Do you keep your computer on at all times?
  Reply
#3
I have no idea about GetTickCount() but you can use gettime() instead.

PHP Code:
public OnPlayerCommandReceived(playeridcmdtext[])
{
? ? if (!
IsPlayerConnected(playerid) || playerid == INVALID_PLAYER_ID)
{
return 
SendClientMessage(playeridCOLOR_INVALID"You are not connected."), false;
}
if (
gettime() < timeUsedCommand[playerid])
? ? {
return 
SendClientMessage(playeridCOLOR_GRAD1"Wait 2 seconds to retype a command!"), false;
? ? }
timeUsedCommand[playerid] = gettime();
? ? return 
1;

  Reply
#4
(2021-03-11, 08:12 PM)Virsenas Wrote: Do you keep your computer on at all times?



No. I usually use it for my daily tasks and then hang up. literally, overnight this problem appeared and what intrigues me the most is that it only happens on the computer.
  Reply
#5
(2021-03-11, 08:53 PM)RhaegarX Wrote:
(2021-03-11, 08:12 PM)Virsenas Wrote: Do you keep your computer on at all times?



No. I usually use it for my daily tasks and then hang up. literally, overnight this problem appeared and what intrigues me the most is that it only happens on the computer.



Do you get the same results without using timerfix and gmtime?
  Reply
#6
(2021-03-11, 08:31 PM)Radical Wrote: I have no idea about GetTickCount() but you can use gettime() instead.



PHP Code:
public OnPlayerCommandReceived(playeridcmdtext[])

{

? ? if (!
IsPlayerConnected(playerid) || playerid == INVALID_PLAYER_ID)

{

return 
SendClientMessage(playeridCOLOR_INVALID"You are not connected."), false;

}

if (
gettime() < timeUsedCommand[playerid])

? ? {

return 
SendClientMessage(playeridCOLOR_GRAD1"Wait 2 seconds to retype a command!"), false;

? ? }

timeUsedCommand[playerid] = gettime();

? ? return 
1;





It is an option too, but on other devices with GetTickCount it works perfectly. And since this function returns the time in seconds since the server was turned on, there is a problem with that, as it is returning a negative time. I wanted to understand why this problem arose
  Reply
#7
(2021-03-11, 08:55 PM)Virsenas Wrote:
(2021-03-11, 08:53 PM)RhaegarX Wrote:
(2021-03-11, 08:12 PM)Virsenas Wrote: Do you keep your computer on at all times?



No. I usually use it for my daily tasks and then hang up. literally, overnight this problem appeared and what intrigues me the most is that it only happens on the computer.



Do you get the same results without using timerfix and gmtime?



I haven?t tested by removing these plugins, I?ll test it now and I?ll give you the answer shortly
  Reply
#8
(2021-03-11, 08:55 PM)Virsenas Wrote:
(2021-03-11, 08:53 PM)RhaegarX Wrote:
(2021-03-11, 08:12 PM)Virsenas Wrote: Do you keep your computer on at all times?

No. I usually use it for my daily tasks and then hang up. literally, overnight this problem appeared and what intrigues me the most is that it only happens on the computer.

Do you get the same results without using timerfix and gmtime?

I removed the plugins and the problem still persists.
OnPlayerText also has the same system using GetTickCount and the problem is exactly the same as well.
  Reply
#9
I ran the gettickcount, on my computer and notebook at the same time to see what results would be obtained, below is the data:



Computer:

[Image: vAZXpD9.png]



Notebook:

[Image: H4v0Uym.png]
  Reply
#10
folks I found the following information on the open mp wiki that talks about gettickcount uptime problems.

[Image: 6aNz0a2.png]

This is my computer's uptime
[Image: yUFZzGZ.png]

EDIT: I tested the include indicated on the wiki and it didn't work.
  Reply
#11
I found the source of the problem, the GetTickCount () actually has problems with long periods of the connected server. I searched on some forums and windows 10 has a fastboot system that keeps some data saved in memory, such as uptime even after the computer is turned off. the computer is only actually "turned off" when you restart it. when restarting my computer my uptime reset and the function started working again. So, I think it's really better to use gettime (), rather than GetTickCount () to avoid problems.
  Reply
#12
(2021-03-11, 09:38 PM)RhaegarX Wrote: folks I found the following information on the open mp wiki that talks about gettickcount uptime problems.



[Image: 6aNz0a2.png]



This is my computer's uptime

[Image: yUFZzGZ.png]



EDIT: I tested the include indicated on the wiki and it didn't work.



I thought I asked if you shut down your computer regularly.



Quote:Do you keep your computer on at all times?



I guess I didn't.
  Reply
#13
(2021-03-11, 10:02 PM)Virsenas Wrote:
(2021-03-11, 09:38 PM)RhaegarX Wrote: folks I found the following information on the open mp wiki that talks about gettickcount uptime problems.

[Image: 6aNz0a2.png]

This is my computer's uptime
[Image: yUFZzGZ.png]

EDIT: I tested the include indicated on the wiki and it didn't work.

I thought I asked if you shut down your computer regularly.

Quote:Do you keep your computer on at all times?

I guess I didn't.

I turn off the computer during the night, but I keep it connected to power, as there is no use. But this windows fastboot system does not reset the computer uptime even when it is turned off (I believe that if you remove the computer from the power outlet it will reset)

https://social.technet.microsoft.com/For...progeneral
  Reply
#14
The wiki is sort of correct, but the solution is very very wrong. You just need to use a subtraction.



While the code might look like this before:



Code:
if (newTime < oldTime  2000)

{

    // Flooding.

}



The solution is amazingly simple - just rearrange the formula



Code:
if (newTime - oldTime < 2000)

{

    // Flooding.

}



That will totally account for all wrap-around and negative numbers (I'm not going to prove it mathematically here though).
  Reply
#15
Thank you all for your help!
  Reply
#16
(2021-03-12, 01:17 AM)RhaegarX Wrote: Thank you all for your help!
You can (and should) use tickcount() as it's same as GetTickCount() except it's the time since THE SERVER is running, not THE COMPUTER.

https://open.mp/docs/scripting/functions/Tickcount
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#17
You can also use this: https://github.com/ScavengeSurvive/tick-difference
  Reply
#18
(2021-03-12, 11:51 AM)Pinch Wrote:
(2021-03-12, 01:17 AM)RhaegarX Wrote: Thank you all for your help!

You can (and should) use tickcount() as it's same as GetTickCount() except it's the time since THE SERVER is running, not THE COMPUTER.



https://open.mp/docs/scripting/functions/Tickcount



It makes no difference if you use the correct code (i.e. the code I posted).



(2021-03-13, 08:40 AM)rasheed Wrote: You can also use this: https://github.com/ScavengeSurvive/tick-difference



No, you shouldn't. It makes the same mistake as I mentioned earlier. Well, not quite mistake - the result is eventually correct, but in an extremely round-about manner.
  Reply
#19
(2021-03-13, 02:25 PM)Y_Less Wrote:
(2021-03-12, 11:51 AM)Pinch Wrote:
(2021-03-12, 01:17 AM)RhaegarX Wrote: Thank you all for your help!
You can (and should) use tickcount() as it's same as GetTickCount() except it's the time since THE SERVER is running, not THE COMPUTER.

https://open.mp/docs/scripting/functions/Tickcount

It makes no difference if you use the correct code (i.e. the code I posted).

Bench it.

Ik it has no difference tho (the formula)
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#20
Yeah I'm not talking about performance, nor do I care about the performance of a single simple native - and neither should you. Whatever your code, that won't be the bottleneck and you should spend your time improving something else.
  Reply
#21
(2021-03-13, 05:36 PM)Y_Less Wrote: Yeah I'm not talking about performance, nor do I care about the performance of a single simple native - and neither should you.? Whatever your code, that won't be the bottleneck and you should spend your time improving something else.



Agreed. Should never over do things with optimizations, become obsessed with it and pay attention to even smallest things. That is exactly how relationships are ruined ...
  Reply
#22
(2021-03-13, 05:36 PM)Y_Less Wrote: Yeah I'm not talking about performance, nor do I care about the performance of a single simple native - and neither should you. Whatever your code, that won't be the bottleneck and you should spend your time improving something else.

Nawh I was just interested, didn't say it means a lot :D
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply


Forum Jump: