i am having trouble about .vote command. if one player type .vote, the entire players in the game have to wait 12 hours.
how can i remove all Hwid record from this code without any error :
i just want to use theese two checking code
ACCOUNT_NAME,
IP_ADRESS,
HWID (this code have to gone)
package handler.voicecommands;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import l2f.commons.util.Rnd;import l2f.gameserver.Config;import l2f.gameserver.ThreadPoolManager;import l2f.gameserver.database.DatabaseFactory;import l2f.gameserver.handler.voicecommands.IVoicedCommandHandler;import l2f.gameserver.handler.voicecommands.VoicedCommandHandler;import l2f.gameserver.model.GameObjectsStorage;import l2f.gameserver.model.Player;import l2f.gameserver.network.serverpackets.Say2;import l2f.gameserver.network.serverpackets.components.ChatType;import l2f.gameserver.scripts.Functions;import l2f.gameserver.scripts.ScriptFile;import l2f.gameserver.utils.BatchStatement;import l2f.gameserver.vote.VoteRead;publicclassRewardVote implements IVoicedCommandHandler,ScriptFile{privatestaticenumValueType{
ACCOUNT_NAME,
IP_ADRESS,
HWID
}privatestatic final String[] COMMANDS_LIST =newString[]{"vote","getreward","getvote","votereward","voteme","fuckvote","rewardget","reward","votereward"};// Rewardsprivatestatic final int[][] BLESSED_ENCHANTS_CATEGORY ={{6673,1}};privatestatic final int[] PERMANENT_CATEGORY ={37004,// Vote Rune1};privatestatic final int[][] MISC_CATEGORY ={{37007,1},{37007,2},{37007,3}};privatestatic final double[][] RANDOM_CATEGORY ={{6577,// 1 Blessed Enchant Weapon S1,0.05},{6578,// 1 Blessed Enchant Armor S1,0.05},{13071,// 1 Red Soul Crystal - Stage 161,0.05},{13072,// 1 Blue Soul Crystal - Stage 161,0.05},{13073,// 1 Green Soul Crystal - Stage 161,0.155},{10480,// 1 Red Soul Crystal - Stage 151,0.155},{10481,// 1 Blue Soul Crystal - Stage 151,0.155},{10482,// 1 Green Soul Crystal - Stage 151,0.566},{14169,// 1 Top Life Stone Level 841,1.25},{14168,// 1 High Life Stone Level 841,2.0},{13073,// 1 Giant's Codex - Mastery1,3.333},{959,// 1 Enchant Weapon S1,3.0},{6622,// 1 Giant's Codex3,8.0},{960,// 1 Enchant Armor S1,8.0},{9552,// 1 Fire Crystal1,8.0},{9553,// 1 Water Crystal1,8.0},{9556,// 1 Dark Crystal1,8.0},{9557,// 1 Holy Crystal1,8.0},{9554,// 1 Earth Crystal1,8.0},{9555,// 1 Wind Crystal1,8.0},{9546,// 1 Fire Stone2,20.0},{9547,// 1 Water Stone2,20.0},{9548,// 1 Earth Stone2,20.0},{9549,// 1 Wind Stone2,20.0},{9550,// 1 Dark Stone2,20.0},{9551,// 1 Holy Stone2,100.0},};privatestatic final long VOTE_COMMAND_REUSE =1*3*1000L;// 5 Minutesprivatestatic final long VOTE_PENALTY =12*60*60*1000L;// 12 Hourspublicstatic final Map<Integer,Long> _votePlayerReuses =newConcurrentHashMap<Integer,Long>();publicstatic final Map<String,Long> _accountPenalties =newConcurrentHashMap<String,Long>();publicstatic final Map<String,Long> _ipPenalties =newConcurrentHashMap<String,Long>();publicstatic final Map<String,Long> _hwidPenalties =newConcurrentHashMap<String,Long>();publicRewardVote(){// If there is a set vote reward message, schedule itif(!Config.VOTE_REWARD_MSG.isEmpty())ThreadPoolManager.getInstance().scheduleAtFixedRate(newVoteAnnounceTask(),1*60*1000,Config.ANNOUNCE_VOTE_DELAY *1000);// Restore from the db all the penalties of the votes, it doesn't matter if its 0. So we can do it only once at startConnection con = null;PreparedStatement statement = null;ResultSet rset = null;try{
con =DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM vote_system");
rset = statement.executeQuery();while(rset.next()){
final String value = rset.getString("value");
final long time = rset.getLong("penalty_time");switch(rset.getInt("value_type")){// Account Namecase0:{
_accountPenalties.put(value, time);break;}// Ip Addresscase1:{
_ipPenalties.put(value, time);break;}// Hwidcase2:{
_hwidPenalties.put(value, time);break;}}}}catch(Exception e){}}@Overridepublic boolean useVoicedCommand(String command,Player activeChar,String params){if(command.equalsIgnoreCase("vote")){try{// No connection, no voteif(activeChar.getNetConnection()== null)returnfalse;if(!Config.ENABLE_VOTE){
activeChar.sendMessage("Voting is currently disabled!");returnfalse;}// Min lvl 40if(activeChar.getLevel()<1){
activeChar.sendMessage("You need to be at least level 1 to use this command.");returnfalse;}
final long currentTime =System.currentTimeMillis();// Synerge - Check if voting is not blocked. If a web connection ocurrs, then the vote will be block for everyone for 15 minutesif(VoteRead._siteBlockTime >= currentTime){
activeChar.sendMessage("There are problems with the connection to the vote site, so it has been disabled for some minutes. Try again later");returnfalse;}// Check player vote reuseif(activeChar.getAccessLevel()<1&& _votePlayerReuses.containsKey(activeChar.getObjectId())){if(_votePlayerReuses.get(activeChar.getObjectId())> currentTime){
activeChar.sendMessage("You can use this command only once every 5 minutes.");returnfalse;}}
_votePlayerReuses.put(activeChar.getObjectId(), currentTime + VOTE_COMMAND_REUSE);// Getting IP of client, here we will have to check for HWID when we have LAMEGUARD
final StringIPClient= activeChar.getIP();
final String HWID =(activeChar.getHWID()!= null ? activeChar.getHWID():"");// Check the penalties of the player to see if he can vote againif(!checkPlayerPenalties(activeChar,IPClient, HWID,true))returnfalse;// Return 0 if he didnt voted. Date when he voted on website/*final long dateHeVotedOnWebsite = VoteRead.checkVotedIP(IPClient);
if(dateHeVotedOnWebsite < 1)
{
activeChar.sendMessage("To claim reward, you need to vote on all banners!");
return false;
}*/if(!hasVoted(activeChar)){
activeChar.sendMessage("To claim reward, you need to vote!");returnfalse;}// Add the vote penalty to the player
addNewPlayerPenalty(activeChar,IPClient, HWID);// Give the rewards
giveRewards(activeChar);
activeChar.sendMessage("Successfully rewarded.");returntrue;}catch(Exception e){
e.printStackTrace();}}returnfalse;}// Thread to send to all players that didn't voted yet to vote for the serverprotectedstaticclassVoteAnnounceTask implements Runnable{@Overridepublicvoid run(){if(Config.VOTE_REWARD_MSG.isEmpty())return;
final Say2 announce =newSay2(0,ChatType.ANNOUNCEMENT,"",Config.VOTE_REWARD_MSG);
final Iterable<Player> world =GameObjectsStorage.getAllPlayersForIterate();for(Player player : world){if(player == null || player.getNetConnection()== null)continue;// No offline or store modeif(player.isInStoreMode())continue;// If the player has an active penalty means that he already votedif(!checkPlayerPenalties(player, player.getIP(), player.getHWID(),false))continue;
player.sendPacket(announce);}}}/**
* Gives to the player all the vote rewards
*
* @param player
*/protectedstaticvoid giveRewards(Player player){// First give the permanent itemFunctions.addItem(player, PERMANENT_CATEGORY[0], PERMANENT_CATEGORY[1],"VoteReward Permanent");// First give the vote main random reward
final int[] reward = getReward();Functions.addItem(player, reward[0], reward[1],"VoteReward Main");// Then give some random rewardsfor(double[] item : RANDOM_CATEGORY){if(Rnd.chance(item[2])){Functions.addItem(player,(int) item[0],(long) item[1],"Vote Random Reward");return;}}}/**
* Puts new penalties for the account name, ip and hwid of the player after he succesfully voted
*
* @param activeChar
* @param IPClient
* @param HWID
*/protectedstaticvoid addNewPlayerPenalty(Player activeChar,StringIPClient,String HWID){
final long newPenalty =System.currentTimeMillis()+ VOTE_PENALTY;
_accountPenalties.put(activeChar.getAccountName(), newPenalty);
_ipPenalties.put(IPClient, newPenalty);
_hwidPenalties.put(HWID, newPenalty);// Also store the penalties in the dbConnection con = null;PreparedStatement statement = null;try{
con =DatabaseFactory.getInstance().getConnection();
statement =BatchStatement.createPreparedStatement(con,"REPLACE INTO vote_system(value_type, value, penalty_time) VALUES (?, ?, ?)");
final String[] values =newString[]{ activeChar.getAccountName(),IPClient, HWID };for(ValueType type :ValueType.values()){
statement.setInt(1, type.ordinal());
statement.setString(2, values[type.ordinal()]);
statement.setLong(3, newPenalty);
statement.addBatch();}
statement.executeBatch();}catch(Exception e){}}/**
* @param activeChar
* @param IPClient
* @param HwID
* @param sendMessage
* @return Returns true if the player doesn't have an active penalty after voting
*/protectedstatic boolean checkPlayerPenalties(Player activeChar,StringIPClient,StringHwID, boolean sendMessage){
final long accountPenalty = checkPenalty(ValueType.ACCOUNT_NAME, activeChar.getAccountName());
final long ipPenalty = checkPenalty(ValueType.IP_ADRESS,IPClient);
final long hwidPenalty = checkPenalty(ValueType.HWID,HwID);
final int penalty =(int)((Math.max(accountPenalty,Math.max(ipPenalty, hwidPenalty))-System.currentTimeMillis())/(60*1000L));if(penalty >0){if(sendMessage){if(penalty >60){
activeChar.sendMessage("You can vote only once every 12 hours. You still have to wait "+(penalty /60)+" hours "+(penalty %60)+" minutes.");}else{
activeChar.sendMessage("You can vote only once every 12 hours. You still have to wait "+ penalty +" minutes.");}}returnfalse;}returntrue;}/**
* @param type
* @param value
* @return Returns the penalty of a particular type and value if it exists
*/privatestaticlong checkPenalty(ValueType type,String value){switch(type){case ACCOUNT_NAME:{if(_accountPenalties.containsKey(value))return _accountPenalties.get(value);break;}case IP_ADRESS:{if(_ipPenalties.containsKey(value))return _ipPenalties.get(value);break;}case HWID:{if(_hwidPenalties.containsKey(value))return _hwidPenalties.get(value);break;}}return0;}publicstaticint[] getReward(){return MISC_CATEGORY[Rnd.get(MISC_CATEGORY.length)];}@Overridepublicvoid onLoad(){VoicedCommandHandler.getInstance().registerVoicedCommandHandler(this);}@Overridepublicvoid onReload(){//}@Overridepublicvoid onShutdown(){//}@OverridepublicString[] getVoicedCommandList(){return COMMANDS_LIST;}// New Topzone Vote Reward System (API)publicString getApiEndpoint(Player player){returnString.format("https://api.l2topzone.com/v1/vote?token=%s&ip=%s",Config.VOTE_TOPZONE_APIKEY, player.getIP());}public boolean hasVoted(Player player){try{String endpoint = getApiEndpoint(player);if(endpoint.startsWith("err"))returnfalse;String voted = grabValue(getApiResponse(endpoint),"\"isVoted\":",",\"serverTime\"");return tryParseBool(voted);}catch(Exception e){
player.sendMessage("Something went wrong. Please try again later.");
e.printStackTrace();}returnfalse;}public boolean tryParseBool(Stringbool){if(bool.startsWith("1"))returntrue;CharSequence cs ="voteTime";if(bool.contains(cs)){//System.out.println("Contains \"voteTime\"");String newbool =bool.substring(0,4);//System.out.println("Bool to pass: " + newbool);returnBoolean.parseBoolean(newbool);}returnBoolean.parseBoolean(bool.trim());}publicString getApiResponse(String endpoint){StringBuilder stringBuilder =newStringBuilder();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 =newBufferedReader(newInputStreamReader(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";}}privatestaticString grabValue(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;}}
Hello everyone!
I have a problem with editing mobs. I took some Mobs from here without sound and added them,
they looked good !!! BUT BUT !
When I hit him it does generate the effect, but when he hits it it doesn't.
Is this effect controlled from Npcgrp.dat?
PD_ I add capture of the event / effect I mention.
I await your answers, thank you!
Alguém que saiba trabalhar com Engine.dll e Core.dll? Tenho hwid no servidor o código adaptado, mas não tenho parte do cliente, pois meu cliente é c4.. Alguém que faça esse tipo de serviço
Question
sqhizein
i am having trouble about .vote command. if one player type .vote, the entire players in the game have to wait 12 hours.
how can i remove all Hwid record from this code without any error :
i just want to use theese two checking code
ACCOUNT_NAME,
IP_ADRESS,
HWID (this code have to gone)
3 answers to this question
Recommended Posts