Guest User

Online Record - Core

a guest
Aug 12th, 2010
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.25 KB | None | 0 0
  1. Index: /trunk/Game/java/realtek/gameserver/model/actor/instance/L2PcInstance.java
  2. ===================================================================
  3. --- /trunk/Game/java/realtek/gameserver/model/actor/instance/L2PcInstance.java (revision 608)
  4. +++ /trunk/Game/java/realtek/gameserver/model/actor/instance/L2PcInstance.java (revision 610)
  5. @@ -61,4 +61,5 @@
  6.  import realtek.gameserver.datatables.NobleSkillTable;
  7.  import realtek.gameserver.datatables.NpcTable;
  8. +import realtek.gameserver.datatables.RecordTable;
  9.  import realtek.gameserver.datatables.SkillTable;
  10.  import realtek.gameserver.datatables.SkillTreeTable;
  11. @@ -5608,4 +5609,13 @@
  12.             statement.execute();
  13.             statement.close();
  14. +           if (isOnline() == 1)
  15. +           {
  16. +               int newPlayer = L2World.getInstance().getAllPlayers().size() + 1;
  17. +               int maxPlayer = RecordTable.getInstance().getMaxPlayer();
  18. +               if (newPlayer > maxPlayer)
  19. +               {
  20. +                   RecordTable.getInstance().setMaxPlayer(newPlayer);
  21. +               }
  22. +           }
  23.         }
  24.         catch (Exception e)
  25. Index: /trunk/Game/java/realtek/gameserver/datatables/RecordTable.java
  26. ===================================================================
  27. --- /trunk/Game/java/realtek/gameserver/datatables/RecordTable.java (revision 610)
  28. +++ /trunk/Game/java/realtek/gameserver/datatables/RecordTable.java (revision 610)
  29. @@ -0,0 +1,109 @@
  30. +/*
  31. + * This program is free software: you can redistribute it and/or modify it under
  32. + * the terms of the GNU General Public License as published by the Free Software
  33. + * Foundation, either version 3 of the License, or (at your option) any later
  34. + * version.
  35. + *
  36. + * This program is distributed in the hope that it will be useful, but WITHOUT
  37. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  38. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  39. + * details.
  40. + *
  41. + * You should have received a copy of the GNU General Public License along with
  42. + * this program. If not, see <http://www.gnu.org/licenses/>.
  43. + */
  44. +package realtek.gameserver.datatables;
  45. +
  46. +import java.sql.Connection;
  47. +import java.sql.PreparedStatement;
  48. +import java.sql.ResultSet;
  49. +import java.util.logging.Level;
  50. +import java.util.logging.Logger;
  51. +
  52. +/**
  53. + *@author Realtek
  54. + */
  55. +
  56. +import realtek.L2DatabaseFactory;
  57. +
  58. +public class RecordTable
  59. +{
  60. +   private final static Logger _log = Logger.getLogger(RecordTable.class.getName());
  61. +  
  62. +   private static RecordTable _instance;
  63. +   private int _maxPlayer = 0;
  64. +   private String _strDateMaxPlayer = null;
  65. +  
  66. +   public static RecordTable getInstance()
  67. +   {
  68. +       if (_instance == null)
  69. +           _instance = new RecordTable();
  70. +       return _instance;
  71. +   }
  72. +  
  73. +   private RecordTable()
  74. +   {
  75. +       restoreRecordData();
  76. +   }
  77. +  
  78. +   private void restoreRecordData()
  79. +   {
  80. +       Connection con = null;
  81. +       try
  82. +       {
  83. +           con = L2DatabaseFactory.getInstance().getConnection();
  84. +          
  85. +           PreparedStatement statement = con.prepareStatement("SELECT maxplayer, date FROM record ORDER by maxplayer desc limit 1");
  86. +           ResultSet recorddata = statement.executeQuery();
  87. +           fillRecordTable(recorddata);
  88. +           recorddata.close();
  89. +           statement.close();
  90. +       }
  91. +       catch (Exception e)
  92. +       {
  93. +           _log.log(Level.SEVERE, "Error while restoring Record table: " + e.getMessage(), e);
  94. +       }
  95. +       finally
  96. +       {
  97. +           try { con.close(); } catch (Exception e) {}
  98. +       }
  99. +   }
  100. +  
  101. +   private void fillRecordTable(ResultSet Recorddata) throws Exception
  102. +   {
  103. +       while (Recorddata.next())
  104. +       {
  105. +           _maxPlayer = Recorddata.getInt("maxplayer");
  106. +           _strDateMaxPlayer = Recorddata.getString("date");
  107. +       }
  108. +   }
  109. +  
  110. +   public int getMaxPlayer()
  111. +   {
  112. +       return _maxPlayer;
  113. +   }
  114. +  
  115. +   public void setMaxPlayer(int maxPlayer)
  116. +   {
  117. +       _maxPlayer = maxPlayer;
  118. +       Connection con = null;
  119. +       try
  120. +       {
  121. +           con = L2DatabaseFactory.getInstance().getConnection();
  122. +          
  123. +           PreparedStatement statement = con.prepareStatement("INSERT INTO record(maxplayer,date) VALUES(?,NOW())");
  124. +           statement.setInt(1, maxPlayer);
  125. +           statement.execute();
  126. +           statement.close();
  127. +       }
  128. +       catch (Exception e)
  129. +       {
  130. +           _log.log(Level.SEVERE, "Error while adding info at Record table: " + e.getMessage(), e);
  131. +       }
  132. +       finally
  133. +       {
  134. +           try { con.close(); } catch (Exception e) {}
  135. +       }
  136. +   }
  137. +  
  138. +   public String getDateMaxPlayer()
  139. +   {
  140. +       return _strDateMaxPlayer;
  141. +   }
  142. +}
Advertisement
Add Comment
Please, Sign In to add comment