Originally Posted by
Lumiere
What you have provided "if (player.logout())" would be a Boolean, and you're checking if its true.
What the other R-S User posted above; you'll notice it makes the Boolean "properLogout" true.
That's basically what you'll want.
Code:
private boolean loggingOut;
public boolean loggingOut() {
return loggingOut;
}
public void setLoggingOut(boolean input) {
loggingOut = input;
}
Something of that sort.
After that, in your destruct/logout method, you'll add "setLoggingOut(true);"
EDIT: reminder, the loggingOut boolean is by default, false.
With that being said, you wont ever want to save this variable per player.
When a player logs in, it will be false, the moment the destruct/logout method is called, it will return true.
Then on their next login, it will be re-instanced as false, which is how you'll want it.
Well here's the thing in my playerhandler.java this is what it looks like
Code:
package com.ownxile.rs2.player;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Objects;
import com.ownxile.config.GameConfig;
import com.ownxile.core.World;
import com.ownxile.core.World.WorldStatus;
import com.ownxile.rs2.npcs.NPC;
import com.ownxile.rs2.npcs.NPCHandler;
import com.ownxile.util.Misc;
import com.ownxile.util.Stream;
public class PlayerHandler {
public static Player players[] = new Player[GameConfig.MAX_PLAYERS];
public static boolean updateAnnounced;
public static boolean updateRunning;
public static int updateSeconds;
public static long updateStartTime;
static {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] != null) {
PlayerSave.saveGame((Client) players[i]);
}
}
}
});
}
public static void disconnectAddress(String address) {
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] != null) {
if (players[i].connectedFrom.equalsIgnoreCase(address)) {
players[i].disconnected = true;
}
}
}
}
public static Player findPlayer(String name) {
for (Player player : players) {
if (player == null) {
continue;
}
if (player.playerName.equalsIgnoreCase(name)) {
return player;
}
}
return null;
}
public static int getAddressConnectionCount(String address) {
int hits = 0;
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] != null) {
if (players[i].connectedFrom.equalsIgnoreCase(address)) {
hits++;
}
}
}
return hits;
}
public static int getPlayerCount() {
double i = 1.6;
for (Player player : players) {
if (player != null) {
i++;
}
}
return (int) i;
}
public static boolean isPlayerOn(String playerName) {
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (PlayerHandler.players[i] != null) {
if (PlayerHandler.players[i].playerName
.equalsIgnoreCase(playerName)) {
return true;
}
}
}
return false;
}
private long time;
private final Stream updateBlock = new Stream(
new byte[GameConfig.BUFFER_SIZE]);
private void catchDisconnect(int i) {
if (players[i].inTrade) {
final Client o = (Client) PlayerHandler.players[players[i].tradeWith];
if (o != null) {
o.getTrade().declineTrade();
}
}
if (players[i].duelStatus == 5) {
final Client o1 = (Client) PlayerHandler.players[players[i].duelingWith];
if (o1 != null) {
o1.getDuel().duelVictory();
}
} else if (players[i].duelStatus <= 4 && players[i].duelStatus >= 1) {
final Client o1 = (Client) PlayerHandler.players[players[i].duelingWith];
if (o1 != null) {
o1.getDuel().declineDuel();
}
}
PlayerSave.saveGame((Client) PlayerHandler.players[i]);
}
public int getFreeSlot() {
for (int i = 1; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] == null) {
return i;
}
}
return -1;
}
public Player getPlayerByName(String name) {
name = name.toLowerCase();
for (final Player p : players) {
if (p != null && p.playerName.toLowerCase().equals(name)) {
return p;
}
}
return null;
}
public Player getRandomPlayer() {
return players[Misc.random(PlayerHandler.getPlayerCount())];
}
private void handlePlayerUpdating(Player player) {
player.preProcessing();
while (player.processQueuedPackets()) {
;
}
player.process();
player.postProcessing();
player.getNextPlayerMovement();
}
public void kickAll() {
for (int i = 1; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] != null) {
players[i].disconnected = true;
}
}
}
public boolean newPlayerClient(Client client1, int slot) {
if (slot == -1) {
return false;
}
client1.handler = this;
client1.playerId = slot;
players[slot] = client1;
players[slot].isActive = true;
// players[slot].hostname = ((InetSocketAddress) client1.getSession()
// .getRemoteAddress()).getAddress().getHostName();
players[slot].connectedFrom = ((InetSocketAddress) client1.getSession()
.getRemoteAddress()).getAddress().getHostAddress();
if (GameConfig.SERVER_DEBUG) {
Misc.println("Player Slot " + slot + " slot 0 " + players[0]
+ " Player Hit " + players[slot]);
}
return true;
}
public void removePlayer(final Player plr) {
if (plr.privChat != 2) {
for (int i = 1; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] == null || players[i].isActive == false) {
continue;
}
final Client o = (Client) PlayerHandler.players[i];
if (o != null) {
o.getFunction().updatePM(plr.playerId, 0);
}
}
}
plr.destruct();
}
public void tick() {
time = System.currentTimeMillis();
if (updateRunning && !updateAnnounced) {
updateAnnounced = true;
World.setStatus(WorldStatus.UPDATING);
}
if (updateRunning && time - updateStartTime > updateSeconds * 1000) {
kickAll();
}
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] == null || !players[i].isActive) {
continue;
}
try {
if (players[i].disconnected
&& time - players[i].logoutDelay > 10000
|| players[i].properLogout) {
catchDisconnect(i);
removePlayer(players[i]);
players[i] = null;
continue;
}
handlePlayerUpdating(players[i]);
} catch (final Exception e) {
e.printStackTrace();
}
}
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] == null || !players[i].isActive) {
continue;
}
try {
if (players[i].disconnected
&& time - players[i].logoutDelay > 10000
|| players[i].properLogout) {
catchDisconnect(i);
removePlayer(players[i]);
players[i] = null;
continue;
}
if (!players[i].initialized) {
players[i].initialize();
players[i].initialized = true;
} else {
players[i].update();
}
} catch (final Exception e) {
e.printStackTrace();
}
}
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (players[i] == null || !players[i].isActive) {
continue;
}
try {
players[i].clearUpdateFlags();
} catch (final Exception e) {
e.printStackTrace();
}
}
}
public void updateNPC(Player plr, Stream str) {
synchronized (plr) {
updateBlock.currentOffset = 0;
str.createFrameVarSizeWord(65);//65 = npc update
str.initBitAccess();
final int size = plr.npcListSize;
str.writeBits(8, size);
plr.npcListSize = 0;
for (int i = 0; i < size; i++) {
if (!plr.RebuildNPCList && plr.withinDistance(plr.npcList[i])) {
plr.npcList[i].updateNPCMovement(str);
plr.npcList[i].appendNPCUpdateBlock(updateBlock);
plr.npcList[plr.npcListSize++] = plr.npcList[i];
} else {
final int id = plr.npcList[i].npcId;
plr.npcInListBitmap[id >> 3] &= ~(1 << (id & 7));
str.writeBits(1, 1);
str.writeBits(2, 3);
}
}
for (int i = 0; i < NPCHandler.MAX_VALUE; i++) {
if (NPCHandler.npcs[i] != null) {
final int id = NPCHandler.npcs[i].npcId;
if (!plr.RebuildNPCList && (plr.npcInListBitmap[id >> 3] & 1 << (id & 7)) != 0) {
if (NPC.zulrah.contains(NPCHandler.npcs[i].npcType) && NPCHandler.npcs[i].needsPositionUpdate) {
plr.updateExistingNPC(NPCHandler.npcs[i], str, updateBlock);
NPCHandler.npcs[i].needsPositionUpdate = false;
}
} else if (plr.withinDistance(NPCHandler.npcs[i])) {
plr.addNewNPC(NPCHandler.npcs[i], str, updateBlock);
}
}
}
plr.RebuildNPCList = false;
if (updateBlock.currentOffset > 0) {
str.writeBits(14, 16383);
str.finishBitAccess();
str.writeBytes(updateBlock.buffer, updateBlock.currentOffset, 0);
} else {
str.finishBitAccess();
}
str.endFrameVarSizeWord();
}
}
public void updatePlayer(Player plr, Stream str) {
synchronized (plr) {
updateBlock.currentOffset = 0;
if (updateRunning && !updateAnnounced) {
str.createFrame(114);
str.writeWordBigEndian(updateSeconds * 50 / 30);
}
plr.updateThisPlayerMovement(str);
final boolean saveChatTextUpdate = plr.isChatTextUpdateRequired();
plr.setChatTextUpdateRequired(false);
plr.appendPlayerUpdateBlock(updateBlock);
plr.setChatTextUpdateRequired(saveChatTextUpdate);
str.writeBits(8, plr.playerListSize);
final int size = plr.playerListSize;
plr.playerListSize = 0;
for (int i = 0; i < size; i++) {
if (!plr.didTeleport && !plr.playerList[i].didTeleport
&& plr.withinDistance(plr.playerList[i])
&& str.currentOffset + updateBlock.currentOffset < 4800) {
plr.playerList[i].updatePlayerMovement(str);
plr.playerList[i].appendPlayerUpdateBlock(updateBlock);
plr.playerList[plr.playerListSize++] = plr.playerList[i];
} else {
final int id = plr.playerList[i].playerId;
plr.playerInListBitmap[id >> 3] &= ~(1 << (id & 7));
str.writeBits(1, 1);
str.writeBits(2, 3);
}
}
int added = 0;
for (int i = 0; i < GameConfig.MAX_PLAYERS; i++) {
if (str.currentOffset + updateBlock.currentOffset >= 4800) {
break;
}
if (players[i] == null || !players[i].isActive
|| players[i] == plr) {
continue;
}
final int id = players[i].playerId;
if ((plr.playerInListBitmap[id >> 3] & 1 << (id & 7)) != 0) {
continue;
}
if (!plr.withinDistance(players[i])) {
continue;
}
if (added++ >= 10) {
break;
}
plr.addNewPlayer(players[i], str, updateBlock);
}
if (updateBlock.currentOffset > 0) {
str.writeBits(11, 2047);
str.finishBitAccess();
str.writeBytes(updateBlock.buffer, updateBlock.currentOffset, 0);
} else {
str.finishBitAccess();
}
str.endFrameVarSizeWord();
}
}
public void yell(String name, int rights, String message) {
for (final Player player : players) {
if (player == null) {
continue;
}
final Client client = (Client) player;
client.getFunction().sendClan(name, Misc.optimizeText(message),
"Yell", rights);
}
}
public static void executeGlobalMessage(String message) {
Player[] clients = new Player[players.length];
System.arraycopy(players, 0, clients, 0, players.length);
Arrays.asList(clients).stream().filter(Objects::nonNull).forEach(player -> player.sendMessage(message));
}
}
And I am using the instructions on rsps-scores.com
First open package com.ruse and create class called HighscoresHandler. Paste this code inside that class and save.
Code:
package com.ruse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mistrix.model.Skill;
import com.mistrix.world.entity.impl.player.Player;
import com.mysql.jdbc.Statement;
public class HighscoresHandler implements Runnable{
/**
* Secret key
*/
final static String secret = "67e69cfdadf8b32";
/**
* Username that is used for mysql connection
*/
final static String user = "2ed9df";
private Player player;
public HighscoresHandler(Player player) {
this.player = player;
}
/**
* Function that handles everything, it inserts or updates
* user data in database
*/
@Override
public void run() {
/**
* Players username
*/
final String username = player.getUsername();
/**
* Represents game mode
* If you want to set game modes do this:
*/
final int gameMode = 0;
/**
* Represents overall xp
*/
final long overallXp = player.getSkillManager().getTotalExp();
/**
* Represents attack xp
*/
final long attackXp = player.getSkillManager().getExperience(Skill.ATTACK);
/**
* Represents defence xp
*/
final long defenceXp = player.getSkillManager().getExperience(Skill.DEFENCE);
/**
* Represents strength xp
*/
final long strengthXp = player.getSkillManager().getExperience(Skill.STRENGTH);
/**
* Represents constitution xp
*/
final long constitutionXp = player.getSkillManager().getExperience(Skill.CONSTITUTION);
/**
* Represents ranged xp
*/
final long rangedXp = player.getSkillManager().getExperience(Skill.RANGED);
/**
* Represents prayer xp
*/
final long prayerXp = player.getSkillManager().getExperience(Skill.PRAYER);
/**
* Represents magic xp
*/
final long magicXp = player.getSkillManager().getExperience(Skill.MAGIC);
/**
* Represents cooking xp
*/
final long cookingXp = player.getSkillManager().getExperience(Skill.COOKING);
/**
* Represents woodcutting xp
*/
final long woodcuttingXp = player.getSkillManager().getExperience(Skill.WOODCUTTING);
/**
* Represents fletching xp
*/
final long fletchingXp = player.getSkillManager().getExperience(Skill.FLETCHING);
/**
* Represents fishing xp
*/
final long fishingXp = player.getSkillManager().getExperience(Skill.FISHING);
/**
* Represents firemaking xp
*/
final long firemakingXp = player.getSkillManager().getExperience(Skill.FIREMAKING);
/**
* Represents crafting xp
*/
final long craftingXp = player.getSkillManager().getExperience(Skill.CRAFTING);
/**
* Represents smithing xp
*/
final long smithingXp = player.getSkillManager().getExperience(Skill.SMITHING);
/**
* Represents mining xp
*/
final long miningXp = player.getSkillManager().getExperience(Skill.MINING);
/**
* Represents herblore xp
*/
final long herbloreXp = player.getSkillManager().getExperience(Skill.HERBLORE);
/**
* Represents agility xp
*/
final long agilityXp = player.getSkillManager().getExperience(Skill.AGILITY);
/**
* Represents thieving xp
*/
final long thievingXp = player.getSkillManager().getExperience(Skill.THIEVING);
/**
* Represents slayer xp
*/
final long slayerXp = player.getSkillManager().getExperience(Skill.SLAYER);
/**
* Represents farming xp
*/
final long farmingXp = player.getSkillManager().getExperience(Skill.FARMING);
/**
* Represents runecrafting xp
*/
final long runecraftingXp = player.getSkillManager().getExperience(Skill.RUNECRAFTING);
/**
* Represents hunter xp
*/
final long hunterXp = player.getSkillManager().getExperience(Skill.HUNTER);
/**
* Represents construction xp
*/
final long constructionXp = player.getSkillManager().getExperience(Skill.CONSTRUCTION);
/**
* Creates new instance of jdbc driver
* if that driver exists
*/
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e1) {
e1.printStackTrace();
}
/**
* Sets Connection variable to null
*/
Connection connection = null;
/**
* Sets Statement variable to null
*/
Statement stmt = null;
/**
* Attempts connecting to database
*/
try {
connection = DriverManager.getConnection("jdbc:mysql://198.211.123.88:3306/admin_scores_data", user, secret);
} catch (SQLException e) {
e.printStackTrace();
return;
}
/**
* Checks if connection isnt null
*/
if (connection != null) {
try {
stmt = (Statement) connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) AS count FROM `"+user+"_scores` WHERE username='" +username+ "'");
if(rs.next()) {
if(rs.getInt("count") > 0) {
stmt.executeUpdate("UPDATE `"+user+"_scores` SET overall_xp = '"+overallXp+"', attack_xp = '"+attackXp+"', defence_xp = '"+defenceXp+"', strength_xp = '"+strengthXp+"', constitution_xp = '"+constitutionXp+"', ranged_xp = '"+rangedXp+"', prayer_xp = '"+prayerXp+"', magic_xp = '"+magicXp+"', cooking_xp = '"+cookingXp+"', woodcutting_xp = '"+woodcuttingXp+"', fletching_xp = '"+fletchingXp+"', fishing_xp = '"+fishingXp+"', firemaking_xp = '"+firemakingXp+"', crafting_xp = '"+craftingXp+"', smithing_xp = '"+smithingXp+"', mining_xp = '"+miningXp+"', herblore_xp = '"+herbloreXp+"', agility_xp = '"+agilityXp+"', thieving_xp = '"+thievingXp+"', slayer_xp = '"+slayerXp+"', farming_xp = '"+farmingXp+"', runecrafting_xp = '"+runecraftingXp+"', hunter_xp = '"+hunterXp+"', construction_xp = '"+constructionXp+"' WHERE username = '"+username+"'");
} else {
stmt.executeUpdate("INSERT INTO `"+user+"_scores` (username, mode, overall_xp, attack_xp, defence_xp, strength_xp, constitution_xp, ranged_xp, prayer_xp, magic_xp, cooking_xp, woodcutting_xp, fletching_xp, fishing_xp, firemaking_xp, crafting_xp, smithing_xp, mining_xp, herblore_xp, agility_xp, thieving_xp, slayer_xp, farming_xp, runecrafting_xp, hunter_xp, construction_xp) VALUES ('"+username+"', '"+gameMode+"', '"+overallXp+"', '"+attackXp+"', '"+defenceXp+"', '"+strengthXp+"', '"+constitutionXp+"', '"+rangedXp+"', '"+prayerXp+"', '"+magicXp+"', '"+cookingXp+"', '"+woodcuttingXp+"', '"+fletchingXp+"', '"+fishingXp+"', '"+firemakingXp+"', '"+craftingXp+"', '"+smithingXp+"', '"+miningXp+"', '"+herbloreXp+"', '"+agilityXp+"', '"+thievingXp+"', '"+slayerXp+"', '"+farmingXp+"', '"+runecraftingXp+"', '"+hunterXp+"', '"+constructionXp+"')");
}
}
stmt.close();
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
} else {
System.out.println("Failed to make connection!");
}
return;
}
}
Next open PlayerHandler.java and under
if(player.logout() || exception) {
paste this code
new Thread(new HighscoresHandler(player)).start();
You now have highscores installed.
WHAT I AM TRYING TO DO IS CONVERT PWNXILE/OWNXILE into rsps-scores.com
or if somebody can make me a highscores that would be nice