Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: net.sf.l2j;Config.java
- ===================================================================
- --- net.sf.l2j;Config.java (revision 84)
- +++ net.sf.l2j;Config.java (working copy)
- + public static final int REWARD_PER_TIME_MODE_RESTRICTION = 2;
- Index: l2jban.renwalday;;DailyRewardManager.java
- ===================================================================
- --- l2jban.renwalday;;DailyRewardManager.java (revision 84)
- +++ l2jban.renwalday;;DailyRewardManager.java (working copy)
- + package l2jban.renwalday;
- +
- + import java.sql.Connection;
- + import java.sql.Date;
- + import java.sql.PreparedStatement;
- + import java.sql.ResultSet;
- + import java.sql.SQLException;
- + import java.text.SimpleDateFormat;
- + import java.util.Calendar;
- +
- + import net.sf.l2j.commons.concurrent.ThreadPool;
- +
- + import net.sf.l2j.Config;
- + import net.sf.l2j.L2DatabaseFactory;
- +
- + import net.sf.l2j.gameserver.model.actor.Player;
- + import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- +
- + /**
- + * @author Gabia
- + *
- + */
- + public class DailyRewardManager
- + {
- + private static int rewardId = 3470;
- +
- + protected DailyRewardManager()
- + {
- + loadSystemThread();
- +
- + System.out.println("Daily Reward Manager: Loaded");
- + }
- +
- + protected static void loadSystemThread()
- + {
- + long spawnMillis = 0;
- +
- + Calendar c = Calendar.getInstance();
- +
- + String[] time = "24:00".split(":");
- + c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH)+1);
- + c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[0]));
- + c.set(Calendar.MINUTE, Integer.parseInt(time[1]));
- + c.set(Calendar.SECOND, 0);
- + spawnMillis = c.getTimeInMillis() - System.currentTimeMillis();
- +
- + ThreadPool.schedule(new Runnable()
- + {
- + @Override
- + public void run()
- + {
- + clearDBTable();
- +
- + // Reload the system
- + loadSystemThread();
- +
- + System.out.println("[Daily Reward] Table cleaned and restart the thread.");
- + }
- + }, spawnMillis);
- + }
- +
- + @SuppressWarnings("resource")
- + protected static void clearDBTable()
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + PreparedStatement statement = con.prepareStatement("DELETE FROM reward_manager");
- + statement.execute();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public static void initialAllEngines(Player activeChar)
- + {
- + if(checkIfIPorHWIDExistInDB(activeChar, "ip") || checkIfIPorHWIDExistInDB(activeChar, "hwid"))
- + {
- + if(DailyRewardManager.checkForLatestHWIDReward(activeChar, "ip") || DailyRewardManager.checkForLatestHWIDReward(activeChar, "hwid")) // Rewarded
- + {
- + if(DailyRewardManager.checkForLatestHWIDReward(activeChar, "ip"))
- + activeChar.sendMessage("Join again in "+Cd(activeChar, "ip", false)+" to get your daily reward.");
- + else if(DailyRewardManager.checkForLatestHWIDReward(activeChar, "hwid"))
- + activeChar.sendMessage("Join again in "+Cd(activeChar, "hwid", false)+" to get your daily reward.");
- + }
- + else { // Not rewarded
- +
- + openDailyRewardHtml(activeChar);
- + }
- + }
- + else // If not exist in Database
- + {
- + openDailyRewardHtml(activeChar);
- + }
- + }
- +
- + public void claimDailyReward(Player player)
- + {
- + if(checkIfIPorHWIDExistInDB(player, "ip") || checkIfIPorHWIDExistInDB(player, "hwid"))
- + {
- + if(DailyRewardManager.checkForLatestHWIDReward(player, "ip") || DailyRewardManager.checkForLatestHWIDReward(player, "hwid")) // Rewarded
- + {
- + if(DailyRewardManager.checkForLatestHWIDReward(player, "ip"))
- + player.sendMessage("Join in "+Cd(player, "ip", false)+" to get your reward.");
- + else if(DailyRewardManager.checkForLatestHWIDReward(player, "hwid"))
- + player.sendMessage("Join in "+Cd(player, "hwid", false)+" to get your reward.");
- + }
- + else { // Not rewarded
- + //System.out.println("Not rewarded");
- + if(checkIfIPorHWIDExistInDB(player, "ip"))
- + updateLastReward(player, "ip");
- +
- + if(checkIfIPorHWIDExistInDB(player, "hwid"))
- + updateLastReward(player, "hwid");
- +
- + giveReward(player);
- + }
- + }
- + else // Insert new Parent and reward
- + {
- + insertNewParentOfPlayerIPHWID(player);
- + giveReward(player);
- + }
- +
- +
- + }
- +
- + private static void openDailyRewardHtml(Player player)
- + {
- + NpcHtmlMessage htm = new NpcHtmlMessage(0);
- + htm.setFile("data/html/dailyrewards/index.htm");
- + htm.replace("", "");
- + player.sendPacket(htm);
- + }
- +
- + /**
- + * @param player
- + *
- + */
- + private static void giveReward(Player player)
- + {
- + player.addItem("HWIDRewardManager", rewardId, 1, null, true);
- +
- + /*player.sendMessage("You are rewarded from daily reward.");
- + for(double infos[] : Config.REWARD_PER_TIME_ITEMLIST)
- + {
- + int chanceIndex = (int) (infos[2] * 1000);
- +
- + if (Rnd.get(100000) <= chanceIndex)
- + {
- + int itemId = (int) infos[0];
- + int itemCount = (int) infos[1];
- +
- + player.addItem("HWIDRewardManager", itemId, itemCount, null, true);
- + }
- + }*/
- + }
- +
- + @SuppressWarnings("unused")
- + private static boolean checkForLatestHWIDReward(Player activeChar, String mode)
- + {
- + if(Config.REWARD_PER_TIME_MODE_RESTRICTION == 0 && mode.equals("hwid"))
- + return false;
- +
- + if(Config.REWARD_PER_TIME_MODE_RESTRICTION == 1 && mode.equals("ip"))
- + return false;
- +
- + //System.out.println("Config: "+Config.REWARD_PER_TIME_MODE_RESTRICTION+" Mode Check: "+mode);
- + return Long.parseLong(Cd(activeChar, mode, true)) > System.currentTimeMillis();
- + }
- +
- + @SuppressWarnings("resource")
- + private static void updateLastReward(Player player, String mode)
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + PreparedStatement statement = con.prepareStatement("UPDATE reward_manager SET expire_time=? WHERE "+mode+"=?");
- + statement.setLong(1, System.currentTimeMillis());
- + statement.setString(2, (mode.equals("ip") ? player.getIP() : player.getHWID()));
- + statement.execute();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + @SuppressWarnings("resource")
- + private static String Cd(Player player, String mode, boolean returnInTimestamp)
- + {
- + long CdMs = 0;
- + long voteDelay = 1440 * 60000L;
- +
- + PreparedStatement statement = null;
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + statement = con.prepareStatement("SELECT expire_time FROM reward_manager WHERE "+mode+"=?");
- + statement.setString(1, (mode.equals("ip") ? player.getIP() : player.getHWID()));
- +
- + ResultSet rset = statement.executeQuery();
- +
- + while (rset.next())
- + {
- + CdMs = rset.getLong("expire_time");
- + }
- +
- + if((CdMs + voteDelay) < System.currentTimeMillis())
- + CdMs = System.currentTimeMillis() - voteDelay;
- +
- + rset.close();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if(statement != null)
- + statement.close();
- + }
- + catch (SQLException e)
- + {
- + // TODO Auto-generated catch block
- + e.printStackTrace();
- + }
- + }
- +
- + SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
- +
- + if(returnInTimestamp)
- + return String.valueOf(CdMs+voteDelay);
- +
- + Date resultdate = new Date(CdMs + voteDelay);
- + return sdf.format(resultdate);
- + }
- +
- + @SuppressWarnings("resource")
- + private static boolean checkIfIPorHWIDExistInDB(Player player, String mode)
- + {
- + boolean flag = false;
- + PreparedStatement statement = null;
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + statement = con.prepareStatement("SELECT * FROM reward_manager WHERE "+mode+"=?");
- + statement.setString(1, (mode.equals("ip") ? player.getIP() : player.getHWID()));
- +
- + ResultSet rset = statement.executeQuery();
- +
- + if (rset.next())
- + flag = true;
- +
- + rset.close();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if(statement != null)
- + statement.close();
- + }
- + catch (SQLException e)
- + {
- + // TODO Auto-generated catch block
- + e.printStackTrace();
- + }
- + }
- +
- + return flag;
- + }
- +
- + @SuppressWarnings("resource")
- + private static void insertNewParentOfPlayerIPHWID(Player player)
- + {
- + PreparedStatement statement = null;
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + statement = con.prepareStatement("INSERT INTO reward_manager (ip,hwid,expire_time) VALUES (?,?,?)");
- + statement.setString(1, player.getIP());
- + statement.setString(2, player.getHWID());
- + statement.setLong(3, System.currentTimeMillis());
- + statement.execute();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + finally
- + {
- + try
- + {
- + if(statement != null)
- + statement.close();
- + }
- + catch (SQLException e)
- + {
- + // TODO Auto-generated catch block
- + e.printStackTrace();
- + }
- + }
- + }
- +
- + public static DailyRewardManager getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final DailyRewardManager _instance = new DailyRewardManager();
- + }
- +
- + }
- +
- +
- Index: net.sf.l2j.gameserver.model.actor;Player.java
- ===================================================================
- --- net.sf.l2j.gameserver.model.actor;Player.java (revision 84)
- +++ net.sf.l2j.gameserver.model.actor;Player.java (working copy)
- private static final String UPDATE_CHARACTER
- +lasthwid=? WHERE obj_id=?";
- public static Player restore(int objectId)
- {
- Player player = null;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(RESTORE_CHARACTER))
- - player.setPledgeType(rs.getInt("subpledge"));
- + player.setPledgeType(rs.getInt("subpledge"));
- + player.setLastHWID(rs.getString("lasthwid"));
- + private String lasthwid = ""; // Empty String
- +
- + public void setLastHWID(String val)
- + {
- + lasthwid = val;
- + }
- +
- + public String getLastHWID()
- + {
- + return lasthwid;
- + }
- + public String getHWID()
- + {
- + return getClient().getHWID() != null ? getClient().getHWID() : this.getName();
- + }
- +
- + public String getIP()
- + {
- + if(getClient().getConnection() == null)
- + return "N/A IP";
- +
- + return getClient().getConnection().getInetAddress().getHostAddress();
- + }
- Index: net.sf.l2j.gameserver.network;GameClient.java
- ===================================================================
- --- net.sf.l2j.gameserver.network;GameClient.java (revision 84)
- +++ net.sf.l2j.gameserver.network;GameClient.java (working copy)
- + private String _hwid;
- + public void setHWID(String value)
- + {
- + _hwid = value;
- + }
- +
- + public String getHWID()
- + {
- + return _hwid;
- + }
- Index: net.sf.l2j.gameserver;GameServer.java
- ===================================================================
- --- net.sf.l2j.gameserver;GameServer.java (revision 84)
- +++ net.sf.l2j.gameserver;GameServer.java (working copy)
- + import l2jban.renwalday.DailyRewardManager;
- +
- +
- + DailyRewardManager.getInstance();
- Index: net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java
- ===================================================================
- --- net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java (revision 84)
- +++ net.sf.l2j.gameserver.network.clientpackets;EnterWorld.java (working copy)
- + import l2jban.renwalday.DailyRewardManager.java
- + // Daily Reward System
- + DailyRewardManager.initialAllEngines(activeChar);
- Index: net.sf.l2j.gameserver.network.clientpackets;;RequestBypassToServer.java
- ===================================================================
- --- net.sf.l2j.gameserver.network.clientpackets;;RequestBypassToServer.java (revision 84)
- +++ net.sf.l2j.gameserver.network.clientpackets;;RequestBypassToServer.java (working copy)
- + import l2jban.renwalday.DailyRewardManager.java
- - else if (_command.startsWith("arenachange")) // change
- - {
- - final boolean isManager = activeChar.getCurrentFolkNPC() instanceof OlympiadManagerNpc;
- - if (!isManager)
- - {
- - // Without npc, command can be used only in observer mode on arena
- - if (!activeChar.isInObserverMode() || activeChar.isInOlympiadMode() || activeChar.getOlympiadGameId() < 0)
- - return;
- - }
- -
- - if (OlympiadManager.getInstance().isRegisteredInComp(activeChar))
- - {
- - activeChar.sendPacket(SystemMessageId.WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
- - return;
- - }
- -
- - final int arenaId = Integer.parseInt(_command.substring(12).trim());
- - activeChar.enterOlympiadObserverMode(arenaId);
- - }
- + else if (_command.startsWith("arenachange")) // change
- + {
- + final boolean isManager = activeChar.getCurrentFolkNPC() instanceof OlympiadManagerNpc;
- + if (!isManager)
- + {
- + // Without npc, command can be used only in observer mode on arena
- + if (!activeChar.isInObserverMode() || activeChar.isInOlympiadMode() || activeChar.getOlympiadGameId() < 0)
- + return;
- + }
- +
- + if (OlympiadManager.getInstance().isRegisteredInComp(activeChar))
- + {
- + activeChar.sendPacket(SystemMessageId.WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
- + return;
- + }
- +
- + final int arenaId = Integer.parseInt(_command.substring(12).trim());
- + activeChar.enterOlympiadObserverMode(arenaId);
- + }
- + else if (_command.startsWith("claimDailyReward"))
- + {
- + DailyRewardManager.getInstance().claimDailyReward(activeChar);
- + }
- Index: data/html/dailyrewards/index.htm
- ===================================================================
- --- data/html/dailyrewards/index.htm (revision 84)
- +++ data/html/dailyrewards/index.htm (working copy)
- + <html>
- + <title>
- + Daily Reward
- + </title>
- + <body>
- + <center>
- + <br>
- + <img src="l2ui.squaregray" width="295" height="1">
- +
- + <font color=LEVEL>Claim your daily chest reward</font>
- + <br>
- + <font color="ff6600">Reset Every 24:00 AM</font>
- + <br>
- +
- + <img src="icon.etc_treasure_box_i02" width=32 height=32>
- + <br><br>
- +
- + <button value="Claim Daily Reward" action="bypass -h claimDailyReward" width=204 height=19 back="ban.btn_over" fore="ban.btn">
- +
- +
- + <img src="l2ui.squaregray" width="295" height="1">
- + <br>
- + <br>
- + <img src="l2ui.squaregray" width="295" height="1">
- + <table width=295 bgcolor="000000">
- + <tr>
- + <td align=center><img src=FondosDevs.domain width=300 height=20></td>
- + </tr>
- + </table>
- + </center>
- + </body>
- + </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement