Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: java/com/l2jserver/Config.java
- ===================================================================
- --- java/com/l2jserver/Config.java (revision 4328)
- +++ java/com/l2jserver/Config.java (working copy)
- @@ -970,6 +970,8 @@
- //chatfilter
- public static ArrayList<String> FILTER_LIST;
- +
- + public static int MAX_PLAYERS_FROM_ONE_PC = 2;
- /**
- * This class initializes all global variables for configuration.<br>
- Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java (revision 4329)
- +++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java (working copy)
- @@ -162,6 +162,7 @@
- import com.l2jserver.gameserver.model.quest.QuestState;
- import com.l2jserver.gameserver.model.quest.State;
- import com.l2jserver.gameserver.network.L2GameClient;
- +import com.l2jserver.gameserver.network.MultiBoxProtection;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
- import com.l2jserver.gameserver.network.communityserver.writepackets.WorldInfo;
- @@ -11935,6 +11936,11 @@
- _log.log(Level.SEVERE, "deleteMe()", e);
- }
- + if (Config.MAX_PLAYERS_FROM_ONE_PC > 0 && getClient() != null)
- + {
- + MultiBoxProtection.getInstance().removeConnection(getClient());
- + }
- +
- // Close the connection with the client
- closeNetConnection(closeClient);
- Index: java/com/l2jserver/gameserver/network/L2GameClient.java
- ===================================================================
- --- java/com/l2jserver/gameserver/network/L2GameClient.java (revision 4322)
- +++ java/com/l2jserver/gameserver/network/L2GameClient.java (working copy)
- @@ -71,6 +71,7 @@
- // Info
- private String _accountName;
- + private String _adress;
- private SessionKey _sessionId;
- private L2PcInstance _activeChar;
- private ReentrantLock _activeCharLock = new ReentrantLock();
- @@ -102,6 +103,7 @@
- public L2GameClient(MMOConnection<L2GameClient> con)
- {
- super(con);
- + _adress = con.getInetAddress().getHostAddress();
- state = GameClientState.CONNECTED;
- _connectionStartTime = System.currentTimeMillis();
- _crypt = new GameCrypt();
- @@ -193,6 +195,11 @@
- {
- return _accountName;
- }
- +
- + public String getAdress()
- + {
- + return _adress;
- + }
- public void setSessionId(SessionKey sk)
- {
- Index: java/com/l2jserver/gameserver/network/MultiBoxProtection.java
- ===================================================================
- --- java/com/l2jserver/gameserver/network/MultiBoxProtection.java (revision 0)
- +++ java/com/l2jserver/gameserver/network/MultiBoxProtection.java (revision 0)
- @@ -0,0 +1,134 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +package com.l2jserver.gameserver.network;
- +
- +
- +import java.util.Arrays;
- +import java.util.Map;
- +
- +import com.l2jserver.Config;
- +
- +import javolution.util.FastMap;
- +
- +
- +/**
- + * @author JIV
- + *
- + */
- +public class MultiBoxProtection
- +{
- + private Map<IpPack, Integer> map;
- +
- + public static MultiBoxProtection getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + public MultiBoxProtection()
- + {
- + map = new FastMap<MultiBoxProtection.IpPack, Integer>();
- + }
- +
- + public synchronized boolean registerNewConnection(L2GameClient client)
- + {
- + IpPack pack = new IpPack(client.getAdress(), client.getTrace());
- + Integer count = map.get(pack);
- + if (count == null)
- + {
- + map.put(pack, 1);
- + }
- + else if (count < Config.MAX_PLAYERS_FROM_ONE_PC)
- + {
- + map.put(pack, count+1);
- + }
- + else
- + {
- + map.put(pack, count+1); // yes do it anyway
- + return false;
- + }
- +
- + return true;
- + }
- +
- + public synchronized void removeConnection(L2GameClient client)
- + {
- + IpPack pack = new IpPack(client.getAdress(), client.getTrace());
- + Integer count = map.get(pack);
- + if (count != null && count > 1)
- + {
- + map.put(pack, count-1);
- + }
- + else
- + {
- + map.remove(pack);
- + }
- + }
- +
- + @SuppressWarnings("synthetic-access")
- + private static class SingletonHolder
- + {
- + protected static final MultiBoxProtection _instance = new MultiBoxProtection();
- + }
- +
- + public final static class IpPack
- + {
- + String ip;
- + int[][] tracert;
- +
- + public IpPack(String ip, int[][] tracert)
- + {
- + this.ip = ip;
- + this.tracert = tracert;
- + }
- +
- + @Override
- + public int hashCode()
- + {
- + final int prime = 31;
- + int result = 1;
- + result = prime * result + ((ip == null) ? 0 : ip.hashCode());
- + for (int[] array: tracert)
- + result = prime * result + Arrays.hashCode(array);
- + return result;
- + }
- +
- + @Override
- + public boolean equals(Object obj)
- + {
- + if (this == obj)
- + return true;
- + if (obj == null)
- + return false;
- + if (getClass() != obj.getClass())
- + return false;
- + IpPack other = (IpPack) obj;
- + if (ip == null)
- + {
- + if (other.ip != null)
- + return false;
- + }
- + else if (!ip.equals(other.ip))
- + return false;
- + for (int i = 0 ; i < tracert.length; i++)
- + for (int o = 0; o < tracert[0].length; o++)
- + if (tracert[i][o] != other.tracert[i][o])
- + return false;
- + return true;
- + }
- +
- + }
- +}
- +
- +
- Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java
- ===================================================================
- --- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (revision 4328)
- +++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (working copy)
- @@ -24,6 +24,7 @@
- import com.l2jserver.gameserver.LoginServerThread;
- import com.l2jserver.gameserver.SevenSigns;
- import com.l2jserver.gameserver.TaskPriority;
- +import com.l2jserver.gameserver.ThreadPoolManager;
- import com.l2jserver.gameserver.cache.HtmCache;
- import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager;
- import com.l2jserver.gameserver.datatables.AdminCommandAccessRights;
- @@ -60,6 +61,7 @@
- import com.l2jserver.gameserver.model.entity.TvTEvent;
- import com.l2jserver.gameserver.model.quest.Quest;
- import com.l2jserver.gameserver.model.quest.QuestState;
- +import com.l2jserver.gameserver.network.MultiBoxProtection;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
- import com.l2jserver.gameserver.network.communityserver.writepackets.WorldInfo;
- @@ -125,7 +127,7 @@
- @Override
- protected void runImpl()
- {
- - L2PcInstance activeChar = getClient().getActiveChar();
- + final L2PcInstance activeChar = getClient().getActiveChar();
- if (activeChar == null)
- {
- @@ -493,6 +495,22 @@
- sm.addString(Integer.toString(birthday));
- activeChar.sendPacket(sm);
- }
- +
- + if (Config.MAX_PLAYERS_FROM_ONE_PC > 0)
- + {
- + if (!MultiBoxProtection.getInstance().registerNewConnection(getClient()))
- + {
- + activeChar.sendMessage("Too many connections, please logout other characters first.");
- + ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
- + {
- + public void run()
- + {
- + activeChar.logout(false);
- + }
- + } , 400);
- + return;
- + }
- + }
- }
- /**
- Index: java/com/l2jserver/gameserver/network/clientpackets/RequestRestart.java
- ===================================================================
- --- java/com/l2jserver/gameserver/network/clientpackets/RequestRestart.java (revision 4322)
- +++ java/com/l2jserver/gameserver/network/clientpackets/RequestRestart.java (working copy)
- @@ -23,6 +23,7 @@
- import com.l2jserver.gameserver.model.L2Party;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.network.L2GameClient;
- +import com.l2jserver.gameserver.network.MultiBoxProtection;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
- import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
- @@ -116,6 +117,11 @@
- record.setParameters(new Object[]{client});
- _logAccounting.log(record);
- + if (Config.MAX_PLAYERS_FROM_ONE_PC > 0 && getClient() != null)
- + {
- + MultiBoxProtection.getInstance().removeConnection(getClient());
- + }
- +
- // detach the client from the char so that the connection isnt closed in the deleteMe
- player.setClient(null);
Advertisement
Add Comment
Please, Sign In to add comment