Author Topic: acc system not working  (Read 1919 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
acc system not working
« on: August 25, 2011, 04:12:03 am »
/create works fine
but no matter what i do /login returns a FileExists = False

the thing is, the file im trying to log into DOES exist, i have checked it with PHP commander

making a case sensitive acc system i do not want lowercase

any ideas?

Code: (pascal) [Select]
if GetPiece(Text,' ',0) = '/create' then begin
    NewLogin(ID, GetPiece(Text,' ',1),GetPiece(Text,' ',2));
    AccName[ID]:= GetPiece(Text,' ',1);
  end;
 
  if GetPiece(Text,' ',0) = '/login' then begin
     afd :='Players/'+GetPiece(Text,' ',1)+'.txt';
     acd:= xsplit(readfile(afd),(chr(13)+chr(10)));
    if FileExists('Players/'+afd) = False then WriteConsole(ID,'This username does not exist or is incorrect, please try again',$EE81FAA1);
    if FileExists('Players/'+afd) then begin
      if GetPiece(Text,' ',2) <> acd[3] then WriteConsole(ID,'This password is incorrect, please try again',$EE81FAA1);
      if GetPiece(Text,' ',2) = acd[3] then begin
        Accname[ID]:= acd[2];
        WriteConsole(ID,'Login Successful, Welcome Back '+acd[2]+'!',$EE81FAA1);
        ExistingLogin(ID,acd[2]);
      end;
    end;
  end;
  end;

im still tidying this up but heres teh full code

http://pastebin.com/2WtEgaZ4
edit: also /char isnt working, i think that issue is tied with /login not working, but not sure, /char hasnt been changed and it used to work so idk

edit2: function SetRank isnt triggering either....ugh
« Last Edit: August 25, 2011, 04:22:12 am by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: acc system not working
« Reply #1 on: August 25, 2011, 07:27:33 am »
There exists code if FileExists('Players/'+afd) but afd is 'Players/'+GetPiece(Text,' ',1)+'.txt'. You have "Players/Players/...". I doubt this was intended.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: acc system not working
« Reply #2 on: August 25, 2011, 01:11:47 pm »
Oops, tx dorkeydear :-)

next problem, password in /login isnt being read properly by acd[3] after removing the 'Players/'+
/char still isnt working

i have attached an acc file, and i have also updated the linked pastebin

edit: anyone know whats causing the issue?

From: August 27, 2011, 01:10:05 am
or maybe im calling the array wrong

would array[0] be the first line of file?

From: August 27, 2011, 03:25:10 am
Bump!

not even changing the array numbers worked for /login

i changed FileExists acd[3] into acd[2]
changed the remaining Accname and Existinglogin acd[2] into acd[1]

wonder why the file isnt reading properly, or is the problem that its not splitting the file fast enough?
« Last Edit: August 27, 2011, 03:25:10 am by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: acc system not working
« Reply #3 on: August 27, 2011, 07:46:20 am »
For dynamic arrays, they are 0-index-based.

acd[3] should be '0', whereas acd[2] should be 'wtf'.

Note that your usernames and passwords are case sensitive.

Please do some debugging yourself. The process I use includes putting WriteLn`s throughout the known location of the issue to figure out the flow of what is being executed, and writing out what the actual value of a variable is, and comparing that against what I expect.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: acc system not working
« Reply #4 on: August 27, 2011, 07:26:10 pm »
well now i cant see why its skipping the writelns, im connected via ARSSE and these writelns arent showing

in game its getting to 'this password is incorrect', but the writelns arent showing on ARSSE

Code: (pascal) [Select]
if GetPiece(Text,' ',0) = '/login' then begin
     afd :='Players/'+GetPiece(Text,' ',1)+'.txt';
     acd:= xsplit(readfile(afd),(chr(13)+chr(10)));
    if FileExists(afd) = False then WriteConsole(ID,'This username does not exist or is incorrect, please try again',$EE81FAA1);
    if FileExists(afd) then begin
  Writeln(acd[2]);
  Writeln(acd[1]);
      if GetPiece(Text,' ',2) <> acd[2] then WriteConsole(ID,'This password is incorrect, please try again',$EE81FAA1);
      if GetPiece(Text,' ',2) = acd[2] then begin
        Accname[ID]:= acd[1];
        WriteConsole(ID,'Login Successful, Welcome Back '+acd[2]+'!',$EE81FAA1);
        ExistingLogin(ID,acd[1]);
      end;
    end;
  end;

i get this on ARSSE, then the last line is from another script, so why is it skipping to writelns but getting to the password error ingame?

how would i troubleshoot skipped lines?
Quote
(10:24:18) Frosty joining game (58.160.74.249:23073)
(10:24:18) Frosty has joined alpha team.
(10:24:30) /login woah wtf (58.160.74.249 [Frosty])
(10:24:34) 30 seconds has passed

From: August 27, 2011, 07:49:25 pm
strange, ive just changed the writelns to
Code: (pascal) [Select]
  Writeln(''+acd[2]+'!');
  Writeln(''+acd[1]+'!');

all im getting is ! in Arsse console, which means it isnt reading the file WTF

From: August 27, 2011, 07:50:31 pm
what do i do? if FileExists is true and its getting to password error then why isnt xsplit reading it properly? :S
« Last Edit: August 27, 2011, 07:50:31 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: acc system not working
« Reply #5 on: August 27, 2011, 08:54:59 pm »
Before going into the problem at hand, I want to provide a few pointers.

I personally like to put the command and it's parameters on the same line or near the line in which you test to see if the command that is used is the correct command; although tbh I don't follow through very much :P So I'm going to write a little comment there saying the command is in format /login < account name > < password >.

The old xsplit code is less efficient than the revised code, called Explode, which can be found in the topic Explode 2 - Function. If you use xsplit in many places in the script already, you can simply rename Explode to xsplit, and it should be fairly easy to replace the old code. Otherwise you may need to replace in all locations calling xsplit, replace that with Explode.

A minor suggestion is with your chr(13)+chr(10) code: Every time this part of the script is executed, it has to re-call the function chr twice. With such functions as these, and because of its application, it is probably not a big deal, but I figured I would mention it while I had it in mind anyways. I usually put a constant at the top of my script saying const CRLF = #13#10;.

For ease of access on your part, putting constants up top for colors makes it easy to change in many places a given color. const Color = $EE81FAA1. This way, if you feel as though you are getting sick of the color, you easily change it everywhere.

Variable names like afd and acd aren't very helpful at trying to figure out what they are and their meaning. I suggest renaming them to filename and file_contents respectively, or something that is a bit more helpful at understanding at first sight what it is.

It kind of makes sense to see if a file exists before trying to get the content. Also, if the file does not exist, there is something called an else statement, which can make it so we don't have to call FileExists multiple times.

Code: [Select]
if GetPiece(Text,' ',0) = '/login' then begin // /login < account name > < password >
  filename := 'Players/'+GetPiece(Text,' ',1)+'.txt';
  if FileExists(filename) then begin
    file_contents := Explode(ReadFile(filename), CRLF);
    if GetPiece(Text,' ',2) = file_contents[2] then begin
      Accname[ID]:= file_contents[1];
      WriteConsole(ID,'Login Successful, Welcome Back '+Accname[ID]+'!',Color);
      ExistingLogin(ID,file_contents[1]);
    end else
     WriteConsole(ID,'This password is incorrect, please try again',Color);
  end else begin
    WriteConsole(ID,'This username does not exist or is incorrect, please try again',Color);
  end;
end;
untested code


all im getting is ! in Arsse console, which means it isnt reading the file WTF
I'm a little confused on what the reasoning is for the issue without actually testing the code. You are not getting exceptions, meaning you did get an array of sufficient length, but they are filled with blanks... Are you using the acd variable previous to the /login command? Maybe you somehow got a bugged xsplit. Try to use Explode, and please share the results.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: acc system not working
« Reply #6 on: August 27, 2011, 10:57:06 pm »
ok i have replaced xsplit with explode, now heres the interesting part

afd and acd isnt used prior to /login except /char and in other procedures

the interesting bit is, when the command is typed

! is appearing before the command in arsse

Quote
(13:52:18) !
(13:52:19) !
(13:52:19) /login woah wtf (58.160.74.249 [Frosty])

Frostys OnPlayerCommand @ Pastebin

From: August 27, 2011, 10:59:02 pm
Yes it is defined as a global variable however it is used differently within each section, could it be the problem that its a global var?

btw i have addressed your suggestion using CRLF :=#10#13;
« Last Edit: August 27, 2011, 11:00:22 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: acc system not working
« Reply #7 on: August 28, 2011, 11:43:39 am »
Yes it is defined as a global variable however it is used differently within each section, could it be the problem that its a global var?
It is possible. Before doing acc_data := Explode(...);, do acc_data := [];. See if that helps.

Or alternatively, you can also declare the variables such that they are local to that function (event), OnPlayerCommand.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: acc system not working
« Reply #8 on: August 29, 2011, 02:45:40 am »
no luck on acc_data := []; before the acc_data:=

same with defining it locally to each function, keeps coming up blank on login

http://pastebin.com/2WtEgaZ4



From: August 30, 2011, 04:05:41 pm
Any ideas?
« Last Edit: August 30, 2011, 04:05:41 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: acc system not working
« Reply #9 on: September 04, 2011, 11:45:39 pm »
Can't do anything with my server until this is figured out, unless i revert to and improve over my old system using ini files. heh that sounds like an idea. I dont like using readfile based code too much. Guess ill just have to improvise like i've always done :-) 
check out my server! click here

If at first you don't succeed, Improvise! :D