Raised This Month: $32 Target: $400
 8% 

[CSGO] Why MY Repeat Timer Stop PrintMessage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bklol
Member
Join Date: May 2019
Location: on my chair
Old 10-12-2020 , 10:29   [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #1

PHP Code:
#include <sourcemod>

int n 0;
int Lines;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_t);
}

public 
Action Command_t(int client,int args)
{
    
CreateTimer(0.1TIMER,client,TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action TIMER(Handle timerany client)
{
    
char lineBuffer[1024];
    
Handle fileHandle OpenFile("addons/sourcemod/configs/badapple.text","r");
    
Lines 1;
    while(!
IsEndOfFile(fileHandle) && ReadFileLine(fileHandlelineBuffersizeof(lineBuffer)))
    {
        for(
int line 1;line <59line++)
        {
            if(
Lines == line n*60)
                
PrintToConsole(client,"%s",lineBuffer);
        }
        
Lines++;
    }
    
n++;

And Here is text file :https://github.com/bklol/badapple-in...r/badapple.txt
Can anyone tell me why timer stop work,thanks a lot!

Last edited by bklol; 10-12-2020 at 10:30.
bklol is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-12-2020 , 13:12   Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #2

you should add "return Plugin_Continue;" in the last line (after n++) if you want that to repeat.
__________________
Marttt is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-16-2020 , 15:06   Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #3

At least, because you have handles leak.
You need to close fileHandle.

Also, your file is just too large. It could be disk overloading /and/or console buffer overflow in constant calling PrintToConsole(). Need to check.
I would read it just once in a huge array and always access to that array only.

Never pass client id in timers, use UserId (retrieved by GetClientUserId()).

PS. Your math is a mind crack. There is surely something wrong.

Marttt, it is Plugin_Continue by default.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 10-16-2020 at 15:07.
Dragokas is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-16-2020 , 21:57   Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #4

Thanks I really dont know where is this in the SM documentation, as an ex Java/DotNet developer is really weird make "Actions" calls without returns
__________________

Last edited by Marttt; 10-16-2020 at 21:57.
Marttt is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-17-2020 , 01:58   Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #5

I would imagine that the timer isn't the only thing that stops working on your server. With 10 handles being leaked every second and the constant buffer overflow from PrintToConsole, you could cause the server and all the players on it to crash/disconnect.

Please read about Handles and Timers before attempting to do something like this. It may seem like "simple code" but it's enough to cause issues for anyone using that plugin along with that large ass file. My browser can't even load the entire page without freezing.
__________________
Psyk0tik is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-17-2020 , 05:21   Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #6

PHP Code:


#include <sdktools>

File myfile;

public 
void OnPluginStart()
{
    
char path[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMpathsizeof(path), "configs/badapple.txt");
    
    if(!
FileExists(path)) SetFailState("Fail: %s"path);
    
    
myfile OpenFile(path"r");
    
    if(
myfile == nullSetFailState("Fail! File is null");


    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{

    if(
client != 0) return Plugin_Handled;

    if(
myfile.EndOfFile())
    {
        
myfile.Seek(0,0);
    }

    
CreateTimer(0.01delayclientTIMER_REPEAT);

    return 
Plugin_Handled;
}


public 
Action delay(Handle timerint client)
{

    if(
myfile.EndOfFile()) return Plugin_Stop;

    
char line[9000];
    
char buffer[9000];
    
int a 0;

    for(
int x 060x++)
    {
        
myfile.ReadLine(linesizeof(line));
        
strlen(line);
        
        if(
0line[a-1]='\0';
        
        
PrintToServer(line);
    }
    
    

    
    
    return 
Plugin_Continue;

Sending to player console will cause buffer overflow errors.
__________________
Do not Private Message @me
Bacardi is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-17-2020 , 09:05   Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #7

Quote:
Originally Posted by Marttt View Post
Thanks I really dont know where is this in the SM documentation, as an ex Java/DotNet developer is really weird make "Actions" calls without returns
That is by default, return 0, which is Plugin_Continue equals.
Actually, I am always wondering, why compiler does not throw error about missed return.

Quote:
Originally Posted by Crasher_3637 View Post
... and the constant buffer overflow from PrintToConsole, you could cause the server and all the players on it to crash/disconnect.
This is looks like some kind of animated graphics, thing the author is trying to implement.
I remember I done similar plugin for animated chat dedicated to the last New Year, and wanted to share.
But I found inexplicable leak somewhere in game engine related to PrintToChat() command,
causing this function is totally broken and displaying a garbage every time.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
bklol
Member
Join Date: May 2019
Location: on my chair
Old 10-19-2020 , 06:05   Re: [CSGO] Why MY Repeat Timer Stop PrintMessage
Reply With Quote #8

it works great!thank you
bklol is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode