Guest User

Repair Community

a guest
Jul 19th, 2016
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.78 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2Network_gameserver
  3. Index: java/net/sf/l2j/gameserver/communitybbs/CommunityBoard.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/communitybbs/CommunityBoard.java (revision 5)
  6. +++ java/net/sf/l2j/gameserver/communitybbs/CommunityBoard.java (working copy)
  7. @@ -21,6 +21,7 @@
  8.  import net.sf.l2j.gameserver.communitybbs.Manager.MailBBSManager;
  9.  import net.sf.l2j.gameserver.communitybbs.Manager.PostBBSManager;
  10.  import net.sf.l2j.gameserver.communitybbs.Manager.RegionBBSManager;
  11. +import net.sf.l2j.gameserver.communitybbs.Manager.RepairBBSManager;
  12.  import net.sf.l2j.gameserver.communitybbs.Manager.TopBBSManager;
  13.  import net.sf.l2j.gameserver.communitybbs.Manager.TopicBBSManager;
  14.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  15. @@ -66,6 +67,10 @@
  16.             TopicBBSManager.getInstance().parseCmd(command, activeChar);
  17.         else if (command.startsWith("_bbsposts"))
  18.             PostBBSManager.getInstance().parseCmd(command, activeChar);
  19. +       else if ((command.equals("_bbsShowRepair")) || (command.startsWith("_bbsRepair")))
  20. +       {
  21. +           RepairBBSManager.getInstance().parseCmd(command, activeChar);
  22. +       }
  23.         else
  24.             BaseBBSManager.separateAndSend("<html><body><br><br><center>The command: " + command + " isn't implemented.</center></body></html>", activeChar);
  25.     }
  26. Index: java/net/sf/l2j/gameserver/communitybbs/Manager/RepairBBSManager.java
  27. ===================================================================
  28. --- java/net/sf/l2j/gameserver/communitybbs/Manager/RepairBBSManager.java   (revision 0)
  29. +++ java/net/sf/l2j/gameserver/communitybbs/Manager/RepairBBSManager.java   (working copy)
  30. @@ -0,0 +1,302 @@
  31. +package net.sf.l2j.gameserver.communitybbs.Manager;
  32. +
  33. +import java.sql.Connection;
  34. +import java.sql.PreparedStatement;
  35. +import java.sql.ResultSet;
  36. +import java.sql.SQLException;
  37. +import java.util.StringTokenizer;
  38. +import java.util.logging.Logger;
  39. +
  40. +import net.sf.l2j.L2DatabaseFactory;
  41. +import net.sf.l2j.gameserver.cache.HtmCache;
  42. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  43. +
  44. +public class RepairBBSManager extends BaseBBSManager
  45. +{
  46. +   private static final Logger _log = Logger.getLogger(RepairBBSManager.class.getName());
  47. +  
  48. +   public static RepairBBSManager getInstance()
  49. +   {
  50. +       return SingletonHolder._instance;
  51. +   }
  52. +  
  53. +   @Override
  54. +   public void parseCmd(String command, L2PcInstance activeChar)
  55. +   {
  56. +       if (command.equals("_bbsShowRepair"))
  57. +       {
  58. +           showRepairWindow(activeChar);
  59. +       }
  60. +       else if (command.startsWith("_bbsRepair"))
  61. +       {
  62. +           StringTokenizer st = new StringTokenizer(command);
  63. +           st.nextToken();
  64. +           String repairChar = st.nextToken();
  65. +           if (repairChar == null)
  66. +           {
  67. +               activeChar.sendMessage("Please first select character to be repaired.");
  68. +               return;
  69. +           }
  70. +           if (checkAcc(activeChar, repairChar))
  71. +           {
  72. +               if (checkChar(activeChar, repairChar))
  73. +               {
  74. +                   activeChar.sendMessage("You cannot repair your self.");
  75. +                   return;
  76. +               }
  77. +               if (checkJail(activeChar, repairChar))
  78. +               {
  79. +                   activeChar.sendMessage("The character that you are attempting to repair is in jail and this function cannot be used to help him.");
  80. +                   return;
  81. +               }
  82. +               repairBadCharacter(repairChar);
  83. +               separateAndSend(HtmCache.getInstance().getHtm("data/html/CommunityBoard/top/repaired.htm"), activeChar);
  84. +           }
  85. +           else
  86. +           {
  87. +               activeChar.sendMessage("Something went wrong. Please contact with the server's administrator.");
  88. +               return;
  89. +           }
  90. +       }
  91. +       else
  92. +       {
  93. +           super.parseCmd(command, activeChar);
  94. +       }
  95. +   }
  96. +  
  97. +   private static void showRepairWindow(L2PcInstance activeChar)
  98. +   {
  99. +       String content = HtmCache.getInstance().getHtm("data/html/CommunityBoard/top/repair.htm");
  100. +      
  101. +       content = content.replaceAll("%acc_chars%", getCharList(activeChar));
  102. +       separateAndSend(content, activeChar);
  103. +   }
  104. +  
  105. +   private static String getCharList(L2PcInstance activeChar)
  106. +   {
  107. +       String result = "";
  108. +       String repCharAcc = activeChar.getAccountName();
  109. +       Connection con = null;
  110. +       try
  111. +       {
  112. +           con = L2DatabaseFactory.getInstance().getConnection();
  113. +           PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters WHERE account_name=?");
  114. +           statement.setString(1, repCharAcc);
  115. +           ResultSet rset = statement.executeQuery();
  116. +           while (rset.next())
  117. +           {
  118. +               if (activeChar.getName().compareTo(rset.getString(1)) != 0)
  119. +               {
  120. +                   result = result + rset.getString(1) + ";";
  121. +               }
  122. +           }
  123. +           rset.close();
  124. +           statement.close();
  125. +       }
  126. +       catch (SQLException e)
  127. +       {
  128. +           e.printStackTrace();
  129. +           return result;
  130. +       }
  131. +       finally
  132. +       {
  133. +           if (con != null)
  134. +               try
  135. +               {
  136. +                   con.close();
  137. +               }
  138. +               catch (SQLException e)
  139. +               {
  140. +                   e.printStackTrace();
  141. +               }
  142. +       }
  143. +       return result;
  144. +   }
  145. +  
  146. +   @SuppressWarnings("null")
  147. +   private static boolean checkAcc(L2PcInstance activeChar, String repairChar)
  148. +   {
  149. +       boolean result = false;
  150. +       String repCharAcc = "";
  151. +       Connection con = null;
  152. +       try
  153. +       {
  154. +           con = L2DatabaseFactory.getInstance().getConnection();
  155. +           PreparedStatement statement = con.prepareStatement("SELECT account_name FROM characters WHERE char_name=?");
  156. +           statement.setString(1, repairChar);
  157. +           ResultSet rset = statement.executeQuery();
  158. +           if (rset.next())
  159. +           {
  160. +               repCharAcc = rset.getString(1);
  161. +           }
  162. +           rset.close();
  163. +           statement.close();
  164. +           try
  165. +           {
  166. +               if (con != null)
  167. +               {
  168. +                   con.close();
  169. +               }
  170. +           }
  171. +           catch (SQLException e)
  172. +           {
  173. +               e.printStackTrace();
  174. +           }
  175. +           if (activeChar.getAccountName().compareTo(repCharAcc) != 0)
  176. +           {
  177. +               return result;
  178. +           }
  179. +       }
  180. +       catch (SQLException e)
  181. +       {
  182. +           e.printStackTrace();
  183. +           return result;
  184. +       }
  185. +       finally
  186. +       {
  187. +           try
  188. +           {
  189. +               if (con != null)
  190. +               {
  191. +                   con.close();
  192. +               }
  193. +           }
  194. +           catch (SQLException e)
  195. +           {
  196. +               e.printStackTrace();
  197. +           }
  198. +       }
  199. +       result = true;
  200. +       return result;
  201. +   }
  202. +  
  203. +   @SuppressWarnings("null")
  204. +   private static boolean checkJail(L2PcInstance activeChar, String repairChar)
  205. +   {
  206. +       boolean result = false;
  207. +       int repCharJail = 0;
  208. +       Connection con = null;
  209. +       try
  210. +       {
  211. +           con = L2DatabaseFactory.getInstance().getConnection();
  212. +           PreparedStatement statement = con.prepareStatement("SELECT punish_level FROM characters WHERE char_name=?");
  213. +           statement.setString(1, repairChar);
  214. +           ResultSet rset = statement.executeQuery();
  215. +           if (rset.next())
  216. +           {
  217. +               repCharJail = rset.getInt(1);
  218. +           }
  219. +           rset.close();
  220. +           statement.close();
  221. +           try
  222. +           {
  223. +               if (con != null)
  224. +               {
  225. +                   con.close();
  226. +               }
  227. +           }
  228. +           catch (SQLException e)
  229. +           {
  230. +               e.printStackTrace();
  231. +           }
  232. +           if (repCharJail <= 1)
  233. +           {
  234. +               return result;
  235. +           }
  236. +       }
  237. +       catch (SQLException e)
  238. +       {
  239. +           e.printStackTrace();
  240. +           return result;
  241. +       }
  242. +       finally
  243. +       {
  244. +           try
  245. +           {
  246. +               if (con != null)
  247. +               {
  248. +                   con.close();
  249. +               }
  250. +           }
  251. +           catch (SQLException e)
  252. +           {
  253. +               e.printStackTrace();
  254. +           }
  255. +       }
  256. +       result = true;
  257. +       return result;
  258. +   }
  259. +  
  260. +   private static boolean checkChar(L2PcInstance activeChar, String repairChar)
  261. +   {
  262. +       boolean result = false;
  263. +       if (activeChar.getName().compareTo(repairChar) == 0)
  264. +       {
  265. +           result = true;
  266. +       }
  267. +       return result;
  268. +   }
  269. +  
  270. +   private static void repairBadCharacter(String charName)
  271. +   {
  272. +       Connection con = null;
  273. +       try
  274. +       {
  275. +           con = L2DatabaseFactory.getInstance().getConnection();
  276. +          
  277. +           PreparedStatement statement = con.prepareStatement("SELECT obj_Id FROM characters WHERE char_name=?");
  278. +           statement.setString(1, charName);
  279. +           ResultSet rset = statement.executeQuery();
  280. +          
  281. +           int objId = 0;
  282. +           if (rset.next())
  283. +           {
  284. +               objId = rset.getInt(1);
  285. +           }
  286. +           rset.close();
  287. +           statement.close();
  288. +           if (objId == 0)
  289. +           {
  290. +               con.close();
  291. +               return;
  292. +           }
  293. +           statement = con.prepareStatement("UPDATE characters SET x=17867, y=170259, z=-3503 WHERE obj_Id=?");
  294. +           statement.setInt(1, objId);
  295. +           statement.execute();
  296. +           statement.close();
  297. +           statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE char_obj_id=?");
  298. +           statement.setInt(1, objId);
  299. +           statement.execute();
  300. +           statement.close();
  301. +           statement = con.prepareStatement("UPDATE items SET loc=\"WAREHOUSE\" WHERE owner_id=? AND loc=\"PAPERDOLL\"");
  302. +           statement.setInt(1, objId);
  303. +           statement.execute();
  304. +           statement.close();
  305. +           return;
  306. +       }
  307. +       catch (Exception e)
  308. +       {
  309. +           _log.warning("GameServer: could not repair character:" + e);
  310. +       }
  311. +       finally
  312. +       {
  313. +          
  314. +           try
  315. +           {
  316. +               if (con != null)
  317. +               {
  318. +                   con.close();
  319. +               }
  320. +           }
  321. +           catch (SQLException e)
  322. +           {
  323. +               e.printStackTrace();
  324. +           }
  325. +       }
  326. +   }
  327. +  
  328. +   private static class SingletonHolder
  329. +   {
  330. +       protected static final RepairBBSManager _instance = new RepairBBSManager();
  331. +   }
  332. +}
  333. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment