NOTE: I am aware that this has already been posted, You can view that thread here: [Only registered and activated users can see links. ] ; However I have re-written the code and fixed a few bugs, I thought it'd be something people may enjoy.
This will make it so users must register on your forum before they access your server; Users also have the ability to recover their account from your forums
Difficulty:1 Tested Base:Project Insanity; Should work with anything. Assumed knowledge:Copy and Pasting, Following Directions.
Step 1:
Get the PHP source file for some quick editing.
Code:
<?php
/***
** Author: Redefined
** Date: March 8th, 2012
** Usage: A module used to integrate a Runescape Server with vBulletin forums.
***/
$SQL_HOST = "";
$SQL_USERNAME = "";
$SQL_PASSWORD = "";
$DATABASE_NAME = "forum database";
$CRYPTION_ID = 3469138;
//Check if number is correct.
if($_GET['crypt'] != $CRYPTION_ID) {
echo '-1';
exit;
}
//Declare variables input.
$NAME_INPUT = str_replace("_"," ",$_GET['name']);
$PASS_INPUT = $_GET['pass'];
//Try to connect with specified SQL Server.
if([email protected]_connect($SQL_HOST, $SQL_USERNAME, $SQL_PASSWORD))
die("Error connecting to SQL Server - " . mysql_error());
//Select the specified SQL database.
if([email protected]_select_db($DATABASE_NAME))
die("Error selecting SQL Database - " . mysql_error());
//Query Selected SQL Database.
$SQL_QUERY = mysql_query("SELECT * FROM user WHERE ".$CALL_FROM." = '".$NAME_INPUT."'");
//Compare login information.
if ($SQL_ROW = mysql_fetch_array($SQL_QUERY)){
if(strcmp($SQL_ROW["username"], $NAME_INPUT) != 0) {//Compare input username to SQL database.
echo '0'; //Query denied(No user found).
} else {
$DATABASE_PASSWORD = md5(md5($PASS_INPUT).$SQL_ROW["salt"]);//Generate correct Password to compare with SQL Database.
if(strcmp($DATABASE_PASSWORD, $SQL_ROW["password"]) == 0) { //Determine if password is correct.
echo '2'; //Successful login.
} else {
echo '1'; //The input Password is incorrect.
}
}
} else {
echo '0'; //Query denied(Database declined query).
}
?>
Step 2:
Edit the following variables, Make sure $CRYPTION_ID is changed, this is your simple security.
Save PHP file as serverintegration.php and upload to vBulletin forum directory.
Step 3:
Navigate to src/server/util and create ForumIntegration.java with the code below
Code:
/***
** Author: Redefined
** Date: March 8th, 2012
** Usage: A module used to integrate a Runescape Server with vBulletin forums.
***/
package server.util;
import server.model.players.Client;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class ForumIntegration {
private static final int CRYPTION_ID = 3469138;
private static final String WEBSITE_DOMAIN = "http://EXAMPLE.COM/forum/";
public static int ProcessUser(Client client){
try {
String URL = WEBSITE_DOMAIN + "serverintegration.php?crypt=" + CRYPTION_ID + "&name="+client.playerName.toLowerCase().replace(" ","_")+"&pass="+client.playerPass;
HttpURLConnection CONNECTION_HANDLE = (HttpURLConnection) new URL(URL).openConnection();
BufferedReader OUTPUT_HANDLE = new BufferedReader(new InputStreamReader(CONNECTION_HANDLE.getInputStream()));
String OUTPUT_DATA = OUTPUT_HANDLE.readLine().trim();
try {
//Parse returned internet data.
int RETURN_CODE = Integer.parseInt(OUTPUT_DATA);
switch(RETURN_CODE){
case -1:
System.out.println("Wrong CRYPTION_ID.");
return 10;
case 1://Invalid Password.
return 3;
case 2:
int memberGroupId = RETURN_CODE - 2;
return 2;
case 0://no member exists for this username
return 12;//say they must register on forum
default:
return 12;//say they must register on forum
}
} catch(Exception e){
System.out.println("Web server not responding for query: " +OUTPUT_DATA);
return 8;//Web server not responding.
}
} catch(Exception e2){ }
System.out.println("Web server not responding for query: " +OUTPUT_DATA);
return 11;//website offline
}
}
Edit the following variables.
Code:
private static final int CRYPTION_ID = 3469138;
private static final String WEBSITE_DOMAIN = "http://EXAMPLE.COM/forum/";
Again; make sure CRYPTION_ID is changed, this is your simple security.
Step 4:
Open RS2LoginProtocolDecoder.java and search for:
Code:
if(returnCode == 2) {
int load = PlayerSave.loadGame(cl, cl.playerName, cl.playerPass);
Just above that, add the following code. This is to call the method during player login.
Code:
if (returnCode == 2)
returnCode = ForumIntegration.ProcessUser(cl);
Also, Make sure you import the Forum Integration class:
Code:
import server.util.ForumIntegration;
Step 5:
Open playerSave.java, Search:
Code:
if (token.equals("character-password")) {
Remove or comment the following code just below that.
Code:
return 3;
I hope this tutorial has helped you, enjoy it; Also, don't forget there are so many possibilitys with this type of integration, try for yourself and see what you can achieve.