Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. /*
  2. This file is part of the OdinMS Maple Story Server
  3. Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
  4. Matthias Butz <matze@odinms.de>
  5. Jan Christian Meyer <vimes@odinms.de>
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU Affero General Public License as
  9. published by the Free Software Foundation version 3 as published by
  10. the Free Software Foundation. You may not use, modify or distribute
  11. this program under any other version of the GNU Affero General Public
  12. License.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU Affero General Public License for more details.
  18.  
  19. You should have received a copy of the GNU Affero General Public License
  20. along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. package client.command;
  23.  
  24. import client.MapleCharacter;
  25. import client.MapleClient;
  26. import com.mysql.jdbc.Connection;
  27. import com.mysql.jdbc.PreparedStatement;
  28. import java.rmi.RemoteException;
  29. import java.sql.SQLException;
  30. import java.util.List;
  31. import provider.MapleData;
  32. import provider.MapleDataProvider;
  33. import provider.MapleDataProviderFactory;
  34. import provider.MapleDataTool;
  35. import tools.Pair;
  36. import java.util.ArrayList;
  37. import java.util.LinkedList;
  38. import java.io.File;
  39. import server.TimerManager;
  40. import server.life.MapleLifeFactory;
  41. import tools.DatabaseConnection;
  42.  
  43. public final class CommandProcessor {
  44.  
  45. private static Runnable persister;
  46. private static List<Pair<MapleCharacter, String>> gmlog = new LinkedList<Pair<MapleCharacter, String>>();
  47.  
  48. public static final boolean processCommand(final MapleClient c, final String s) throws SQLException, RemoteException, IllegalCommandSyntaxException {
  49.  
  50.  
  51. if (s.charAt(0) == '!' && (c.getPlayer().isGM() || c.getPlayer().getGmLevel() > 0)) {
  52. String[] sp = s.split(" ");
  53. sp[0] = sp[0].toLowerCase().substring(1);
  54. c.getPlayer().addCommandToList(s);
  55. if (c.getPlayer().gmLevel() >= 2) {
  56. if (JrGM.execute(c, sp, '!')) {
  57. return true;
  58. }
  59. }
  60. if (c.getPlayer().gmLevel() >= 1){
  61. if (DonorCommand.execute(c, sp, '!')){
  62. return true;
  63. }
  64. }
  65. if (c.getPlayer().gmLevel() >= 3) {
  66. if (GMCommand.execute(c, sp, '!')) {
  67. return true;
  68. }
  69. }
  70. if (c.getPlayer().gmLevel() >= 4) {
  71. if (SGMCommand.execute(c, sp, '!')) {
  72. return true;
  73. }
  74. }
  75. if (c.getPlayer().gmLevel() >= 5) {
  76. if (DeveloperCommand.execute(c, sp, '!')) {
  77. return true;
  78. }
  79. }
  80. if (c.getPlayer().gmLevel() >= 6) {
  81. if (AdminCommand.execute(c, sp, '!')) {
  82. return true;
  83. }
  84. }
  85. return true;
  86. }
  87. if (s.charAt(0) == '@') {
  88. if (c.getPlayer().inJail()){
  89. c.getPlayer().dropMessage("You may not use this command in this map.");
  90. return false;
  91. }
  92. String[] sp = s.split(" ");
  93. sp[0] = sp[0].toLowerCase().substring(1);
  94. PlayerCommands.execute(c, sp, '@');
  95.  
  96. return true;
  97. }
  98. return false;
  99. }
  100.  
  101. public static void forcePersisting() {
  102. persister.run();
  103. }
  104.  
  105. static {
  106. persister = new PersistingTask();
  107. TimerManager.getInstance().register(persister, 62000);
  108. }
  109.  
  110. public static class PersistingTask implements Runnable {
  111.  
  112. @Override
  113. public void run() {
  114. synchronized (gmlog) {
  115. Connection con = (Connection) DatabaseConnection.getConnection();
  116. try {
  117. PreparedStatement ps = (PreparedStatement) con.prepareStatement("INSERT INTO gmlog (cid, command) VALUES (?, ?)");
  118. for (Pair<MapleCharacter, String> logentry : gmlog) {
  119. ps.setInt(1, logentry.getLeft().getId());
  120. ps.setString(2, logentry.getRight());
  121. ps.executeUpdate();
  122. }
  123. ps.close();
  124. } catch (SQLException e) {
  125. System.out.println("Error persisting cheatlog" + e);
  126. }
  127. gmlog.clear();
  128. }
  129. }
  130. }
  131.  
  132.  
  133.  
  134. public static ArrayList<Pair<Integer, String>> getMobsIDsFromName(String search) {
  135. MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File("wz/String.wz"));
  136. ArrayList<Pair<Integer, String>> retMobs = new ArrayList<Pair<Integer, String>>();
  137. MapleData data = dataProvider.getData("Mob.img");
  138. List<Pair<Integer, String>> mobPairList = new LinkedList<Pair<Integer, String>>();
  139. for (MapleData mobIdData : data.getChildren()) {
  140. int mobIdFromData = Integer.parseInt(mobIdData.getName());
  141. String mobNameFromData = MapleDataTool.getString(mobIdData.getChildByPath("name"), "NO-NAME");
  142. mobPairList.add(new Pair<Integer, String>(mobIdFromData, mobNameFromData));
  143. }
  144. for (Pair<Integer, String> mobPair : mobPairList) {
  145. if (mobPair.getRight().toLowerCase().contains(search.toLowerCase())) {
  146. retMobs.add(mobPair);
  147. }
  148. }
  149. return retMobs;
  150. }
  151.  
  152. public static String getMobNameFromID(int id) {
  153. try {
  154. return MapleLifeFactory.getMonster(id).getName();
  155. } catch (Exception e) {
  156. return null; //nonexistant mob
  157. }
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement