PDA

View Full Version : checking username



malyczolg
1st November 2013, 12:55
hello , i make account system
how to check if an account exists?

if(self.typedvalutelogin.size > 3)
{
if=openfile(self.typedvalutelogin+".iwd","read");
...
}

IzNoGoD
1st November 2013, 13:05
open it as read. if the fileheader is -1, file does not exist.
if the fileheader is different from -1, the file exists and you should close the file.

malyczolg
1st November 2013, 13:27
account created but i cant login msg: No such user
where is error ?



if(response == "create")
{
name= self.typedvalutelogin;
f = openfile("account/" + name + ".czolg", "write");
fprintln(f, self.typedvalutelogin);
fprintln(f, self.typedvalutepassword);
closefile(f);

self iprintlnbold("account created name : " + self.typedvalutelogin + " / password : "+ self.typedvalutepassword);
}

if(response == "login")
{
self.writelogin = 0;
self.writepassword = 0;

if(self.typedvalutelogin.size > 3)
{

if(self.typedvalutelogin=="")
{
self iprintlnbold("Please specify a name");
continue;
}

if(self.typedvalutepassword=="")
{
self iprintlnbold("Please specify a password");
continue;
}

f=openfile("account/" + self.typedvalutelogin + ".czolg","read");
if(f==-1)
{
self iprintlnbold("No such user");
continue;
}

freadln(f);
if(fgetarg(f,1)!=self.typedvalutepassword)
{
self iprintlnbold("Invalid password");
closefile(f);
continue;
}
}
else if(self.typedvalutelogin.size <= 3)
{
self iprintlnbold("atleast 3 letters");
}
}

randall
1st November 2013, 13:55
On localhost you can read files only from iwds.

malyczolg
1st November 2013, 13:59
randall thanks , i go test on dediced srv
@edit
this same on dediced srv
i cant login msg: No such user

need help

Tally
1st November 2013, 14:03
On localhost you can read files only from iwds.

Not true. you can read them from raw files on a local server.

The only real drawback with local servers is that you can only use the files functions at callback_startgametype and once only. If you try to rotate to the next map with a local server, the file functions will fail.

IzNoGoD
1st November 2013, 14:07
As you can see, macyl is doing this reading from the _menus.gsc file, depending on user input, which means it is after serverstart.

OP: use some more debugging, like printing the filename the script will use etc.

malyczolg
1st November 2013, 15:28
beta login.menu

malyczolg
1st November 2013, 15:47
this same help.


if(response == "create")
{
name= self.typedvalutelogin;
f = openfile("account/" + name + ".czolg", "write");
fprintln(f, self.typedvalutelogin);
fprintln(f, self.typedvalutepassword);
closefile(f);

self iprintlnbold("account created name : " + self.typedvalutelogin + " / password : "+ self.typedvalutepassword);
}

if(response == "login")
{
self.writelogin = 0;
self.writepassword = 0;

if(self.typedvalutelogin=="")
{
self iprintlnbold("Please specify a name");
continue;
}
else if(self.typedvalutepassword=="")
{
self iprintlnbold("Please specify a password");
continue;
}
else if(self.typedvalutelogin.size > 3)
{
f=openfile("account/" + self.typedvalutelogin + ".czolg","read");
if(fgetarg(f,0)!=self.typedvalutelogin)
{
self iprintlnbold("No such user");
continue;
}

freadln(f);
if(fgetarg(f,1)!=self.typedvalutepassword)
{
self iprintlnbold("Invalid password");
closefile(f);
continue;
}
}
else if(self.typedvalutelogin.size <= 3)
{
self iprintlnbold("atleast 3 letters");
}
}

IzNoGoD
1st November 2013, 15:53
is there actually a file created?

malyczolg
1st November 2013, 15:54
every time I check, so it is

test account:
scriptdata\account\dsadsa.czolg

dsadsa,dadsa,
Error : No such user

malyczolg
1st November 2013, 16:09
if(response == "create")
{
name = self.typedvalutelogin;
f = openfile("account/" + name + ".czolg", "write");
fprintln(f, self.typedvalutelogin);
fprintln(f, self.typedvalutepassword);
closefile(f);

self iprintlnbold("account created name : " + self.typedvalutelogin + " / password : "+ self.typedvalutepassword);
}

if(response == "login")
{
self.writelogin = 0;
self.writepassword = 0;

if(self.typedvalutelogin=="")
{
self iprintlnbold("Please specify a name");
continue;
}
else if(self.typedvalutepassword=="")
{
self iprintlnbold("Please specify a password");
continue;
}
else if(self.typedvalutelogin.size > 3)
{
f = openfile("account/" + self.typedvalutelogin + ".czolg","read");
if(fgetarg(f,0) != self.typedvalutelogin)
{
self iprintlnbold("bad login");
continue;
}

freadln(f);
if(fgetarg(f,1) != self.typedvalutepassword)
{
self iprintlnbold("bad password");
closefile(f);
continue;
}
}
else if(self.typedvalutelogin.size <= 3)
{
self iprintlnbold("atleast 3 letters");
}
}

how fix this error ?

randall
1st November 2013, 17:02
Print the value of "self.typedvalutelogin" -.- And what kind of extension .czolg? Do not try to create your own extension please. Maybe it also can be an error.

malyczolg
1st November 2013, 17:23
this same
help

IzNoGoD
1st November 2013, 17:44
does it create a file?

or isnt there any file?

malyczolg
1st November 2013, 17:46
mod create scriptdata files

Tally
1st November 2013, 18:07
The file is being created, but it can't read the format because it isn't text-based, and so is acting like the file doesn't exist. Use .txt for the format instead.

malyczolg
1st November 2013, 18:28
The file is being created, but it can't read the format because it isn't text-based, and so is acting like the file doesn't exist. Use .txt for the format instead.
edit and this same :


if(response == "login")
{
self.writelogin = 0;
self.writepassword = 0;

if(self.typedvalutelogin=="")
{
self iprintlnbold("Please specify a name");
continue;
}
else if(self.typedvalutepassword=="")
{
self iprintlnbold("Please specify a password");
continue;
}
else if(self.typedvalutelogin.size > 3)
{

file = openFile("account/" + self.typedvalutelogin + ".txt", "read");
if(file == -1)
{
self iprintlnbold("bad login");
continue;
}

//freadln(f);
if(fgetarg(file,1) != self.typedvalutepassword)
{
self iprintlnbold("bad password");
closefile(file);
continue;
}
}
else if(self.typedvalutelogin.size <= 3)
{
self iprintlnbold("atleast 3 letters");
}
}

Tally
1st November 2013, 18:39
Bad luck then. Looks like you are not ready to be doing file functions. Perhaps in a couple of years, once you've mastered how to script, you might be ready.

Why not try something else? I hear knitting is fun. Or, you could always try making models with matchsticks and glue.

malyczolg
1st November 2013, 18:41
can u tell me where is error ?

IzNoGoD
1st November 2013, 19:36
i still fail to see how you are actually debuggin this.

i see no iprintlns printing the filename its trying to write to.
i see no iprints whatsoever for debugging.

Are you sure you wanna fix this code or are you just wasting our time?

EvoloZz
1st November 2013, 19:38
Bad luck then. Looks like you are not ready to be doing file functions. Perhaps in a couple of years, once you've mastered how to script, you might be ready.

Why not try something else? I hear knitting is fun. Or, you could always try making models with matchsticks and glue.

Couple of years? LOL? I learned the basics in ½ year, and file reading/writing in few weeks.
In case that was sarcasm, its hard to detect like that...

malyczolg
2nd November 2013, 07:52
I found a bug, but I can not solve it.
creating account work .

why not read asd.txt?

create test account:


if(response == "create")
{
f=openfile("asd.txt", "write");
fprintln(f, self.pers["typedvalutelogin"]);
fprintln(f, self.pers["typedvalutepassword"]);
closefile(f);

self iprintlnbold("account created name : " + self.pers["typedvalutelogin"] + " / password : "+ self.pers["typedvalutepassword"]);
continue;
}



if(response == "login")
{
self.writelogin = 0;
self.writepassword = 0;

f=openfile("asd.txt","read");
freadln(f);
self.checklogin = int(fgetarg(f,0));
self.checkpassword = int(fgetarg(f,1));
closefile(f);

if(self.pers["typedvalutelogin"]=="")
{
self iprintlnbold("Please specify a name");
continue;
}
else if(self.pers["typedvalutepassword"]=="")
{
self iprintlnbold("Please specify a password");
continue;
}
else if(self.pers["typedvalutelogin"].size > 3)
{
self iprintlnbold(self.checklogin+" / "+self.checkpassword);

if(self.checklogin != self.pers["typedvalutelogin"])
{
self iprintlnbold("login niepasuje:"+self.checklogin+" / "+ self.pers["typedvalutelogin"]);
continue;
}

if(self.checkpassword != self.pers["typedvalutepassword"])
{
self iprintlnbold("haslo niepasuje:"+self.checkpassword+" / "+ self.pers["typedvalutepassword"]);
continue;
}

}
else if(self.pers["typedvalutelogin"].size <= 3)
{
self iprintlnbold("atleast 3 letters");
continue;
}
}

Ni3ls
2nd November 2013, 08:03
DEBUG WITH DEVELOPER 1. AND ADD IPRINTS AND POST THEM HERE

malyczolg
2nd November 2013, 08:11
no errors ;
on developer 1 / developer 2

randall
2nd November 2013, 08:55
You are totally unsuitable for scripting :(
At first:
What is checklogin?
Password contains only numbers? If no, why the hell you convert to integer the string?
Please use that frigging iPrintln() to print the values of the variables. We are not wizards who can read your minds.
And finally, write an acceptable script, because it's less than amateur.