0 Members and 1 Guest are viewing this topic.
//// 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;
/ 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;
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))
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;
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 :)
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;
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;
but why you reset stat after saving ?
We also forgot the create account part ...
procedure CreateAccount(ID: byte);beginAccountFile := '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;
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;
Function OnPlayerCommand(ID: Byte; Text: String): Boolean; Begin ifGetPiece(Text,' ',0) = '/create'ThenCreateAccount(GetPiece(Text,' ',1),GetPiece(Text,' ',2)); end;
And for the command ''/create username password'' i do that ?Code: [Select]Function OnPlayerCommand(ID: Byte; Text: String): Boolean; Begin ifGetPiece(Text,' ',0) = '/create'ThenCreateAccount(GetPiece(Text,' ',1),GetPiece(Text,' ',2)); end;
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;