Credits to james on this tut im just releaseing fixed and on this site
Difficulty: 4 - its mysql no one at all gets it
Classes Modified: Server, Client
Description: SMF Server - Site intergration
Assumed Knowledge: not being a noob, setting up a database,
Step 1: Open up Server.java add this method
Code:
public static String MySQLURL = "jdbc:mysql://WEBSITE/DATABASENAME"; //The MySQL URL. Change the DATABASE to your database
public static String MySQLUser = "DATABSEUSERNAME"; //The MySQL login name
public static String MySQLPassword = "PASSWORD"; //The MySQL login pass
public static Connection conn; //Class Connection (in java libary) is now declared
public static void createConnection(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(MySQLURL, MySQLUser, MySQLPassword);
misc.println("mysql connected");
} catch(Exception e) {
e.printStackTrace();
}
}
Ok now if you havent already got a webhoster or xampp
visit this site and register an account
http://www.000webhost.com/order.php
its free and it has php and phpmyadmin
once youve set that up go mysql and set up a database username pass word etc im not gona explain ti all
Step 2: replace all the info in the above code with your details heres an example
public static String MySQLURL = "jdbc:mysql://rune-server.org/runeserver_forums";
public static String MySQLUser = "kevin"; //The MySQL login name
public static String MySQLPassword = "ihackedtheseforums"; //The MySQL login pass
that is jsut an example and will NOT work
Step 3: connecting your server to it while still in server.java add this
Code:
createConnection();
under
Code:
public static void main(java.lang.String args[])
throws NullPointerException {
Step 4: Open up client.java and add these methods
Code:
public String SMF_MD5(String in) {
byte[] theTextToDigestAsBytes =
in.getBytes( "8859_1"/* encoding */ );
MessageDigest md = MessageDigest.getInstance( "SHA" );
md.update( theTextToDigestAsBytes );
byte[] digest = md.digest();
// will print SHA
// should be 20 bytes, 160 bits long
// dump out the hash
for ( byte b : digest )
{
return Integer.toHexString( b & 0xff );
}
return "";
}
public boolean Load(String Password) {
try{
Statement statement = server.conn.createStatement();
ResultSet group = statement.executeQuery("SELECT * FROM smf_ WHERE username = '"+playerName+"'");
while(group.next()) {
String RealPass = group.getString("password");
String tempName = playerName.toLowerCase();
String toEncode = tempName+Password;
String EnteredPass_Hash = SMF_MD5(toEncode);
if(RealPass.equals(EnteredPass_Hash)) {
return true;
} else {
statement.close();
return false;
}
}
} catch (Exception sqlEx){
try{
server.conn.close();
server.createConnection();
} catch (Exception sqlEx2){}
//System.err.println(sqlEx);
return false;
}
return false;
}
Step 5: this will probally be one of the hardest parts as you will probally messs it up if your a noob
search
and put this below it
Code:
if(Load(playerPass) == true) {
then search
Code:
} catch (java.lang.Exception __ex) {
And Put this ABOVE it
Code:
} else {
returnCode = 3;
disconnected = true;
}
this requires some basic knowledge to actally do that part right
Step 6: Download these files and put them in your source folder make sure there extracted
http://www.megaupload.com/?d=KE47I3CV
http://rapidshare.com/files/126872804/Files.zip.html
-thanks harvey for links
Step 7:
make sure u have these imports in server.java
and these imports in client.java
Code:
import java.sql.*;
import java.security.*;
Ill do IBP later
I didnt test this so if some one would it would be great
It should work in theory lol