Handle Network Login Request.

Started by
8 comments, last by hplus0603 19 years, 6 months ago
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.
-[ thx ]-
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!)

enum Bool { True, False, FileNotFound };
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.
-[ thx ]-
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
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 ;)
______________________________________________________________________________________________________
[AirBash.com]
FireNet:

I will give SQL an try and se if I get it to work ;)

thx all for your replys!.
-[ thx ]-
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?
enum Bool { True, False, FileNotFound };
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.
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.

LostLogicwww.GamerOutfit.comXBox 360 Community Games Reviews and NewsExisled - 2D/3D Shooter for XBox 360

@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!)
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement