Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P L2jFrozen_15
- Index: head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java (working copy)
- @@ -0,0 +1,391 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.votesystem.Handler;
- +
- +import java.util.HashSet;
- +import java.util.Iterator;
- +import java.util.Map;
- +import java.util.Optional;
- +import java.util.Set;
- +import java.util.concurrent.ConcurrentHashMap;
- +import java.util.concurrent.ScheduledFuture;
- +import java.util.stream.Collectors;
- +
- +import com.l2jfrozen.Config;
- +import com.l2jfrozen.gameserver.model.L2World;
- +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jfrozen.gameserver.network.L2GameClient;
- +import com.l2jfrozen.gameserver.network.SystemMessageId;
- +import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
- +import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
- +import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
- +import com.l2jfrozen.gameserver.util.Broadcast;
- +import com.l2jfrozen.gameserver.votesystem.DB.globalVoteDB;
- +import com.l2jfrozen.gameserver.votesystem.DB.individualVoteDB;
- +import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
- +import com.l2jfrozen.gameserver.votesystem.Model.Reward;
- +import com.l2jfrozen.gameserver.votesystem.Model.globalVote;
- +import com.l2jfrozen.gameserver.votesystem.Model.individualVote;
- +import com.l2jfrozen.gameserver.votesystem.Model.individualVoteResponse;
- +import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
- +import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteUtil;
- +
- +/**
- + * @author l2.topgameserver.net
- + *
- + */
- +public class voteManager extends voteHandler
- +{
- + private ScheduledFuture<?> _saveGlobalVotes;
- + private ScheduledFuture<?> _updateIndividualVotes;
- + private ScheduledFuture<?> _cleanInnecesaryIndividualVotes;
- + private ScheduledFuture<?> _autoGlobalVotesReward;
- +
- + private HashSet<individualVote> _votes;
- + private Map<String,individualVote[]> _foundVoters;
- + private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
- +
- + public voteManager() {
- + loadVotes();
- + loadGlobalVotes();
- + _foundVoters = new ConcurrentHashMap<>();
- + checkAllResponseGlobalVotes();
- + stopAutoTasks();
- +
- + if(Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM) {
- + _cleanInnecesaryIndividualVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoCleanInnecesaryIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES);
- + _updateIndividualVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES);
- + }
- + if(Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM) {
- + _autoGlobalVotesReward = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD);
- + _saveGlobalVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(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(_cleanInnecesaryIndividualVotes != null) {
- + _cleanInnecesaryIndividualVotes.cancel(true);
- + _cleanInnecesaryIndividualVotes = null;
- + }
- + if(_autoGlobalVotesReward != null) {
- + _autoGlobalVotesReward.cancel(true);
- + _autoGlobalVotesReward = null;
- + }
- + }
- +
- + public void getReward(L2PcInstance activeChar, 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);
- + _votes.add(iv);
- + individualVote[] aiv;
- + if(!_foundVoters.containsKey(ip)) {
- + Set<individualVote> ivts = _votes.stream().filter(st -> st.getVoterIp().equalsIgnoreCase(iv.getVoterIp())).collect(Collectors.toSet());
- + aiv = new individualVote[voteSite.values().length];
- + if(ivts.size()>1) {
- + ivts.forEach(x -> {
- + x.setAlreadyRewarded(true);
- + aiv[x.getVoteSite()] = x;
- + });
- + iv.setAlreadyRewarded(true);
- + _foundVoters.put(ip, aiv);
- + }else {
- + aiv[ordinalSite] = iv;
- + iv.setAlreadyRewarded(true);
- + _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()).addNumber(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()).addNumber(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 activeChar, int ordinalSite) {
- + String ip = existIp(activeChar);
- + //If player has registered almost 1 vote
- + 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;
- + }
- + }
- + }
- +
- + //if the player hasn't registered a vote or after the initial charge
- + Optional<individualVote> iv = _votes.stream().filter(s -> s.getVoterIp().equalsIgnoreCase(ip)).filter(y -> y.getVoteSite() == ordinalSite).findFirst();
- + if(!iv.isPresent()) {
- + return true;
- + }
- + if(getTimeRemaining(iv.get()) <0) {
- + 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 activeChar, int ordinalSite) {
- + String ip = existIp(activeChar);
- + 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;
- + }
- + }
- + }
- + Optional<individualVote> iv = _votes.stream().filter(s -> s.getVoterIp().equalsIgnoreCase(ip)).filter(y -> y.getVoteSite() == ordinalSite).findFirst();
- + if(iv.isPresent()) {
- + if(getTimeRemaining(iv.get()) > 0) {
- + long timeRemaining = getTimeRemaining(iv.get());
- + 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 activeChar) {
- +
- + L2GameClient client = activeChar.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() {
- + _votes = individualVoteDB.getInstance().getVotesDB();
- + }
- + protected void loadGlobalVotes(){
- + _globalVotes = globalVoteDB.getInstance().getGlobalVotes();
- + }
- + protected void saveVotes() {
- + individualVoteDB.getInstance().SaveVotes(_votes);
- + }
- +
- + 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() + Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD) {
- + _globalVotes[vs.ordinal()].setVotesLastReward(_globalVotes[vs.ordinal()].getVotesLastReward() + Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
- + for(L2PcInstance activeChar : L2World.getInstance().getAllPlayers()) {
- + String ip = existIp(activeChar);
- + if(ip == null) {
- + continue;
- + }
- + if(ipList.contains(ip)) {
- + continue;
- + }
- + for(Reward reward : VoteSiteXml.getInstance().getRewards(11)) {
- + activeChar.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), activeChar, null);
- + activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
- + }
- + ipList.add(ip);
- + activeChar.sendPacket(new ItemList(activeChar, true));
- + }
- + Broadcast.announceToOnlinePlayers(VoteUtil.Sites[vs.ordinal()]+": All players has been rewarded, please check your inventory", true);
- + }else {
- + String encourage ="";
- + int nextReward = _globalVotes[vs.ordinal()].getVotesLastReward() + Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD;
- + encourage = String.format("Vote for %s current Votes: %s, next quantity of votes to reward : %s, need votes to next reward: %s", VoteUtil.Sites[vs.ordinal()], _globalVotes[vs.ordinal()].getCurrentVotes(),nextReward, nextReward-_globalVotes[vs.ordinal()].getCurrentVotes() );
- + Broadcast.announceToOnlinePlayers(encourage, true);
- + }
- + }).start();
- +
- + }
- + }
- +
- + protected void AutoSaveGlobalVotes() {
- + globalVoteDB.getInstance().saveGlobalVotes(_globalVotes);
- + }
- +
- + protected synchronized void AutoUpdateIndividualVotes() {
- + individualVoteDB.getInstance().SaveVotes(_votes);
- + }
- +
- + protected synchronized void AutoCleanInnecesaryIndividualVotes() {
- + HashSet<individualVote> removeVotes= new HashSet<>();
- + Iterator<individualVote> iv = _votes.iterator();
- + while(iv.hasNext()){
- + individualVote individualvote = iv.next();
- + if(getTimeRemaining(individualvote) < 0) {
- + removeVotes.add(individualvote);
- + iv.remove();
- + 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 - Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD;
- + if(last <0 ) {
- + _globalVotes[ordinalSite].setVotesLastReward(0);
- + return;
- + }
- + if((_globalVotes[ordinalSite].getVotesLastReward() + Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD) < globalVotesResponse) {
- + _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse);
- + return;
- + }
- + }
- +
- + public void Shutdown() {
- + AutoSaveGlobalVotes();
- + AutoCleanInnecesaryIndividualVotes();
- + AutoUpdateIndividualVotes();
- + }
- +
- + protected class AutoGlobalVoteRewardTask implements Runnable {
- +
- + /* (non-Javadoc)
- + * @see java.lang.Runnable#run()
- + */
- + @Override
- + public void run()
- + {
- + AutoGlobalVoteReward();
- +
- + }
- +
- + }
- +
- + protected class AutoSaveGlobalVotesTask implements Runnable {
- +
- + /* (non-Javadoc)
- + * @see java.lang.Runnable#run()
- + */
- + @Override
- + public void run()
- + {
- + AutoSaveGlobalVotes();
- +
- + }
- +
- + }
- +
- + protected class AutoUpdateIndividualVotesTask implements Runnable {
- +
- + /* (non-Javadoc)
- + * @see java.lang.Runnable#run()
- + */
- + @Override
- + public void run()
- + {
- + AutoUpdateIndividualVotes();
- +
- + }
- +
- + }
- +
- + protected class AutoCleanInnecesaryIndividualVotesTask implements Runnable {
- +
- + /* (non-Javadoc)
- + * @see java.lang.Runnable#run()
- + */
- + @Override
- + public void run()
- + {
- + AutoCleanInnecesaryIndividualVotes();
- +
- + }
- +
- + }
- +
- + public static voteManager getInatance() {
- + return SingleHolder.INSTANCE;
- + }
- +
- + private static class SingleHolder {
- + protected static final voteManager INSTANCE = new voteManager();
- + }
- +}
- Index: head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java (working copy)
- @@ -0,0 +1,512 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- +*/
- +package com.l2jfrozen.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.Level;
- +import java.util.logging.Logger;
- +
- +import com.l2jfrozen.Config;
- +import com.l2jfrozen.gameserver.votesystem.Model.individualVoteResponse;
- +import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
- +import com.l2jfrozen.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) {
- + 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;
- + StringBuffer response = new StringBuffer();
- +
- + 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)
- + {
- +
- + 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 = 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 = Boolean.parseBoolean(response);
- + if(isVoted) {
- + voteSiteTime = System.currentTimeMillis();
- + diffTime = 0;
- + }
- + break;
- +
- + case 2:
- + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal);
- + isVoted = Boolean.parseBoolean(response);
- + if(isVoted) {
- + voteSiteTime = System.currentTimeMillis();
- + diffTime = 0;
- + }
- + break;
- +
- + case 3:
- + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal);
- + isVoted = 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 = 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 = (Integer.parseInt(response) == 1) ? true : false;
- + if(isVoted) {
- + voteSiteTime = System.currentTimeMillis();
- + diffTime = 0;
- + }
- + break;
- +
- + case 6:
- + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal);
- + isVoted = Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
- + if(isVoted) {
- + try
- + {
- + voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"l2topserversServerTime\"")).getTime();
- + diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"l2topserversServerTime\":\"", response, "\",\"status_code\"")).getTime();
- + }
- + catch (ParseException e)
- + {
- + e.printStackTrace();
- + }
- +
- + }
- + break;
- +
- + case 7:
- + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal);
- + isVoted = Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1 ? true : false;
- + if(isVoted) {
- + try
- + {
- + voteSiteTime = format.parse(VoteUtil.between("\"date\":\"", response, "\",\"status\"")).getTime();
- + diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"server_time\":\"", response, "\",\"hours_since_vote\"")).getTime();
- + }
- + catch (ParseException e)
- + {
- + e.printStackTrace();
- + }
- + }
- + break;
- +
- + case 8:
- + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal);
- + isVoted = 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 = 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,"}}"));
- + }
- + break;
- +
- + case 10:
- + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal);
- + isVoted = 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(response)) ? Integer.parseInt(responseNetwork) : -1;
- + break;
- +
- + /*case 6:
- +
- + 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 = "";
- + 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
- + return String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS,Config.TGS_API_KEY);
- + break;*/
- +
- + case 7:
- + //top.l2jbrasil.com
- + url = "https://top.l2jbrasil.com/index.php?a=stats&u=julioguzman";
- + 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;
- + }
- +}
- Index: head-src/com/l2jfrozen/gameserver/util/Broadcast.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/util/Broadcast.java (revision 1257)
- +++ head-src/com/l2jfrozen/gameserver/util/Broadcast.java (working copy)
- @@ -42,6 +42,9 @@
- import com.l2jfrozen.gameserver.network.serverpackets.L2GameServerPacket;
- import com.l2jfrozen.gameserver.network.serverpackets.RelationChanged;
- +import com.l2jfrozen.gameserver.network.clientpackets.Say2;
- +import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
- +
- /**
- * This class ...
- * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
- @@ -237,4 +240,8 @@
- onlinePlayer.sendPacket(mov);
- }
- }
- + public static void announceToOnlinePlayers(String text, boolean critical)
- + {
- + toAllOnlinePlayers(new CreatureSay(0, (critical) ? Say2.CRITICAL_ANNOUNCE : Say2.ANNOUNCEMENT, "", text));
- + }
- }
- Index: head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java (working copy)
- @@ -0,0 +1,86 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.votesystem.VoteUtil;
- +
- +import java.nio.file.Path;
- +import java.util.Collection;
- +import java.util.HashMap;
- +import java.util.Map;
- +import java.util.logging.Level;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +
- +import com.l2jfrozen.gameserver.util.IXmlReader;
- +import com.l2jfrozen.gameserver.votesystem.Model.Reward;
- +import com.l2jfrozen.gameserver.votesystem.Model.VoteSite;
- +
- +/**
- + * @author l2.topgameserver.net
- + *
- + */
- +public class VoteSiteXml implements IXmlReader
- +{
- + private final Map<Integer,VoteSite> _voteSites = new HashMap<>();
- +
- + public VoteSiteXml() {
- + load();
- + }
- +
- +
- + @Override
- + public void load()
- + {
- + parseFile("data/xml/votesystem.xml");
- + LOGGER.log(Level.INFO,"Loaded {} reward sites", _voteSites.size());
- + }
- +
- + @Override
- + public void parseDocument(Document doc, Path path)
- + {
- + forEach(doc, "list", listNode -> {
- + forEach(listNode, "votesite", votesiteNode -> {
- + final VoteSite votesite = new VoteSite();
- + final NamedNodeMap attrs = votesiteNode.getAttributes();
- + votesite.setSiteOrdinal(parseInteger(attrs,"ordinal"));
- + votesite.setSiteName(parseString(attrs,"name"));
- + forEach(votesiteNode,"items", itemsNode -> forEach(itemsNode,"item",itemNode
- + -> votesite.getRewardList().add(new Reward(parseInteger(itemNode.getAttributes(),"itemId"),parseInteger(itemNode.getAttributes(),"itemCount")))));
- + _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();
- + }
- +
- +}
- Index: head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java (revision 1257)
- +++ head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
- @@ -215,6 +217,31 @@
- else
- player.processQuestEvent(p.substring(0, idx), p.substring(idx).trim());
- + }else if(bypassCommand.startsWith("vote_")) {
- +
- + if (!activeChar.validateBypass(bypassCommand))
- + return;
- +
- + int endOfId = bypassCommand.indexOf('_', 6);
- + String id;
- + if (endOfId > 0)
- + id = bypassCommand.substring(5, endOfId);
- + else
- + id = bypassCommand.substring(5);
- +
- + if(bypassCommand.split(" ")[1].toString() != null) {
- + final L2Object object = L2World.getInstance().findObject(Integer.parseInt(id));
- + if ((Config.ALLOW_CLASS_MASTERS && Config.ALLOW_REMOTE_CLASS_MASTERS && object instanceof L2ClassMasterInstance) || (object instanceof L2NpcInstance && endOfId > 0 && activeChar.isInsideRadius(object, L2NpcInstance.INTERACTION_DISTANCE, false, false)))
- + ((L2NpcInstance) object).onBypassFeedback(activeChar, bypassCommand.split(" ")[1].toString());
- + }
- + }
- else if (bypassCommand.startsWith("custom_"))
- CustomBypassHandler.getInstance().handleBypass(activeChar, bypassCommand);
- else if (bypassCommand.startsWith("OlympiadArenaChange"))
- Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java (working copy)
- @@ -0,0 +1,81 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.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: dist/gameserver/data/xml/votesystem.xml
- ===================================================================
- --- dist/gameserver/data/xml/votesystem.xml (nonexistent)
- +++ dist/gameserver/data/xml/votesystem.xml (working copy)
- @@ -0,0 +1,75 @@
- +<?xml version="1.0" encoding="UTF-8"?>
- +<list>
- + <votesite name="l2.topgameserver.net" ordinal="0">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="ItopZ.com" ordinal="1">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Top.co" ordinal="2">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Votes.com" ordinal="3">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="Hopzone.net" ordinal="4">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Network.eu" ordinal="5">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Topservers.com" ordinal="6">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="top.l2jbrasil.com" ordinal="7">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="MMOTOP.eu" ordinal="8">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Topzone.com" ordinal="9">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="L2Servers.com" ordinal="10">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- + <votesite name="globalVotes" ordinal="11">
- + <items>
- + <item itemId="57" itemCount="10000000" />
- + <item itemId="6673" itemCount="1"/>
- + </items>
- + </votesite>
- +</list>
- \ No newline at end of file
- Index: dist/gameserver/data/html/mods/votesystem/25529.html
- ===================================================================
- --- dist/gameserver/data/html/mods/votesystem/25529.html (nonexistent)
- +++ dist/gameserver/data/html/mods/votesystem/25529.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 background="L2UI_CH3.refinewnd_back_Pattern">
- + <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/config/votesystem.properties
- ===================================================================
- --- dist/gameserver/config/votesystem.properties (nonexistent)
- +++ dist/gameserver/config/votesystem.properties (working copy)
- @@ -0,0 +1,93 @@
- +
- +EnableVoteSystem = True
- +
- +EnableGlobalVote = True
- +
- +EnableIndividualVote = True
- +
- +## Time to Update table totalVotes from DB in minutes
- +NextTimeToAutoUpdateTotalVote = 2
- +
- +## Time to update table individualVotes in minutes
- +NextTimeToAutoUpdateIndividualVotes = 30
- +
- +## In minutes
- +NextTimeToAutoCleanInnecesaryVotes = 30
- +
- +## In minutes
- +NextTimeToCheckAutoGlobalVotesReward = 10
- +
- +## In hours
- +IntervalToNextVote = 12
- +
- +## Amount of votes to set reward
- +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 =
- +
- +## L2Votes - Server Id
- +VtsSid = 208
- +
- +## 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 =
- +
- +## top.l2jbrasil.com
- +BrasilVoteLink = https://top.l2jbrasil.com/votesystem/index.php?
- +
- +BrasilUserName =
- +
- +## 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 =
- +
- Index: head-src/com/l2jfrozen/gameserver/util/IXmlReader.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/util/IXmlReader.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/util/IXmlReader.java (working copy)
- @@ -0,0 +1,228 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.util;
- +
- +import java.io.IOException;
- +import java.nio.file.FileVisitOption;
- +import java.nio.file.FileVisitResult;
- +import java.nio.file.Files;
- +import java.nio.file.Path;
- +import java.nio.file.Paths;
- +import java.nio.file.SimpleFileVisitor;
- +import java.nio.file.attribute.BasicFileAttributes;
- +import java.util.EnumSet;
- +import java.util.LinkedList;
- +import java.util.List;
- +import java.util.function.Consumer;
- +import java.util.function.Predicate;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import javax.xml.parsers.DocumentBuilder;
- +import javax.xml.parsers.DocumentBuilderFactory;
- +import javax.xml.parsers.ParserConfigurationException;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +import org.w3c.dom.NodeList;
- +import org.xml.sax.ErrorHandler;
- +import org.xml.sax.SAXException;
- +import org.xml.sax.SAXParseException;
- +
- +
- +
- +/**
- + * @author aCis
- + *
- + */
- +
- +public interface IXmlReader
- +{
- + public static final Logger LOGGER = Logger.getLogger(IXmlReader.class.getName());
- +
- + String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
- + String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
- +
- + void load();
- +
- +void parseDocument(Document doc, Path path);
- +
- + default void parseFile(String path)
- + {
- + parseFile(Paths.get(path), false, true, true);
- + }
- +
- + default void parseFile(Path path, boolean validate, boolean ignoreComments, boolean ignoreWhitespaces)
- + {
- + if (Files.isDirectory(path))
- + {
- + final List<Path> pathsToParse = new LinkedList<>();
- + try
- + {
- + Files.walkFileTree(path, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new SimpleFileVisitor<Path>()
- + {
- + @Override
- + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- + {
- + pathsToParse.add(file);
- + return FileVisitResult.CONTINUE;
- + }
- + });
- +
- + pathsToParse.forEach(p -> parseFile(p, validate, ignoreComments, ignoreWhitespaces));
- + }
- + catch (IOException e)
- + {
- + LOGGER.log(Level.WARNING,"Could not parse directory: {} ", e);
- + }
- + }
- + else
- + {
- + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- + dbf.setNamespaceAware(true);
- + dbf.setValidating(validate);
- + dbf.setIgnoringComments(ignoreComments);
- + dbf.setIgnoringElementContentWhitespace(ignoreWhitespaces);
- + dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
- +
- + try
- + {
- + final DocumentBuilder db = dbf.newDocumentBuilder();
- + db.setErrorHandler(new XMLErrorHandler());
- + parseDocument(db.parse(path.toAbsolutePath().toFile()), path);
- + }
- + catch (SAXParseException e)
- + {
- + LOGGER.log(Level.WARNING, "Could not parse file: "+path+" at line: "+e.getLineNumber()+", column: "+e.getColumnNumber()+" :", e);
- + }
- + catch (ParserConfigurationException | SAXException | IOException e)
- + {
- + LOGGER.log(Level.WARNING ,"Could not parse file: "+path+" ", e);
- + }
- + }
- + }
- +
- +
- + default void forEach(Node node, Consumer<Node> action)
- + {
- + forEach(node, a -> true, action);
- + }
- +
- + default void forEach(Node node, String nodeName, Consumer<Node> action)
- + {
- + forEach(node, innerNode ->
- + {
- + if (nodeName.contains("|"))
- + {
- + final String[] nodeNames = nodeName.split("\\|");
- + for (String name : nodeNames)
- + {
- + if (!name.isEmpty() && name.equals(innerNode.getNodeName()))
- + {
- + return true;
- + }
- + }
- + return false;
- + }
- + return nodeName.equals(innerNode.getNodeName());
- + }, action);
- + }
- +
- + default void forEach(Node node, Predicate<Node> filter, Consumer<Node> action)
- + {
- + final NodeList list = node.getChildNodes();
- + for (int i = 0; i < list.getLength(); i++)
- + {
- + final Node targetNode = list.item(i);
- + if (filter.test(targetNode))
- + {
- + action.accept(targetNode);
- + }
- + }
- + }
- +
- + default int parseInt(Node node, Integer defaultValue)
- + {
- + return node != null ? Integer.decode(node.getNodeValue()) : defaultValue;
- + }
- +
- + default int parseInt(Node node)
- + {
- + return parseInt(node, -1);
- + }
- +
- + default Integer parseInteger(Node node, Integer defaultValue)
- + {
- + return node != null ? Integer.decode(node.getNodeValue()) : defaultValue;
- + }
- +
- + default Integer parseInteger(Node node)
- + {
- + return parseInteger(node, null);
- + }
- +
- + default Integer parseInteger(NamedNodeMap attrs, String name)
- + {
- + return parseInteger(attrs.getNamedItem(name));
- + }
- +
- + default Integer parseInteger(NamedNodeMap attrs, String name, Integer defaultValue)
- + {
- + return parseInteger(attrs.getNamedItem(name), defaultValue);
- + }
- +
- + default String parseString(Node node, String defaultValue)
- + {
- + return node != null ? node.getNodeValue() : defaultValue;
- + }
- +
- + default String parseString(Node node)
- + {
- + return parseString(node, null);
- + }
- +
- + default String parseString(NamedNodeMap attrs, String name)
- + {
- + return parseString(attrs.getNamedItem(name));
- + }
- +
- + default String parseString(NamedNodeMap attrs, String name, String defaultValue)
- + {
- + return parseString(attrs.getNamedItem(name), defaultValue);
- + }
- +
- +
- + class XMLErrorHandler implements ErrorHandler
- + {
- + @Override
- + public void warning(SAXParseException e) throws SAXParseException
- + {
- + throw e;
- + }
- +
- + @Override
- + public void error(SAXParseException e) throws SAXParseException
- + {
- + throw e;
- + }
- +
- + @Override
- + public void fatalError(SAXParseException e) throws SAXParseException
- + {
- + throw e;
- + }
- + }
- +}
- Index: head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java (working copy)
- @@ -0,0 +1,108 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.votesystem.DB;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
- +import com.l2jfrozen.gameserver.votesystem.Model.globalVote;
- +import com.l2jfrozen.util.database.L2DatabaseFactory;
- +
- +/**
- + * @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 = L2DatabaseFactory.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", _globalVotes.length);
- +
- + }catch(SQLException e) {
- +
- + e.printStackTrace();
- + }
- + }
- + public void saveGlobalVote(globalVote gb) {
- + try(Connection con = L2DatabaseFactory.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 = L2DatabaseFactory.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();
- + }
- +}
- Index: head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java (working copy)
- @@ -0,0 +1,154 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.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.HashSet;
- +import java.util.logging.Logger;
- +
- +import com.l2jfrozen.gameserver.votesystem.Model.individualVote;
- +import com.l2jfrozen.util.database.L2DatabaseFactory;
- +
- +
- +/**
- + * @author l2.topgameserver.net
- + *
- + */
- +public class individualVoteDB
- +{
- + private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
- + private HashSet<individualVote> _votes;
- + private Statement st;
- + private Connection con;
- +
- + private individualVoteDB() {
- + _votes = new HashSet<>();
- + loadVotes();
- + }
- +
- + public void loadVotes() {
- +
- + _votes.clear();
- + try(Connection con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualVotes");
- + ResultSet rs = ps.executeQuery();)
- + {
- + 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"));
- + _votes.add(iv);
- + }
- + }
- + catch (SQLException e)
- + {
- + e.printStackTrace();
- + }
- +
- + }
- +
- + public void SaveVotes(HashSet<individualVote> votes) {
- +
- + if(votes == null)
- + return;
- + if(votes.size() == 0) {
- + return;
- + }
- + try(Connection con = L2DatabaseFactory.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(individualVote iv : votes) {
- + 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 = L2DatabaseFactory.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 = L2DatabaseFactory.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 HashSet<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: head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java (working copy)
- @@ -0,0 +1,34 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.votesystem.Enum;
- +
- +/**
- + * @author l2.topgameserver.net
- + *
- + */
- +public enum voteSite
- +{
- + L2TOPGAMESERVER,
- + ITOPZ,
- + L2TOPCO,
- + L2VOTES,
- + HOPZONE,
- + L2NETWORK,
- + L2TOPSERVERS,
- + TOPL2JBRASIL,
- + MMOTOP,
- + TOPZONE,
- + L2SERVERS,
- +}
- Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java (working copy)
- @@ -0,0 +1,44 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.votesystem.Model;
- +
- +/**
- + * @author l2.topgameserver.net
- + *
- + */
- +public class Reward
- +{
- + private int _itemId;
- + private int _itemCount;
- +
- + public Reward(int itemId, int itemCount)
- + {
- + _itemId = itemId;
- + _itemCount = itemCount;
- + }
- +
- + public void setItemId(int itemId) {
- + _itemId = itemId;
- + }
- + public void setItemCount(int itemCount) {
- + _itemCount = itemCount;
- + }
- + public int getItemId() {
- + return _itemId;
- + }
- + public int getItemCount() {
- + return _itemCount;
- + }
- +}
- Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java (working copy)
- @@ -0,0 +1,51 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.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 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;
- + }
- +}
- Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java (working copy)
- @@ -0,0 +1,59 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.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: head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java (working copy)
- @@ -0,0 +1,50 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.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: head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java (working copy)
- @@ -0,0 +1,128 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.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 org.apache.log4j.Logger;
- +
- +import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
- +
- +/**
- + * @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;
- + }
- + }
- + }
- + in.close();
- + return response.toString();
- + }
- +
- + }
- + catch (Exception e)
- + {
- + LOGGER.info(VoteUtil.Sites[ordinal]+" Say: An error ocurred: "+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;
- + }
- +}
- Index: head-src/com/l2jfrozen/FService.java
- ===================================================================
- --- head-src/com/l2jfrozen/FService.java (revision 1257)
- +++ head-src/com/l2jfrozen/FService.java (working copy)
- @@ -49,6 +49,8 @@
- public static final String BOSS_CONFIG_FILE = "./config/head/boss.properties";
- + public static final String VOTE_SYSTEM_FILE = "./config/votesystem.properties";
- // functions
- public static final String ACCESS_CONFIGURATION_FILE = "./config/access_level/access.properties";
- public static final String CRAFTING = "./config/functions/crafting.properties";
- public static final String DEVELOPER = "./config/functions/developer.properties";
- Index: head-src/com/l2jfrozen/gameserver/network/serverpackets/CreatureSay.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/network/serverpackets/CreatureSay.java (revision 1257)
- +++ head-src/com/l2jfrozen/gameserver/network/serverpackets/CreatureSay.java (working copy)
- @@ -1,72 +1,68 @@
- -/*
- - * L2jFrozen Project
- - *
- - * This program is free software; you can redistribute it and/or modify
- - * it under the terms of the GNU General Public License as published by
- - * the Free Software Foundation; either version 2, or (at your option)
- - * any later version.
- - *
- - * This program is distributed in the hope that it will be useful,
- - * but WITHOUT ANY WARRANTY; without even the implied warranty of
- - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- - * GNU General Public License for more details.
- - *
- - * You should have received a copy of the GNU General Public License
- - * along with this program; if not, write to the Free Software
- - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- - * 02111-1307, USA.
- - *
- - * http://www.gnu.org/copyleft/gpl.html
- - */
- package com.l2jfrozen.gameserver.network.serverpackets;
- -import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- +import java.util.ArrayList;
- +import java.util.List;
- -/**
- - * This class ...
- - * @version $Revision: 1.4.2.1.2.3 $ $Date: 2005/03/27 15:29:57 $
- - */
- +import com.l2jfrozen.gameserver.network.SystemMessageId;
- +
- public class CreatureSay extends L2GameServerPacket
- {
- - private final int objectId;
- - private final int textType;
- - private final String charName;
- - private final String text;
- + private final int _objectId;
- + private final int _textType;
- + private String _charName = null;
- + private int _charId = 0;
- + private String _text = null;
- + private int _npcString = -1;
- + private List<String> _parameters;
- - /**
- - * @param objectId
- - * @param messageType
- - * @param charName
- - * @param text
- - */
- - public CreatureSay(final int objectId, final int messageType, final String charName, final String text)
- + public CreatureSay(int objectId, int messageType, String charName, String text)
- {
- - this.objectId = objectId;
- - textType = messageType;
- - this.charName = charName;
- - this.text = text;
- - // setLifeTime(0);
- + _objectId = objectId;
- + _textType = messageType;
- + _charName = charName;
- + _text = text;
- }
- + public CreatureSay(int objectId, int messageType, int charId, SystemMessageId sysString)
- + {
- + _objectId = objectId;
- + _textType = messageType;
- + _charId = charId;
- + _npcString = sysString.getId();
- + }
- +
- + public void addStringParameter(String text)
- + {
- + if (_parameters == null)
- + _parameters = new ArrayList<>();
- +
- + _parameters.add(text);
- + }
- +
- @Override
- protected final void writeImpl()
- {
- writeC(0x4a);
- - writeD(objectId);
- - writeD(textType);
- - writeS(charName);
- - writeS(text);
- -
- - final L2PcInstance pci = getClient().getActiveChar();
- - if (pci != null)
- + writeD(_objectId);
- + writeD(_textType);
- + if (_charName != null)
- + writeS(_charName);
- + else
- + writeD(_charId);
- + writeD(_npcString); // High Five NPCString ID
- + if (_text != null)
- + writeS(_text);
- + else
- {
- - pci.broadcastSnoop(textType, charName, text, this);
- + if (_parameters != null)
- + {
- + for (String s : _parameters)
- + writeS(s);
- + }
- }
- }
- -
- @Override
- - public String getType()
- - {
- + public String getType() {
- return "[S] 4A CreatureSay";
- }
- }
- \ No newline at end of file
- Index: head-src/com/l2jfrozen/Config.java
- ===================================================================
- --- head-src/com/l2jfrozen/Config.java (revision 1257)
- +++ head-src/com/l2jfrozen/Config.java (working copy)
- @@ -49,6 +49,7 @@
- import com.l2jfrozen.gameserver.util.FloodProtectorConfig;
- import com.l2jfrozen.util.StringUtil;
- import java.util.Properties;
- + import java.util.concurrent.TimeUnit;
- import java.util.logging.Level;
- @@ -113,6 +116,439 @@
- }
- }
- + //---------------------------------------------------
- + // 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 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;
- +
- + //VoteSystem
- +
- + private static final void loadVoteRewardSystem()
- + {
- + final String VOTE = FService.VOTE_SYSTEM_FILE;
- + try{
- + final Properties votesystem = new Properties();
- + final InputStream is = new FileInputStream(new File(VOTE));
- + votesystem.load(is);
- + is.close();
- +
- + ENABLE_VOTE_SYSTEM = Boolean.parseBoolean(votesystem.getProperty("EnableVoteSystem", "true"));
- + ENABLE_INDIVIDUAL_VOTE = Boolean.parseBoolean(votesystem.getProperty("EnableIndividualVote","true"));
- + ENABLE_GLOBAL_VOTE = Boolean.parseBoolean(votesystem.getProperty("EnableGlobalVote", "true"));
- + NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = TimeUnit.MINUTES.toMillis(Long.parseLong(votesystem.getProperty("NextTimeToAutoUpdateTotalVote", "60")));// -> minutes
- + NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = TimeUnit.MINUTES.toMillis(Long.parseLong(votesystem.getProperty("NextTimeToAutoUpdateIndividualVotes", "60")));// -> minutes
- + NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = TimeUnit.MINUTES.toMillis(Long.parseLong(votesystem.getProperty("NextTimeToAutoCleanInnecesaryVotes", "30")));// -> minutes
- + NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = TimeUnit.MINUTES.toMillis(Long.parseLong(votesystem.getProperty("NextTimeToCheckAutoGlobalVotesReward", "5")));// -> minutes
- + INTERVAL_TO_NEXT_VOTE = TimeUnit.HOURS.toMillis(Long.parseLong(votesystem.getProperty("IntervalTimeToNextVote", "12"))); // -> hours
- + GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = Integer.parseInt(votesystem.getProperty("GlobalVotesAmountToNextReward","50"));
- + ENABLE_VOTING_COMMAND = Boolean.parseBoolean(votesystem.getProperty("EnableVotingCommand","true"));
- + VOTING_COMMAND = votesystem.getProperty("VotingCommand","");
- + 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","");
- + 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","");
- + }catch(Exception e) {
- + e.printStackTrace();
- + }
- + }
- @@ -4197,7 +4633,10 @@
- loadPCBPointConfig();
- loadOfflineConfig();
- loadPowerPak();
- + loadVoteRewardSystem();
- +
- // Other
- loadExtendersConfig();
- loadDaemonsConf();
- Index: head-src/com/l2jfrozen/gameserver/GameServer.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/GameServer.java (revision 1257)
- +++ head-src/com/l2jfrozen/gameserver/GameServer.java (working copy)
- import com.l2jfrozen.gameserver.thread.daemons.ItemsAutoDestroy;
- import com.l2jfrozen.gameserver.thread.daemons.PcPoint;
- import com.l2jfrozen.gameserver.util.DynamicExtension;
- +import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
- +import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
- import com.l2jfrozen.netcore.NetcoreConfig;
- import com.l2jfrozen.netcore.SelectorConfig;
- import com.l2jfrozen.netcore.SelectorThread;
- @@ -421,6 +428,14 @@
- AdminCommandHandler.getInstance();
- UserCommandHandler.getInstance();
- VoicedCommandHandler.getInstance();
- + Util.printSection("Vote System");
- + if(Config.ENABLE_VOTE_SYSTEM) {
- + voteManager.getInatance();
- + LOGGER.info("======================Vote System Enabled=========================");
- + VoteSiteXml.getInstance();
- + }else {
- + LOGGER.info("======================Vote System Disabled=========================");
- + }
- LOGGER.info("AutoChatHandler : Loaded " + AutoChatHandler.getInstance().size() + " handlers in total.");
- LOGGER.info("AutoSpawnHandler : Loaded " + AutoSpawn.getInstance().size() + " handlers in total.");
- Index: head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoteRewardCommandHandler.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoteRewardCommandHandler.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoteRewardCommandHandler.java (working copy)
- @@ -0,0 +1,72 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
- +
- +import com.l2jfrozen.Config;
- +import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
- +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
- +import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
- +
- +/**
- + * @author l2.topgameserver.net
- + *
- + */
- +public class VoteRewardCommandHandler implements IVoicedCommandHandler
- +{
- +
- +
- + @Override
- + public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
- + {
- + if (command.equalsIgnoreCase(Config.VOTING_COMMAND))
- + {
- + if(activeChar.isInJail()) {
- + activeChar.sendMessage("You cannot use this function while you are jailed");
- + return false;
- + }
- + if(!Config.ENABLE_VOTE_SYSTEM) {
- + activeChar.sendMessage("The rewards system has been disabled by your administrator");
- + return false;
- + }
- + if(!Config.ENABLE_INDIVIDUAL_VOTE) {
- + activeChar.sendMessage("The individual reward system is disabled");
- + return false;
- + }
- + if(!Config.ENABLE_VOTING_COMMAND) {
- + activeChar.sendMessage("Voting command reward is disabled");
- + return false;
- + }
- +
- + for(voteSite vs : voteSite.values()) {
- + new Thread(()->{
- + voteManager.getInatance().getReward(activeChar, vs.ordinal());
- + }).start();
- + }
- + return true;
- + }
- + return false;
- + }
- +
- + @Override
- + public String[] getVoicedCommandList()
- + {
- + return new String[]
- + {
- + Config.VOTING_COMMAND,
- + };
- + }
- +
- +}
- Index: head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (revision 1257)
- +++ head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (working copy)
- @@ -38,6 +38,8 @@
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.ServerTimeCmd;
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.StatsCmd;
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.TvTCmd;
- +import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.VoteCommandHandler;
- +import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.VoteRewardCommandHandler;
- import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.WeddingCmd;
- public class VoicedCommandHandler
- @@ -88,6 +90,9 @@
- if (Config.CHARACTER_REPAIR)
- registerVoicedCommandHandler(new Repair());
- + if(Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTING_COMMAND)
- + registerVoicedCommandHandler(new VoteRewardCommandHandler());
- +
- registerVoicedCommandHandler(new ServerTimeCmd());
- LOGGER.info("VoicedCommandHandler: Loaded " + voicedCommands.size() + " handlers.");
- Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2NpcVoteRewardInstance.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2NpcVoteRewardInstance.java (nonexistent)
- +++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2NpcVoteRewardInstance.java (working copy)
- @@ -0,0 +1,97 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jfrozen.gameserver.model.actor.instance;
- +
- +import com.l2jfrozen.Config;
- +import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
- +import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
- +import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
- +import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
- +import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
- +import com.l2jfrozen.gameserver.votesystem.Model.Reward;
- +import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
- +
- +/**
- + * @author l2.topgameserver.net
- + *
- + */
- +public class L2NpcVoteRewardInstance extends L2FolkInstance
- +{
- + /**
- + * @param objectId
- + * @param template
- + */
- + public L2NpcVoteRewardInstance(int objectId, L2NpcTemplate template)
- + {
- + super(objectId, template);
- + }
- +
- + @Override
- + public void onBypassFeedback(L2PcInstance player, String command)
- + {
- + if(command == null) {
- + return;
- + }
- + int Ordinalsite = Integer.parseInt(command);
- + voteManager.getInatance().getReward(player, Ordinalsite);
- + showChatWindow(player,0);
- + super.onBypassFeedback(player, command);
- + }
- +
- + @Override
- + public void showChatWindow(L2PcInstance player, int val) {
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + StringBuilder sb = new StringBuilder();
- + html.setFile(getHtmlPath(getNpcId(), 0));
- + for(voteSite vs : voteSite.values()) {
- + sb.append("<table bgcolor=000000 width=280><tr>");
- + sb.append("<td width=42><img src=\"icon.etc_treasure_box_i08\" width=32 height=32></td>");
- + sb.append("<td width=220><table width=220>");
- + sb.append("<tr><td><table width=220><tr><td width=145>On "+String.format("%s",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=\"sek.cbui94\" fore=\"sek.cbui92\">",getObjectId(),vs.ordinal())+"</td>");
- + }else {
- + sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(player, vs.ordinal())));
- + }
- + sb.append("</tr></table></td></tr>");
- + sb.append("<tr><td><table width=220><tr>");
- + int i=0;
- + for(Reward r : 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>");
- + }
- + html.replace("%everyXtime%",Config.INTERVAL_TO_NEXT_VOTE/(3600*1000));
- + html.replace("%enablevote%", sb.toString());
- + html.replace("%accountName%",player.getName());
- + player.sendPacket(html);
- + }
- +
- + @Override
- + public String getHtmlPath(int npcId, int val)
- + {
- + String filename = "";
- + if (val == 0)
- + filename = "" + npcId;
- + else
- + filename = npcId + "-" + val;
- +
- + return "data/html/mods/votesystem/" + filename + ".html";
- + }
- +}
- Index: head-src/com/l2jfrozen/gameserver/Shutdown.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/Shutdown.java (revision 1257)
- +++ head-src/com/l2jfrozen/gameserver/Shutdown.java (working copy)
- @@ -50,8 +50,10 @@
- import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
- import com.l2jfrozen.gameserver.thread.LoginServerThread;
- import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
- +import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
- import com.l2jfrozen.util.database.L2DatabaseFactory;
- +
- /**
- * This class provides the functions for shutting down and restarting the server It closes all open client connections and saves all data.
- * @version $Revision: 1.2.4.6 $ $Date: 2009/05/12 19:45:09 $
- @@ -474,6 +476,10 @@
- TradeController.getInstance().dataCountStore();
- LOGGER.info("TradeController: All count Item Saved");
- + //Save global and individual votes
- + voteManager.getInatance().Shutdown();
- + LOGGER.info("Vote data has been saved");
- +
- // Save Olympiad status
- try
- {
- ==================================== 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;
- -- ----------------------------
- -- Records of npc
- -- ----------------------------
- INSERT INTO `npc` VALUES (25529,35468,Kaaya,1,Vote System,1,NPC.a_common_peopleB_MHuman,8.00,22.00,70,male,L2NpcVoteReward,40,3862,1493,11.85,2.78,40,43,30,21,20,10,0,0,1314,470,780,382,278,0,333,0,0,0,55,132,0,1,0,LAST_HIT);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement