Code:
player setClientCvar( "autologin" , "openscriptmenu login Jane Doe|pw1234" );
sets a variable (could be any name of your choice), which opens a menu called login
and passes username|password which can be caught in script via player waittill( "menuresponse" , menu , response );
and parsed afterwards
Code:
player setClientCvar( "username" , "Jane Doe" );
player setClientCvar( "password" , "pw1234" );
those variables (name of your choice) have a dummy variable at first,
but those will be reset after you parsed the menuresponse from above
those also will be displayed in your login-menu
and are also placeholders to save the username + password in a config later
Code:
player setClientCvar( "autoexec" , "vstr autologin" );
autoexec is a special command in CoD2 (maybe also later and earlier CoD's)
when a player connects to a server, this command will automatically be executed (hence the name)
so it calls vstr cvarname:
vstr transforms a string which is in cvarname into a config-command
and therefore will execute what is stored in autoexec, which is the menuresponse
and therefore the menuresponse is triggered in the frame the player connects to the server
You have to parse the menuresponse and save its data on the server (libcod, files)
after your player is logged in or registered, you have to set
what will later be saved in the autologin-cvar
Code:
player setClientCvar( "autologin" , "openscriptmenu " + player.username + "|" + player.password );
// maybe not needed, shuld already be set via menu, but it doesnt hurt to set them again
player setClientCvar( "username" , player.username );
player setClientCvar( "password" , player.password );
(im not 100% sure about this part anylonger)
Code:
player execClientCommand( "writeconfig save.cfg" );
Then you save/create/orverride a new config, which is stored on the clients pc (not the server),
when a client connects to the server, you have to let him execute the safe.cfg
either from within your login menu ( onOpen { exec safe.cfg } ) or via the well known execClientCommand() workaround
so the next time he connects, the autologin is set, and does its job on connect
if the player deletes this safe.cfg for some reason (reinstall, removed manual),
he has to manually type in its username/password again
so this is somewhat like cookies in a browser..
This is all I remember for now..
So this is what happens when a new user registers:
- connects to the server
- doesn't yet have a autoexec command in its config, nothing gets called
- you let the player execute his safe.cfg, which does not yet exists, nothing happens
- player registers himself, you safe the input on the server
- you set the autologin-cvar accordingly
- you create the safe.cfg
Now if the player connects again on the server:
- the autoexec variable is set and gets called
- it fires the vstr command that calls the openscriptmenu one
- now you get a menuresponse and can grab the login information and parse it
- login the player automatically
- (excute the safe.cfg, so autologin gets set if not already)