Thread: [Hyperion] SMF integration.

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 48
  1. #1 [Hyperion] SMF integration. 
    WutWut
    Guest
    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.
    Reply With Quote  
     

  2. #2  
    Sub
    Sub is offline
    sυввч

    Sub's Avatar
    Join Date
    Aug 2007
    Age
    21
    Posts
    4,325
    Thanks given
    1,082
    Thanks received
    346
    Discord
    View profile
    Rep Power
    2755
    clever boy.
    Reply With Quote  
     

  3. #3  
    WutWut
    Guest
    Thanks Sub
    Reply With Quote  
     

  4. #4  
    Yumil
    Guest
    Works or not?
    Reply With Quote  
     

  5. #5  
    Registered Member laxmaster213's Avatar
    Join Date
    Feb 2008
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    1
    ousosmart
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Jan 2007
    Age
    27
    Posts
    4,417
    Thanks given
    3
    Thanks received
    105
    Rep Power
    0
    Nice, simple, and good, just how I like it.
    Hopefully it works though..
    Reply With Quote  
     

  7. #7  
    Donator

    Ecstasy's Avatar
    Join Date
    Sep 2008
    Age
    26
    Posts
    5,032
    Thanks given
    324
    Thanks received
    596
    Rep Power
    843
    Looks good, very simple. Alot simpler than mine

    Reply With Quote  
     

  8. #8  
    WutWut
    Guest
    I have tested it 100 times over, as long as your host isn't ridiculously slow, it works amazing.
    If you guys want me to port it for any other bases, or anything just tell me.
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    May 2008
    Posts
    140
    Thanks given
    39
    Thanks received
    13
    Rep Power
    176
    So this will work if your MySQL host doesn't allow external connections?
    Reply With Quote  
     

  10. #10  
    WutWut
    Guest
    Yes it will, because you're not accessing it externally
    Reply With Quote  
     

Page 1 of 5 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •