Thread: [614] Players Online Displayed via Website

Results 1 to 6 of 6
  1. #1 [614] Players Online Displayed via Website 
    Registered Member
    Join Date
    Feb 2014
    Posts
    16
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Alright so lets begin

    Open the folder "util"
    Make a new file, call it PlayersOnline.java
    put this code inside of it
    Code:
    package dragonkk.rs2rsps.util;
    
    import dragonkk.rs2rsps.util.Misc;
    import java.sql.*;
    import dragonkk.rs2rsps.model.player.Player;
    import java.security.MessageDigest;
    import dragonkk.rs2rsps.model.World;
    import dragonkk.rs2rsps.net.codec.LoginDecoder;
    
    public class PlayersOnline {
    
    	public static Connection con = null;
    	public static Statement stm;
    
    	public static void createCon() {
    		try {
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    			con = DriverManager.getConnection("jdbc:mysql://HOST/MYSQL_SERVER_NAME", "username on database", "password on database");
    			stm = con.createStatement();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    	public static ResultSet query(String s) throws SQLException {
    		try {
    			if (s.toLowerCase().startsWith("select")) {
    				ResultSet rs = stm.executeQuery(s);
    				return rs;
    			} else {
    				stm.executeUpdate(s);
    			}
    			return null;
    		} catch (Exception e) {
    		//	Misc.println("MySQL Error:"+s);
    			e.printStackTrace();
    		}
    		return null;
    	}
    
    	public static void destroyCon() {
    		try {
    			stm.close();
    			con.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}	
    
    	public static boolean offline(LoginDecoder p) {
    		try {
    			query("DELETE FROM `online` WHERE id = 1;");
    
    		} catch (Exception e) {
    			e.printStackTrace();
    			return false;
    		}
    		return true;
    	}
    
    	public static boolean online(LoginDecoder p) {
    		try {
    			query("INSERT INTO `online` (id, currentlyonline) VALUES('1','"+World.getPlayers().size()+"');");
    			System.out.println("Worked");
    		} catch (Exception e) {
    			e.printStackTrace();
    			return false;
    		}
    		return true;
    	}
    }
    Go to world.java, under registerconnection, add this.
    Code:
    PlayersOnline.createCon();
    PlayersOnline.offline(p);
    PlayersOnline.online(p);
    PlayersOnline.destroyCon();
    under unregisterconnection, add this

    Code:
    PlayersOnline.createCon();
    PlayersOnline.offline(p);
    PlayersOnline.destroyCon();
    Now go to Cpanel, make a new database call it whatever you want. Make an account and add that account to the database. Then, import this MYSQL code into the database

    Code:
    CREATE TABLE `online` (
      `id` varchar(1) NOT NULL default '',
      `currentlyonline` int(4) default NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    Now go inside the playersonline.java file and search for this code

    Code:
    con = DriverManager.getConnection("jdbc:mysql://HOST/MYSQL_SERVER_NAME", "username on database", "password on database");
    edit this with your website host ip, mysql server name, mysql server username, and mysql server pw.

    now make a php file on your webhost called playersonline.php

    add this code to it
    Code:
    <?php
    
    // Make a MySQL Connection
    mysql_connect("DATABASESERVER", "DATABASEUSER", "DATABASEPASS") or die(mysql_error());
    mysql_select_db("DATABASENAME") or die(mysql_error());
    
    //Query
    $online = mysql_query("SELECT * FROM online  WHERE id = 1");
    
    //put the query result into a var
    $totalonline = mysql_fetch_array($online);
    
    //print the result
    echo "Total online: ".$totalonline['currentlyonline']."";
    
    ?>
    Next go to yourdomain.com/playersonline.php and your 614 server's playercount will be displayed on this page, you can use iframes to use that number in an html file. Later guys
    Reply With Quote  
     

  2. #2  
    The internet's reject
    Andy's Avatar
    Join Date
    Jun 2007
    Age
    33
    Posts
    4,371
    Thanks given
    148
    Thanks received
    1,522
    Rep Power
    3133
    Why are you constantly opening and destroying the connection? JBCD will poll and manage in the background anyway, so constantly reconnecting is pointless.

    Also

    Code:
    <?php
    
    // Make a MySQL Connection
    mysql_connect("DATABASESERVER", "DATABASEUSER", "DATABASEPASS") or die(mysql_error());
    mysql_select_db("DATABASENAME") or die(mysql_error());
    
    //Query
    $online = mysql_query("SELECT * FROM online  WHERE id = 1");
    
    //put the query result into a var
    $totalonline = mysql_fetch_array($online);
    
    //print the result
    echo "Total online: ".$totalonline['currentlyonline']."";
    
    ?>
    It is 2014, you should not be using mysql_query, it is deprecated.

    A simple alternative


    Code:
    // Fill in all the info we need to connect to the database.
    // This is the same info you need even if you're using the old mysql_ library.
    $host = 'localhost';
    $port = 3306; // This is the default port for MySQL
    $database = 'myDatabase';
    $username = 'myDatabaseUser';
    $password = 'myDatabaseUserPassword';
    
    // Construct the DSN, or "Data Source Name".  Really, it's just a fancy name
    // for a string that says what type of server we're connecting to, and how
    // to connect to it.  As long as the above is filled out, this line is all
    $dsn = "mysql:host=$host;port=$port;dbname=$database";
    
    // Connect!
    $db = new PDO($dsn, $username, $password);
    and querys are simple as shit

    Code:
    $statement = $db->prepare("SELECT * FROM online  WHERE id = 1");
    $statement->execute();
    
    while ($result = $statement->fetchObject()) {
        echo $result->totalonline;
        echo "<br />";
    }
    What am I watching now?

    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Mar 2010
    Posts
    2,218
    Thanks given
    170
    Thanks received
    262
    Rep Power
    0
    Gj but who still uses 614s? dkks 614 is the worse 614 ever written D:
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Dec 2012
    Posts
    2,999
    Thanks given
    894
    Thanks received
    921
    Rep Power
    2555
    Quote Originally Posted by Teek View Post
    Gj but who still uses 614s? dkks 614 is the worse 614 ever written D:
    You can easily change it in accordance to work with your own 614.
    Attached image
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Mar 2010
    Posts
    2,218
    Thanks given
    170
    Thanks received
    262
    Rep Power
    0
    Quote Originally Posted by Kaleem View Post
    You can easily change it in accordance to work with your own 614.
    Or you could just make your own framework or even change a server revision like 718 to 614...
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Feb 2013
    Posts
    4,409
    Thanks given
    59
    Thanks received
    478
    Rep Power
    138
    why would you use sql for this
    Reply With Quote  
     


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. [614] Players Online (For Website)
    By Tillian in forum Help
    Replies: 5
    Last Post: 05-03-2011, 04:09 PM
  2. Players online display on Website?!! HELP!~
    By Zᴀᴄʜ in forum Help
    Replies: 0
    Last Post: 12-29-2010, 12:50 AM
  3. Players Online!!! On Your Website
    By ZeRo' in forum Snippets
    Replies: 31
    Last Post: 04-19-2010, 05:54 PM
  4. Replies: 6
    Last Post: 09-07-2009, 10:32 PM
  5. Replies: 19
    Last Post: 06-08-2008, 09:36 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
  •