Advertisement
Guest User

permanent ban coded for acis (AbsolutePower)

a guest
Aug 6th, 2013
1,572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.96 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,192 @@
  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. +                                
  65. +                               @SuppressWarnings("static-access")
  66. +                               final InetAddress ip = p.getClient().getConnection().getInetAddress().getLocalHost();
  67. +                                NetworkInterface network = NetworkInterface.getByInetAddress(ip);      
  68. +                              
  69. +                                if(network !=null)
  70. +                                {
  71. +                                        mac = network.getHardwareAddress();
  72. +                                }
  73. +                              
  74. +                                if(mac!=null)          
  75. +                                {
  76. +                                for (int i = 0; i < mac.length; i++)
  77. +                                {
  78. +                                        sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
  79. +                                }
  80. +                                }
  81. +                                else
  82. +                                        sb.append("No mac found");
  83. +                
  84. +                        }
  85. +                        catch (SocketException e)
  86. +                        {
  87. +                
  88. +                                e.printStackTrace();
  89. +                
  90. +                        }
  91. +                        catch (UnknownHostException e)
  92. +                        {
  93. +                                e.printStackTrace();
  94. +                        }
  95. +                      
  96. +                        return sb.toString();
  97. +           }
  98. +        
  99. +           public String getIp(L2PcInstance p)
  100. +           {
  101. +                    return p.getClient().getConnection().getInetAddress().getHostAddress();
  102. +           }  
  103. +          
  104. +           //return true if catched :D
  105. +           public boolean isCatched(L2PcInstance p)
  106. +           {
  107. +                        if(ips.contains(getMacAddr(p)) || ips.contains(getIp(p)))
  108. +                           return true;
  109. +                      
  110. +                        return false;
  111. +           }
  112. +          
  113. +           //make textfile if not exist
  114. +           public static void MkTiNe()
  115. +           {
  116. +                   if(file == null)
  117. +                   file.mkdirs();
  118. +           }
  119. +          
  120. +        public void addIp(L2PcInstance p)
  121. +        {
  122. +                MkTiNe();
  123. +                        final String ip = getIp(p);
  124. +                        final String name = p.getName();
  125. +                      
  126. +                        if(ip != null && name != null)
  127. +                        ips.add("Name");
  128. +                        ips.add(name);
  129. +                        ips.add("Ip");
  130. +                        ips.add(ip);
  131. +                        ips.add("Mac Addres");
  132. +                        ips.add(getMacAddr(p));
  133. +                        ips.add("-");
  134. +              
  135. +                        FileWriter s = null;
  136. +                        try
  137. +                        {
  138. +                                s = new FileWriter(file);
  139. +                                for (int i = 0; i < ips.size(); i ++)
  140. +                                {
  141. +                                        s.write(ips.get(i));
  142. +                                        s.write("\r\n");
  143. +                                }
  144. +                                s.flush();
  145. +                                s.close();
  146. +                                s = null;
  147. +                        }
  148. +                        catch (IOException e)
  149. +                        {
  150. +                                e.printStackTrace();
  151. +                        }
  152. +                        ipsLoad();
  153. +        }
  154. +
  155. +        public void removeIp(L2PcInstance p)
  156. +        {
  157. +                        final String ip = getIp(p);
  158. +                        final String name = p.getName();
  159. +                      
  160. +                        if(ip != null && name != null)
  161. +                        ips.remove("Name");
  162. +                        ips.remove(name);
  163. +                        ips.remove("Ip");
  164. +                        ips.remove(ip);
  165. +                        ips.remove("Mac Addres");
  166. +                        ips.remove(getMacAddr(p));
  167. +                        ips.remove("-");
  168. +              
  169. +                        FileWriter s = null;
  170. +                        try
  171. +                        {
  172. +                                s = new FileWriter(file);
  173. +                                for (int i = 0; i < ips.size(); i ++)
  174. +                                {
  175. +                                        s.write(ips.get(i));
  176. +                                        s.write("\r\n");
  177. +                                }
  178. +                                s.flush();
  179. +                                s.close();
  180. +                                s = null;
  181. +                        }
  182. +                        catch (IOException e)
  183. +                        {
  184. +                                e.printStackTrace();
  185. +                        }
  186. +                        ipsLoad();
  187. +        }
  188. +                
  189. +        public static void ipsLoad()
  190. +        {
  191. +                        MkTiNe();
  192. +                        LineNumberReader l = null;
  193. +                                try
  194. +                                {
  195. +                                        String line = null;
  196. +                                        l = new LineNumberReader(new FileReader(file));
  197. +                                        while ( (line = l.readLine()) != null)
  198. +                                        {
  199. +                                                StringTokenizer st = new StringTokenizer(line,"\n\r");
  200. +                                                if (st.hasMoreTokens())
  201. +                                                {
  202. +                                                        String n = st.nextToken();
  203. +                                                        ips.add(n);
  204. +                                                }                                      
  205. +                                        }      
  206. +                                }
  207. +                                catch(Exception e){
  208. +                                        e.printStackTrace();
  209. +                                }
  210. +                                finally
  211. +                                {
  212. +                                        try
  213. +                                        {
  214. +                                                if(l != null)
  215. +                                                l.close();
  216. +                                        }
  217. +                                        catch (Exception e)
  218. +                                        {
  219. +                                        }
  220. +                        }
  221. +                  }
  222. +}
  223. \ No newline at end of file
  224. Index: java/net/sf/l2j/gameserver/GameServer.java
  225. ===================================================================
  226. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 65)
  227. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  228. @@ -95,6 +95,7 @@
  229.  import net.sf.l2j.gameserver.model.L2World;
  230.  import net.sf.l2j.gameserver.model.PartyMatchRoomList;
  231.  import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
  232. +import net.sf.l2j.gameserver.model.actor.ipCatcher;
  233.  import net.sf.l2j.gameserver.model.entity.AutoAnnouncement;
  234.  import net.sf.l2j.gameserver.model.entity.Castle;
  235.  import net.sf.l2j.gameserver.model.entity.Hero;
  236. @@ -293,7 +294,8 @@
  237.         AutoAnnouncement.getInstance();
  238.         if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
  239.         OfflineTradersTable.restoreOfflineTraders();
  240. -        
  241. +       ipCatcher.ipsLoad();
  242. +      
  243.         Util.printSection("System");
  244.         TaskManager.getInstance();
  245.        
  246. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBan.java
  247. ===================================================================
  248. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBan.java   (revision 65)
  249. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBan.java   (working copy)
  250. @@ -24,6 +24,7 @@
  251.  import net.sf.l2j.gameserver.LoginServerThread;
  252.  import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  253.  import net.sf.l2j.gameserver.model.L2World;
  254. +import net.sf.l2j.gameserver.model.actor.ipCatcher;
  255.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  256.  import net.sf.l2j.gameserver.network.SystemMessageId;
  257.  import net.sf.l2j.gameserver.util.GMAudit;
  258. @@ -49,7 +50,9 @@
  259.         "admin_unban_chat",
  260.        
  261.         "admin_jail",
  262. -       "admin_unjail"
  263. +       "admin_unjail",
  264. +       "admin_permaban",
  265. +       "admin_removeperma"
  266.     };
  267.    
  268.     @Override
  269. @@ -131,6 +134,36 @@
  270.             auditAction(command, activeChar, (targetPlayer == null ? player : targetPlayer.getName()));
  271.             return changeCharAccessLevel(targetPlayer, player, activeChar, -100);
  272.         }
  273. +        else if (command.startsWith("admin_permaban"))
  274. +        {                       if (targetPlayer == null && player.equals(""))                  {
  275. +                        activeChar.sendMessage("Usage: //permaban <char_name> (if none, target char is banned)");
  276. +                        return false;
  277. +                }
  278. +                 final ipCatcher ipc = new ipCatcher();
  279. +                 if(targetPlayer!=null && !targetPlayer.isGM())
  280. +                 {
  281. +                 ipc.addIp(targetPlayer);
  282. +                 activeChar.sendMessage(targetPlayer.getName()+" banned permanently");
  283. +                 targetPlayer.sendMessage("You are banned permanently from " +activeChar.getName()+"!");
  284. +                 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!");
  285. +                 //targetPlayer.logout();
  286. +                 }
  287. +        }
  288. +        else if (command.startsWith("admin_removeperma"))
  289. +        {
  290. +                if (targetPlayer == null && player.equals(""))
  291. +                {
  292. +                        activeChar.sendMessage("Usage: //removeperma <char_name> (if none, target char is unbanned)");
  293. +                        return false;
  294. +                }
  295. +                 final ipCatcher ipc = new ipCatcher();
  296. +                 if(targetPlayer!=null)
  297. +                 {
  298. +                 ipc.removeIp(targetPlayer);
  299. +                 activeChar.sendMessage(targetPlayer.getName()+" permanently ban has been removed!");
  300. +                 targetPlayer.sendMessage("Your permanently ban has been removed from " +activeChar.getName()+"!");
  301. +                 }
  302. +        }
  303.         else if (command.startsWith("admin_ban_chat"))
  304.         {
  305.             if (targetPlayer == null && player.equals(""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement