Now Save & Exit Client.java and open Server.java and add this import at the top
Code:
import server.model.players.Account
Now you should have something like this a bit further down
Code:
System.out.println("Loading Server - 317.");
Below this add
Code:
Account.process();
if (Account.connected) {
System.out.println("Successfully Connected to MySQL Database!");
} else {
System.out.println("Failed to connect to MySQL Database!");
}
All this code does really is tells you if you are correctly connecting to the MySQL database or not. Now download [Only registered and activated users can see links. ] file and extract, then put the contents inside it into bin.server.model.players, it must be in the bin sub-directory not the src sub-directory. Now add this file and edit the MySQL Details. I have highlighted them in red
Code:
import java.sql.*;
import java.security.MessageDigest;
public class SQL {
public static Connection con = null;
public static Statement stmt;
public static boolean connectionMade;
public static void createConnection() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://mysqlhost/mysqldatabasename","mysqlusername","mysqlpassword");
stmt = con.createStatement();
} catch (Exception e) {
e.printStackTrace();
}
}
public static ResultSet query(String s) throws SQLException {
try {
if (s.toLowerCase().startsWith("select")) {
ResultSet rs = stmt.executeQuery(s);
return rs;
} else {
stmt.executeUpdate(s);
}
return null;
} catch (Exception e) {
destroyConnection();
createConnection();
e.printStackTrace();
}
return null;
}
public static void destroyConnection() {
try {
stmt.close();
con.close();
connectionMade = false;
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean saveHighScore(client clientToSave) {
try {
query("DELETE FROM `users` WHERE playerName = '"+clientToSave.playerName+"';");
query("INSERT INTO `users` (`playerName`) VALUES ('"+clientToSave.playerName+"');
query("DELETE FROM `users` WHERE playerPassword = '"+clientToSave.playerPassword+"';");
query("INSERT INTO `users` (`playerPassword`) VALUES ('"+clientToSave.playerPassword+"');
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
OK, You might need to change the MySQL query because my player passwords are saved differently mostly because I I don't like the way they are currently saved in Project Insanity. Also, your Password's cannot be encrypted otherwise is confuses the system, I will post below on how to get rid of the encrpyion. Open PlayerSave.java and search for
Code:
case 1:
There might be a few, but its the character-password case, now replace it with this
Code:
case 1:
if (token.equals("character-password")) {
playerPass.equalsIgnoreCase(token2);
}
break;
CREDITS
Credits %100 to me for making the tutorial + I made it in Notepad
Also Credits to whom ever released the original HighScore's, I think his name is Zenock or something, mostly because I used some of his code Server Sided
Profanity is the one language all programmers know best.
If you say 'plz' because it's shorter than 'please', I'll say 'no' because it's shorter than 'yes'.
All right remember to do the Website side and also the Website side is not complete, you have to do some query's like if(!logged_in()) { header('Location: index.php'); exit(); on control panel.php, changeusername.php and changepass.php and also changepass.php and changeusername.php is not completed because I don't want to see all the noobs having it, but it's simple to add, and it's only for the Control Panel not the actual game, if I update I will most likely add it so it change's username/password in game.
EDIT: My server manager is still thinking about it
Profanity is the one language all programmers know best.
If you say 'plz' because it's shorter than 'please', I'll say 'no' because it's shorter than 'yes'.
I don't quite get what your trying to do here? The sql.java file is a mess to start with. You're calling from the class Account but you didn't give the source to the file.
Code:
Account.process();
if (Account.connected) {
System.out.println("Successfully Connected to MySQL Database!");
} else {
System.out.println("Failed to connect to MySQL Database!");
}
^This code is from my highscores tutorial, and with your SQL file listed it should be something like this:
Code:
SQL.createConnection();
if (SQL.connectionMade) {
System.out.println("Successfully Connected to MySQL Database!");
} else {
System.out.println("Failed to connect to MySQL Database!");
}