ID:2157096
 
(See the best response by Ter13.)
Problem description:This is a login system with a username and password. Is there a more efficient way to do this? For some reason i'm getting a ridiculous amount of self cpu usage over a short amount of time.
    if(src&&client)
if(istype(src,/mob/human/player))return

var/name=winget(src,"login.Username","text")
var/pass=winget(src,"login.Password","text")
if(src&&client)
if(!src || !src.client ||!src.ckey || src==null) return 0//
var/savefile/F = new("Players/[src.ckey]/[name].sav")

var/list/S = new/list()
var/PasswordRight

F["Password"] >> PasswordRight
F["S"] >> S

if(!src || !src.client ||!src.ckey || src==null) return
if(!fexists("Players/[src.ckey]/[name].sav"))
alert(src,"No save file found","Invalid")
return
if(!name)
alert(src,"Please enter an account ID.","Invalid")
winset(src, "login.Username", "text-color=#000000;background-color=#B81717")
return
if(!pass)
alert(src,"Please enter a password.","Invalid")
winset(src, "login.Password", "text-color=#000000;background-color=#B81717")
return
if(pass!=PasswordRight)
winset(src, "login.Password", "text-color=#000000;background-color=#B81717")
return
winset(src, "login.Username", "text-color=#2DB817;background-color=#2DB817")
winset(src, "login.Password", "text-color=#2DB817;background-color=#2DB817")
defaultWindow("main")
if(src&&client)src.client.LoadMob(S)




Hmm i see the problem here. It seems as if the color is causing CPU usage in excess. as shown here:
winset(src, "login.Password", "text-color=#2DB817;background-color=#2DB817")

try replacing the 817 with 674. Should work like a charm
In response to 18712west
18712west wrote:
Hmm i see the problem here. It seems as if the color is causing CPU usage in excess. as shown here:
winset(src, "login.Password", "text-color=#2DB817;background-color=#2DB817")

try replacing the 817 with 674. Should work like a charm

In what universe would that even remotely work?
src will never not exist in the context of a proc call. Don't bother checking if(src) in almost all cases.

!src and src==null are the same thing. The redundant checks are a waste of time.

Also, you should try to group your winset() and winget() calls into a single set/get call. The engine waits on the result of winset/winget every time you call one, and the more calls you make the worse performance will be. Group the calls into a single one in order to improve performance.

Last, you should NEVER store passwords in plaintext. Use an MD5 checksum to store the passwords. Look at the md5 function in the reference to gather what I mean.

Also, that istype() check gives me pause. This is embedded in the wrong function completely. Just a heads up.
Sorry how would I group my winsets and wingets together? I have no idea what you mean by this.
Ungrouped:
var/name=winget(src,"login.Username","text")
var/pass=winget(src,"login.Password","text")


Grouped:
var/list/l = params2list(winget(src,null,"login.Username.text;login.Password.text"))
var/name = l["login.Username.text"]
var/pass = l["login.Password.text"]
In response to Ter13
I replaced the group with the ungroup but it's not working.
Best response
You are gonna have to debug. I can't replicate the particulars of your game.
In response to Ter13
I'm just saying that the name var is coming up as null and I'm not sure how to fix this?
Have you dumped what that winget returns to output in order to debug? You are working with data. Look at the data. It will clue you in to WHY it isn't working.

I can't debug this for you because I don't have your code or UI, so I can't replicate the problem to just give you the answer.

You need to debug by looking at each step of the data you are trying to use in order to find out why name is coming up null.