This is for Graham and Blake's server, Hyperion
Well, I didn't have external access to my database to I found a way around it.
So I can integrate my SMF forum with my server.
So here I will be releasing the code!
Please backup before you do the tutorial.
JUST AND FYI BUT IF YOU GIVE ME HOW ANOTHER FORUMS HASHING WORKS I WOULD BE MORE THAN GLAD TO WRITE AN IMPLEMENTATION FOR OTHER FORUM SOFTWARES.
Step 1
Save this as auth.php and upload it to your site, after replacing database values of course.
Code:
<?php
$mysql = array(
'host' => 'HOST',
'name' => 'DBNAME',
'user' => 'DBUSER',
'pass' => 'DBPASS'
);
$conn = mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']) or die('noconnect');
mysql_select_db($mysql['name']);
$user = mysql_real_escape_string($_GET['user']);
$pass = mysql_real_escape_string($_GET['pass']);
$hash = sha1(strtolower($user) . $pass);
$query = "SELECT * from smf_members where member_name='$user' and passwd='$hash'";
$result = mysql_query($query) or die('no'. mysql_error());
$row=mysql_fetch_row($result);
echo $row ? "yes" : "no";
?>
Step 2
Search for the folllowing code in GenericWorldLoader.java
Code:
checkLogin(PlayerDetails pd) {
The replace the entire method with the following.
Code:
public LoginResult checkLogin(PlayerDetails pd) {
Player player = null;
int code = 2;
try {
URL url = new URL("http://YOURSITE/auth.php?user="+pd.getName() + "&pass="+pd.getPassword());
URLConnection connection = url.openConnection();
connection.addRequestProperty("Referer", "http://www.codewithus.net/");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = reader.readLine();
code = line.equalsIgnoreCase("yes") ? 2 : 3;
} catch (IOException e) {
code = 11;
}
if(code == 2) {
player = new Player(pd);
}
return new LoginResult(code, player);
}
Step 3
Save this as info.php and upload it to your site, after replacing database values of course.
Code:
<?php
$admin = ADMINGROUPID;
$mod = MODGROUPID;
$members = MEMBERSGROUPID;
$mysql = array(
'host' => 'DBHOST',
'name' => 'DBNAME',
'user' => 'DBUSER',
'pass' => 'DBPASS'
);
$conn = mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']) or die('noconnect');
mysql_select_db($mysql['name']);
$user = mysql_real_escape_string($_GET['user']);
$query = "SELECT * from smf_members where member_name='$user'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array( $result );
if($row['id_group'] == $admin) {
echo 'admin';
} else if($row['id_group'] == $mod) {
echo 'mod';
} else {
echo 'player';
}
if($row['id_group'] == $members) {
echo ' true';
} else {
echo ' false';
}
?>
Replace the values at the top with yours.
Step 4
Search for the folllowing code in GenericWorldLoader.java
Code:
savePlayer(Player player) {
The replace the entire method with the following.
Code:
public boolean savePlayer(Player player) {
try {
DataOutputStream os = new DataOutputStream(new GZIPOutputStream(
new FileOutputStream("data/savedGames/"
+ NameUtils.formatNameForProtocol(player.getName())
+ ".dat")));
os.writeShort(player.getLocation().getX());
os.writeShort(player.getLocation().getY());
os.writeByte(player.getLocation().getZ());
int[] look = player.getAppearance().getLook();
for (int i = 0; i < 13; i++) {
os.writeByte((byte) look[i]);
}
for (int i = 0; i < Equipment.SIZE; i++) {
Item item = player.getEquipment().getEquipment(i);
if (item == null) {
os.writeShort((short) -1);
} else {
os.writeShort((short) item.getId());
os.writeInt(item.getCount());
}
}
for (int i = 0; i < Skills.SKILL_COUNT; i++) {
os.writeByte((byte) player.getSkills().getLevel(i));
os.writeDouble(player.getSkills().getExperience(i));
}
os.flush();
os.close();
return true;
} catch (IOException ex) {
return false;
}
}
Step 5
Search for the folllowing code in GenericWorldLoader.java
Code:
loadPlayer(Player player) {
The replace the entire method with the following.
Code:
public boolean loadPlayer(Player player) {
try {
URL url = new URL("http://YOURSITE/info.php?user="
+ player.getName());
URLConnection connection = url.openConnection();
connection.addRequestProperty("Referer",
"http://www.codewithus.net/");
BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String line = reader.readLine();
String[] args = line.split(" ");
String rights = args[0];
String members = args[1];
System.out.println(rights);
if (rights.equalsIgnoreCase("admin")) {
player.setRights(Player.Rights.ADMINISTRATOR);
player.setMembers(true);
} else if (rights.equalsIgnoreCase("mod")) {
player.setRights(Player.Rights.MODERATOR);
player.setMembers(true);
} else {
player.setRights(Player.Rights.PLAYER);
player.setMembers(members.equalsIgnoreCase("true") ? true
: false);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
DataInputStream is = new DataInputStream(new GZIPInputStream(
new FileInputStream("data/savedGames/"
+ NameUtils.formatNameForProtocol(player.getName())
+ ".dat")));
player.setLocation(Location.create(is.readUnsignedShort(), is
.readUnsignedShort(), is.readUnsignedByte()));
int[] look = new int[13];
for (int i = 0; i < 13; i++) {
look[i] = is.readByte();
}
player.getAppearance().setLook(look);
for (int i = 0; i < Equipment.SIZE; i++) {
int id = is.readUnsignedShort();
if (id != 65535) {
int amt = is.readInt();
Item item = new Item(id, amt);
player.getEquipment().setEquipment(i, item);
}
}
for (int i = 0; i < Skills.SKILL_COUNT; i++) {
player.getSkills().setLevel(i, is.readByte());
player.getSkills().setExperience(i, is.readDouble());
}
return true;
} catch (IOException ex) {
return false;
}
}
Replacing YOURSITE with the site which you upload the auth.php and info.php to.
That's it, now your server is integrated with your forum, please do note this is half-assed and probably needs improvement.