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