Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
### Eclipse Workspace Patch 1.0 #P Trunk Index: java/l2f/gameserver/model/instances/VoteRewardInstance.java =================================================================== --- java/l2f/gameserver/model/instances/VoteRewardInstance.java (nonexistent) +++ java/l2f/gameserver/model/instances/VoteRewardInstance.java (working copy) @@ -0,0 +1,102 @@ +package l2f.gameserver.model.instances; + + +import l2f.gameserver.Config; +import l2f.gameserver.data.xml.holder.ItemHolder; +import l2f.gameserver.model.Player; +import l2f.gameserver.network.serverpackets.NpcHtmlMessage; +import l2f.gameserver.templates.npc.NpcTemplate; +import l2f.gameserver.votesystem.Enum.voteSite; +import l2f.gameserver.votesystem.Handler.voteManager; +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml; +import l2f.gameserver.votesystem.Model.Reward; + +@SuppressWarnings("serial") +public class VoteRewardInstance extends NpcInstance{ + + public VoteRewardInstance(int objectId, NpcTemplate template) { + super(objectId,template); + } + + @Override + public void onBypassFeedback(Player 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 boolean isNpc() + { + return true; + } + + @Override + public void showChatWindow(Player player, int val, Object... arg) + { + + final NpcHtmlMessage html = new NpcHtmlMessage(player, this,getHtmlPath(this.getTemplate().getNpcId(), 0, player) , 0); + StringBuilder sb = new StringBuilder(); + if (Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE) + { + 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", VoteSiteXml.getInstance().getSiteName(vs.ordinal())) + "</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=\"L2UI_ct1.button_df\" 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(player, 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>", ItemHolder.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>"); + } + } + else + { + sb.append("<table bgcolor=000000 width=280><tr><td><p><font color=#bfb300 >Individual vote system has been disabled for your server owner.</font></p></td></tr></table>"); + } + 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,Player player) + { + String filename = ""; + if (val == 0) + { + filename = "" + npcId; + } + else + { + filename = npcId + "-" + val; + } + + return "custom/votesystem/" + filename + ".html"; + } +} Index: java/l2f/gameserver/handler/voicecommands/impl/VoteReward.java =================================================================== --- java/l2f/gameserver/handler/voicecommands/impl/VoteReward.java (nonexistent) +++ java/l2f/gameserver/handler/voicecommands/impl/VoteReward.java (working copy) @@ -0,0 +1,64 @@ +package l2f.gameserver.handler.voicecommands.impl; + +import l2f.gameserver.Config; +import l2f.gameserver.handler.voicecommands.IVoicedCommandHandler; +import l2f.gameserver.model.Player; +import l2f.gameserver.votesystem.Enum.voteSite; +import l2f.gameserver.votesystem.Handler.voteManager; +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml; + +public class VoteReward implements IVoicedCommandHandler{ + + @Override + public boolean useVoicedCommand(String command, Player player, String params) + { + if (command.equalsIgnoreCase("rewardme")) + { + if (player.isJailed()) + { + 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; + } + + + for (voteSite vs : voteSite.values()) + { + new Thread(() -> + { + voteManager.getInatance().getReward(player, vs.ordinal()); + }).start(); + } + + return true; + + } + if (command.equalsIgnoreCase("reloadrewards") && player.isGM()) + { + VoteSiteXml.getInstance().load(); + player.sendMessage("=====All reward has been reloaded======"); + return true; + } + return false; + } + + @Override + public String[] getVoicedCommandList() + { + return new String[] + { + "rewardme", + "reloadrewards", + }; + } + +} Index: java/l2f/gameserver/votesystem/DB/globalVoteDB.java =================================================================== --- java/l2f/gameserver/votesystem/DB/globalVoteDB.java (nonexistent) +++ java/l2f/gameserver/votesystem/DB/globalVoteDB.java (working copy) @@ -0,0 +1,121 @@ +package l2f.gameserver.votesystem.DB; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.logging.Logger; + +import l2f.gameserver.database.DatabaseFactory; +import l2f.gameserver.votesystem.Enum.voteSite; +import l2f.gameserver.votesystem.Model.globalVote; + + +/** + * @author l2.topgameserver.net + */ +public class globalVoteDB +{ + public static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName()); + private final globalVote[] _globalVotes; + + private globalVoteDB() + { + _globalVotes = new globalVote[voteSite.values().length]; + loadGlobalVotes(); + } + + public void loadGlobalVotes() + { + + try (Connection con = DatabaseFactory.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; + } + ps.close(); + con.close(); + + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + public void saveGlobalVote(globalVote gb) + { + try (Connection con = DatabaseFactory.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(); + + ps.close(); + con.close(); + + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + public void saveGlobalVotes(globalVote[] globalVotes) + { + try (Connection con = DatabaseFactory.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(); + + 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(); + } +} Index: java/l2f/gameserver/handler/voicecommands/VoicedCommandHandler.java =================================================================== --- java/l2f/gameserver/handler/voicecommands/VoicedCommandHandler.java (revision 1) +++ java/l2f/gameserver/handler/voicecommands/VoicedCommandHandler.java (working copy) @@ -36,6 +36,7 @@ import l2f.gameserver.handler.voicecommands.impl.ServerInfo; import l2f.gameserver.handler.voicecommands.impl.Teleport; import l2f.gameserver.handler.voicecommands.impl.VoiceGmEvent; +import l2f.gameserver.handler.voicecommands.impl.VoteReward; import l2f.gameserver.handler.voicecommands.impl.Wedding; import l2f.gameserver.handler.voicecommands.impl.WhoAmI; import l2f.gameserver.handler.voicecommands.impl.res; @@ -83,6 +84,7 @@ registerVoicedCommandHandler(new LockPc()); registerVoicedCommandHandler(new NpcSpawn()); registerVoicedCommandHandler(new Donate()); + registerVoicedCommandHandler(new VoteReward()); if (Config.ENABLE_ACHIEVEMENTS) registerVoicedCommandHandler(new AchievementsVoice()); Index: dist/gameserver/data/xsd/votesystem.xsd =================================================================== --- dist/gameserver/data/xsd/votesystem.xsd (nonexistent) +++ dist/gameserver/data/xsd/votesystem.xsd (working copy) @@ -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> Index: java/l2f/gameserver/votesystem/VoteUtil/VoteSiteXml.java =================================================================== --- java/l2f/gameserver/votesystem/VoteUtil/VoteSiteXml.java (nonexistent) +++ java/l2f/gameserver/votesystem/VoteUtil/VoteSiteXml.java (working copy) @@ -0,0 +1,122 @@ +package l2f.gameserver.votesystem.VoteUtil; + +import java.io.File; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + + +import l2f.gameserver.Config; +import l2f.gameserver.votesystem.Model.Reward; +import l2f.gameserver.votesystem.Model.VoteSite; + +/** + * @author l2.topgameserver.net + */ +public class VoteSiteXml +{ + private final Map<Integer, VoteSite> _voteSites = new HashMap<>(); + private static Logger LOGGER = Logger.getLogger(VoteSiteXml.class); + + private VoteSiteXml(){ + load(); + } + + + public void load() + { + try + { + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + factory.setIgnoringComments(true); + + File file = new File(Config.DATAPACK_ROOT + "/data/votesystem.xml"); + if (!file.exists()) + { + if (Config.DEBUG) + { + LOGGER.info("The votesystem file is missing."); + } + return; + } + + Document doc = factory.newDocumentBuilder().parse(file); + + 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()) + { + final VoteSite votesite = new VoteSite(); + if ("votesite".equalsIgnoreCase(d.getNodeName())) + { + NamedNodeMap attrs = d.getAttributes(); + String name = attrs.getNamedItem("name").getNodeValue(); + int ordinal = Integer.parseInt(attrs.getNamedItem("ordinal").getNodeValue()); + votesite.setSiteName(name); + votesite.setSiteOrdinal(ordinal); + for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling()) + { + if ("item".equalsIgnoreCase(cd.getNodeName())) + { + attrs = cd.getAttributes(); + int itemId = Integer.parseInt(attrs.getNamedItem("itemId").getNodeValue()); + int itemCount = Integer.parseInt(attrs.getNamedItem("itemCount").getNodeValue()); + votesite.getRewardList().add(new Reward(itemId,itemCount)); + } + + } + _voteSites.put(votesite.getSiteOrdinal(), votesite); + attrs = null; + } + } + } + } + + + doc = null; + file = null; + } + catch (final Exception e) + { + e.printStackTrace(); + + LOGGER.error("Error parsing votesystem.xml", e); + + return; + } + } + + + 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(); + } + + + +} Index: java/l2f/gameserver/GameServer.java =================================================================== --- java/l2f/gameserver/GameServer.java (revision 1) +++ java/l2f/gameserver/GameServer.java (working copy) @@ -90,6 +90,8 @@ import l2f.gameserver.taskmanager.tasks.RestoreOfflineTraders; import l2f.gameserver.utils.Strings; import l2f.gameserver.vote.VoteMain; +import l2f.gameserver.votesystem.Handler.voteManager; +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml; import net.sf.ehcache.CacheManager; import org.slf4j.Logger; @@ -296,6 +298,19 @@ VoicedCommandHandler.getInstance().log(); TaskManager.getInstance(); _log.info("======================[Loading Castels & Clan Halls]=========================="); + + // load vote reward system + printSection("Vote Reward System"); + if (Config.ENABLE_VOTE_SYSTEM) + { + voteManager.getInatance(); + _log.info("======================Vote System Enabled========================="); + VoteSiteXml.getInstance(); + } + else + { + _log.info("======================Vote System Disabled========================="); + } ResidenceHolder.getInstance().callInit(); EventHolder.getInstance().callInit(); CastleManorManager.getInstance(); Index: java/l2f/gameserver/network/clientpackets/RequestBypassToServer.java =================================================================== --- java/l2f/gameserver/network/clientpackets/RequestBypassToServer.java (revision 1) +++ java/l2f/gameserver/network/clientpackets/RequestBypassToServer.java (working copy) @@ -122,6 +122,29 @@ ((NpcInstance) object).onBypassFeedback(activeChar, bp.bypass.substring(endOfId + 1)); } } + else if (bp.bypass.startsWith("vote_")) + { + + int endOfId = bp.bypass.indexOf('_', 6); + String id; + if (endOfId > 0) + { + id = bp.bypass.substring(5, endOfId); + } + else + { + id = bp.bypass.substring(5); + } + + if (bp.bypass.split(" ")[1].toString() != null) + { + GameObject object = activeChar.getVisibleObject(Integer.parseInt(id)); + if ((object != null) && object.isNpc() && (endOfId > 0) && activeChar.isInRange(object, Creature.INTERACTION_DISTANCE)) + { + ((NpcInstance) object).onBypassFeedback(activeChar, bp.bypass.split(" ")[1].toString()); + } + } + } else if (bp.bypass.startsWith("_olympiad?")) { String[] ar = bp.bypass.replace("_olympiad?", "").split("&"); Index: java/l2f/gameserver/votesystem/Model/individualVote.java =================================================================== --- java/l2f/gameserver/votesystem/Model/individualVote.java (nonexistent) +++ java/l2f/gameserver/votesystem/Model/individualVote.java (working copy) @@ -0,0 +1,78 @@ +package l2f.gameserver.votesystem.Model; + +/** + * @author l2.topgameserver.net + */ +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; + } + +} Index: java/l2f/gameserver/votesystem/Model/Reward.java =================================================================== --- java/l2f/gameserver/votesystem/Model/Reward.java (nonexistent) +++ java/l2f/gameserver/votesystem/Model/Reward.java (working copy) @@ -0,0 +1,44 @@ +package l2f.gameserver.votesystem.Model; + +import l2f.gameserver.templates.StatsSet; + +/** + * @author l2.topgameserver.net + */ +public class Reward +{ + private int _itemId; + private int _itemCount; + + public Reward(int itemId, int itemCount) + { + this._itemId = itemId; + this._itemCount = itemCount; + } + + public Reward(StatsSet set) + { + _itemId = set.getInteger("itemId"); + _itemCount = set.getInteger("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; + } +} Index: java/l2f/gameserver/votesystem/VoteUtil/VoteUtil.java =================================================================== --- java/l2f/gameserver/votesystem/VoteUtil/VoteUtil.java (nonexistent) +++ java/l2f/gameserver/votesystem/VoteUtil/VoteUtil.java (working copy) @@ -0,0 +1,122 @@ +package l2f.gameserver.votesystem.VoteUtil; + +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.Logger; + + +/** + * @author l2.topgameserver.net + */ +public final class VoteUtil +{ + public 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 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 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 == 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; + } + +} Index: java/l2f/gameserver/votesystem/Model/globalVote.java =================================================================== --- java/l2f/gameserver/votesystem/Model/globalVote.java (nonexistent) +++ java/l2f/gameserver/votesystem/Model/globalVote.java (working copy) @@ -0,0 +1,53 @@ +package l2f.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; + } + +} Index: java/l2f/gameserver/votesystem/Enum/voteSite.java =================================================================== --- java/l2f/gameserver/votesystem/Enum/voteSite.java (nonexistent) +++ java/l2f/gameserver/votesystem/Enum/voteSite.java (working copy) @@ -0,0 +1,19 @@ +package l2f.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 +} Index: java/l2f/gameserver/votesystem/Model/individualVoteResponse.java =================================================================== --- java/l2f/gameserver/votesystem/Model/individualVoteResponse.java (nonexistent) +++ java/l2f/gameserver/votesystem/Model/individualVoteResponse.java (working copy) @@ -0,0 +1,46 @@ +package l2f.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; + } +} Index: dist/gameserver/data/votesystem.xml =================================================================== --- dist/gameserver/data/votesystem.xml (nonexistent) +++ dist/gameserver/data/votesystem.xml (working copy) @@ -0,0 +1,46 @@ +<?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"> + <item itemId="57" itemCount="100000" /> + </votesite> + <votesite name="ItopZ.com" ordinal="1"> + <item itemId="57" itemCount="100000" /> + </votesite> + <votesite name="L2Top.co" ordinal="2"> + <item itemId="57" itemCount="100000" /> + <item itemId="6673" itemCount="1"/> + </votesite> + <votesite name="L2Votes.com" ordinal="3"> + <item itemId="57" itemCount="100000" /> + </votesite> + <votesite name="Hopzone.net" ordinal="4"> + <item itemId="57" itemCount="100000" /> + </votesite> + <votesite name="L2Network.eu" ordinal="5"> + <item itemId="57" itemCount="100000" /> + <item itemId="6673" itemCount="1"/> + </votesite> + <votesite name="L2Topservers.com" ordinal="6"> + <item itemId="57" itemCount="100000" /> + <item itemId="6673" itemCount="1"/> + </votesite> + <votesite name="top.l2jbrasil.com" ordinal="7"> + <item itemId="57" itemCount="100000" /> + <item itemId="6673" itemCount="1"/> + </votesite> + <votesite name="MMOTOP.eu" ordinal="8"> + <item itemId="57" itemCount="100000" /> + <item itemId="6673" itemCount="1"/> + </votesite> + <votesite name="L2Topzone.com" ordinal="9"> + <item itemId="57" itemCount="100000" /> + </votesite> + <votesite name="L2Servers.com" ordinal="10"> + <item itemId="57" itemCount="100000" /> + <item itemId="6673" itemCount="1"/> + </votesite> + <votesite name="globalVotes" ordinal="11"> + <item itemId="57" itemCount="100000" /> + <item itemId="6673" itemCount="1"/> + </votesite> +</list> \ No newline at end of file Index: dist/gameserver/config/votesystem.ini =================================================================== --- dist/gameserver/config/votesystem.ini (nonexistent) +++ dist/gameserver/config/votesystem.ini (working copy) @@ -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 + +IntervalToNextVote = 12 + +GlobalVotesAmountToNextReward = 1 + +EnableVotingCommand = True + +VotingCommand = rewardme + +## 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 = + Index: java/l2f/gameserver/votesystem/DB/individualVoteDB.java =================================================================== --- java/l2f/gameserver/votesystem/DB/individualVoteDB.java (nonexistent) +++ java/l2f/gameserver/votesystem/DB/individualVoteDB.java (working copy) @@ -0,0 +1,180 @@ +package l2f.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 l2f.gameserver.database.DatabaseFactory; +import l2f.gameserver.votesystem.Enum.voteSite; +import l2f.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 individualVoteDB() + { + _votes = new HashMap<>(); + loadVotes(); + } + + public void loadVotes() + { + _votes.clear(); + try (Connection con = DatabaseFactory.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 = DatabaseFactory.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 = DatabaseFactory.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(Connection con = DatabaseFactory.getInstance().getConnection();Statement 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(); + } +} Index: java/l2f/gameserver/votesystem/Handler/voteHandler.java =================================================================== --- java/l2f/gameserver/votesystem/Handler/voteHandler.java (nonexistent) +++ java/l2f/gameserver/votesystem/Handler/voteHandler.java (working copy) @@ -0,0 +1,510 @@ +package l2f.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 l2f.gameserver.Config; +import l2f.gameserver.votesystem.Enum.voteSite; +import l2f.gameserver.votesystem.Model.individualVoteResponse; +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml; +import l2f.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(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 = (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: + // mmotop + 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: + // mmotop.eu/l2/ + 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 Index: java/l2f/gameserver/votesystem/Handler/voteManager.java =================================================================== --- java/l2f/gameserver/votesystem/Handler/voteManager.java (nonexistent) +++ java/l2f/gameserver/votesystem/Handler/voteManager.java (working copy) @@ -0,0 +1,394 @@ +package l2f.gameserver.votesystem.Handler; + +import java.util.HashSet; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; + +import l2f.gameserver.Announcements; +import l2f.gameserver.Config; +import l2f.gameserver.ThreadPoolManager; +import l2f.gameserver.model.GameObjectsStorage; +import l2f.gameserver.model.Player; +import l2f.gameserver.network.GameClient; +import l2f.gameserver.network.serverpackets.components.ChatType; +import l2f.gameserver.votesystem.DB.globalVoteDB; +import l2f.gameserver.votesystem.DB.individualVoteDB; +import l2f.gameserver.votesystem.Enum.voteSite; +import l2f.gameserver.votesystem.Model.Reward; +import l2f.gameserver.votesystem.Model.globalVote; +import l2f.gameserver.votesystem.Model.individualVote; +import l2f.gameserver.votesystem.Model.individualVoteResponse; +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml; +import l2f.gameserver.votesystem.VoteUtil.VoteUtil; +import l2f.gameserver.network.serverpackets.SystemMessage2; +import l2f.gameserver.network.serverpackets.components.SystemMsg; + +/** + * @author l2.topgameserver.net + */ +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 (Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM) + { + _updateIndividualVotes = ThreadPoolManager.getInstance().scheduleAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES); + } + if (Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM) + { + _autoGlobalVotesReward = ThreadPoolManager.getInstance().scheduleAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD); + _saveGlobalVotes = ThreadPoolManager.getInstance().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(Player 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); + } + 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(reward.getItemId(), reward.getItemCount(),"VoteSystem"); + player.sendPacket(new SystemMessage2(SystemMsg.YOU_HAVE_EARNED_S2_S1S).addItemName(reward.getItemId()).addInteger(reward.getItemCount())); + } + player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite))); + player.sendItemList(true);; + } + + public boolean checkIndividualAvailableVote(Player 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 ? iv.getDiffTime() : -1 * iv.getDiffTime())) - System.currentTimeMillis(); + return timeRemaining; + } + + public String getTimeRemainingWithSampleFormat(Player 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(Player p) + { + + GameClient client = p.getNetConnection(); + if ((client.getConnection() != null) && (client.getActiveChar() != null) && client.isAuthed()) + { + try + { + return client.getIpAddr(); + } + 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 (Player player : GameObjectsStorage.getAllPlayersForIterate()) + { + String ip = existIp(player); + if (ip == null) + { + continue; + } + if (ipList.contains(ip)) + { + continue; + } + for (Reward reward : VoteSiteXml.getInstance().getRewards(11)) + { + player.getInventory().addItem(reward.getItemId(), reward.getItemCount(),"VoteSystem"); + player.sendPacket(new SystemMessage2(SystemMsg.YOU_HAVE_EARNED_S2_S1S).addItemName(reward.getItemId()).addInteger(reward.getItemCount())); + } + ipList.add(ip); + player.sendItemList(true);; + } + Announcements.getInstance().announceToAll(VoteUtil.Sites[vs.ordinal()] + ": All players has been rewarded, please check your inventory", ChatType.CRITICAL_ANNOUNCE); + } + 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()); + Announcements.getInstance().announceToAll(encourage, ChatType.CRITICAL_ANNOUNCE); + } + }).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(); + } +} Index: java/l2f/gameserver/votesystem/Model/VoteSite.java =================================================================== --- java/l2f/gameserver/votesystem/Model/VoteSite.java (nonexistent) +++ java/l2f/gameserver/votesystem/Model/VoteSite.java (working copy) @@ -0,0 +1,53 @@ +package l2f.gameserver.votesystem.Model; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author l2.topgameserver.net + */ +public class VoteSite +{ + private int _siteOrdinal; + private String _siteName; + private final 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 Index: java/l2f/gameserver/Shutdown.java =================================================================== --- java/l2f/gameserver/Shutdown.java (revision 1) +++ java/l2f/gameserver/Shutdown.java (working copy) @@ -27,6 +27,7 @@ import l2f.gameserver.scripts.Scripts; import l2f.gameserver.utils.Log; import l2f.gameserver.utils.Util; +import l2f.gameserver.votesystem.Handler.voteManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; */ public synchronized void cancel() { @@ -247,6 +248,12 @@ private void saveData() { + // Save individual votes data + if (Config.ENABLE_VOTE_SYSTEM) + { + voteManager.getInatance().Shutdown(); + _log.info("VoteSystem: Data saved."); + } try { // Seven Signs data is now saved along with Festival data. Index: java/l2f/gameserver/Config.java =================================================================== --- java/l2f/gameserver/Config.java (revision 1) +++ java/l2f/gameserver/Config.java (working copy) import java.util.Properties; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -114,6 +114,7 @@ public static final String DEFENSE_TOWNS_CONFIG_FILE = "config/events/DefenseTowns.ini"; public static final String VIKTORINA_CONFIG_FILE = "config/events/Victorina.ini"; public static final String PVP_MOD_CONFIG_FILE = "config/mod/PvPmod.ini"; + public static final String VOTE_SYSTEM_FILE = "config/votesystem.ini"; public static final String ZONE_DRAGONVALLEY_FILE = "config/zones/DragonValley.ini"; public static final String ZONE_LAIROFANTHARAS_FILE = "config/zones/LairOfAntharas.ini"; @@ -313,7 +314,52 @@ public static int SERVICES_EXCHANGE_EQUIP_ITEM_PRICE; public static int SERVICES_EXCHANGE_UPGRADE_EQUIP_ITEM; public static int SERVICES_EXCHANGE_UPGRADE_EQUIP_ITEM_PRICE; + + // --------------------------------------------------- + // 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; + // L2Mythras Configs public static int DONATOR_NPC_ITEM; public static String DONATOR_NPC_ITEM_NAME; @@ -2643,6 +2689,49 @@ SERVICES_EXCHANGE_UPGRADE_EQUIP_ITEM_PRICE = DonationStore.getProperty("ExchangeUpgradeEquipPrice", 50); } + public static void loadVoteSystemConfig() { + ExProperties votesystem = load(VOTE_SYSTEM_FILE); + ENABLE_VOTE_SYSTEM = votesystem.getProperty("EnableVoteSystem", true); + ENABLE_INDIVIDUAL_VOTE = votesystem.getProperty("EnableIndividualVote", true); + ENABLE_GLOBAL_VOTE = votesystem.getProperty("EnableGlobalVote", true); + NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoUpdateTotalVote", 60));// -> minutes + NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoUpdateIndividualVotes", 60));// -> minutes + NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoCleanInnecesaryVotes", 30));// -> minutes + NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToCheckAutoGlobalVotesReward", 5));// -> minutes + INTERVAL_TO_NEXT_VOTE = TimeUnit.HOURS.toMillis(votesystem.getProperty("IntervalTimeToNextVote", 12)); // -> hours + GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = votesystem.getProperty("GlobalVotesAmountToNextReward", 50); + ENABLE_VOTING_COMMAND = votesystem.getProperty("EnableVotingCommand", true); + VOTING_COMMAND = votesystem.getProperty("VotingCommand", "rewardme"); + VOTE_LINK_TGS = votesystem.getProperty("VoteLinkTgs", ""); + TGS_API_KEY = votesystem.getProperty("TgsApiKey", ""); + VOTE_LINK_TOP_CO = votesystem.getProperty("VoteLinkTopCo", ""); + TOP_CO_SRV_ID = votesystem.getProperty("TopCoSrvId", ""); + VOTE_LINK_ITOPZ = votesystem.getProperty("VoteLinkItopz", ""); + ITOPZ_API_KEY = votesystem.getProperty("ItopzZpiKey", ""); + ITOPZ_SRV_ID = votesystem.getProperty("ItopzSrvId", ""); + VOTE_LINK_VTS = votesystem.getProperty("VoteLinkVts", ""); + VTS_API_KEY = votesystem.getProperty("VtsApiKey", ""); + VTS_SID = votesystem.getProperty("VtsSid", ""); + VOTE_LINK_HZ = votesystem.getProperty("VoteLinkHz", ""); + HZ_API_KEY = votesystem.getProperty("HzApiKey", ""); + VOTE_NETWORK_LINK = votesystem.getProperty("VoteNetworkLink", ""); + VOTE_NETWORK_USER_NAME = votesystem.getProperty("VoteNetworkUserName", ""); + VOTE_NETWORK_API_KEY = votesystem.getProperty("VoteNetworkApiKey", ""); + VOTE_LINK_TSS = votesystem.getProperty("VoteLinkTss", ""); + TSS_API_TOKEN = votesystem.getProperty("TssApiToken", ""); + TS_SRV_ID = votesystem.getProperty("TsSrvId", ""); + TS_DOMAIN_NAME = votesystem.getProperty("TsDomainName", ""); + BRASIL_VOTE_LINK = votesystem.getProperty("BrasilVoteLink", ""); + BRASIL_USER_NAME = votesystem.getProperty("BrasilUserName", ""); + VOTE_LINK_MMOTOP = votesystem.getProperty("VoteLinkMmotop", ""); + MMOTOP_API_KEY = votesystem.getProperty("MmotopApiKey", ""); + VOTE_LINK_TZ = votesystem.getProperty("VoteLinkTz", ""); + TZ_API_KEY = votesystem.getProperty("TzApiKey", ""); + VOTE_LINK_SERVERS = votesystem.getProperty("VoteLinkServers", ""); + SERVERS_HASH_CODE = votesystem.getProperty("ServersHashCode", ""); + SERVERS_SRV_ID = votesystem.getProperty("ServersSrvId", ""); + TEST_IP = votesystem.getProperty("TestIp", ""); + } public static void loadNpcConfig() { ExProperties npcSettings = load(NPC_FILE); @@ -4423,6 +4512,7 @@ loadItemsUseConfig(); loadSchemeBuffer(); loadChatConfig(); + loadVoteSystemConfig(); loadDonationStore(); loadNpcConfig(); loadBossConfig(); Index: dist/gameserver/data/html-en/custom/votesystem/53008.html =================================================================== --- dist/gameserver/data/html-en/custom/votesystem/53008.html (nonexistent) +++ dist/gameserver/data/html-en/custom/votesystem/53008.html (working copy) @@ -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 Index: dist/gameserver/data/npc/53000-53099.xml =================================================================== --- dist/gameserver/data/npc/53000-53099.xml (revision 1) +++ dist/gameserver/data/npc/53000-53099.xml (working copy) @@ -621,4 +621,51 @@ <defence attribute="unholy" value="200" /> </attributes> </npc> + <npc id="53008" name="Kaaya" title="Vote Reward System"> + <set name="aggroRange" value="0" /> + <set name="ai_type" value="CharacterAI" /> + <set name="baseAtkRange" value="40" /> + <set name="baseCON" value="43" /> + <set name="baseCritRate" value="40" /> + <set name="baseDEX" value="30" /> + <set name="baseHpMax" value="2444.468" /> + <set name="baseHpRate" value="1" /> + <set name="baseHpReg" value="7.5" /> + <set name="baseINT" value="21" /> + <set name="baseMAtk" value="780" /> + <set name="baseMAtkSpd" value="500" /> + <set name="baseMDef" value="382" /> + <set name="baseMEN" value="20" /> + <set name="baseMpMax" value="1345.8" /> + <set name="baseMpReg" value="2.7" /> + <set name="basePAtk" value="1303" /> + <set name="basePAtkSpd" value="253" /> + <set name="basePDef" value="471" /> + <set name="baseRunSpd" value="120" /> + <set name="baseSTR" value="40" /> + <set name="baseShldDef" value="0" /> + <set name="baseShldRate" value="0" /> + <set name="baseWIT" value="20" /> + <set name="baseWalkSpd" value="26" /> + <set name="collision_height" value="15.0" /> + <set name="collision_radius" value="8.0" /> + <set name="level" value="70" /> + <set name="rewardExp" value="0" /> + <set name="rewardRp" value="0" /> + <set name="rewardSp" value="0" /> + <set name="shots" value="NONE" /> + <set name="texture" value="" /> + <set name="type" value="VoteReward" /> + <skills> + <skill id="4416" level="7" /> <!--Spirits--> + </skills> + <attributes> + <defence attribute="fire" value="150" /> + <defence attribute="water" value="150" /> + <defence attribute="wind" value="150" /> + <defence attribute="earth" value="150" /> + <defence attribute="holy" value="150" /> + <defence attribute="unholy" value="150" /> + </attributes> + </npc> </list> ==========================================SQL================================ -- ---------------------------- -- 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;
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
⭐✅ Swapzone Glitch ✅ Working
JavaScript | 9 sec ago | 0.25 KB
⭐✅ Trading Profit Method ⭐
JavaScript | 21 sec ago | 0.25 KB
ChangeNOW Exploit
JavaScript | 35 sec ago | 0.25 KB
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐
JavaScript | 47 sec ago | 0.25 KB
⭐✅ MAKE $2500 IN 15 MIN ⭐
JavaScript | 59 sec ago | 0.25 KB
⭐✅ Crypto Exchange Exploit ⭐⭐
JavaScript | 1 min ago | 0.25 KB
⭐ Instant BTC Profit Method ⭐
JavaScript | 1 min ago | 0.25 KB
✅⭐ Make $2500 in 15 minutes ⭐✅
JavaScript | 2 min ago | 0.25 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!