Author Topic: Account system ! (Based on mission mod)  (Read 3644 times)

0 Members and 1 Guest are viewing this topic.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Account system ! (Based on mission mod)
« on: June 18, 2010, 11:01:07 am »
So i have this 2 part !

part 1 (save)
Code: [Select]
//
// Account related Functions(save)
//
function Save(ID: byte; Name,Pass,Action: string): boolean;
begin

    if Action = 'new' then
    begin
        if(REQUIREDLEVEL > 0) then
        begin
            DrawText(ID,'Level '+ inttostr(REQUIREDLEVEL) +' Required' + br + 'Yours: ' + inttostr(soldier[ID].level),200,RGB(255,255,255),0.2,20,250);
            exit;
        end;
        Reset(ID);
        soldier[ID].name := Name;
        soldier[ID].pass := Pass;

    end;
   
     
    if WriteFile('accounts/'+Name+'.ini',
      '[ACCOUNT]'+chr(13)+chr(10)+
      'Pass='+Pass+chr(13)+chr(10)+
     
      '[STATS]'+chr(13)+chr(10)+
      'Level='+IntToStr(soldier[ID].level)+chr(13)+chr(10)+
      'XP='+FloatToStr(soldier[ID].xp)+chr(13)+chr(10)+
      'SPEC='+IntToStr(soldier[ID].spec)+chr(13)+chr(10)
     
      ) then
    begin
        if(Action = 'logout') then
        begin
            Reset(ID);
            command('/setteam5 ' + inttostr(ID));
        end
        else if(Action = 'quit') then
        begin
            Reset(ID);
        end
        else if(Action = 'new') then
        begin
            command('/setteam1 ' + inttostr(ID));
            setWeaponSpec(ID, soldier[ID].spec);
        end
        else
        begin
            setWeaponSpec(ID, soldier[ID].spec);
        end;
        Result := true;

    end
    else
    begin
        Result := false;
    end;
end;
part 2 (load)

Code: [Select]
/ Account related Functions(load)
//
function Load(ID: byte; Name,Pass: string): string;
var
    file,rPass: String;
begin
file := ReadFile('accounts/'+Name+'.ini');
if file <> '' then
    begin
        rPass := copy(file,StrPos('Pass=',file)+5,32);
        if rPass = MD5String(Pass) then
        begin
            if soldier[ID].name <> '' then Save(ID,soldier[ID].name,soldier[ID].Pass,''); // Saving current account
            Reset(ID);

            soldier[ID].name := Name;
            soldier[ID].pass := rPass;
            try
                soldier[ID].level := StrToInt(copy(file,StrPos('Level=',file)+6,StrPos('XP=',file)-StrPos('Level=',file)-8));
                if(soldier[ID].level >= 16) then
                begin
                    GiveBonus(ID,3);
                end;
            except
                soldier[ID].level := 1;
            end;

            try
                soldier[ID].xp := StrToFloat(copy(file,StrPos('XP=',file)+3,StrPos('SPEC=',file)-StrPos('XP=',file)-5));
            except
                soldier[ID].xp := 0;
            end;
            try
                soldier[ID].spec := StrToInt(copy(file,StrPos('SPEC=',file)+5,1));
            except
                soldier[ID].spec := BASICSOLDIER;
            end;
            setWeaponSpec(ID, soldier[ID].spec);
            MaxXP(ID);
            if(soldier[ID].level < REQUIREDLEVEL) then
            begin
                DrawText(ID,'Level '+ inttostr(REQUIREDLEVEL) +' Required' + br + 'Yours: ' + inttostr(soldier[ID].level),200,RGB(255,255,255),0.2,20,250);
                Result := 'Not High enough level: ' + inttostr(soldier[ID].level);
                reset(ID);
                exit;

            end;
            Result := 'Logged in ('+Name+') with level: ' + inttostr(soldier[ID].level);
            command('/setteam1 ' + inttostr(ID));
            setWeaponSpec(ID, soldier[ID].spec);
        end
        else
        begin
            Result := 'Invalid password (try again)';
        end;
    end
    else
    begin
        Result := 'Error reading file, please try again';
    end;
