Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ============================================ CORE ===============================================
- diff --git a/src/main/java/com/l2jserver/gameserver/GameServer.java b/src/main/java/com/l2jserver/gameserver/GameServer.java
- index 18c2bb0..2562230 100644
- --- a/src/main/java/com/l2jserver/gameserver/GameServer.java
- +++ b/src/main/java/com/l2jserver/gameserver/GameServer.java
- @@ -47,6 +47,7 @@
- import com.l2jserver.commons.util.Util;
- import com.l2jserver.gameserver.bbs.service.ForumsBBSManager;
- import com.l2jserver.gameserver.cache.HtmCache;
- +import static com.l2jserver.gameserver.config.Configuration.votesystem;
- import com.l2jserver.gameserver.dao.factory.impl.DAOFactory;
- import com.l2jserver.gameserver.data.json.ExperienceData;
- import com.l2jserver.gameserver.data.sql.impl.AnnouncementsTable;
- @@ -151,6 +152,8 @@
- import com.l2jserver.gameserver.taskmanager.KnownListUpdateTaskManager;
- import com.l2jserver.gameserver.taskmanager.TaskManager;
- import com.l2jserver.gameserver.util.DeadLockDetector;
- +import com.l2jserver.gameserver.votesystem.Handler.voteManager;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteSiteXml;
- import com.l2jserver.mmocore.SelectorConfig;
- import com.l2jserver.mmocore.SelectorThread;
- @@ -336,6 +339,15 @@
- ScriptEngineManager.getInstance().executeScript("com/l2jserver/datapack/quests/QuestLoader.java");
- ScriptEngineManager.getInstance().executeScript("com/l2jserver/datapack/quests/TerritoryWarScripts/TerritoryWarSuperClass.java");
- + printSection("Vote System");
- + if(votesystem().getEnableVoteSystem()) {
- + voteManager.getInatance();
- + LOG.info("======================Vote System Enabled=========================");
- + VoteSiteXml.getInstance();
- + }else {
- + LOG.info("======================Vote System Disabled=========================");
- + }
- +
- printSection("Scripts");
- ScriptEngineManager.getInstance().executeScriptList(new File(server().getDatapackRoot(), "data/scripts.cfg"));
- diff --git a/src/main/java/com/l2jserver/gameserver/Shutdown.java b/src/main/java/com/l2jserver/gameserver/Shutdown.java
- index 25b6b4b..ea81bff 100644
- --- a/src/main/java/com/l2jserver/gameserver/Shutdown.java
- +++ b/src/main/java/com/l2jserver/gameserver/Shutdown.java
- @@ -28,6 +28,7 @@
- import com.l2jserver.commons.UPnPService;
- import com.l2jserver.commons.database.ConnectionFactory;
- +import static com.l2jserver.gameserver.config.Configuration.votesystem;
- import com.l2jserver.gameserver.data.sql.impl.ClanTable;
- import com.l2jserver.gameserver.data.sql.impl.OfflineTradersTable;
- import com.l2jserver.gameserver.datatables.BotReportTable;
- @@ -50,6 +51,7 @@
- import com.l2jserver.gameserver.network.serverpackets.ServerClose;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.util.Broadcast;
- +import com.l2jserver.gameserver.votesystem.Handler.voteManager;
- /**
- * This class provides the functions for shutting down and restarting the server.<br>
- @@ -425,6 +427,12 @@
- LOG.info("Castle Manor Manager: Data saved({}ms).", tc.getEstimatedTimeAndRestartCounter());
- }
- + //Save global and individual votes
- + if(votesystem().getEnableVoteSystem()){
- + voteManager.getInatance().Shutdown();
- + LOG.info("Vote data has been saved");
- + }
- +
- ClanHallSiegeManager.getInstance().onServerShutDown();
- LOG.info("CHSiegeManager: Siegable hall attacker lists saved!");
- diff --git a/src/main/java/com/l2jserver/gameserver/config/Configuration.java b/src/main/java/com/l2jserver/gameserver/config/Configuration.java
- index 42189df..6c87fe5 100644
- --- a/src/main/java/com/l2jserver/gameserver/config/Configuration.java
- +++ b/src/main/java/com/l2jserver/gameserver/config/Configuration.java
- @@ -86,6 +86,8 @@
- private static final BufferServiceConfiguration bufferService = ConfigFactory.create(BufferServiceConfiguration.class);
- private static final DiscordConfiguration discord = ConfigFactory.create(DiscordConfiguration.class);
- +
- + private static final VoteSystemConfiguration votesystem = ConfigFactory.create(VoteSystemConfiguration.class);
- private Configuration() {
- // Do nothing.
- @@ -206,4 +208,9 @@
- public static DiscordConfiguration discord() {
- return discord;
- }
- +
- + public static VoteSystemConfiguration votesystem(){
- + return votesystem;
- + }
- +
- }
- diff --git a/src/main/java/com/l2jserver/gameserver/config/VoteSystemConfiguration.java b/src/main/java/com/l2jserver/gameserver/config/VoteSystemConfiguration.java
- new file mode 100644
- index 0000000..9765386
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/config/VoteSystemConfiguration.java
- @@ -0,0 +1,147 @@
- +package com.l2jserver.gameserver.config;
- +
- +import com.l2jserver.gameserver.config.converter.Hours2MillisecondsConverter;
- +import com.l2jserver.gameserver.config.converter.Minutes2MillisecondsConverter;
- +import static java.util.concurrent.TimeUnit.MINUTES;
- +import org.aeonbits.owner.Config;
- +import static org.aeonbits.owner.Config.HotReloadType.ASYNC;
- +import org.aeonbits.owner.Reloadable;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +
- +@Config.Sources({
- + "file:./config/votesystem.properties",
- + "classpath:config/votesystem.properties"
- +})
- +@Config.HotReload(value = 20, unit = MINUTES, type = ASYNC)
- +public interface VoteSystemConfiguration extends Config, Reloadable{
- +
- + @Key("EnableVoteSystem")
- + Boolean getEnableVoteSystem();
- +
- + @Key("EnableGlobalVote")
- + Boolean getEnableGlobalVote();
- +
- + @Key("EnableIndividualVote")
- + Boolean getEnableIndividualVote();
- +
- + @Key("NextTimeToAutoUpdateTotalVote")
- + @ConverterClass(Minutes2MillisecondsConverter.class)
- + Integer getNextTimeToAutoUpdateTotalVote();
- +
- + @Key("NextTimeToAutoUpdateIndividualVotes")
- + @ConverterClass(Minutes2MillisecondsConverter.class)
- + Integer getNextTimeToAutoUpdateIndividualVotes();
- +
- + @Key("NextTimeToAutoCleanInnecesaryVotes")
- + @ConverterClass(Minutes2MillisecondsConverter.class)
- + Integer getNextTimeToAutoCleanInnecesaryVotes();
- +
- + @Key("NextTimeToCheckAutoGlobalVotesReward")
- + @ConverterClass(Minutes2MillisecondsConverter.class)
- + Integer getNextTimeToCheckAutoGlobalVotesReward();
- +
- + @Key("IntervalToNextVote")
- + @ConverterClass(Hours2MillisecondsConverter.class)
- + Integer getIntervalToNextVote();
- +
- + @Key("GlobalVotesAmountToNextReward")
- + Integer getGlobalVotesAmountToNextReward();
- +
- + @Key("EnableVotingCommand")
- + Boolean getEnableVotingCommand();
- +
- + @Key("VotingCommand")
- + String getVotingCommand();
- +
- + @Key("VoteLinkTgs")
- + String getVoteLinkTgs();
- +
- + @Key("TgsApiKey")
- + String getTgsApiKey();
- +
- + @Key("VoteLinkTopCo")
- + String getVoteLinkTopCo();
- +
- + @Key("TopCoSrvId")
- + String getTopCoSrvId();
- +
- + @Key("VoteLinkItopz")
- + String getVoteLinkItopz();
- +
- + @Key("ItopzZpiKey")
- + String getItopzZpiKey();
- +
- + @Key("ItopzSrvId")
- + String getItopzSrvId();
- +
- + @Key("VoteLinkVts")
- + String getVoteLinkVts();
- +
- + @Key("VtsApiKey")
- + String getVtsApiKey();
- +
- + @Key("VtsSid")
- + String getVtsSid();
- +
- + @Key("VoteLinkHz")
- + String getVoteLinkHz();
- +
- + @Key("HzApiKey")
- + String getHzApiKey();
- +
- + @Key("VoteNetworkLink")
- + String getVoteNetworkLink();
- +
- + @Key("VoteNetworkUserName")
- + String getVoteNetworkUserName();
- +
- + @Key("VoteNetworkApiKey")
- + String getVoteNetworkApiKey();
- +
- + @Key("VoteLinkTss")
- + String getVoteLinkTss();
- +
- + @Key("TssApiToken")
- + String getTssApiToken();
- +
- + @Key("TsSrvId")
- + String getTsSrvId();
- +
- + @Key("TsDomainName")
- + String getTsDomainName();
- +
- + @Key("BrasilVoteLink")
- + String getBrasilVoteLink();
- +
- + @Key("BrasilUserName")
- + String getBrasilUserName();
- +
- + @Key("VoteLinkMmotop")
- + String getVoteLinkMmotop();
- +
- + @Key("MmotopApiKey")
- + String getMmotopApiKey();
- +
- + @Key("VoteLinkTz")
- + String getVoteLinkTz();
- +
- + @Key("TzApiKey")
- + String getTzApiKey();
- +
- + @Key("VoteLinkServers")
- + String getVoteLinkServers();
- +
- + @Key("ServersHashCode")
- + String getServersHashCode();
- +
- + @Key("ServersSrvId")
- + String getServersSrvId();
- +
- + @Key("TestIp")
- + String getTestIp();
- +
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/config/converter/Hours2MillisecondsConverter.java b/src/main/java/com/l2jserver/gameserver/config/converter/Hours2MillisecondsConverter.java
- new file mode 100644
- index 0000000..a324a56
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/config/converter/Hours2MillisecondsConverter.java
- @@ -0,0 +1,20 @@
- +package com.l2jserver.gameserver.config.converter;
- +
- +import java.lang.reflect.Method;
- +import static java.util.concurrent.TimeUnit.HOURS;
- +import org.aeonbits.owner.Converter;
- +import org.apache.logging.log4j.util.Strings;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class Hours2MillisecondsConverter implements Converter<Integer> {
- + @Override
- + public Integer convert(Method method, String input) {
- + if (Strings.isBlank(input)) {
- + return 0;
- + }
- + return (int) HOURS.toMillis(Integer.parseInt(input));
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/config/converter/MapIntegerHoursToMillisecondsConverter.java b/src/main/java/com/l2jserver/gameserver/config/converter/MapIntegerHoursToMillisecondsConverter.java
- new file mode 100644
- index 0000000..042476c
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/config/converter/MapIntegerHoursToMillisecondsConverter.java
- @@ -0,0 +1,29 @@
- +package com.l2jserver.gameserver.config.converter;
- +
- +import java.lang.reflect.Method;
- +import java.util.HashMap;
- +import java.util.Map;
- +import static java.util.concurrent.TimeUnit.HOURS;
- +import org.aeonbits.owner.Converter;
- +import org.apache.logging.log4j.util.Strings;
- +
- +/**
- + *
- + * @author escor
- + */
- +public class MapIntegerHoursToMillisecondsConverter implements Converter<Map<Integer, Integer>> {
- + @Override
- + public Map<Integer, Integer> convert(Method method, String input) {
- + final var map = new HashMap<Integer, Integer>();
- + if (Strings.isBlank(input)) {
- + return map;
- + }
- +
- + final var tokens = input.replaceAll(" ", "").split(";");
- + for (var token : tokens) {
- + final var splitToken = token.split(",");
- + map.put(Integer.valueOf(splitToken[0]), (int) HOURS.toMillis(Integer.parseInt(splitToken[1])));
- + }
- + return map;
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/model/actor/instance/L2NpcVoteInstance.java b/src/main/java/com/l2jserver/gameserver/model/actor/instance/L2NpcVoteInstance.java
- new file mode 100644
- index 0000000..642839c
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/model/actor/instance/L2NpcVoteInstance.java
- @@ -0,0 +1,92 @@
- +package com.l2jserver.gameserver.model.actor.instance;
- +
- +import com.l2jserver.gameserver.cache.HtmCache;
- +import static com.l2jserver.gameserver.config.Configuration.votesystem;
- +import com.l2jserver.gameserver.datatables.ItemTable;
- +import com.l2jserver.gameserver.model.actor.L2Npc;
- +import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
- +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- +import com.l2jserver.gameserver.votesystem.Enum.voteSite;
- +import com.l2jserver.gameserver.votesystem.Handler.voteManager;
- +import com.l2jserver.gameserver.votesystem.Model.Reward;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteSiteXml;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class L2NpcVoteInstance extends L2Npc{
- +
- + public L2NpcVoteInstance(L2NpcTemplate template) {
- + super(template);
- + }
- +
- + @Override
- + public void onBypassFeedback(L2PcInstance activeChar, String command)
- + {
- + if(command == null) {
- + return;
- + }
- + int Ordinalsite = Integer.parseInt(command);
- + voteManager.getInatance().getReward(activeChar, Ordinalsite);
- + showChatWindow(activeChar,0);
- + super.onBypassFeedback(activeChar, command);
- + }
- +
- + @Override
- + public void showChatWindow(L2PcInstance activeChar, int val) {
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + StringBuilder sb = new StringBuilder();
- + int npcId = getTemplate().getId();
- + String filename = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), getHtmlPath(npcId, 0));
- + html.setHtml(filename);
- + int count = 2;
- + if(votesystem().getEnableVoteSystem()) {
- + for(voteSite vs : voteSite.values()) {
- + if(count%2 == 1)
- + sb.append("<table bgcolor=002F17 width=280><tr>");
- + else
- + sb.append("<table bgcolor=000C2F width=280><tr>");
- + sb.append("<td width=32><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>"+String.format("%s",VoteSiteXml.getInstance().getSiteName(vs.ordinal()))+"</td>");
- + if(voteManager.getInatance().checkIndividualAvailableVote(activeChar, vs.ordinal())) {
- + sb.append("<td width=75>"+String.format("<button value=\"Get reward\" action=\"bypass -h vote_%s_site %s\" height=17 width=70 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\">",getObjectId(),vs.ordinal())+"</td>");
- + }else {
- + sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(activeChar, vs.ordinal())));
- + }
- + sb.append("</tr></table></td></tr>");
- + sb.append("<tr><td><table width=220><tr>");
- + int i=0;
- + for(Reward r : VoteSiteXml.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>");
- + count++;
- + }
- + }else {
- + sb.append("<table><tr><td>Vote system has been disabled for your server owner!</td></tr></table>");
- + }
- + html.replace("%everyXtime%",votesystem().getIntervalToNextVote()/(3600*1000));
- + html.replace("%enablevote%", sb.toString());
- + html.replace("%accountName%",activeChar.getName());
- + activeChar.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/src/main/java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java b/src/main/java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java
- index 886cc49..9cf586c 100644
- --- a/src/main/java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java
- +++ b/src/main/java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java
- @@ -186,7 +186,27 @@
- } catch (NumberFormatException nfe) {
- _log.log(Level.WARNING, "NFE for command [" + _command + "]", nfe);
- }
- - } else if (_command.startsWith("_match")) {
- + }
- +
- + 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 (Util.isDigit(id)) {
- + L2Object object = L2World.getInstance().findObject(Integer.parseInt(id));
- +
- + if ((object != null) && object.isNpc() && (endOfId > 0) && activeChar.isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false)) {
- + ((L2Npc) object).onBypassFeedback(activeChar, _command.split(" ")[1]);
- + }
- + }
- + activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- +
- +
- + }else if (_command.startsWith("_match")) {
- String params = _command.substring(_command.indexOf("?") + 1);
- StringTokenizer st = new StringTokenizer(params, "&");
- int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
- diff --git a/src/main/java/com/l2jserver/gameserver/util/IXmlReader.java b/src/main/java/com/l2jserver/gameserver/util/IXmlReader.java
- index 5630f9d..eb4a77a 100644
- --- a/src/main/java/com/l2jserver/gameserver/util/IXmlReader.java
- +++ b/src/main/java/com/l2jserver/gameserver/util/IXmlReader.java
- @@ -19,6 +19,7 @@
- package com.l2jserver.gameserver.util;
- import static com.l2jserver.gameserver.config.Configuration.server;
- +import com.l2jserver.gameserver.model.StatsSet;
- import java.io.File;
- import java.io.FileFilter;
- @@ -514,6 +515,21 @@
- return parseString(attrs.getNamedItem(name), defaultValue);
- }
- +
- + default StatsSet parseAttributes(Node node)
- + {
- + final NamedNodeMap attrs = node.getAttributes();
- + final StatsSet map = new StatsSet();
- + for (int i = 0; i < attrs.getLength(); i++)
- + {
- + final Node att = attrs.item(i);
- + map.set(att.getNodeName(), att.getNodeValue());
- + }
- + return map;
- + }
- +
- +
- +
- /**
- * Parses an enumerated value.
- * @param <T> the enumerated type
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/DB/globalVoteDB.java b/src/main/java/com/l2jserver/gameserver/votesystem/DB/globalVoteDB.java
- new file mode 100644
- index 0000000..686ac1d
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/DB/globalVoteDB.java
- @@ -0,0 +1,92 @@
- +package com.l2jserver.gameserver.votesystem.DB;
- +
- +import com.l2jserver.commons.database.ConnectionFactory;
- +import com.l2jserver.gameserver.votesystem.Enum.voteSite;
- +import com.l2jserver.gameserver.votesystem.Model.globalVote;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteUtil;
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.sql.Statement;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class globalVoteDB {
- + private static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName());
- + private globalVote[] _globalVotes;
- + private globalVoteDB() {
- + _globalVotes = new globalVote[voteSite.values().length];
- + loadGlobalVotes();
- + }
- +
- + public void loadGlobalVotes() {
- + try(Connection con = ConnectionFactory.getInstance().getConnection();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;
- + }
- + LOGGER.log(Level.INFO,"{} global votes have been uploaded", new Object[]{_globalVotes.length});
- + }catch(SQLException e) {
- +
- + e.printStackTrace();
- + }
- + }
- + public void saveGlobalVote(globalVote gb) {
- + try(Connection con = ConnectionFactory.getInstance().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();
- +
- + }catch(SQLException e) {
- + e.printStackTrace();
- + }
- + }
- +
- + public void saveGlobalVotes(globalVote[] globalVotes) {
- + try(Connection con = ConnectionFactory.getInstance().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();
- +
- + }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();
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/DB/individualVoteDB.java b/src/main/java/com/l2jserver/gameserver/votesystem/DB/individualVoteDB.java
- new file mode 100644
- index 0000000..304bdad
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/DB/individualVoteDB.java
- @@ -0,0 +1,156 @@
- +package com.l2jserver.gameserver.votesystem.DB;
- +
- +import com.l2jserver.commons.database.ConnectionFactory;
- +import com.l2jserver.gameserver.votesystem.Enum.voteSite;
- +import com.l2jserver.gameserver.votesystem.Model.individualVote;
- +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;
- +
- +/**
- + *
- + * @author escor
- + */
- +public final class individualVoteDB {
- + private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
- + private Map<String,individualVote[]> _votes;
- + private Statement st;
- + private Connection con;
- +
- +
- + private individualVoteDB() {
- + _votes = new HashMap<>();
- + loadVotes();
- + }
- +
- + public void loadVotes() {
- +
- + _votes.clear();
- + try(Connection con = ConnectionFactory.getInstance().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.setDiffTime(rs.getLong("diffTime"));
- + 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 = ConnectionFactory.getInstance().getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE "
- + + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), 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(3, iv.getDiffTime());
- + 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 = ConnectionFactory.getInstance().getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE"
- + + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");)
- + {
- + ps.setString(1, vote.getVoterIp());
- + ps.setInt(2, vote.getVoteSite());
- + ps.setLong(3, vote.getDiffTime());
- + 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 = ConnectionFactory.getInstance().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/src/main/java/com/l2jserver/gameserver/votesystem/Enum/voteSite.java b/src/main/java/com/l2jserver/gameserver/votesystem/Enum/voteSite.java
- new file mode 100644
- index 0000000..ea93f66
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Enum/voteSite.java
- @@ -0,0 +1,19 @@
- +package com.l2jserver.gameserver.votesystem.Enum;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public enum voteSite {
- + L2TOPGAMESERVER,
- + ITOPZ,
- + L2TOPCO,
- + L2VOTES,
- + HOPZONE,
- + L2NETWORK,
- + L2TOPSERVERS,
- + TOPL2JBRASIL,
- + MMOTOP,
- + TOPZONE,
- + L2SERVERS,
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/Handler/voteHandler.java b/src/main/java/com/l2jserver/gameserver/votesystem/Handler/voteHandler.java
- new file mode 100644
- index 0000000..8eda6ea
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Handler/voteHandler.java
- @@ -0,0 +1,484 @@
- +package com.l2jserver.gameserver.votesystem.Handler;
- +
- +import static com.l2jserver.gameserver.config.Configuration.votesystem;
- +import com.l2jserver.gameserver.votesystem.Enum.voteSite;
- +import com.l2jserver.gameserver.votesystem.Model.individualVoteResponse;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteSiteXml;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteUtil;
- +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;
- +
- +/**
- + *
- + * @author escor
- + */
- +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(votesystem().getVoteNetworkApiKey()) || "".equals(votesystem().getVoteNetworkLink()) || "".equals(votesystem().getVoteNetworkUserName())))
- + return "";
- +
- + StringBuffer response = new StringBuffer();
- + try {
- + String API_URL = votesystem().getVoteNetworkLink();
- + 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(votesystem().getVoteNetworkApiKey()) || "".equals(votesystem().getVoteNetworkLink()) || "".equals(votesystem().getVoteNetworkUserName())))
- + 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(VoteSiteXml.getInstance().getSiteName(ordinal)+" 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();
- + diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"server_time\":\"", response, "\"}")).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;
- + diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"servertime\":", response.toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), "}")))*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();
- + diffTime = 0;
- + }
- + 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 = System.currentTimeMillis();
- + diffTime = 0;
- + }
- + catch (Exception e)
- + {
- + e.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();
- + diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"hopzoneServerTime\":\"", response, "\",\"status_code\":")).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();
- + diffTime = 0;
- + }
- + 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 = System.currentTimeMillis();
- + diffTime = 0;
- + }
- + 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 = System.currentTimeMillis();
- + diffTime = 0;
- + }
- + 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;
- + diffTime = System.currentTimeMillis() - Long.parseLong(VoteUtil.between("\"server_time\":",response,"}}"))*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;
- + diffTime = System.currentTimeMillis() - Long.parseLong(VoteUtil.between("\"serverTime\": ",response,"}}"))*1000;
- + }
- + break;
- +
- + case 10:
- + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal);
- + isVoted = (response == "") ? false : Boolean.parseBoolean(response);
- + if(isVoted) {
- + voteSiteTime = System.currentTimeMillis();
- + diffTime = 0;
- + }
- + break;
- +
- + }
- + if(!response.equals("")) {
- + 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)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 1:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("server_votes\":",response.replace(" ", ""),",\"server_rank");
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 2:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -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)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 4:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("\"totalvotes\":",response,",\"status_code\"");
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 5:
- + String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal),ordinal);
- + totalVotes = (!"".equals(responseNetwork)) ? Integer.parseInt(responseNetwork) : -1;
- + break;
- +
- + case 6:
- + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>");
- +
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 7:
- + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("nicas:</b> ", response, "<br /><br />");
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 8:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("\"monthly_votes\":",response,"}}");
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 9:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\"");
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
- + break;
- +
- + case 10:
- + response = getResponse(getGlobalUrl(ordinal), ordinal);
- + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
- + break;
- + }
- +
- +
- + return totalVotes;
- + }
- +
- + public static String getIndividualUrl(int ordinal,String ip,String AccountName)
- + {
- + String url = "";
- + ip = (votesystem().getTestIp().equalsIgnoreCase("off") || votesystem().getTestIp().equalsIgnoreCase("")) ? ip : votesystem().getTestIp();
- + switch(ordinal) {
- + case 0:
- + //l2.topgameserver.net
- + url = String.format("%sAPI_KEY=%s/getData/%s", votesystem().getVoteLinkTgs(), votesystem().getTgsApiKey(),ip);
- + break;
- +
- + case 1:
- + //itopz.com
- + url = String.format("%s%s/%s/%s", votesystem().getVoteLinkItopz(),votesystem().getItopzZpiKey(),votesystem().getItopzSrvId(),ip);
- + break;
- +
- + case 2:
- + //l2top.co
- + url = String.format("%sVoteCheck.php?id=%s&ip=%s", votesystem().getVoteLinkTopCo(),votesystem().getTopCoSrvId(),ip);
- + break;
- +
- + case 3:
- + //l2votes.com
- + url = String.format("%sapi.php?apiKey=%s&ip=%s", votesystem().getVoteLinkVts(),votesystem().getVtsApiKey(),ip);
- + break;
- +
- + case 4:
- + //hopzone.net
- + url = String.format("%svote?token=%s&ip_address=%s",votesystem().getVoteLinkHz(),votesystem().getHzApiKey(),ip);
- + break;
- +
- + case 5:
- + //l2network.eu
- + url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", votesystem().getVoteNetworkUserName(),ip);
- + break;
- +
- + case 6:
- + //l2topservers.com
- + url = String.format("%stoken=%s&ip=%s", votesystem().getVoteLinkTss(),votesystem().getTssApiToken(),ip);
- + break;
- +
- + case 7:
- + //top.l2jbrasil.com
- + url = String.format("%susername=%s&ip=%s&type=json",votesystem().getBrasilVoteLink(),votesystem().getBrasilUserName(),ip);
- + break;
- +
- + case 8:
- + //mmotop
- + url = String.format("%s%s/ip/%s", votesystem().getVoteLinkMmotop(),votesystem().getMmotopApiKey(),ip);
- + break;
- +
- + case 9:
- + //topzone.com
- + url = String.format("%svote?token=%s&ip=%s", votesystem().getVoteLinkTz(),votesystem().getTzApiKey(),ip);
- + break;
- +
- + case 10:
- + //l2servers.com
- + url = String.format("%scheckip.php?hash=%s&server_id=%s&ip=%s", votesystem().getVoteLinkServers(),votesystem().getServersHashCode(),votesystem().getServersSrvId(),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", votesystem().getVoteLinkTgs(),votesystem().getTgsApiKey());
- + break;
- +
- + case 1:
- + //itopz.com
- + url = String.format("%s%s/%s", votesystem().getVoteLinkItopz(),votesystem().getItopzZpiKey(),votesystem().getItopzSrvId());
- + break;
- +
- + case 2:
- + //l2top.co
- + url = String.format("%sVoteCheck_Total.php?id=%s", votesystem().getVoteLinkTopCo(),votesystem().getTopCoSrvId());
- + break;
- +
- + case 3:
- + //l2votes.com
- + url = String.format("%sserverPage.php?sid=%s",votesystem().getVoteLinkVts(),votesystem().getVtsSid());
- + break;
- +
- + case 4:
- + //hopzone.net
- + url = String.format("%svotes?token=%s", votesystem().getVoteLinkHz(),votesystem().getHzApiKey());
- + break;
- +
- + case 5:
- + //l2network.eu
- + url = String.format("apiKey=%s&type=%s&player=",votesystem().getVoteNetworkApiKey(),1);
- + break;
- +
- + case 6:
- + //l2topservers
- + url = String.format("https://l2topservers.com/l2top/%s/%s", votesystem().getTsSrvId(),votesystem().getTsDomainName());
- + break;
- +
- + case 7:
- + //top.l2jbrasil.com
- + url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s",votesystem().getBrasilUserName());
- + break;
- +
- + case 8:
- + //mmotop.eu/l2/
- + url = String.format("%s%s/info/", votesystem().getVoteLinkMmotop(),votesystem().getMmotopApiKey());
- + break;
- +
- + case 9:
- + //l2topzone.com
- + url = String.format("%sserver_%s/getServerData", votesystem().getVoteLinkTz(),votesystem().getTzApiKey());
- + break;
- +
- + case 10:
- + //l2servers.com
- + url = String.format("%syearlyvotes.php?server_id=%s", votesystem().getVoteLinkServers(),votesystem().getServersSrvId());
- + break;
- + }
- +
- + return url;
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/Handler/voteManager.java b/src/main/java/com/l2jserver/gameserver/votesystem/Handler/voteManager.java
- new file mode 100644
- index 0000000..4cac6cc
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Handler/voteManager.java
- @@ -0,0 +1,328 @@
- +package com.l2jserver.gameserver.votesystem.Handler;
- +
- +import com.l2jserver.gameserver.ThreadPoolManager;
- +import static com.l2jserver.gameserver.config.Configuration.votesystem;
- +import com.l2jserver.gameserver.model.L2World;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.network.L2GameClient;
- +import com.l2jserver.gameserver.network.SystemMessageId;
- +import com.l2jserver.gameserver.network.serverpackets.ItemList;
- +import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- +import com.l2jserver.gameserver.util.Broadcast;
- +import com.l2jserver.gameserver.votesystem.DB.globalVoteDB;
- +import com.l2jserver.gameserver.votesystem.DB.individualVoteDB;
- +import com.l2jserver.gameserver.votesystem.Enum.voteSite;
- +import com.l2jserver.gameserver.votesystem.Model.Reward;
- +import com.l2jserver.gameserver.votesystem.Model.globalVote;
- +import com.l2jserver.gameserver.votesystem.Model.individualVote;
- +import com.l2jserver.gameserver.votesystem.Model.individualVoteResponse;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteSiteXml;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteUtil;
- +import java.util.HashSet;
- +import java.util.Map;
- +import java.util.concurrent.ConcurrentHashMap;
- +import java.util.concurrent.ScheduledFuture;
- +
- +/**
- + *
- + * @author escor
- + */
- + public final class voteManager extends voteHandler{
- + private ScheduledFuture<?> _saveGlobalVotes;
- + private ScheduledFuture<?> _updateIndividualVotes;
- + private ScheduledFuture<?> _autoGlobalVotesReward;
- +
- +
- + private Map<String,individualVote[]> _foundVoters;
- + private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
- +
- + public voteManager() {
- + _foundVoters = new ConcurrentHashMap<>();
- + loadVotes();
- + loadGlobalVotes();
- + checkAllResponseGlobalVotes();
- + stopAutoTasks();
- +
- + if(votesystem().getEnableIndividualVote() && votesystem().getEnableVoteSystem()) {
- + _updateIndividualVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, votesystem().getNextTimeToAutoUpdateIndividualVotes());
- + }
- + if(votesystem().getEnableGlobalVote() && votesystem().getEnableVoteSystem()) {
- + _autoGlobalVotesReward = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, votesystem().getNextTimeToCheckAutoGlobalVotesReward());
- + _saveGlobalVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, votesystem().getNextTimeToAutoUpdateTotalVote());
- + }
- + }
- +
- + 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(L2PcInstance 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: "+VoteSiteXml.getInstance().getSiteName(ordinalSite)+", please try again");
- + return;
- + }
- +
- + if (getTimeRemaining(new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false)) < 0)
- + {
- + player.sendMessage("We were unable to verify your vote with: " + VoteSiteXml.getInstance().getSiteName(ordinalSite) + ", please try again");
- + return;
- + }
- + if(!ivr.getIsVoted()) {
- + player.sendMessage(String.format("You haven't vote on %s yet!", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
- + return;
- + }
- + if(!checkIndividualAvailableVote(player,ordinalSite)) {
- + player.sendMessage(String.format("You can get the reward again on %s at %s", VoteSiteXml.getInstance().getSiteName(ordinalSite),getTimeRemainingWithSampleFormat(player,ordinalSite)));
- + return;
- + }
- + individualVote iv = new individualVote(ip,ivr.getDiffTime(),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);
- + for(Reward reward : VoteSiteXml.getInstance().getRewards(ordinalSite)) {
- + player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null);
- + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addInt(reward.getItemCount()));
- + }
- + player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
- + player.sendPacket(new ItemList(player, true));
- + }else {
- + aiv = _foundVoters.get(ip);
- + iv.setAlreadyRewarded(true);
- + aiv[ordinalSite] = iv;
- + _foundVoters.replace(ip, aiv);
- + for(Reward reward : VoteSiteXml.getInstance().getRewards(ordinalSite)) {
- + player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null);
- + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addInt(reward.getItemCount()));
- + }
- + player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
- + player.sendPacket(new ItemList(player, true));
- + }
- + }
- +
- + public boolean checkIndividualAvailableVote(L2PcInstance 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;
- + timeRemaining = ((iv.getVotingTimeSite() + Config.INTERVAL_TO_NEXT_VOTE) - ((iv.getDiffTime() > 0) ? (System.currentTimeMillis() + iv.getDiffTime()) : (System.currentTimeMillis() - iv.getDiffTime())));
- + return timeRemaining;
- + }
- +
- + public String getTimeRemainingWithSampleFormat(L2PcInstance 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(L2PcInstance p) {
- +
- + L2GameClient client = p.getClient();
- + if(client.getConnection() != null && client.getActiveChar() != null && !client.isDetached()) {
- + try
- + {
- + return client.getConnection().getInetAddress().getHostAddress();
- + }
- + 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*votesystem().getGlobalVotesAmountToNextReward() : votesystem().getGlobalVotesAmountToNextReward())) {
- + _globalVotes[vs.ordinal()].setVotesLastReward(_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25*votesystem().getGlobalVotesAmountToNextReward() : votesystem().getGlobalVotesAmountToNextReward()));
- + for(L2PcInstance player : L2World.getInstance().getPlayers()) {
- + String ip = existIp(player);
- + if(ip == null) {
- + continue;
- + }
- + if(ipList.contains(ip)) {
- + continue;
- + }
- + for(Reward reward : VoteSiteXml.getInstance().getRewards(11)) {
- + player.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), player, null);
- + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addInt(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*votesystem().getGlobalVotesAmountToNextReward() : votesystem().getGlobalVotesAmountToNextReward());
- + 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 * votesystem().getGlobalVotesAmountToNextReward() : votesystem().getGlobalVotesAmountToNextReward());
- + if(last <0 ) {
- + _globalVotes[ordinalSite].setVotesLastReward(0);
- + return;
- + }
- + if((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * votesystem().getGlobalVotesAmountToNextReward() : votesystem().getGlobalVotesAmountToNextReward())) < 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/src/main/java/com/l2jserver/gameserver/votesystem/Model/Reward.java b/src/main/java/com/l2jserver/gameserver/votesystem/Model/Reward.java
- new file mode 100644
- index 0000000..3457ab1
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Model/Reward.java
- @@ -0,0 +1,31 @@
- +package com.l2jserver.gameserver.votesystem.Model;
- +
- +import com.l2jserver.gameserver.model.StatsSet;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class Reward {
- + private int _itemId;
- + private int _itemCount;
- +
- + public Reward(StatsSet set)
- + {
- + _itemId = set.getInt("itemId");
- + _itemCount = set.getInt("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;
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/Model/VoteSite.java b/src/main/java/com/l2jserver/gameserver/votesystem/Model/VoteSite.java
- new file mode 100644
- index 0000000..9c512ee
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Model/VoteSite.java
- @@ -0,0 +1,42 @@
- +package com.l2jserver.gameserver.votesystem.Model;
- +
- +import java.util.ArrayList;
- +import java.util.List;
- +
- +/*
- + * To change this license header, choose License Headers in Project Properties.
- + * To change this template file, choose Tools | Templates
- + * and open the template in the editor.
- + */
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class VoteSite {
- + private int _siteOrdinal;
- + private String _siteName;
- + private List<Reward> _rewards = new ArrayList<>();
- + public VoteSite() {
- +
- + }
- + public void setSiteOrdinal(int siteOrdinal) {
- + _siteOrdinal = siteOrdinal;
- + }
- + public void setSiteName(String siteName) {
- + _siteName = siteName;
- + }
- + public void setRewardList(List<Reward> rewards) {
- + for(Reward r : rewards)
- + _rewards.add(r);
- + }
- + public int getSiteOrdinal() {
- + return _siteOrdinal;
- + }
- + public String getSiteName() {
- + return _siteName;
- + }
- + public List<Reward> getRewardList(){
- + return _rewards;
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/Model/globalVote.java b/src/main/java/com/l2jserver/gameserver/votesystem/Model/globalVote.java
- new file mode 100644
- index 0000000..48275fb
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Model/globalVote.java
- @@ -0,0 +1,43 @@
- +package com.l2jserver.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;
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/Model/individualVote.java b/src/main/java/com/l2jserver/gameserver/votesystem/Model/individualVote.java
- new file mode 100644
- index 0000000..c67eec4
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Model/individualVote.java
- @@ -0,0 +1,72 @@
- +/*
- + * To change this license header, choose License Headers in Project Properties.
- + * To change this template file, choose Tools | Templates
- + * and open the template in the editor.
- + */
- +package com.l2jserver.gameserver.votesystem.Model;
- +
- +/**
- + *
- + * @author escor
- + */
- + public class individualVote {
- + private String _voterIp;
- + private long _diffTime;
- + private long _votingTimeSite;
- + private int _voteSite;
- + private boolean _alreadyRewarded;
- +
- +
- + public individualVote(String voterIp, long diffTime, long votingTimeSite, int voteSite, boolean alreadyRewarded){
- + _voterIp = voterIp;
- + _diffTime = diffTime;
- + _votingTimeSite = votingTimeSite;
- + _voteSite = voteSite;
- + _alreadyRewarded = alreadyRewarded;
- + }
- +
- + public individualVote(){
- +
- + }
- +
- + public void setVoterIp(String voterIp) {
- + _voterIp = voterIp;
- + }
- +
- + public void setDiffTime(long diffTime) {
- + _diffTime = diffTime;
- + }
- +
- + 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 getDiffTime() {
- + return _diffTime;
- + }
- +
- + public long getVotingTimeSite() {
- + return _votingTimeSite;
- + }
- +
- + public int getVoteSite() {
- + return _voteSite;
- + }
- +
- + public boolean getAlreadyRewarded() {
- + return _alreadyRewarded;
- + }
- +
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/Model/individualVoteResponse.java b/src/main/java/com/l2jserver/gameserver/votesystem/Model/individualVoteResponse.java
- new file mode 100644
- index 0000000..d0a72f4
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/Model/individualVoteResponse.java
- @@ -0,0 +1,35 @@
- +package com.l2jserver.gameserver.votesystem.Model;
- +
- +/**
- + *
- + * @author escor
- + */
- +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;
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/VoteUtil/VoteSiteXml.java b/src/main/java/com/l2jserver/gameserver/votesystem/VoteUtil/VoteSiteXml.java
- new file mode 100644
- index 0000000..9e34c43
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/VoteUtil/VoteSiteXml.java
- @@ -0,0 +1,76 @@
- +package com.l2jserver.gameserver.votesystem.VoteUtil;
- +
- +import com.l2jserver.gameserver.util.IXmlReader;
- +import com.l2jserver.gameserver.votesystem.Model.Reward;
- +import com.l2jserver.gameserver.votesystem.Model.VoteSite;
- +import java.util.Collection;
- +import java.util.HashMap;
- +import java.util.Map;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +import org.w3c.dom.Document;
- +import org.w3c.dom.Node;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class VoteSiteXml implements IXmlReader{
- + private static final Logger LOGGER = Logger.getLogger(VoteSiteXml.class.getName());
- + private final Map<Integer,VoteSite> _voteSites = new HashMap<>();
- +
- + protected VoteSiteXml() {
- + load();
- + }
- +
- + @Override
- + public synchronized void load()
- + {
- + parseDatapackFile("data/votesystem.xml");
- + LOGGER.log(Level.INFO,"Loaded {} reward sites", _voteSites.size());
- + }
- +
- +
- + @Override
- + public void parseDocument(Document doc)
- + {
- + for(Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()){
- + if("list".equalsIgnoreCase(n.getNodeName())){
- + for(Node d = n.getFirstChild(); d != null; d = d.getNextSibling()){
- + if("votesite".equalsIgnoreCase(d.getNodeName())){
- + final VoteSite votesite = new VoteSite();
- + votesite.setSiteName(parseString(d.getAttributes(),"name"));
- + votesite.setSiteOrdinal(parseInteger(d.getAttributes(),"ordinal"));
- + for(Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling()){
- + for(Node cde = cd.getFirstChild(); cde != null; cde = cde.getNextSibling()){
- + if("item".equalsIgnoreCase(cde.getNodeName())){
- + votesite.getRewardList().add(new Reward(parseAttributes(cde)));
- + _voteSites.put(votesite.getSiteOrdinal(), votesite);
- + }
- + }
- + }
- + }
- + }
- + }
- + }
- + }
- +
- +
- + public String getSiteName(int ordinal) {
- + return _voteSites.get(ordinal).getSiteName();
- + }
- +
- + public Collection<Reward> getRewards(int ordinal){
- + return _voteSites.get(ordinal).getRewardList();
- + }
- +
- + public static final VoteSiteXml getInstance()
- + {
- + return SingletonHolder.INSTANCE;
- + }
- +
- + private static final class SingletonHolder
- + {
- + protected static final VoteSiteXml INSTANCE = new VoteSiteXml();
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/java/com/l2jserver/gameserver/votesystem/VoteUtil/VoteUtil.java b/src/main/java/com/l2jserver/gameserver/votesystem/VoteUtil/VoteUtil.java
- new file mode 100644
- index 0000000..c41f162
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/gameserver/votesystem/VoteUtil/VoteUtil.java
- @@ -0,0 +1,118 @@
- +package com.l2jserver.gameserver.votesystem.VoteUtil;
- +
- +import com.l2jserver.gameserver.votesystem.Enum.voteSite;
- +import java.io.BufferedReader;
- +import java.io.InputStreamReader;
- +import java.net.HttpURLConnection;
- +import java.net.URL;
- +import java.time.LocalDateTime;
- +import java.time.ZoneId;
- +import java.time.ZonedDateTime;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class VoteUtil {
- + private static final Logger LOGGER = Logger.getLogger(VoteUtil.class.getName());
- +
- + private static String voteTimeZones[] = {
- + "topgameserver.net=Europe/Berlin",
- + "itopz.com=America/New_York",
- + "l2top.co=Europe/London",
- + "l2votes.com=GMT",
- + "hopzone.net=Europe/Athens",
- + "l2network.eu=America/Chicago",
- + "l2topservers.com=Europe/Athens",
- + "top.l2jbrasil.com=America/Sao_Paulo",
- + "mmotop.eu=America/Chicago",
- + "l2topzone.com=America/Chicago",
- + "l2servers.com=America/Chicago",
- + };
- +
- + public static final long getTimeVotingSite(int ordinalSite) {
- + LocalDateTime ldt = LocalDateTime.now(ZoneId.of(voteTimeZones[ordinalSite].split("=")[1]));
- + ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
- + long millis = zdt.toInstant().toEpochMilli();
- + return millis;
- + }
- +
- + 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"
- + };
- +
- + 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 == voteSite.L2VOTES.ordinal()) {
- + if(inputLine.contains("Votes:")) {
- + response.append(inputLine);
- + break;
- + }
- + }
- + if(ordinal == voteSite.TOPL2JBRASIL.ordinal()){
- + if(inputLine.contains("<b>Entradas ")) {
- + response.append(inputLine);
- + break;
- + }
- + }
- + if(ordinal == voteSite.L2TOPSERVERS.ordinal()){
- + if(inputLine.contains("VOTE <span>")) {
- + response.append(inputLine);
- + break;
- + }
- + }
- + }
- + in.close();
- + return response.toString();
- + }
- +
- + }
- + catch (Exception e)
- + {
- + LOGGER.log(Level.INFO, "{0} Say: An error ocurred: {1}", new Object[]{VoteUtil.Sites[ordinal], e.getMessage()});
- + 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;
- + }
- +}
- \ No newline at end of file
- diff --git a/src/main/resources/config/votesystem.properties b/src/main/resources/config/votesystem.properties
- new file mode 100644
- index 0000000..ef708bb
- --- /dev/null
- +++ b/src/main/resources/config/votesystem.properties
- @@ -0,0 +1,94 @@
- +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
- +
- +IntervalToNextVote = 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
- +
- +## Mmotop.eu
- +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 localhost test if your project is live, put the word off or leave it blank
- +TestIp =
- ============================================= DATAPACK ====================================================
- diff --git a/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java b/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java
- index 5efeda6..c9eaee3 100644
- --- a/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java
- +++ b/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java
- @@ -265,7 +265,9 @@
- import com.l2jserver.datapack.handlers.voicedcommandhandlers.Debug;
- import com.l2jserver.datapack.handlers.voicedcommandhandlers.Lang;
- import com.l2jserver.datapack.handlers.voicedcommandhandlers.StatsVCmd;
- +import com.l2jserver.datapack.handlers.voicedcommandhandlers.VoteSystem;
- import com.l2jserver.datapack.handlers.voicedcommandhandlers.Wedding;
- +import static com.l2jserver.gameserver.config.Configuration.votesystem;
- import com.l2jserver.gameserver.handler.ActionHandler;
- import com.l2jserver.gameserver.handler.ActionShiftHandler;
- import com.l2jserver.gameserver.handler.AdminCommandHandler;
- @@ -566,6 +568,7 @@
- (customs().multiLangEnable() && customs().multiLangVoiceCommand() ? Lang.class : null),
- (customs().debugVoiceCommand() ? Debug.class : null),
- (customs().allowChangePassword() ? ChangePassword.class : null),
- + (votesystem().getEnableVoteSystem() && votesystem().getEnableIndividualVote() && votesystem().getEnableVotingCommand() ? VoteSystem.class : null),
- };
- // TODO(Zoey76): Add this handler.
- diff --git a/src/main/java/com/l2jserver/datapack/handlers/voicedcommandhandlers/VoteSystem.java b/src/main/java/com/l2jserver/datapack/handlers/voicedcommandhandlers/VoteSystem.java
- new file mode 100644
- index 0000000..6448823
- --- /dev/null
- +++ b/src/main/java/com/l2jserver/datapack/handlers/voicedcommandhandlers/VoteSystem.java
- @@ -0,0 +1,70 @@
- +package com.l2jserver.datapack.handlers.voicedcommandhandlers;
- +
- +import static com.l2jserver.gameserver.config.Configuration.votesystem;
- +import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.votesystem.Handler.voteManager;
- +import com.l2jserver.gameserver.votesystem.Enum.voteSite;
- +import com.l2jserver.gameserver.votesystem.VoteUtil.VoteSiteXml;
- +
- +/**
- + *
- + * @author l2.topgameserver.net
- + */
- +public class VoteSystem implements IVoicedCommandHandler{
- +
- + @Override
- + public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params) {
- + if (command.equalsIgnoreCase(votesystem().getVotingCommand()))
- + {
- + if(!votesystem().getEnableVoteSystem()) {
- + activeChar.sendMessage("The rewards system has been disabled by your administrator");
- + return false;
- + }
- + if(!votesystem().getEnableIndividualVote()) {
- + activeChar.sendMessage("The individual reward system is disabled");
- + return false;
- + }
- + if(!votesystem().getEnableVotingCommand()) {
- + activeChar.sendMessage("Voting command reward is disabled");
- + return false;
- + }
- + if(activeChar.isJailed()) {
- + activeChar.sendMessage("You can't use that function while incarcerated");
- + return false;
- + }
- +
- + for(voteSite vs : voteSite.values()) {
- +
- + new Thread(()->{
- + voteManager.getInatance().getReward(activeChar, vs.ordinal());
- + }).start();
- + }
- +
- + }
- + if(command.equalsIgnoreCase("reloadrewards")) {
- + if(activeChar.isGM()) {
- + VoteSiteXml.getInstance().load();
- + activeChar.sendMessage("All rewards sites has been reloaded");
- + }
- + }
- + if(command.equalsIgnoreCase("rechargeiv")) {
- + if(activeChar.isGM()) {
- + voteManager.getInatance().saveVotes();
- + voteManager.getInatance().loadVotes();
- + activeChar.sendMessage("All individual votes has been recharged");
- + }
- + }
- + return true;
- + }
- +
- + @Override
- + public String[] getVoicedCommandList() {
- + return new String[]{
- + votesystem().getVotingCommand(),
- + "reloadrewards",
- + "rechargeiv",
- + };
- + }
- +
- +}
- \ No newline at end of file
- diff --git a/src/main/resources/data/html/mods/votesystem/1000004.html b/src/main/resources/data/html/mods/votesystem/1000004.html
- new file mode 100644
- index 0000000..4b54f8e
- --- /dev/null
- +++ b/src/main/resources/data/html/mods/votesystem/1000004.html
- @@ -0,0 +1,20 @@
- +
- +<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/src/main/resources/data/stats/npcs/custom/custom.xml b/src/main/resources/data/stats/npcs/custom/custom.xml
- index 18f8f27..094ebc4 100644
- --- a/src/main/resources/data/stats/npcs/custom/custom.xml
- +++ b/src/main/resources/data/stats/npcs/custom/custom.xml
- @@ -58,4 +58,10 @@
- <height normal="22.25" />
- </collision>
- </npc>
- + <npc id="1000004" displayId="32226" name="Kaaya" usingServerSideName="true" title="Vote Reward System" usingServerSideTitle="true" type="L2NpcVote">
- + <collision>
- + <radius normal="11" />
- + <height normal="22.25" />
- + </collision>
- + </npc>
- </list>
- \ No newline at end of file
- diff --git a/src/main/resources/data/votesystem.xml b/src/main/resources/data/votesystem.xml
- new file mode 100644
- index 0000000..c125243
- --- /dev/null
- +++ b/src/main/resources/data/votesystem.xml
- @@ -0,0 +1,71 @@
- +<?xml version="1.0" encoding="UTF-8"?>
- +<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xsd/votesystem.xsd">
- +
- + <votesite name="l2.topgameserver.net" ordinal="0">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + </items>
- + </votesite>
- + <votesite name="ItopZ.com" ordinal="1">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + </items>
- + </votesite>
- + <votesite name="L2Top.co" ordinal="2">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Votes.com" ordinal="3">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + </items>
- + </votesite>
- + <votesite name="Hopzone.net" ordinal="4">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + </items>
- + </votesite>
- + <votesite name="L2Network.eu" ordinal="5">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Topservers.com" ordinal="6">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="top.l2jbrasil.com" ordinal="7">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="MMOTOP.eu" ordinal="8">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Topzone.com" ordinal="9">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + </items>
- + </votesite>
- + <votesite name="L2Servers.com" ordinal="10">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="globalVotes" ordinal="11">
- + <items>
- + <item itemId="57" itemCount="100000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- +</list>
- \ No newline at end of file
- diff --git a/src/main/resources/data/xsd/votesystem.xsd b/src/main/resources/data/xsd/votesystem.xsd
- new file mode 100644
- index 0000000..4d63c5d
- --- /dev/null
- +++ b/src/main/resources/data/xsd/votesystem.xsd
- @@ -0,0 +1,32 @@
- +<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
- + <xs:element name="list">
- + <xs:complexType>
- + <xs:sequence>
- + <xs:element name="votesite" maxOccurs="unbounded" minOccurs="0">
- + <xs:complexType>
- + <xs:sequence>
- + <xs:element name="items">
- + <xs:complexType>
- + <xs:sequence>
- + <xs:element name="item" maxOccurs="unbounded" minOccurs="0">
- + <xs:complexType>
- + <xs:simpleContent>
- + <xs:extension base="xs:string">
- + <xs:attribute type="xs:short" name="itemId" use="optional"/>
- + <xs:attribute type="xs:int" name="itemCount" use="optional"/>
- + </xs:extension>
- + </xs:simpleContent>
- + </xs:complexType>
- + </xs:element>
- + </xs:sequence>
- + </xs:complexType>
- + </xs:element>
- + </xs:sequence>
- + <xs:attribute type="xs:string" name="name" use="optional"/>
- + <xs:attribute type="xs:byte" name="ordinal" use="optional"/>
- + </xs:complexType>
- + </xs:element>
- + </xs:sequence>
- + </xs:complexType>
- + </xs:element>
- +</xs:schema>
- -- ----------------------------
- -- 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,
- `DiffTime` bigint(20) NULL DEFAULT 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;
Add Comment
Please, Sign In to add comment