Guest User

Untitled

a guest
Jul 5th, 2010
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.96 KB | None | 0 0
  1. Index: java/com/l2jserver/Config.java
  2. ===================================================================
  3. --- java/com/l2jserver/Config.java  (revision 4328)
  4. +++ java/com/l2jserver/Config.java  (working copy)
  5. @@ -970,6 +970,8 @@
  6.    
  7.     //chatfilter
  8.     public static ArrayList<String> FILTER_LIST;
  9. +  
  10. +   public static int MAX_PLAYERS_FROM_ONE_PC = 2;
  11.  
  12.     /**
  13.      * This class initializes all global variables for configuration.<br>
  14. Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  15. ===================================================================
  16. --- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (revision 4329)
  17. +++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (working copy)
  18. @@ -162,6 +162,7 @@
  19.  import com.l2jserver.gameserver.model.quest.QuestState;
  20.  import com.l2jserver.gameserver.model.quest.State;
  21.  import com.l2jserver.gameserver.network.L2GameClient;
  22. +import com.l2jserver.gameserver.network.MultiBoxProtection;
  23.  import com.l2jserver.gameserver.network.SystemMessageId;
  24.  import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
  25.  import com.l2jserver.gameserver.network.communityserver.writepackets.WorldInfo;
  26. @@ -11935,6 +11936,11 @@
  27.             _log.log(Level.SEVERE, "deleteMe()", e);
  28.         }
  29.        
  30. +       if (Config.MAX_PLAYERS_FROM_ONE_PC > 0 && getClient() != null)
  31. +       {
  32. +           MultiBoxProtection.getInstance().removeConnection(getClient());
  33. +       }
  34. +      
  35.         // Close the connection with the client
  36.         closeNetConnection(closeClient);
  37.        
  38. Index: java/com/l2jserver/gameserver/network/L2GameClient.java
  39. ===================================================================
  40. --- java/com/l2jserver/gameserver/network/L2GameClient.java (revision 4322)
  41. +++ java/com/l2jserver/gameserver/network/L2GameClient.java (working copy)
  42. @@ -71,6 +71,7 @@
  43.  
  44.     // Info
  45.      private String _accountName;
  46. +    private String _adress;
  47.      private SessionKey _sessionId;
  48.     private L2PcInstance _activeChar;
  49.     private ReentrantLock _activeCharLock = new ReentrantLock();
  50. @@ -102,6 +103,7 @@
  51.     public L2GameClient(MMOConnection<L2GameClient> con)
  52.     {
  53.         super(con);
  54. +       _adress = con.getInetAddress().getHostAddress();
  55.         state = GameClientState.CONNECTED;
  56.         _connectionStartTime = System.currentTimeMillis();
  57.          _crypt = new GameCrypt();
  58. @@ -193,6 +195,11 @@
  59.     {
  60.         return _accountName;
  61.     }
  62. +  
  63. +   public String getAdress()
  64. +   {
  65. +       return _adress;
  66. +   }
  67.  
  68.     public void setSessionId(SessionKey sk)
  69.     {
  70. Index: java/com/l2jserver/gameserver/network/MultiBoxProtection.java
  71. ===================================================================
  72. --- java/com/l2jserver/gameserver/network/MultiBoxProtection.java   (revision 0)
  73. +++ java/com/l2jserver/gameserver/network/MultiBoxProtection.java   (revision 0)
  74. @@ -0,0 +1,134 @@
  75. +/*
  76. + * This program is free software: you can redistribute it and/or modify it under
  77. + * the terms of the GNU General Public License as published by the Free Software
  78. + * Foundation, either version 3 of the License, or (at your option) any later
  79. + * version.
  80. + *
  81. + * This program is distributed in the hope that it will be useful, but WITHOUT
  82. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  83. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  84. + * details.
  85. + *
  86. + * You should have received a copy of the GNU General Public License along with
  87. + * this program. If not, see <http://www.gnu.org/licenses/>.
  88. + */
  89. +package com.l2jserver.gameserver.network;
  90. +
  91. +
  92. +import java.util.Arrays;
  93. +import java.util.Map;
  94. +
  95. +import com.l2jserver.Config;
  96. +
  97. +import javolution.util.FastMap;
  98. +
  99. +
  100. +/**
  101. + * @author JIV
  102. + *
  103. + */
  104. +public class MultiBoxProtection
  105. +{
  106. +   private Map<IpPack, Integer> map;
  107. +  
  108. +   public static MultiBoxProtection getInstance()
  109. +   {
  110. +       return SingletonHolder._instance;
  111. +   }
  112. +  
  113. +   public MultiBoxProtection()
  114. +   {
  115. +       map = new FastMap<MultiBoxProtection.IpPack, Integer>();
  116. +   }
  117. +  
  118. +   public synchronized boolean registerNewConnection(L2GameClient client)
  119. +   {
  120. +       IpPack pack = new IpPack(client.getAdress(), client.getTrace());
  121. +       Integer count = map.get(pack);
  122. +       if (count == null)
  123. +       {
  124. +           map.put(pack, 1);
  125. +       }
  126. +       else if (count < Config.MAX_PLAYERS_FROM_ONE_PC)
  127. +       {
  128. +           map.put(pack, count+1);
  129. +       }
  130. +       else
  131. +       {
  132. +           map.put(pack, count+1); // yes do it anyway
  133. +           return false;
  134. +       }
  135. +      
  136. +       return true;
  137. +   }
  138. +  
  139. +   public synchronized void removeConnection(L2GameClient client)
  140. +   {
  141. +       IpPack pack = new IpPack(client.getAdress(), client.getTrace());
  142. +       Integer count = map.get(pack);
  143. +       if (count != null && count > 1)
  144. +       {
  145. +           map.put(pack, count-1);
  146. +       }
  147. +       else
  148. +       {
  149. +           map.remove(pack);
  150. +       }
  151. +   }
  152. +  
  153. +   @SuppressWarnings("synthetic-access")
  154. +   private static class SingletonHolder
  155. +   {
  156. +       protected static final MultiBoxProtection _instance = new MultiBoxProtection();
  157. +   }
  158. +  
  159. +   public final static class IpPack
  160. +   {
  161. +       String ip;
  162. +       int[][] tracert;
  163. +      
  164. +       public IpPack(String ip, int[][] tracert)
  165. +       {
  166. +           this.ip = ip;
  167. +           this.tracert = tracert;
  168. +       }
  169. +
  170. +       @Override
  171. +       public int hashCode()
  172. +       {
  173. +           final int prime = 31;
  174. +           int result = 1;
  175. +           result = prime * result + ((ip == null) ? 0 : ip.hashCode());
  176. +           for (int[] array: tracert)
  177. +               result = prime * result + Arrays.hashCode(array);
  178. +           return result;
  179. +       }
  180. +
  181. +       @Override
  182. +       public boolean equals(Object obj)
  183. +       {
  184. +           if (this == obj)
  185. +               return true;
  186. +           if (obj == null)
  187. +               return false;
  188. +           if (getClass() != obj.getClass())
  189. +               return false;
  190. +           IpPack other = (IpPack) obj;
  191. +           if (ip == null)
  192. +           {
  193. +               if (other.ip != null)
  194. +                   return false;
  195. +           }
  196. +           else if (!ip.equals(other.ip))
  197. +               return false;
  198. +           for (int i = 0 ; i < tracert.length; i++)
  199. +               for (int o = 0; o < tracert[0].length; o++)
  200. +                   if (tracert[i][o] != other.tracert[i][o])
  201. +                       return false;
  202. +           return true;
  203. +       }
  204. +
  205. +   }
  206. +}
  207. +
  208. +
  209. Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java
  210. ===================================================================
  211. --- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (revision 4328)
  212. +++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (working copy)
  213. @@ -24,6 +24,7 @@
  214.  import com.l2jserver.gameserver.LoginServerThread;
  215.  import com.l2jserver.gameserver.SevenSigns;
  216.  import com.l2jserver.gameserver.TaskPriority;
  217. +import com.l2jserver.gameserver.ThreadPoolManager;
  218.  import com.l2jserver.gameserver.cache.HtmCache;
  219.  import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager;
  220.  import com.l2jserver.gameserver.datatables.AdminCommandAccessRights;
  221. @@ -60,6 +61,7 @@
  222.  import com.l2jserver.gameserver.model.entity.TvTEvent;
  223.  import com.l2jserver.gameserver.model.quest.Quest;
  224.  import com.l2jserver.gameserver.model.quest.QuestState;
  225. +import com.l2jserver.gameserver.network.MultiBoxProtection;
  226.  import com.l2jserver.gameserver.network.SystemMessageId;
  227.  import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
  228.  import com.l2jserver.gameserver.network.communityserver.writepackets.WorldInfo;
  229. @@ -125,7 +127,7 @@
  230.     @Override
  231.     protected void runImpl()
  232.     {
  233. -       L2PcInstance activeChar = getClient().getActiveChar();
  234. +       final L2PcInstance activeChar = getClient().getActiveChar();
  235.  
  236.         if (activeChar == null)
  237.         {
  238. @@ -493,6 +495,22 @@
  239.             sm.addString(Integer.toString(birthday));
  240.             activeChar.sendPacket(sm);
  241.         }
  242. +      
  243. +       if (Config.MAX_PLAYERS_FROM_ONE_PC > 0)
  244. +       {
  245. +           if (!MultiBoxProtection.getInstance().registerNewConnection(getClient()))
  246. +           {
  247. +               activeChar.sendMessage("Too many connections, please logout other characters first.");
  248. +               ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  249. +               {
  250. +                   public void run()
  251. +                   {
  252. +                       activeChar.logout(false);
  253. +                   }
  254. +               } , 400);
  255. +               return;
  256. +           }
  257. +       }
  258.     }
  259.  
  260.     /**
  261. Index: java/com/l2jserver/gameserver/network/clientpackets/RequestRestart.java
  262. ===================================================================
  263. --- java/com/l2jserver/gameserver/network/clientpackets/RequestRestart.java (revision 4322)
  264. +++ java/com/l2jserver/gameserver/network/clientpackets/RequestRestart.java (working copy)
  265. @@ -23,6 +23,7 @@
  266.  import com.l2jserver.gameserver.model.L2Party;
  267.  import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  268.  import com.l2jserver.gameserver.network.L2GameClient;
  269. +import com.l2jserver.gameserver.network.MultiBoxProtection;
  270.  import com.l2jserver.gameserver.network.SystemMessageId;
  271.  import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  272.  import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
  273. @@ -116,6 +117,11 @@
  274.         record.setParameters(new Object[]{client});
  275.         _logAccounting.log(record);
  276.  
  277. +       if (Config.MAX_PLAYERS_FROM_ONE_PC > 0 && getClient() != null)
  278. +       {
  279. +           MultiBoxProtection.getInstance().removeConnection(getClient());
  280. +       }
  281. +      
  282.         // detach the client from the char so that the connection isnt closed in the deleteMe
  283.         player.setClient(null);
Advertisement
Add Comment
Please, Sign In to add comment