Need help with adjusting code

 

Hi, I am trying to change this very simple code that protects my EA to include more than 1 account number or range of account numbers. Can someone please advise me on how to make this possible so the protection script includes more than 1 account or a range of accounts.


Thank you!


}
                                                                                                                                                                                                                                                                                                                                                                           
int start() {

int hard_accnt = XXXXXXX; //<-- type the user account here before compiling
int accnt = AccountNumber();

if (accnt != hard_accnt)
{
Alert ("You can not use this account (" + DoubleToStr(accnt,0) + ") with this program!");
return(0);
}

 

Create an array with all valid account numbers

Then loop through the array to check if the account number is allowed

Maybe better to do in init as I don't think that it would be necessary to check every tick 

 

Could you possibly provide me an example of what you mean by creating a loop through the array? I am not an advanced programmer and still unsure about many things.

How would the code look like on what you mean by a loop through the array! I'd appreciate your assistance and response GumRai (Keith), thank you!

 
rocktheworld:

Could you possibly provide me an example of what you mean by creating a loop through the array? I am not an advanced programmer and still unsure about many things.

How would the code look like on what you mean by a loop through the array! I'd appreciate your assistance and response GumRai (Keith), thank you!


Something like this

int OnInit()
  {
//---
   bool Allowed=false;
   int accnt = AccountNumber();
   int ValidAccounts[]={1231234,4561234,7891234,3941234,9241234};
   int arrsize=ArraySize(ValidAccounts);
   for (int x=0;x<arrsize;x++)
      {
      if(ValidAccounts[x]==accnt)
         {
         Allowed=true;
         Print("Account Number ",accnt," Allowed");
         break;
         }
      }
   if(!Allowed)
      {
      Print("Account Number ",accnt," Invalid");
      return(INIT_FAILED);
      }
//---
   return(INIT_SUCCEEDED);
  }

 Obviously, the array ValidAccounts will be initialised with allowed account numbers

 

thanx for the help, but I dont even know where to start with this and where to put it into my EA or how it interface with the original code mentioned in my first post.

I have no idea how to add this to my EA! Do I leave the other code as it is, do I remove it, do I change it and how?

 
rocktheworld:

thanx for the help, but I dont even know where to start with this and where to put it into my EA

Clue!

int OnInit()

 Sorry to be blunt, but if you are not able to understand this simple code, then I don't see that you will be capable of writing an EA that needs protection.

Read the code carefully and read about what you don't fully understand.

Ask specific questions and somebody will answer.

rocktheworld:

I have no idea how to add this to my EA! Do I leave the other code as it is, do I remove it, do I change it and how?

You don't use any of your other posted code.l

If the account number is not in the array, the EA will not initialise 

Reason: