Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/L2J_Mobius_C6_Interlude/dist/game/config/custom/votesystem.ini b/L2J_Mobius_C6_Interlude/dist/game/config/custom/votesystem.ini
- new file mode 100644
- index 0000000..3ea8d39
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/dist/game/config/custom/votesystem.ini
- @@ -0,0 +1,95 @@
- +EnableVoteSystem = True
- +
- +EnableGlobalVote = True
- +
- +EnableIndividualVote = True
- +
- +## Time to Update table totalVotes from DB
- +NextTimeToAutoUpdateTotalVote = 2
- +
- +## Time to update table individualVotes
- +NextTimeToAutoUpdateIndividualVotes = 2
- +
- +NextTimeToAutoCleanInnecesaryVotes = 30
- +
- +NextTimeToCheckAutoGlobalVotesReward = 1
- +
- +IntervalTimeToNextVote = 12
- +
- +GlobalVotesAmountToNextReward = 1
- +
- +EnableVotingCommand = True
- +
- +VotingCommand = getreward
- +
- +## l2.topgameserver.net
- +VoteLinkTgs = http://l2.topgameserver.net/lineage/VoteApi/
- +
- +TgsApiKey =
- +
- +## l2top.co
- +VoteLinkTopCo = https://l2top.co/reward/
- +
- +TopCoSrvId =
- +
- +## ITopz.com
- +VoteLinkItopz = https://itopz.com/check/
- +
- +ItopzZpiKey =
- +
- +ItopzSrvId =
- +
- +## l2votes.com
- +VoteLinkVts = https://l2votes.com/
- +
- +VtsApiKey =
- +
- +VtsSid =
- +
- +## Hopzone.net
- +VoteLinkHz = https://api.hopzone.net/lineage2/
- +
- +HzApiKey =
- +
- +## l2network.eu
- +VoteNetworkLink = https://l2network.eu/api.php
- +
- +VoteNetworkUserName =
- +
- +VoteNetworkApiKey =
- +
- +## L2TopServer.com
- +VoteLinkTss = https://l2topservers.com/votes?
- +
- +TssApiToken =
- +
- +TsSrvId = 453
- +
- +TsDomainName= l2catgang
- +
- +## top.l2jbrasil.com
- +BrasilVoteLink = https://top.l2jbrasil.com/votesystem/index.php?
- +
- +BrasilUserName = julioguzman
- +
- +## l2jtop.com
- +VoteLinkMmotop = https://l2jtop.com/api/
- +
- +MmotopApiKey =
- +
- +## L2TopZone.com
- +VoteLinkTz = https://api.l2topzone.com/v1/
- +
- +TzApiKey =
- +
- +## L2Servers.com
- +VoteLinkServers = https://www.l2servers.com/api/
- +
- +ServersHashCode =
- +
- +ServersSrvId =
- +
- +
- +## for local test
- +TestIp =
- +
- diff --git a/L2J_Mobius_C6_Interlude/dist/game/data/html/mods/votesystem/50009.html b/L2J_Mobius_C6_Interlude/dist/game/data/html/mods/votesystem/50009.html
- new file mode 100644
- index 0000000..b2a5624
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/dist/game/data/html/mods/votesystem/50009.html
- @@ -0,0 +1,19 @@
- +<html>
- +<title>Voting panel</title>
- +<body><center>
- + <br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
- + <table cellpadding=2 width=280>
- + <tr><td width="280">Hello <font color="C6AF00">%accountName%</font>, welcome to the voting rewards dashboard, please help us by voting by server every <font color="C6AF00">%everyXtime% hours</font> in all voting sites.</td></tr>
- + </table>
- + <table width="290"><tr><td width="290" align="center">You can vote: </td></tr></table>
- + <br><img src="l2ui.SquareWhite" width=290 height=1><br>
- +
- + %enablevote%
- +
- + <br>
- + <img src="l2ui.SquareWhite" width=290 height=1><br>
- +
- +
- +
- +</center></body>
- +</html>
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/dist/game/data/votesystem.json b/L2J_Mobius_C6_Interlude/dist/game/data/votesystem.json
- new file mode 100644
- index 0000000..dabcc63
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/dist/game/data/votesystem.json
- @@ -0,0 +1,14 @@
- +[
- + {"votesite":{"ordinal":"0","name":"l2.topgameserver.net","timezone":"GMT+2", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"1","name":"Itopz.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"2","name":"L2Top.co","timezone":"GMT+2", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"3","name":"L2Votes.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"4","name":"Hopzone.net","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"5","name":"L2Network.eu","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"6","name":"L2Topservers.com","timezone":"Asia/Tokyo", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"7","name":"top.l2jbrasil.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"8","name":"l2jtop.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"9","name":"L2Topzone.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"10","name":"L2Servers.com","timezone":"GMT", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
- + {"votesite":{"ordinal":"11","name":"globalVotes","timezone":"", "nextvotetime":"12","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}}
- +]
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/dist/libs/json-simple-1.1.1.jar b/L2J_Mobius_C6_Interlude/dist/libs/json-simple-1.1.1.jar
- new file mode 100644
- index 0000000..66347a6
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/dist/libs/json-simple-1.1.1.jar
- Binary files differ
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java
- index b126291..876bcaf 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java
- @@ -33,6 +33,7 @@
- import java.util.List;
- import java.util.Map;
- import java.util.Properties;
- +import java.util.concurrent.TimeUnit;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- @@ -98,6 +99,7 @@
- private static final String SCHEME_BUFFER_CONFIG_FILE = "./config/custom/SchemeBuffer.ini";
- private static final String EVENT_REBIRTH_CONFIG_FILE = "./config/custom/Rebirth.ini";
- private static final String EVENT_WEDDING_CONFIG_FILE = "./config/custom/Wedding.ini";
- + private static final String VOTE_SYSTEM_FILE = "./config/custom/votesystem.ini";
- // login
- private static final String LOGIN_CONFIG_FILE = "./config/main/LoginServer.ini";
- // others
- @@ -509,6 +511,50 @@
- public static boolean GIVE_CUPID_BOW;
- public static boolean ANNOUNCE_WEDDING;
- + // ---------------------------------------------------
- + // VOTE SYSTEM
- + // ---------------------------------------------------
- + public static boolean ENABLE_VOTE_SYSTEM;
- + public static boolean ENABLE_INDIVIDUAL_VOTE;
- + public static boolean ENABLE_GLOBAL_VOTE;
- + public static long NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE;
- + public static long NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES;
- + public static long NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES;
- + public static long NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD;
- + public static long INTERVAL_TO_NEXT_VOTE;
- + public static int GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD;
- + public static boolean ENABLE_VOTING_COMMAND;
- + public static String VOTING_COMMAND;
- + public static String VOTE_LINK_TGS;
- + public static String TGS_API_KEY;
- + public static String VOTE_LINK_TOP_CO;
- + public static String TOP_CO_SRV_ID;
- + public static String VOTE_LINK_ITOPZ;
- + public static String ITOPZ_API_KEY;
- + public static String ITOPZ_SRV_ID;
- + public static String VOTE_LINK_VTS;
- + public static String VTS_API_KEY;
- + public static String VTS_SID;
- + public static String VOTE_LINK_HZ;
- + public static String HZ_API_KEY;
- + public static String VOTE_NETWORK_LINK;
- + public static String VOTE_NETWORK_USER_NAME;
- + public static String VOTE_NETWORK_API_KEY;
- + public static String VOTE_LINK_TSS;
- + public static String TSS_API_TOKEN;
- + public static String TS_SRV_ID;
- + public static String TS_DOMAIN_NAME;
- + public static String BRASIL_VOTE_LINK;
- + public static String BRASIL_USER_NAME;
- + public static String VOTE_LINK_MMOTOP;
- + public static String MMOTOP_API_KEY;
- + public static String VOTE_LINK_TZ;
- + public static String TZ_API_KEY;
- + public static String VOTE_LINK_SERVERS;
- + public static String SERVERS_HASH_CODE;
- + public static String SERVERS_SRV_ID;
- + public static String TEST_IP;
- +
- public static String TVT_EVEN_TEAMS;
- public static boolean TVT_ALLOW_INTERFERENCE;
- public static boolean TVT_ALLOW_POTIONS;
- @@ -1758,6 +1804,53 @@
- ANNOUNCE_WEDDING = weddingConfig.getBoolean("AnnounceWedding", true);
- }
- + public static void loadVoteConfig()
- + {
- + // Load vote system settings
- + final PropertiesParser votesystem = new PropertiesParser(VOTE_SYSTEM_FILE);
- +
- + ENABLE_VOTE_SYSTEM = votesystem.getBoolean("EnableVoteSystem", true);
- + ENABLE_INDIVIDUAL_VOTE = votesystem.getBoolean("EnableIndividualVote", true);
- + ENABLE_GLOBAL_VOTE = votesystem.getBoolean("EnableGlobalVote", true);
- + NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoUpdateTotalVote", 60));// -> minutes
- + NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoUpdateIndividualVotes", 60));// -> minutes
- + NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoCleanInnecesaryVotes", 30));// -> minutes
- + NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToCheckAutoGlobalVotesReward", 5));// -> minutes
- + INTERVAL_TO_NEXT_VOTE = TimeUnit.HOURS.toMillis(votesystem.getInt("IntervalTimeToNextVote", 12)); // -> hours
- + GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = votesystem.getInt("GlobalVotesAmountToNextReward", 50);
- + ENABLE_VOTING_COMMAND = votesystem.getBoolean("EnableVotingCommand", true);
- + VOTING_COMMAND = votesystem.getString("VotingCommand", "getreward");
- + VOTE_LINK_TGS = votesystem.getString("VoteLinkTgs", "");
- + TGS_API_KEY = votesystem.getString("TgsApiKey", "");
- + VOTE_LINK_TOP_CO = votesystem.getString("VoteLinkTopCo", "");
- + TOP_CO_SRV_ID = votesystem.getString("TopCoSrvId", "");
- + VOTE_LINK_ITOPZ = votesystem.getString("VoteLinkItopz", "");
- + ITOPZ_API_KEY = votesystem.getString("ItopzZpiKey", "");
- + ITOPZ_SRV_ID = votesystem.getString("ItopzSrvId", "");
- + VOTE_LINK_VTS = votesystem.getString("VoteLinkVts", "");
- + VTS_API_KEY = votesystem.getString("VtsApiKey", "");
- + VTS_SID = votesystem.getString("VtsSid", "");
- + VOTE_LINK_HZ = votesystem.getString("VoteLinkHz", "");
- + HZ_API_KEY = votesystem.getString("HzApiKey", "");
- + VOTE_NETWORK_LINK = votesystem.getString("VoteNetworkLink", "");
- + VOTE_NETWORK_USER_NAME = votesystem.getString("VoteNetworkUserName", "");
- + VOTE_NETWORK_API_KEY = votesystem.getString("VoteNetworkApiKey", "");
- + VOTE_LINK_TSS = votesystem.getString("VoteLinkTss", "");
- + TSS_API_TOKEN = votesystem.getString("TssApiToken", "");
- + TS_SRV_ID = votesystem.getString("TsSrvId", "");
- + TS_DOMAIN_NAME = votesystem.getString("TsDomainName", "");
- + BRASIL_VOTE_LINK = votesystem.getString("BrasilVoteLink", "");
- + BRASIL_USER_NAME = votesystem.getString("BrasilUserName", "");
- + VOTE_LINK_MMOTOP = votesystem.getString("VoteLinkMmotop", "");
- + MMOTOP_API_KEY = votesystem.getString("MmotopApiKey", "");
- + VOTE_LINK_TZ = votesystem.getString("VoteLinkTz", "");
- + TZ_API_KEY = votesystem.getString("TzApiKey", "");
- + VOTE_LINK_SERVERS = votesystem.getString("VoteLinkServers", "");
- + SERVERS_HASH_CODE = votesystem.getString("ServersHashCode", "");
- + SERVERS_SRV_ID = votesystem.getString("ServersSrvId", "");
- + TEST_IP = votesystem.getString("TestIp", "");
- + }
- +
- public static void loadTVTConfig()
- {
- final PropertiesParser tvtConfig = new PropertiesParser(EVENT_TVT_CONFIG_FILE);
- @@ -3190,6 +3283,7 @@
- loadAutoPotionsConfig();
- loadCustomMailManagerConfig();
- loadMerchantZeroPriceConfig();
- + loadVoteConfig();
- loadWeddingConfig();
- loadRebirthConfig();
- loadBankingConfig();
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/StatsSet.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/StatsSet.java
- new file mode 100644
- index 0000000..cb54758
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/util/StatsSet.java
- @@ -0,0 +1,91 @@
- +/*
- + * This file is part of the L2J Mobius project.
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU General Public License as published by
- + * the Free Software Foundation, either version 3 of the License, or
- + * (at your option) any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * General Public License for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * along with this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package org.l2jmobius.commons.util;
- +
- +import java.util.HashMap;
- +
- +/**
- + * @author escor
- + */
- +public class StatsSet extends HashMap<String, Object>
- +{
- +
- + public StatsSet()
- + {
- + super();
- + }
- +
- + public StatsSet(final StatsSet set)
- + {
- + super(set);
- + }
- +
- + public void set(final String key, final Object value)
- + {
- + put(key, value);
- + }
- +
- + public void set(final String key, final int value)
- + {
- + put(key, value);
- + }
- +
- + public void set(final String key, final int[] value)
- + {
- + put(key, value);
- + }
- +
- + public int getInteger(final String key)
- + {
- + final Object val = get(key);
- +
- + if (val instanceof Number)
- + {
- + return ((Number) val).intValue();
- + }
- + if (val instanceof String)
- + {
- + return Integer.parseInt((String) val);
- + }
- + if (val instanceof Boolean)
- + {
- + return (Boolean) val ? 1 : 0;
- + }
- +
- + throw new IllegalArgumentException("StatsSet : Integer value required, but found: " + val + " for key: " + key + ".");
- + }
- +
- + public int getInteger(final String key, final int defaultValue)
- + {
- + final Object val = get(key);
- +
- + if (val instanceof Number)
- + {
- + return ((Number) val).intValue();
- + }
- + if (val instanceof String)
- + {
- + return Integer.parseInt((String) val);
- + }
- + if (val instanceof Boolean)
- + {
- + return (Boolean) val ? 1 : 0;
- + }
- +
- + return defaultValue;
- + }
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
- index 72f2e67..806f612 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
- @@ -131,6 +131,8 @@
- import org.l2jmobius.gameserver.scripting.ScriptEngineManager;
- import org.l2jmobius.gameserver.taskmanager.TaskManager;
- import org.l2jmobius.gameserver.ui.Gui;
- +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
- +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
- import org.l2jmobius.telnet.TelnetStatusThread;
- public class GameServer
- @@ -331,6 +333,18 @@
- FortSiegeManager.getInstance();
- CrownManager.getInstance();
- + Util.printSection("Vote Reward System");
- + if (Config.ENABLE_VOTE_SYSTEM)
- + {
- + voteManager.getInatance();
- + LOGGER.info("======================Vote System Enabled=========================");
- + ReadJson.getInstance();
- + }
- + else
- + {
- + LOGGER.info("======================Vote System Disabled=========================");
- + }
- +
- Util.printSection("Boat");
- BoatData.getInstance();
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java
- index c040922..569a5d9 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/Shutdown.java
- @@ -42,6 +42,7 @@
- import org.l2jmobius.gameserver.network.gameserverpackets.ServerStatus;
- import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
- import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
- +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
- /**
- * This class provides the functions for shutting down and restarting the server.<br>
- @@ -453,6 +454,14 @@
- FishingChampionshipManager.getInstance().shutdown();
- LOGGER.info("Fishing Championship data have been saved!!");
- + // Save invidual votes data
- +
- + if (Config.ENABLE_VOTE_SYSTEM)
- + {
- + voteManager.getInatance().Shutdown();
- + LOGGER.info("Vote data have been saved!!");
- + }
- +
- // Schemes save.
- SchemeBufferTable.getInstance().saveSchemes();
- LOGGER.info("BufferTable data has been saved!!");
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java
- index 9236561..c5b807b 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/VoicedCommandHandler.java
- @@ -31,6 +31,7 @@
- import org.l2jmobius.gameserver.handler.voicedcommandhandlers.Online;
- import org.l2jmobius.gameserver.handler.voicedcommandhandlers.StatsCmd;
- import org.l2jmobius.gameserver.handler.voicedcommandhandlers.TvTCmd;
- +import org.l2jmobius.gameserver.handler.voicedcommandhandlers.VoteReward;
- import org.l2jmobius.gameserver.handler.voicedcommandhandlers.Wedding;
- public class VoicedCommandHandler
- @@ -97,6 +98,11 @@
- registerVoicedCommandHandler(new AutoPotion());
- }
- + if (Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTING_COMMAND)
- + {
- + registerVoicedCommandHandler(new VoteReward());
- + }
- +
- LOGGER.info("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers.");
- }
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/VoteReward.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/VoteReward.java
- new file mode 100644
- index 0000000..ade580a
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/voicedcommandhandlers/VoteReward.java
- @@ -0,0 +1,80 @@
- +/*
- + * This file is part of the L2J Mobius project.
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU General Public License as published by
- + * the Free Software Foundation, either version 3 of the License, or
- + * (at your option) any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * General Public License for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * along with this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package org.l2jmobius.gameserver.handler.voicedcommandhandlers;
- +
- +import org.l2jmobius.Config;
- +import org.l2jmobius.gameserver.handler.IVoicedCommandHandler;
- +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
- +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
- +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class VoteReward implements IVoicedCommandHandler
- +{
- +
- + @Override
- + public boolean useVoicedCommand(String command, PlayerInstance player, String params)
- + {
- + if (command.equalsIgnoreCase(Config.VOTING_COMMAND))
- + {
- + if (player.isInJail())
- + {
- + player.sendMessage("You cannot use this function while you are jailed");
- + return false;
- + }
- + if (!Config.ENABLE_VOTE_SYSTEM)
- + {
- + player.sendMessage("The rewards system has been disabled by your administrator");
- + return false;
- + }
- + if (!Config.ENABLE_INDIVIDUAL_VOTE)
- + {
- + player.sendMessage("The individual reward system is disabled");
- + return false;
- + }
- + if (!Config.ENABLE_VOTING_COMMAND)
- + {
- + player.sendMessage("Voting command reward is disabled");
- + return false;
- + }
- +
- + for (voteSite vs : voteSite.values())
- + {
- + new Thread(() ->
- + {
- + voteManager.getInatance().getReward(player, vs.ordinal());
- + }).start();
- + }
- +
- + return true;
- +
- + }
- + return false;
- + }
- +
- + @Override
- + public String[] getVoicedCommandList()
- + {
- + return new String[]
- + {
- + Config.VOTING_COMMAND,
- + };
- + }
- +
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java
- new file mode 100644
- index 0000000..42b55bd
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java
- @@ -0,0 +1,112 @@
- +/*
- + * This file is part of the L2J Mobius project.
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU General Public License as published by
- + * the Free Software Foundation, either version 3 of the License, or
- + * (at your option) any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * General Public License for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * along with this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package org.l2jmobius.gameserver.model.actor.instance;
- +
- +import org.l2jmobius.Config;
- +import org.l2jmobius.gameserver.datatables.ItemTable;
- +import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
- +import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
- +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
- +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
- +import org.l2jmobius.gameserver.votesystem.Model.Reward;
- +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class NpcVoteRewardInstance extends NpcInstance
- +{
- +
- + /**
- + * @param objectId
- + * @param template
- + */
- + public NpcVoteRewardInstance(int objectId, NpcTemplate template)
- + {
- + super(objectId, template);
- + }
- +
- + @Override
- + public void onBypassFeedback(PlayerInstance player, String command)
- + {
- + if (command == null)
- + {
- + return;
- + }
- + int Ordinalsite = Integer.parseInt(command);
- + voteManager.getInatance().getReward(player, Ordinalsite);
- + showChatWindow(player, 0);
- + super.onBypassFeedback(player, command);
- + }
- +
- + @Override
- + public void showChatWindow(PlayerInstance player, int val)
- + {
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + StringBuilder sb = new StringBuilder();
- + html.setFile(getHtmlPath(getNpcId(), 0));
- + for (voteSite vs : voteSite.values())
- + {
- + sb.append("<table bgcolor=000000 width=280><tr>");
- + sb.append("<td width=42><img src=\"icon.etc_treasure_box_i08\" width=32 height=32></td>");
- + sb.append("<td width=220><table width=220>");
- + sb.append("<tr><td><table width=220><tr><td width=145>On " + String.format("%s", ReadJson.getInstance().getRecordSite(vs.ordinal()).getSiteName()) + "</td>");
- + if (voteManager.getInatance().checkIndividualAvailableVote(player, vs.ordinal()))
- + {
- + sb.append("<td width=75>" + String.format("<button value=\"Get reward\" action=\"bypass -h vote_%s_site %s\" height=17 width=64 back=\"sek.cbui94\" fore=\"sek.cbui92\">", getObjectId(), vs.ordinal()) + "</td>");
- + }
- + else
- + {
- + sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(player, vs.ordinal())));
- + }
- + sb.append("</tr></table></td></tr>");
- + sb.append("<tr><td><table width=220><tr>");
- + int i = 0;
- + for (Reward r : ReadJson.getInstance().getRewards(vs.ordinal()))
- + {
- + sb.append(String.format("<td width=110 height=32 align=center><font color=BFAF00>%s x%s</font></td>", ItemTable.getInstance().getTemplate(r.getItemId()).getName(), r.getItemCount()));
- + i++;
- + if ((i % 2) == 0)
- + {
- + sb.append("</tr><tr>");
- + }
- + }
- + sb.append("</tr></table></td></tr></table></td></tr></table><br>");
- + }
- + html.replace("%everyXtime%", Config.INTERVAL_TO_NEXT_VOTE / (3600 * 1000));
- + html.replace("%enablevote%", sb.toString());
- + html.replace("%accountName%", player.getName());
- + player.sendPacket(html);
- + }
- +
- + @Override
- + public String getHtmlPath(int npcId, int val)
- + {
- + String filename = "";
- + if (val == 0)
- + {
- + filename = "" + npcId;
- + }
- + else
- + {
- + filename = npcId + "-" + val;
- + }
- +
- + return "data/html/mods/votesystem/" + filename + ".html";
- + }
- +
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java
- index 93288b1..5cf052a 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/SchemeBufferInstance.java
- @@ -28,10 +28,11 @@
- import org.l2jmobius.gameserver.model.actor.Creature;
- import org.l2jmobius.gameserver.model.actor.Summon;
- import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
- +import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
- import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
- import org.l2jmobius.gameserver.util.Util;
- -public class SchemeBufferInstance extends FolkInstance
- +public class SchemeBufferInstance extends NpcInstance
- {
- private static final int PAGE_LIMIT = 6;
- @@ -40,6 +41,40 @@
- super(objectId, template);
- }
- + public String getSpecialSkills(String groupType)
- + {
- + List<Integer> skills = SchemeBufferTable.getInstance().getSkillsIdsByType(groupType);
- +
- + if (skills.isEmpty())
- + {
- + return "That group doesn't contain any skills.";
- + }
- +
- + final StringBuilder sb = new StringBuilder(skills.size() * 150);
- + int row = 0;
- +
- + for (int skillId : skills)
- + {
- + sb.append(((row % 2) == 0 ? "<table width=\"280\" bgcolor=\"000000\"><tr>" : "<table width=\"280\"><tr>"));
- + if ((skillId > 0) && (skillId < 100))
- + {
- + StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill00", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass npc_", getObjectId(), "_getSpecialBuff;", skillId, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
- + }
- + else if ((skillId >= 100) && (skillId < 1000))
- + {
- + StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill0", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass npc_", getObjectId(), "_getSpecialBuff;", skillId, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
- + }
- + else if (skillId >= 1000)
- + {
- + StringUtil.append(sb, "<td height=40 width=40><img src=\"icon.skill", skillId, "\" width=32 height=32></td><td width=190>", SkillTable.getInstance().getSkill(skillId, 1).getName(), "<br1><font color=\"B09878\">", SchemeBufferTable.getInstance().getAvailableBuff(skillId).getDescription(), "</font></td><td><button action=\"bypass npc_", getObjectId(), "_getSpecialBuff;", skillId, "\" width=32 height=32 back=\"L2UI_CH3.mapbutton_zoomin2\" fore=\"L2UI_CH3.mapbutton_zoomin1\"></td>");
- + }
- + sb.append("</tr></table><img src=\"L2UI.SquareGray\" width=277 height=1>");
- + row++;
- + }
- +
- + return sb.toString();
- + }
- +
- @Override
- public void onBypassFeedback(PlayerInstance player, String commandValue)
- {
- @@ -48,7 +83,68 @@
- final StringTokenizer st = new StringTokenizer(command, ";");
- final String currentCommand = st.nextToken();
- - if (currentCommand.startsWith("menu"))
- +
- + if (currentCommand.startsWith("specialbuff"))
- + {
- + final String ncommand = st.nextToken();
- + final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- + html.setFile(getHtmlPath(getNpcId(), 3));
- + if (ncommand.startsWith("Resist"))
- + {
- + html.replace("%specialbuff%", getSpecialSkills("Resist"));
- + }
- + else if (ncommand.startsWith("Summon_buffs"))
- + {
- + html.replace("%specialbuff%", getSpecialSkills("Summon_buffs"));
- + }
- + else if (ncommand.startsWith("Malarias"))
- + {
- + html.replace("%specialbuff%", getSpecialSkills("Malarias"));
- + }
- + html.replace("%objectId%", getObjectId());
- + player.sendPacket(html);
- + }
- +
- + else if (currentCommand.startsWith("getSpecialBuff"))
- + {
- + final int skillid = Integer.parseInt(st.nextToken());
- + final int price = SchemeBufferTable.getInstance().getAvailableBuff(skillid).getPrice();
- + if (player.getInventory().getInventoryItemCount(7164, -1) >= 1)
- + {
- +
- + }
- + else if (player.getInventory().getInventoryItemCount(7569, -1) > price)
- + {
- + player.destroyItemByItemId("Buffer: ", 7569, price, player, true);
- + }
- + else
- + {
- + player.sendMessage("You don't have the necessary items to continue this action.");
- + return;
- + }
- + Creature target = null;
- + if (st.hasMoreTokens())
- + {
- + final String targetType = st.nextToken();
- + if ((targetType != null) && targetType.equalsIgnoreCase("pet"))
- + {
- + target = player.getPet();
- + }
- + }
- + else
- + {
- + target = player;
- + }
- +
- + if (target == null)
- + {
- + player.sendMessage("You don't have a pet.");
- + }
- + this.broadcastPacket(new MagicSkillUse(this, target, skillid, SchemeBufferTable.getInstance().getAvailableBuff(skillid).getLevel(), 0, 0));
- + SkillTable.getInstance().getSkill(skillid, SchemeBufferTable.getInstance().getAvailableBuff(skillid).getLevel()).getEffects(this, target);
- + player.sendMessage("You have acquired " + SkillTable.getInstance().getSkill(skillid, 1).getName());
- + }
- + else if (currentCommand.startsWith("menu"))
- {
- final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- html.setFile(getHtmlPath(getNpcId(), 0));
- @@ -388,6 +484,10 @@
- int count = 0;
- for (String type : SchemeBufferTable.getInstance().getSkillTypes())
- {
- + if ((type.equalsIgnoreCase("Resist")) || (type.equalsIgnoreCase("Summon_buffs")) || (type.equalsIgnoreCase("Malarias")))
- + {
- + continue;
- + }
- if (count == 0)
- {
- sb.append("<tr>");
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
- index 528e895..84fc800 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
- @@ -109,6 +109,30 @@
- ach.useAdminCommand(_command, player);
- }
- + else if (_command.startsWith("vote_"))
- + {
- +
- + int endOfId = _command.indexOf('_', 6);
- + String id;
- + if (endOfId > 0)
- + {
- + id = _command.substring(5, endOfId);
- + }
- + else
- + {
- + id = _command.substring(5);
- + }
- +
- + if (_command.split(" ")[1].toString() != null)
- + {
- + final WorldObject object = World.getInstance().findObject(Integer.parseInt(id));
- + if ((Config.ALLOW_CLASS_MASTERS && Config.ALLOW_REMOTE_CLASS_MASTERS && (object instanceof ClassMasterInstance)) //
- + || ((object instanceof NpcInstance) && (endOfId > 0) && player.isInsideRadius(object, NpcInstance.INTERACTION_DISTANCE, false, false)))
- + {
- + ((NpcInstance) object).onBypassFeedback(player, _command.split(" ")[1].toString());
- + }
- + }
- + }
- else if (_command.equals("come_here") && player.isGM())
- {
- final WorldObject obj = player.getTarget();
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java
- index 66c4ddd..0365268 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/CreatureSay.java
- @@ -25,7 +25,7 @@
- public class CreatureSay extends GameServerPacket
- {
- private final int _objectId;
- - private final ChatType _chatType;
- + private final int _chatType;
- private final String _charName;
- private final String _text;
- @@ -38,6 +38,14 @@
- public CreatureSay(int objectId, ChatType chatType, String charName, String text)
- {
- _objectId = objectId;
- + _chatType = chatType.getClientId();
- + _charName = charName;
- + _text = text;
- + }
- +
- + public CreatureSay(int objectId, int chatType, String charName, String text)
- + {
- + _objectId = objectId;
- _chatType = chatType;
- _charName = charName;
- _text = text;
- @@ -48,14 +56,14 @@
- {
- writeC(0x4a);
- writeD(_objectId);
- - writeD(_chatType.getClientId());
- + writeD(_chatType);
- writeS(_charName);
- writeS(_text);
- final PlayerInstance player = getClient().getPlayer();
- if (player != null)
- {
- - player.broadcastSnoop(_chatType, _charName, _text, this);
- + player.broadcastSnoop(ChatType.values()[_chatType], _charName, _text, this);
- }
- }
- }
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java
- index 308ab18..ccf7ad6 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/util/Broadcast.java
- @@ -17,11 +17,13 @@
- package org.l2jmobius.gameserver.util;
- import org.l2jmobius.gameserver.datatables.xml.ZoneData;
- +import org.l2jmobius.gameserver.enums.ChatType;
- import org.l2jmobius.gameserver.model.World;
- import org.l2jmobius.gameserver.model.actor.Creature;
- import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
- import org.l2jmobius.gameserver.model.zone.ZoneType;
- import org.l2jmobius.gameserver.network.serverpackets.CharInfo;
- +import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
- import org.l2jmobius.gameserver.network.serverpackets.GameServerPacket;
- import org.l2jmobius.gameserver.network.serverpackets.RelationChanged;
- @@ -194,6 +196,11 @@
- }
- }
- + public static void toAllOnlinePlayers(String text, boolean isCritical)
- + {
- + toAllOnlinePlayers(new CreatureSay(0, isCritical ? ChatType.CRITICAL_ANNOUNCE.ordinal() : ChatType.ANNOUNCEMENT.ordinal(), "", text));
- + }
- +
- /**
- * Send a packet to all players in a specific zone type.
- * @param <T> ZoneType.
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java
- new file mode 100644
- index 0000000..899b19c
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java
- @@ -0,0 +1,123 @@
- +package org.l2jmobius.gameserver.votesystem.DB;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.sql.Statement;
- +import java.util.logging.Logger;
- +
- +import org.l2jmobius.commons.database.DatabaseFactory;
- +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
- +import org.l2jmobius.gameserver.votesystem.Model.globalVote;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class globalVoteDB
- +{
- + public static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName());
- + private Statement st;
- + private Connection con;
- + private final globalVote[] _globalVotes;
- +
- + private globalVoteDB()
- + {
- + _globalVotes = new globalVote[voteSite.values().length];
- + loadGlobalVotes();
- + }
- +
- + public void loadGlobalVotes()
- + {
- + con = DatabaseFactory.getConnection();
- + try (PreparedStatement ps = con.prepareStatement("Select voteSite,lastRewardVotes from globalvotes");
- + ResultSet rs = ps.executeQuery();)
- + {
- + if (rs.getRow() == 0)
- + {
- + for (voteSite vs : voteSite.values())
- + {
- + globalVote gv = new globalVote();
- + gv.setVoteSite(vs.ordinal());
- + gv.setVotesLastReward(0);
- + _globalVotes[gv.getVoyeSite()] = gv;
- + }
- + return;
- + }
- + while (rs.next())
- + {
- + globalVote gv = new globalVote();
- + gv.setVoteSite(rs.getInt("voteSite"));
- + gv.setVotesLastReward(rs.getInt("lastRewardVotes"));
- + _globalVotes[gv.getVoyeSite()] = gv;
- + }
- + ps.close();
- + con.close();
- +
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public void saveGlobalVote(globalVote gb)
- + {
- + try (Connection con = DatabaseFactory.getConnection();
- + PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
- +
- + {
- + ps.setInt(1, gb.getVoyeSite());
- + ps.setInt(2, gb.getVotesLastReward());
- + ps.executeUpdate();
- +
- + ps.close();
- + con.close();
- +
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public void saveGlobalVotes(globalVote[] globalVotes)
- + {
- + try (Connection con = DatabaseFactory.getConnection();
- + PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
- +
- + {
- + for (voteSite vs : voteSite.values())
- + {
- + globalVote gb = globalVotes[vs.ordinal()];
- + ps.setInt(1, gb.getVoyeSite());
- + ps.setInt(2, gb.getVotesLastReward());
- + ps.addBatch();
- + }
- + ps.executeBatch();
- +
- + ps.close();
- + con.close();
- +
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public globalVote[] getGlobalVotes()
- + {
- + return _globalVotes;
- + }
- +
- + public static final globalVoteDB getInstance()
- + {
- + return SingleHolder.INSTANCE;
- + }
- +
- + private static final class SingleHolder
- + {
- + protected static final globalVoteDB INSTANCE = new globalVoteDB();
- + }
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java
- new file mode 100644
- index 0000000..a3cfbbe
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java
- @@ -0,0 +1,180 @@
- +package org.l2jmobius.gameserver.votesystem.DB;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.sql.Statement;
- +import java.util.HashMap;
- +import java.util.HashSet;
- +import java.util.Map;
- +import java.util.logging.Logger;
- +
- +import org.l2jmobius.commons.database.DatabaseFactory;
- +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
- +import org.l2jmobius.gameserver.votesystem.Model.individualVote;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class individualVoteDB
- +{
- + private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
- + private final Map<String, individualVote[]> _votes;
- + private Statement st;
- + private Connection con;
- +
- + private individualVoteDB()
- + {
- + _votes = new HashMap<>();
- + loadVotes();
- + }
- +
- + public void loadVotes()
- + {
- +
- + _votes.clear();
- + try (Connection con = DatabaseFactory.getConnection();
- + PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualvotes");
- + ResultSet rs = ps.executeQuery();)
- + {
- + individualVote[] ivs = new individualVote[voteSite.values().length];
- + while (rs.next())
- + {
- + individualVote iv = new individualVote();
- + iv.setVoterIp(rs.getString("voterIp"));
- + iv.setVoteSite(rs.getInt("voteSite"));
- + iv.setVotingTimeSite(rs.getLong("votingTimeSite"));
- + iv.setAlreadyRewarded(rs.getBoolean("alreadyRewarded"));
- +
- + if (_votes.containsKey(iv.getVoterIp()))
- + {
- + if (_votes.get(iv.getVoterIp())[iv.getVoteSite()] == null)
- + {
- + ivs[iv.getVoteSite()] = iv;
- + _votes.replace(iv.getVoterIp(), ivs);
- + }
- + }
- + else
- + {
- + ivs[iv.getVoteSite()] = iv;
- + _votes.put(iv.getVoterIp(), ivs);
- +
- + }
- + }
- +
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- +
- + }
- +
- + public void SaveVotes(Map<String, individualVote[]> votes)
- + {
- +
- + if (votes == null)
- + {
- + return;
- + }
- + if (votes.size() == 0)
- + {
- + return;
- + }
- + try (Connection con = DatabaseFactory.getConnection();
- + PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE " + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), votingTimeSite = VALUES(votingTimeSite),alreadyRewarded = VALUES(alreadyRewarded)");)
- + {
- +
- + for (Map.Entry<String, individualVote[]> ivm : votes.entrySet())
- + {
- + for (individualVote iv : ivm.getValue())
- + {
- + if (iv == null)
- + {
- + continue;
- + }
- + ps.setString(1, iv.getVoterIp());
- + ps.setInt(2, iv.getVoteSite());
- + ps.setLong(4, iv.getVotingTimeSite());
- + ps.setBoolean(5, iv.getAlreadyRewarded());
- + ps.addBatch();
- + }
- + }
- + ps.executeBatch();
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public void SaveVote(individualVote vote)
- + {
- +
- + if (vote == null)
- + {
- + return;
- + }
- +
- + try (Connection con = DatabaseFactory.getConnection();
- + PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE" + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");)
- + {
- + ps.setString(1, vote.getVoterIp());
- + ps.setInt(2, vote.getVoteSite());
- + ps.setLong(4, vote.getVotingTimeSite());
- + ps.setBoolean(5, vote.getAlreadyRewarded());
- + ps.executeUpdate();
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public void DeleteVotes(HashSet<individualVote> deleteVotes)
- + {
- + if (deleteVotes == null)
- + {
- + return;
- + }
- + if (deleteVotes.size() == 0)
- + {
- + return;
- + }
- + try
- + {
- + con = DatabaseFactory.getConnection();
- + st = con.createStatement();
- + for (individualVote iv : deleteVotes)
- + {
- + String sql = String.format("Delete from individualvotes where voterIp = '%s' AND voteSite = %s", iv.getVoterIp(), iv.getVoteSite());
- + st.addBatch(sql);
- + }
- + int[] result = st.executeBatch();
- + st.close();
- + con.close();
- + LOGGER.info(result.length + " Innecesary votes has been deleted");
- +
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public Map<String, individualVote[]> getVotesDB()
- + {
- + return _votes;
- + }
- +
- + public static final individualVoteDB getInstance()
- + {
- + return SingleHolder.INSTANCE;
- + }
- +
- + private static final class SingleHolder
- + {
- + protected static final individualVoteDB INSTANCE = new individualVoteDB();
- + }
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java
- new file mode 100644
- index 0000000..9218452
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java
- @@ -0,0 +1,19 @@
- +package org.l2jmobius.gameserver.votesystem.Enum;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public enum voteSite
- +{
- + L2TOPGAMESERVER, // 0
- + ITOPZ, // 1
- + L2TOPCO, // 2
- + L2VOTES, // 3
- + HOPZONE, // 4
- + L2NETWORK, // 5
- + L2TOPSERVERS, // 6
- + TOPL2JBRASIL, // 7
- + MMOTOP, // 8
- + TOPZONE, // 9
- + L2SERVERS,// 10
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java
- new file mode 100644
- index 0000000..d74419c
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java
- @@ -0,0 +1,500 @@
- +package org.l2jmobius.gameserver.votesystem.Handler;
- +
- +import java.io.BufferedReader;
- +import java.io.DataOutputStream;
- +import java.io.InputStreamReader;
- +import java.net.HttpURLConnection;
- +import java.net.URL;
- +import java.nio.charset.Charset;
- +import java.text.ParseException;
- +import java.text.SimpleDateFormat;
- +import java.util.logging.Logger;
- +
- +import org.l2jmobius.Config;
- +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
- +import org.l2jmobius.gameserver.votesystem.Model.individualVoteResponse;
- +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
- +import org.l2jmobius.gameserver.votesystem.VoteUtil.VoteUtil;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class voteHandler
- +{
- + public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
- +
- + protected static String getNetWorkResponse(String URL, int ordinal)
- + {
- + if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
- + {
- + return "";
- + }
- +
- + StringBuffer response = new StringBuffer();
- + try
- + {
- + String API_URL = Config.VOTE_NETWORK_LINK;
- + String detail = URL;
- + String postParameters = "";
- + postParameters += "apiKey=" + VoteUtil.between("apiKey=", detail, "&type=");
- + postParameters += "&type=" + VoteUtil.between("&type=", detail, "&player");
- + String beginIndexPlayer = "&player=";
- + String player = detail.substring(detail.indexOf(beginIndexPlayer) + beginIndexPlayer.length());
- +
- + if ((player != null) && !player.equals(""))
- + {
- + postParameters += "&player=" + player;
- + }
- +
- + byte[] postData = postParameters.getBytes(Charset.forName("UTF-8"));
- + URL url = new URL(API_URL);
- + HttpURLConnection con = (HttpURLConnection) url.openConnection();
- + con.setConnectTimeout(5000);
- + con.setRequestMethod("POST");
- + con.setRequestProperty("Content-Length", Integer.toString(postData.length));
- + con.setRequestProperty("User-Agent", "Mozilla/5.0");
- + con.setDoOutput(true);
- +
- + DataOutputStream os = new DataOutputStream(con.getOutputStream());
- + os.write(postData);
- + os.flush();
- + os.close();
- +
- + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- + String inputLine;
- +
- + while ((inputLine = in.readLine()) != null)
- + {
- + response.append(inputLine);
- + }
- + in.close();
- +
- + return response.toString();
- +
- + }
- + catch (Exception e)
- + {
- + LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getCause());
- + return "";
- + }
- + }
- +
- + protected static String getResponse(String Url, int ordinal)
- + {
- + if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
- + {
- + return "";
- + }
- +
- + try
- + {
- + int responseCode = 0;
- + URL objUrl = new URL(Url);
- + HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
- + con.setRequestMethod("GET");
- + con.setRequestProperty("User-Agent", "Mozilla/5.0");
- + con.setConnectTimeout(5000);
- + responseCode = con.getResponseCode();
- + if (responseCode == HttpURLConnection.HTTP_OK)
- + {
- + String inputLine;
- + StringBuffer response = new StringBuffer();
- + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- + while ((inputLine = in.readLine()) != null)
- + {
- + response.append(inputLine);
- + }
- + in.close();
- + return response.toString();
- + }
- +
- + }
- + catch (Exception e)
- + {
- + LOGGER.warning(ReadJson.getInstance().getRecordSite(ordinal).getSiteName() + " Say: An error ocurred " + e.getCause());
- + return "";
- + }
- +
- + return "";
- + }
- +
- + public static individualVoteResponse getIndividualVoteResponse(int ordinal, String ip, String AccountName)
- + {
- + String response = "";
- + boolean isVoted = false;
- + long voteSiteTime = 0L, diffTime = 0L;
- + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- + individualVoteResponse ivr = new individualVoteResponse();
- +
- + switch (ordinal)
- + {
- + case 0:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"already_voted\":", response, ",\"vote_time\""));
- + if (isVoted)
- + {
- + try
- + {
- + voteSiteTime = format.parse(VoteUtil.between("\"vote_time\":\"", response, "\",\"server_time\"")).getTime();
- + }
- + catch (ParseException e)
- + {
- + e.printStackTrace();
- + }
- + }
- + break;
- +
- + case 1:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isvoted\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"votetime").replaceAll("\"", ""));
- + if (isVoted)
- + {
- + try
- + {
- + voteSiteTime = (Long.parseLong(VoteUtil.between("\"votetime\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"servertime"))) * 1000;
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- + break;
- +
- + case 2:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(response);
- + if (isVoted)
- + {
- + voteSiteTime = System.currentTimeMillis() - (VoteUtil.getTimeZoneVotingSite(ordinal));
- + }
- + break;
- +
- + case 3:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"date\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"date\"")) == 1)) ? true : false;
- + if (isVoted)
- + {
- + String dateString = VoteUtil.between("\"date\":\"", response, "\"}]");
- + try
- + {
- + voteSiteTime = format.parse(String.format("%s-%s-%s %s:%s:%s", dateString.substring(0, 4), dateString.substring(4, 6), dateString.substring(6, 8), dateString.substring(8, 10), dateString.substring(10, 12), dateString.substring(12, 14))).getTime();
- + }
- + catch (ParseException e1)
- + {
- + e1.printStackTrace();
- + }
- +
- + }
- + break;
- +
- + case 4:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
- + if (isVoted)
- + {
- + try
- + {
- + voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"hopzoneServerTime\"")).getTime();
- + }
- + catch (ParseException e)
- + {
- + e.printStackTrace();
- + }
- + }
- + break;
- +
- + case 5:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (!"".equals(response) && (Integer.parseInt(response) == 1)) ? true : false;
- + if (isVoted)
- + {
- + voteSiteTime = System.currentTimeMillis() - (VoteUtil.getTimeZoneVotingSite(ordinal));
- + }
- + break;
- +
- + case 6:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = ("".equals(response)) ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
- + if (isVoted)
- + {
- + try
- + {
- + voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"l2topserversServerTime\"")).getTime();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- +
- + }
- + break;
- +
- + case 7:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"server_time\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1)) ? true : false;
- + if (isVoted)
- + {
- + try
- + {
- + voteSiteTime = format.parse(VoteUtil.between("\"date\":\"", response, "\",\"status\"")).getTime();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- + break;
- +
- + case 8:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"is_voted\":", response, ",\"vote_time\""));
- + if (isVoted)
- + {
- + try
- + {
- + voteSiteTime = (Long.parseLong(VoteUtil.between("\"vote_time\":", response, ",\"server_time\""))) * 1000;
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- + break;
- +
- + case 9:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isVoted\": ", response, ",\"voteTime\""));
- + if (isVoted)
- + {
- + voteSiteTime = Long.parseLong(VoteUtil.between("\"voteTime\": \"", response, "\",\"serverTime\"")) * 1000;
- + }
- + break;
- +
- + case 10:
- + response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(response);
- + if (isVoted)
- + {
- + voteSiteTime = System.currentTimeMillis() - (VoteUtil.getTimeZoneVotingSite(ordinal));
- + }
- + break;
- +
- + default:
- + return null;
- + }
- + if (!response.equals("") && isVoted)
- + {
- + ivr.setIsVoted(isVoted);
- + ivr.setDiffTime(diffTime);
- + ivr.setVoteSiteTime(voteSiteTime);
- + return ivr;
- + }
- + return null;
- + }
- +
- + public int getGlobalVotesResponse(int ordinal)
- + {
- +
- + String response = "";
- + int totalVotes = 0;
- +
- + switch (ordinal)
- + {
- + case 0:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("\"getVotes\":", response, "}");
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 1:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("server_votes\":", response.replace(" ", ""), ",\"server_rank");
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 2:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 3:
- + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("Votes:</th><th><a class='votes'>", response, "</a></th></tr><tr><th>Clicks:");
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 4:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("\"totalvotes\":", response, ",\"status_code\"");
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 5:
- + String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal), ordinal);
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 6:
- + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>");
- +
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 7:
- + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("nicas:</b> ", response, "<br /><br />");
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 8:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("\"monthly_votes\":", response, "}}");
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 9:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\"");
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- +
- + case 10:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + totalVotes = ((!"".equals(response)) ? (VoteUtil.isNumeric(response) ? Integer.parseInt(response) : -1) : -1);
- + break;
- + }
- +
- + return totalVotes;
- + }
- +
- + public static String getIndividualUrl(int ordinal, String ip, String AccountName)
- + {
- + String url = "";
- + ip = (Config.TEST_IP.equalsIgnoreCase("off") || Config.TEST_IP.equalsIgnoreCase("")) ? ip : Config.TEST_IP;
- + switch (ordinal)
- + {
- + case 0:
- + // l2.topgameserver.net
- + url = String.format("%sAPI_KEY=%s/getData/%s", Config.VOTE_LINK_TGS, Config.TGS_API_KEY, ip);
- + break;
- +
- + case 1:
- + // itopz.com
- + url = String.format("%s%s/%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID, ip);
- + break;
- +
- + case 2:
- + // l2top.co
- + url = String.format("%sVoteCheck.php?id=%s&ip=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID, ip);
- + break;
- +
- + case 3:
- + // l2votes.com
- + url = String.format("%sapi.php?apiKey=%s&ip=%s", Config.VOTE_LINK_VTS, Config.VTS_API_KEY, ip);
- + break;
- +
- + case 4:
- + // hopzone.net
- + url = String.format("%svote?token=%s&ip_address=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY, ip);
- + break;
- +
- + case 5:
- + // l2network.eu
- + url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_USER_NAME, ip);
- + break;
- +
- + case 6:
- + // l2topservers.com
- + url = String.format("%stoken=%s&ip=%s", Config.VOTE_LINK_TSS, Config.TSS_API_TOKEN, ip);
- + break;
- +
- + case 7:
- + // top.l2jbrasil.com
- + url = String.format("%susername=%s&ip=%s&type=json", Config.BRASIL_VOTE_LINK, Config.BRASIL_USER_NAME, ip);
- + break;
- +
- + case 8:
- + // l2jtop
- + url = String.format("%s%s/ip/%s", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY, ip);
- + break;
- +
- + case 9:
- + // topzone.com
- + url = String.format("%svote?token=%s&ip=%s", Config.VOTE_LINK_TZ, Config.TZ_API_KEY, ip);
- + break;
- +
- + case 10:
- + // l2servers.com
- + url = String.format("%scheckip.php?hash=%s&server_id=%s&ip=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_HASH_CODE, Config.SERVERS_SRV_ID, ip);
- + break;
- + }
- +
- + return url;
- + }
- +
- + public String getGlobalUrl(int ordinal)
- + {
- + String url = "";
- +
- + switch (ordinal)
- + {
- + case 0:
- + // l2.topgameserver.net
- + url = String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS, Config.TGS_API_KEY);
- + break;
- +
- + case 1:
- + // itopz.com
- + url = String.format("%s%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID);
- + break;
- +
- + case 2:
- + // l2top.co
- + url = String.format("%sVoteCheck_Total.php?id=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID);
- + break;
- +
- + case 3:
- + // l2votes.com
- + url = String.format("%sserverPage.php?sid=%s", Config.VOTE_LINK_VTS, Config.VTS_SID);
- + break;
- +
- + case 4:
- + // hopzone.net
- + url = String.format("%svotes?token=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY);
- + break;
- +
- + case 5:
- + // l2network.eu
- + url = String.format("apiKey=%s&type=%s&player=", Config.VOTE_NETWORK_API_KEY, 1);
- + break;
- +
- + case 6:
- + // l2topservers
- + url = String.format("https://l2topservers.com/l2top/%s/%s", Config.TS_SRV_ID, Config.TS_DOMAIN_NAME);
- + break;
- +
- + case 7:
- + // top.l2jbrasil.com
- + url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s", Config.BRASIL_USER_NAME);
- + break;
- +
- + case 8:
- + // l2jtop.com
- + url = String.format("%s%s/info/", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY);
- + break;
- +
- + case 9:
- + // l2topzone.com
- + url = String.format("%sserver_%s/getServerData", Config.VOTE_LINK_TZ, Config.TZ_API_KEY);
- + break;
- +
- + case 10:
- + // l2servers.com
- + url = String.format("%syearlyvotes.php?server_id=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_SRV_ID);
- + break;
- + }
- +
- + return url;
- + }
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java
- new file mode 100644
- index 0000000..651ecde
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java
- @@ -0,0 +1,395 @@
- +package org.l2jmobius.gameserver.votesystem.Handler;
- +
- +import java.util.HashSet;
- +import java.util.Map;
- +import java.util.concurrent.ConcurrentHashMap;
- +import java.util.concurrent.ScheduledFuture;
- +
- +import org.l2jmobius.Config;
- +import org.l2jmobius.commons.concurrent.ThreadPool;
- +import org.l2jmobius.gameserver.model.World;
- +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
- +import org.l2jmobius.gameserver.network.GameClient;
- +import org.l2jmobius.gameserver.network.SystemMessageId;
- +import org.l2jmobius.gameserver.network.serverpackets.ItemList;
- +import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
- +import org.l2jmobius.gameserver.util.Broadcast;
- +import org.l2jmobius.gameserver.votesystem.DB.globalVoteDB;
- +import org.l2jmobius.gameserver.votesystem.DB.individualVoteDB;
- +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
- +import org.l2jmobius.gameserver.votesystem.Model.Reward;
- +import org.l2jmobius.gameserver.votesystem.Model.globalVote;
- +import org.l2jmobius.gameserver.votesystem.Model.individualVote;
- +import org.l2jmobius.gameserver.votesystem.Model.individualVoteResponse;
- +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
- +import org.l2jmobius.gameserver.votesystem.VoteUtil.VoteUtil;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public final class voteManager extends voteHandler
- +{
- + private ScheduledFuture<?> _saveGlobalVotes;
- + private ScheduledFuture<?> _updateIndividualVotes;
- + private ScheduledFuture<?> _autoGlobalVotesReward;
- +
- + private HashSet<individualVote> _votes;
- + private Map<String, individualVote[]> _foundVoters;
- + private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
- +
- + public voteManager()
- + {
- + _foundVoters = new ConcurrentHashMap<>();
- + loadVotes();
- + loadGlobalVotes();
- + checkAllResponseGlobalVotes();
- + stopAutoTasks();
- +
- + if (Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
- + {
- + _updateIndividualVotes = ThreadPool.scheduleAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES);
- + }
- + if (Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
- + {
- + _autoGlobalVotesReward = ThreadPool.scheduleAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD);
- + _saveGlobalVotes = ThreadPool.scheduleAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE);
- + }
- + }
- +
- + private void stopAutoTasks()
- + {
- + if (_saveGlobalVotes != null)
- + {
- + _saveGlobalVotes.cancel(true);
- + _saveGlobalVotes = null;
- + }
- + if (_updateIndividualVotes != null)
- + {
- + _updateIndividualVotes.cancel(true);
- + _updateIndividualVotes = null;
- + }
- + if (_autoGlobalVotesReward != null)
- + {
- + _autoGlobalVotesReward.cancel(true);
- + _autoGlobalVotesReward = null;
- + }
- + }
- +
- + public void getReward(PlayerInstance player, int ordinalSite)
- + {
- + String ip = existIp(player);
- + if (ip == null)
- + {
- + return;
- + }
- + individualVoteResponse ivr = getIndividualVoteResponse(ordinalSite, ip, player.getAccountName());
- + if (ivr == null)
- + {
- + player.sendMessage("We were unable to verify your vote with: " + ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName() + ", please try again");
- + return;
- + }
- +
- + if (getTimeRemaining(new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false)) < 0)
- + {
- + player.sendMessage("We were unable to verify your vote with: " + ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName() + ", please try again");
- + return;
- + }
- + if (!ivr.getIsVoted())
- + {
- + player.sendMessage(String.format("You haven't vote on %s yet!", ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName()));
- + return;
- + }
- + if (!checkIndividualAvailableVote(player, ordinalSite))
- + {
- + player.sendMessage(String.format("You can get the reward again on %s at %s", ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName(), getTimeRemainingWithSampleFormat(player, ordinalSite)));
- + return;
- + }
- + individualVote iv = new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false);
- +
- + individualVote[] aiv;
- + if (!_foundVoters.containsKey(ip))
- + {
- + aiv = new individualVote[voteSite.values().length];
- + iv.setAlreadyRewarded(true);
- + aiv[ordinalSite] = iv;
- + _foundVoters.put(ip, aiv);
- + }
- + else
- + {
- + aiv = _foundVoters.get(ip);
- + iv.setAlreadyRewarded(true);
- + aiv[ordinalSite] = iv;
- + _foundVoters.replace(ip, aiv);
- +
- + }
- + for (Reward reward : ReadJson.getInstance().getRewards(ordinalSite))
- + {
- + player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null);
- + player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
- + }
- + player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName()));
- + player.sendPacket(new ItemList(player, true));
- + }
- +
- + public boolean checkIndividualAvailableVote(PlayerInstance player, int ordinalSite)
- + {
- + String ip = existIp(player);
- + if (_foundVoters.containsKey(ip))
- + {
- + individualVote[] ivs = _foundVoters.get(ip);
- + if (ivs[ordinalSite] == null)
- + {
- + return true;
- + }
- + if (ivs[ordinalSite] != null)
- + {
- + individualVote iv = ivs[ordinalSite];
- + if (getTimeRemaining(iv) < 0)
- + {
- + return true;
- + }
- + }
- + }
- + else
- + {
- + return true;
- + }
- +
- + return false;
- + }
- +
- + public long getTimeRemaining(individualVote iv)
- + {
- + long timeRemaining = 0L;
- + long diff = VoteUtil.getTimeZoneVotingSite(iv.getVoteSite());
- + long nexttime = ReadJson.getInstance().getRecordSite(iv.getVoteSite()).getNextVoteTime();
- + timeRemaining = (iv.getVotingTimeSite() + nexttime) - (System.currentTimeMillis() - diff);
- + return timeRemaining;
- + }
- +
- + public String getTimeRemainingWithSampleFormat(PlayerInstance player, int ordinalSite)
- + {
- + String ip = existIp(player);
- +
- + String timeRemainingWithSampleFormat = "";
- + if (_foundVoters.containsKey(ip))
- + {
- + individualVote[] ivs = _foundVoters.get(ip);
- + if (ivs[ordinalSite] != null)
- + {
- + individualVote iv = ivs[ordinalSite];
- + long timeRemaining = getTimeRemaining(iv);
- + if (timeRemaining > 0)
- + {
- + timeRemainingWithSampleFormat = CalculateTimeRemainingWithSampleDateFormat(timeRemaining);
- + return timeRemainingWithSampleFormat;
- + }
- + }
- + }
- + return timeRemainingWithSampleFormat;
- + }
- +
- + public String CalculateTimeRemainingWithSampleDateFormat(long timeRemaining)
- + {
- + long t = timeRemaining / 1000;
- + int hours = Math.round(((t / 3600) % 24));
- + int minutes = Math.round((t / 60) % 60);
- + int seconds = Math.round(t % 60);
- + return String.format("%sH:%sm:%ss", hours, minutes, seconds);
- + }
- +
- + public String existIp(PlayerInstance p)
- + {
- +
- + GameClient client = p.getClient();
- + if ((client.getConnection().getInetAddress() != null) && (client.getPlayer() != null) && !client.isDetached())
- + {
- + try
- + {
- + return client.getIpAddress();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- + return null;
- +
- + }
- +
- + public final void loadVotes()
- + {
- + _foundVoters = individualVoteDB.getInstance().getVotesDB();
- + }
- +
- + protected void loadGlobalVotes()
- + {
- + _globalVotes = globalVoteDB.getInstance().getGlobalVotes();
- + }
- +
- + public void saveVotes()
- + {
- + individualVoteDB.getInstance().SaveVotes(_foundVoters);
- + }
- +
- + protected void AutoGlobalVoteReward()
- + {
- + HashSet<String> ipList = new HashSet<>();
- + for (voteSite vs : voteSite.values())
- + {
- + new Thread(() ->
- + {
- + checkNewUpdate(vs.ordinal());
- + if (_globalVotes[vs.ordinal()].getCurrentVotes() >= (_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)))
- + {
- + _globalVotes[vs.ordinal()].setVotesLastReward(_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD));
- + for (PlayerInstance player : World.getInstance().getAllPlayers())
- + {
- + String ip = existIp(player);
- + if (ip == null)
- + {
- + continue;
- + }
- + if (ipList.contains(ip))
- + {
- + continue;
- + }
- + for (Reward reward : ReadJson.getInstance().getRewards(11))
- + {
- + player.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), player, null);
- + player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
- + }
- + ipList.add(ip);
- + player.sendPacket(new ItemList(player, true));
- + }
- + Broadcast.toAllOnlinePlayers(VoteUtil.Sites[vs.ordinal()] + ": All players has been rewarded, please check your inventory", true);
- + }
- + else
- + {
- + String encourage = "";
- + int nextReward = _globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
- + encourage = String.format("Vote for %s current Votes: %s, next quantity of votes to reward : %s, need votes to next reward: %s", VoteUtil.Sites[vs.ordinal()], _globalVotes[vs.ordinal()].getCurrentVotes(), nextReward, nextReward - _globalVotes[vs.ordinal()].getCurrentVotes());
- + Broadcast.toAllOnlinePlayers(encourage, true);
- + }
- + }).start();
- +
- + }
- + }
- +
- + protected void AutoSaveGlobalVotes()
- + {
- + globalVoteDB.getInstance().saveGlobalVotes(_globalVotes);
- + }
- +
- + protected synchronized void AutoUpdateIndividualVotes()
- + {
- + AutoCleanInnecesaryIndividualVotes();
- + individualVoteDB.getInstance().SaveVotes(_foundVoters);
- + }
- +
- + protected synchronized void AutoCleanInnecesaryIndividualVotes()
- + {
- + HashSet<individualVote> removeVotes = new HashSet<>();
- + for (Map.Entry<String, individualVote[]> ivs : _foundVoters.entrySet())
- + {
- + for (individualVote individualvote : ivs.getValue())
- + {
- + if (individualvote == null)
- + {
- + continue;
- + }
- + if (getTimeRemaining(individualvote) < 0)
- + {
- + removeVotes.add(individualvote);
- + if (_foundVoters.containsKey(individualvote.getVoterIp()))
- + {
- + if (_foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] != null)
- + {
- + _foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] = null;
- + }
- + }
- + }
- + }
- + }
- + individualVoteDB.getInstance().DeleteVotes(removeVotes);
- + }
- +
- + public void checkAllResponseGlobalVotes()
- + {
- + for (voteSite vs : voteSite.values())
- + {
- + new Thread(() ->
- + {
- + checkNewUpdate(vs.ordinal());
- + });
- + }
- + }
- +
- + public void checkNewUpdate(int ordinalSite)
- + {
- + int globalVotesResponse = getGlobalVotesResponse(ordinalSite);
- + if (globalVotesResponse == -1)
- + {
- + return;
- + }
- + _globalVotes[ordinalSite].setCurrentVotes(globalVotesResponse);
- + int last = globalVotesResponse - (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
- + if (last < 0)
- + {
- + _globalVotes[ordinalSite].setVotesLastReward(0);
- + return;
- + }
- + if ((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) < globalVotesResponse)
- + {
- + _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse);
- + return;
- + }
- + }
- +
- + public void Shutdown()
- + {
- + AutoSaveGlobalVotes();
- + AutoCleanInnecesaryIndividualVotes();
- + AutoUpdateIndividualVotes();
- + }
- +
- + protected class AutoGlobalVoteRewardTask implements Runnable
- + {
- +
- + @Override
- + public void run()
- + {
- + AutoGlobalVoteReward();
- +
- + }
- +
- + }
- +
- + protected class AutoSaveGlobalVotesTask implements Runnable
- + {
- +
- + @Override
- + public void run()
- + {
- + AutoSaveGlobalVotes();
- +
- + }
- +
- + }
- +
- + protected class AutoUpdateIndividualVotesTask implements Runnable
- + {
- +
- + @Override
- + public void run()
- + {
- + AutoUpdateIndividualVotes();
- +
- + }
- +
- + }
- +
- + public static voteManager getInatance()
- + {
- + return SingleHolder.INSTANCE;
- + }
- +
- + private static class SingleHolder
- + {
- + protected static final voteManager INSTANCE = new voteManager();
- + }
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java
- new file mode 100644
- index 0000000..d0cda74
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java
- @@ -0,0 +1,36 @@
- +package org.l2jmobius.gameserver.votesystem.Model;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class Reward
- +{
- + private int _itemId;
- + private int _itemCount;
- +
- + public Reward(int itemId, int itemCount)
- + {
- + _itemId = itemId;
- + _itemCount = itemCount;
- + }
- +
- + public void setItemId(int itemId)
- + {
- + _itemId = itemId;
- + }
- +
- + public void setItemCount(int itemCount)
- + {
- + _itemCount = itemCount;
- + }
- +
- + public int getItemId()
- + {
- + return _itemId;
- + }
- +
- + public int getItemCount()
- + {
- + return _itemCount;
- + }
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java
- new file mode 100644
- index 0000000..b17237b
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java
- @@ -0,0 +1,76 @@
- +package org.l2jmobius.gameserver.votesystem.Model;
- +
- +import java.util.ArrayList;
- +import java.util.List;
- +import java.util.concurrent.TimeUnit;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class VoteSite
- +{
- + private int _siteOrdinal;
- + private String _siteName;
- + private String _timeZone;
- + private long _nextVoteTime;
- + private final List<Reward> _rewards = new ArrayList<>();
- +
- + public VoteSite()
- + {
- +
- + }
- +
- + public void setSiteOrdinal(int siteOrdinal)
- + {
- + _siteOrdinal = siteOrdinal;
- + }
- +
- + public void setTimeZone(String timeZone)
- + {
- + _timeZone = timeZone;
- + }
- +
- + public void setNextVoteTime(int nextVoteTime)
- + {
- + _nextVoteTime = nextVoteTime;
- + }
- +
- + public void setSiteName(String siteName)
- + {
- + _siteName = siteName;
- + }
- +
- + public void setRewardList(List<Reward> rewards)
- + {
- + for (Reward r : rewards)
- + {
- + _rewards.add(r);
- + }
- + }
- +
- + public String getTimeZone()
- + {
- + return _timeZone;
- + }
- +
- + public long getNextVoteTime()
- + {
- + return TimeUnit.HOURS.toMillis(_nextVoteTime);
- + }
- +
- + public int getSiteOrdinal()
- + {
- + return _siteOrdinal;
- + }
- +
- + public String getSiteName()
- + {
- + return _siteName;
- + }
- +
- + public List<Reward> getRewardList()
- + {
- + return _rewards;
- + }
- +
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java
- new file mode 100644
- index 0000000..6ed7b6b
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java
- @@ -0,0 +1,53 @@
- +package org.l2jmobius.gameserver.votesystem.Model;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class globalVote
- +{
- + private int _voteSite;
- + private int _votesLastReward;
- + private int _currentVotes;
- +
- + public globalVote()
- + {
- +
- + }
- +
- + public globalVote(int voteSite, int votesLastReward)
- + {
- + _voteSite = voteSite;
- + _votesLastReward = votesLastReward;
- + }
- +
- + public void setVoteSite(int voteSite)
- + {
- + _voteSite = voteSite;
- + }
- +
- + public void setVotesLastReward(int votesLastReward)
- + {
- + _votesLastReward = votesLastReward;
- + }
- +
- + public void setCurrentVotes(int currentVotes)
- + {
- + _currentVotes = currentVotes;
- + }
- +
- + public int getVoyeSite()
- + {
- + return _voteSite;
- + }
- +
- + public int getVotesLastReward()
- + {
- + return _votesLastReward;
- + }
- +
- + public int getCurrentVotes()
- + {
- + return _currentVotes;
- + }
- +
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java
- new file mode 100644
- index 0000000..e0d227e
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java
- @@ -0,0 +1,66 @@
- +package org.l2jmobius.gameserver.votesystem.Model;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class individualVote
- +{
- + private String _voterIp;
- + private long _votingTimeSite;
- + private int _voteSite;
- + private boolean _alreadyRewarded;
- +
- + public individualVote(String voterIp, long votingTimeSite, int voteSite, boolean alreadyRewarded)
- + {
- + _voterIp = voterIp;
- + _votingTimeSite = votingTimeSite;
- + _voteSite = voteSite;
- + _alreadyRewarded = alreadyRewarded;
- + }
- +
- + public individualVote()
- + {
- +
- + }
- +
- + public void setVoterIp(String voterIp)
- + {
- + _voterIp = voterIp;
- + }
- +
- + public void setVotingTimeSite(long votingTimeSite)
- + {
- + _votingTimeSite = votingTimeSite;
- + }
- +
- + public void setVoteSite(int voteSite)
- + {
- + _voteSite = voteSite;
- + }
- +
- + public void setAlreadyRewarded(boolean alreadyRewarded)
- + {
- + _alreadyRewarded = alreadyRewarded;
- + }
- +
- + public String getVoterIp()
- + {
- + return _voterIp;
- + }
- +
- + public long getVotingTimeSite()
- + {
- + return _votingTimeSite;
- + }
- +
- + public int getVoteSite()
- + {
- + return _voteSite;
- + }
- +
- + public boolean getAlreadyRewarded()
- + {
- + return _alreadyRewarded;
- + }
- +
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java
- new file mode 100644
- index 0000000..6707e1b
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java
- @@ -0,0 +1,46 @@
- +package org.l2jmobius.gameserver.votesystem.Model;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public class individualVoteResponse
- +{
- + private boolean _isVoted;
- + private long _diffTime;
- + private long _voteSiteTime;
- +
- + public individualVoteResponse()
- + {
- +
- + }
- +
- + public void setIsVoted(boolean isVoted)
- + {
- + _isVoted = isVoted;
- + }
- +
- + public void setDiffTime(long diffTime)
- + {
- + _diffTime = diffTime;
- + }
- +
- + public void setVoteSiteTime(long voteSiteTime)
- + {
- + _voteSiteTime = voteSiteTime;
- + }
- +
- + public boolean getIsVoted()
- + {
- + return _isVoted;
- + }
- +
- + public long getDiffTime()
- + {
- + return _diffTime;
- + }
- +
- + public long getVoteSiteTime()
- + {
- + return _voteSiteTime;
- + }
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java
- new file mode 100644
- index 0000000..0196c2a
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java
- @@ -0,0 +1,126 @@
- +/*
- + * This file is part of the L2J Mobius project.
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU General Public License as published by
- + * the Free Software Foundation, either version 3 of the License, or
- + * (at your option) any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * General Public License for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * along with this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package org.l2jmobius.gameserver.votesystem.VoteUtil;
- +
- +import java.io.FileNotFoundException;
- +import java.io.FileReader;
- +import java.io.IOException;
- +import java.util.Collection;
- +import java.util.HashMap;
- +import java.util.Map;
- +import java.util.concurrent.TimeUnit;
- +import java.util.logging.Logger;
- +
- +import org.json.simple.JSONArray;
- +import org.json.simple.JSONObject;
- +import org.json.simple.parser.JSONParser;
- +
- +import org.l2jmobius.Config;
- +import org.l2jmobius.gameserver.votesystem.Model.Reward;
- +import org.l2jmobius.gameserver.votesystem.Model.VoteSite;
- +
- +public class ReadJson
- +{
- + Logger LOGGER = Logger.getLogger(ReadJson.class.getName());
- + private final static Map<Integer, VoteSite> _voteSites = new HashMap<>();
- +
- + public ReadJson()
- + {
- + load();
- + }
- +
- + @SuppressWarnings("unchecked")
- + public void load()
- + {
- + JSONParser jsonParser = new JSONParser();
- +
- + try (FileReader reader = new FileReader(parseDatapackFile("/data/votesystem.json")))
- + {
- + Object obj = jsonParser.parse(reader);
- +
- + JSONArray rewardSiteList = (JSONArray) obj;
- + rewardSiteList.forEach(emp -> parseRewardSites((JSONObject) emp));
- + LOGGER.info("Loaded " + _voteSites.size() + " reward sites");
- +
- + }
- + catch (FileNotFoundException e)
- + {
- + e.printStackTrace();
- + }
- + catch (IOException e)
- + {
- + e.printStackTrace();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + private void parseRewardSites(JSONObject site)
- + {
- + VoteSite votesite = new VoteSite();
- + JSONObject rewardsite = (JSONObject) site.get("votesite");
- +
- + votesite.setSiteOrdinal(Integer.parseInt((String) rewardsite.get("ordinal")));
- + votesite.setSiteName((String) rewardsite.get("name"));
- + votesite.setNextVoteTime(Integer.parseInt((String) rewardsite.get("nextvotetime")));
- + votesite.setTimeZone((String) rewardsite.get("timezone"));
- +
- + JSONArray rewardList = (JSONArray) rewardsite.get("rewards");
- + for (int i = 0; i < rewardList.size(); i++)
- + {
- + JSONObject object = (JSONObject) rewardList.get(i);
- + votesite.getRewardList().add(new Reward(Integer.parseInt((String) object.get("item_id")), Integer.parseInt((String) object.get("item_count"))));
- +
- + }
- +
- + _voteSites.put(votesite.getSiteOrdinal(), votesite);
- + }
- +
- + private String parseDatapackFile(String path)
- + {
- + String p = Config.DATAPACK_ROOT + path;
- + return p;
- + }
- +
- + public VoteSite getRecordSite(int ordinal)
- + {
- + return _voteSites.get(ordinal);
- + }
- +
- + public long getNextVoteTime(int ordinal)
- + {
- + return TimeUnit.HOURS.toMillis(_voteSites.get(ordinal).getNextVoteTime());
- + }
- +
- + public Collection<Reward> getRewards(int ordinal)
- + {
- + return _voteSites.get(ordinal).getRewardList();
- + }
- +
- + public static final ReadJson getInstance()
- + {
- + return SingletonHolder.INSTANCE;
- + }
- +
- + private static final class SingletonHolder
- + {
- + protected static final ReadJson INSTANCE = new ReadJson();
- + }
- +
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java
- new file mode 100644
- index 0000000..8feba1f
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java
- @@ -0,0 +1,130 @@
- +package org.l2jmobius.gameserver.votesystem.VoteUtil;
- +
- +import java.io.BufferedReader;
- +import java.io.InputStreamReader;
- +import java.net.HttpURLConnection;
- +import java.net.URL;
- +import java.text.ParseException;
- +import java.text.SimpleDateFormat;
- +import java.time.ZoneId;
- +import java.time.ZonedDateTime;
- +import java.time.format.DateTimeFormatter;
- +import java.util.Date;
- +import java.util.TimeZone;
- +import java.util.logging.Logger;
- +
- +/**
- + * @author l2.topgameserver.net
- + */
- +public final class VoteUtil
- +{
- + public static final Logger LOGGER = Logger.getLogger(VoteUtil.class.getName());
- +
- + public static final long getTimeZoneVotingSite(int ordinalSite)
- + {
- + try
- + {
- + String id = TimeZone.getDefault().getID();
- + String myDate = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(ZonedDateTime.now(ZoneId.of(ReadJson.getInstance().getRecordSite(ordinalSite).getTimeZone()))).toString();
- + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- + Date date = sdf.parse(myDate);
- + String myDate2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(ZonedDateTime.now(ZoneId.of(id))).toString();
- + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- + Date date2 = sdf2.parse(myDate2);
- + return (date2.getTime() - date.getTime());
- +
- + }
- + catch (ParseException pe)
- + {
- + pe.printStackTrace();
- + return 0L;
- + }
- +
- + }
- +
- + public static final String Sites[] =
- + {
- + "L2.TopGameServer.net",
- + "ITopZ.com",
- + "L2Top.co",
- + "L2Votes.com",
- + "L2.Hopzone.net",
- + "L2Network.eu",
- + "L2TopServers.com",
- + "top.l2jbrasil.com",
- + "MMOTOP.eu",
- + "L2Topzone.com",
- + "L2Servers.com",
- + "GolbalVotes"
- + };
- +
- + public static final String getResponse(String Url, int ordinal)
- + {
- +
- + try
- + {
- + int responseCode = 0;
- + URL objUrl = new URL(Url);
- + HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
- + con.setRequestMethod("GET");
- + con.setRequestProperty("User-Agent", "Mozilla/5.0");
- + con.setConnectTimeout(5000);
- + responseCode = con.getResponseCode();
- + if (responseCode == HttpURLConnection.HTTP_OK)
- + {
- +
- + String inputLine;
- + StringBuffer response = new StringBuffer();
- + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- + while ((inputLine = in.readLine()) != null)
- + {
- + if (ordinal == 3)
- + {
- + if (inputLine.contains("Votes:"))
- + {
- + response.append(inputLine);
- + break;
- + }
- + }
- + if (ordinal == 7)
- + {
- + if (inputLine.contains("<b>Entradas "))
- + {
- + response.append(inputLine);
- + break;
- + }
- + }
- + }
- + in.close();
- + return response.toString();
- + }
- +
- + }
- + catch (Exception e)
- + {
- + LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getStackTrace());
- + return "";
- + }
- +
- + return "";
- + }
- +
- + public static final String between(String p1, String str, String p2)
- + {
- + String returnValue = "";
- + int i1 = str.indexOf(p1);
- + int i2 = str.indexOf(p2);
- + if ((i1 != -1) && (i2 != -1))
- + {
- + i1 = i1 + p1.length();
- + returnValue = str.substring(i1, i2);
- + }
- + return returnValue;
- + }
- +
- + public static final boolean isNumeric(String text)
- + {
- + return text.matches("[+-]?\\d*(\\.\\d+)?");
- + }
- +
- +}
- -- ----------------------------
- -- Table structure for globalvotes
- -- ----------------------------
- DROP TABLE IF EXISTS `globalvotes`;
- CREATE TABLE `globalvotes` (
- `voteSite` tinyint(2) NOT NULL,
- `lastRewardVotes` int(11) NULL DEFAULT NULL,
- PRIMARY KEY (`voteSite`) USING BTREE
- ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
- -- ----------------------------
- -- Records of globalvotes
- -- ----------------------------
- INSERT INTO `globalvotes` VALUES (0, 13);
- INSERT INTO `globalvotes` VALUES (1, 68);
- INSERT INTO `globalvotes` VALUES (2, 0);
- INSERT INTO `globalvotes` VALUES (3, 3);
- INSERT INTO `globalvotes` VALUES (4, 2);
- INSERT INTO `globalvotes` VALUES (5, 0);
- INSERT INTO `globalvotes` VALUES (6, 0);
- INSERT INTO `globalvotes` VALUES (7, 2);
- INSERT INTO `globalvotes` VALUES (8, 3);
- INSERT INTO `globalvotes` VALUES (9, 0);
- INSERT INTO `globalvotes` VALUES (10, 75);
- -- ----------------------------
- -- Table structure for individualvotes
- -- ----------------------------
- DROP TABLE IF EXISTS `individualvotes`;
- CREATE TABLE `individualvotes` (
- `voterIp` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
- `voteSite` tinyint(3) NOT NULL,
- `votingTimeSite` bigint(20) NULL DEFAULT NULL,
- `alreadyRewarded` tinyint(3) NULL DEFAULT NULL,
- PRIMARY KEY (`voterIp`, `voteSite`) USING BTREE
- ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
- -- ----------------------------
- -- Records of npc
- -- ----------------------------
- INSERT INTO `l2jmobiusc6`.`npc`(`id`, `idTemplate`, `name`, `serverSideName`, `title`, `serverSideTitle`, `class`, `collision_radius`, `collision_height`, `level`, `sex`, `type`, `attackrange`, `hp`, `mp`, `hpreg`, `mpreg`, `str`, `con`, `dex`, `int`, `wit`, `men`, `exp`, `sp`, `patk`, `pdef`, `matk`, `mdef`, `atkspd`, `aggro`, `matkspd`, `rhand`, `lhand`, `armor`, `walkspd`, `runspd`, `faction_id`, `faction_range`, `isUndead`, `absorb_level`, `absorb_type`) VALUES (75014, 35587, 'Kaaya', 1, 'Vote Reward System', 0, 'NPC.a_traderC_Fhuman', 8.00, 21.00, 70, 'female', 'NpcVoteReward', 40, 3862, 1493, 11.85, 2.78, 40, 43, 30, 21, 20, 10, 0, 0, 1314, 470, 780, 382, 278, 0, 333, 0, 0, 0, 88, 132, NULL, 0, 0, 0, 'LAST_HIT');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement