50 Views and no replys? No wonder people never help each other on this community. Any more leeching before theres a post and im removing this.
Description: How to add highscores to your server. I will give you guys the files and explain how to implement it into your server. I will NOT be telling you how to get a mysql database, or how to upload the highscores to your website.
Difficulty: About 5/10
Assumed Knowledge: How to use CTRL+F button, how to download, paste, copy, etc..
Tested Server: SoulSplit(PI)
Files/Classes Modified: Client.java, Highscores.java, Server.java
Step 1:
BACK UP ALL SERVER FILES
Step 2:
Create the following class file:
Code:
package server.model.players;
import java.sql.*;
/*
* I decompiled the SQL.class file from SoulSplit source
* I edited it heavily though.
* Credits to Zenocko and owner of EvoScape for the file
*/
public class Highscores {
public static Connection con;
public static Statement stm;
public static boolean connected;
public static void process() {
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String databaseURL = "jdbc:mysql://HOST/DATABASE";
Connection con = DriverManager.getConnection(databaseURL, "USERNAME", "PASSWORD");
stm = con.createStatement();
connected = true;
}
catch(Exception e)
{
connected = false;
e.printStackTrace();
}
}
public static ResultSet query(String s)
throws SQLException
{
if(s.toLowerCase().startsWith("select"))
{
ResultSet resultset = stm.executeQuery(s);
return resultset;
}
try
{
stm.executeUpdate(s);
return null;
}
catch(Exception e)
{
destroy();
}
process();
return null;
}
public static void destroy() {
try
{
stm.close();
con.close();
connected = false;
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static boolean save(Client c) {
try
{
query((new StringBuilder()).append("DELETE FROM `skills` WHERE playerName = '").append(c.playerName).append("';").toString());
query((new StringBuilder()).append("DELETE FROM `skillsoverall` WHERE playerName = '").append(c.playerName).append("';").toString());
query((new StringBuilder()).append("INSERT INTO `skills` (`playerName`,`Attacklvl`,`Attackxp`,`Defencelvl`,`Defencexp`,`Strengthlvl`,`Strengthxp`,`Hitpointslvl`,`Hitpointsxp`,`Rangelvl`,`Rangexp`,`Prayerlvl`,`Prayerxp`,`Magiclvl`,`Magicxp`,`Cookinglvl`,`Cookingxp`,`Woodcuttinglvl`,`Woodcuttingxp`,`Fletchinglvl`,`Fletchingxp`,`Fishinglvl`,`Fishingxp`,`Firemakinglvl`,`Firemakingxp`,`Craftinglvl`,`Craftingxp`,`Smithinglvl`,`Smithingxp`,`Mininglvl`,`Miningxp`,`Herblorelvl`,`Herblorexp`,`Agilitylvl`,`Agilityxp`,`Thievinglvl`,`Thievingxp`,`Slayerlvl`,`Slayerxp`,`Farminglvl`,`Farmingxp`,`Runecraftlvl`,`Runecraftxp`) VALUES ('").append(c.playerName).append("',").append(c.playerLevel[0]).append(",").append(c.playerXP[0]).append(",").append(c.playerLevel[1]).append(",").append(c.playerXP[1]).append(",").append(c.playerLevel[2]).append(",").append(c.playerXP[2]).append(",").append(c.playerLevel[3]).append(",").append(c.playerXP[3]).append(",").append(c.playerLevel[4]).append(",").append(c.playerXP[4]).append(",").append(c.playerLevel[5]).append(",").append(c.playerXP[5]).append(",").append(c.playerLevel[6]).append(",").append(c.playerXP[6]).append(",").append(c.playerLevel[7]).append(",").append(c.playerXP[7]).append(",").append(c.playerLevel[8]).append(",").append(c.playerXP[8]).append(",").append(c.playerLevel[9]).append(",").append(c.playerXP[9]).append(",").append(c.playerLevel[10]).append(",").append(c.playerXP[10]).append(",").append(c.playerLevel[11]).append(",").append(c.playerXP[11]).append(",").append(c.playerLevel[12]).append(",").append(c.playerXP[12]).append(",").append(c.playerLevel[13]).append(",").append(c.playerXP[13]).append(",").append(c.playerLevel[14]).append(",").append(c.playerXP[14]).append(",").append(c.playerLevel[15]).append(",").append(c.playerXP[15]).append(",").append(c.playerLevel[16]).append(",").append(c.playerXP[16]).append(",").append(c.playerLevel[17]).append(",").append(c.playerXP[17]).append(",").append(c.playerLevel[18]).append(",").append(c.playerXP[18]).append(",").append(c.playerLevel[19]).append(",").append(c.playerXP[19]).append(",").append(c.playerLevel[20]).append(",").append(c.playerXP[20]).append(");").toString());
query((new StringBuilder()).append("INSERT INTO `skillsoverall` (`playerName`,`lvl`,`xp`) VALUES ('").append(c.playerName).append("',").append(c.getLevelForXP(c.playerXP[0]) + c.getLevelForXP(c.playerXP[1]) + c.getLevelForXP(c.playerXP[2]) + c.getLevelForXP(c.playerXP[3]) + c.getLevelForXP(c.playerXP[4]) + c.getLevelForXP(c.playerXP[5]) + c.getLevelForXP(c.playerXP[6]) + c.getLevelForXP(c.playerXP[7]) + c.getLevelForXP(c.playerXP[8]) + c.getLevelForXP(c.playerXP[9]) + c.getLevelForXP(c.playerXP[10]) + c.getLevelForXP(c.playerXP[11]) + c.getLevelForXP(c.playerXP[12]) + c.getLevelForXP(c.playerXP[13]) + c.getLevelForXP(c.playerXP[14]) + c.getLevelForXP(c.playerXP[15]) + c.getLevelForXP(c.playerXP[16]) + c.getLevelForXP(c.playerXP[17]) + c.getLevelForXP(c.playerXP[18]) + c.getLevelForXP(c.playerXP[19]) + c.getLevelForXP(c.playerXP[20])).append(",").append(c.playerXP[0] + c.playerXP[1] + c.playerXP[2] + c.playerXP[3] + c.playerXP[4] + c.playerXP[5] + c.playerXP[6] + c.playerXP[7] + c.playerXP[8] + c.playerXP[9] + c.playerXP[10] + c.playerXP[11] + c.playerXP[12] + c.playerXP[13] + c.playerXP[14] + c.playerXP[15] + c.playerXP[16] + c.playerXP[17] + c.playerXP[18] + c.playerXP[19] + c.playerXP[20]).append(");").toString());
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
return true;
}
}
Save it as "Highscores.java" in your src.server.model.players folder. Edit the red parts I highlighted to fit your own database info.
Step 3:
Now that we have the correct highscores file we need to implement it into the server.
Open Client.java(src.server.model.players) and find
Code:
public void logout() {
Under it add:
Code:
Highscores.process();
Highscores.save(this);
Save & Exit Client.java
Open Server.java(src.server) and search for
Code:
public static void main
Under it you should see something like
Code:
System.out.println("Loading Alison317 - Zenocko.");
Below this code ^ add:
Code:
if (Highscores.connected = true) {
System.out.println("Connected to MySQL Database!");
}
This is so that you can make sure the server is connecting to your mysql database.
Step 4:
Now we need to add the mysql connector(the com.mysql.jdbc.Driver files). Alot of people already have the files but for the new people download them here:
UPLOAD.EE - Download sql.rar. Anyways, once you have the files extract them to bin.server.model.players so that the "com" folder is in the same directory as the Highscores.class file.
Save Compile & Run. You can follow this tut:
http://www.rune-server.org/runescape...a-website.html for help on getting the website part to work for you.
Anything I forgot post please. Post errors/bugs/fixes here too. I encourage people to show me more efficient ways of doing things
.
FAQ: This is my first tut. I have been coding rsps since 2006 (my mopar register date is july-20-2006). I did a few tuts on mopar but leech pissed me off so I never did one again. This tut looked like it was actually needed so I made it. Dont like it? Fuck you.
Downloads:
Mysql Connector files:
UPLOAD.EE - Download sql.rar
Highscore php and img files:
highscores.zip
Credits:
IntV - You attempted to do this and it was kinda crappy no offense. You gave me the inspiration.
deathchaos9 - For the highscore php files, imgs, and the Database.
This is my first tut but if it helped rep++ if I get good comments Ill make some more tuts in the future.