Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Support [Server] Problem with GetTickCount

 
  • 0 Vote(s) - 0 Average
Server Problem with GetTickCount
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#1
2021-03-11, 12:55 PM (This post was last modified: 2021-03-11, 12:57 PM by RhaegarX.)
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(playerid, cmdtext[])
{
    if (!IsPlayerConnected(playerid) || playerid == INVALID_PLAYER_ID)
{
return 
SendClientMessage(playerid, COLOR_INVALID, "You are not connected."), false;
}
if (
GetTickCount() - timeUsedCommand[playerid] < 2000)
    {
return 
SendClientMessage(playerid, COLOR_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.
Virsenas
Offline

Burgershot Member
Posts: 47
Threads: 0
Joined: Feb 2021
Reputation: 6
#2
2021-03-11, 08:12 PM
Do you keep your computer on at all times?
Radical
Offline

Burgershot Member
Posts: 148
Threads: 21
Joined: Dec 2020
Reputation: 16
#3
2021-03-11, 08:31 PM (This post was last modified: 2021-03-11, 08:31 PM by Radical.)
I have no idea about GetTickCount() but you can use gettime() instead.

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

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#4
2021-03-11, 08:53 PM
(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.
Virsenas
Offline

Burgershot Member
Posts: 47
Threads: 0
Joined: Feb 2021
Reputation: 6
#5
2021-03-11, 08:55 PM
(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?
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#6
2021-03-11, 08:55 PM
(2021-03-11, 08:31 PM)Radical Wrote: I have no idea about GetTickCount() but you can use gettime() instead.

PHP Code:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if (!IsPlayerConnected(playerid) || playerid == INVALID_PLAYER_ID)
{
return 
SendClientMessage(playerid, COLOR_INVALID, "You are not connected."), false;
}
if (
gettime() < timeUsedCommand[playerid])
    {
return 
SendClientMessage(playerid, COLOR_GRAD1, "Wait 2 seconds to retype a command!"), false;
    }
timeUsedCommand[playerid] = gettime()+2;
    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
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#7
2021-03-11, 08:57 PM
(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
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#8
2021-03-11, 09:08 PM (This post was last modified: 2021-03-11, 09:14 PM by RhaegarX.)
(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.
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#9
2021-03-11, 09:31 PM
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]
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#10
2021-03-11, 09:38 PM (This post was last modified: 2021-03-11, 09:42 PM by RhaegarX.)
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.
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#11
2021-03-11, 09:57 PM
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.
Virsenas
Offline

Burgershot Member
Posts: 47
Threads: 0
Joined: Feb 2021
Reputation: 6
#12
2021-03-11, 10:02 PM
(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.
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#13
2021-03-11, 10:06 PM (This post was last modified: 2021-03-11, 10:08 PM by RhaegarX.)
(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/Forums/windows/en-US/3a6a2ed8-c6e2-4941-a31c-f1ca5b2a450c/why-shutdown-doesnt-reset-the-quotup-timequot-counter?forum=win10itprogeneral
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#14
2021-03-11, 11:18 PM
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).
RhaegarX
Offline

Burgershot Member
Posts: 66
Threads: 12
Joined: Nov 2020
Reputation: 4
#15
2021-03-12, 01:17 AM
Thank you all for your help!
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#16
2021-03-12, 11:51 AM (This post was last modified: 2021-03-12, 11:52 AM by Pinch.)
(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.
rasheed
Offline

Burgershot Member
Posts: 11
Threads: 1
Joined: Apr 2019
Reputation: 0
#17
2021-03-13, 08:40 AM
You can also use this: https://github.com/ScavengeSurvive/tick-difference
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#18
2021-03-13, 02:25 PM
(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.
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#19
2021-03-13, 03:02 PM (This post was last modified: 2021-03-13, 03:03 PM by Pinch.)
(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.
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#20
2021-03-13, 05:36 PM
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.
Virsenas
Offline

Burgershot Member
Posts: 47
Threads: 0
Joined: Feb 2021
Reputation: 6
#21
2021-03-13, 05:46 PM
(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 ...
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#22
2021-03-13, 06:22 PM
(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.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode