Jump to content
  • Advertisement
Sign in to follow this  
X5-Programmer

Handle Network Login Request.

This topic is 5406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been working on an login system for my game. I have think me something like this -> client's fill in his "username" "password", then client send it to the server and the server will check if the user exist in an file/database and if it does it sends back an request message to the client that says he can continue and receve the clients character data. How whold you do this? How to check if its an existed user? Feel free to come with ideas. thx.

Share this post


Link to post
Share on other sites
Advertisement

int r = prepare_sql( "select * from registered_characters where name=$name and password=$password" );
bind_sql( r, "name", userName );
bind_sql( r, "password", encryptedPassword );
int q = exec_sql( r );
if( sql_row_count( q ) != 1 ) {
// user does not exist with this password
}
else {
// user exists with this password
}


The specifics of prepare_sql(), bind_sql(), exec_sql() and sql_row_count() vary based on what database you're using -- look it up in the manual. (I recommend sqlite because it's very small, and free, and comes with source!)

Share this post


Link to post
Share on other sites
hplus0603:

Thanks for your replay and explanation on read from sql databases, But does it not exist any easyer ways? like when an new user logs in it make an clinetloginname.txt file that hold his data? is not that faster to read/write to and so on.. I dont know exactly what way I shold go.

Share this post


Link to post
Share on other sites
It should be absolutely trivial to program a client-server logon system, if you're planning on writing an online game.

Therefore I suggest you just use the same database system as you're storing all your other player data.

Mark

Share this post


Link to post
Share on other sites
You can use text files but using SQL give you a nice way to make quires and do lots of data manipulations, very easily.

Making a clinetname.txt for every client is none too good an idea.It might be easier to manage sql tables rows if you want to hold temp data.

Writing a data management system takes a bit of time so using sql might take a bit of the load off.I never really thought of using SQL in network programs but it's a good idea.

You could even use a combination of PHP and SQL to manage your databases.

Might be more fun to do that knocking up a C++ database management sytem.But if your dtb needs are small it might be better to go for making your own dtb manager especially if your are fimiliar with use file i/o more that SQL ;)

Share this post


Link to post
Share on other sites
From that question, it's un-clear to me whether you're asking how to store the login name on the CLIENT or on the server. What is it, exactly, that you need help with? An algorithm that takes what as input, and does what to it, running on what machine?

Share this post


Link to post
Share on other sites
Its entirely possible that it'll be faster to read a row from a SQL database than it will be to open a text file and parse it. Firstly, under the windows NT kernel, opening a file takes a relatively long time, whereas if the SQL server is on the same machine, you just need to open a socket/pipe. Secondly, if you have a large test file (a lot of user details), you may need to parse the whole file to get the information you need. An SQL database could be faster doing a SELECT query than your app parsing a text file.

Share this post


Link to post
Share on other sites
If you do use SQL make sure you "cleanse" the username and password to prevent malicious code; otherwise, people can send in data that embeds SQL code in your call.

Share this post


Link to post
Share on other sites
@LostLogic: that's why I suggested using prepared SQL statements with data binding, as you can't get any meta-character insert problems if you do that (and it's faster, to boot!)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!