Advertisement
Guest User

Untitled

a guest
Nov 13th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.17 KB | None | 0 0
  1. package com.ruse;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import com.mistrix.model.Skill;
  9. import com.mistrix.world.entity.impl.player.Player;
  10. import com.mysql.jdbc.Statement;
  11.  
  12. public class HighscoresHandler implements Runnable{
  13.  
  14. /**
  15. * Secret key
  16. */
  17. final static String secret = "'.$this->server->secret.'";
  18. /**
  19. * Username that is used for mysql connection
  20. */
  21. final static String user = "'.$this->server->server_id.'";
  22.  
  23.  
  24. private Player player;
  25.  
  26. public HighscoresHandler(Player player) {
  27. this.player = player;
  28. }
  29.  
  30. /**
  31. * Function that handles everything, it inserts or updates
  32. * user data in database
  33. */
  34. @Override
  35. public void run() {
  36. /**
  37. * Players username
  38. */
  39. final String username = player.getUsername();
  40. /**
  41. * Represents game mode
  42. * If you want to set game modes do this:';
  43. if($this->serverData->getGameModes($this->server->server_id)) {
  44. foreach ($this->serverData->getGameModes($this->server->server_id) as $row) {
  45. echo '<br> * Set gameMode variable to '.$row['mode_id'].' if player is '.$row['mode_name'].'';
  46. }
  47. }
  48. echo '
  49. */
  50. final int gameMode = 0;
  51. /**
  52. * Represents overall xp
  53. */
  54. final long overallXp = player.getSkillManager().getTotalExp();
  55. /**
  56. * Represents attack xp
  57. */
  58. final long attackXp = player.getSkillManager().getExperience(Skill.ATTACK);
  59. /**
  60. * Represents defence xp
  61. */
  62. final long defenceXp = player.getSkillManager().getExperience(Skill.DEFENCE);
  63. /**
  64. * Represents strength xp
  65. */
  66. final long strengthXp = player.getSkillManager().getExperience(Skill.STRENGTH);
  67. /**
  68. * Represents constitution xp
  69. */
  70. final long constitutionXp = player.getSkillManager().getExperience(Skill.CONSTITUTION);
  71. /**
  72. * Represents ranged xp
  73. */
  74. final long rangedXp = player.getSkillManager().getExperience(Skill.RANGED);
  75. /**
  76. * Represents prayer xp
  77. */
  78. final long prayerXp = player.getSkillManager().getExperience(Skill.PRAYER);
  79. /**
  80. * Represents magic xp
  81. */
  82. final long magicXp = player.getSkillManager().getExperience(Skill.MAGIC);
  83. /**
  84. * Represents cooking xp
  85. */
  86. final long cookingXp = player.getSkillManager().getExperience(Skill.COOKING);
  87. /**
  88. * Represents woodcutting xp
  89. */
  90. final long woodcuttingXp = player.getSkillManager().getExperience(Skill.WOODCUTTING);
  91. /**
  92. * Represents fletching xp
  93. */
  94. final long fletchingXp = player.getSkillManager().getExperience(Skill.FLETCHING);
  95. /**
  96. * Represents fishing xp
  97. */
  98. final long fishingXp = player.getSkillManager().getExperience(Skill.FISHING);
  99. /**
  100. * Represents firemaking xp
  101. */
  102. final long firemakingXp = player.getSkillManager().getExperience(Skill.FIREMAKING);
  103. /**
  104. * Represents crafting xp
  105. */
  106. final long craftingXp = player.getSkillManager().getExperience(Skill.CRAFTING);
  107. /**
  108. * Represents smithing xp
  109. */
  110. final long smithingXp = player.getSkillManager().getExperience(Skill.SMITHING);
  111. /**
  112. * Represents mining xp
  113. */
  114. final long miningXp = player.getSkillManager().getExperience(Skill.MINING);
  115. /**
  116. * Represents herblore xp
  117. */
  118. final long herbloreXp = player.getSkillManager().getExperience(Skill.HERBLORE);
  119. /**
  120. * Represents agility xp
  121. */
  122. final long agilityXp = player.getSkillManager().getExperience(Skill.AGILITY);
  123. /**
  124. * Represents thieving xp
  125. */
  126. final long thievingXp = player.getSkillManager().getExperience(Skill.THIEVING);
  127. /**
  128. * Represents slayer xp
  129. */
  130. final long slayerXp = player.getSkillManager().getExperience(Skill.SLAYER);
  131. /**
  132. * Represents farming xp
  133. */
  134. final long farmingXp = player.getSkillManager().getExperience(Skill.FARMING);
  135. /**
  136. * Represents runecrafting xp
  137. */
  138. final long runecraftingXp = player.getSkillManager().getExperience(Skill.RUNECRAFTING);
  139. /**
  140. * Represents hunter xp
  141. */
  142. final long hunterXp = player.getSkillManager().getExperience(Skill.HUNTER);
  143. /**
  144. * Represents construction xp
  145. */
  146. final long constructionXp = player.getSkillManager().getExperience(Skill.CONSTRUCTION);
  147. /**
  148. * Creates new instance of jdbc driver
  149. * if that driver exists
  150. */
  151. try {
  152. Class.forName("com.mysql.jdbc.Driver").newInstance();
  153. } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e1) {
  154. e1.printStackTrace();
  155. }
  156. /**
  157. * Sets Connection variable to null
  158. */
  159. Connection connection = null;
  160. /**
  161. * Sets Statement variable to null
  162. */
  163. Statement stmt = null;
  164.  
  165. /**
  166. * Attempts connecting to database
  167. */
  168. try {
  169. connection = DriverManager.getConnection("jdbc:mysql://198.211.123.88:3306/admin_scores_data", user, secret);
  170. } catch (SQLException e) {
  171. e.printStackTrace();
  172. return;
  173. }
  174. /**
  175. * Checks if connection isnt null
  176. */
  177. if (connection != null) {
  178. try {
  179. stmt = (Statement) connection.createStatement();
  180. ResultSet rs = stmt.executeQuery("SELECT COUNT(*) AS count FROM `"+user+"_scores` WHERE username=\'" +username+ "\'");
  181. if(rs.next()) {
  182. if(rs.getInt("count") > 0) {
  183. 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+"\'");
  184. } else {
  185. 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+"\')");
  186. }
  187. }
  188. stmt.close();
  189. connection.close();
  190. } catch (SQLException e1) {
  191. e1.printStackTrace();
  192. }
  193. } else {
  194. System.out.println("Failed to make connection!");
  195. }
  196.  
  197. return;
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement