Merged with released L2J-Unity files.
This commit is contained in:
469
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Debug.java
vendored
Normal file
469
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Debug.java
vendored
Normal file
@@ -0,0 +1,469 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.GameServer;
|
||||
import com.l2jmobius.gameserver.GameTimeController;
|
||||
import com.l2jmobius.gameserver.LoginServerThread;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.AdminData;
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2MonsterInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.AdminForgePacket;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import com.l2jmobius.gameserver.taskmanager.DecayTaskManager;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class Debug implements ITelnetCommand
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(Debug.class.getName());
|
||||
|
||||
private Debug()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "debug";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Debug <decay/packetsend/PacketTP/IOPacketTP/GeneralTP/full>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
if ((args.length == 0) || args[0].isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
switch (args[0])
|
||||
{
|
||||
case "decay":
|
||||
{
|
||||
return DecayTaskManager.getInstance().toString();
|
||||
}
|
||||
case "packetsend":
|
||||
{
|
||||
if (args.length < 4)
|
||||
{
|
||||
return "Usage: debug packetsend <charName> <packetData>";
|
||||
}
|
||||
final L2PcInstance player = L2World.getInstance().getPlayer(args[1]);
|
||||
if (player == null)
|
||||
{
|
||||
return "Couldn't find player with such name.";
|
||||
}
|
||||
|
||||
final AdminForgePacket sp = new AdminForgePacket();
|
||||
for (int i = 2; i < args.length; i++)
|
||||
{
|
||||
final String b = args[i];
|
||||
if (!b.isEmpty())
|
||||
{
|
||||
sp.addPart("C".getBytes()[0], "0x" + b);
|
||||
}
|
||||
}
|
||||
player.sendPacket(sp);
|
||||
return "Packet has been sent!";
|
||||
}
|
||||
case "PacketTP":
|
||||
{
|
||||
final String str = ThreadPoolManager.getInstance().getPacketStats();
|
||||
int i = 0;
|
||||
File f = new File("./log/StackTrace-PacketTP-" + i + ".txt");
|
||||
while (f.exists())
|
||||
{
|
||||
i++;
|
||||
f = new File("./log/StackTrace-PacketTP-" + i + ".txt");
|
||||
}
|
||||
f.getParentFile().mkdirs();
|
||||
try
|
||||
{
|
||||
Files.write(f.toPath(), str.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Couldn't write packet tp.", e);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
case "IOPacketTP":
|
||||
{
|
||||
final String str = ThreadPoolManager.getInstance().getIOPacketStats();
|
||||
int i = 0;
|
||||
File f = new File("./log/StackTrace-IOPacketTP-" + i + ".txt");
|
||||
while (f.exists())
|
||||
{
|
||||
i++;
|
||||
f = new File("./log/StackTrace-IOPacketTP-" + i + ".txt");
|
||||
}
|
||||
f.getParentFile().mkdirs();
|
||||
try
|
||||
{
|
||||
Files.write(f.toPath(), str.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Couldn't write packet tp.", e);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
case "GeneralTP":
|
||||
{
|
||||
final String str = ThreadPoolManager.getInstance().getGeneralStats();
|
||||
int i = 0;
|
||||
File f = new File("./log/StackTrace-GeneralTP-" + i + ".txt");
|
||||
while (f.exists())
|
||||
{
|
||||
i++;
|
||||
f = new File("./log/StackTrace-GeneralTP-" + i + ".txt");
|
||||
}
|
||||
f.getParentFile().mkdirs();
|
||||
try
|
||||
{
|
||||
Files.write(f.toPath(), str.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Couldn't write packet tp.", e);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
case "GeneralScheduledTP":
|
||||
{
|
||||
final String str = ThreadPoolManager.getInstance().getGeneralStats();
|
||||
int i = 0;
|
||||
File f = new File("./log/StackTrace-GeneralScheduledTP-" + i + ".txt");
|
||||
while (f.exists())
|
||||
{
|
||||
i++;
|
||||
f = new File("./log/StackTrace-GeneralScheduledTP-" + i + ".txt");
|
||||
}
|
||||
f.getParentFile().mkdirs();
|
||||
try
|
||||
{
|
||||
Files.write(f.toPath(), str.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Couldn't write packet tp.", e);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
case "full":
|
||||
{
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(sdf.format(cal.getTime()));
|
||||
sb.append("\r\nServer");
|
||||
sb.append("\r\n");
|
||||
sb.append(getServerStatus());
|
||||
sb.append("\r\n");
|
||||
sb.append("\r\n## Java Platform Information ##");
|
||||
sb.append("\r\nJava Runtime Name: " + System.getProperty("java.runtime.name"));
|
||||
sb.append("\r\nJava Version: " + System.getProperty("java.version"));
|
||||
sb.append("\r\nJava Class Version: " + System.getProperty("java.class.version"));
|
||||
sb.append("\r\n");
|
||||
sb.append("\r\n## Virtual Machine Information ##");
|
||||
sb.append("\r\nVM Name: " + System.getProperty("java.vm.name"));
|
||||
sb.append("\r\nVM Version: " + System.getProperty("java.vm.version"));
|
||||
sb.append("\r\nVM Vendor: " + System.getProperty("java.vm.vendor"));
|
||||
sb.append("\r\nVM Info: " + System.getProperty("java.vm.info"));
|
||||
sb.append("\r\n");
|
||||
sb.append("\r\n## OS Information ##");
|
||||
sb.append("\r\nName: " + System.getProperty("os.name"));
|
||||
sb.append("\r\nArchiteture: " + System.getProperty("os.arch"));
|
||||
sb.append("\r\nVersion: " + System.getProperty("os.version"));
|
||||
sb.append("\r\n");
|
||||
sb.append("\r\n## Runtime Information ##");
|
||||
sb.append("\r\nCPU Count: " + Runtime.getRuntime().availableProcessors());
|
||||
sb.append("\r\nCurrent Free Heap Size: " + (Runtime.getRuntime().freeMemory() / 1024 / 1024) + " mb");
|
||||
sb.append("\r\nCurrent Heap Size: " + (Runtime.getRuntime().totalMemory() / 1024 / 1024) + " mb");
|
||||
sb.append("\r\nMaximum Heap Size: " + (Runtime.getRuntime().maxMemory() / 1024 / 1024) + " mb");
|
||||
|
||||
sb.append("\r\n");
|
||||
sb.append("\r\n## Class Path Information ##\r\n");
|
||||
final String cp = System.getProperty("java.class.path");
|
||||
final String[] libs = cp.split(File.pathSeparator);
|
||||
for (String lib : libs)
|
||||
{
|
||||
sb.append(lib);
|
||||
sb.append("\r\n");
|
||||
}
|
||||
|
||||
sb.append("\r\n");
|
||||
sb.append("## Threads Information ##\r\n");
|
||||
final Map<Thread, StackTraceElement[]> allThread = Thread.getAllStackTraces();
|
||||
|
||||
final List<Entry<Thread, StackTraceElement[]>> entries = new ArrayList<>(allThread.entrySet());
|
||||
Collections.sort(entries, (e1, e2) -> e1.getKey().getName().compareTo(e2.getKey().getName()));
|
||||
|
||||
for (Entry<Thread, StackTraceElement[]> entry : entries)
|
||||
{
|
||||
final StackTraceElement[] stes = entry.getValue();
|
||||
final Thread t = entry.getKey();
|
||||
sb.append("--------------\r\n");
|
||||
sb.append(t.toString() + " (" + t.getId() + ")\r\n");
|
||||
sb.append("State: " + t.getState() + "\r\n");
|
||||
sb.append("isAlive: " + t.isAlive() + " | isDaemon: " + t.isDaemon() + " | isInterrupted: " + t.isInterrupted() + "\r\n");
|
||||
sb.append("\r\n");
|
||||
for (StackTraceElement ste : stes)
|
||||
{
|
||||
sb.append(ste.toString());
|
||||
sb.append("\r\n");
|
||||
}
|
||||
sb.append("\r\n");
|
||||
}
|
||||
|
||||
sb.append("\r\n");
|
||||
final ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
|
||||
final long[] ids = findDeadlockedThreads(mbean);
|
||||
if ((ids != null) && (ids.length > 0))
|
||||
{
|
||||
final Thread[] threads = new Thread[ids.length];
|
||||
for (int i = 0; i < threads.length; i++)
|
||||
{
|
||||
threads[i] = findMatchingThread(mbean.getThreadInfo(ids[i]));
|
||||
}
|
||||
sb.append("Deadlocked Threads:\r\n");
|
||||
sb.append("-------------------\r\n");
|
||||
for (Thread thread : threads)
|
||||
{
|
||||
System.err.println(thread);
|
||||
for (StackTraceElement ste : thread.getStackTrace())
|
||||
{
|
||||
sb.append("\t" + ste);
|
||||
sb.append("\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("\r\n## Thread Pool Manager Statistics ##\r\n");
|
||||
for (String line : ThreadPoolManager.getInstance().getStats())
|
||||
{
|
||||
sb.append(line);
|
||||
sb.append("\r\n");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
File f = new File("./log/Debug-" + i + ".txt");
|
||||
while (f.exists())
|
||||
{
|
||||
i++;
|
||||
f = new File("./log/Debug-" + i + ".txt");
|
||||
}
|
||||
f.getParentFile().mkdirs();
|
||||
|
||||
try
|
||||
{
|
||||
Files.write(f.toPath(), sb.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Couldn't write packet tp.", e);
|
||||
}
|
||||
return "Debug output saved to log/" + f.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private long[] findDeadlockedThreads(ThreadMXBean mbean)
|
||||
{
|
||||
// JDK 1.5 only supports the findMonitorDeadlockedThreads()
|
||||
// method, so you need to comment out the following three lines
|
||||
if (mbean.isSynchronizerUsageSupported())
|
||||
{
|
||||
return mbean.findDeadlockedThreads();
|
||||
}
|
||||
return mbean.findMonitorDeadlockedThreads();
|
||||
}
|
||||
|
||||
private Thread findMatchingThread(ThreadInfo inf)
|
||||
{
|
||||
for (Thread thread : Thread.getAllStackTraces().keySet())
|
||||
{
|
||||
if (thread.getId() == inf.getThreadId())
|
||||
{
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Deadlocked Thread not found");
|
||||
}
|
||||
|
||||
public static String getServerStatus()
|
||||
{
|
||||
int playerCount = 0, objectCount = 0;
|
||||
final int max = LoginServerThread.getInstance().getMaxPlayer();
|
||||
|
||||
playerCount = L2World.getInstance().getPlayers().size();
|
||||
objectCount = L2World.getInstance().getVisibleObjectsCount();
|
||||
|
||||
int itemCount = 0;
|
||||
int itemVoidCount = 0;
|
||||
int monsterCount = 0;
|
||||
int minionCount = 0;
|
||||
int minionsGroupCount = 0;
|
||||
int npcCount = 0;
|
||||
int charCount = 0;
|
||||
int pcCount = 0;
|
||||
int detachedCount = 0;
|
||||
int doorCount = 0;
|
||||
int summonCount = 0;
|
||||
int AICount = 0;
|
||||
|
||||
for (L2Object obj : L2World.getInstance().getVisibleObjects())
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (obj.isCharacter())
|
||||
{
|
||||
if (((L2Character) obj).hasAI())
|
||||
{
|
||||
AICount++;
|
||||
}
|
||||
}
|
||||
if (obj.isItem())
|
||||
{
|
||||
if (((L2ItemInstance) obj).getItemLocation() == ItemLocation.VOID)
|
||||
{
|
||||
itemVoidCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemCount++;
|
||||
}
|
||||
}
|
||||
else if (obj.isMonster())
|
||||
{
|
||||
monsterCount++;
|
||||
if (((L2MonsterInstance) obj).hasMinions())
|
||||
{
|
||||
minionCount += ((L2MonsterInstance) obj).getMinionList().countSpawnedMinions();
|
||||
minionsGroupCount += ((L2MonsterInstance) obj).getMinionList().lazyCountSpawnedMinionsGroups();
|
||||
}
|
||||
}
|
||||
else if (obj.isNpc())
|
||||
{
|
||||
npcCount++;
|
||||
}
|
||||
else if (obj.isPlayer())
|
||||
{
|
||||
pcCount++;
|
||||
if ((((L2PcInstance) obj).getClient() != null) && ((L2PcInstance) obj).getClient().isDetached())
|
||||
{
|
||||
detachedCount++;
|
||||
}
|
||||
}
|
||||
else if (obj.isSummon())
|
||||
{
|
||||
summonCount++;
|
||||
}
|
||||
else if (obj.isDoor())
|
||||
{
|
||||
doorCount++;
|
||||
}
|
||||
else if (obj.isCharacter())
|
||||
{
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("Server Status: ");
|
||||
sb.append("\r\n ---> Player Count: " + playerCount + "/" + max);
|
||||
sb.append("\r\n ---> Offline Count: " + detachedCount + "/" + playerCount);
|
||||
sb.append("\r\n +--> Object Count: " + objectCount);
|
||||
sb.append("\r\n +--> AI Count: " + AICount);
|
||||
sb.append("\r\n +.... L2Item(Void): " + itemVoidCount);
|
||||
sb.append("\r\n +.......... L2Item: " + itemCount);
|
||||
sb.append("\r\n +....... L2Monster: " + monsterCount);
|
||||
sb.append("\r\n +......... Minions: " + minionCount);
|
||||
sb.append("\r\n +.. Minions Groups: " + minionsGroupCount);
|
||||
sb.append("\r\n +........... L2Npc: " + npcCount);
|
||||
sb.append("\r\n +............ L2Pc: " + pcCount);
|
||||
sb.append("\r\n +........ L2Summon: " + summonCount);
|
||||
sb.append("\r\n +.......... L2Door: " + doorCount);
|
||||
sb.append("\r\n +.......... L2Char: " + charCount);
|
||||
sb.append("\r\n ---> Ingame Time: " + gameTime());
|
||||
sb.append("\r\n ---> Server Uptime: " + GameServer.getInstance().getUptime());
|
||||
sb.append("\r\n ---> GM Count: " + getOnlineGMS());
|
||||
sb.append("\r\n ---> Threads: " + Thread.activeCount());
|
||||
sb.append("\r\n RAM Used: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576)); // 1024 * 1024 = 1048576
|
||||
sb.append("\r\n");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static int getOnlineGMS()
|
||||
{
|
||||
return AdminData.getInstance().getAllGms(true).size();
|
||||
}
|
||||
|
||||
private static String gameTime()
|
||||
{
|
||||
final int t = GameTimeController.getInstance().getGameTime();
|
||||
final int h = t / 60;
|
||||
final int m = t % 60;
|
||||
final SimpleDateFormat format = new SimpleDateFormat("H:mm");
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, h);
|
||||
cal.set(Calendar.MINUTE, m);
|
||||
return format.format(cal.getTime());
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new Debug());
|
||||
}
|
||||
}
|
56
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ForceGC.java
vendored
Normal file
56
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ForceGC.java
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ForceGC implements ITelnetCommand
|
||||
{
|
||||
private ForceGC()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "forcegc";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "ForceGC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
System.gc();
|
||||
return "RAM Used: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new ForceGC());
|
||||
}
|
||||
}
|
82
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Memusage.java
vendored
Normal file
82
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Memusage.java
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class Memusage implements ITelnetCommand
|
||||
{
|
||||
private Memusage()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "memusage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "MemUsage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
final double max = Runtime.getRuntime().maxMemory() / 1024; // maxMemory is the upper
|
||||
// limit the jvm can use
|
||||
final double allocated = Runtime.getRuntime().totalMemory() / 1024; // totalMemory the
|
||||
// size of the current allocation pool
|
||||
final double nonAllocated = max - allocated; // non allocated memory till jvm limit
|
||||
final double cached = Runtime.getRuntime().freeMemory() / 1024; // freeMemory the
|
||||
// unused memory in the allocation pool
|
||||
final double used = allocated - cached; // really used memory
|
||||
final double useable = max - used; // allocated, but non-used and non-allocated memory
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
final DecimalFormat df = new DecimalFormat(" (0.0000'%')");
|
||||
final DecimalFormat df2 = new DecimalFormat(" # 'KB'");
|
||||
|
||||
sb.append("+----" + Config.EOL); // ...
|
||||
sb.append("| Allowed Memory:" + df2.format(max) + Config.EOL);
|
||||
sb.append("| |= Allocated Memory:" + df2.format(allocated) + df.format((allocated / max) * 100) + Config.EOL);
|
||||
sb.append("| |= Non-Allocated Memory:" + df2.format(nonAllocated) + df.format((nonAllocated / max) * 100) + Config.EOL);
|
||||
sb.append("| Allocated Memory:" + df2.format(allocated) + Config.EOL);
|
||||
sb.append("| |= Used Memory:" + df2.format(used) + df.format((used / max) * 100) + Config.EOL);
|
||||
sb.append("| |= Unused (cached) Memory:" + df2.format(cached) + df.format((cached / max) * 100) + Config.EOL);
|
||||
sb.append("| Useable Memory:" + df2.format(useable) + df.format((useable / max) * 100) + Config.EOL); // ...
|
||||
sb.append("+----" + Config.EOL);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new Memusage());
|
||||
}
|
||||
}
|
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Performance.java
vendored
Normal file
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Performance.java
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class Performance implements ITelnetCommand
|
||||
{
|
||||
private Performance()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "performance";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Performance";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
ThreadPoolManager.getInstance().purge();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (String line : ThreadPoolManager.getInstance().getStats())
|
||||
{
|
||||
sb.append(line + Config.EOL);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new Performance());
|
||||
}
|
||||
}
|
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Purge.java
vendored
Normal file
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Purge.java
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class Purge implements ITelnetCommand
|
||||
{
|
||||
private Purge()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "purge";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Purge";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
ThreadPoolManager.getInstance().purge();
|
||||
final StringBuilder sb = new StringBuilder("STATUS OF THREAD POOLS AFTER PURGE COMMAND:" + Config.EOL);
|
||||
for (String line : ThreadPoolManager.getInstance().getStats())
|
||||
{
|
||||
sb.append(line + Config.EOL);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new Purge());
|
||||
}
|
||||
}
|
274
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Reload.java
vendored
Normal file
274
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Reload.java
vendored
Normal file
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.cache.HtmCache;
|
||||
import com.l2jmobius.gameserver.data.sql.impl.CrestTable;
|
||||
import com.l2jmobius.gameserver.data.sql.impl.TeleportLocationTable;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.AbilityPointsData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.AdminData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.AppearanceItemData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.ArmorSetsData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.BuyListData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.DoorData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.EnchantItemData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.EnchantItemGroupsData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.ItemCrystalizationData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.MultisellData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.SayuneData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.SkillData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.TeleportersData;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.TransformData;
|
||||
import com.l2jmobius.gameserver.datatables.ItemTable;
|
||||
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.QuestManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.WalkingManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import com.l2jmobius.gameserver.scripting.ScriptEngineManager;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class Reload implements ITelnetCommand
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(Reload.class.getName());
|
||||
|
||||
private Reload()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Reload <zone/multisell/teleport/skill/npc/htm/item/config/npcwalkers/access/quests/door/primeshop/html/script>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
if ((args.length == 0) || args[0].isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
switch (args[0])
|
||||
{
|
||||
case "config":
|
||||
{
|
||||
Config.load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
|
||||
}
|
||||
case "access":
|
||||
{
|
||||
AdminData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Access.");
|
||||
}
|
||||
case "npc":
|
||||
{
|
||||
NpcData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Npcs.");
|
||||
}
|
||||
case "quest":
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
final String value = args[1];
|
||||
if (!Util.isDigit(value))
|
||||
{
|
||||
QuestManager.getInstance().reload(value);
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Quest Name:" + value + ".");
|
||||
}
|
||||
final int questId = Integer.parseInt(value);
|
||||
QuestManager.getInstance().reload(questId);
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Quest ID:" + questId + ".");
|
||||
}
|
||||
QuestManager.getInstance().reloadAllScripts();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Quests.");
|
||||
}
|
||||
case "walker":
|
||||
{
|
||||
WalkingManager.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Walkers.");
|
||||
}
|
||||
case "htm":
|
||||
case "html":
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
final String path = args[1];
|
||||
final File file = new File(Config.DATAPACK_ROOT, "data/html/" + path);
|
||||
if (file.exists())
|
||||
{
|
||||
HtmCache.getInstance().reload(file);
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Htm File:" + file.getName() + ".");
|
||||
}
|
||||
return "File or Directory does not exist.";
|
||||
}
|
||||
HtmCache.getInstance().reload();
|
||||
AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Htms.");
|
||||
return "Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded";
|
||||
}
|
||||
case "multisell":
|
||||
{
|
||||
MultisellData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Multisells.");
|
||||
}
|
||||
case "buylist":
|
||||
{
|
||||
BuyListData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Buylists.");
|
||||
}
|
||||
case "teleport":
|
||||
{
|
||||
TeleportLocationTable.getInstance().reloadAll();
|
||||
TeleportersData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Teleports.");
|
||||
}
|
||||
case "skill":
|
||||
{
|
||||
SkillData.getInstance().reload();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Skills.");
|
||||
}
|
||||
case "item":
|
||||
{
|
||||
ItemTable.getInstance().reload();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Items.");
|
||||
}
|
||||
case "door":
|
||||
{
|
||||
DoorData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Doors.");
|
||||
}
|
||||
case "zone":
|
||||
{
|
||||
ZoneManager.getInstance().reload();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Zones.");
|
||||
}
|
||||
case "cw":
|
||||
{
|
||||
CursedWeaponsManager.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Cursed Weapons.");
|
||||
}
|
||||
case "crest":
|
||||
{
|
||||
CrestTable.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Crests.");
|
||||
}
|
||||
case "effect":
|
||||
{
|
||||
try
|
||||
{
|
||||
ScriptEngineManager.getInstance().executeEffectMasterHandler();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded effect master handler.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Failed executing effect master handler!", e);
|
||||
return "Error reloading effect master handler: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
case "handler":
|
||||
{
|
||||
try
|
||||
{
|
||||
ScriptEngineManager.getInstance().executeMasterHandler();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded master handler.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Failed executing master handler!", e);
|
||||
return "Error reloading master handler: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
case "enchant":
|
||||
{
|
||||
EnchantItemGroupsData.getInstance().load();
|
||||
EnchantItemData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded item enchanting data.");
|
||||
}
|
||||
case "transform":
|
||||
{
|
||||
TransformData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded transform data.");
|
||||
}
|
||||
case "crystalizable":
|
||||
{
|
||||
ItemCrystalizationData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded item crystalization data.");
|
||||
}
|
||||
case "ability":
|
||||
{
|
||||
AbilityPointsData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded ability points data.");
|
||||
}
|
||||
case "appearance":
|
||||
{
|
||||
AppearanceItemData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded appearance item data.");
|
||||
}
|
||||
case "sayune":
|
||||
{
|
||||
SayuneData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Sayune data.");
|
||||
}
|
||||
case "sets":
|
||||
{
|
||||
ArmorSetsData.getInstance().load();
|
||||
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Armor sets data.");
|
||||
}
|
||||
case "script":
|
||||
{
|
||||
if (args.length < 2)
|
||||
{
|
||||
return "Syntax: reload script <path>";
|
||||
}
|
||||
try
|
||||
{
|
||||
ScriptEngineManager.getInstance().executeScript(Paths.get(args[1]));
|
||||
return "Script " + args[1] + " has been reloaded successfuly.";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return "Couldn't reload script: " + args[1] + " err: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new Reload());
|
||||
}
|
||||
}
|
57
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ServerAbort.java
vendored
Normal file
57
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ServerAbort.java
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import com.l2jmobius.gameserver.Shutdown;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ServerAbort implements ITelnetCommand
|
||||
{
|
||||
private ServerAbort()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "abort";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Abort";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
Shutdown.getInstance().telnetAbort(ctx.channel().remoteAddress().toString());
|
||||
return "Server shutdown/restart aborted!";
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new ServerAbort());
|
||||
}
|
||||
}
|
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ServerRestart.java
vendored
Normal file
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ServerRestart.java
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import com.l2jmobius.gameserver.Shutdown;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ServerRestart implements ITelnetCommand
|
||||
{
|
||||
private ServerRestart()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "restart";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Restart <time in seconds>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
if ((args.length == 0) || !Util.isDigit(args[0]))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final int time = Integer.parseInt(args[0]);
|
||||
Shutdown.getInstance().startTelnetShutdown(ctx.channel().remoteAddress().toString(), time, true);
|
||||
return "Server will restart in " + time + " seconds!";
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new ServerRestart());
|
||||
}
|
||||
}
|
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ServerShutdown.java
vendored
Normal file
63
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ServerShutdown.java
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import com.l2jmobius.gameserver.Shutdown;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ServerShutdown implements ITelnetCommand
|
||||
{
|
||||
private ServerShutdown()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "shutdown";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Shutdown <time in seconds>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
if ((args.length == 0) || !Util.isDigit(args[0]))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final int time = Integer.parseInt(args[0]);
|
||||
Shutdown.getInstance().startTelnetShutdown(ctx.channel().remoteAddress().toString(), time, false);
|
||||
return "Server will shutdown in " + time + " seconds!";
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new ServerShutdown());
|
||||
}
|
||||
}
|
55
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Status.java
vendored
Normal file
55
trunk/dist/game/data/scripts/handlers/telnethandlers/server/Status.java
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class Status implements ITelnetCommand
|
||||
{
|
||||
private Status()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "status";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "Status";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
return Debug.getServerStatus();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new Status());
|
||||
}
|
||||
}
|
177
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ThreadPoolDebug.java
vendored
Normal file
177
trunk/dist/game/data/scripts/handlers/telnethandlers/server/ThreadPoolDebug.java
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.telnethandlers.server;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager.RunnableWrapper;
|
||||
import com.l2jmobius.gameserver.network.telnet.ITelnetCommand;
|
||||
import com.l2jmobius.gameserver.network.telnet.TelnetServer;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ThreadPoolDebug implements ITelnetCommand
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(ThreadPoolDebug.class.getName());
|
||||
|
||||
@Override
|
||||
public String getCommand()
|
||||
{
|
||||
return "threadpooldebug";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return "threadpooldebug [effect, general, ai, events]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(ChannelHandlerContext ctx, String[] args)
|
||||
{
|
||||
String pool = "_generalScheduledThreadPool";
|
||||
if (args.length > 0)
|
||||
{
|
||||
switch (args[0])
|
||||
{
|
||||
case "effect":
|
||||
{
|
||||
pool = "_effectsScheduledThreadPool";
|
||||
break;
|
||||
}
|
||||
case "general":
|
||||
{
|
||||
pool = "_generalScheduledThreadPool";
|
||||
break;
|
||||
}
|
||||
case "ai":
|
||||
{
|
||||
pool = "_aiScheduledThreadPool";
|
||||
break;
|
||||
}
|
||||
case "events":
|
||||
{
|
||||
pool = "_eventScheduledThreadPool";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return args[0] + " is not implemented!";
|
||||
}
|
||||
}
|
||||
}
|
||||
final ScheduledThreadPoolExecutor executor = getObject(ThreadPoolManager.class, ThreadPoolManager.getInstance(), pool, ScheduledThreadPoolExecutor.class);
|
||||
if (executor == null)
|
||||
{
|
||||
return "Couldn't retreive " + pool + "!";
|
||||
}
|
||||
|
||||
Class<?> adapterClass;
|
||||
try
|
||||
{
|
||||
adapterClass = Class.forName("java.util.concurrent.Executors$RunnableAdapter");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.getMessage();
|
||||
}
|
||||
|
||||
final Map<String, Integer> tasks = new HashMap<>();
|
||||
for (Runnable run : executor.getQueue())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (run instanceof FutureTask)
|
||||
{
|
||||
final Object callableObject = getObject(FutureTask.class, run, "callable", Object.class);
|
||||
final Object taskObject = getObject(adapterClass, callableObject, "task", Object.class);
|
||||
|
||||
if (taskObject instanceof RunnableWrapper)
|
||||
{
|
||||
final Runnable task = getObject(RunnableWrapper.class, taskObject, "_r", Runnable.class);
|
||||
final String name = task.getClass().getName();
|
||||
final int times = tasks.containsKey(name) ? tasks.get(name) : 0;
|
||||
tasks.put(name, times + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(pool + " queue size: " + executor.getQueue().size() + Config.EOL);
|
||||
|
||||
tasks.entrySet().stream().sorted(Comparator.comparingInt(Entry::getValue)).forEach(entry -> sb.append("Class: " + entry.getKey() + " = " + entry.getValue() + Config.EOL));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static final <T> T getObject(Class<?> sourceClass, Object sourceInstance, String fieldName, Class<T> targetClass)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Field field = sourceClass.getDeclaredField(fieldName);
|
||||
|
||||
// Mark down if field was accessible
|
||||
final boolean isAccessible = field.isAccessible();
|
||||
|
||||
// Enforce accessible to retrieve the object associated with this field
|
||||
if (!isAccessible)
|
||||
{
|
||||
field.setAccessible(true);
|
||||
}
|
||||
|
||||
// Get the object
|
||||
final Object fieldObject = field.get(sourceInstance);
|
||||
|
||||
// Restore the original accessible state.
|
||||
field.setAccessible(isAccessible);
|
||||
|
||||
// Make sure the object is the one we expect to be
|
||||
if (targetClass.isInstance(fieldObject))
|
||||
{
|
||||
return targetClass.cast(fieldObject);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Error while retrieving object of " + sourceInstance.getClass().getName() + "." + fieldName, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
TelnetServer.getInstance().addHandler(new ThreadPoolDebug());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user