Raised This Month: $12 Target: $400
 3% 

[Help] Need to find and remove a line from admin_simple.ini


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 09-27-2016 , 15:07   [Help] Need to find and remove a line from admin_simple.ini
Reply With Quote #1

well, the topic says everything , i have already made my plugin to find SteamID and write it through admin_simple.ini but for removing it i need to have a code to find the Line with the given SteamID and Remove That line.
Any Help?
ambn is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 09-28-2016 , 13:12   Re: [Help] Need to find and remove a line from admin_simple.ini
Reply With Quote #2

Nothing?
ambn is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-28-2016 , 15:29   Re: [Help] Need to find and remove a line from admin_simple.ini
Reply With Quote #3

I recommend to leave SM admins files alone and create new one for add/remove steamids by plugin.

Last edited by Bacardi; 09-28-2016 at 15:30.
Bacardi is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-28-2016 , 17:38   Re: [Help] Need to find and remove a line from admin_simple.ini
Reply With Quote #4

^^^

Anyway, It might not work because I never tested it. There's also probably a better way than what I am doing.

It returns the new handle to the file since you have to delete and rewrite it.
PHP Code:
 file RemoveEntryFromFile(SteamIDfile"admin_simple.ini"); 

PHP Code:
File RemoveEntryFromFile(const char[] sSearchFile hFile, const char[] fileName)
{
    
char sLine[128], path[PLATFORM_MAX_PATH];
    
ArrayList array;
    
    
BuildPath(Path_SMpathsizeof(path), "addons/sourcemod/configs/%s"fileName)
    array.
Clear();
    
    while (!
hFile.EndOfFile() && hFile.ReadLine(sLinesizeof(sLine)))
    {
        if(
StrContains(sLinesSearch) == -1)
        {
            array.
Push(sLine);
        }
    }
    
hFile OpenFile(path"w");
    for (
int i 0< array.Size(); i++)
    {
        array.
GetString(isLinesizeof(sLine));
        
hFile.WriteLine(sLine);
    }
    
delete array;
    return 
hFile;


Last edited by headline; 09-28-2016 at 17:42.
headline is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 09-30-2016 , 04:02   Re: [Help] Need to find and remove a line from admin_simple.ini
Reply With Quote #5

Quote:
Originally Posted by Headline View Post
^^^

Anyway, It might not work because I never tested it. There's also probably a better way than what I am doing.

It returns the new handle to the file since you have to delete and rewrite it.
PHP Code:
 file RemoveEntryFromFile(SteamIDfile"admin_simple.ini"); 
PHP Code:
File RemoveEntryFromFile(const char[] sSearchFile hFile, const char[] fileName)
{
    
char sLine[128], path[PLATFORM_MAX_PATH];
    
ArrayList array;
    
    
BuildPath(Path_SMpathsizeof(path), "addons/sourcemod/configs/%s"fileName)
    array.
Clear();
    
    while (!
hFile.EndOfFile() && hFile.ReadLine(sLinesizeof(sLine)))
    {
        if(
StrContains(sLinesSearch) == -1)
        {
            array.
Push(sLine);
        }
    }
    
hFile OpenFile(path"w");
    for (
int i 0< array.Size(); i++)
    {
        array.
GetString(isLinesizeof(sLine));
        
hFile.WriteLine(sLine);
    }
    
delete array;
    return 
hFile;

Well, as long as i'm not a sm scripter i konda don't know how to use this code! but let me give you my own code for adding admins to admin_simple.ini (I kinda went Though SM AddAdmin Plugin)
PHP Code:
public Action:Command_NormalAdmin(clientargs)
{
    if(
args 1)
    {
        
ReplyToCommand(client"[SM] Usage: sm_mkadmin <name or #userid>");
        return 
Plugin_Handled;
    }
    new 
String:szTarget[64], String:szFlags[20], String:Sid[32], String:name[32];
    
GetCmdArg(1szTargetsizeof(szTarget));
    
int target FindTarget(clientszTarget);
    if(
target == -1)
    {
        
PrintToChat(client"  \x02[Admin-Add] \x10Choose a Valid Client!");
        return 
Plugin_Handled;
    }
    
GetClientAuthString(targetSidsizeof(Sid));
    
GetClientName(targetnamesizeof(name));
    
szFlags "bcefgjk";
    new 
String:szFile[256];
    
BuildPath(Path_SMszFilesizeof(szFile), "configs/admins_simple.ini");

    new 
Handle:hFile OpenFile(szFile"at");

    
WriteFileLine(hFile" \"%s\"  \"%s\" //%s"SidszFlagsname);
    
    
CloseHandle(hFile);

    
PrintToChatAll(" \x02[Admin-Add] \x10 Client %s With Steam ID [%s] Has Gained Level \x04 NORMAL ADMIN \x10 !"nameSid);
    
CreateTimer(5.0reloadadmin);
    return 
Plugin_Handled;

Now It Adds Something Like This in admin_simple.ini With Player name mentioned after the Flags:
PHP Code:
 "STEAMID"    "Flags"    //Player Name 
This Thing i want is a code to search for the Line That //Player Name Is on the that line then remove the line!
Can anyone help me to do so?
ambn is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 09-30-2016 , 23:48   Re: [Help] Need to find and remove a line from admin_simple.ini
Reply With Quote #6

In return for this plugin, I want you to donate any amount to this community using the donate button at the top.

You're welcome.


As I said before, it might not work at all. I haven't tested it.

(SourceMod 1.8 is required)
Attached Files
File Type: sp Get Plugin or Get Source (hl_removeadmin.sp - 335 views - 1.8 KB)

Last edited by headline; 09-30-2016 at 23:51.
headline is offline
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 01-04-2021 , 13:17   Re: [Help] Need to find and remove a line from admin_simple.ini
Reply With Quote #7

Quote:
Originally Posted by headline View Post
In return for this plugin, I want you to donate any amount to this community using the donate button at the top.

You're welcome.


As I said before, it might not work at all. I haven't tested it.

(SourceMod 1.8 is required)
Code:
while (!file.EndOfFile() && file.ReadLine(sLine, sizeof(sLine))) {     int ch; if((ch = FindCharInString(sLine, '\n')) != -1) {         sLine[ch] = '\0';     }         if(StrContains(sLine, szTarget) != -1) {         found = true;         continue;     }     array.PushString(sLine); }
Newline char must be omitted.. and 'rt' file handle must be closed before it will be opened for writing!

Last edited by ZASTRELIS; 01-04-2021 at 13:18.
ZASTRELIS 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 02:45.


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