Jump to content
Sign in to follow this  
Daedalus

[PI] Users login - MySQL method

Recommended Posts

Hey,

Well I have been working on this a couple of days now (though I could have got it completed in under a day, just y'know work, work more work @ real life...)

I was going to work on making it full on SQL, but had decided to make it only store certain information with on the database, for if I did decide to store all on the database, it could cause strain on the database itself handling the requests.
So we still use the character.TXT files for majority of the stuff.

Any case, here is the results.

1. First off be sure you have the [URL="http://up.ht/1mmfHA9"]mysql JAR file[/URL], it is needed (stating the obvious), and an actual MySQL database server.

2. Be sure to include mysql.jar both in compiler and server runner BAT files (I won't go into detail about this, if you know what your doing then you should already understand. I won't do all the leg work ;) )

3. Find [B]PlayerSave.java[/B] and remove it from the directory (We won't be needing it).

4. Download [URL="http://up.ht/1mmkrWs"]PlayerLoaderSQL.java[/URL], save file under server/util/sql (Create new folders if needed)

5. Next we need to remove the old variables for the old PlayerSave.java which is located within these files;
Server.java
Client.java
PlayerHandler.java
PlayerSaving.java
RS2LoginProtocolDecoder.java
ShutDownHook.java

6. Find on each of the files listed above
[code]
import server.model.players.PlayerSave;
[/code]
And replace with
[code]
import server.util.sql.PlayerLoaderSQL;
[/code]


7. Find on all except RS2LoginProtocolDecoder.java:
[code]
PlayerSave.saveGame(c);[/code]
And replace with
[code]
PlayerLoaderSQL.save_Player(c);[/code]


8. Now open RS2LoginProtocolDecoder.java
Find:
[code]
load = PlayerSave.loadGame(cl, cl.playerName, cl.playerPass);[/code]
And replace with
[code]
PlayerLoaderSQL.getConnection();
load = PlayerLoaderSQL.load_Player(cl, name, pass);
PlayerLoaderSQL.destroyConnection();

[/code]

9. Download [URL="http://up.ht/1p4fNYJ"]this SQL file[/URL] and execute it on the database you have chosen.

10. Compile & Run


11. Login server offline notify (Optional)

Underneath [B]PlayerLoaderSQL.load_Player(cl,name,pass)[/B] you will find something similar to this (or should find);
[code]
if (returnCode == 2) {
switch (load) {
case 3:
returnCode = 3;
cl.saveFile = false;
break;

default:
for (int i = 0; i < cl.playerEquipment.length; i++) {
if(cl.playerEquipment[i] == 0) {
cl.playerEquipment[i] = -1;
cl.playerEquipmentN[i] = 0;
}
}
if (!PlayerHandler.newPlayerClient(cl)) {
returnCode = 7;
cl.saveFile = false;
} else
cl.saveFile = true;
break;
}
}
[/code]
Underneath [B]case 3: [/B]add
[code]

case 8:
returnCode = 8;
cl.saveFile = false;
break;
[/code]
This should return an error stating the login server is offline.


[B]What's the benefit towards this?[/B]
It will stop those who decide to spam log in on your server (at least to my knowledge correct me if I am wrong besides from sql injection), it will give you and your users more freedom on your website should they choose to register or not and being able to do more than with what most basic donation features are (donate, contact admin to receive donation in-game etc).

[B]What's the down side towards this?[/B]
Should your SQL database go down for what ever reason, no one won't be able to login, though there is a simple patch to this which I won't go into.
Also, if your database isn't that secure enough (IE weak password to database) then you could be suseptible to those that could easily manipulate the database.

[B]Required files in total;[/B]
[URL="http://up.ht/1p4fNYJ"]SQL File
[/URL][URL="http://up.ht/1mmkrWs"]PlayerLoaderSQL.java
[/URL][URL="http://up.ht/1mmfHA9"]mysql JAR file[/URL][URL="http://up.ht/1p4fNYJ"]
[/URL]


Let me know if I missed anything :L half asleep been up for nearly 24 hours :x

P.S. Hope I posted in the right area :L Edited by Daedalus

Share this post


Link to post
Share on other sites
Yes, you put it in the right area :), also thank you for the contribution! I like seeing stuff like this :). It will help out many.

Share this post


Link to post
Share on other sites
could someone link me to a newer tutorial like this or update this one please "op"...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×