this is a simple, easy to use script that will insert account info as players make them on an OPEN ACCOUNT setting in your ini, so there is no need to register on a website, they make their account at the game screen same.
pay attention to the MD5 part of the account setup, i am using the MySQL's hashing function, and there are alot more, and better, hashing functions available to you to use in MySQL, so keep that in mind.
also pay attention to my use of STRMATCH to look for bad words in the queries, i do this so would be scripting hackers dont try to inject ur database through the game somehow, its always best to sanitize user input, even in game.
first u need to set up a table in MySQL, the one i used:
Code:
name: acc_info
fields:
id int(11)
username varchar(40) Unique Index
pword varchar(40)
firstip varchar(16)
lastip varchar(16)
plevel int(11)
email varchar(254) // per RanXerox - varchar(254)
dpoints int(11)
vpoints int(11)
be sure you have the correct username and password in your ini file for your MySQL database, otherwise this will all be useless
the below function can be found in sphere_serv_triggers.scp:
Code:
[FUNCTION f_onaccount_login]
// add this to the function
if ((STRMATCH(*insert*, <ARGS>)) || (STRMATCH(*select*, <ARGS>)) || (STRMATCH(*update*, <ARGS>)) || (STRMATCH(*execute*, <ARGS>)) || (STRMATCH(*delete*, <ARGS>)) || (STRMATCH(*drop*, <ARGS>)))
// first we make sure they arent trying to inject us
return 1 // if so, they dont need to log in
serv.log Use of special MySQL word detected // log the attempt
else // otherwise, lets input their account
db.connect
db.query SELECT username FROM acc_info WHERE username LIKE '<ARGS>'
if <db.row.numrows> == 0
db.execute INSERT INTO acc_info VALUES('','<ARGS>',md5('<serv.account.<ARGS>.PASSWORD>'),'<serv.account.<ARGS>.lastip>','<serv.account.<ARGS>.lastip>','<serv.account.<ARGS>.plevel>',NULL,'0','0')
else
db.execute UPDATE acc_info SET lastip = '<serv.account.<ARGS>.lastip>' WHERE username LIKE '<ARGS>'
endif
db.close
endif
below is an event to be placed on all players thru your ini file (it can go on any events, however it must be a global events on all players.)
Code:
[EVENTS e_allplayers]
on=@login
//----------------------------
// check for registered email
//----------------------------
db.connect
db.query SELECT email FROM acc_info WHERE username LIKE '<account.name>'
if (<isempty <db.row.0.email>>)
dialog d_addemail
endif
db.close
below is the dialog that is called for the email request (the display can be changed, the function for the button must stay the same):
Code:
[DIALOG d_addemail]
50,50
NOCLOSE
NOMOVE
NODISPOSE
page 0
resizepic 63 55 9200 397 158
resizepic 68 62 3500 388 119
dtext 112 76 0 Enter An Email Address To Attach To This Account
dtext 139 93 0 So That You Can Use Website Functions
button 342 183 5204 5205 1 0 1
dtext 94 124 2484 this email will not be used for any purposes other than
dtext 126 140 2484 to send account information and validation
resizepic 91 179 2620 232 33
dtextentry 98 186 221 19 99 0 Enter Your Email Address
[DIALOG d_addemail button]
ON=0
ON=1
if ((STRMATCH(*insert*, <ARGTXT[0]>)) || (STRMATCH(*select*, <ARGTXT[0]>)) || (STRMATCH(*update*, <ARGTXT[0]>)) || (STRMATCH(*execute*, <ARGTXT[0]>)) || (STRMATCH(*delete*, <ARGTXT[0]>)) || (STRMATCH(*drop*, <ARGTXT[0]>)))
// first we make sure they arent trying to inject us
return 1 // if so, they dont need to add an email
serv.log Use of special MySQL word detected // log the attempt
else // otherwise, lets input their email
db.connect
db.execute UPDATE acc_info SET email = '<ARGTXT[0]>' WHERE username LIKE '<src.account.name>'
db.close
endif
if u guys find any bugs, or by all means make it smaller and/or easier, or better in any way, feel free to post and let me know.