ID:264652
 
Code:
world/New()
..()
if(fexists("accounts.sav"))
var/savefile/f=new("accounts.sav")
f>>clients
var/list/clients=list()
client
var/savefile/path
proc
check_save()
if(!path)
path=new("clients/[ckey].sav")
save()
check_save()
if(mob.account)
path[mob.account]<<mob
load(var/v)
check_save()
if(v in path.dir)
path[v]>>mob
New()
..()
winshow(src,"login",1)
winshow(src,"register",0)
winshow(src,"buddylist",0)
winshow(src,"chat",0)
Del()
save()
..()
account
var/password
var/name
var/list/buddies
New(n, p)
if(n in clients)return
src.name=n
src.password=p
clients.Add(src.name=src.password)
mob
Write(var/savefile/F)
if(!clients.Find(src.account))
clients.Add(src.account)
var/savefile/f=new("accounts.sav")
f<<clients
..()
var/account/account
verb
login()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if(account_name in clients && clients[account_name]==account_password)
src.client.load(account_name)
src.account=clients.Find(account_name)
alert(src,"this worked")
register()
winset(src,"loginbutton","is-visible=false")
winset(src,"registerbutton","is-visible=false")
winset(src,"finishbutton","is-visible=true")
finish()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if(account_name in clients)return
account.New(src, account_name, account_password)
src.client.save()
winset(src,"loginbutton","is-visible=true")
winset(src,"registerbutton","is-visible=true")
winset(src,"finishbutton","is-visible=false")


Problem description:
Okay this is what I'm trying to do. When people login they use their username and password to enter. If they don't have one they hit register and make one. When accounts are made they are added to a list along with the password. Then they can login to this account without others being able to use the same username.

The problem I am having is, nothing seems to work. When registering when you hit the finish button nothing happens. I switched it up some and got it to at least change the buttons, but that wasn't really doing anything I needed it to so I switched it back. Then logining in also doesn't work it can't seem to find the clients list or something. I even hard coded some fake accounts with passwords and it still doesn't work.

I'm not sure what I am doing wrong. The way I am saving and loading the account is like so.

New account is created

Add new account to list so it would be like- clientslist(accountname=accountpassword)

Then load the account by checking if the account name is in the list and if it equals the password.

If so load the mob the account was used for. This loads their variables, and buddies.

I am not doing something right though. I just don't understand what.

You are supplying an object for the directory of a savefile (path[mob.account]). I don't actually know if this would work or not, because it's inherently silly. Use a text string instead.

You have similar issues confusing text and objects elsewhere. For example, you are searching clients for account_name, but clients only have /account objects and account_name is a text string.

You are also calling the New() proc directly. This should not be done and honestly should result in a compiler error. New() is automatically called by using the new() statement, and so is used for initializing new objects. Calling it otherwise defeats its purpose.
In response to Garthor (#1)
<s>If I gave the directory a text string how can I find the specific one to load if they have multiply accounts? If I did path["account"]<<mob wouldn't it override the previous account with the new one?</s>(Wasn't thinking clearly.) I fixed what you said, but I'm still not getting any expected results. I think that registering is working, because trying to make an account that already exist doesn't work. Though trying to login with that account doesn't bring up the "this worked" alert.

world/New()
..()
if(fexists("accounts.sav"))
var/savefile/f=new("accounts.sav")
f>>clients
var/list/clients=list()
client
var/savefile/path
proc
check_save()
if(!path)
path=new("clients/[ckey].sav")
save()
check_save()
if(mob.account)
path["account"]<<mob
load()
check_save()
path["account"]>>mob
New()
..()
winshow(src,"login",1)
winshow(src,"register",0)
winshow(src,"buddylist",0)
winshow(src,"chat",0)
Del()
save()
..()
account
var/password
var/name
var/list/buddies
New(mob/m, n, p)
if(n in clients)return
src.name=n
src.password=p
clients.Add(src.name=src.password)
m.account=src
mob
Write(var/savefile/F)
if(!clients.Find(src.account))
clients.Add(src.account)
var/savefile/f=new("accounts.sav")
f<<clients
..()
Read(var/savefile/F)
..()
var/account/account
verb
login()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if(account_name in clients && clients[account_name]==account_password)
src.client.load()
src.account=clients.Find(account_name)
alert(src,"this worked")
register()
winset(src,"loginbutton","is-visible=false")
winset(src,"registerbutton","is-visible=false")
winset(src,"finishbutton","is-visible=true")
finish()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if(account_name in clients)return
src.account=new(src, account_name, account_password)
src.client.save()
winset(src,"loginbutton","is-visible=true")
winset(src,"registerbutton","is-visible=true")
winset(src,"finishbutton","is-visible=false")
In response to Ultima Anime (#2)
Bump.
Okay, I actually have an output now so I received this runtime error after trying to create a new account.

runtime error: illegal use of list2args() or named parameters
proc name: New (/account/New)
usr: Ultima Anime (/mob)
src: hhh (/account)
call stack:
hhh (/account): New(Ultima Anime (/mob), "hhh", "hhh")
Ultima Anime (/mob): finish()

I also found a few conflicts in the code that I didn't change while switching things around. Changed the code to this and it got rid of the runtime, but still login doesn't do what I want it to.

After further testing, in the login code I checked the clients list for all the usernames and passwords. They are in there and are correct. For some reason they are in there multiple times, but that doesn't really have an effect on much. What confuses me is if they are in there, why can't my if statement find them?

world/New()
..()
if(fexists("accounts.sav"))
var/savefile/f=new("accounts.sav")
f>>clients
var/list/clients=list()
client
var/savefile/path
proc
check_save()
if(!path)
path=new("clients.sav")
save()
check_save()
if(mob.account)
path[mob.account.name]<<mob
load()
check_save()
path[mob.account.name]>>mob
New()
..()
winshow(src,"login",1)
winshow(src,"register",0)
winshow(src,"buddylist",0)
winshow(src,"chat",0)
Del()
save()
..()
account
var/password
var/name
var/list/buddies
New(mob/m, n, p)
if(n in clients)return
src.name=n
src.password=p
clients.Add(src.name)
clients[src.name]=src.password
m.account=src
mob
Write(var/savefile/F)
if(!clients.Find(src.account.name))
clients.Add(src.account.name)
clients[src.account.name]=src.account.password
var/savefile/f=new("accounts.sav")
f<<clients
..()
Read(var/savefile/F)
..()
var/account/account
verb
login()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if(account_name in clients && clients[account_name]==account_password)
src.client.load()
src.account=clients.Find(account_name)
alert(src,"this worked")
register()
winset(src,"loginbutton","is-visible=false")
winset(src,"registerbutton","is-visible=false")
winset(src,"finishbutton","is-visible=true")
finish()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if(account_name in clients)return
src.account=new(src, account_name, account_password)
src.client.save()
winset(src,"loginbutton","is-visible=true")
winset(src,"registerbutton","is-visible=true")
winset(src,"finishbutton","is-visible=false")
In response to Ultima Anime (#3)
>       login()
> var/account_name=winget(src,"loginusername","text")
> var/account_password=winget(src,"loginpassword","text")
> if(account_name in clients && clients[account_name]==account_password)
>
> src.account=clients.Find(account_name)//this
src.client.load()//this
> alert(src,"this worked")


Try switching those two lines. Otherwise you are loading a null account name. That probably won't fix your current problem, but it will fix a future one.
In response to Ultima Anime (#3)
// wrong
if(account_name in clients && clients[account_name]==account_password)

// right
if((account_name in clients) && clients[account_name]==account_password)


Why?
Because "in" has lower precedence than && and ||. And pretty much every other operator, I think. if(account_name in clients && clients[account_name]==account_password) is equivalent to if(account_name in (clients && clients[account_name]==account_password)), which is the same as if(account_name in (TRUE or FALSE)), which is wrong.
In response to Keeth (#5)
Okay, thanks this fixes that problem. Now I just have a ton of runtime errors. I think my saving system is wanky.

proc name: check save (/proc/check_save)
source file: Save System.dm,14
usr: Ultima Anime (/mob)
src: null
call stack:
check save()
load(Ultima Anime (/mob), "h")
Ultima Anime (/mob): login()
runtime error: bad savefile or list
proc name: load (/proc/load)
source file: Save System.dm,22
usr: Ultima Anime (/mob)
src: null
call stack:
load(Ultima Anime (/mob), "h")
Ultima Anime (/mob): login()
runtime error: Cannot modify null.account.
proc name: New (/account/New)
source file: Save System.dm,43
usr: null
src: /account (/account)
call stack:
/account (/account): New(null, null, null)
the mob (/mob): Read(clients.sav (/savefile))
load(Ultima Anime (/mob), "h")
Ultima Anime (/mob): login()

I've changed it around a lot and got to this point.

#define DEBUG

world/New()
..()
if(fexists("accounts.sav"))
var/savefile/f=new("accounts.sav")
f>>clients
var/list/clients=list()

var/savefile/path
proc
check_save()
if(!path)
path=new("clients.sav")//< Line 14
save(mob/m, n)
check_save()
if(n)
path[n]<<m
load(mob/m, n)
check_save()
if(n)
path[n]>>m//< Line 22
client
New()
..()
winshow(src,"login",1)
winshow(src,"register",0)
winshow(src,"buddylist",0)
winshow(src,"chat",0)
Del()
save(src.mob,src.mob.account.name)
..()
account
var/password
var/name
var/list/buddies
New(mob/m, n, p)
if(n in clients)return
src.name=n
src.password=p
clients.Add(src.name)
clients[src.name]=src.password
m.account=src
mob
Write(var/savefile/F)
var/savefile/f=new("accounts.sav")
f<<clients
..()
Read(var/savefile/F)
..()
var/account/account
verb
login()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if((account_name in clients)&& clients[account_name]==account_password)
src.account=new(src, account_name, account_password)
load(src, account_name)
alert(src,"this worked")
register()
winset(src,"loginbutton","is-visible=false")
winset(src,"registerbutton","is-visible=false")
winset(src,"finishbutton","is-visible=true")
finish()
var/account_name=winget(src,"loginusername","text")
var/account_password=winget(src,"loginpassword","text")
if(account_name in clients)return
src.account=new(src, account_name, account_password)
save(src, account_name)
winset(src,"loginbutton","is-visible=true")
winset(src,"registerbutton","is-visible=true")
winset(src,"finishbutton","is-visible=false")


I've made multiple modifications to the savefile directories, and other places in the code. Each modifiction just produces a different error. Bad index, can't read arg2list, and some more. I am deleting the accounts.sav, and clients.sav before each test.