EDIT: I ment to post this in the snippet section. If you don't know the very basic fundamentals of java, then I think there's no point in you being here.
EDIT EDIT: If your website goes offline, that will mean no one will be able to log on. To prevent this, make it check off a private table which is not related to your website.
I've made this a couple of days ago, for a person who paid me $40 for such an easy task.
I don't see why people should pay for integration, so here you go, this is what I wrote for that particular server.
Note: You might need to edit things here and there depending on the base you're using, HENCE that this is strictly for ipboard since other forum platforms use different ways of hashing/encrypting account details. I can alter this to work with your forum software if you don't know how to, for a small fee.
Essentially you can use this for any platform, if you change the encryption logic to the same method your software uses. Obviously you also need to change the columns it has to search for in your query
My first intention was to make an interface based library which you could edit settings on to pick between most common forum platforms, but in the end I think people should just read this code and be able to somewhat understand the concept instead of being spoonfed a library without understanding the logic operating behind it.
Currently this only reads the player details and the player rights which I've commented out since not everyone will have the same system as I do.
I understand that JDBC is a rather outdated method of validating forum users, but it really fits the use that is required.
I've also thought about having a webserver print out information with the JSON format, but I can imagine alot of things could be exploited with that system depending on how well you authenticate gameserver requests to the webserver.
Code:
package com.rs.game.sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.apache.commons.codec.digest.DigestUtils;
import com.rs.game.player.Player;
import com.rs.utils.Logger;
/**
* @author Arno | Articron
*/
public class ForumIntegration {
/* database_details */
private static final String database_location = "jdbc:mysql://WEBSITEIPHERE/DBNAMEHERE";
private static final String database_username = "USERNAME";
private static final String database_password = "PASSWORD";
/* connection vars */
private static Connection server_website_throttle;
private PreparedStatement prepared_statement;
private ResultSet result_printset;
/* player_details */
private String password;
private String password_md5;
private String salt_md5;
private int player_right;
/* Entry point for initiation */
public static void init() {
try {
Class.forName("com.mysql.jdbc.Driver");
server_website_throttle = DriverManager.getConnection(
database_location, database_username, database_password);
Logger.log("Forum Integration", "Hooked up correctly...");
} catch (Exception e) {
e.printStackTrace();
}
}
/* Object instance to check authentication */
public ForumIntegration(Player player_instance) {
this.password = player_instance.getPassword().toLowerCase();
try {
prepared_statement = server_website_throttle
.prepareStatement("SELECT * FROM ipbmembers WHERE name='"
+ player_instance.getUsername() + "'");
result_printset = prepared_statement.executeQuery();
/* if player exists in database */
if (result_printset.next()) {
password_md5 = result_printset.getString("members_pass_hash");
salt_md5 = result_printset.getString("members_pass_salt");
player_right = result_printset.getInt("member_group_id");
} else {
/* if player does not exist in forum database */
password_md5 = null;
salt_md5 = null;
}
addToStaffHash(player_right, player_instance);
} catch (Exception e) {
e.printStackTrace();
}
}
/* HashMap parsing */
private void addToStaffHash(int playerRights, Player player) {
switch (playerRights) {
case 7: // dev
case 4: // owner
case 8: // owner
// player.getStaff().put(player, 2);
break;
default: // regular
break;
}
}
/* authentication */
public boolean getValid() {
return (password_md5 == null || salt_md5 == null) ? false
: encryptToMD5(password, salt_md5).equalsIgnoreCase(
password_md5);
}
/* Apache Commons Codec DigestUtility lib */
private String encryptToMD5(String pass, String salt) {
return DigestUtils.md5Hex(DigestUtils.md5Hex(salt).concat(
DigestUtils.md5Hex(pass)));
}
}
Code:
if (!new ForumIntegration(player).getValid()) {
session.getLoginPackets().sendClientPacket(3);
return;
}
}
Libraries you will need:
Codec - Home
JDBC/UCP Download Page