Advertisement
Guest User

permanent ban coded for acis (AbsolutePower)

a guest
Aug 6th, 2013
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.92 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (revision 65)
  6. +++ java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (working copy)
  7. @@ -33,6 +33,7 @@
  8.  import net.sf.l2j.gameserver.model.L2Clan;
  9.  import net.sf.l2j.gameserver.model.L2World;
  10.  import net.sf.l2j.gameserver.model.actor.L2Character;
  11. +import net.sf.l2j.gameserver.model.actor.ipCatcher;
  12.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  13.  import net.sf.l2j.gameserver.model.entity.ClanHall;
  14.  import net.sf.l2j.gameserver.model.entity.Couple;
  15. @@ -175,6 +176,10 @@
  16.         if (Config.ALLOW_WEDDING)
  17.             engage(activeChar);
  18.        
  19. +       final ipCatcher ipc = new ipCatcher();
  20. +       if(ipc.isCatched(activeChar))
  21. +             activeChar.logout();
  22. +          
  23.         // Announcements, welcome & Seven signs period messages
  24.         activeChar.sendPacket(SystemMessageId.WELCOME_TO_LINEAGE);
  25.         SevenSigns.getInstance().sendCurrentPeriodMsg(activeChar);
  26. Index: java/net/sf/l2j/gameserver/model/actor/ipCatcher.java
  27. ===================================================================
  28. --- java/net/sf/l2j/gameserver/model/actor/ipCatcher.java   (revision 0)
  29. +++ java/net/sf/l2j/gameserver/model/actor/ipCatcher.java   (revision 0)
  30. @@ -0,0 +1,191 @@
  31. +package net.sf.l2j.gameserver.model.actor;
  32. +
  33. +import java.io.File;
  34. +import java.io.FileReader;
  35. +import java.io.FileWriter;
  36. +import java.io.IOException;
  37. +import java.io.LineNumberReader;
  38. +import java.net.InetAddress;
  39. +import java.net.NetworkInterface;
  40. +import java.net.SocketException;
  41. +import java.net.UnknownHostException;
  42. +import java.util.StringTokenizer;
  43. +
  44. +import javolution.util.FastList;
  45. +
  46. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  47. +
  48. +/**
  49. + * @author AbsolutePower
  50. + */
  51. +public class ipCatcher
  52. +{
  53. +        public static FastList<String> ips = new FastList<>();                                              
  54. +          static File file = new File("data/ips.txt");  
  55. +        
  56. +          public String getMacAddr(L2PcInstance p)
  57. +          {
  58. +                  StringBuilder sb = new StringBuilder();      
  59. +                  byte[] mac = null;
  60. +                
  61. +                  if(p != null)            
  62. +                        try
  63. +                        {      
  64. +                                p.getClient().getConnection().getInetAddress();
  65. +                               final InetAddress ip = InetAddress.getLocalHost();
  66. +                                NetworkInterface network = NetworkInterface.getByInetAddress(ip);      
  67. +                              
  68. +                                if(network !=null)
  69. +                                {
  70. +                                        mac = network.getHardwareAddress();
  71. +                                }
  72. +                              
  73. +                                if(mac!=null)          
  74. +                                {
  75. +                                for (int i = 0; i < mac.length; i++)
  76. +                                {
  77. +                                        sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
  78. +                                }
  79. +                                }
  80. +                                else
  81. +                                        sb.append("No mac found");
  82. +                
  83. +                        }
  84. +                        catch (SocketException e)
  85. +                        {
  86. +                
  87. +                                e.printStackTrace();
  88. +                
  89. +                        }
  90. +                        catch (UnknownHostException e)
  91. +                        {
  92. +                                e.printStackTrace();
  93. +                        }
  94. +                      
  95. +                        return sb.toString();
  96. +           }
  97. +        
  98. +           public String getIp(L2PcInstance p)
  99. +           {
  100. +                    return p.getClient().getConnection().getInetAddress().getHostAddress();
  101. +           }  
  102. +          
  103. +           //return true if catched :D
  104. +           public boolean isCatched(L2PcInstance p)
  105. +           {
  106. +                        if(ips.contains(getMacAddr(p)) || ips.contains(getIp(p)))
  107. +                           return true;
  108. +                      
  109. +                        return false;
  110. +           }
  111. +          
  112. +           //make textfile if not exist
  113. +           public static void MkTiNe()
  114. +           {
  115. +                   if(file == null)
  116. +                   file.mkdirs();
  117. +           }
  118. +          
  119. +        public void addIp(L2PcInstance p)
  120. +        {
  121. +                MkTiNe();
  122. +                        final String ip = getIp(p);
  123. +                        final String name = p.getName();
  124. +                      
  125. +                        if(ip != null && name != null)
  126. +                        ips.add("Name");
  127. +                        ips.add(name);
  128. +                        ips.add("Ip");
  129. +                        ips.add(ip);
  130. +                        ips.add("Mac Addres");
  131. +                        ips.add(getMacAddr(p));
  132. +                        ips.add("-");
  133. +              
  134. +                        FileWriter s = null;
  135. +                        try
  136. +                        {
  137. +                                s = new FileWriter(file);
  138. +                                for (int i = 0; i < ips.size(); i ++)
  139. +                                {
  140. +                                        s.write(ips.get(i));
  141. +                                        s.write("\r\n");
  142. +                                }
  143. +                                s.flush();
  144. +                                s.close();
  145. +                                s = null;
  146. +                        }
  147. +                        catch (IOException e)
  148. +                        {
  149. +                                e.printStackTrace();
  150. +                        }
  151. +                        ipsLoad();
  152. +        }
  153. +
  154. +        public void removeIp(L2PcInstance p)
  155. +        {
  156. +                        final String ip = getIp(p);
  157. +                        final String name = p.getName();
  158. +                      
  159. +                        if(ip != null && name != null)
  160. +                        ips.remove("Name");
  161. +                        ips.remove(name);
  162. +                        ips.remove("Ip");
  163. +                        ips.remove(ip);
  164. +                        ips.remove("Mac Addres");
  165. +                        ips.remove(getMacAddr(p));
  166. +                        ips.remove("-");
  167. +              
  168. +                        FileWriter s = null;
  169. +                        try
  170. +                        {
  171. +                                s = new FileWriter(file);
  172. +                                for (int i = 0; i < ips.size(); i ++)
  173. +                                {
  174. +                                        s.write(ips.get(i));
  175. +                                        s.write("\r\n");
  176. +                                }
  177. +                                s.flush();
  178. +                                s.close();
  179. +                                s = null;
  180. +                        }
  181. +                        catch (IOException e)
  182. +                        {
  183. +                                e.printStackTrace();
  184. +                        }
  185. +                        ipsLoad();
  186. +        }
  187. +                
  188. +        public static void ipsLoad()
  189. +        {
  190. +                        MkTiNe();
  191. +                        LineNumberReader l = null;
  192. +                                try
  193. +                                {
  194. +                                        String line = null;
  195. +                                        l = new LineNumberReader(new FileReader(file));
  196. +                                        while ( (line = l.readLine()) != null)
  197. +                                        {
  198. +                                                StringTokenizer st = new StringTokenizer(line,"\n\r");
  199. +                                                if (st.hasMoreTokens())
  200. +                                                {
  201. +                                                        String n = st.nextToken();
  202. +                                                        ips.add(n);
  203. +                                                }                                      
  204. +                                        }      
  205. +                                }
  206. +                                catch(Exception e){
  207. +                                        e.printStackTrace();
  208. +                                }
  209. +                                finally
  210. +                                {
  211. +                                        try
  212. +                                        {
  213. +                                                if(l != null)
  214. +                                                l.close();
  215. +                                        }
  216. +                                        catch (Exception e)
  217. +                                        {
  218. +                                        }
  219. +                        }
  220. +                  }
  221. +}
  222. \ No newline at end of file
  223. Index: java/net/sf/l2j/gameserver/GameServer.java
  224. ===================================================================
  225. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 65)
  226. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  227. @@ -95,6 +95,7 @@
  228.  import net.sf.l2j.gameserver.model.L2World;
  229.  import net.sf.l2j.gameserver.model.PartyMatchRoomList;
  230.  import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
  231. +import net.sf.l2j.gameserver.model.actor.ipCatcher;
  232.  import net.sf.l2j.gameserver.model.entity.AutoAnnouncement;
  233.  import net.sf.l2j.gameserver.model.entity.Castle;
  234.  import net.sf.l2j.gameserver.model.entity.Hero;
  235. @@ -293,7 +294,8 @@
  236.         AutoAnnouncement.getInstance();
  237.         if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
  238.         OfflineTradersTable.restoreOfflineTraders();
  239. -        
  240. +       ipCatcher.ipsLoad();
  241. +      
  242.         Util.printSection("System");
  243.         TaskManager.getInstance();
  244.        
  245. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBan.java
  246. ===================================================================
  247. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBan.java   (revision 65)
  248. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBan.java   (working copy)
  249. @@ -24,6 +24,7 @@
  250.  import net.sf.l2j.gameserver.LoginServerThread;
  251.  import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  252.  import net.sf.l2j.gameserver.model.L2World;
  253. +import net.sf.l2j.gameserver.model.actor.ipCatcher;
  254.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  255.  import net.sf.l2j.gameserver.network.SystemMessageId;
  256.  import net.sf.l2j.gameserver.util.GMAudit;
  257. @@ -49,7 +50,9 @@
  258.         "admin_unban_chat",
  259.        
  260.         "admin_jail",
  261. -       "admin_unjail"
  262. +       "admin_unjail",
  263. +       "admin_permaban",
  264. +       "admin_removeperma"
  265.     };
  266.    
  267.     @Override
  268. @@ -131,6 +134,36 @@
  269.             auditAction(command, activeChar, (targetPlayer == null ? player : targetPlayer.getName()));
  270.             return changeCharAccessLevel(targetPlayer, player, activeChar, -100);
  271.         }
  272. +        else if (command.startsWith("admin_permaban"))
  273. +        {                       if (targetPlayer == null && player.equals(""))                  {
  274. +                        activeChar.sendMessage("Usage: //permaban <char_name> (if none, target char is banned)");
  275. +                        return false;
  276. +                }
  277. +                 final ipCatcher ipc = new ipCatcher();
  278. +                 if(targetPlayer!=null && !targetPlayer.isGM())
  279. +                 {
  280. +                 ipc.addIp(targetPlayer);
  281. +                 activeChar.sendMessage(targetPlayer.getName()+" banned permanently");
  282. +                 targetPlayer.sendMessage("You are banned permanently from " +activeChar.getName()+"!");
  283. +                 targetPlayer.sendMessage("if you will log out you won't be able to log in again!server gave you a opportunity to stay and ask for forgiveness!");
  284. +                 //targetPlayer.logout();
  285. +                 }
  286. +        }
  287. +        else if (command.startsWith("admin_removeperma"))
  288. +        {
  289. +                if (targetPlayer == null && player.equals(""))
  290. +                {
  291. +                        activeChar.sendMessage("Usage: //removeperma <char_name> (if none, target char is unbanned)");
  292. +                        return false;
  293. +                }
  294. +                 final ipCatcher ipc = new ipCatcher();
  295. +                 if(targetPlayer!=null)
  296. +                 {
  297. +                 ipc.removeIp(targetPlayer);
  298. +                 activeChar.sendMessage(targetPlayer.getName()+" permanently ban has been removed!");
  299. +                 targetPlayer.sendMessage("Your permanently ban has been removed from " +activeChar.getName()+"!");
  300. +                 }
  301. +        }
  302.         else if (command.startsWith("admin_ban_chat"))
  303.         {
  304.             if (targetPlayer == null && player.equals(""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement