Thread: {317}*Finally* Fully Working IPB Server Integration (IPB 3.1)

Results 1 to 10 of 10
  1. #1 {317}*Finally* Fully Working IPB Server Integration (IPB 3.1) 
    Registered Member
    Join Date
    Aug 2010
    Posts
    56
    Thanks given
    6
    Thanks received
    11
    Rep Power
    1
    That's right, the search for IPB server integration is over! I was tooling around with Martin's vbulletin code and was able to update it to work 100% with IPB 3.1.2. Keep in mind 98% of this code is by Martin, I just updated it to work with the latest version of IPB. Now, for those of you who don't know what integration between your forums and server is, it's allowing people to log onto your server using the same username and password as the forums. This code will also prevent people from registering an account at the login screen forcing new members to register on your forums. In order for this to work you must have IPB 3.1 or higher currently installed on your host/server. Invisionfree or any other free forum software will not work for this. If you have IPB 3.1 then you obviously know your way around a MySQL database so this should be fairly simple.

    NOTE: If your database is hosted in a different place other than where your server is hosted you need to make sure you are allowing external connections to the database.

    NOTE: Like I said before this is originally for vBulletin by Martin so do not be alarmed if parts of the code and file names say vBulletin

    Step 1:
    Open server.java and add this:
    Code:
    public static vBulletin vb = new vBulletin("databasehost","database","username","password",vBulletin.Type.IPB);
    Make sure you substitute databasehost, database, username, and password with the MySQL database details.

    Step 2:
    Create a new file called vBullletin.java
    Code:
    /**
     * vBulletin class
     * @author Mad Turnip
     */
    
    import java.sql.*;
    
    public class vBulletin implements Runnable {
    	
    	
    	private Connection connection = null;
    	private Statement statement = null;
    	private static Thread thread = null;
    	
    	public enum Type {
    		myBB,
    		SMF,
    		IPB,
    		vBulletin,
    		phpBB,
    	}
    
    	private String[] tableNames = new String[6];
    	private void setTables(){
    		if(forum == Type.myBB){
    			tableNames = new String[] {"mybb_users","username","password","salt","usergroupid",};
    		} else if(forum == Type.SMF){
    			tableNames = new String[] {" smf_members","memberName","passwd","passwordSalt","ID_GROUP",};
    		} else if(forum == Type.IPB){
    			tableNames = new String[] {"members","members_display_name","members_pass_hash","members_pass_salt","member_group_id",};
    		} else if(forum == Type.vBulletin){//vbulletin
    			tableNames = new String[] {"user","username","password","salt","usergroupid",};
    		} else if(forum == Type.phpBB){//phpBB
    			tableNames = new String[] {"users","username","user_password","user_password","group_id",};
    		}
    	}
    	
    	public vBulletin(String url,String database,String username,String password,Type t){
    		this.hostAddress = "jdbc:mysql://"+url+"/"+database;
    		this.username = username;
    		this.password = password;
    		this.forum = t;
    		try {
    			//connect();
    			thread = new Thread(this);
    			thread.start();
    		} catch(Exception e){
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	
    	private final String hostAddress;
    	private final String username;
    	private final String password;
    	private final Type forum;
    	
    	private void connect(){
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    		} catch(Exception e2){
    			System.out.println("Cannot find mySql Driver.");
    			return;
    		}
    		try {
    			connection = DriverManager.getConnection(hostAddress, username,password);
    			statement = connection.createStatement();
    		} catch(Exception e){
    			System.out.println("Connetion rejected, Wrong username or password, or ip is banned, or host is down.");
    			connection = null;
    			e.printStackTrace();
    		}
    	}
    	private void ping(){
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[2]+" LIKE 'null312'";
    			results = statement.executeQuery(query);
    		} catch(Exception e){
    			connection = null;
    			connect();
    			e.printStackTrace();
    		}
    	}
    	
    	public void run(){
    		boolean allowRun = true;
    		while(allowRun){
    			try {
    				if(connection == null) {
    					setTables();
    					connect();
    				} else {
    					ping();
    				}
    				thread.sleep(10000);
    			} catch(Exception e){
    			}
    		}
    	}
    	/**
    	 * returns 2 integers, the return code and the usergroup of the player
    	 */
    	
    	public int[] checkUser(String name,String password){
    		int i = 0;
    		int[] returnCodes = {0,0};//return code for client, group id
    
    		try{
    			ResultSet results = null;
    			String query = "SELECT * FROM "+tableNames[0]+" WHERE "+tableNames[1]+" LIKE '"+name+"'";
    			try {
    			if(statement == null)
    				statement = connection.createStatement();
    			} catch(Exception e5){
    				statement = null;
    				connection = null;
    				connect();
    				statement = connection.createStatement();
    			}
    			results = statement.executeQuery(query);
    			if(results.next()){
    				String salt = results.getString(tableNames[3]);
    				String pass = results.getString(tableNames[2]);
    				int group = results.getInt(tableNames[4]);
    				returnCodes[1] = group;
    				String pass2 = "";
    				if(forum == Type.myBB){
    					pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
    				} else if(forum == Type.vBulletin){
    					pass2 = MD5.MD5(password);
    					pass2 = MD5.MD5(pass2+salt);
    				} else if(forum == Type.SMF){
    					pass2 = MD5.SHA((name.toLowerCase())+password);
    				} else if(forum == Type.phpBB){
    					pass2 = MD5.MD5(password);
    				} else if(forum == Type.IPB){
    					pass2 = MD5.MD5(MD5.MD5(salt)+MD5.MD5(password));
    				}
    				if(pass.equals(pass2)){
    					returnCodes[0] = 2;
    					return returnCodes;
    				} else {
    					returnCodes[0] = 3;
    					return returnCodes;
    				}
    			} else {
    				//no user exists
    				returnCodes[0] = 12;
    				return returnCodes;
    			}
    		} catch(Exception e){
    			statement = null;
    			returnCodes[0] = 8;
    			return returnCodes;
    		}
    	}
    }
    Step 3:
    Create a new file called MD5.java
    Code:
    import java.io.UnsupportedEncodingException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    
    public class MD5 {
    	private static String convertToHex(byte[] data) {
            StringBuffer buf = new StringBuffer();
            for (int i = 0; i < data.length; i++) {
            	int halfbyte = (data[i] >>> 4) & 0x0F;
            	int two_halfs = 0;
            	do {
    	        	if ((0 <= halfbyte) && (halfbyte <= 9))
    	                buf.append((char) ('0' + halfbyte));
    	            else
    	            	buf.append((char) ('a' + (halfbyte - 10)));
    	        	halfbyte = data[i] & 0x0F;
            	} while(two_halfs++ < 1);
            }
            return buf.toString();
        }
    	
    	public static String SHA(String text) 
    	throws NoSuchAlgorithmException, UnsupportedEncodingException  {
    		MessageDigest md;
    		md = MessageDigest.getInstance("SHA");
    		byte[] md5hash = new byte[32];
    		md.update(text.getBytes("iso-8859-1"), 0, text.length());
    		md5hash = md.digest();
    		return convertToHex(md5hash);
    	}
    	
    	public static String MD5(String text) 
    	throws NoSuchAlgorithmException, UnsupportedEncodingException  {
    		MessageDigest md;
    		md = MessageDigest.getInstance("MD5");
    		byte[] md5hash = new byte[32];
    		md.update(text.getBytes("iso-8859-1"), 0, text.length());
    		md5hash = md.digest();
    		return convertToHex(md5hash);
    	}
    	
    }
    Step 4:
    Now that we are connected to the database we need to check their password and username on login
    Open client.java
    Find:
    Code:
    int loadgame = loadgame(playerName, playerPass);
    Keep in mind this may be different depending on your server.

    Add this underneath:

    Code:
    			if(loadgame == 2 || loadgame == 0){
    				int[] returnCodes = server.vb.checkUser(playerName,playerPass);
    				int usergroupId = returnCodes[1];
    				//below is an example of using usergroups
    				switch(usergroupId){
    					case 4://admin
    						playerRights = 3;
    					break;
    					//case 6://gmod
    						//playerRights = 2;
    					//break;
    					//case 7://mod
    						//playerRights = 1;
    					//break;
    					//case 3://member
    						//playerRights = 0;
    					//break;
    				}
    				returnCode = returnCodes[0];
    				if(returnCode != 2){
    					disconnected = true;
    				} else
    					loadgame = 0;
    			}
    This will make sure the username and password matches the forum credentials. Now that everything is working you can do even more with the integration. In the above code you can see:
    Code:
    					case 4://admin
    						playerRights = 3;
    					break;
    This code is saying that while the system is checking the username and password, it is also fetching that member's group ID. This can be very helpful if you want to make them an admin on your forums and then not have to manually change their playerRights.

    Log into your IP.Board Admin and go to Manage User Groups


    Look at the id of the group after its name. As you can see in mine, my admins group is id:4
    Replace the 4 in case 4 with your admin group ID and you can even specify how many rights they get (mod = 1, admin = 2, owner = 3)
    You may also want to add your mods, member group, and donator group.

    Also, don't forget your MySQL Drivers:
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    (add these with you server files)

    Wow! That's a mouthful, but this is the simplest way I could make it. I'm not an expert, but I will do my best to answer your questions

    Credits: 98% Martin, 2% me (I just had to update the tables that were being called form the database)

    You can view the original thread for smf/vB and more: [Only registered and activated users can see links. ]
     

  2. Thankful user:


  3. #2  
    Registered Member TMC07's Avatar
    Join Date
    Jul 2009
    Posts
    80
    Thanks given
    6
    Thanks received
    4
    Rep Power
    1
    epic.
     

  4. #3  
    Registered Member
    jordan641's Avatar
    Join Date
    Apr 2010
    Posts
    1,809
    Thanks given
    70
    Thanks received
    128
    Rep Power
    189
    =o very nice I might use this for my server rep+
     

  5. #4  
    Registered Member
    Ninja assassin's Avatar
    Join Date
    Oct 2008
    Posts
    1,961
    Thanks given
    217
    Thanks received
    115
    Rep Power
    77
    Looks good for Vbulletin Otherwise already released [Only registered and activated users can see links. ]
    Btc: 1tpWTbAznzWYh6YpoUJeQ3MDVK56GGJ
     

  6. #5  
    Registered Member
    Join Date
    Aug 2010
    Posts
    56
    Thanks given
    6
    Thanks received
    11
    Rep Power
    1
    yea I know, I included the link at the end of the code, but this is for IPB 3.1 which is the latest version of IPB and I have yet to see one that's compatible with 3.1
     

  7. #6  
    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
    Quote Originally Posted by FinalRevolution View Post
    yea I know, I included the link at the end of the code, but this is for IPB 3.1 which is the latest version of IPB and I have yet to see one that's compatible with 3.1
    what's the difference? the ipb updates are only patch updates not major database structure changing updates..
     

  8. #7  
    Registered Member
    Join Date
    May 2008
    Age
    27
    Posts
    538
    Thanks given
    117
    Thanks received
    42
    Rep Power
    12
    great job smf now please

     

  9. #8  
    Registered Member
    Join Date
    Aug 2010
    Posts
    56
    Thanks given
    6
    Thanks received
    11
    Rep Power
    1
    Quote Originally Posted by Sub View Post
    what's the difference? the ipb updates are only patch updates not major database structure changing updates..
    I can assure you that there were in fact very large differences from IPB 2.3 to 3.1 considering it was completely different software. The tables were affected, but it was not difficult to adjust it.
    [Only registered and activated users can see links. ]
     

  10. #9  
    Registered Member
    Join Date
    Oct 2010
    Posts
    136
    Thanks given
    2
    Thanks received
    8
    Rep Power
    6
    because it takes more then 3 mins to edit the code to work for the new ipb, o ye
    edit:
    Quote Originally Posted by FinalRevolution View Post
    I can assure you that there were in fact very large differences from IPB 2.3 to 3.1 considering it was completely different software. The tables were affected, but it was not difficult to adjust it.
    i can assure you that your full of shit as there isn't that many differences as i've tested both and noticed that there is nothing drastically different. why the fuck are you wasting time
     

  11. #10  
    Registered Member Phiction's Avatar
    Join Date
    Dec 2006
    Age
    28
    Posts
    253
    Thanks given
    13
    Thanks received
    2
    Rep Power
    31
    Removed
    [Only registered and activated users can see links. ]
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. [Php]Fully working Highscore & Server side SQL Engine.
    By blackaddiction in forum Tutorials
    Replies: 51
    Last Post: 12-15-2011, 05:07 PM
  2. Replies: 1
    Last Post: 09-21-2010, 01:12 AM
  3. Fully working [Server Only] Report Abuse
    By Blair' in forum Snippets
    Replies: 9
    Last Post: 03-22-2010, 10:30 PM
  4. Fully Working Server Pets
    By HyreScape in forum Tutorials
    Replies: 103
    Last Post: 06-06-2008, 07:37 AM
  5. Replies: 2
    Last Post: 03-11-2008, 10:35 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •