Quote from Adam on April 24, 2022, 3:38 pm~Bootstrap Highscores~
Built from scratch with Bootstrap and Bootswatch themes.============
Update 6/26/15:
- Added crowns based on player rights (check incl/Settings.php) - Screenshot
- Replaced crappy smooth scrolling with different one, performs much better
- Improved player stats (See screenshot)Update 4/17/15:
- Fixed an issue with mismatching tables. Should have no problem setting it up now ^-^
- Added a new php class for database queries
- Updated statements to use parameterized PDO
- Updated thread with more accurate tutorial
============Download: https://www.dropbox.com/s/ku6uonnfhx...newhs.zip?dl=0
[Sep 27, 2018] Updated download linkMD5 Checksum: 4870D8E50FCDEDDE7913790D95E9AD04
SHA1 Checksum: 4DB7ACA5C7F366F98580AA8DB1BCAC1BC082D8D0If you've received these files from someone else, please verify they have not been tampered with by checking the zip file beforehand by going here:
http://onlinemd5.com/Features:
- Pagination (Multiple pages)
- Search & Compare
- 100% Safe from XSS, Injections, etc.
- Fully Responsive (looks great on mobile devices)
- 10+ Different themes included
- PDO statements for better security
Alrighty, first thing is first, setup your highscores database (You can call it whatever you like, but remember we'll need it later). Below is the SQL query you're going to run on this database (If you already have an existing database with this structure, then you can skip this part):
Code:CREATE TABLE IF NOT EXISTS `hs_users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `rights` int(1) NOT NULL DEFAULT '0', `overall_xp` bigint(20) NOT NULL, `attack_xp` int(11) NOT NULL, `defence_xp` int(11) NOT NULL, `strength_xp` int(11) NOT NULL, `constitution_xp` int(11) NOT NULL, `ranged_xp` int(11) NOT NULL, `prayer_xp` int(11) NOT NULL, `magic_xp` int(11) NOT NULL, `cooking_xp` int(11) NOT NULL, `woodcutting_xp` int(11) NOT NULL, `fletching_xp` int(11) NOT NULL, `fishing_xp` int(11) NOT NULL, `firemaking_xp` int(11) NOT NULL, `crafting_xp` int(11) NOT NULL, `smithing_xp` int(11) NOT NULL, `mining_xp` int(11) NOT NULL, `herblore_xp` int(11) NOT NULL, `agility_xp` int(11) NOT NULL, `thieving_xp` int(11) NOT NULL, `slayer_xp` int(11) NOT NULL, `farming_xp` int(11) NOT NULL, `runecrafting_xp` int(11) NOT NULL, `hunter_xp` int(11) NOT NULL, `construction_xp` int(11) NOT NULL, `summoning_xp` int(11) NOT NULL, `dungeoneering_xp` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=0;
Now then, download and unzip the archive, you should now have a 'newhs' folder. Upload this to your webhost. If your website is not premium, its most likely that it does not support RemoteSQL and you will NOT be able to continue. First you'll need to import the tables using phpMyAdmin. After that's done, you can then edit the script.
Open this folder and navigate to incl/Settings.php and you should see this:
Code:#edit database info here $db = new Database("localhost", "user", "pass", "database", "hs_users"); $db->connect();
You'll need to edit what is in red with your database settings. To test if its working, insert a new entry into the database and you should see it displayed on the page. I can not help much with server side as alot of servers handle SQL alot differently. I do have a few classes however you can use if your server does not have sql at all.
First thing you'll need is the MySQL library which can be found here:
https://dev.mysql.com/downloads/connector/j/Make sure you import the jar into your project in eclipse, or edit bat files accordingly if necessary. Next you'll need a class to handle the connection and queries. You do not need to edit anything in this class since it is instanced to allow multiple connections simultaneously.
Change packaging ofc..if jar is imported correctly you souldn't have problems with the imports.
Code:package com.foxtrot.game.cores.mysql; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Database { private Connection conn; private Statement stmt; // do not modify private String host; private String user; private String pass; private String database; public Database(String host, String user, String pass, String data) { this.host = host; this.user = user; this.pass = pass; this.database = data; } public Connection getConnection() { return conn; } public Statement getStatement() { return stmt; } public boolean init() { try { this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass); return true; } catch (SQLException e) { return false; } } public PreparedStatement prepare(String query) throws SQLException { return conn.prepareStatement(query); } public int executeUpdate(String query) { try { this.stmt = this.conn.createStatement(1005, 1008); int results = stmt.executeUpdate(query); return results; } catch (SQLException ex) { ex.printStackTrace(); } return -1; } public ResultSet executeQuery(String query) { try { this.stmt = this.conn.createStatement(1005, 1008); ResultSet results = stmt.executeQuery(query); return results; } catch (SQLException ex) { ex.printStackTrace(); } return null; } public void destroyAll() { try { conn.close(); conn = null; if (stmt != null) { stmt.close(); stmt = null; } } catch(Exception e) { e.printStackTrace(); } } }
And now you'll need the highscores class for generating the queries and submitting them to the database. This will take a little bit of editing due to different imports and packing, but there shouldn't be too much to edit.
Code:package com.foxtrot.game.cores.mysql.impl; import java.sql.PreparedStatement; import com.foxtrot.Settings; import com.foxtrot.game.cores.mysql.Database; import com.foxtrot.game.player.Player; import com.foxtrot.utils.Utils; public class Highscores implements Runnable { private Player player; public Highscores(Player player) { this.player = player; } @Override public void run() { try { Database db = new Database("host", "username", "password", "database"); String name = Utils.formatString(player.getUsername()); if (!db.init()) { System.err.println("Failing to update "+name+" highscores. Database could not connect."); return; } PreparedStatement stmt1 = db.prepare("DELETE FROM hs_users WHERE username=?"); stmt1.setString(1, name); stmt1.execute(); PreparedStatement stmt2 = db.prepare(generateQuery()); stmt2.setString(1, name); stmt2.setInt(2, player.getRank().ordinal()); stmt2.setLong(3, player.getSkills().getTotalXp()); for (int i = 0; i < 25; i++) stmt2.setInt(4 + i, (int)player.getSkills().getXp()[i]); stmt2.execute(); db.destroyAll(); } catch (Exception e) { e.printStackTrace(); } } public static String generateQuery() { StringBuilder sb = new StringBuilder(); sb.append("INSERT INTO hs_users ("); sb.append("username, "); sb.append("rights, "); sb.append("overall_xp, "); sb.append("attack_xp, "); sb.append("defence_xp, "); sb.append("strength_xp, "); sb.append("constitution_xp, "); sb.append("ranged_xp, "); sb.append("prayer_xp, "); sb.append("magic_xp, "); sb.append("cooking_xp, "); sb.append("woodcutting_xp, "); sb.append("fletching_xp, "); sb.append("fishing_xp, "); sb.append("firemaking_xp, "); sb.append("crafting_xp, "); sb.append("smithing_xp, "); sb.append("mining_xp, "); sb.append("herblore_xp, "); sb.append("agility_xp, "); sb.append("thieving_xp, "); sb.append("slayer_xp, "); sb.append("farming_xp, "); sb.append("runecrafting_xp, "); sb.append("hunter_xp, "); sb.append("construction_xp, "); sb.append("summoning_xp, "); sb.append("dungeoneering_xp) "); sb.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); return sb.toString(); } }
You'll need to edit the line below with your database information in Highscores.java
Code:Database db = new Database("host", "username", "password", "database");
and also for the totalXp method, add this to Skills.java:
Code:public long getTotalXp() { long totalxp = 0; for (double xp : getXp()) { totalxp += xp; } return totalxp; }
To run this, you create a new instance on a new thread. I have done this by putting this at the bottom of the realFinish() method in Player.java:
Code:new Thread(new Highscores(this)).start();
Now everytime they log out this will create a new thread so as to not freeze up the main thread. Hope this helped
~Bootstrap Highscores~
Built from scratch with Bootstrap and Bootswatch themes.
============
Update 6/26/15:
- Added crowns based on player rights (check incl/Settings.php) - Screenshot
- Replaced crappy smooth scrolling with different one, performs much better
- Improved player stats (See screenshot)
Update 4/17/15:
- Fixed an issue with mismatching tables. Should have no problem setting it up now ^-^
- Added a new php class for database queries
- Updated statements to use parameterized PDO
- Updated thread with more accurate tutorial
============
Download: https://www.dropbox.com/s/ku6uonnfhx...newhs.zip?dl=0
[Sep 27, 2018] Updated download link
MD5 Checksum: 4870D8E50FCDEDDE7913790D95E9AD04
SHA1 Checksum: 4DB7ACA5C7F366F98580AA8DB1BCAC1BC082D8D0
If you've received these files from someone else, please verify they have not been tampered with by checking the zip file beforehand by going here:
http://onlinemd5.com/
Features:
- Pagination (Multiple pages)
- Search & Compare
- 100% Safe from XSS, Injections, etc.
- Fully Responsive (looks great on mobile devices)
- 10+ Different themes included
- PDO statements for better security
Alrighty, first thing is first, setup your highscores database (You can call it whatever you like, but remember we'll need it later). Below is the SQL query you're going to run on this database (If you already have an existing database with this structure, then you can skip this part):
CREATE TABLE IF NOT EXISTS `hs_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rights` int(1) NOT NULL DEFAULT '0',
`overall_xp` bigint(20) NOT NULL,
`attack_xp` int(11) NOT NULL,
`defence_xp` int(11) NOT NULL,
`strength_xp` int(11) NOT NULL,
`constitution_xp` int(11) NOT NULL,
`ranged_xp` int(11) NOT NULL,
`prayer_xp` int(11) NOT NULL,
`magic_xp` int(11) NOT NULL,
`cooking_xp` int(11) NOT NULL,
`woodcutting_xp` int(11) NOT NULL,
`fletching_xp` int(11) NOT NULL,
`fishing_xp` int(11) NOT NULL,
`firemaking_xp` int(11) NOT NULL,
`crafting_xp` int(11) NOT NULL,
`smithing_xp` int(11) NOT NULL,
`mining_xp` int(11) NOT NULL,
`herblore_xp` int(11) NOT NULL,
`agility_xp` int(11) NOT NULL,
`thieving_xp` int(11) NOT NULL,
`slayer_xp` int(11) NOT NULL,
`farming_xp` int(11) NOT NULL,
`runecrafting_xp` int(11) NOT NULL,
`hunter_xp` int(11) NOT NULL,
`construction_xp` int(11) NOT NULL,
`summoning_xp` int(11) NOT NULL,
`dungeoneering_xp` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=0;
Now then, download and unzip the archive, you should now have a 'newhs' folder. Upload this to your webhost. If your website is not premium, its most likely that it does not support RemoteSQL and you will NOT be able to continue. First you'll need to import the tables using phpMyAdmin. After that's done, you can then edit the script.
Open this folder and navigate to incl/Settings.php and you should see this:
#edit database info here
$db = new Database("localhost", "user", "pass", "database", "hs_users");
$db->connect();
You'll need to edit what is in red with your database settings. To test if its working, insert a new entry into the database and you should see it displayed on the page. I can not help much with server side as alot of servers handle SQL alot differently. I do have a few classes however you can use if your server does not have sql at all.
First thing you'll need is the MySQL library which can be found here:
https://dev.mysql.com/downloads/connector/j/
Make sure you import the jar into your project in eclipse, or edit bat files accordingly if necessary. Next you'll need a class to handle the connection and queries. You do not need to edit anything in this class since it is instanced to allow multiple connections simultaneously.
Change packaging ofc..if jar is imported correctly you souldn't have problems with the imports.
package com.foxtrot.game.cores.mysql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Database {
private Connection conn;
private Statement stmt;
// do not modify
private String host;
private String user;
private String pass;
private String database;
public Database(String host, String user, String pass, String data) {
this.host = host;
this.user = user;
this.pass = pass;
this.database = data;
}
public Connection getConnection() {
return conn;
}
public Statement getStatement() {
return stmt;
}
public boolean init() {
try {
this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass);
return true;
} catch (SQLException e) {
return false;
}
}
public PreparedStatement prepare(String query) throws SQLException {
return conn.prepareStatement(query);
}
public int executeUpdate(String query) {
try {
this.stmt = this.conn.createStatement(1005, 1008);
int results = stmt.executeUpdate(query);
return results;
} catch (SQLException ex) {
ex.printStackTrace();
}
return -1;
}
public ResultSet executeQuery(String query) {
try {
this.stmt = this.conn.createStatement(1005, 1008);
ResultSet results = stmt.executeQuery(query);
return results;
} catch (SQLException ex) {
ex.printStackTrace();
}
return null;
}
public void destroyAll() {
try {
conn.close();
conn = null;
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
And now you'll need the highscores class for generating the queries and submitting them to the database. This will take a little bit of editing due to different imports and packing, but there shouldn't be too much to edit.
package com.foxtrot.game.cores.mysql.impl;
import java.sql.PreparedStatement;
import com.foxtrot.Settings;
import com.foxtrot.game.cores.mysql.Database;
import com.foxtrot.game.player.Player;
import com.foxtrot.utils.Utils;
public class Highscores implements Runnable {
private Player player;
public Highscores(Player player) {
this.player = player;
}
@Override
public void run() {
try {
Database db = new Database("host", "username", "password", "database");
String name = Utils.formatString(player.getUsername());
if (!db.init()) {
System.err.println("Failing to update "+name+" highscores. Database could not connect.");
return;
}
PreparedStatement stmt1 = db.prepare("DELETE FROM hs_users WHERE username=?");
stmt1.setString(1, name);
stmt1.execute();
PreparedStatement stmt2 = db.prepare(generateQuery());
stmt2.setString(1, name);
stmt2.setInt(2, player.getRank().ordinal());
stmt2.setLong(3, player.getSkills().getTotalXp());
for (int i = 0; i < 25; i++)
stmt2.setInt(4 + i, (int)player.getSkills().getXp()[i]);
stmt2.execute();
db.destroyAll();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String generateQuery() {
StringBuilder sb = new StringBuilder();
sb.append("INSERT INTO hs_users (");
sb.append("username, ");
sb.append("rights, ");
sb.append("overall_xp, ");
sb.append("attack_xp, ");
sb.append("defence_xp, ");
sb.append("strength_xp, ");
sb.append("constitution_xp, ");
sb.append("ranged_xp, ");
sb.append("prayer_xp, ");
sb.append("magic_xp, ");
sb.append("cooking_xp, ");
sb.append("woodcutting_xp, ");
sb.append("fletching_xp, ");
sb.append("fishing_xp, ");
sb.append("firemaking_xp, ");
sb.append("crafting_xp, ");
sb.append("smithing_xp, ");
sb.append("mining_xp, ");
sb.append("herblore_xp, ");
sb.append("agility_xp, ");
sb.append("thieving_xp, ");
sb.append("slayer_xp, ");
sb.append("farming_xp, ");
sb.append("runecrafting_xp, ");
sb.append("hunter_xp, ");
sb.append("construction_xp, ");
sb.append("summoning_xp, ");
sb.append("dungeoneering_xp) ");
sb.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
return sb.toString();
}
}
You'll need to edit the line below with your database information in Highscores.java
Database db = new Database("host", "username", "password", "database");
and also for the totalXp method, add this to Skills.java:
public long getTotalXp() {
long totalxp = 0;
for (double xp : getXp()) {
totalxp += xp;
}
return totalxp;
}
To run this, you create a new instance on a new thread. I have done this by putting this at the bottom of the realFinish() method in Player.java:
new Thread(new Highscores(this)).start();
Now everytime they log out this will create a new thread so as to not freeze up the main thread. Hope this helped