Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git config/server.properties config/server.properties
- index 8cb45ab..784144c 100644
- --- config/server.properties
- +++ config/server.properties
- @@ -25,6 +25,15 @@
- AcceptAlternateID = True
- # ================================================================
- +# Vote reward system
- +# ================================================================
- +
- +VoteNetworkName = adler1313
- +VoteTopzoneApiKey = 2e83b3bf89f0d34f9eb0b7151608349d
- +VoteTopzoneServerId = 10994
- +VoteHopzoneApiKey = LHu2UpXFNYWXYklS
- +
- +# ================================================================
- # Database informations
- # ================================================================
- diff --git java/net/sf/l2j/Config.java java/net/sf/l2j/Config.java
- index 23216b2..56e2266 100644
- --- java/net/sf/l2j/Config.java
- +++ java/net/sf/l2j/Config.java
- @@ -52,6 +52,13 @@
- public static final String SERVER_FILE = "./config/server.properties";
- public static final String SIEGE_FILE = "./config/siege.properties";
- + /** Vote configs */
- +
- + public static String VOTE_NETWORK_NAME;
- + public static String VOTE_TOPZONE_APIKEY;
- + public static int VOTE_TOPZONE_SERVERID;
- + public static String VOTE_HOPZONE_APIKEY;
- +
- // --------------------------------------------------
- // Clans settings
- // --------------------------------------------------
- @@ -1261,6 +1268,11 @@
- PLAYER_DROPPED_ITEM_MULTIPLIER = server.getProperty("PlayerDroppedItemMultiplier", 1);
- SAVE_DROPPED_ITEM = server.getProperty("SaveDroppedItem", false);
- + VOTE_NETWORK_NAME = server.getProperty("VoteNetworkName", "");
- + VOTE_TOPZONE_APIKEY = server.getProperty("VoteTopzoneApiKey", "");
- + VOTE_TOPZONE_SERVERID = server.getProperty("VoteTopzoneServerId", 0);
- + VOTE_HOPZONE_APIKEY = server.getProperty("VoteHopzoneApiKey", "");
- +
- RATE_XP = server.getProperty("RateXp", 1.);
- RATE_SP = server.getProperty("RateSp", 1.);
- RATE_PARTY_XP = server.getProperty("RatePartyXp", 1.);
- diff --git java/net/sf/l2j/commons/lang/StringUtil.java java/net/sf/l2j/commons/lang/StringUtil.java
- index 61c9f76..b61d8b5 100644
- --- java/net/sf/l2j/commons/lang/StringUtil.java
- +++ java/net/sf/l2j/commons/lang/StringUtil.java
- @@ -163,6 +163,22 @@
- LOG.info(sb.toString());
- }
- + public static String substringBetween(String str, String open, String close) {
- + final int INDEX_NOT_FOUND = -1;
- + if (str == null || open == null || close == null) {
- + return null;
- + }
- + int start = str.indexOf(open);
- + if (start != INDEX_NOT_FOUND) {
- + int end = str.indexOf(close, start + open.length());
- + if (end != INDEX_NOT_FOUND) {
- + return str.substring(start + open.length(), end);
- + }
- + }
- + return null;
- + }
- +
- +
- /**
- * Format a time given in seconds into "h m s" String format.
- * @param time : a time given in seconds.
- diff --git java/net/sf/l2j/gameserver/GameServer.java java/net/sf/l2j/gameserver/GameServer.java
- index c9f02ea..0b9715f 100644
- --- java/net/sf/l2j/gameserver/GameServer.java
- +++ java/net/sf/l2j/gameserver/GameServer.java
- @@ -72,6 +72,7 @@
- import net.sf.l2j.gameserver.handler.ItemHandler;
- import net.sf.l2j.gameserver.handler.SkillHandler;
- import net.sf.l2j.gameserver.handler.UserCommandHandler;
- +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
- import net.sf.l2j.gameserver.idfactory.IdFactory;
- import net.sf.l2j.gameserver.instancemanager.AuctionManager;
- import net.sf.l2j.gameserver.instancemanager.AutoSpawnManager;
- @@ -292,6 +293,7 @@
- _log.config("ItemHandler: Loaded " + ItemHandler.getInstance().size() + " handlers.");
- _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
- _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
- + _log.config("VoicedCommandHandler: Loaded " + VoicedCommandHandler.getInstance().size() + " handlers.");
- StringUtil.printSection("System");
- Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
- diff --git java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java
- new file mode 100644
- index 0000000..c1f737d
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java
- @@ -0,0 +1,27 @@
- +/*
- + * 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 net.sf.l2j.gameserver.handler;
- +
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * @author Elfocrash
- + *
- + */
- +public interface IVoicedCommandHandler
- +{
- + public void useVoicedCommand(L2PcInstance activeChar);
- + public String[] getVoicedCommands();
- +}
- \ No newline at end of file
- diff --git java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
- new file mode 100644
- index 0000000..a14e449
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
- @@ -0,0 +1,60 @@
- +/*
- + * 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 net.sf.l2j.gameserver.handler;
- +
- +import java.util.Arrays;
- +import java.util.HashMap;
- +import java.util.Map;
- +
- +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.VoteCommand;
- +
- +/**
- + * @author Elfocrash
- + *
- + */
- +public class VoicedCommandHandler
- +{
- + private static final Map<Integer, IVoicedCommandHandler> VOICED_COMMANDS = new HashMap<>();
- +
- + VoicedCommandHandler()
- + {
- + registerVoicedCommand(new VoteCommand());
- + }
- +
- + private static void registerVoicedCommand(IVoicedCommandHandler voicedCommand)
- + {
- + Arrays.stream(voicedCommand.getVoicedCommands()).forEach(v -> VOICED_COMMANDS.put(v.intern().hashCode(), voicedCommand));
- + }
- +
- + public IVoicedCommandHandler getVoicedCommand(String voicedCommand)
- + {
- + return VOICED_COMMANDS.get(voicedCommand.hashCode());
- + }
- +
- + public int size()
- + {
- + return VOICED_COMMANDS.size();
- + }
- +
- + public static final VoicedCommandHandler getInstance()
- + {
- + return SingletonHolder.INSTANCE;
- + }
- +
- + private static final class SingletonHolder
- + {
- + static final VoicedCommandHandler INSTANCE = new VoicedCommandHandler();
- + }
- +}
- diff --git java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
- index 4c1c9e6..679a471 100644
- --- java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
- +++ java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
- @@ -15,6 +15,8 @@
- package net.sf.l2j.gameserver.handler.chathandlers;
- import net.sf.l2j.gameserver.handler.IChatHandler;
- +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
- +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
- import net.sf.l2j.gameserver.model.BlockList;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
- @@ -34,12 +36,17 @@
- if (!FloodProtectors.performAction(activeChar.getClient(), Action.GLOBAL_CHAT))
- return;
- + if (text.startsWith("."))
- + {
- + final IVoicedCommandHandler voicedCommand = VoicedCommandHandler.getInstance().getVoicedCommand(text.substring(1).toLowerCase());
- + if (voicedCommand != null)
- + {
- + voicedCommand.useVoicedCommand(activeChar);
- + return;
- + }
- + }
- final CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
- - for (L2PcInstance player : activeChar.getKnownTypeInRadius(L2PcInstance.class, 1250))
- - {
- - if (!BlockList.isBlocked(player, activeChar))
- - player.sendPacket(cs);
- - }
- + activeChar.getKnownTypeInRadius(L2PcInstance.class, 1250).stream().filter(p -> !BlockList.isBlocked(p, activeChar)).forEach(p -> p.sendPacket(cs));
- activeChar.sendPacket(cs);
- }
- diff --git java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteCommand.java java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteCommand.java
- new file mode 100644
- index 0000000..a8042bc
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteCommand.java
- @@ -0,0 +1,68 @@
- +/*
- + * 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 net.sf.l2j.gameserver.handler.voicedcommandhandlers;
- +
- +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- +
- +/**
- + * @author Elfocrash
- + *
- + */
- +public class VoteCommand implements IVoicedCommandHandler
- +{
- + private static final String[] VOICED_COMMANDS = {"vote"};
- +
- + @Override
- + public void useVoicedCommand(L2PcInstance player)
- + {
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + html.setHtml(getVoteHtml(player));
- + player.sendPacket(html);
- +
- + player.sendPacket(ActionFailed.STATIC_PACKET);
- + }
- +
- + private static String getVoteHtml(L2PcInstance player)
- + {
- + StringBuilder sb = new StringBuilder();
- + sb.append("<html><body><center><br>");
- + if(player.eligibleToVoteHop())
- + sb.append("<a action=\"bypass -h vote hopzone\">I have voted on hopzone</a><br1>");
- + else
- + sb.append(String.format("You can vote again in: %s <br1>",player.getVoteCountdownHop()));
- +
- + if(player.eligibleToVoteTop())
- + sb.append("<a action=\"bypass -h vote topzone\">I have voted on topzone</a><br1>");
- + else
- + sb.append(String.format("You can vote again in: %s <br1>",player.getVoteCountdownTop()));
- +
- + if(player.eligibleToVoteNet())
- + sb.append("<a action=\"bypass -h vote network\">I have voted on network</a><br1>");
- + else
- + sb.append(String.format("You can vote again in: %s <br1>",player.getVoteCountdownNet()));
- +
- + sb.append("</body></html>");
- + return sb.toString();
- + }
- +
- + @Override
- + public String[] getVoicedCommands()
- + {
- + return VOICED_COMMANDS;
- + }
- +}
- diff --git java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
- index de6d35e..d1adf59 100644
- --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
- +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
- @@ -315,9 +315,9 @@
- private static final String RESTORE_SKILL_SAVE = "SELECT skill_id,skill_level,effect_count,effect_cur_time, reuse_delay, systime, restore_type FROM character_skills_save WHERE char_obj_id=? AND class_index=? ORDER BY buff_index ASC";
- private static final String DELETE_SKILL_SAVE = "DELETE FROM character_skills_save WHERE char_obj_id=? AND class_index=?";
- - private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- + private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date,last_hop_vote,last_top_vote,last_net_vote) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=? WHERE obj_id=?";
- - private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level FROM characters WHERE obj_id=?";
- + private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,last_hop_vote,last_top_vote,last_net_vote FROM characters WHERE obj_id=?";
- private static final String RESTORE_CHAR_SUBCLASSES = "SELECT class_id,exp,sp,level,class_index FROM character_subclasses WHERE char_obj_id=? ORDER BY class_index ASC";
- private static final String ADD_CHAR_SUBCLASS = "INSERT INTO character_subclasses (char_obj_id,class_id,exp,sp,level,class_index) VALUES (?,?,?,?,?,?)";
- @@ -371,6 +371,9 @@
- private long _onlineBeginTime;
- private long _lastAccess;
- private long _uptime;
- + private long _lastHopVote;
- + private long _lastTopVote;
- + private long _lastNetVote;
- protected int _baseClass;
- protected int _activeClass;
- @@ -723,6 +726,9 @@
- statement.setInt(32, player.isNoble() ? 1 : 0);
- statement.setLong(33, 0);
- statement.setLong(34, System.currentTimeMillis());
- + statement.setLong(35, System.currentTimeMillis()-43200000);
- + statement.setLong(36, System.currentTimeMillis()-43200000);
- + statement.setLong(37, System.currentTimeMillis()-43200000);
- statement.executeUpdate();
- statement.close();
- }
- @@ -5384,6 +5390,9 @@
- player.setAllianceWithVarkaKetra(rset.getInt("varka_ketra_ally"));
- player.setDeathPenaltyBuffLevel(rset.getInt("death_penalty_level"));
- + player.setLastHopVote(rset.getLong("last_hop_vote"));
- + player.setLastTopVote(rset.getLong("last_top_vote"));
- + player.setLastNetVote(rset.getLong("last_net_vote"));
- // Set the x,y,z position of the L2PcInstance and make it invisible
- player.getPosition().set(rset.getInt("x"), rset.getInt("y"), rset.getInt("z"));
- @@ -8425,6 +8434,36 @@
- return _lastAccess;
- }
- + public long getLastHopVote()
- + {
- + return _lastHopVote;
- + }
- +
- + public long getLastTopVote()
- + {
- + return _lastTopVote;
- + }
- +
- + public long getLastNetVote()
- + {
- + return _lastNetVote;
- + }
- +
- + public void setLastHopVote(long val)
- + {
- + _lastHopVote = val;
- + }
- +
- + public void setLastTopVote(long val)
- + {
- + _lastTopVote = val;
- + }
- +
- + public void setLastNetVote(long val)
- + {
- + _lastNetVote = val;
- + }
- +
- private void checkRecom(int recsHave, int recsLeft)
- {
- Calendar check = Calendar.getInstance();
- @@ -8621,6 +8660,51 @@
- }
- }
- + public boolean eligibleToVoteHop()
- + {
- + return (getLastHopVote() + 43200000) < System.currentTimeMillis();
- + }
- +
- + public boolean eligibleToVoteTop()
- + {
- + return (getLastTopVote() + 43200000) < System.currentTimeMillis();
- + }
- +
- + public boolean eligibleToVoteNet()
- + {
- + return (getLastNetVote() + 43200000) < System.currentTimeMillis();
- + }
- +
- + public String getVoteCountdownHop()
- + {
- + long youCanVote = getLastHopVote() - (System.currentTimeMillis() - 43200000);
- + return convertLongToCountdown(youCanVote);
- + }
- +
- + public String getVoteCountdownTop()
- + {
- + long youCanVote = getLastTopVote() - (System.currentTimeMillis() - 43200000);
- + return convertLongToCountdown(youCanVote);
- + }
- +
- + public String getVoteCountdownNet()
- + {
- + long youCanVote = getLastNetVote() - (System.currentTimeMillis() - 43200000);
- + return convertLongToCountdown(youCanVote);
- + }
- +
- + public static String convertLongToCountdown(long youCanVote)
- + {
- + String formattedCountdown = String.format("%d hours, %d mins, %d secs",
- + TimeUnit.MILLISECONDS.toHours(youCanVote),
- + TimeUnit.MILLISECONDS.toMinutes(youCanVote) -
- + TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(youCanVote)),
- + TimeUnit.MILLISECONDS.toSeconds(youCanVote) -
- + TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(youCanVote))
- + );
- + return formattedCountdown;
- + }
- +
- /**
- * @param expertiseIndex The expertiseIndex to set.
- */
- diff --git java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
- index 113a32c..cb71311 100644
- --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
- +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
- @@ -35,6 +35,9 @@
- import net.sf.l2j.gameserver.util.FloodProtectors;
- import net.sf.l2j.gameserver.util.FloodProtectors.Action;
- import net.sf.l2j.gameserver.util.GMAudit;
- +import net.sf.l2j.gameserver.voteengine.VoteHopzone;
- +import net.sf.l2j.gameserver.voteengine.VoteNetwork;
- +import net.sf.l2j.gameserver.voteengine.VoteTopzone;
- public final class RequestBypassToServer extends L2GameClientPacket
- {
- @@ -95,6 +98,67 @@
- {
- playerHelp(activeChar, _command.substring(12));
- }
- + else if (_command.startsWith("vote "))
- + {
- + String voteSiteName = _command.substring(5);
- + switch(voteSiteName)
- + {
- + case "hopzone":
- + new Thread(() -> {
- + if(activeChar.eligibleToVoteHop())
- + {
- + VoteHopzone voteHop = new VoteHopzone();
- + if(voteHop.hasVoted(activeChar))
- + {
- + voteHop.updateDB(activeChar, "last_hop_vote");
- + voteHop.setVoted(activeChar);
- + voteHop.reward(activeChar);
- + }
- + else
- + activeChar.sendMessage("You haven't voted yet.");
- + }
- + else
- + _log.warning(activeChar.getName() + " tried to send a bypass with adrenalin/phx");
- + }).start();
- + break;
- + case "topzone":
- + new Thread(() -> {
- + if(activeChar.eligibleToVoteTop())
- + {
- + VoteTopzone voteTop = new VoteTopzone();
- + if(voteTop.hasVoted(activeChar))
- + {
- + voteTop.updateDB(activeChar, "last_top_vote");
- + voteTop.setVoted(activeChar);
- + voteTop.reward(activeChar);
- + }
- + else
- + activeChar.sendMessage("You haven't voted yet.");
- + }
- + else
- + _log.warning(activeChar.getName() + " tried to send a bypass with adrenalin/phx");
- + }).start();
- + break;
- + case "network":
- + new Thread(() -> {
- + if(activeChar.eligibleToVoteNet())
- + {
- + VoteNetwork voteNet = new VoteNetwork();
- + if(voteNet.hasVoted(activeChar))
- + {
- + voteNet.updateDB(activeChar, "last_net_vote");
- + voteNet.setVoted(activeChar);
- + voteNet.reward(activeChar);
- + }
- + else
- + activeChar.sendMessage("You haven't voted yet.");
- + }
- + else
- + _log.warning(activeChar.getName() + " tried to send a bypass with adrenalin/phx");
- + }).start();
- + break;
- + }
- + }
- else if (_command.startsWith("npc_"))
- {
- if (!activeChar.validateBypass(_command))
- diff --git java/net/sf/l2j/gameserver/voteengine/VoteBase.java java/net/sf/l2j/gameserver/voteengine/VoteBase.java
- new file mode 100644
- index 0000000..8217360
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/voteengine/VoteBase.java
- @@ -0,0 +1,124 @@
- +/*
- + * 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 net.sf.l2j.gameserver.voteengine;
- +
- +import java.io.BufferedReader;
- +import java.io.InputStreamReader;
- +import java.net.HttpURLConnection;
- +import java.net.URL;
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +
- +import net.sf.l2j.commons.lang.StringUtil;
- +
- +import net.sf.l2j.L2DatabaseFactory;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * @author Elfocrash
- + *
- + */
- +public abstract class VoteBase
- +{
- +
- + public String getPlayerIp(L2PcInstance player)
- + {
- + System.out.println(player.getClient().getConnection().getInetAddress().getHostAddress());
- + return player.getClient().getConnection().getInetAddress().getHostAddress();
- + }
- +
- + public abstract void reward(L2PcInstance player);
- +
- + public abstract void setVoted(L2PcInstance player);
- +
- + public void updateDB(L2PcInstance player, String columnName)
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + PreparedStatement statement = con.prepareStatement(String.format("Update characters set %s=? where obj_Id=?",columnName));
- + statement.setLong(1, System.currentTimeMillis());
- + statement.setInt(2, player.getObjectId());
- + statement.execute();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + System.out.println("Error in VoteBase::updateDB");
- + }
- + }
- +
- + public boolean hasVoted(L2PcInstance player)
- + {
- + try
- + {
- + String endpoint = getApiEndpoint(player);
- + if(endpoint.startsWith("err"))
- + return false;
- + String voted = endpoint.startsWith("http://api.hopzone.net") ? StringUtil.substringBetween(getApiResponse(endpoint),"\"voted\":",",\"hopzoneServerTime\"") : getApiResponse(endpoint);
- + return tryParseBool(voted);
- + }
- + catch (Exception e)
- + {
- + player.sendMessage("Something went wrong. Please try again later.");
- + e.printStackTrace();
- + }
- + return false;
- + }
- +
- + public boolean tryParseBool(String bool)
- + {
- + if(bool.startsWith("1"))
- + return true;
- +
- + return Boolean.parseBoolean(bool.trim());
- + }
- +
- + public abstract String getApiEndpoint(L2PcInstance player);
- +
- + public String getApiResponse(String endpoint)
- + {
- + StringBuilder stringBuilder = new StringBuilder();
- +
- + try
- + {
- + URL url = new URL(endpoint);
- + HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- + connection.addRequestProperty("User-Agent", "Mozilla/4.76");
- + connection.setRequestMethod("GET");
- +
- + connection.setReadTimeout(5*1000);
- + connection.connect();
- +
- + try(BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())))
- + {
- + String line = null;
- + while ((line = reader.readLine()) != null)
- + {
- + stringBuilder.append(line + "\n");
- + }
- + }
- + connection.disconnect();
- + System.out.println(stringBuilder.toString());//
- + return stringBuilder.toString();
- + }
- + catch (Exception e)
- + {
- + System.out.println("Something went wrong in VoteBase::getApiResponse");
- + e.printStackTrace();
- + return "err";
- + }
- + }
- +}
- diff --git java/net/sf/l2j/gameserver/voteengine/VoteHopzone.java java/net/sf/l2j/gameserver/voteengine/VoteHopzone.java
- new file mode 100644
- index 0000000..d6ac852
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/voteengine/VoteHopzone.java
- @@ -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 net.sf.l2j.gameserver.voteengine;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * @author Elfocrash
- + *
- + */
- +public class VoteHopzone extends VoteBase
- +{
- + @Override
- + public void reward(L2PcInstance player)
- + {
- + player.sendMessage("The admin should add the reward method here.");
- + }
- +
- + @Override
- + public String getApiEndpoint(L2PcInstance player)
- + {
- + return String.format("http://api.hopzone.net/lineage2/vote?token=%s&ip_address=%s",Config.VOTE_HOPZONE_APIKEY, getPlayerIp(player));
- + }
- +
- + @Override
- + public void setVoted(L2PcInstance player)
- + {
- + player.setLastHopVote(System.currentTimeMillis());
- + }
- +
- +}
- diff --git java/net/sf/l2j/gameserver/voteengine/VoteNetwork.java java/net/sf/l2j/gameserver/voteengine/VoteNetwork.java
- new file mode 100644
- index 0000000..317809f
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/voteengine/VoteNetwork.java
- @@ -0,0 +1,45 @@
- +/*
- + * 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 net.sf.l2j.gameserver.voteengine;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * @author Elfocrash
- + *
- + */
- +public class VoteNetwork extends VoteBase
- +{
- +
- + @Override
- + public void reward(L2PcInstance player)
- + {
- + player.sendMessage("The admin should add the reward method here.");
- + }
- +
- + @Override
- + public String getApiEndpoint(L2PcInstance player)
- + {
- + return String.format("http://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_NAME, getPlayerIp(player));
- + }
- +
- + @Override
- + public void setVoted(L2PcInstance player)
- + {
- + player.setLastNetVote(System.currentTimeMillis());
- + }
- +
- +}
- diff --git java/net/sf/l2j/gameserver/voteengine/VoteTopzone.java java/net/sf/l2j/gameserver/voteengine/VoteTopzone.java
- new file mode 100644
- index 0000000..c56cd09
- --- /dev/null
- +++ java/net/sf/l2j/gameserver/voteengine/VoteTopzone.java
- @@ -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 net.sf.l2j.gameserver.voteengine;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * @author Elfocrash
- + *
- + */
- +public class VoteTopzone extends VoteBase
- +{
- + @Override
- + public void reward(L2PcInstance player)
- + {
- + player.sendMessage("The admin should add the reward method here.");
- + }
- +
- + @Override
- + public String getApiEndpoint(L2PcInstance player)
- + {
- + return String.format("http://l2topzone.com/api.php?API_KEY=%s&SERVER_ID=%d&IP=%s",Config.VOTE_TOPZONE_APIKEY,Config.VOTE_TOPZONE_SERVERID, getPlayerIp(player));
- + }
- +
- + @Override
- + public void setVoted(L2PcInstance player)
- + {
- + player.setLastTopVote(System.currentTimeMillis());
- + }
- +
- +}
- ### Eclipse Workspace Patch 1.0
- #P aCis_datapack
- diff --git sql/characters.sql sql/characters.sql
- index 1a04a4a..11fd549 100644
- --- sql/characters.sql
- +++ sql/characters.sql
- @@ -54,6 +54,9 @@
- `clan_join_expiry_time` BIGINT UNSIGNED NOT NULL DEFAULT 0,
- `clan_create_expiry_time` BIGINT UNSIGNED NOT NULL DEFAULT 0,
- `death_penalty_level` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
- + `last_hop_vote` BIGINT UNSIGNED NOT NULL DEFAULT 0,
- + `last_top_vote` BIGINT UNSIGNED NOT NULL DEFAULT 0,
- + `last_net_vote` BIGINT UNSIGNED NOT NULL DEFAULT 0,
- PRIMARY KEY (obj_Id),
- KEY `clanid` (`clanid`)
- );
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment