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

[Req] Plugins.ini check & rewrite


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Adryyy
Member
Join Date: Oct 2011
Old 07-23-2016 , 16:44   [Req] Plugins.ini check & rewrite
Reply With Quote #1

Hi. Someoane can help me with one code to check and rewrite plugins.ini? If the first line is not what i want, this code rewrite first line with what i want...
Adryyy is offline
Send a message via Yahoo to Adryyy Send a message via Skype™ to Adryyy
wickedd
Veteran Member
Join Date: Nov 2009
Old 07-23-2016 , 17:05   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #2

What are you trying to do?
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Adryyy
Member
Join Date: Oct 2011
Old 07-23-2016 , 17:31   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #3

Quote:
Originally Posted by wickedd View Post
What are you trying to do?
A plugin )

Last edited by Adryyy; 07-23-2016 at 17:51.
Adryyy is offline
Send a message via Yahoo to Adryyy Send a message via Skype™ to Adryyy
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 07-23-2016 , 18:00   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #4

Quote:
Originally Posted by Adryyy View Post
A plugin )
Fucking savage xddd

He means, what are you trying to achieve with it?
redivcram is offline
Adryyy
Member
Join Date: Oct 2011
Old 07-23-2016 , 18:10   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #5

And..What's so important? too many pointless questions

Last edited by Adryyy; 07-23-2016 at 18:14.
Adryyy is offline
Send a message via Yahoo to Adryyy Send a message via Skype™ to Adryyy
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-23-2016 , 19:21   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #6

Quote:
Originally Posted by Adryyy View Post
And..What's so important? too many pointless questions
Exactly. Your question make no sense. We can't answer you question if you don't ask one that we can understand.
__________________
fysiks is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 07-24-2016 , 00:20   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #7

Quote:
Originally Posted by Adryyy View Post
And..What's so important? too many pointless questions
He is saying, we are saying, we are trying the get, ...

The XY problem is asking about your attempted solution rather than your actual problem.
That is, you are trying to solve problem X , and you think solution Y would work, but instead of
asking about X when you run into trouble, you ask about Y.
What is the XY problem? - Meta Stack Exchange

So, we need to know what problem you are trying to solve, not how your are trying to solve.
Because mostly you could pick up the wrong solution, then we would just to waist time, rather than
solve your actual problem.

However, you want to replace the first line of your 'plugins.ini' file?
No problem.
First, you will need to read/load the whole file into the computers memory.
Second, you will modify your first line.
Third, you will delete your current 'plugins.ini' file.
Forth, your will write the contents of the computer memory, which contains the modified file you just read/load, on the file 'plugins.ini'.

Mostly, a better algorithm would to just read the first line, modify it, then write it to a temp file, and then keep reading from one file and writing it on the other until it finishes.
After that, just delete your 'plugins.ini' file and rename the 'temp_file.ini' to 'plugins.ini'.

Easy easy, but expensive operation. Then what is the problem you are trying to solve?
Using Files to write data/values(old and new file commands) (use the new functions a.k.a faster).
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 07-24-2016 at 00:29. Reason: update
addons_zz is offline
Adryyy
Member
Join Date: Oct 2011
Old 07-24-2016 , 03:54   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #8

Yep, open file, read file(flag r + w) > first line, replace first line, close file, thx for tutorial.

It's easy not hard.

Look, plugins.ini


Code:
PLUGINS
MY FIRST LINE
PLUGINS

WITH THIS PLUGIN. CHECK MY FIRST LINE AND...

>>>

Code:
MY FIRST LINE
PLUGINS
fopen, fclose, fread, fwrite


Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Filehandle"
#define VERSION "1.0"
#define AUTHOR "Administrator"

new filename[256]

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    /*get the config directory of amxx*/
    get_configsdir(filename,charsmax(filename))
    format(filename,charsmax(filename),"%s/plugins.ini",filename) // HERE, OPEN FILE..
    //register_concmd("amx_filetestwrite","filewritetest")
    //register_concmd("amx_filetestread","filereadtest")
}

public plugin_cfg()
{
    new readdata[128],plugin[32],/*anyvalue,Float:anyfloatvalue,*/txtlen
    new parsedplugin[32]/*,parsedname[32],parsedanyvalue[8],parsedanyfloatvalue[8]*/
    
    /*now read the data from the file*/
    /*It give 2 ways to read a file until end of line*/
    
    /*The first way*/
    /*file_size - Returns the size of a file.
    If flag is 0, size is returned in bytes.
    If flag is 1, the number of lines is returned.
    If flag is 2, 1 is returned if the file ends in a line feed.
    If the file doesn't exist, -1 is returned. */
    new fsize = file_size(filename,1)
    for (new line=0;line<=fsize;line++)
    {
        /*read_file ( const file[], line, text[], len, &txtLen )*/
        read_file(filename,line,readdata,charsmax(readdata),txtlen) // HERE JUST READ THE FIRTH LINE IN .INI, WHAT IS, and if it's not what I want to rewrite
        /*We must parse the readata in somthing that we can use*/
        //parse(readdata,parsedsteamid,31,parsedname,31,parsedanyvalue,7,parsedanyfloatvalue,7)
	parse(readdata,parsedplugin,charsmax(parsedplugin))
        
        /*check if steamid the same as in file*/
        //get_user_authid(id,steamid,31)
        if(equal(plugin,parsedplugin)/*&&is_plugin_loaded("plugin")*/)
        {
            /*steamid is same as in file,the do somthing with the rest of parsed values*/
            //anyvalue = str_to_num(parsedanyvalue)
            //anyfloatvalue = str_to_float(parsedanyfloatvalue)
            //client_print(id,print_chat,"Your saved Steamid:%s Name:%s Value:%d FloatValue:%f",parsedsteamid,parsedname,anyvalue,anyfloatvalue)
            /*i use break to stop the loop to save more performance.On big files this is good*/
	    // MY MESSAGE HERE
            break
            //...
        }


        else
        {
		new writedata[128]
		formatex(writedata,charsmax(writedata),"plugin.amxx debug")

		write_file(filename,writedata)
        }
    }
    


    /*The second way/the better way*/
    new line = 0 // THIS WAY IS MORE BETTER
    while(!read_file(filename,line++,readdata,charsmax(readdata),txtlen))
    {
        //parse(filename,parsedsteamid,31,parsedname,31,parsedanyvalue,7,parsedanyfloatvalue,7)
	parse(filename,parsedplugin,charsmax(parsedplugin))
        
        //get_user_authid(id,steamid,31)
        if(equal(plugin,parsedplugin))
        {
            //anyvalue = str_to_num(parsedanyvalue)
            //anyfloatvalue = str_to_float(parsedanyfloatvalue)
            //client_print(id,print_chat,"Your saved Steamid:%s Name:%s Value:%d FloatValue:%f",parsedsteamid,parsedname,anyvalue,anyfloatvalue)
	    // MY MESSAGE HERE
            break
            //...
        }


        else
        {
		new writedata[128]
		formatex(writedata,charsmax(writedata),"plugin.amxx debug")

		write_file(filename,writedata)
        }
    }   
}

/*
public filewritetest(id){
    new writedata[128]
    new steamid[32],name[32],anyvalue,Float:anyfloatvalue
    
    //Lets create and copy some dummy data
    get_user_authid(id,steamid,31)
    get_user_name(id,name,31)
    anyvalue = 10
    anyfloatvalue = 5.5
    
    formatex(writedata,127,"%s %s %d %f",steamid,name,anyvalue,anyfloatvalue)
    
    //Now write this data to the file at last line
    //write_file ( const file[], const text[], [ line ] )
    //The line parameter defaults to -1, which appends to the end of the file. Otherwise, a specific line is overwritten.
    //If no file exist write_file create one
    write_file(filename,writedata)
}

public filereadtest(id){
    new readdata[128],steamid[32],anyvalue,Float:anyfloatvalue,txtlen
    new parsedsteamid[32],parsedname[32],parsedanyvalue[8],parsedanyfloatvalue[8]
    
    //now read the data from the file
    //It give 2 ways to read a file until end of line
    
    //The first way
    //file_size - Returns the size of a file.
    //If flag is 0, size is returned in bytes.
    //If flag is 1, the number of lines is returned.
    //If flag is 2, 1 is returned if the file ends in a line feed.
    //If the file doesn't exist, -1 is returned. 
    new fsize = file_size(filename,1)
    for (new line=0;line<=fsize;line++)
    {
        //read_file ( const file[], line, text[], len, &txtLen )
        read_file(filename,line,readdata,127,txtlen)
        //We must parse the readata in somthing that we can use
        parse(readdata,parsedsteamid,31,parsedname,31,parsedanyvalue,7,parsedanyfloatvalue,7)
        
        //check if steamid the same as in file
        get_user_authid(id,steamid,31)
        if(equal(steamid,parsedsteamid))
        {
            //steamid is same as in file,the do somthing with the rest of parsed values
            anyvalue = str_to_num(parsedanyvalue)
            anyfloatvalue = str_to_float(parsedanyfloatvalue)
            client_print(id,print_chat,"Your saved Steamid:%s Name:%s Value:%d FloatValue:%f",parsedsteamid,parsedname,anyvalue,anyfloatvalue)
            //i use break to stop the loop to save more performance.On big files this is good
            break
            //...
        }
    }
    
    //The second way/the better way
    new line = 0
    while(!read_file(filename,line++,readdata,127,txtlen))
    {
        parse(filename,parsedsteamid,31,parsedname,31,parsedanyvalue,7,parsedanyfloatvalue,7)
        
        get_user_authid(id,steamid,31)
        if(equal(steamid,parsedsteamid))
        {
            anyvalue = str_to_num(parsedanyvalue)
            anyfloatvalue = str_to_float(parsedanyfloatvalue)
            client_print(id,print_chat,"Your saved Steamid:%s Name:%s Value:%d FloatValue:%f",parsedsteamid,parsedname,anyvalue,anyfloatvalue)
            break
            //...
        }
    }   
}
*/

Last edited by Adryyy; 07-24-2016 at 04:15.
Adryyy is offline
Send a message via Yahoo to Adryyy Send a message via Skype™ to Adryyy
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-24-2016 , 04:23   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #9

Looks like some non steam stuff for me or even backdoor. If it's your server, how would the file get changed?
__________________

Last edited by HamletEagle; 07-24-2016 at 04:23.
HamletEagle is offline
Adryyy
Member
Join Date: Oct 2011
Old 07-24-2016 , 04:36   Re: [Req] Plugins.ini check & rewrite
Reply With Quote #10

What backdoor? This is tutorial )). Look here :

Code:
#include <amxmodx>
#include <amxmisc>

#include <file>

#define PLUGIN "Filehandle"
#define VERSION "1.0"
#define AUTHOR "Administrator"

new filename[256]

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    get_configsdir(filename,charsmax(filename))
    format(filename,charsmax(filename),"%s/plugins.ini",filename)
    //register_concmd("amx_filetestwrite","filewritetest")
    //register_concmd("amx_filetestread","filereadtest")
}

public plugin_cfg()
{
// READ MOD
   /*open file in read-mode*/
    new filepointer = fopen(filename,"r")
    /*check if file is open,on an error filepointer is 0*/
    if(filepointer)
    {
        new readdata[128],plugin[32]
        new parsedplugin[32]



	// MY METHOD
//The new file commands dont read linespecific,they use a cursor inside the file to read the data.
//This cursor position can get with
        ftell(filepointer) // not filename ??
//And the cursor can set with
        fseek ( filepointer, 1, SEEK_SET ) // beginning of the file , but position?? i can set 1 ? =]
//move the cursor position to begin of the file.
	//rewind ( filepointer )   NOT WORK, UNDEFINED SYMBOL
//Open a file with given filename and mode.
//It returns a pointer to the file.
	fopen ( filename,"a+" )
//Write a formated string to a text file.Same as the format/formatex command,but for files.
//fputs/fprint dont add a newline at end of the string,so it must set manually.
	//fputs ( filename, "plugin.amxx debug")  NOT GOOD?
//Write a string to a text file at current filecursor position.
//"file" must be a pointer to a file from the fopen command.
	fprintf ( filepointer, "plugins.amxx debug" )
	// END OF MY METHOD




        /*Read the file until it is at end of file*/
        /*fgets - Reads a line from a text file -- includes newline!*/
        while(fgets(filepointer,readdata,charsmax(readdata)))
        {   
            parse(readdata,parsedplugin,charsmax(parsedplugin))
        
            if(equal(plugin,parsedplugin))
            {
		// MY MESSAGE HERE
                break
                //...
            }
        }
        fclose(filepointer)
    }
// END READ MOD


// WRITE MOD
    new writedata[128]
    
    /*fopen - Returns a file handle for advanced file functions. 
    Mode uses the standard C library of mode types.
    The first character can be:
    "a" - append
    "r" - read
    "w" - write
    
    The second character can be:
    "t" - text
    "b" - binary
    
    You can also append a "+" to specify both read and write.
    Open a file in append+read+write mode
    On mode "a+"/"w+" it create a file if there no exist
    Mode "w+" overwrite a file if one exist*/
    new filepointerX = fopen(filename,"a+")

    /*check if file is open,on an error filepointer is 0*/
    if(filepointerX)
    {
        /*It give 2 ways to write a string inside a file*/
        
        /*First way*/
        formatex(writedata,charsmax(writedata),"plugin.amxx debug^n")
        //The new file commands need to create a newline manual with "^n"
        
        /*write the string to the file*/
        /*another commands are:
        fputc - Writes a char (1 byte) to a file handle.
        fputf - Writes a float (4 bytes, 8 on AMD64) to a file handle. 
        fputi - Writes an integer (4 bytes) to a file handle. 
        fputl - Writes a long (4 bytes) to a file handle. */
        fputs(filepointerX,writedata)
        



        /*Second way*/  // LIKE THIS
        /*fprintf - Writes a line to a file */
        fprintf(filepointerX,"plugin.amxx debug^n")
        
        /*close the file,this is optional,but better is it to close the file*/
        fclose(filepointerX)
    }
// END WRTIE MOD
}

public filewritetest(id){
    new writedata[128]
    new steamid[32],name[32],anyvalue,Float:anyfloatvalue
    
    get_user_authid(id,steamid,31)
    get_user_name(id,name,31)
    anyvalue = 10
    anyfloatvalue = 5.5
    
    /*fopen - Returns a file handle for advanced file functions. 
    Mode uses the standard C library of mode types.
    The first character can be:
    "a" - append
    "r" - read
    "w" - write
    
    The second character can be:
    "t" - text
    "b" - binary
    
    You can also append a "+" to specify both read and write.
    Open a file in append+read+write mode
    On mode "a+"/"w+" it create a file if there no exist
    Mode "w+" overwrite a file if one exist*/
    new filepointer = fopen(filename,"a+")

    /*check if file is open,on an error filepointer is 0*/
    if(filepointer)
    {
        /*It give 2 ways to write a string inside a file*/
        
        /*First way*/
        formatex(writedata,127,"%s %s %d %f^n",steamid,name,anyvalue,anyfloatvalue)
        //The new file commands need to create a newline manual with "^n"
        
        /*write the string to the file*/
        /*another commands are:
        fputc - Writes a char (1 byte) to a file handle.
        fputf - Writes a float (4 bytes, 8 on AMD64) to a file handle. 
        fputi - Writes an integer (4 bytes) to a file handle. 
        fputl - Writes a long (4 bytes) to a file handle. */
        fputs(filepointer,writedata)
        
        /*Second way*/
        /*fprintf - Writes a line to a file */
        fprintf(filepointer,"%s %s %d %f^n",steamid,name,anyvalue,anyfloatvalue)
        
        /*close the file,this is optional,but better is it to close the file*/
        fclose(filepointer)
    }
}

public filereadtest(id){
    /*open file in read-mode*/
    new filepointer = fopen(filename,"r")
    /*check if file is open,on an error filepointer is 0*/
    if(filepointer)
    {
        new readdata[128],steamid[32],anyvalue,Float:anyfloatvalue
        new parsedsteamid[32],parsedname[32],parsedanyvalue[8],parsedanyfloatvalue[8]
    
        /*Read the file until it is at end of file*/
        /*fgets - Reads a line from a text file -- includes newline!*/
        while(fgets(filepointer,readdata,127))
        {   
            parse(readdata,parsedsteamid,31,parsedname,31,parsedanyvalue,7,parsedanyfloatvalue,7)
        
            get_user_authid(id,steamid,31)
            if(equal(steamid,parsedsteamid))
            {
                anyvalue = str_to_num(parsedanyvalue)
                anyfloatvalue = str_to_float(parsedanyfloatvalue)
                client_print(id,print_chat,"Your saved Steamid:%s Name:%s Value:%d FloatValue:%f",parsedsteamid,parsedname,anyvalue,anyfloatvalue)
                break
                //...
            }
        }
        fclose(filepointer)
    }
}
Adryyy is offline
Send a message via Yahoo to Adryyy Send a message via Skype™ to Adryyy
Reply



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 00:30.


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