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

ReadFileLine help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 01-28-2014 , 15:51   ReadFileLine help
Reply With Quote #1

Hello.
Im going back through my plugins that i made a while back when i wasnt this "more experienced" in Pawn.
My main trouble is my AutoMember plugin. (I know there are a bunch of risks in this code, like misuse of ServerCommand(Ex). Please ignore them )
PHP Code:
#include <sourcemod>
#include <colors>
 
public Plugin:myinfo =
{
    
name "AutoMember",
    
author "Danian de Leeuw",
    
description "Adds members automatically",
    
version "1.0",
    
url "http://www.databasegaming.com"
};

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
PrintToServer("Booting AutoMember v2.0");
    
RegConsoleCmd("sm_register"register);
}

public 
Action:register(clientargs)
{
    
decl String:steamid[64];
    
GetClientAuthString(clientsteamidsizeof(steamid));

    
decl String:name[32];
    
GetClientName(clientnamesizeof(name));
    
    new 
String:szFile[256];
    
BuildPath(Path_SMszFilesizeof(szFile), "configs/admins_simple.ini");
    
    new 
Handle:File OpenFile(szFile"a");
    
WriteFileLine(File"\"%s\" \"1:@members\"     //&s"steamidclient);
    
CloseHandle(File);
    
    
ServerCommand("wait 50; sm_reloadadmins; wait 80; sm plugins reload custom-chatcolors");
    
FakeClientCommandEx(client"say /subscribe");

    
CPrintToChatAll("{green}[AutoMember]{blue} %s{default} has just applied for Member!"name);

    return 
Plugin_Handled;

As of right now, it adds people properly and gives them the flag (it works how its supposed to).
One downside is that it doesnt check if people were already added. So im getting tons of useless duplicates. From about 50-200 member sign ups per day, 45% of those are duplicates.
I read up on ReadFileLine but i dont get how it works.

Also, is there any way that i can check if someone is part of a steam group, so that they have to join it to get the member perks?

Thanks!
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 01-28-2014 at 15:55.
DJ Data is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-28-2014 , 16:41   Re: ReadFileLine help
Reply With Quote #2

If I understand you right, you want to loop throw whole file and read it by lines?

This code do it:
PHP Code:
new Handle:fileHandle OpenFilepath"r" );

while( !
IsEndOfFilefileHandle ) && ReadFileLinefileHandlefileLinesizeoffileLine ) ) )
{
    
TrimStringfileLine );
    
    
// CODE
}

CloseHandlefileHandle ); 
nothing hard..

EDIT: For the steam group, try to use SteamTools, but I might heard something that it's not working properly with CS:S

Last edited by KissLick; 01-28-2014 at 16:47.
KissLick is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 01-28-2014 , 16:44   Re: ReadFileLine help
Reply With Quote #3

I dont know what what loop throw means ^_^*

What i want it to do is:
When someone !register 's it should check if that person is already in the file. So it would have to check if their steamid is already in there, and if it is, return <code>.
Else, <code> (already done this part)
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 01-28-2014 at 16:46.
DJ Data is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-28-2014 , 16:59   Re: ReadFileLine help
Reply With Quote #4

PHP Code:
new Handle:fileHandle OpenFilepath"r" );

decl String:steamid[64], String:LineSteamID16 ];
GetClientAuthString(clientsteamidsizeof(steamid));

while( !
IsEndOfFilefileHandle ) && ReadFileLinefileHandlefileLinesizeoffileLine ) ) )
{
    
TrimStringfileLine );
    
    
// here you get file line - on every loop next line
    // if the lines are in format like shit
    // "STEAMID" "1:@members"    // PLAYER_NAME
    // you can "parse" the steam id and test it
    
    
ReplaceStringExfileLinesizeoffileLine ), "\"""" ); // remove first " from line -> STEAMID" "1:@members"    // PLAYER_NAME
    
strcopyLineSteamIDFindCharInStringfileLine"\"" ), fileLine ); // FindCharInString( fileLine, "\"" ) = until first " is found
    // now you have steam id from file in LineSteamID
    // so compare LineSteamID to steamid
    
    
if( StrEqualLineSteamIDsteamid ) )
    {
        
// Player is already in file..
    
}
}

CloseHandlefileHandle ); 
EDIT: a little mistake in code..

Last edited by KissLick; 01-28-2014 at 17:11.
KissLick is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 01-28-2014 , 19:20   Re: ReadFileLine help
Reply With Quote #5

You shouldn't loop through the file every time someone does a command. You should loop through the file one time when the client connects, and cache the results into an array for that client. Then simply check the array for what it is you are looking for.

Last edited by Marcus_Brown001; 01-28-2014 at 19:20.
Marcus_Brown001 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-28-2014 , 20:21   Re: ReadFileLine help
Reply With Quote #6

You should never write into SourceMod's admin config files - just write your own storage and give people access directly.
__________________
asherkin is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 01-28-2014 , 20:31   Re: ReadFileLine help
Reply With Quote #7

Quote:
Originally Posted by asherkin View Post
You should never write into SourceMod's admin config files - just write your own storage and give people access directly.
Oops. I didn't look to see what file you were opening.
Marcus_Brown001 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-29-2014 , 07:21   Re: ReadFileLine help
Reply With Quote #8

I guess simple KV file of SQLite is better choice (depends on number of members).. And give player admin access via sm functions is peasy -> CreateAdmin -> AdminInheritGroup

EDIT: And one little thing, if player is already in "configs/admins_simple.ini", he has an admin access, so you can just test if player is admin or not.. (GetUserAdmin)

Last edited by KissLick; 01-29-2014 at 07:31.
KissLick is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 01-29-2014 , 08:40   Re: ReadFileLine help
Reply With Quote #9

I think im gonna keep how it is right now then. I need to develop more understanding to what all the "File" commands do.
__________________
SourcePawn Coding Level: Novice
DJ Data is offline
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 10:33.


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