Raised This Month: $ Target: $400
 0% 

Need Opinion (Optimizing / File or Array)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 01-31-2009 , 18:14   Need Opinion (Optimizing / File or Array)
Reply With Quote #1

In a file, I have the line:
Code:
 hitman *p STEAM_ID_SOMETHING a b c d
This restricts the model "hitman" to "steam_id_something" and access flags "a b c d". I have this function to check it.
Code:
bool:CheckAccess(id,const Model[]) {     if(!is_user_connected(id))         return false         new pFile = fopen(g_ConfigDir,"r"),bool:FileFound = false,bool:HasAccess = false     if(!pFile)         return false         static Data[128],fModel[36],Access[36]     while(!feof(pFile))     {         fgets(pFile,Data,127);         strbreak(Data,fModel,35,Access,35);                 if(containi(Model,fModel) == -1)             continue                 if(containi(Access,"*P") != -1)             strbreak(Access,Data,1,Access,35);                 FileFound = true                 if(!Access[0])             break                 strbreak(Access,Access,35,Data,127);         if(containi(Access,"STEAM_") != -1)         {             new AuthID[36]             get_user_authid(id,AuthID,35);                         if(equali(Access,Data))             {                 HasAccess = true                 break             }         }         if(Data[0])         {             new Len = strlen(Data) / 2,iAccess             server_print("LEN: %d",Len);             for(new Count;Count < Len;Count++)             {                 strbreak(Data,Access,35,Data,127);                 iAccess = GetStringAccess(Access);                 if(iAccess & GetUserAccess(id))                 {                     HasAccess = true                     break                 }             }             if(HasAccess)                 break         }     }     fclose(pFile);         if(FileFound)         return HasAccess         return true }

But I'm super annoyed when I think I'm doing something wrong. The above function works. But I think it can be better, is there anything / other alternatives i can do, to accomplish this?

Also, since i'm using a file. Should I use ether a vault system, or dynamic arrays?
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
stupok
Veteran Member
Join Date: Feb 2006
Old 01-31-2009 , 20:47   Re: Need Opinion (Optimizing / File or Array)
Reply With Quote #2

I think this should do it:

(I haven't tested and didn't check for typos.)

You should write the file like this if you want to use my function:
Code:
hitman *p STEAM_ID_SOMETHING abcd
Code:
public CheckAccess(id, const model) {     if(!is_user_connected) return 0         new fh = fopen(FILE_NAME, "rt")         if(!fh) return 0         static szBuffer[256], szModel[32], szSomething[8], szAuth[32], szFlags[32]         static szPlayerAuth[32]     get_user_authid(id, szPlayerAuth, charsmax(szPlayerAuth))         while(!feof(fh))     {         fgets(fh, szBuffer, charsmax(szBuffer))         parse(szBuffer, szModel, charsmax(szModel), szSomething, charsmax(szSomething), szAuth, charsmax(szAuth), szFlags, charsmax(szFlags))                 if(equali(model, szModel) && (equali(szAuth, szPlayerAuth) || get_user_flags(id) & read_flags(szFlags)))         {             fclose(fh)             return 1         }     }         fclose(fh)     return 0 }
__________________
stupok is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 01-31-2009 , 22:37   Re: Need Opinion (Optimizing / File or Array)
Reply With Quote #3

Well one thing is. I'm not using AMXX flags. It's a custom access thing. So read_flags could not be used here.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 01-31-2009 , 23:57   Re: Need Opinion (Optimizing / File or Array)
Reply With Quote #4

Quote:
Originally Posted by Drak View Post
Well one thing is. I'm not using AMXX flags. It's a custom access thing. So read_flags could not be used here.
read_flags doesn't care about AMXX, it does what i says, converts the string into a bitflag. You can check it with your own values, use your own flags as you wish.

And I think the best way would be to read the file into a cellarray on mapload/command, and check it when needed.
__________________

Community / No support through PM
danielkza is offline
BOYSplayCS
BANNED
Join Date: Apr 2008
Location: Gainesville, FL
Old 01-31-2009 , 23:16   Re: Need Opinion (Optimizing / File or Array)
Reply With Quote #5

To answer your last question Drak, use a vault system.
BOYSplayCS 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 01:43.


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