This commit is contained in:
114
trunk/dist/game/data/scripts/handlers/telnethandlers/ChatsHandler.java
vendored
Normal file
114
trunk/dist/game/data/scripts/handlers/telnethandlers/ChatsHandler.java
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.l2jserver.gameserver.datatables.AdminTable;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.network.clientpackets.Say2;
|
||||
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
|
||||
import com.l2jserver.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ChatsHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"announce",
|
||||
"msg",
|
||||
"gmchat"
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.startsWith("announce"))
|
||||
{
|
||||
try
|
||||
{
|
||||
command = command.substring(9);
|
||||
Broadcast.toAllOnlinePlayers(command);
|
||||
_print.println("Announcement Sent!");
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please Enter Some Text To Announce!");
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("msg"))
|
||||
{
|
||||
try
|
||||
{
|
||||
String val = command.substring(4);
|
||||
StringTokenizer st = new StringTokenizer(val);
|
||||
String name = st.nextToken();
|
||||
String message = val.substring(name.length() + 1);
|
||||
L2PcInstance reciever = L2World.getInstance().getPlayer(name);
|
||||
CreatureSay cs = new CreatureSay(0, Say2.TELL, "Telnet Priv", message);
|
||||
if (reciever != null)
|
||||
{
|
||||
reciever.sendPacket(cs);
|
||||
_print.println("Telnet Priv->" + name + ": " + message);
|
||||
_print.println("Message Sent!");
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("Unable To Find Username: " + name);
|
||||
}
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please Enter Some Text!");
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("gmchat"))
|
||||
{
|
||||
try
|
||||
{
|
||||
command = command.substring(7);
|
||||
CreatureSay cs = new CreatureSay(0, Say2.ALLIANCE, "Telnet GM Broadcast from " + _cSocket.getInetAddress().getHostAddress(), command);
|
||||
AdminTable.getInstance().broadcastToGMs(cs);
|
||||
_print.println("Your Message Has Been Sent To " + getOnlineGMS() + " GM(s).");
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please Enter Some Text To Announce!");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getOnlineGMS()
|
||||
{
|
||||
return AdminTable.getInstance().getAllGms(true).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
497
trunk/dist/game/data/scripts/handlers/telnethandlers/DebugHandler.java
vendored
Normal file
497
trunk/dist/game/data/scripts/handlers/telnethandlers/DebugHandler.java
vendored
Normal file
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.net.Socket;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javolution.util.FastComparator;
|
||||
import javolution.util.FastTable;
|
||||
|
||||
import com.l2jserver.gameserver.GameTimeController;
|
||||
import com.l2jserver.gameserver.LoginServerThread;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.datatables.AdminTable;
|
||||
import com.l2jserver.gameserver.enums.ItemLocation;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Npc;
|
||||
import com.l2jserver.gameserver.model.actor.L2Summon;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jserver.gameserver.network.serverpackets.AdminForgePacket;
|
||||
import com.l2jserver.gameserver.taskmanager.DecayTaskManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class DebugHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"debug"
|
||||
};
|
||||
|
||||
private int uptime = 0;
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.startsWith("debug") && (command.length() > 6))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(command.substring(6));
|
||||
// TODO: Rewrite to use ARM.
|
||||
FileOutputStream fos = null;
|
||||
OutputStreamWriter out = null;
|
||||
try
|
||||
{
|
||||
String dbg = st.nextToken();
|
||||
|
||||
if (dbg.equals("decay"))
|
||||
{
|
||||
_print.print(DecayTaskManager.getInstance().toString());
|
||||
}
|
||||
else if (dbg.equals("packetsend"))
|
||||
{
|
||||
if (st.countTokens() < 2)
|
||||
{
|
||||
_print.println("Usage: debug packetsend <charName> <packetData>");
|
||||
return false;
|
||||
}
|
||||
String charName = st.nextToken();
|
||||
L2PcInstance targetPlayer = L2World.getInstance().getPlayer(charName);
|
||||
|
||||
if (targetPlayer == null)
|
||||
{
|
||||
_print.println("Player " + charName + " cannot be found online");
|
||||
return false;
|
||||
}
|
||||
|
||||
AdminForgePacket sp = new AdminForgePacket();
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
String b = st.nextToken();
|
||||
if (!b.isEmpty())
|
||||
{
|
||||
sp.addPart("C".getBytes()[0], "0x" + b);
|
||||
}
|
||||
}
|
||||
|
||||
targetPlayer.sendPacket(sp);
|
||||
_print.println("Packet sent to player " + charName);
|
||||
}
|
||||
else if (dbg.equals("PacketTP"))
|
||||
{
|
||||
String str = ThreadPoolManager.getInstance().getPacketStats();
|
||||
_print.println(str);
|
||||
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();
|
||||
fos = new FileOutputStream(f);
|
||||
out = new OutputStreamWriter(fos, "UTF-8");
|
||||
out.write(str);
|
||||
}
|
||||
else if (dbg.equals("IOPacketTP"))
|
||||
{
|
||||
String str = ThreadPoolManager.getInstance().getIOPacketStats();
|
||||
_print.println(str);
|
||||
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();
|
||||
fos = new FileOutputStream(f);
|
||||
out = new OutputStreamWriter(fos, "UTF-8");
|
||||
out.write(str);
|
||||
}
|
||||
else if (dbg.equals("GeneralTP"))
|
||||
{
|
||||
String str = ThreadPoolManager.getInstance().getGeneralStats();
|
||||
_print.println(str);
|
||||
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();
|
||||
fos = new FileOutputStream(f);
|
||||
out = new OutputStreamWriter(fos, "UTF-8");
|
||||
out.write(str);
|
||||
}
|
||||
else if (dbg.equals("full"))
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(sdf.format(cal.getTime()));
|
||||
sb.append("\n\n");
|
||||
uptime = _uptime;
|
||||
sb.append(getServerStatus());
|
||||
sb.append("\n\n");
|
||||
sb.append("\n## Java Platform Information ##");
|
||||
sb.append("\nJava Runtime Name: " + System.getProperty("java.runtime.name"));
|
||||
sb.append("\nJava Version: " + System.getProperty("java.version"));
|
||||
sb.append("\nJava Class Version: " + System.getProperty("java.class.version"));
|
||||
sb.append('\n');
|
||||
sb.append("\n## Virtual Machine Information ##");
|
||||
sb.append("\nVM Name: " + System.getProperty("java.vm.name"));
|
||||
sb.append("\nVM Version: " + System.getProperty("java.vm.version"));
|
||||
sb.append("\nVM Vendor: " + System.getProperty("java.vm.vendor"));
|
||||
sb.append("\nVM Info: " + System.getProperty("java.vm.info"));
|
||||
sb.append('\n');
|
||||
sb.append("\n## OS Information ##");
|
||||
sb.append("\nName: " + System.getProperty("os.name"));
|
||||
sb.append("\nArchiteture: " + System.getProperty("os.arch"));
|
||||
sb.append("\nVersion: " + System.getProperty("os.version"));
|
||||
sb.append('\n');
|
||||
sb.append("\n## Runtime Information ##");
|
||||
sb.append("\nCPU Count: " + Runtime.getRuntime().availableProcessors());
|
||||
sb.append("\nCurrent Free Heap Size: " + (Runtime.getRuntime().freeMemory() / 1024 / 1024) + " mb");
|
||||
sb.append("\nCurrent Heap Size: " + (Runtime.getRuntime().totalMemory() / 1024 / 1024) + " mb");
|
||||
sb.append("\nMaximum Heap Size: " + (Runtime.getRuntime().maxMemory() / 1024 / 1024) + " mb");
|
||||
|
||||
sb.append('\n');
|
||||
sb.append("\n## Class Path Information ##\n");
|
||||
String cp = System.getProperty("java.class.path");
|
||||
String[] libs = cp.split(File.pathSeparator);
|
||||
for (String lib : libs)
|
||||
{
|
||||
sb.append(lib);
|
||||
sb.append('\n');
|
||||
}
|
||||
|
||||
sb.append('\n');
|
||||
sb.append("## Threads Information ##\n");
|
||||
Map<Thread, StackTraceElement[]> allThread = Thread.getAllStackTraces();
|
||||
|
||||
FastTable<Entry<Thread, StackTraceElement[]>> entries = new FastTable<>();
|
||||
entries.setValueComparator(new FastComparator<Entry<Thread, StackTraceElement[]>>()
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean areEqual(Entry<Thread, StackTraceElement[]> e1, Entry<Thread, StackTraceElement[]> e2)
|
||||
{
|
||||
return e1.getKey().getName().equals(e2.getKey().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Entry<Thread, StackTraceElement[]> e1, Entry<Thread, StackTraceElement[]> e2)
|
||||
{
|
||||
return e1.getKey().getName().compareTo(e2.getKey().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCodeOf(Entry<Thread, StackTraceElement[]> e)
|
||||
{
|
||||
return e.hashCode();
|
||||
}
|
||||
|
||||
});
|
||||
entries.addAll(allThread.entrySet());
|
||||
entries.sort();
|
||||
for (Entry<Thread, StackTraceElement[]> entry : entries)
|
||||
{
|
||||
StackTraceElement[] stes = entry.getValue();
|
||||
Thread t = entry.getKey();
|
||||
sb.append("--------------\n");
|
||||
sb.append(t.toString() + " (" + t.getId() + ")\n");
|
||||
sb.append("State: " + t.getState() + '\n');
|
||||
sb.append("isAlive: " + t.isAlive() + " | isDaemon: " + t.isDaemon() + " | isInterrupted: " + t.isInterrupted() + '\n');
|
||||
sb.append('\n');
|
||||
for (StackTraceElement ste : stes)
|
||||
{
|
||||
sb.append(ste.toString());
|
||||
sb.append('\n');
|
||||
}
|
||||
sb.append('\n');
|
||||
}
|
||||
|
||||
sb.append('\n');
|
||||
ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
|
||||
long[] ids = findDeadlockedThreads(mbean);
|
||||
if ((ids != null) && (ids.length > 0))
|
||||
{
|
||||
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:\n");
|
||||
sb.append("-------------------\n");
|
||||
for (Thread thread : threads)
|
||||
{
|
||||
System.err.println(thread);
|
||||
for (StackTraceElement ste : thread.getStackTrace())
|
||||
{
|
||||
sb.append("\t" + ste);
|
||||
sb.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("\n\n## Thread Pool Manager Statistics ##\n");
|
||||
for (String line : ThreadPoolManager.getInstance().getStats())
|
||||
{
|
||||
sb.append(line);
|
||||
sb.append('\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();
|
||||
fos = new FileOutputStream(f);
|
||||
out = new OutputStreamWriter(fos, "UTF-8");
|
||||
out.write(sb.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
fos.close();
|
||||
|
||||
_print.println("Debug output saved to log/" + f.getName());
|
||||
_print.flush();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (out != null)
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (fos != null)
|
||||
{
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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 String getServerStatus()
|
||||
{
|
||||
int playerCount = 0, objectCount = 0;
|
||||
int max = LoginServerThread.getInstance().getMaxPlayer();
|
||||
|
||||
playerCount = L2World.getInstance().getAllPlayersCount();
|
||||
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 instanceof L2Character)
|
||||
{
|
||||
if (((L2Character) obj).hasAI())
|
||||
{
|
||||
AICount++;
|
||||
}
|
||||
}
|
||||
if (obj instanceof L2ItemInstance)
|
||||
{
|
||||
if (((L2ItemInstance) obj).getItemLocation() == ItemLocation.VOID)
|
||||
{
|
||||
itemVoidCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemCount++;
|
||||
}
|
||||
}
|
||||
else if (obj instanceof L2MonsterInstance)
|
||||
{
|
||||
monsterCount++;
|
||||
if (((L2MonsterInstance) obj).hasMinions())
|
||||
{
|
||||
minionCount += ((L2MonsterInstance) obj).getMinionList().countSpawnedMinions();
|
||||
minionsGroupCount += ((L2MonsterInstance) obj).getMinionList().lazyCountSpawnedMinionsGroups();
|
||||
}
|
||||
}
|
||||
else if (obj instanceof L2Npc)
|
||||
{
|
||||
npcCount++;
|
||||
}
|
||||
else if (obj instanceof L2PcInstance)
|
||||
{
|
||||
pcCount++;
|
||||
if ((((L2PcInstance) obj).getClient() != null) && ((L2PcInstance) obj).getClient().isDetached())
|
||||
{
|
||||
detachedCount++;
|
||||
}
|
||||
}
|
||||
else if (obj instanceof L2Summon)
|
||||
{
|
||||
summonCount++;
|
||||
}
|
||||
else if (obj instanceof L2DoorInstance)
|
||||
{
|
||||
doorCount++;
|
||||
}
|
||||
else if (obj instanceof L2Character)
|
||||
{
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
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: " + getUptime(uptime));
|
||||
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 int getOnlineGMS()
|
||||
{
|
||||
return AdminTable.getInstance().getAllGms(true).size();
|
||||
}
|
||||
|
||||
private String getUptime(int time)
|
||||
{
|
||||
int uptime = (int) System.currentTimeMillis() - time;
|
||||
uptime = uptime / 1000;
|
||||
int h = uptime / 3600;
|
||||
int m = (uptime - (h * 3600)) / 60;
|
||||
int s = ((uptime - (h * 3600)) - (m * 60));
|
||||
return h + "hrs " + m + "mins " + s + "secs";
|
||||
}
|
||||
|
||||
private String gameTime()
|
||||
{
|
||||
int t = GameTimeController.getInstance().getGameTime();
|
||||
int h = t / 60;
|
||||
int m = t % 60;
|
||||
SimpleDateFormat format = new SimpleDateFormat("H:mm");
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, h);
|
||||
cal.set(Calendar.MINUTE, m);
|
||||
return format.format(cal.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
83
trunk/dist/game/data/scripts/handlers/telnethandlers/HelpHandler.java
vendored
Normal file
83
trunk/dist/game/data/scripts/handlers/telnethandlers/HelpHandler.java
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class HelpHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"help"
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.equals("help"))
|
||||
{
|
||||
_print.println("The following is a list of all available commands: ");
|
||||
_print.println("help - shows this help.");
|
||||
_print.println("status - displays basic server statistics.");
|
||||
_print.println("gamestat privatestore - displays info about stores");
|
||||
_print.println("performance - shows server performance statistics.");
|
||||
_print.println("forcegc - forced garbage collection.");
|
||||
_print.println("purge - removes finished threads from thread pools.");
|
||||
_print.println("memusage - displays memory amounts in JVM.");
|
||||
_print.println("announce <text> - announces <text> in game.");
|
||||
_print.println("msg <nick> <text> - Sends a whisper to char <nick> with <text>.");
|
||||
_print.println("gmchat <text> - Sends a message to all GMs with <text>.");
|
||||
_print.println("gmlist - lists all gms online.");
|
||||
_print.println("kick - kick player <name> from server.");
|
||||
_print.println("shutdown <time> - shuts down server in <time> seconds.");
|
||||
_print.println("restart <time> - restarts down server in <time> seconds.");
|
||||
_print.println("abort - aborts shutdown/restart.");
|
||||
_print.println("give <player> <itemid> <amount>");
|
||||
_print.println("enchant <player> <itemType> <enchant> (itemType: 1 - Helmet, 2 - Chest, 3 - Gloves, 4 - Feet, 5 - Legs, 6 - Right Hand, 7 - Left Hand, 8 - Left Ear, 9 - Right Ear , 10 - Left Finger, 11 - Right Finger, 12- Necklace, 13 - Underwear, 14 - Back, 15 - Belt, 0 - No Enchant)");
|
||||
_print.println("debug <cmd> - executes the debug command (see 'help debug').");
|
||||
_print.println("reload <type> - reload data");
|
||||
_print.println("jail <player> [time]");
|
||||
_print.println("unjail <player>");
|
||||
_print.println("quit - closes telnet session.");
|
||||
}
|
||||
else if (command.equals("help debug"))
|
||||
{
|
||||
_print.println("The following is a list of all available debug commands: ");
|
||||
_print.println("full - Dumps complete debug information to an file (recommended)");
|
||||
_print.println("decay - prints info about the DecayManager");
|
||||
_print.println("packetsend - Send packet data to a player");
|
||||
_print.println("PacketTP - prints info about the General Packet ThreadPool");
|
||||
_print.println("IOPacketTP - prints info about the I/O Packet ThreadPool");
|
||||
_print.println("GeneralTP - prints info about the General ThreadPool");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
342
trunk/dist/game/data/scripts/handlers/telnethandlers/PlayerHandler.java
vendored
Normal file
342
trunk/dist/game/data/scripts/handlers/telnethandlers/PlayerHandler.java
vendored
Normal file
@@ -0,0 +1,342 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.datatables.CharNameTable;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
import com.l2jserver.gameserver.instancemanager.PunishmentManager;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.itemcontainer.Inventory;
|
||||
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
|
||||
import com.l2jserver.gameserver.model.punishment.PunishmentTask;
|
||||
import com.l2jserver.gameserver.model.punishment.PunishmentType;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.gameserver.network.serverpackets.CharInfo;
|
||||
import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
|
||||
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
||||
import com.l2jserver.gameserver.network.serverpackets.UserInfo;
|
||||
import com.l2jserver.gameserver.util.GMAudit;
|
||||
import com.l2jserver.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class PlayerHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"kick",
|
||||
"give",
|
||||
"enchant",
|
||||
"jail",
|
||||
"unjail"
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.startsWith("kick"))
|
||||
{
|
||||
try
|
||||
{
|
||||
command = command.substring(5);
|
||||
L2PcInstance player = L2World.getInstance().getPlayer(command);
|
||||
if (player != null)
|
||||
{
|
||||
player.sendMessage("You are kicked by gm");
|
||||
player.logout();
|
||||
_print.println("Player kicked");
|
||||
}
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please enter player name to kick");
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("give"))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(command.substring(5));
|
||||
|
||||
try
|
||||
{
|
||||
L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
|
||||
int itemId = Integer.parseInt(st.nextToken());
|
||||
int amount = Integer.parseInt(st.nextToken());
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
L2ItemInstance item = player.getInventory().addItem("Status-Give", itemId, amount, null, null);
|
||||
InventoryUpdate iu = new InventoryUpdate();
|
||||
iu.addItem(item);
|
||||
player.sendPacket(iu);
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1);
|
||||
sm.addItemName(itemId);
|
||||
sm.addLong(amount);
|
||||
player.sendPacket(sm);
|
||||
_print.println("ok");
|
||||
GMAudit.auditGMAction("Telnet Admin", "Give Item", player.getName(), "item: " + itemId + " amount: " + amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("Player not found");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("enchant"))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(command.substring(8), " ");
|
||||
int enchant = 0, itemType = 0;
|
||||
|
||||
try
|
||||
{
|
||||
L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
|
||||
itemType = Integer.parseInt(st.nextToken());
|
||||
enchant = Integer.parseInt(st.nextToken());
|
||||
|
||||
switch (itemType)
|
||||
{
|
||||
case 1:
|
||||
itemType = Inventory.PAPERDOLL_HEAD;
|
||||
break;
|
||||
case 2:
|
||||
itemType = Inventory.PAPERDOLL_CHEST;
|
||||
break;
|
||||
case 3:
|
||||
itemType = Inventory.PAPERDOLL_GLOVES;
|
||||
break;
|
||||
case 4:
|
||||
itemType = Inventory.PAPERDOLL_FEET;
|
||||
break;
|
||||
case 5:
|
||||
itemType = Inventory.PAPERDOLL_LEGS;
|
||||
break;
|
||||
case 6:
|
||||
itemType = Inventory.PAPERDOLL_RHAND;
|
||||
break;
|
||||
case 7:
|
||||
itemType = Inventory.PAPERDOLL_LHAND;
|
||||
break;
|
||||
case 8:
|
||||
itemType = Inventory.PAPERDOLL_LEAR;
|
||||
break;
|
||||
case 9:
|
||||
itemType = Inventory.PAPERDOLL_REAR;
|
||||
break;
|
||||
case 10:
|
||||
itemType = Inventory.PAPERDOLL_LFINGER;
|
||||
break;
|
||||
case 11:
|
||||
itemType = Inventory.PAPERDOLL_RFINGER;
|
||||
break;
|
||||
case 12:
|
||||
itemType = Inventory.PAPERDOLL_NECK;
|
||||
break;
|
||||
case 13:
|
||||
itemType = Inventory.PAPERDOLL_UNDER;
|
||||
break;
|
||||
case 14:
|
||||
itemType = Inventory.PAPERDOLL_CLOAK;
|
||||
break;
|
||||
case 15:
|
||||
itemType = Inventory.PAPERDOLL_BELT;
|
||||
break;
|
||||
default:
|
||||
itemType = 0;
|
||||
}
|
||||
|
||||
if (enchant > 65535)
|
||||
{
|
||||
enchant = 65535;
|
||||
}
|
||||
else if (enchant < 0)
|
||||
{
|
||||
enchant = 0;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
|
||||
if ((player != null) && (itemType > 0))
|
||||
{
|
||||
success = setEnchant(player, enchant, itemType);
|
||||
if (success)
|
||||
{
|
||||
_print.println("Item enchanted successfully.");
|
||||
}
|
||||
}
|
||||
else if (!success)
|
||||
{
|
||||
_print.println("Item failed to enchant.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("jail"))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(command.substring(5));
|
||||
try
|
||||
{
|
||||
String name = st.nextToken();
|
||||
int charId = CharNameTable.getInstance().getIdByName(name);
|
||||
int delay = 0;
|
||||
String reason = "";
|
||||
if (st.hasMoreTokens())
|
||||
{
|
||||
String token = st.nextToken();
|
||||
if (Util.isDigit(token))
|
||||
{
|
||||
delay = Integer.parseInt(token);
|
||||
}
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
reason += st.nextToken() + " ";
|
||||
}
|
||||
if (!reason.isEmpty())
|
||||
{
|
||||
reason = reason.substring(0, reason.length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (charId > 0)
|
||||
{
|
||||
long expirationTime = delay > 0 ? System.currentTimeMillis() + (delay * 60 * 1000) : -1;
|
||||
PunishmentManager.getInstance().startPunishment(new PunishmentTask(charId, PunishmentAffect.CHARACTER, PunishmentType.JAIL, expirationTime, reason, "Telnet Admin: " + _cSocket.getInetAddress().getHostAddress()));
|
||||
_print.println("Character " + name + " jailed for " + (delay > 0 ? delay + " minutes." : "ever!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("Character with name: " + name + " was not found!");
|
||||
}
|
||||
}
|
||||
catch (NoSuchElementException nsee)
|
||||
{
|
||||
_print.println("Specify a character name.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Config.DEBUG)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("unjail"))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(command.substring(7));
|
||||
try
|
||||
{
|
||||
String name = st.nextToken();
|
||||
int charId = CharNameTable.getInstance().getIdByName(name);
|
||||
|
||||
if (charId > 0)
|
||||
{
|
||||
PunishmentManager.getInstance().stopPunishment(charId, PunishmentAffect.CHARACTER, PunishmentType.JAIL);
|
||||
_print.println("Character " + name + " have been unjailed");
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println("Character with name: " + name + " was not found!");
|
||||
}
|
||||
}
|
||||
catch (NoSuchElementException nsee)
|
||||
{
|
||||
_print.println("Specify a character name.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Config.DEBUG)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean setEnchant(L2PcInstance activeChar, int ench, int armorType)
|
||||
{
|
||||
// now we need to find the equipped weapon of the targeted character...
|
||||
int curEnchant = 0; // display purposes only
|
||||
L2ItemInstance itemInstance = null;
|
||||
|
||||
// only attempt to enchant if there is a weapon equipped
|
||||
L2ItemInstance parmorInstance = activeChar.getInventory().getPaperdollItem(armorType);
|
||||
if ((parmorInstance != null) && (parmorInstance.getLocationSlot() == armorType))
|
||||
{
|
||||
itemInstance = parmorInstance;
|
||||
}
|
||||
else
|
||||
{
|
||||
// for bows/crossbows and double handed weapons
|
||||
parmorInstance = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
|
||||
if ((parmorInstance != null) && (parmorInstance.getLocationSlot() == Inventory.PAPERDOLL_RHAND))
|
||||
{
|
||||
itemInstance = parmorInstance;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemInstance != null)
|
||||
{
|
||||
curEnchant = itemInstance.getEnchantLevel();
|
||||
|
||||
// set enchant value
|
||||
activeChar.getInventory().unEquipItemInSlot(armorType);
|
||||
itemInstance.setEnchantLevel(ench);
|
||||
activeChar.getInventory().equipItem(itemInstance);
|
||||
|
||||
// send packets
|
||||
InventoryUpdate iu = new InventoryUpdate();
|
||||
iu.addModifiedItem(itemInstance);
|
||||
activeChar.sendPacket(iu);
|
||||
activeChar.broadcastPacket(new CharInfo(activeChar));
|
||||
activeChar.sendPacket(new UserInfo(activeChar));
|
||||
activeChar.broadcastPacket(new ExBrExtraUserInfo(activeChar));
|
||||
|
||||
// informations
|
||||
activeChar.sendMessage("Changed enchantment of " + activeChar.getName() + "'s " + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
|
||||
activeChar.sendMessage("Admin has changed the enchantment of your " + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
|
||||
|
||||
// log
|
||||
GMAudit.auditGMAction("TelnetAdministrator", "enchant", activeChar.getName(), itemInstance.getItem().getName() + "(" + itemInstance.getObjectId() + ")" + " from " + curEnchant + " to " + ench);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
164
trunk/dist/game/data/scripts/handlers/telnethandlers/ReloadHandler.java
vendored
Normal file
164
trunk/dist/game/data/scripts/handlers/telnethandlers/ReloadHandler.java
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import com.l2jserver.gameserver.cache.HtmCache;
|
||||
import com.l2jserver.gameserver.datatables.ItemTable;
|
||||
import com.l2jserver.gameserver.datatables.MultisellData;
|
||||
import com.l2jserver.gameserver.datatables.NpcData;
|
||||
import com.l2jserver.gameserver.datatables.SkillData;
|
||||
import com.l2jserver.gameserver.datatables.SpawnTable;
|
||||
import com.l2jserver.gameserver.datatables.TeleportLocationTable;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
import com.l2jserver.gameserver.instancemanager.DayNightSpawnManager;
|
||||
import com.l2jserver.gameserver.instancemanager.QuestManager;
|
||||
import com.l2jserver.gameserver.instancemanager.RaidBossSpawnManager;
|
||||
import com.l2jserver.gameserver.instancemanager.ZoneManager;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ReloadHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"reload"
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.startsWith("reload"))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(command.substring(7));
|
||||
try
|
||||
{
|
||||
String type = st.nextToken();
|
||||
|
||||
if (type.equals("multisell"))
|
||||
{
|
||||
_print.print("Reloading multisell... ");
|
||||
MultisellData.getInstance().load();
|
||||
_print.println("done");
|
||||
}
|
||||
else if (type.equals("skill"))
|
||||
{
|
||||
_print.print("Reloading skills... ");
|
||||
SkillData.getInstance().reload();
|
||||
_print.println("done");
|
||||
}
|
||||
else if (type.equals("npc"))
|
||||
{
|
||||
_print.print("Reloading npc templates... ");
|
||||
NpcData.getInstance().load();
|
||||
QuestManager.getInstance().reloadAllScripts();
|
||||
_print.println("done");
|
||||
}
|
||||
else if (type.equals("html"))
|
||||
{
|
||||
_print.print("Reloading html cache... ");
|
||||
HtmCache.getInstance().reload();
|
||||
_print.println("done");
|
||||
}
|
||||
else if (type.equals("item"))
|
||||
{
|
||||
_print.print("Reloading item templates... ");
|
||||
ItemTable.getInstance().reload();
|
||||
_print.println("done");
|
||||
}
|
||||
else if (type.equals("zone"))
|
||||
{
|
||||
_print.print("Reloading zone tables... ");
|
||||
ZoneManager.getInstance().reload();
|
||||
_print.println("done");
|
||||
}
|
||||
else if (type.equals("teleports"))
|
||||
{
|
||||
_print.print("Reloading telport location table... ");
|
||||
TeleportLocationTable.getInstance().reloadAll();
|
||||
_print.println("done");
|
||||
}
|
||||
else if (type.equals("spawns"))
|
||||
{
|
||||
_print.print("Reloading spawns... ");
|
||||
RaidBossSpawnManager.getInstance().cleanUp();
|
||||
DayNightSpawnManager.getInstance().cleanUp();
|
||||
L2World.getInstance().deleteVisibleNpcSpawns();
|
||||
NpcData.getInstance().load();
|
||||
SpawnTable.getInstance().load();
|
||||
RaidBossSpawnManager.getInstance().load();
|
||||
_print.println("done\n");
|
||||
}
|
||||
else if (type.equalsIgnoreCase("script"))
|
||||
{
|
||||
try
|
||||
{
|
||||
String questPath = st.hasMoreTokens() ? st.nextToken() : "";
|
||||
|
||||
File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, questPath);
|
||||
if (file.isFile())
|
||||
{
|
||||
try
|
||||
{
|
||||
L2ScriptEngineManager.getInstance().executeScript(file);
|
||||
_print.println(file.getName() + " was successfully loaded!\n");
|
||||
}
|
||||
catch (ScriptException e)
|
||||
{
|
||||
_print.println("Failed loading: " + questPath);
|
||||
L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_print.println("Failed loading: " + questPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_print.println(file.getName() + " is not a file in: " + questPath);
|
||||
}
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please Enter Some Text!");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
91
trunk/dist/game/data/scripts/handlers/telnethandlers/ServerHandler.java
vendored
Normal file
91
trunk/dist/game/data/scripts/handlers/telnethandlers/ServerHandler.java
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
|
||||
import com.l2jserver.gameserver.Shutdown;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ServerHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"shutdown",
|
||||
"restart",
|
||||
"abort"
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.startsWith("shutdown"))
|
||||
{
|
||||
try
|
||||
{
|
||||
int val = Integer.parseInt(command.substring(9));
|
||||
Shutdown.getInstance().startTelnetShutdown(_cSocket.getInetAddress().getHostAddress(), val, false);
|
||||
_print.println("Server Will Shutdown In " + val + " Seconds!");
|
||||
_print.println("Type \"abort\" To Abort Shutdown!");
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please Enter * amount of seconds to shutdown!");
|
||||
}
|
||||
catch (Exception NumberFormatException)
|
||||
{
|
||||
_print.println("Numbers Only!");
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("restart"))
|
||||
{
|
||||
try
|
||||
{
|
||||
int val = Integer.parseInt(command.substring(8));
|
||||
Shutdown.getInstance().startTelnetShutdown(_cSocket.getInetAddress().getHostAddress(), val, true);
|
||||
_print.println("Server Will Restart In " + val + " Seconds!");
|
||||
_print.println("Type \"abort\" To Abort Restart!");
|
||||
}
|
||||
catch (StringIndexOutOfBoundsException e)
|
||||
{
|
||||
_print.println("Please Enter * amount of seconds to restart!");
|
||||
}
|
||||
catch (Exception NumberFormatException)
|
||||
{
|
||||
_print.println("Numbers Only!");
|
||||
}
|
||||
}
|
||||
else if (command.startsWith("abort"))
|
||||
{
|
||||
Shutdown.getInstance().telnetAbort(_cSocket.getInetAddress().getHostAddress());
|
||||
_print.println("OK! - Shutdown/Restart Aborted.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
257
trunk/dist/game/data/scripts/handlers/telnethandlers/StatusHandler.java
vendored
Normal file
257
trunk/dist/game/data/scripts/handlers/telnethandlers/StatusHandler.java
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.l2jserver.gameserver.GameTimeController;
|
||||
import com.l2jserver.gameserver.LoginServerThread;
|
||||
import com.l2jserver.gameserver.datatables.AdminTable;
|
||||
import com.l2jserver.gameserver.enums.ItemLocation;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.L2World;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Npc;
|
||||
import com.l2jserver.gameserver.model.actor.L2Summon;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class StatusHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"status",
|
||||
"forcegc",
|
||||
"memusage",
|
||||
"gmlist"
|
||||
};
|
||||
|
||||
private int uptime;
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.equals("status"))
|
||||
{
|
||||
uptime = _uptime;
|
||||
_print.print(getServerStatus());
|
||||
_print.flush();
|
||||
}
|
||||
else if (command.equals("forcegc"))
|
||||
{
|
||||
System.gc();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("RAM Used: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576)); // 1024 * 1024 = 1048576
|
||||
_print.println(sb.toString());
|
||||
}
|
||||
else if (command.startsWith("memusage"))
|
||||
{
|
||||
double max = Runtime.getRuntime().maxMemory() / 1024; // maxMemory is the upper
|
||||
// limit the jvm can use
|
||||
double allocated = Runtime.getRuntime().totalMemory() / 1024; // totalMemory the
|
||||
// size of the
|
||||
// current
|
||||
// allocation pool
|
||||
double nonAllocated = max - allocated; // non allocated memory till jvm limit
|
||||
double cached = Runtime.getRuntime().freeMemory() / 1024; // freeMemory the
|
||||
// unused memory in
|
||||
// the allocation pool
|
||||
double used = allocated - cached; // really used memory
|
||||
double useable = max - used; // allocated, but non-used and non-allocated memory
|
||||
|
||||
DecimalFormat df = new DecimalFormat(" (0.0000'%')");
|
||||
DecimalFormat df2 = new DecimalFormat(" # 'KB'");
|
||||
|
||||
_print.println("+----");// ...
|
||||
_print.println("| Allowed Memory:" + df2.format(max));
|
||||
_print.println("| |= Allocated Memory:" + df2.format(allocated) + df.format((allocated / max) * 100));
|
||||
_print.println("| |= Non-Allocated Memory:" + df2.format(nonAllocated) + df.format((nonAllocated / max) * 100));
|
||||
_print.println("| Allocated Memory:" + df2.format(allocated));
|
||||
_print.println("| |= Used Memory:" + df2.format(used) + df.format((used / max) * 100));
|
||||
_print.println("| |= Unused (cached) Memory:" + df2.format(cached) + df.format((cached / max) * 100));
|
||||
_print.println("| Useable Memory:" + df2.format(useable) + df.format((useable / max) * 100)); // ...
|
||||
_print.println("+----");
|
||||
}
|
||||
else if (command.equals("gmlist"))
|
||||
{
|
||||
int igm = 0;
|
||||
String gmList = "";
|
||||
|
||||
for (String player : AdminTable.getInstance().getAllGmNames(true))
|
||||
{
|
||||
gmList = gmList + ", " + player;
|
||||
igm++;
|
||||
}
|
||||
_print.println("There are currently " + igm + " GM(s) online...");
|
||||
if (!gmList.isEmpty())
|
||||
{
|
||||
_print.println(gmList);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getServerStatus()
|
||||
{
|
||||
int playerCount = 0, objectCount = 0;
|
||||
int max = LoginServerThread.getInstance().getMaxPlayer();
|
||||
|
||||
playerCount = L2World.getInstance().getAllPlayersCount();
|
||||
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 instanceof L2Character)
|
||||
{
|
||||
if (((L2Character) obj).hasAI())
|
||||
{
|
||||
AICount++;
|
||||
}
|
||||
}
|
||||
if (obj instanceof L2ItemInstance)
|
||||
{
|
||||
if (((L2ItemInstance) obj).getItemLocation() == ItemLocation.VOID)
|
||||
{
|
||||
itemVoidCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemCount++;
|
||||
}
|
||||
}
|
||||
else if (obj instanceof L2MonsterInstance)
|
||||
{
|
||||
monsterCount++;
|
||||
if (((L2MonsterInstance) obj).hasMinions())
|
||||
{
|
||||
minionCount += ((L2MonsterInstance) obj).getMinionList().countSpawnedMinions();
|
||||
minionsGroupCount += ((L2MonsterInstance) obj).getMinionList().lazyCountSpawnedMinionsGroups();
|
||||
}
|
||||
}
|
||||
else if (obj instanceof L2Npc)
|
||||
{
|
||||
npcCount++;
|
||||
}
|
||||
else if (obj instanceof L2PcInstance)
|
||||
{
|
||||
pcCount++;
|
||||
if ((((L2PcInstance) obj).getClient() != null) && ((L2PcInstance) obj).getClient().isDetached())
|
||||
{
|
||||
detachedCount++;
|
||||
}
|
||||
}
|
||||
else if (obj instanceof L2Summon)
|
||||
{
|
||||
summonCount++;
|
||||
}
|
||||
else if (obj instanceof L2DoorInstance)
|
||||
{
|
||||
doorCount++;
|
||||
}
|
||||
else if (obj instanceof L2Character)
|
||||
{
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
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: " + getUptime(uptime));
|
||||
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 int getOnlineGMS()
|
||||
{
|
||||
return AdminTable.getInstance().getAllGms(true).size();
|
||||
}
|
||||
|
||||
private String getUptime(int time)
|
||||
{
|
||||
int uptime = (int) System.currentTimeMillis() - time;
|
||||
uptime = uptime / 1000;
|
||||
int h = uptime / 3600;
|
||||
int m = (uptime - (h * 3600)) / 60;
|
||||
int s = ((uptime - (h * 3600)) - (m * 60));
|
||||
return h + "hrs " + m + "mins " + s + "secs";
|
||||
}
|
||||
|
||||
private String gameTime()
|
||||
{
|
||||
int t = GameTimeController.getInstance().getGameTime();
|
||||
int h = t / 60;
|
||||
int m = t % 60;
|
||||
SimpleDateFormat format = new SimpleDateFormat("H:mm");
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR_OF_DAY, h);
|
||||
cal.set(Calendar.MINUTE, m);
|
||||
return format.format(cal.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
68
trunk/dist/game/data/scripts/handlers/telnethandlers/ThreadHandler.java
vendored
Normal file
68
trunk/dist/game/data/scripts/handlers/telnethandlers/ThreadHandler.java
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J DataPack
|
||||
*
|
||||
* This file is part of L2J DataPack.
|
||||
*
|
||||
* L2J DataPack 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.
|
||||
*
|
||||
* L2J DataPack 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;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.handler.ITelnetHandler;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class ThreadHandler implements ITelnetHandler
|
||||
{
|
||||
private final String[] _commands =
|
||||
{
|
||||
"purge",
|
||||
"performance"
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
|
||||
{
|
||||
if (command.equals("performance"))
|
||||
{
|
||||
for (String line : ThreadPoolManager.getInstance().getStats())
|
||||
{
|
||||
_print.println(line);
|
||||
}
|
||||
_print.flush();
|
||||
}
|
||||
else if (command.equals("purge"))
|
||||
{
|
||||
ThreadPoolManager.getInstance().purge();
|
||||
_print.println("STATUS OF THREAD POOLS AFTER PURGE COMMAND:");
|
||||
_print.println("");
|
||||
for (String line : ThreadPoolManager.getInstance().getStats())
|
||||
{
|
||||
_print.println(line);
|
||||
}
|
||||
_print.flush();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommandList()
|
||||
{
|
||||
return _commands;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user