SHOW:
|
|
- or go back to the newest paste.
1 | diff --git a/aCis_gameserver/config/votesystem.properties b/aCis_gameserver/config/votesystem.properties | |
2 | new file mode 100644 | |
3 | index 0000000..10f1f93 | |
4 | --- /dev/null | |
5 | +++ b/aCis_gameserver/config/votesystem.properties | |
6 | @@ -0,0 +1,95 @@ | |
7 | +EnableVoteSystem = True | |
8 | + | |
9 | +EnableGlobalVote = True | |
10 | + | |
11 | +EnableIndividualVote = True | |
12 | + | |
13 | +## Time to Update table totalVotes from DB | |
14 | +NextTimeToAutoUpdateTotalVote = 2 | |
15 | + | |
16 | +## Time to update table individualVotes | |
17 | +NextTimeToAutoUpdateIndividualVotes = 2 | |
18 | + | |
19 | +NextTimeToAutoCleanInnecesaryVotes = 30 | |
20 | + | |
21 | +NextTimeToCheckAutoGlobalVotesReward = 1 | |
22 | + | |
23 | +IntervalToNextVote = 12 | |
24 | + | |
25 | +GlobalVotesAmountToNextReward = 1 | |
26 | + | |
27 | +EnableVotingCommand = True | |
28 | + | |
29 | +VotingCommand = .getreward | |
30 | + | |
31 | +## l2.topgameserver.net | |
32 | +VoteLinkTgs = http://l2.topgameserver.net/lineage/VoteApi/ | |
33 | + | |
34 | +TgsApiKey = | |
35 | + | |
36 | +## l2top.co | |
37 | +VoteLinkTopCo = https://l2top.co/reward/ | |
38 | + | |
39 | +TopCoSrvId = | |
40 | + | |
41 | +## ITopz.com | |
42 | +VoteLinkItopz = https://itopz.com/check/ | |
43 | + | |
44 | +ItopzZpiKey = | |
45 | + | |
46 | +ItopzSrvId = | |
47 | + | |
48 | +## l2votes.com | |
49 | +VoteLinkVts = https://l2votes.com/ | |
50 | + | |
51 | +VtsApiKey = | |
52 | + | |
53 | +VtsSid = | |
54 | + | |
55 | +## Hopzone.net | |
56 | +VoteLinkHz = https://api.hopzone.net/lineage2/ | |
57 | + | |
58 | +HzApiKey = | |
59 | + | |
60 | +## l2network.eu | |
61 | +VoteNetworkLink = https://l2network.eu/api.php | |
62 | + | |
63 | +VoteNetworkUserName = | |
64 | + | |
65 | +VoteNetworkApiKey = | |
66 | + | |
67 | +## L2TopServer.com | |
68 | +VoteLinkTss = https://l2topservers.com/votes? | |
69 | + | |
70 | +TssApiToken = | |
71 | + | |
72 | +TsSrvId = 453 | |
73 | + | |
74 | +TsDomainName= l2catgang | |
75 | + | |
76 | +## top.l2jbrasil.com | |
77 | +BrasilVoteLink = https://top.l2jbrasil.com/votesystem/index.php? | |
78 | + | |
79 | +BrasilUserName = julioguzman | |
80 | + | |
81 | +## Mmotop.eu | |
82 | +VoteLinkMmotop = https://l2jtop.com/api/ | |
83 | + | |
84 | +MmotopApiKey = | |
85 | + | |
86 | +## L2TopZone.com | |
87 | +VoteLinkTz = https://api.l2topzone.com/v1/ | |
88 | + | |
89 | +TzApiKey = | |
90 | + | |
91 | +## L2Servers.com | |
92 | +VoteLinkServers = https://www.l2servers.com/api/ | |
93 | + | |
94 | +ServersHashCode = | |
95 | + | |
96 | +ServersSrvId = | |
97 | + | |
98 | + | |
99 | +## for localhost test if your project is live, put the word off or leave it blank | |
100 | +TestIp = | |
101 | + | |
102 | diff --git a/aCis_gameserver/java/net/sf/l2j/Config.java b/aCis_gameserver/java/net/sf/l2j/Config.java | |
103 | index 4b7181f..800de1e 100644 | |
104 | --- a/aCis_gameserver/java/net/sf/l2j/Config.java | |
105 | +++ b/aCis_gameserver/java/net/sf/l2j/Config.java | |
106 | ||
107 | import java.util.Properties; | |
108 | + import java.util.concurrent.TimeUnit; | |
109 | import java.util.logging.Level; | |
110 | ||
111 | @@ -35,6 +35,7 @@ | |
112 | public static final String PLAYERS_FILE = "./config/players.properties"; | |
113 | public static final String SERVER_FILE = "./config/server.properties"; | |
114 | public static final String SIEGE_FILE = "./config/siege.properties"; | |
115 | + public static final String VOTE_SYSTEM_FILE = "./config/votesystem.properties"; | |
116 | ||
117 | // -------------------------------------------------- | |
118 | // Clans settings | |
119 | @@ -461,6 +462,52 @@ | |
120 | public static int MAX_DEFENDERS_NUMBER; | |
121 | public static int ATTACKERS_RESPAWN_DELAY; | |
122 | ||
123 | + | |
124 | + //--------------------------------------------------- | |
125 | + // VOTE SYSTEM | |
126 | + //--------------------------------------------------- | |
127 | + public static boolean ENABLE_VOTE_SYSTEM; | |
128 | + public static boolean ENABLE_INDIVIDUAL_VOTE; | |
129 | + public static boolean ENABLE_GLOBAL_VOTE; | |
130 | + public static long NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE; | |
131 | + public static long NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES; | |
132 | + public static long NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES; | |
133 | + public static long NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD; | |
134 | + public static long INTERVAL_TO_NEXT_VOTE; | |
135 | + public static int GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD; | |
136 | + public static boolean ENABLE_VOTING_COMMAND; | |
137 | + public static String VOTING_COMMAND; | |
138 | + public static String VOTE_LINK_TGS; | |
139 | + public static String TGS_API_KEY; | |
140 | + public static String VOTE_LINK_TOP_CO; | |
141 | + public static String TOP_CO_SRV_ID; | |
142 | + public static String VOTE_LINK_ITOPZ; | |
143 | + public static String ITOPZ_API_KEY; | |
144 | + public static String ITOPZ_SRV_ID; | |
145 | + public static String VOTE_LINK_VTS; | |
146 | + public static String VTS_API_KEY; | |
147 | + public static String VTS_SID; | |
148 | + public static String VOTE_LINK_HZ; | |
149 | + public static String HZ_API_KEY; | |
150 | + public static String VOTE_NETWORK_LINK; | |
151 | + public static String VOTE_NETWORK_USER_NAME; | |
152 | + public static String VOTE_NETWORK_API_KEY; | |
153 | + public static String VOTE_LINK_TSS; | |
154 | + public static String TSS_API_TOKEN; | |
155 | + public static String TS_SRV_ID; | |
156 | + public static String TS_DOMAIN_NAME; | |
157 | + public static String BRASIL_VOTE_LINK; | |
158 | + public static String BRASIL_USER_NAME; | |
159 | + public static String VOTE_LINK_MMOTOP; | |
160 | + public static String MMOTOP_API_KEY; | |
161 | + public static String VOTE_LINK_TZ; | |
162 | + public static String TZ_API_KEY; | |
163 | + public static String VOTE_LINK_SERVERS; | |
164 | + public static String SERVERS_HASH_CODE; | |
165 | + public static String SERVERS_SRV_ID; | |
166 | + public static String TEST_IP; | |
167 | + | |
168 | + | |
169 | // -------------------------------------------------- | |
170 | // Server | |
171 | // -------------------------------------------------- | |
172 | @@ -1102,6 +1149,52 @@ | |
173 | ATTACKERS_RESPAWN_DELAY = sieges.getProperty("AttackerRespawn", 10000); | |
174 | } | |
175 | ||
176 | + private static final void loadVoteSystem() | |
177 | + { | |
178 | + final ExProperties votesystem = initProperties(Config.VOTE_SYSTEM_FILE); | |
179 | + | |
180 | + ENABLE_VOTE_SYSTEM = votesystem.getProperty("EnableVoteSystem", true); | |
181 | + ENABLE_INDIVIDUAL_VOTE = votesystem.getProperty("EnableIndividualVote", true); | |
182 | + ENABLE_GLOBAL_VOTE = votesystem.getProperty("EnableGlobalVote", true); | |
183 | + NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoUpdateTotalVote", 60));// -> minutes | |
184 | + NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoUpdateIndividualVotes", 60));// -> minutes | |
185 | + NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoCleanInnecesaryVotes", 30));// -> minutes | |
186 | + NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToCheckAutoGlobalVotesReward", 5));// -> minutes | |
187 | + INTERVAL_TO_NEXT_VOTE = TimeUnit.HOURS.toMillis(votesystem.getProperty("IntervalTimeToNextVote", 12)); // -> hours | |
188 | + GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = votesystem.getProperty("GlobalVotesAmountToNextReward",50); | |
189 | + ENABLE_VOTING_COMMAND = votesystem.getProperty("EnableVotingCommand",true); | |
190 | + VOTING_COMMAND = votesystem.getProperty("VotingCommand","getreward"); | |
191 | + VOTE_LINK_TGS = votesystem.getProperty("VoteLinkTgs",""); | |
192 | + TGS_API_KEY = votesystem.getProperty("TgsApiKey",""); | |
193 | + VOTE_LINK_TOP_CO = votesystem.getProperty("VoteLinkTopCo",""); | |
194 | + TOP_CO_SRV_ID = votesystem.getProperty("TopCoSrvId",""); | |
195 | + VOTE_LINK_ITOPZ = votesystem.getProperty("VoteLinkItopz",""); | |
196 | + ITOPZ_API_KEY = votesystem.getProperty("ItopzZpiKey",""); | |
197 | + ITOPZ_SRV_ID = votesystem.getProperty("ItopzSrvId",""); | |
198 | + VOTE_LINK_VTS = votesystem.getProperty("VoteLinkVts",""); | |
199 | + VTS_API_KEY = votesystem.getProperty("VtsApiKey",""); | |
200 | + VTS_SID = votesystem.getProperty("VtsSid",""); | |
201 | + VOTE_LINK_HZ = votesystem.getProperty("VoteLinkHz",""); | |
202 | + HZ_API_KEY = votesystem.getProperty("HzApiKey",""); | |
203 | + VOTE_NETWORK_LINK = votesystem.getProperty("VoteNetworkLink",""); | |
204 | + VOTE_NETWORK_USER_NAME = votesystem.getProperty("VoteNetworkUserName",""); | |
205 | + VOTE_NETWORK_API_KEY = votesystem.getProperty("VoteNetworkApiKey",""); | |
206 | + VOTE_LINK_TSS = votesystem.getProperty("VoteLinkTss",""); | |
207 | + TSS_API_TOKEN = votesystem.getProperty("TssApiToken",""); | |
208 | + TS_SRV_ID = votesystem.getProperty("TsSrvId",""); | |
209 | + TS_DOMAIN_NAME = votesystem.getProperty("TsDomainName",""); | |
210 | + BRASIL_VOTE_LINK = votesystem.getProperty("BrasilVoteLink",""); | |
211 | + BRASIL_USER_NAME = votesystem.getProperty("BrasilUserName",""); | |
212 | + VOTE_LINK_MMOTOP = votesystem.getProperty("VoteLinkMmotop",""); | |
213 | + MMOTOP_API_KEY = votesystem.getProperty("MmotopApiKey",""); | |
214 | + VOTE_LINK_TZ = votesystem.getProperty("VoteLinkTz",""); | |
215 | + TZ_API_KEY = votesystem.getProperty("TzApiKey",""); | |
216 | + VOTE_LINK_SERVERS = votesystem.getProperty("VoteLinkServers",""); | |
217 | + SERVERS_HASH_CODE = votesystem.getProperty("ServersHashCode",""); | |
218 | + SERVERS_SRV_ID = votesystem.getProperty("ServersSrvId",""); | |
219 | + TEST_IP = votesystem.getProperty("TestIp",""); | |
220 | + } | |
221 | + | |
222 | /** | |
223 | * Loads gameserver settings.<br> | |
224 | * IP addresses, database, rates, feature enabled/disabled, misc. | |
225 | @@ -1309,6 +1402,9 @@ | |
226 | ||
227 | // server settings | |
228 | loadServer(); | |
229 | + | |
230 | + //vote settings | |
231 | + loadVoteSystem(); | |
232 | } | |
233 | ||
234 | public static final void loadLoginServer() | |
235 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java b/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java | |
236 | index 41a9f92..da97fd2 100644 | |
237 | --- a/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java | |
238 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java | |
239 | @@ -99,6 +99,8 @@ | |
240 | import net.sf.l2j.gameserver.taskmanager.RandomAnimationTaskManager; | |
241 | import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager; | |
242 | import net.sf.l2j.gameserver.taskmanager.WaterTaskManager; | |
243 | +import net.sf.l2j.gameserver.votesystem.Handler.voteManager; | |
244 | +import net.sf.l2j.gameserver.votesystem.VoteUtil.VoteSiteXml; | |
245 | import net.sf.l2j.util.DeadLockDetector; | |
246 | import net.sf.l2j.util.IPv4Filter; | |
247 | ||
248 | @@ -194,6 +196,15 @@ | |
249 | CrestCache.getInstance(); | |
250 | ClanTable.getInstance(); | |
251 | ||
252 | + StringUtil.printSection("Vote System"); | |
253 | + if(Config.ENABLE_VOTE_SYSTEM) { | |
254 | + voteManager.getInatance(); | |
255 | + LOGGER.info("======================Vote System Enabled========================="); | |
256 | + VoteSiteXml.getInstance(); | |
257 | + }else { | |
258 | + LOGGER.info("======================Vote System Disabled========================="); | |
259 | + } | |
260 | + | |
261 | StringUtil.printSection("Geodata & Pathfinding"); | |
262 | GeoEngine.getInstance(); | |
263 | ||
264 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/Shutdown.java b/aCis_gameserver/java/net/sf/l2j/gameserver/Shutdown.java | |
265 | index 88a3dc4..8443463 100644 | |
266 | --- a/aCis_gameserver/java/net/sf/l2j/gameserver/Shutdown.java | |
267 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/Shutdown.java | |
268 | @@ -27,6 +27,7 @@ | |
269 | import net.sf.l2j.gameserver.network.serverpackets.ServerClose; | |
270 | import net.sf.l2j.gameserver.network.serverpackets.SystemMessage; | |
271 | import net.sf.l2j.gameserver.taskmanager.ItemsOnGroundTaskManager; | |
272 | +import net.sf.l2j.gameserver.votesystem.Handler.voteManager; | |
273 | ||
274 | /** | |
275 | * This class provides functions for shutting down and restarting the server. It closes all client connections and saves data. | |
276 | @@ -146,6 +147,10 @@ | |
277 | LOGGER.info("CoupleManager data has been saved."); | |
278 | } | |
279 | ||
280 | + //Save global and individual votes | |
281 | + voteManager.getInatance().Shutdown(); | |
282 | + LOGGER.info("Vote data has been saved"); | |
283 | + | |
284 | // Save server memos. | |
285 | ServerMemoTable.getInstance().storeMe(); | |
286 | LOGGER.info("ServerMemo data has been saved."); | |
287 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/handler/CustomCommandsHandler.java b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/CustomCommandsHandler.java | |
288 | new file mode 100644 | |
289 | index 0000000..aca915c | |
290 | --- /dev/null | |
291 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/CustomCommandsHandler.java | |
292 | @@ -0,0 +1,42 @@ | |
293 | +package net.sf.l2j.gameserver.handler; | |
294 | + | |
295 | +import java.util.Map; | |
296 | + | |
297 | +import net.sf.l2j.gameserver.handler.customcommandHandler.VoteCommandHandler; | |
298 | + | |
299 | +import java.util.HashMap; | |
300 | + | |
301 | +/** | |
302 | + * @author l2.topgameserver.net | |
303 | + * | |
304 | + */ | |
305 | +public class CustomCommandsHandler { | |
306 | + private final Map<Integer, ICustomCommandsHandler> _datatable = new HashMap<>(); | |
307 | + | |
308 | + | |
309 | + | |
310 | + protected CustomCommandsHandler() { | |
311 | + registerCustomCommandHandler(new VoteCommandHandler()); | |
312 | + } | |
313 | + | |
314 | + public void registerCustomCommandHandler(ICustomCommandsHandler handler) { | |
315 | + for (String id : handler.getCustomCommandList()) | |
316 | + _datatable.put(id.hashCode(), handler); | |
317 | + } | |
318 | + | |
319 | + public ICustomCommandsHandler getCustomCommandHandler(String customCommand) { | |
320 | + return _datatable.get(customCommand.hashCode()); | |
321 | + } | |
322 | + | |
323 | + public int size() { | |
324 | + return _datatable.size(); | |
325 | + } | |
326 | + | |
327 | + public static CustomCommandsHandler getInstance() { | |
328 | + return SingletonHolder._instance; | |
329 | + } | |
330 | + | |
331 | + private static class SingletonHolder { | |
332 | + protected static final CustomCommandsHandler _instance = new CustomCommandsHandler(); | |
333 | + } | |
334 | +} | |
335 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/handler/ICustomCommandsHandler.java b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/ICustomCommandsHandler.java | |
336 | new file mode 100644 | |
337 | index 0000000..5b4fda9 | |
338 | --- /dev/null | |
339 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/ICustomCommandsHandler.java | |
340 | @@ -0,0 +1,13 @@ | |
341 | +package net.sf.l2j.gameserver.handler; | |
342 | + | |
343 | +import net.sf.l2j.gameserver.model.actor.Player; | |
344 | + | |
345 | +/** | |
346 | + * @author l2.topgameserver.net | |
347 | + * | |
348 | + */ | |
349 | +public interface ICustomCommandsHandler | |
350 | +{ | |
351 | + void useCustomCommand(String command, Player activeChar); | |
352 | + public String[] getCustomCommandList(); | |
353 | +} | |
354 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/handler/customcommandHandler/VoteCommandHandler.java b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/customcommandHandler/VoteCommandHandler.java | |
355 | new file mode 100644 | |
356 | index 0000000..36d318c | |
357 | --- /dev/null | |
358 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/handler/customcommandHandler/VoteCommandHandler.java | |
359 | @@ -0,0 +1,71 @@ | |
360 | +package net.sf.l2j.gameserver.handler.customcommandHandler; | |
361 | + | |
362 | +import net.sf.l2j.Config; | |
363 | +import net.sf.l2j.gameserver.handler.ICustomCommandsHandler; | |
364 | +import net.sf.l2j.gameserver.model.actor.Player; | |
365 | +import net.sf.l2j.gameserver.votesystem.DB.individualVoteDB; | |
366 | +import net.sf.l2j.gameserver.votesystem.Enum.voteSite; | |
367 | +import net.sf.l2j.gameserver.votesystem.Handler.voteManager; | |
368 | + | |
369 | +/** | |
370 | + * @author l2.topgameserver.net | |
371 | + * | |
372 | + */ | |
373 | +public class VoteCommandHandler implements ICustomCommandsHandler | |
374 | +{ | |
375 | + | |
376 | + @Override | |
377 | + public void useCustomCommand(String command, Player player) | |
378 | + { | |
379 | + | |
380 | + if (command.equalsIgnoreCase(Config.VOTING_COMMAND)) | |
381 | + { | |
382 | + if(player.isInJail()) { | |
383 | + player.sendMessage("You cannot use this function while you are jailed"); | |
384 | + return; | |
385 | + } | |
386 | + if(!Config.ENABLE_VOTE_SYSTEM) { | |
387 | + player.sendMessage("The rewards system has been disabled by your administrator"); | |
388 | + return; | |
389 | + } | |
390 | + if(!Config.ENABLE_INDIVIDUAL_VOTE) { | |
391 | + player.sendMessage("The individual reward system is disabled"); | |
392 | + return; | |
393 | + } | |
394 | + if(!Config.ENABLE_VOTING_COMMAND) { | |
395 | + player.sendMessage("Voting command reward is disabled"); | |
396 | + return; | |
397 | + } | |
398 | + | |
399 | + for(voteSite vs : voteSite.values()) { | |
400 | + new Thread(()->{ | |
401 | + voteManager.getInatance().getReward(player, vs.ordinal()); | |
402 | + }).start(); | |
403 | + } | |
404 | + | |
405 | + } | |
406 | + if(player.isGM() && command.equalsIgnoreCase(".reloadinvotes")) { | |
407 | + individualVoteDB.getInstance().loadVotes(); | |
408 | + player.sendMessage("All individual votes has been recharged"); | |
409 | + } | |
410 | + } | |
411 | + | |
412 | + | |
413 | + @Override | |
414 | + public String[] getCustomCommandList() | |
415 | + { | |
416 | + return new String[] | |
417 | + { | |
418 | + Config.VOTING_COMMAND, | |
419 | + ".reloadinvotes", | |
420 | + }; | |
421 | + } | |
422 | + public static VoteCommandHandler getInstance() | |
423 | + { | |
424 | + return SingletonHolder._instance; | |
425 | + } | |
426 | + private static class SingletonHolder | |
427 | + { | |
428 | + protected static final VoteCommandHandler _instance = new VoteCommandHandler(); | |
429 | + } | |
430 | +} | |
431 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/instance/NpcVote.java b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/instance/NpcVote.java | |
432 | new file mode 100644 | |
433 | index 0000000..d4bf57f | |
434 | --- /dev/null | |
435 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/instance/NpcVote.java | |
436 | @@ -0,0 +1,87 @@ | |
437 | +package net.sf.l2j.gameserver.model.actor.instance; | |
438 | + | |
439 | +import net.sf.l2j.Config; | |
440 | +import net.sf.l2j.gameserver.data.ItemTable; | |
441 | +import net.sf.l2j.gameserver.model.actor.Player; | |
442 | +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate; | |
443 | +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; | |
444 | +import net.sf.l2j.gameserver.votesystem.Enum.voteSite; | |
445 | +import net.sf.l2j.gameserver.votesystem.Handler.voteManager; | |
446 | +import net.sf.l2j.gameserver.votesystem.Model.Reward; | |
447 | +import net.sf.l2j.gameserver.votesystem.VoteUtil.VoteSiteXml; | |
448 | + | |
449 | +/** | |
450 | + * @author l2.topgameserver.net | |
451 | + * | |
452 | + */ | |
453 | +public class NpcVote extends Folk | |
454 | +{ | |
455 | + | |
456 | + /** | |
457 | + * @param objectId | |
458 | + * @param template | |
459 | + */ | |
460 | + public NpcVote(int objectId, NpcTemplate template) | |
461 | + { | |
462 | + super(objectId, template); | |
463 | + // TODO Auto-generated constructor stub | |
464 | + } | |
465 | + | |
466 | + @Override | |
467 | + public void onBypassFeedback(Player player, String command) | |
468 | + { | |
469 | + if(command == null) { | |
470 | + return; | |
471 | + } | |
472 | + int Ordinalsite = Integer.parseInt(command); | |
473 | + voteManager.getInatance().getReward(player, Ordinalsite); | |
474 | + showChatWindow(player,0); | |
475 | + super.onBypassFeedback(player, command); | |
476 | + } | |
477 | + | |
478 | + @Override | |
479 | + public void showChatWindow(Player player, int val) { | |
480 | + final NpcHtmlMessage html = new NpcHtmlMessage(0); | |
481 | + StringBuilder sb = new StringBuilder(); | |
482 | + html.setFile(getHtmlPath(getNpcId(), 0)); | |
483 | + for(voteSite vs : voteSite.values()) { | |
484 | + sb.append("<table bgcolor=000000 width=280><tr>"); | |
485 | + sb.append("<td width=42><img src=\"icon.etc_treasure_box_i08\" width=32 height=32></td>"); | |
486 | + sb.append("<td width=220><table width=220>"); | |
487 | + sb.append("<tr><td><table width=220><tr><td width=145>On "+String.format("%s",VoteSiteXml.getInstance().getSiteName(vs.ordinal()))+"</td>"); | |
488 | + if(voteManager.getInatance().checkIndividualAvailableVote(player, vs.ordinal())) { | |
489 | + 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>"); | |
490 | + }else { | |
491 | + sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(player, vs.ordinal()))); | |
492 | + } | |
493 | + sb.append("</tr></table></td></tr>"); | |
494 | + sb.append("<tr><td><table width=220><tr>"); | |
495 | + int i=0; | |
496 | + for(Reward r : VoteSiteXml.getInstance().getRewards(vs.ordinal())) { | |
497 | + 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())); | |
498 | + i++; | |
499 | + if(i%2==0) { | |
500 | + sb.append("</tr><tr>"); | |
501 | + } | |
502 | + } | |
503 | + sb.append("</tr></table></td></tr></table></td></tr></table><br>"); | |
504 | + } | |
505 | + html.replace("%everyXtime%",Config.INTERVAL_TO_NEXT_VOTE/(3600*1000)); | |
506 | + html.replace("%enablevote%", sb.toString()); | |
507 | + html.replace("%accountName%",player.getName()); | |
508 | + player.sendPacket(html); | |
509 | + } | |
510 | + | |
511 | + @Override | |
512 | + public String getHtmlPath(int npcId, int val) | |
513 | + { | |
514 | + String filename = ""; | |
515 | + if (val == 0) | |
516 | + filename = "" + npcId; | |
517 | + else | |
518 | + filename = npcId + "-" + val; | |
519 | + | |
520 | + return "data/html/mods/votesystem/" + filename + ".html"; | |
521 | + } | |
522 | + | |
523 | +} | |
524 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java | |
525 | index cfd76fa..773eee2 100644 | |
526 | --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java | |
527 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java | |
528 | @@ -99,6 +99,23 @@ | |
529 | html.disableValidation(); | |
530 | player.sendPacket(html); | |
531 | } | |
532 | + else if(_command.startsWith("vote_")) { | |
533 | + if (!player.validateBypass(_command)) | |
534 | + return; | |
535 | + | |
536 | + int endOfId = _command.indexOf('_', 6); | |
537 | + String id; | |
538 | + if (endOfId > 0) | |
539 | + id = _command.substring(5, endOfId); | |
540 | + else | |
541 | + id = _command.substring(5); | |
542 | + | |
543 | + if(_command.split(" ")[1].toString() != null) { | |
544 | + final WorldObject object = World.getInstance().getObject(Integer.parseInt(id)); | |
545 | + if (object != null && object instanceof Npc && endOfId > 0 && ((Npc) object).canInteract(player)) | |
546 | + ((Npc) object).onBypassFeedback(player, _command.split(" ")[1].toString()); | |
547 | + } | |
548 | + } | |
549 | else if (_command.startsWith("npc_")) | |
550 | { | |
551 | if (!player.validateBypass(_command)) | |
552 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/DB/globalVoteDB.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/DB/globalVoteDB.java | |
553 | new file mode 100644 | |
554 | index 0000000..43865e9 | |
555 | --- /dev/null | |
556 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/DB/globalVoteDB.java | |
557 | @@ -0,0 +1,104 @@ | |
558 | +package net.sf.l2j.gameserver.votesystem.DB; | |
559 | + | |
560 | +import java.sql.Connection; | |
561 | +import java.sql.PreparedStatement; | |
562 | +import java.sql.ResultSet; | |
563 | +import java.sql.SQLException; | |
564 | +import java.sql.Statement; | |
565 | + | |
566 | +import net.sf.l2j.commons.logging.CLogger; | |
567 | + | |
568 | +import net.sf.l2j.L2DatabaseFactory; | |
569 | +import net.sf.l2j.gameserver.votesystem.Enum.voteSite; | |
570 | +import net.sf.l2j.gameserver.votesystem.Model.globalVote; | |
571 | + | |
572 | + | |
573 | +/** | |
574 | + * @author l2.topgameserver.net | |
575 | + * | |
576 | + */ | |
577 | +public class globalVoteDB | |
578 | +{ | |
579 | + public static final CLogger LOGGER = new CLogger(globalVoteDB.class.getName()); | |
580 | + private Statement st; | |
581 | + private Connection con; | |
582 | + private globalVote[] _globalVotes; | |
583 | + private globalVoteDB() { | |
584 | + _globalVotes = new globalVote[voteSite.values().length]; | |
585 | + loadGlobalVotes(); | |
586 | + } | |
587 | + | |
588 | + public void loadGlobalVotes() { | |
589 | + con = L2DatabaseFactory.getInstance().getConnection(); | |
590 | + try(PreparedStatement ps = con.prepareStatement("Select voteSite,lastRewardVotes from globalvotes"); | |
591 | + ResultSet rs = ps.executeQuery();){ | |
592 | + if(rs.getRow() == 0){ | |
593 | + for(voteSite vs : voteSite.values()){ | |
594 | + globalVote gv = new globalVote(); | |
595 | + gv.setVoteSite(vs.ordinal()); | |
596 | + gv.setVotesLastReward(0); | |
597 | + _globalVotes[gv.getVoyeSite()] = gv; | |
598 | + } | |
599 | + return; | |
600 | + } | |
601 | + while(rs.next()) { | |
602 | + globalVote gv = new globalVote(); | |
603 | + gv.setVoteSite(rs.getInt("voteSite")); | |
604 | + gv.setVotesLastReward(rs.getInt("lastRewardVotes")); | |
605 | + _globalVotes[gv.getVoyeSite()] = gv; | |
606 | + } | |
607 | + ps.close(); | |
608 | + con.close(); | |
609 | + | |
610 | + }catch(SQLException e) { | |
611 | + e.printStackTrace(); | |
612 | + } | |
613 | + } | |
614 | + public void saveGlobalVote(globalVote gb) { | |
615 | + try(Connection con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" | |
616 | + + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)")) | |
617 | + | |
618 | + { | |
619 | + ps.setInt(1, gb.getVoyeSite()); | |
620 | + ps.setInt(2, gb.getVotesLastReward()); | |
621 | + ps.executeUpdate(); | |
622 | + | |
623 | + ps.close(); | |
624 | + con.close(); | |
625 | + | |
626 | + }catch(SQLException e) { | |
627 | + e.printStackTrace(); | |
628 | + } | |
629 | + } | |
630 | + | |
631 | + public void saveGlobalVotes(globalVote[] globalVotes) { | |
632 | + try(Connection con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" | |
633 | + + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)")) | |
634 | + | |
635 | + { | |
636 | + for(voteSite vs : voteSite.values()) { | |
637 | + globalVote gb = globalVotes[vs.ordinal()]; | |
638 | + ps.setInt(1, gb.getVoyeSite()); | |
639 | + ps.setInt(2, gb.getVotesLastReward()); | |
640 | + ps.addBatch(); | |
641 | + } | |
642 | + ps.executeBatch(); | |
643 | + | |
644 | + ps.close(); | |
645 | + con.close(); | |
646 | + | |
647 | + }catch(SQLException e) { | |
648 | + e.printStackTrace(); | |
649 | + } | |
650 | + } | |
651 | + | |
652 | + public globalVote[] getGlobalVotes() { | |
653 | + return _globalVotes; | |
654 | + } | |
655 | + public static final globalVoteDB getInstance() { | |
656 | + return SingleHolder.INSTANCE; | |
657 | + } | |
658 | + private static final class SingleHolder { | |
659 | + protected static final globalVoteDB INSTANCE = new globalVoteDB(); | |
660 | + } | |
661 | +} | |
662 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/DB/individualVoteDB.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/DB/individualVoteDB.java | |
663 | new file mode 100644 | |
664 | index 0000000..2cf9522 | |
665 | --- /dev/null | |
666 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/DB/individualVoteDB.java | |
667 | @@ -0,0 +1,160 @@ | |
668 | +package net.sf.l2j.gameserver.votesystem.DB; | |
669 | + | |
670 | + | |
671 | +import java.sql.Connection; | |
672 | +import java.sql.PreparedStatement; | |
673 | +import java.sql.ResultSet; | |
674 | +import java.sql.SQLException; | |
675 | +import java.sql.Statement; | |
676 | +import java.util.HashMap; | |
677 | +import java.util.HashSet; | |
678 | +import java.util.Map; | |
679 | +import java.util.logging.Logger; | |
680 | +import net.sf.l2j.L2DatabaseFactory; | |
681 | +import net.sf.l2j.gameserver.votesystem.Enum.voteSite; | |
682 | + | |
683 | + | |
684 | +import net.sf.l2j.gameserver.votesystem.Model.individualVote; | |
685 | + | |
686 | +/** | |
687 | + * @author l2.topgameserver.net | |
688 | + * | |
689 | + */ | |
690 | +public class individualVoteDB | |
691 | +{ | |
692 | + private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName()); | |
693 | + private Map<String,individualVote[]> _votes; | |
694 | + private Statement st; | |
695 | + private Connection con; | |
696 | + | |
697 | + | |
698 | + private individualVoteDB() { | |
699 | + _votes = new HashMap<>(); | |
700 | + loadVotes(); | |
701 | + } | |
702 | + | |
703 | + public void loadVotes() { | |
704 | + | |
705 | + _votes.clear(); | |
706 | + try(Connection con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualvotes"); | |
707 | + ResultSet rs = ps.executeQuery();) | |
708 | + { | |
709 | + individualVote[] ivs = new individualVote[voteSite.values().length]; | |
710 | + while(rs.next()) { | |
711 | + individualVote iv = new individualVote(); | |
712 | + iv.setVoterIp(rs.getString("voterIp")); | |
713 | + iv.setVoteSite(rs.getInt("voteSite")); | |
714 | + iv.setDiffTime(rs.getLong("diffTime")); | |
715 | + iv.setVotingTimeSite(rs.getLong("votingTimeSite")); | |
716 | + iv.setAlreadyRewarded(rs.getBoolean("alreadyRewarded")); | |
717 | + | |
718 | + if(_votes.containsKey(iv.getVoterIp())) { | |
719 | + if(_votes.get(iv.getVoterIp())[iv.getVoteSite()] == null) { | |
720 | + ivs[iv.getVoteSite()] = iv; | |
721 | + _votes.replace(iv.getVoterIp(), ivs); | |
722 | + } | |
723 | + }else { | |
724 | + ivs[iv.getVoteSite()] = iv; | |
725 | + _votes.put(iv.getVoterIp(), ivs); | |
726 | + | |
727 | + | |
728 | + } | |
729 | + } | |
730 | + | |
731 | + } | |
732 | + catch (SQLException e) | |
733 | + { | |
734 | + e.printStackTrace(); | |
735 | + } | |
736 | + | |
737 | + } | |
738 | + | |
739 | + public void SaveVotes(Map<String,individualVote[]> votes) { | |
740 | + | |
741 | + if(votes == null) | |
742 | + return; | |
743 | + if(votes.size() == 0) { | |
744 | + return; | |
745 | + } | |
746 | + try(Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE " | |
747 | + + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite),alreadyRewarded = VALUES(alreadyRewarded)");) | |
748 | + { | |
749 | + | |
750 | + for(Map.Entry<String, individualVote[]> ivm : votes.entrySet()) { | |
751 | + for(individualVote iv : ivm.getValue()) { | |
752 | + if(iv == null) | |
753 | + continue; | |
754 | + ps.setString(1, iv.getVoterIp()); | |
755 | + ps.setInt(2, iv.getVoteSite()); | |
756 | + ps.setLong(3, iv.getDiffTime()); | |
757 | + ps.setLong(4, iv.getVotingTimeSite()); | |
758 | + ps.setBoolean(5, iv.getAlreadyRewarded()); | |
759 | + ps.addBatch(); | |
760 | + } | |
761 | + } | |
762 | + ps.executeBatch(); | |
763 | + } | |
764 | + catch (SQLException e) | |
765 | + { | |
766 | + e.printStackTrace(); | |
767 | + } | |
768 | + } | |
769 | + | |
770 | + public void SaveVote(individualVote vote) { | |
771 | + | |
772 | + if(vote == null) | |
773 | + return; | |
774 | + | |
775 | + try(Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE" | |
776 | + + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");) | |
777 | + { | |
778 | + ps.setString(1, vote.getVoterIp()); | |
779 | + ps.setInt(2, vote.getVoteSite()); | |
780 | + ps.setLong(3, vote.getDiffTime()); | |
781 | + ps.setLong(4, vote.getVotingTimeSite()); | |
782 | + ps.setBoolean(5, vote.getAlreadyRewarded()); | |
783 | + ps.executeUpdate(); | |
784 | + } | |
785 | + catch (SQLException e) | |
786 | + { | |
787 | + e.printStackTrace(); | |
788 | + } | |
789 | + } | |
790 | + | |
791 | + public void DeleteVotes(HashSet<individualVote> deleteVotes) { | |
792 | + if(deleteVotes == null) { | |
793 | + return; | |
794 | + } | |
795 | + if(deleteVotes.size() == 0) { | |
796 | + return; | |
797 | + } | |
798 | + try { | |
799 | + con = L2DatabaseFactory.getInstance().getConnection(); | |
800 | + st = con.createStatement(); | |
801 | + for(individualVote iv : deleteVotes) { | |
802 | + String sql = String.format("Delete from individualvotes where voterIp = '%s' AND voteSite = %s", iv.getVoterIp(),iv.getVoteSite()); | |
803 | + st.addBatch(sql); | |
804 | + } | |
805 | + int[] result = st.executeBatch(); | |
806 | + st.close(); | |
807 | + con.close(); | |
808 | + LOGGER.info(result.length+" Innecesary votes has been deleted"); | |
809 | + | |
810 | + }catch(SQLException e) { | |
811 | + e.printStackTrace(); | |
812 | + } | |
813 | + } | |
814 | + | |
815 | + public Map<String,individualVote[]> getVotesDB(){ | |
816 | + return _votes; | |
817 | + } | |
818 | + | |
819 | + public static final individualVoteDB getInstance() | |
820 | + { | |
821 | + return SingleHolder.INSTANCE; | |
822 | + } | |
823 | + | |
824 | + private static final class SingleHolder { | |
825 | + protected static final individualVoteDB INSTANCE = new individualVoteDB(); | |
826 | + } | |
827 | +} | |
828 | \ No newline at end of file | |
829 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Enum/voteSite.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Enum/voteSite.java | |
830 | new file mode 100644 | |
831 | index 0000000..4ce2a5d | |
832 | --- /dev/null | |
833 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Enum/voteSite.java | |
834 | @@ -0,0 +1,20 @@ | |
835 | +package net.sf.l2j.gameserver.votesystem.Enum; | |
836 | + | |
837 | +/** | |
838 | + * @author l2.topgameserver.net | |
839 | + * | |
840 | + */ | |
841 | +public enum voteSite | |
842 | +{ | |
843 | + L2TOPGAMESERVER,//0 | |
844 | + ITOPZ,//1 | |
845 | + L2TOPCO,//2 | |
846 | + L2VOTES,//3 | |
847 | + HOPZONE,//4 | |
848 | + L2NETWORK,//5 | |
849 | + L2TOPSERVERS,//6 | |
850 | + TOPL2JBRASIL,//7 | |
851 | + MMOTOP,//8 | |
852 | + TOPZONE,//9 | |
853 | + L2SERVERS,//10 | |
854 | +} | |
855 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Handler/voteHandler.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Handler/voteHandler.java | |
856 | new file mode 100644 | |
857 | index 0000000..8d0eb07 | |
858 | --- /dev/null | |
859 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Handler/voteHandler.java | |
860 | @@ -0,0 +1,488 @@ | |
861 | +package net.sf.l2j.gameserver.votesystem.Handler; | |
862 | + | |
863 | +import java.io.BufferedReader; | |
864 | +import java.io.DataOutputStream; | |
865 | +import java.io.InputStreamReader; | |
866 | +import java.net.HttpURLConnection; | |
867 | +import java.net.URL; | |
868 | +import java.nio.charset.Charset; | |
869 | +import java.text.ParseException; | |
870 | +import java.text.SimpleDateFormat; | |
871 | +import java.util.logging.Logger; | |
872 | + | |
873 | +import net.sf.l2j.Config; | |
874 | +import net.sf.l2j.gameserver.votesystem.Enum.voteSite; | |
875 | +import net.sf.l2j.gameserver.votesystem.Model.individualVoteResponse; | |
876 | +import net.sf.l2j.gameserver.votesystem.VoteUtil.VoteSiteXml; | |
877 | +import net.sf.l2j.gameserver.votesystem.VoteUtil.VoteUtil; | |
878 | + | |
879 | +/** | |
880 | + * @author l2.topgameserver.net | |
881 | + * | |
882 | + */ | |
883 | +public class voteHandler { | |
884 | + public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName()); | |
885 | + | |
886 | + protected static String getNetWorkResponse(String URL,int ordinal) { | |
887 | + if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME))) | |
888 | + { | |
889 | + return ""; | |
890 | + } | |
891 | + | |
892 | + StringBuffer response = new StringBuffer(); | |
893 | + try { | |
894 | + String API_URL = Config.VOTE_NETWORK_LINK; | |
895 | + String detail = URL; | |
896 | + String postParameters = ""; | |
897 | + postParameters +="apiKey="+VoteUtil.between("apiKey=", detail, "&type="); | |
898 | + postParameters += "&type="+VoteUtil.between("&type=", detail, "&player"); | |
899 | + String beginIndexPlayer = "&player="; | |
900 | + String player = detail.substring(detail.indexOf(beginIndexPlayer)+beginIndexPlayer.length()); | |
901 | + | |
902 | + if (player != null && !player.equals("")) | |
903 | + postParameters += "&player=" + player; | |
904 | + | |
905 | + byte[] postData = postParameters.getBytes(Charset.forName("UTF-8")); | |
906 | + URL url = new URL(API_URL); | |
907 | + HttpURLConnection con = (HttpURLConnection)url.openConnection(); | |
908 | + con.setConnectTimeout(5000); | |
909 | + con.setRequestMethod("POST"); | |
910 | + con.setRequestProperty("Content-Length", Integer.toString(postData.length)); | |
911 | + con.setRequestProperty("User-Agent", "Mozilla/5.0"); | |
912 | + con.setDoOutput(true); | |
913 | + | |
914 | + DataOutputStream os = new DataOutputStream(con.getOutputStream()); | |
915 | + os.write(postData); | |
916 | + os.flush(); | |
917 | + os.close(); | |
918 | + | |
919 | + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); | |
920 | + String inputLine; | |
921 | + | |
922 | + while ((inputLine = in.readLine()) != null) { | |
923 | + response.append(inputLine); | |
924 | + } | |
925 | + in.close(); | |
926 | + | |
927 | + return response.toString(); | |
928 | + | |
929 | + } catch (Exception e) { | |
930 | + LOGGER.warning(VoteUtil.Sites[ordinal]+ " Say: An error ocurred "+ e.getCause()); | |
931 | + return ""; | |
932 | + } | |
933 | + } | |
934 | + | |
935 | + protected static String getResponse(String Url, int ordinal) | |
936 | + { | |
937 | + if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME))) | |
938 | + { | |
939 | + return ""; | |
940 | + } | |
941 | + | |
942 | + try | |
943 | + { | |
944 | + int responseCode = 0; | |
945 | + URL objUrl = new URL(Url); | |
946 | + HttpURLConnection con = (HttpURLConnection) objUrl.openConnection(); | |
947 | + con.setRequestMethod("GET"); | |
948 | + con.setRequestProperty("User-Agent", "Mozilla/5.0"); | |
949 | + con.setConnectTimeout(5000); | |
950 | + responseCode = con.getResponseCode(); | |
951 | + if (responseCode == HttpURLConnection.HTTP_OK) { | |
952 | + String inputLine; | |
953 | + StringBuffer response = new StringBuffer(); | |
954 | + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); | |
955 | + while ((inputLine = in.readLine()) != null) { | |
956 | + response.append(inputLine); | |
957 | + } | |
958 | + in.close(); | |
959 | + return response.toString(); | |
960 | + } | |
961 | + | |
962 | + } | |
963 | + catch (Exception e) | |
964 | + { | |
965 | + LOGGER.warning(VoteSiteXml.getInstance().getSiteName(ordinal)+" Say: An error ocurred "+e.getCause()); | |
966 | + return ""; | |
967 | + } | |
968 | + | |
969 | + return ""; | |
970 | + } | |
971 | + | |
972 | + | |
973 | + public static individualVoteResponse getIndividualVoteResponse(int ordinal,String ip, String AccountName) | |
974 | + { | |
975 | + String response = ""; | |
976 | + boolean isVoted = false; | |
977 | + long voteSiteTime = 0L, diffTime = 0L; | |
978 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); | |
979 | + individualVoteResponse ivr = new individualVoteResponse(); | |
980 | + | |
981 | + switch(ordinal) | |
982 | + { | |
983 | + case 0: | |
984 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
985 | + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"already_voted\":", response, ",\"vote_time\"")); | |
986 | + if(isVoted) { | |
987 | + try | |
988 | + { | |
989 | + voteSiteTime = format.parse(VoteUtil.between("\"vote_time\":\"", response, "\",\"server_time\"")).getTime(); | |
990 | + diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"server_time\":\"", response, "\"}")).getTime(); | |
991 | + } | |
992 | + catch (ParseException e) | |
993 | + { | |
994 | + e.printStackTrace(); | |
995 | + } | |
996 | + } | |
997 | + break; | |
998 | + | |
999 | + case 1: | |
1000 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1001 | + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isvoted\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"votetime").replaceAll("\"", "")); | |
1002 | + if(isVoted) { | |
1003 | + try | |
1004 | + { | |
1005 | + voteSiteTime = (Long.parseLong(VoteUtil.between("\"votetime\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"servertime")))*1000; | |
1006 | + diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"servertime\":", response.toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), "}")))*1000; | |
1007 | + } | |
1008 | + catch (Exception e) | |
1009 | + { | |
1010 | + e.printStackTrace(); | |
1011 | + } | |
1012 | + } | |
1013 | + break; | |
1014 | + | |
1015 | + case 2: | |
1016 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1017 | + isVoted = (response == "") ? false :Boolean.parseBoolean(response); | |
1018 | + if(isVoted) { | |
1019 | + voteSiteTime = System.currentTimeMillis(); | |
1020 | + diffTime = 0; | |
1021 | + } | |
1022 | + break; | |
1023 | + | |
1024 | + case 3: | |
1025 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1026 | + isVoted = (VoteUtil.between("\"status\":\"", response, "\",\"date\"") != "" && Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"date\"")) == 1) ? true : false; | |
1027 | + if(isVoted) { | |
1028 | + String dateString = VoteUtil.between("\"date\":\"", response, "\"}]"); | |
1029 | + try | |
1030 | + { | |
1031 | + voteSiteTime = System.currentTimeMillis(); | |
1032 | + diffTime = 0; | |
1033 | + } | |
1034 | + catch (Exception e) | |
1035 | + { | |
1036 | + e.printStackTrace(); | |
1037 | + } | |
1038 | + | |
1039 | + } | |
1040 | + break; | |
1041 | + | |
1042 | + case 4: | |
1043 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1044 | + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\"")); | |
1045 | + if(isVoted) { | |
1046 | + try | |
1047 | + { | |
1048 | + voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"hopzoneServerTime\"")).getTime(); | |
1049 | + diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"hopzoneServerTime\":\"", response, "\",\"status_code\":")).getTime(); | |
1050 | + } | |
1051 | + catch (ParseException e) | |
1052 | + { | |
1053 | + e.printStackTrace(); | |
1054 | + } | |
1055 | + } | |
1056 | + break; | |
1057 | + | |
1058 | + case 5: | |
1059 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1060 | + isVoted = (!"".equals(response) && Integer.parseInt(response) == 1) ? true : false; | |
1061 | + if(isVoted) { | |
1062 | + voteSiteTime = System.currentTimeMillis(); | |
1063 | + diffTime = 0; | |
1064 | + } | |
1065 | + break; | |
1066 | + | |
1067 | + case 6: | |
1068 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1069 | + isVoted = ("".equals(response)) ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\"")); | |
1070 | + if(isVoted) { | |
1071 | + try | |
1072 | + { | |
1073 | + voteSiteTime = System.currentTimeMillis(); | |
1074 | + diffTime = 0; | |
1075 | + } | |
1076 | + catch (Exception e) | |
1077 | + { | |
1078 | + e.printStackTrace(); | |
1079 | + } | |
1080 | + | |
1081 | + } | |
1082 | + break; | |
1083 | + | |
1084 | + case 7: | |
1085 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1086 | + isVoted = (VoteUtil.between("\"status\":\"", response, "\",\"server_time\"") != "" && Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1) ? true : false; | |
1087 | + if(isVoted) { | |
1088 | + try | |
1089 | + { | |
1090 | + voteSiteTime = System.currentTimeMillis(); | |
1091 | + diffTime = 0; | |
1092 | + } | |
1093 | + catch (Exception e) | |
1094 | + { | |
1095 | + e.printStackTrace(); | |
1096 | + } | |
1097 | + } | |
1098 | + break; | |
1099 | + | |
1100 | + case 8: | |
1101 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1102 | + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"is_voted\":", response, ",\"vote_time\"")); | |
1103 | + if(isVoted) { | |
1104 | + try | |
1105 | + { | |
1106 | + voteSiteTime = (Long.parseLong(VoteUtil.between("\"vote_time\":", response, ",\"server_time\"")))*1000; | |
1107 | + diffTime = System.currentTimeMillis() - Long.parseLong(VoteUtil.between("\"server_time\":",response,"}}"))*1000; | |
1108 | + } | |
1109 | + catch (Exception e) | |
1110 | + { | |
1111 | + e.printStackTrace(); | |
1112 | + } | |
1113 | + } | |
1114 | + break; | |
1115 | + | |
1116 | + case 9: | |
1117 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1118 | + isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isVoted\": ", response, ",\"voteTime\"")); | |
1119 | + if(isVoted) { | |
1120 | + voteSiteTime = Long.parseLong(VoteUtil.between("\"voteTime\": \"", response, "\",\"serverTime\""))*1000; | |
1121 | + diffTime = System.currentTimeMillis() - Long.parseLong(VoteUtil.between("\"serverTime\": ",response,"}}"))*1000; | |
1122 | + } | |
1123 | + break; | |
1124 | + | |
1125 | + case 10: | |
1126 | + response = getResponse(getIndividualUrl(ordinal,ip,null),ordinal); | |
1127 | + isVoted = (response == "") ? false : Boolean.parseBoolean(response); | |
1128 | + if(isVoted) { | |
1129 | + voteSiteTime = System.currentTimeMillis(); | |
1130 | + diffTime = 0; | |
1131 | + } | |
1132 | + break; | |
1133 | + | |
1134 | + } | |
1135 | + if(!response.equals("")) { | |
1136 | + ivr.setIsVoted(isVoted); | |
1137 | + ivr.setDiffTime(diffTime); | |
1138 | + ivr.setVoteSiteTime(voteSiteTime); | |
1139 | + return ivr; | |
1140 | + } | |
1141 | + return null; | |
1142 | + } | |
1143 | + | |
1144 | + public int getGlobalVotesResponse(int ordinal) | |
1145 | + { | |
1146 | + | |
1147 | + String response = ""; | |
1148 | + int totalVotes = 0; | |
1149 | + | |
1150 | + switch(ordinal) | |
1151 | + { | |
1152 | + case 0: | |
1153 | + response = getResponse(getGlobalUrl(ordinal), ordinal); | |
1154 | + response = VoteUtil.between("\"getVotes\":",response,"}"); | |
1155 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1156 | + break; | |
1157 | + | |
1158 | + case 1: | |
1159 | + response = getResponse(getGlobalUrl(ordinal), ordinal); | |
1160 | + response = VoteUtil.between("server_votes\":",response.replace(" ", ""),",\"server_rank"); | |
1161 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1162 | + break; | |
1163 | + | |
1164 | + case 2: | |
1165 | + response = getResponse(getGlobalUrl(ordinal), ordinal); | |
1166 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1167 | + break; | |
1168 | + | |
1169 | + case 3: | |
1170 | + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal); | |
1171 | + response = VoteUtil.between("Votes:</th><th><a class='votes'>", response, "</a></th></tr><tr><th>Clicks:"); | |
1172 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1173 | + break; | |
1174 | + | |
1175 | + case 4: | |
1176 | + response = getResponse(getGlobalUrl(ordinal), ordinal); | |
1177 | + response = VoteUtil.between("\"totalvotes\":",response,",\"status_code\""); | |
1178 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1179 | + break; | |
1180 | + | |
1181 | + case 5: | |
1182 | + String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal),ordinal); | |
1183 | + totalVotes = (!"".equals(responseNetwork)) ? Integer.parseInt(responseNetwork) : -1; | |
1184 | + break; | |
1185 | + | |
1186 | + case 6: | |
1187 | + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal); | |
1188 | + response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>"); | |
1189 | + | |
1190 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1191 | + break; | |
1192 | + | |
1193 | + case 7: | |
1194 | + response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal); | |
1195 | + response = VoteUtil.between("nicas:</b> ", response, "<br /><br />"); | |
1196 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1197 | + break; | |
1198 | + | |
1199 | + case 8: | |
1200 | + response = getResponse(getGlobalUrl(ordinal), ordinal); | |
1201 | + response = VoteUtil.between("\"monthly_votes\":",response,"}}"); | |
1202 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1203 | + break; | |
1204 | + | |
1205 | + case 9: | |
1206 | + response = getResponse(getGlobalUrl(ordinal), ordinal); | |
1207 | + response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\""); | |
1208 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1209 | + break; | |
1210 | + | |
1211 | + case 10: | |
1212 | + response = getResponse(getGlobalUrl(ordinal), ordinal); | |
1213 | + totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1; | |
1214 | + break; | |
1215 | + } | |
1216 | + | |
1217 | + | |
1218 | + return totalVotes; | |
1219 | + } | |
1220 | + | |
1221 | + public static String getIndividualUrl(int ordinal,String ip,String AccountName) | |
1222 | + { | |
1223 | + String url = ""; | |
1224 | + ip = (Config.TEST_IP.equalsIgnoreCase("off") || Config.TEST_IP.equalsIgnoreCase("") ) ? ip : Config.TEST_IP; | |
1225 | + switch(ordinal) { | |
1226 | + case 0: | |
1227 | + //l2.topgameserver.net | |
1228 | + url = String.format("%sAPI_KEY=%s/getData/%s", Config.VOTE_LINK_TGS, Config.TGS_API_KEY,ip); | |
1229 | + break; | |
1230 | + | |
1231 | + case 1: | |
1232 | + //itopz.com | |
1233 | + url = String.format("%s%s/%s/%s", Config.VOTE_LINK_ITOPZ,Config.ITOPZ_API_KEY,Config.ITOPZ_SRV_ID,ip); | |
1234 | + break; | |
1235 | + | |
1236 | + case 2: | |
1237 | + //l2top.co | |
1238 | + url = String.format("%sVoteCheck.php?id=%s&ip=%s", Config.VOTE_LINK_TOP_CO,Config.TOP_CO_SRV_ID,ip); | |
1239 | + break; | |
1240 | + | |
1241 | + case 3: | |
1242 | + //l2votes.com | |
1243 | + url = String.format("%sapi.php?apiKey=%s&ip=%s", Config.VOTE_LINK_VTS,Config.VTS_API_KEY,ip); | |
1244 | + break; | |
1245 | + | |
1246 | + case 4: | |
1247 | + //hopzone.net | |
1248 | + url = String.format("%svote?token=%s&ip_address=%s",Config.VOTE_LINK_HZ,Config.HZ_API_KEY,ip); | |
1249 | + break; | |
1250 | + | |
1251 | + case 5: | |
1252 | + //l2network.eu | |
1253 | + url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_USER_NAME,ip); | |
1254 | + break; | |
1255 | + | |
1256 | + case 6: | |
1257 | + //l2topservers.com | |
1258 | + url = String.format("%stoken=%s&ip=%s", Config.VOTE_LINK_TSS,Config.TSS_API_TOKEN,ip); | |
1259 | + break; | |
1260 | + | |
1261 | + case 7: | |
1262 | + //top.l2jbrasil.com | |
1263 | + url = String.format("%susername=%s&ip=%s&type=json",Config.BRASIL_VOTE_LINK,Config.BRASIL_USER_NAME,ip); | |
1264 | + break; | |
1265 | + | |
1266 | + case 8: | |
1267 | + //mmotop | |
1268 | + url = String.format("%s%s/ip/%s", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY, ip); | |
1269 | + break; | |
1270 | + | |
1271 | + case 9: | |
1272 | + //topzone.com | |
1273 | + url = String.format("%svote?token=%s&ip=%s", Config.VOTE_LINK_TZ,Config.TZ_API_KEY,ip); | |
1274 | + break; | |
1275 | + | |
1276 | + case 10: | |
1277 | + //l2servers.com | |
1278 | + 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); | |
1279 | + break; | |
1280 | + } | |
1281 | + | |
1282 | + return url; | |
1283 | + } | |
1284 | + | |
1285 | + public String getGlobalUrl(int ordinal) | |
1286 | + { | |
1287 | + String url = ""; | |
1288 | + | |
1289 | + switch(ordinal) { | |
1290 | + case 0: | |
1291 | + //l2.topgameserver.net | |
1292 | + url = String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS, Config.TGS_API_KEY); | |
1293 | + break; | |
1294 | + | |
1295 | + case 1: | |
1296 | + //itopz.com | |
1297 | + url = String.format("%s%s/%s", Config.VOTE_LINK_ITOPZ,Config.ITOPZ_API_KEY,Config.ITOPZ_SRV_ID); | |
1298 | + break; | |
1299 | + | |
1300 | + case 2: | |
1301 | + //l2top.co | |
1302 | + url = String.format("%sVoteCheck_Total.php?id=%s", Config.VOTE_LINK_TOP_CO,Config.TOP_CO_SRV_ID); | |
1303 | + break; | |
1304 | + | |
1305 | + case 3: | |
1306 | + //l2votes.com | |
1307 | + url = String.format("%sserverPage.php?sid=%s",Config.VOTE_LINK_VTS,Config.VTS_SID); | |
1308 | + break; | |
1309 | + | |
1310 | + case 4: | |
1311 | + //hopzone.net | |
1312 | + url = String.format("%svotes?token=%s", Config.VOTE_LINK_HZ,Config.HZ_API_KEY); | |
1313 | + break; | |
1314 | + | |
1315 | + case 5: | |
1316 | + //l2network.eu | |
1317 | + url = String.format("apiKey=%s&type=%s&player=",Config.VOTE_NETWORK_API_KEY,1); | |
1318 | + break; | |
1319 | + | |
1320 | + case 6: | |
1321 | + //l2topservers | |
1322 | + url = String.format("https://l2topservers.com/l2top/%s/%s", Config.TS_SRV_ID,Config.TS_DOMAIN_NAME); | |
1323 | + break; | |
1324 | + | |
1325 | + case 7: | |
1326 | + //top.l2jbrasil.com | |
1327 | + url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s",Config.BRASIL_USER_NAME); | |
1328 | + break; | |
1329 | + | |
1330 | + case 8: | |
1331 | + //mmotop.eu/l2/ | |
1332 | + url = String.format("%s%s/info/", Config.VOTE_LINK_MMOTOP,Config.MMOTOP_API_KEY); | |
1333 | + break; | |
1334 | + | |
1335 | + case 9: | |
1336 | + //l2topzone.com | |
1337 | + url = String.format("%sserver_%s/getServerData", Config.VOTE_LINK_TZ,Config.TZ_API_KEY); | |
1338 | + break; | |
1339 | + | |
1340 | + case 10: | |
1341 | + //l2servers.com | |
1342 | + url = String.format("%syearlyvotes.php?server_id=%s", Config.VOTE_LINK_SERVERS,Config.SERVERS_SRV_ID); | |
1343 | + break; | |
1344 | + } | |
1345 | + | |
1346 | + return url; | |
1347 | + } | |
1348 | +} | |
1349 | \ No newline at end of file | |
1350 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Handler/voteManager.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Handler/voteManager.java | |
1351 | new file mode 100644 | |
1352 | index 0000000..aec398b | |
1353 | --- /dev/null | |
1354 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Handler/voteManager.java | |
1355 | @@ -0,0 +1,328 @@ | |
1356 | +package net.sf.l2j.gameserver.votesystem.Handler; | |
1357 | + | |
1358 | +import java.util.HashSet; | |
1359 | +import java.util.Map; | |
1360 | +import java.util.concurrent.ConcurrentHashMap; | |
1361 | +import java.util.concurrent.ScheduledFuture; | |
1362 | + | |
1363 | +import net.sf.l2j.Config; | |
1364 | +import net.sf.l2j.commons.concurrent.ThreadPool; | |
1365 | +import net.sf.l2j.gameserver.model.World; | |
1366 | +import net.sf.l2j.gameserver.model.actor.Player; | |
1367 | +import net.sf.l2j.gameserver.network.GameClient; | |
1368 | +import net.sf.l2j.gameserver.network.SystemMessageId; | |
1369 | +import net.sf.l2j.gameserver.network.serverpackets.ItemList; | |
1370 | +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage; | |
1371 | +import net.sf.l2j.gameserver.votesystem.DB.globalVoteDB; | |
1372 | +import net.sf.l2j.gameserver.votesystem.DB.individualVoteDB; | |
1373 | +import net.sf.l2j.gameserver.votesystem.Enum.voteSite; | |
1374 | +import net.sf.l2j.gameserver.votesystem.Model.Reward; | |
1375 | +import net.sf.l2j.gameserver.votesystem.Model.globalVote; | |
1376 | +import net.sf.l2j.gameserver.votesystem.Model.individualVote; | |
1377 | +import net.sf.l2j.gameserver.votesystem.Model.individualVoteResponse; | |
1378 | +import net.sf.l2j.gameserver.votesystem.VoteUtil.VoteSiteXml; | |
1379 | +import net.sf.l2j.gameserver.votesystem.VoteUtil.VoteUtil; | |
1380 | + | |
1381 | +/** | |
1382 | + * @author l2.topgameserver.net | |
1383 | + * | |
1384 | + */ | |
1385 | +public final class voteManager extends voteHandler{ | |
1386 | + private ScheduledFuture<?> _saveGlobalVotes; | |
1387 | + private ScheduledFuture<?> _updateIndividualVotes; | |
1388 | + private ScheduledFuture<?> _autoGlobalVotesReward; | |
1389 | + | |
1390 | + private HashSet<individualVote> _votes; | |
1391 | + private Map<String,individualVote[]> _foundVoters; | |
1392 | + private globalVote[] _globalVotes = new globalVote[voteSite.values().length]; | |
1393 | + | |
1394 | + public voteManager() { | |
1395 | + _foundVoters = new ConcurrentHashMap<>(); | |
1396 | + loadVotes(); | |
1397 | + loadGlobalVotes(); | |
1398 | + checkAllResponseGlobalVotes(); | |
1399 | + stopAutoTasks(); | |
1400 | + | |
1401 | + if(Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM) { | |
1402 | + _updateIndividualVotes = ThreadPool.scheduleAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES); | |
1403 | + } | |
1404 | + if(Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM) { | |
1405 | + _autoGlobalVotesReward = ThreadPool.scheduleAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD); | |
1406 | + _saveGlobalVotes = ThreadPool.scheduleAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE); | |
1407 | + } | |
1408 | + } | |
1409 | + | |
1410 | + private void stopAutoTasks() { | |
1411 | + if(_saveGlobalVotes != null) { | |
1412 | + _saveGlobalVotes.cancel(true); | |
1413 | + _saveGlobalVotes = null; | |
1414 | + } | |
1415 | + if(_updateIndividualVotes != null) { | |
1416 | + _updateIndividualVotes.cancel(true); | |
1417 | + _updateIndividualVotes = null; | |
1418 | + } | |
1419 | + if(_autoGlobalVotesReward != null) { | |
1420 | + _autoGlobalVotesReward.cancel(true); | |
1421 | + _autoGlobalVotesReward = null; | |
1422 | + } | |
1423 | + } | |
1424 | + | |
1425 | + public void getReward(Player player, int ordinalSite) { | |
1426 | + String ip = existIp(player); | |
1427 | + if(ip == null) { | |
1428 | + return; | |
1429 | + } | |
1430 | + individualVoteResponse ivr = getIndividualVoteResponse(ordinalSite,ip,player.getAccountName()); | |
1431 | + if(ivr == null) { | |
1432 | + player.sendMessage("We were unable to verify your vote with: "+VoteSiteXml.getInstance().getSiteName(ordinalSite)+", please try again"); | |
1433 | + return; | |
1434 | + } | |
1435 | + | |
1436 | + if (getTimeRemaining(new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false)) < 0) | |
1437 | + { | |
1438 | + player.sendMessage("We were unable to verify your vote with: " + VoteSiteXml.getInstance().getSiteName(ordinalSite) + ", please try again"); | |
1439 | + return; | |
1440 | + } | |
1441 | + if(!ivr.getIsVoted()) { | |
1442 | + player.sendMessage(String.format("You haven't vote on %s yet!", VoteSiteXml.getInstance().getSiteName(ordinalSite))); | |
1443 | + return; | |
1444 | + } | |
1445 | + if(!checkIndividualAvailableVote(player,ordinalSite)) { | |
1446 | + player.sendMessage(String.format("You can get the reward again on %s at %s", VoteSiteXml.getInstance().getSiteName(ordinalSite),getTimeRemainingWithSampleFormat(player,ordinalSite))); | |
1447 | + return; | |
1448 | + } | |
1449 | + individualVote iv = new individualVote(ip,ivr.getDiffTime(),ivr.getVoteSiteTime(),ordinalSite,false); | |
1450 | + | |
1451 | + individualVote[] aiv; | |
1452 | + if(!_foundVoters.containsKey(ip)) { | |
1453 | + aiv = new individualVote[voteSite.values().length]; | |
1454 | + iv.setAlreadyRewarded(true); | |
1455 | + aiv[ordinalSite] = iv; | |
1456 | + _foundVoters.put(ip, aiv); | |
1457 | + for(Reward reward : VoteSiteXml.getInstance().getRewards(ordinalSite)) { | |
1458 | + player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null); | |
1459 | + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount())); | |
1460 | + } | |
1461 | + player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite))); | |
1462 | + player.sendPacket(new ItemList(player, true)); | |
1463 | + }else { | |
1464 | + aiv = _foundVoters.get(ip); | |
1465 | + iv.setAlreadyRewarded(true); | |
1466 | + aiv[ordinalSite] = iv; | |
1467 | + _foundVoters.replace(ip, aiv); | |
1468 | + for(Reward reward : VoteSiteXml.getInstance().getRewards(ordinalSite)) { | |
1469 | + player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null); | |
1470 | + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount())); | |
1471 | + } | |
1472 | + player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite))); | |
1473 | + player.sendPacket(new ItemList(player, true)); | |
1474 | + } | |
1475 | + } | |
1476 | + | |
1477 | + public boolean checkIndividualAvailableVote(Player player, int ordinalSite) { | |
1478 | + String ip = existIp(player); | |
1479 | + if(_foundVoters.containsKey(ip)) { | |
1480 | + individualVote[] ivs=_foundVoters.get(ip); | |
1481 | + if(ivs[ordinalSite] == null) { | |
1482 | + return true; | |
1483 | + } | |
1484 | + if(ivs[ordinalSite] != null) { | |
1485 | + individualVote iv = ivs[ordinalSite]; | |
1486 | + if(getTimeRemaining(iv)<0) { | |
1487 | + return true; | |
1488 | + } | |
1489 | + } | |
1490 | + }else { | |
1491 | + return true; | |
1492 | + } | |
1493 | + | |
1494 | + return false; | |
1495 | + } | |
1496 | + | |
1497 | + public long getTimeRemaining(individualVote iv) | |
1498 | + { | |
1499 | + long timeRemaining = 0L; | |
1500 | + timeRemaining = ((iv.getVotingTimeSite() + Config.INTERVAL_TO_NEXT_VOTE) - ((iv.getDiffTime() > 0) ? (System.currentTimeMillis() + iv.getDiffTime()) : (System.currentTimeMillis() - iv.getDiffTime()))); | |
1501 | + return timeRemaining; | |
1502 | + } | |
1503 | + | |
1504 | + public String getTimeRemainingWithSampleFormat(Player player, int ordinalSite) { | |
1505 | + String ip = existIp(player); | |
1506 | + String timeRemainingWithSampleFormat =""; | |
1507 | + if(_foundVoters.containsKey(ip)) { | |
1508 | + individualVote[] ivs=_foundVoters.get(ip); | |
1509 | + if(ivs[ordinalSite] != null) { | |
1510 | + individualVote iv = ivs[ordinalSite]; | |
1511 | + long timeRemaining = getTimeRemaining(iv); | |
1512 | + if(timeRemaining>0) { | |
1513 | + timeRemainingWithSampleFormat = CalculateTimeRemainingWithSampleDateFormat(timeRemaining); | |
1514 | + return timeRemainingWithSampleFormat; | |
1515 | + } | |
1516 | + } | |
1517 | + } | |
1518 | + return timeRemainingWithSampleFormat; | |
1519 | + } | |
1520 | + | |
1521 | + public String CalculateTimeRemainingWithSampleDateFormat(long timeRemaining) { | |
1522 | + long t = timeRemaining/1000; | |
1523 | + int hours = Math.round((t/3600%24)); | |
1524 | + int minutes = Math.round((t/60)%60); | |
1525 | + int seconds = Math.round(t%60); | |
1526 | + return String.format("%sH:%sm:%ss", hours,minutes,seconds); | |
1527 | + } | |
1528 | + | |
1529 | + public String existIp(Player p) { | |
1530 | + | |
1531 | + GameClient client = p.getClient(); | |
1532 | + if(client.getConnection() != null && client.getPlayer() != null && !client.isDetached()) { | |
1533 | + try | |
1534 | + { | |
1535 | + return client.getConnection().getInetAddress().getHostAddress(); | |
1536 | + } | |
1537 | + catch (Exception e) | |
1538 | + { | |
1539 | + e.printStackTrace(); | |
1540 | + } | |
1541 | + } | |
1542 | + return null; | |
1543 | + | |
1544 | + } | |
1545 | + | |
1546 | + public final void loadVotes() { | |
1547 | + _foundVoters = individualVoteDB.getInstance().getVotesDB(); | |
1548 | + } | |
1549 | + protected void loadGlobalVotes(){ | |
1550 | + _globalVotes = globalVoteDB.getInstance().getGlobalVotes(); | |
1551 | + } | |
1552 | + public void saveVotes() { | |
1553 | + individualVoteDB.getInstance().SaveVotes(_foundVoters); | |
1554 | + } | |
1555 | + | |
1556 | + protected void AutoGlobalVoteReward() { | |
1557 | + HashSet<String> ipList = new HashSet<>(); | |
1558 | + for(voteSite vs : voteSite.values()) { | |
1559 | + | |
1560 | + new Thread(() -> { | |
1561 | + checkNewUpdate(vs.ordinal()); | |
1562 | + if(_globalVotes[vs.ordinal()].getCurrentVotes() >= _globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25*Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) { | |
1563 | + _globalVotes[vs.ordinal()].setVotesLastReward(_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25*Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)); | |
1564 | + for(Player player : World.getInstance().getPlayers()) { | |
1565 | + String ip = existIp(player); | |
1566 | + if(ip == null) { | |
1567 | + continue; | |
1568 | + } | |
1569 | + if(ipList.contains(ip)) { | |
1570 | + continue; | |
1571 | + } | |
1572 | + for(Reward reward : VoteSiteXml.getInstance().getRewards(11)) { | |
1573 | + player.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), player, null); | |
1574 | + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount())); | |
1575 | + } | |
1576 | + ipList.add(ip); | |
1577 | + player.sendPacket(new ItemList(player, true)); | |
1578 | + } | |
1579 | + World.announceToOnlinePlayers(VoteUtil.Sites[vs.ordinal()]+": All players has been rewarded, please check your inventory", true); | |
1580 | + }else { | |
1581 | + String encourage =""; | |
1582 | + int nextReward = _globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25*Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD); | |
1583 | + 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() ); | |
1584 | + World.announceToOnlinePlayers(encourage, true); | |
1585 | + } | |
1586 | + }).start(); | |
1587 | + | |
1588 | + } | |
1589 | + } | |
1590 | + | |
1591 | + protected void AutoSaveGlobalVotes() { | |
1592 | + globalVoteDB.getInstance().saveGlobalVotes(_globalVotes); | |
1593 | + } | |
1594 | + | |
1595 | + protected synchronized void AutoUpdateIndividualVotes() { | |
1596 | + AutoCleanInnecesaryIndividualVotes(); | |
1597 | + individualVoteDB.getInstance().SaveVotes(_foundVoters); | |
1598 | + } | |
1599 | + | |
1600 | + protected synchronized void AutoCleanInnecesaryIndividualVotes() { | |
1601 | + HashSet<individualVote> removeVotes= new HashSet<>(); | |
1602 | + for(Map.Entry<String, individualVote[]> ivs : _foundVoters.entrySet()) { | |
1603 | + for(individualVote individualvote : ivs.getValue()) { | |
1604 | + if(individualvote == null) | |
1605 | + continue; | |
1606 | + if(getTimeRemaining(individualvote) < 0) { | |
1607 | + removeVotes.add(individualvote); | |
1608 | + if(_foundVoters.containsKey(individualvote.getVoterIp())) { | |
1609 | + if(_foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] != null) { | |
1610 | + _foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] = null; | |
1611 | + } | |
1612 | + } | |
1613 | + } | |
1614 | + } | |
1615 | + } | |
1616 | + individualVoteDB.getInstance().DeleteVotes(removeVotes); | |
1617 | + } | |
1618 | + | |
1619 | + public void checkAllResponseGlobalVotes() { | |
1620 | + for(voteSite vs : voteSite.values()) { | |
1621 | + new Thread(()-> { | |
1622 | + checkNewUpdate(vs.ordinal()); | |
1623 | + }); | |
1624 | + } | |
1625 | + } | |
1626 | + | |
1627 | + public void checkNewUpdate(int ordinalSite) { | |
1628 | + int globalVotesResponse = getGlobalVotesResponse(ordinalSite); | |
1629 | + if(globalVotesResponse == -1) { | |
1630 | + return; | |
1631 | + } | |
1632 | + _globalVotes[ordinalSite].setCurrentVotes(globalVotesResponse); | |
1633 | + int last = globalVotesResponse - (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD); | |
1634 | + if(last <0 ) { | |
1635 | + _globalVotes[ordinalSite].setVotesLastReward(0); | |
1636 | + return; | |
1637 | + } | |
1638 | + if((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) < globalVotesResponse) { | |
1639 | + _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse); | |
1640 | + return; | |
1641 | + } | |
1642 | + } | |
1643 | + | |
1644 | + public void Shutdown() { | |
1645 | + AutoSaveGlobalVotes(); | |
1646 | + AutoCleanInnecesaryIndividualVotes(); | |
1647 | + AutoUpdateIndividualVotes(); | |
1648 | + } | |
1649 | + | |
1650 | + protected class AutoGlobalVoteRewardTask implements Runnable { | |
1651 | + | |
1652 | + @Override | |
1653 | + public void run() | |
1654 | + { | |
1655 | + AutoGlobalVoteReward(); | |
1656 | + | |
1657 | + } | |
1658 | + | |
1659 | + } | |
1660 | + | |
1661 | + protected class AutoSaveGlobalVotesTask implements Runnable { | |
1662 | + | |
1663 | + @Override | |
1664 | + public void run() | |
1665 | + { | |
1666 | + AutoSaveGlobalVotes(); | |
1667 | + | |
1668 | + } | |
1669 | + | |
1670 | + } | |
1671 | + | |
1672 | + protected class AutoUpdateIndividualVotesTask implements Runnable { | |
1673 | + | |
1674 | + @Override | |
1675 | + public void run() | |
1676 | + { | |
1677 | + AutoUpdateIndividualVotes(); | |
1678 | + | |
1679 | + } | |
1680 | + | |
1681 | + } | |
1682 | + | |
1683 | + public static voteManager getInatance() { | |
1684 | + return SingleHolder.INSTANCE; | |
1685 | + } | |
1686 | + | |
1687 | + private static class SingleHolder { | |
1688 | + protected static final voteManager INSTANCE = new voteManager(); | |
1689 | + } | |
1690 | +} | |
1691 | \ No newline at end of file | |
1692 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/Reward.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/Reward.java | |
1693 | new file mode 100644 | |
1694 | index 0000000..2ca11e8 | |
1695 | --- /dev/null | |
1696 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/Reward.java | |
1697 | @@ -0,0 +1,33 @@ | |
1698 | +package net.sf.l2j.gameserver.votesystem.Model; | |
1699 | + | |
1700 | + | |
1701 | +import net.sf.l2j.commons.util.StatsSet; | |
1702 | + | |
1703 | +/** | |
1704 | + * @author l2.topgameserver.net | |
1705 | + * | |
1706 | + */ | |
1707 | +public class Reward | |
1708 | +{ | |
1709 | + private int _itemId; | |
1710 | + private int _itemCount; | |
1711 | + | |
1712 | + public Reward(StatsSet set) | |
1713 | + { | |
1714 | + _itemId = set.getInteger("itemId"); | |
1715 | + _itemCount = set.getInteger("itemCount"); | |
1716 | + } | |
1717 | + | |
1718 | + public void setItemId(int itemId) { | |
1719 | + _itemId = itemId; | |
1720 | + } | |
1721 | + public void setItemCount(int itemCount) { | |
1722 | + _itemCount = itemCount; | |
1723 | + } | |
1724 | + public int getItemId() { | |
1725 | + return _itemId; | |
1726 | + } | |
1727 | + public int getItemCount() { | |
1728 | + return _itemCount; | |
1729 | + } | |
1730 | +} | |
1731 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/VoteSite.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/VoteSite.java | |
1732 | new file mode 100644 | |
1733 | index 0000000..e2c23ac | |
1734 | --- /dev/null | |
1735 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/VoteSite.java | |
1736 | @@ -0,0 +1,38 @@ | |
1737 | +package net.sf.l2j.gameserver.votesystem.Model; | |
1738 | + | |
1739 | +import java.util.ArrayList; | |
1740 | +import java.util.List; | |
1741 | + | |
1742 | +/** | |
1743 | + * @author l2.topgameserver.net | |
1744 | + * | |
1745 | + */ | |
1746 | +public class VoteSite | |
1747 | +{ | |
1748 | + private int _siteOrdinal; | |
1749 | + private String _siteName; | |
1750 | + private List<Reward> _rewards = new ArrayList<>(); | |
1751 | + public VoteSite() { | |
1752 | + | |
1753 | + } | |
1754 | + public void setSiteOrdinal(int siteOrdinal) { | |
1755 | + _siteOrdinal = siteOrdinal; | |
1756 | + } | |
1757 | + public void setSiteName(String siteName) { | |
1758 | + _siteName = siteName; | |
1759 | + } | |
1760 | + public void setRewardList(List<Reward> rewards) { | |
1761 | + for(Reward r : rewards) | |
1762 | + _rewards.add(r); | |
1763 | + } | |
1764 | + public int getSiteOrdinal() { | |
1765 | + return _siteOrdinal; | |
1766 | + } | |
1767 | + public String getSiteName() { | |
1768 | + return _siteName; | |
1769 | + } | |
1770 | + public List<Reward> getRewardList(){ | |
1771 | + return _rewards; | |
1772 | + } | |
1773 | + | |
1774 | +} | |
1775 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/globalVote.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/globalVote.java | |
1776 | new file mode 100644 | |
1777 | index 0000000..ca5d979 | |
1778 | --- /dev/null | |
1779 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/globalVote.java | |
1780 | @@ -0,0 +1,45 @@ | |
1781 | +package net.sf.l2j.gameserver.votesystem.Model; | |
1782 | + | |
1783 | +/** | |
1784 | + * @author l2.topgameserver.net | |
1785 | + * | |
1786 | + */ | |
1787 | +public class globalVote | |
1788 | +{ | |
1789 | + private int _voteSite; | |
1790 | + private int _votesLastReward; | |
1791 | + private int _currentVotes; | |
1792 | + public globalVote() { | |
1793 | + | |
1794 | + } | |
1795 | + | |
1796 | + public globalVote(int voteSite, int votesLastReward) { | |
1797 | + _voteSite = voteSite; | |
1798 | + _votesLastReward = votesLastReward; | |
1799 | + } | |
1800 | + | |
1801 | + public void setVoteSite(int voteSite) { | |
1802 | + _voteSite = voteSite; | |
1803 | + } | |
1804 | + | |
1805 | + public void setVotesLastReward(int votesLastReward) { | |
1806 | + _votesLastReward = votesLastReward; | |
1807 | + } | |
1808 | + | |
1809 | + public void setCurrentVotes(int currentVotes) { | |
1810 | + _currentVotes = currentVotes; | |
1811 | + } | |
1812 | + | |
1813 | + public int getVoyeSite() { | |
1814 | + return _voteSite; | |
1815 | + } | |
1816 | + | |
1817 | + public int getVotesLastReward() { | |
1818 | + return _votesLastReward; | |
1819 | + } | |
1820 | + | |
1821 | + public int getCurrentVotes() { | |
1822 | + return _currentVotes; | |
1823 | + } | |
1824 | + | |
1825 | +} | |
1826 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/individualVote.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/individualVote.java | |
1827 | new file mode 100644 | |
1828 | index 0000000..7d24d7f | |
1829 | --- /dev/null | |
1830 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/individualVote.java | |
1831 | @@ -0,0 +1,69 @@ | |
1832 | +package net.sf.l2j.gameserver.votesystem.Model; | |
1833 | + | |
1834 | + | |
1835 | +/** | |
1836 | + * @author l2.topgameserver.net | |
1837 | + * | |
1838 | + */ | |
1839 | +public class individualVote | |
1840 | +{ | |
1841 | + private String _voterIp; | |
1842 | + private long _diffTime; | |
1843 | + private long _votingTimeSite; | |
1844 | + private int _voteSite; | |
1845 | + private boolean _alreadyRewarded; | |
1846 | + | |
1847 | + | |
1848 | + public individualVote(String voterIp, long diffTime, long votingTimeSite, int voteSite, boolean alreadyRewarded){ | |
1849 | + _voterIp = voterIp; | |
1850 | + _diffTime = diffTime; | |
1851 | + _votingTimeSite = votingTimeSite; | |
1852 | + _voteSite = voteSite; | |
1853 | + _alreadyRewarded = alreadyRewarded; | |
1854 | + } | |
1855 | + | |
1856 | + public individualVote(){ | |
1857 | + | |
1858 | + } | |
1859 | + | |
1860 | + public void setVoterIp(String voterIp) { | |
1861 | + _voterIp = voterIp; | |
1862 | + } | |
1863 | + | |
1864 | + public void setDiffTime(long diffTime) { | |
1865 | + _diffTime = diffTime; | |
1866 | + } | |
1867 | + | |
1868 | + public void setVotingTimeSite(long votingTimeSite) { | |
1869 | + _votingTimeSite = votingTimeSite; | |
1870 | + } | |
1871 | + | |
1872 | + public void setVoteSite(int voteSite) { | |
1873 | + _voteSite = voteSite; | |
1874 | + } | |
1875 | + | |
1876 | + public void setAlreadyRewarded(boolean alreadyRewarded) { | |
1877 | + _alreadyRewarded = alreadyRewarded; | |
1878 | + } | |
1879 | + | |
1880 | + public String getVoterIp() { | |
1881 | + return _voterIp; | |
1882 | + } | |
1883 | + | |
1884 | + public long getDiffTime() { | |
1885 | + return _diffTime; | |
1886 | + } | |
1887 | + | |
1888 | + public long getVotingTimeSite() { | |
1889 | + return _votingTimeSite; | |
1890 | + } | |
1891 | + | |
1892 | + public int getVoteSite() { | |
1893 | + return _voteSite; | |
1894 | + } | |
1895 | + | |
1896 | + public boolean getAlreadyRewarded() { | |
1897 | + return _alreadyRewarded; | |
1898 | + } | |
1899 | + | |
1900 | +} | |
1901 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/individualVoteResponse.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/individualVoteResponse.java | |
1902 | new file mode 100644 | |
1903 | index 0000000..14b7625 | |
1904 | --- /dev/null | |
1905 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/Model/individualVoteResponse.java | |
1906 | @@ -0,0 +1,36 @@ | |
1907 | +package net.sf.l2j.gameserver.votesystem.Model; | |
1908 | + | |
1909 | +/** | |
1910 | + * @author l2.topgameserver.net | |
1911 | + * | |
1912 | + */ | |
1913 | +public class individualVoteResponse | |
1914 | +{ | |
1915 | + private boolean _isVoted; | |
1916 | + private long _diffTime; | |
1917 | + private long _voteSiteTime; | |
1918 | + | |
1919 | + public individualVoteResponse() { | |
1920 | + | |
1921 | + } | |
1922 | + | |
1923 | + public void setIsVoted(boolean isVoted) { | |
1924 | + _isVoted = isVoted; | |
1925 | + } | |
1926 | + public void setDiffTime(long diffTime) { | |
1927 | + _diffTime = diffTime; | |
1928 | + } | |
1929 | + public void setVoteSiteTime(long voteSiteTime) { | |
1930 | + _voteSiteTime = voteSiteTime; | |
1931 | + } | |
1932 | + | |
1933 | + public boolean getIsVoted() { | |
1934 | + return _isVoted; | |
1935 | + } | |
1936 | + public long getDiffTime() { | |
1937 | + return _diffTime; | |
1938 | + } | |
1939 | + public long getVoteSiteTime() { | |
1940 | + return _voteSiteTime; | |
1941 | + } | |
1942 | +} | |
1943 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/VoteUtil/VoteSiteXml.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/VoteUtil/VoteSiteXml.java | |
1944 | new file mode 100644 | |
1945 | index 0000000..d943fb8 | |
1946 | --- /dev/null | |
1947 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/VoteUtil/VoteSiteXml.java | |
1948 | @@ -0,0 +1,69 @@ | |
1949 | +package net.sf.l2j.gameserver.votesystem.VoteUtil; | |
1950 | + | |
1951 | +import java.nio.file.Path; | |
1952 | +import java.util.Collection; | |
1953 | +import java.util.HashMap; | |
1954 | +import java.util.Map; | |
1955 | + | |
1956 | +import net.sf.l2j.commons.data.xml.IXmlReader; | |
1957 | +import net.sf.l2j.gameserver.votesystem.Model.Reward; | |
1958 | +import net.sf.l2j.gameserver.votesystem.Model.VoteSite; | |
1959 | + | |
1960 | +import org.w3c.dom.Document; | |
1961 | +import org.w3c.dom.NamedNodeMap; | |
1962 | + | |
1963 | +/** | |
1964 | + * @author l2.topgameserver.net | |
1965 | + * | |
1966 | + */ | |
1967 | +public class VoteSiteXml implements IXmlReader | |
1968 | +{ | |
1969 | + | |
1970 | + private final Map<Integer,VoteSite> _voteSites = new HashMap<>(); | |
1971 | + | |
1972 | + protected VoteSiteXml() { | |
1973 | + load(); | |
1974 | + } | |
1975 | + | |
1976 | + @Override | |
1977 | + public void load() | |
1978 | + { | |
1979 | + parseFile("./data/xml/votesystem.xml"); | |
1980 | + LOGGER.info("Loaded {} reward sites", _voteSites.size()); | |
1981 | + } | |
1982 | + | |
1983 | + | |
1984 | + @Override | |
1985 | + public void parseDocument(Document doc, Path path) | |
1986 | + { | |
1987 | + forEach(doc, "list", listNode -> { | |
1988 | + forEach(listNode, "votesite", votesiteNode -> { | |
1989 | + final VoteSite votesite = new VoteSite(); | |
1990 | + final NamedNodeMap attrs = votesiteNode.getAttributes(); | |
1991 | + votesite.setSiteOrdinal(parseInteger(attrs,"ordinal")); | |
1992 | + votesite.setSiteName(parseString(attrs,"name")); | |
1993 | + forEach(votesiteNode,"items", itemsNode -> forEach(itemsNode,"item",itemNode -> votesite.getRewardList().add(new Reward(parseAttributes(itemNode))))); | |
1994 | + _voteSites.put(votesite.getSiteOrdinal(),votesite); | |
1995 | + }); | |
1996 | + }); | |
1997 | + } | |
1998 | + | |
1999 | + public String getSiteName(int ordinal) { | |
2000 | + return _voteSites.get(ordinal).getSiteName(); | |
2001 | + } | |
2002 | + | |
2003 | + public Collection<Reward> getRewards(int ordinal){ | |
2004 | + return _voteSites.get(ordinal).getRewardList(); | |
2005 | + } | |
2006 | + | |
2007 | + public static final VoteSiteXml getInstance() | |
2008 | + { | |
2009 | + return SingletonHolder.INSTANCE; | |
2010 | + } | |
2011 | + | |
2012 | + private static final class SingletonHolder | |
2013 | + { | |
2014 | + protected static final VoteSiteXml INSTANCE = new VoteSiteXml(); | |
2015 | + } | |
2016 | + | |
2017 | +} | |
2018 | diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/VoteUtil/VoteUtil.java b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/VoteUtil/VoteUtil.java | |
2019 | new file mode 100644 | |
2020 | index 0000000..a555b85 | |
2021 | --- /dev/null | |
2022 | +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/votesystem/VoteUtil/VoteUtil.java | |
2023 | @@ -0,0 +1,132 @@ | |
2024 | +package net.sf.l2j.gameserver.votesystem.VoteUtil; | |
2025 | + | |
2026 | +import java.io.BufferedReader; | |
2027 | +import java.io.InputStreamReader; | |
2028 | +import java.net.HttpURLConnection; | |
2029 | +import java.net.URL; | |
2030 | +import java.time.LocalDateTime; | |
2031 | +import java.time.ZoneId; | |
2032 | +import java.time.ZonedDateTime; | |
2033 | + | |
2034 | +import net.sf.l2j.commons.logging.CLogger; | |
2035 | + | |
2036 | + | |
2037 | +/** | |
2038 | + * @author l2.topgameserver.net | |
2039 | + * | |
2040 | + */ | |
2041 | +public final class VoteUtil | |
2042 | +{ | |
2043 | + public static final CLogger LOGGER = new CLogger(VoteUtil.class.getName()); | |
2044 | + | |
2045 | + private static String voteTimeZones[] = { | |
2046 | + "topgameserver.net=Europe/Berlin", | |
2047 | + "itopz.com=America/New_York", | |
2048 | + "l2top.co=Europe/London", | |
2049 | + "l2votes.com=GMT", | |
2050 | + "hopzone.net=Europe/Athens", | |
2051 | + "l2network.eu=America/Chicago", | |
2052 | + "l2topservers.com=Europe/Athens", | |
2053 | + "top.l2jbrasil.com=America/Sao_Paulo", | |
2054 | + "mmotop.eu=America/Chicago", | |
2055 | + "l2topzone.com=America/Chicago", | |
2056 | + "l2servers.com=America/Chicago", | |
2057 | + }; | |
2058 | + | |
2059 | + public static final long getTimeVotingSite(int ordinalSite) { | |
2060 | + LocalDateTime ldt = LocalDateTime.now(ZoneId.of(voteTimeZones[ordinalSite].split("=")[1])); | |
2061 | + ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault()); | |
2062 | + long millis = zdt.toInstant().toEpochMilli(); | |
2063 | + return millis; | |
2064 | + } | |
2065 | + | |
2066 | + public static final String Sites[] = | |
2067 | + { | |
2068 | + "L2.TopGameServer.net", | |
2069 | + "ITopZ.com", | |
2070 | + "L2Top.co", | |
2071 | + "L2Votes.com", | |
2072 | + "L2.Hopzone.net", | |
2073 | + "L2Network.eu", | |
2074 | + "L2TopServers.com", | |
2075 | + "top.l2jbrasil.com", | |
2076 | + "MMOTOP.eu", | |
2077 | + "L2Topzone.com", | |
2078 | + "L2Servers.com" | |
2079 | + }; | |
2080 | + | |
2081 | + public static final String getResponse(String Url, int ordinal) | |
2082 | + { | |
2083 | + | |
2084 | + try | |
2085 | + { | |
2086 | + int responseCode = 0; | |
2087 | + URL objUrl = new URL(Url); | |
2088 | + HttpURLConnection con = (HttpURLConnection) objUrl.openConnection(); | |
2089 | + con.setRequestMethod("GET"); | |
2090 | + con.setRequestProperty("User-Agent", "Mozilla/5.0"); | |
2091 | + con.setConnectTimeout(5000); | |
2092 | + responseCode = con.getResponseCode(); | |
2093 | + if (responseCode == HttpURLConnection.HTTP_OK) { | |
2094 | + | |
2095 | + String inputLine; | |
2096 | + StringBuffer response = new StringBuffer(); | |
2097 | + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); | |
2098 | + while ((inputLine = in.readLine()) != null) { | |
2099 | + if(ordinal == 3) { | |
2100 | + if(inputLine.contains("Votes:")) { | |
2101 | + response.append(inputLine); | |
2102 | + break; | |
2103 | + } | |
2104 | + } | |
2105 | + if(ordinal == 7){ | |
2106 | + if(inputLine.contains("<b>Entradas ")) { | |
2107 | + response.append(inputLine); | |
2108 | + break; | |
2109 | + } | |
2110 | + } | |
2111 | + } | |
2112 | + in.close(); | |
2113 | + return response.toString(); | |
2114 | + } | |
2115 | + | |
2116 | + } | |
2117 | + catch (Exception e) | |
2118 | + { | |
2119 | + LOGGER.error(VoteUtil.Sites[ordinal]+ " Say: An error ocurred ", e.getMessage()); | |
2120 | + return ""; | |
2121 | + } | |
2122 | + | |
2123 | + return ""; | |
2124 | + } | |
2125 | + | |
2126 | + public static final String between(String p1, String str, String p2){ | |
2127 | + String returnValue = ""; | |
2128 | + int i1 = str.indexOf(p1); | |
2129 | + int i2 = str.indexOf(p2); | |
2130 | + if(i1 != -1 && i2 != -1){ | |
2131 | + i1 = i1+p1.length(); | |
2132 | + returnValue = str.substring(i1,i2); | |
2133 | + } | |
2134 | + return returnValue; | |
2135 | + } | |
2136 | + | |
2137 | + public static void goToVoteSite(String urlSiiteVotation) { | |
2138 | + /*try | |
2139 | + { | |
2140 | + URL url = new URL(urlSiiteVotation); | |
2141 | + try | |
2142 | + { | |
2143 | + Desktop.getDesktop().browse(url.toURI()); | |
2144 | + } | |
2145 | + catch (IOException | URISyntaxException e) | |
2146 | + { | |
2147 | + e.printStackTrace(); | |
2148 | + } | |
2149 | + } | |
2150 | + catch (MalformedURLException e) | |
2151 | + { | |
2152 | + e.printStackTrace(); | |
2153 | + }*/ | |
2154 | + } | |
2155 | +} | |
2156 | ||
2157 | ||
2158 | ==============================================DATAPACK======================================= | |
2159 | ||
2160 | diff --git a/aCis_datapack/data/html/mods/votesystem/100005.html b/aCis_datapack/data/html/mods/votesystem/50009.html | |
2161 | new file mode 100644 | |
2162 | index 0000000..d7d938a | |
2163 | --- /dev/null | |
2164 | +++ b/aCis_datapack/data/html/mods/votesystem/50009.html | |
2165 | @@ -0,0 +1,19 @@ | |
2166 | +<html> | |
2167 | +<title>Voting panel</title> | |
2168 | +<body><center> | |
2169 | + <br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br> | |
2170 | + <table cellpadding=2 width=280> | |
2171 | + <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> | |
2172 | + </table> | |
2173 | + <table width="290"><tr><td width="290" align="center">You can vote: </td></tr></table> | |
2174 | + <br><img src="l2ui.SquareWhite" width=290 height=1><br> | |
2175 | + | |
2176 | + %enablevote% | |
2177 | + | |
2178 | + <br> | |
2179 | + <img src="l2ui.SquareWhite" width=290 height=1><br> | |
2180 | + | |
2181 | + | |
2182 | + | |
2183 | +</center></body> | |
2184 | +</html> | |
2185 | \ No newline at end of file | |
2186 | diff --git a/aCis_datapack/data/xml/npcs/50000-50999.xml b/aCis_datapack/data/xml/npcs/50000-50999.xml | |
2187 | index 1a21b51..0e9b37f 100644 | |
2188 | --- a/aCis_datapack/data/xml/npcs/50000-50999.xml | |
2189 | +++ b/aCis_datapack/data/xml/npcs/50000-50999.xml | |
2190 | @@ -1,114 +1,153 @@ | |
2191 | ||
2192 | </npc> | |
2193 | ||
2194 | + <npc id="50009" idTemplate="30519" name="Kaaya" title="Vote System"> | |
2195 | + <set name="usingServerSideName" val="true"/> | |
2196 | + <set name="usingServerSideTitle" val="true"/> | |
2197 | + <set name="level" val="70"/> | |
2198 | + <set name="radius" val="7"/> | |
2199 | + <set name="height" val="18"/> | |
2200 | + <set name="rHand" val="0"/> | |
2201 | + <set name="lHand" val="0"/> | |
2202 | + <set name="type" val="NpcVote"/> | |
2203 | + <set name="exp" val="0"/> | |
2204 | + <set name="sp" val="0"/> | |
2205 | + <set name="hp" val="2444.46819"/> | |
2206 | + <set name="mp" val="1345.8"/> | |
2207 | + <set name="hpRegen" val="7.5"/> | |
2208 | + <set name="mpRegen" val="2.7"/> | |
2209 | + <set name="pAtk" val="688.86373"/> | |
2210 | + <set name="pDef" val="295.91597"/> | |
2211 | + <set name="mAtk" val="470.40463"/> | |
2212 | + <set name="mDef" val="216.53847"/> | |
2213 | + <set name="crit" val="4"/> | |
2214 | + <set name="atkSpd" val="253"/> | |
2215 | + <set name="str" val="40"/> | |
2216 | + <set name="int" val="21"/> | |
2217 | + <set name="dex" val="30"/> | |
2218 | + <set name="wit" val="20"/> | |
2219 | + <set name="con" val="43"/> | |
2220 | + <set name="men" val="20"/> | |
2221 | + <set name="corpseTime" val="7"/> | |
2222 | + <set name="walkSpd" val="50"/> | |
2223 | + <set name="runSpd" val="120"/> | |
2224 | + <set name="dropHerbGroup" val="0"/> | |
2225 | + <ai type="DEFAULT" ssCount="0" ssRate="0" spsCount="0" spsRate="0" aggro="0" canMove="true" seedable="false"/> | |
2226 | + <skills> | |
2227 | + <skill id="4045" level="1"/> | |
2228 | + <skill id="4416" level="18"/> | |
2229 | + </skills> | |
2230 | + </npc> | |
2231 | + | |
2232 | </list> | |
2233 | \ No newline at end of file | |
2234 | diff --git a/aCis_datapack/data/xml/votesystem.xml b/aCis_datapack/data/xml/votesystem.xml | |
2235 | new file mode 100644 | |
2236 | index 0000000..f254f8c | |
2237 | --- /dev/null | |
2238 | +++ b/aCis_datapack/data/xml/votesystem.xml | |
2239 | @@ -0,0 +1,75 @@ | |
2240 | +<?xml version="1.0" encoding="UTF-8"?> | |
2241 | +<list> | |
2242 | + <votesite name="l2.topgameserver.net" ordinal="0"> | |
2243 | + <items> | |
2244 | + <item itemId="57" itemCount="10000000" /> | |
2245 | + <item itemId="6673" itemCount="1"/> | |
2246 | + </items> | |
2247 | + </votesite> | |
2248 | + <votesite name="ItopZ.com" ordinal="1"> | |
2249 | + <items> | |
2250 | + <item itemId="57" itemCount="10000000" /> | |
2251 | + <item itemId="6673" itemCount="1"/> | |
2252 | + </items> | |
2253 | + </votesite> | |
2254 | + <votesite name="L2Top.co" ordinal="2"> | |
2255 | + <items> | |
2256 | + <item itemId="57" itemCount="10000000" /> | |
2257 | + <item itemId="6673" itemCount="1"/> | |
2258 | + </items> | |
2259 | + </votesite> | |
2260 | + <votesite name="L2Votes.com" ordinal="3"> | |
2261 | + <items> | |
2262 | + <item itemId="57" itemCount="10000000" /> | |
2263 | + <item itemId="6673" itemCount="1"/> | |
2264 | + </items> | |
2265 | + </votesite> | |
2266 | + <votesite name="Hopzone.net" ordinal="4"> | |
2267 | + <items> | |
2268 | + <item itemId="57" itemCount="10000000" /> | |
2269 | + <item itemId="6673" itemCount="1"/> | |
2270 | + </items> | |
2271 | + </votesite> | |
2272 | + <votesite name="L2Network.eu" ordinal="5"> | |
2273 | + <items> | |
2274 | + <item itemId="57" itemCount="10000000" /> | |
2275 | + <item itemId="6673" itemCount="1"/> | |
2276 | + </items> | |
2277 | + </votesite> | |
2278 | + <votesite name="L2Topservers.com" ordinal="6"> | |
2279 | + <items> | |
2280 | + <item itemId="57" itemCount="10000000" /> | |
2281 | + <item itemId="6673" itemCount="1"/> | |
2282 | + </items> | |
2283 | + </votesite> | |
2284 | + <votesite name="top.l2jbrasil.com" ordinal="7"> | |
2285 | + <items> | |
2286 | + <item itemId="57" itemCount="10000000" /> | |
2287 | + <item itemId="6673" itemCount="1"/> | |
2288 | + </items> | |
2289 | + </votesite> | |
2290 | + <votesite name="MMOTOP.eu" ordinal="8"> | |
2291 | + <items> | |
2292 | + <item itemId="57" itemCount="10000000" /> | |
2293 | + <item itemId="6673" itemCount="1"/> | |
2294 | + </items> | |
2295 | + </votesite> | |
2296 | + <votesite name="L2Topzone.com" ordinal="9"> | |
2297 | + <items> | |
2298 | + <item itemId="57" itemCount="10000000" /> | |
2299 | + <item itemId="6673" itemCount="1"/> | |
2300 | + </items> | |
2301 | + </votesite> | |
2302 | + <votesite name="L2Servers.com" ordinal="10"> | |
2303 | + <items> | |
2304 | + <item itemId="57" itemCount="10000000" /> | |
2305 | + <item itemId="6673" itemCount="1"/> | |
2306 | + </items> | |
2307 | + </votesite> | |
2308 | + <votesite name="globalVotes" ordinal="11"> | |
2309 | + <items> | |
2310 | + <item itemId="57" itemCount="10000000" /> | |
2311 | + <item itemId="6673" itemCount="1"/> | |
2312 | + </items> | |
2313 | + </votesite> | |
2314 | +</list> | |
2315 | \ No newline at end of file | |
2316 | ||
2317 | ||
2318 | SET NAMES utf8mb4; | |
2319 | SET FOREIGN_KEY_CHECKS = 0; | |
2320 | ||
2321 | -- ---------------------------- | |
2322 | -- Table structure for globalvotes | |
2323 | -- ---------------------------- | |
2324 | DROP TABLE IF EXISTS `globalvotes`; | |
2325 | CREATE TABLE `globalvotes` ( | |
2326 | `voteSite` tinyint(2) NOT NULL, | |
2327 | `lastRewardVotes` int(11) NULL DEFAULT NULL, | |
2328 | PRIMARY KEY (`voteSite`) USING BTREE | |
2329 | ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic; | |
2330 | ||
2331 | -- ---------------------------- | |
2332 | -- Records of globalvotes | |
2333 | -- ---------------------------- | |
2334 | INSERT INTO `globalvotes` VALUES (0, 13); | |
2335 | INSERT INTO `globalvotes` VALUES (1, 68); | |
2336 | INSERT INTO `globalvotes` VALUES (2, 0); | |
2337 | INSERT INTO `globalvotes` VALUES (3, 3); | |
2338 | INSERT INTO `globalvotes` VALUES (4, 2); | |
2339 | INSERT INTO `globalvotes` VALUES (5, 0); | |
2340 | INSERT INTO `globalvotes` VALUES (6, 0); | |
2341 | INSERT INTO `globalvotes` VALUES (7, 2); | |
2342 | INSERT INTO `globalvotes` VALUES (8, 3); | |
2343 | INSERT INTO `globalvotes` VALUES (9, 0); | |
2344 | INSERT INTO `globalvotes` VALUES (10, 75); | |
2345 | ||
2346 | -- ---------------------------- | |
2347 | -- Table structure for individualvotes | |
2348 | -- ---------------------------- | |
2349 | DROP TABLE IF EXISTS `individualvotes`; | |
2350 | CREATE TABLE `individualvotes` ( | |
2351 | `voterIp` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL, | |
2352 | `voteSite` tinyint(3) NOT NULL, | |
2353 | `diffTime` bigint(20) NULL DEFAULT NULL, | |
2354 | `votingTimeSite` bigint(20) NULL DEFAULT NULL, | |
2355 | `alreadyRewarded` tinyint(3) NULL DEFAULT NULL, | |
2356 | PRIMARY KEY (`voterIp`, `voteSite`) USING BTREE | |
2357 | ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic; | |
2358 | ||
2359 | -- ---------------------------- | |
2360 | -- Records of individualvotes | |
2361 | -- ---------------------------- | |
2362 | INSERT INTO `individualvotes` VALUES ('127.0.0.1', 0, 1588703279833, 1588702011000, 1); | |
2363 | INSERT INTO `individualvotes` VALUES ('127.0.0.1', 3, 1588704503248, 1588703396000, 1); | |
2364 | INSERT INTO `individualvotes` VALUES ('127.0.0.1', 5, 1588692835993, 1588692823000, 1); | |
2365 | ||
2366 | SET FOREIGN_KEY_CHECKS = 1; |