end;
I want to save the money of player by account system !

Do this will write the money in a ini folder ?
 
Code: [Select]
if WriteFile('accounts/'+Name+'.ini',
'[ACCOUNT]'+chr(13)+chr(10)+
'Pass='+Pass+chr(13)+chr(10)+
     
'[STATS]'+chr(13)+chr(10)+
'Money='+inttostr(money[ID])+chr(13)+chr(10))

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #1 on: June 18, 2010, 11:19:39 am »
You have to use XSplit..

Do like this:

Code: (pascal) [Select]
Procedure SaveAccount(ID: Byte);
 Var S, AccountFile: String;
  Begin
   AccountFile := 'scripts/'+ScriptName+'/Accounts/'+Player[ID].Name+'.ini';
    if FileExists(AccountFile) Then begin
     S := Chr(13)+Chr(10);
    WriteFile(AccountFile,'[Account]'+S+Player[ID].Password+S+Money[ID]);
   end else WriteConsole(ID,'Account doesnt exists',$FFFFFF);
 end;

Procedure LoadAccount(ID: Byte; Username, Pass: String);
 Var TempAcc: Array of String; AccountFile: String;
  Begin
   AccountFile := 'scripts/'+ScriptName+'/Accounts/'+UserName+'.ini';
    if FileExists(AccountFile) Then Begin
     TempAcc := XSplit(ReadFile(AccountFile),Chr(13)+Chr(10));
Try
     TempAcc[1] := Player[ID].Password;
    TempAcc[2] := StrToInt(Money[ID]);
Except
   WriteConsole(ID,'Error ocurred!',$FFFFFF);
  end;
 end;
end;
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod) help please !
« Reply #2 on: June 18, 2010, 12:26:59 pm »
Thanks  :D
but ....  :-\
i place these to procedure in my shop script !
but do i need to declare it somewhere ?
« Last Edit: June 18, 2010, 12:29:18 pm by mich1103 »

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #3 on: June 18, 2010, 03:27:14 pm »
What? Didn't understand.. :O
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #4 on: June 18, 2010, 03:57:11 pm »
i place these two procedure on my shop script ?
and what i do after ?

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #5 on: June 18, 2010, 04:03:38 pm »
You have to place XSplit before the two procedures, and just go like this:

Code: (pascal) [Select]
Function OnPlayerCommand(ID: Byte; Text: String): Boolean;
 Begin
  if GetPiece(Text,' ',0) = '/login' Then
   LoadAccount(GetPiece(Text,' ',1),GetPiece(Text,' ',2));
end;

//This is simplified, but you get the idea :)
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #6 on: June 18, 2010, 06:09:29 pm »
after place it on this order !
1-xsplit
2-save
3-load
i declare save on leave game ?
and with command /save ?

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #7 on: June 19, 2010, 06:50:36 am »
Code: (pascal) [Select]
Function OnPlayerCommand(ID: Byte; Text: String): Boolean;
 Begin
 if Text = '/save' Then SaveAccount(ID);
end;

Procedure OnLeaveGame(ID, Team: Byte; Kicked: Boolean);
 Begin
  SaveAccount(ID);
 ResetStats(ID); //You should have this, I'd say.
end;
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #8 on: June 19, 2010, 06:53:57 am »
why reset stat ?

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #9 on: June 19, 2010, 07:00:51 am »
To reset the hell out of every info.

Code: (pascal) [Select]
Procedure ResetStats(ID: Byte; LoggedIN: Boolean); //LoggedIN should determine if he stays logged in. True = yes..
 Begin
  Player[ID].Name := '';
   Player[ID].Password := '';
   Player[ID].Level := 0;
  Player[ID].Money := 0;
 Player[ID].Logged := LoggedIN;
end;
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #10 on: June 19, 2010, 09:44:01 am »
Dont understand more ...
what mean :   

Player[ID].Level := 0; 
Player[ID].Logged := LoggedIN;   
??? ??? ??? ??? ???

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #11 on: June 19, 2010, 10:11:37 am »
It was just some examples..

I don't know what are the variables inside "Player" so..

Change them yourself.
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #12 on: June 19, 2010, 06:22:28 pm »
Ok thanks ! :D
but why you reset stat after saving ?  :-\
We also forgot the create account part ...  :-\
« Last Edit: June 19, 2010, 06:24:50 pm by mich1103 »

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #13 on: June 19, 2010, 06:49:03 pm »
but why you reset stat after saving ?  :-\

I don't know. I usually do. Because it's on LeaveGame, perhaps?

Quote
We also forgot the create account part ...  :-\

I'm sure you can handle it. If not, ask here :)
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #14 on: June 19, 2010, 06:57:32 pm »
something like that ?
Code: [Select]
procedure CreateAccount(ID: byte);
begin
AccountFile := 'scripts/'+ScriptName+'/Accounts/'+Player[ID].Name+'.ini'; 
ifFileExists(AccountFile) Then begin
  S := Chr(13)+Chr(10); 
   WriteFile(AccountFile,'[Account]'+S+Player[ID].Password+S+Money[ID]); 
  endelse WriteConsole(ID,'Error while creating account !',$FFFFFF);   
 end;
end;

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #15 on: June 19, 2010, 07:26:36 pm »
You forgot one thing.

Code: (pascal) [Select]
Procedure CreateAccount(ID: Byte; UserName, Pass: String); //Have to use "UserName/Pass", otherwise it will save Username and pass as "".
 Var AccountFile, S: String; //Declare the vars..
  Begin
   AccountFile := 'scripts/'+ScriptName+'/Accounts/'+UserName+'.ini';
    if NOT FileExists(AccountFile) Then Begin //Check if the account name DOESNT exists..
     S := Chr(13)+Chr(10);
     WriteFile(AccountFile,'[Account]'+S+Player[ID].Password+S+IntToStr(Money[ID])); //IntToStr().. You forgot it :P
 end else WriteConsole(ID,'Error! Account already exists!',$FFFFFF);
end;
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #16 on: June 20, 2010, 07:12:05 am »
And for the command ''/create username password''
i do that ?
Code: [Select]
Function OnPlayerCommand(ID: Byte; Text: String): Boolean; 
Begin 
ifGetPiece(Text,' ',0) = '/create'Then
CreateAccount(GetPiece(Text,' ',1),GetPiece(Text,' ',2)); 
end;
« Last Edit: June 20, 2010, 07:15:35 am by mich1103 »

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #17 on: June 20, 2010, 08:55:23 am »
And for the command ''/create username password''
i do that ?
Code: [Select]
Function OnPlayerCommand(ID: Byte; Text: String): Boolean; 
Begin 
ifGetPiece(Text,' ',0) = '/create'Then
CreateAccount(GetPiece(Text,' ',1),GetPiece(Text,' ',2)); 
end;

Shouldn't work, because you forgot one parameter (ID).

Do you remember? CreateAccount(ID: Byte; UserName, Password: String); :)

This should work.

Code: (pascal) [Select]
Function OnPlayerCommand(ID: Byte; Text: String): Boolean;
 Var TempName, TempPass: String;
  Begin
   Text := LowerCase(Text);
    if GetPiece(Text,' ',0) = '/create' Then if GetPiece(Text,' ',2) <> Nil Then Begin //It's quite important to have this, otherwise it could return errors.
    TempName := GetPiece(Text,' ',1);
   TempPass := GetPiece(Text,' ',2);
  CreateAccount(ID,TempName,TempPass);
 end;
end;
www.soldatx.com.br - The brazilian Soldat community.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Account system ! (Based on mission mod)
« Reply #18 on: June 20, 2010, 09:10:02 am »
Ahhh  :-\
i forgot the Variable and (ID) ...
Anyway ! Thanks  :D
do we forget another part ?

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Account system ! (Based on mission mod)
« Reply #19 on: June 20, 2010, 09:12:56 am »
You tell me, it's your script :P
www.soldatx.com.br - The brazilian Soldat community.