Noticias:

Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate

Menú Principal

//serverinfo admin command

Iniciado por Swarlog, Ago 19, 2022, 12:27 AM

Tema anterior - Siguiente tema

Swarlog


### Eclipse Workspace Patch 1.0
#P L2J_Server_BETA
Index: java/com/l2jserver/gameserver/ThreadPoolManager.java
===================================================================
--- java/com/l2jserver/gameserver/ThreadPoolManager.java (revision 6602)
+++ java/com/l2jserver/gameserver/ThreadPoolManager.java (working copy)
@@ -35,6 +35,7 @@
 import javolution.util.FastSet;
 
 import com.l2jserver.Config;
+import com.l2jserver.gameserver.model.StatsSet;
 import com.l2jserver.util.StringUtil;
 
 /**
@@ -449,6 +450,100 @@
  }
  }
 
+ public StatsSet getStats(String category)
+ {
+ final StatsSet StatsSet = new StatsSet();
+
+ switch (category)
+ {
+ case "EFFECTS":
+ {
+ StatsSet.set("ActiveThreads", _effectsScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _effectsScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSize", _effectsScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSize", _effectsScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _effectsScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _effectsScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "GENERAL":
+ {
+ StatsSet.set("ActiveThreads", _generalScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSizes", _generalScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSizes", _generalScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSizes", _generalScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _generalScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _generalScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "AI":
+ {
+ StatsSet.set("ActiveThreads", _aiScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _aiScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSize", _aiScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSize", _aiScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _aiScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _aiScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "EVENT":
+ {
+ StatsSet.set("ActiveThreads", _eventScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _eventScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSize", _eventScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSize", _eventScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _eventScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _eventScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "PACKETS":
+ {
+ StatsSet.set("ActiveThreads", _generalPacketsThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _generalPacketsThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _generalPacketsThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _generalPacketsThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _generalPacketsThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _generalPacketsThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _generalPacketsThreadPool.getQueue().size());
+ break;
+ }
+ case "IOPACKETS":
+ {
+ StatsSet.set("ActiveThreads", _ioPacketsThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _ioPacketsThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _ioPacketsThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _ioPacketsThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _ioPacketsThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _ioPacketsThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _ioPacketsThreadPool.getQueue().size());
+ break;
+ }
+ case "GENERAL_TASKS":
+ {
+ StatsSet.set("ActiveThreads", _generalThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _generalThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _generalThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _generalThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _generalThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _generalThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _generalThreadPool.getQueue().size());
+ break;
+ }
+ case "EVENT_TASKS":
+ {
+ StatsSet.set("ActiveThreads", _eventThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _eventThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _eventThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _eventThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _eventThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _eventThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _eventThreadPool.getQueue().size());
+ break;
+ }
+ }
+ return StatsSet;
+ }
+
  public String[] getStats()
  {
  return new String[]
#P L2J_DataPack_BETA
Index: dist/game/data/html/admin/serverinfo.htm
===================================================================
--- dist/game/data/html/admin/serverinfo.htm (revision 0)
+++ dist/game/data/html/admin/serverinfo.htm (working copy)
@@ -0,0 +1,105 @@
+<html><title>Admin Server Info</title><body>
+<center>
+<table width=270>
+<tr>
+<td width=45><button value="Main" action="bypass -h admin_admin" width=45 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
+<td width=180><center>Server Info</center></td>
+<td width=45><button value="Back" action="bypass -h admin_admin4" width=45 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
+</tr>
+</table>
+<br>
+<br>
+<font color="LEVEL">General info:<font><br1>
+ <table width="270" border="0" bgcolor="444444">
+ <tr>
+ <td>OS:</td>
+ <td><font color="00FF00">%os_name%</font></td>
+ </tr>
+ <tr>
+ <td>OS version:</td>
+ <td><font color="00FF00">%os_ver%</font></td>
+ </tr>
+ <tr>
+ <td>Server slots:</td>
+ <td><font color="00FF00">%slots%</font></td>
+ </tr>
+ <tr>
+ <td>Server UpTime:</td>
+ <td><font color="00FF00">%serverUpTime%</font></td>
+ </tr>
+ <tr>
+ <td>Server Time:</td>
+ <td><font color="00FF00">%serverTime%</font></td>
+ </tr>
+ <tr>
+ <td>Game Time:</td>
+ <td><font color="00FF00">%gameTime% (%dayNight%)</font></td>
+ </tr>
+ <tr>
+ <td>Geodata:</td>
+ <td><font color="00FF00">%geodata%</font></td>
+ </tr>
+ </table>
+<br>
+<font color="LEVEL">Players info:<font><br1>
+ <table width="270" border="0" bgcolor="444444">
+ <tr>
+ <td>Total players count:</td>
+ <td><font color="00FF00">%onlineAll%</font></td>
+ </tr>
+ <tr>
+ <td>Offline trade count:</td>
+ <td><font color="00FF00">%offlineTrade%</font></td>
+ </tr>
+ <tr>
+ <td>Online GM count:</td>
+ <td><font color="00FF00">%onlineGM%</font></td>
+ </tr>
+ <tr>
+ <td>Real player count:</td>
+ <td><font color="00FF00">%onlineReal%</font></td>
+ </tr>
+ </table>
+<br>
+<font color="LEVEL">Memory Info:<font><br1>
+ <table width="270" border="0" bgcolor="444444">
+ <tr>
+ <td>Used Memory:</td>
+ <td><font color="00FF00">%usedMem% MB</font></td>
+ </tr>
+ <tr>
+ <td>Free Memory:</td>
+ <td><font color="00FF00">%freeMem% MB</font></td>
+ </tr>
+ <tr>
+ <td>Total Memory:</td>
+ <td><font color="00FF00">%totalMem% MB</font></td>
+ </tr>
+ </table>
+<br>
+<font color="LEVEL">Theard Info - General (STP):<font><br1>
+ %theardInfoGen%
+<br>
+<font color="LEVEL">Theard Info - Effects (STP):<font><br1>
+ %theardInfoEff%
+<br>
+<font color="LEVEL">Theard Info - AI (STP):<font><br1>
+ %theardInfoAi%
+<br>
+<font color="LEVEL">Theard Info - Event (STP):<font><br1>
+ %theardInfoEvent%
+<br>
+<font color="LEVEL">Theard Info - Packets (TP):<font><br1>
+ %theardInfoPack%
+<br>
+<font color="LEVEL">Theard Info - I/O Packets (TP):<font><br1>
+ %theardInfoIOPack%
+<br>
+<font color="LEVEL">Theard Info - General Tasks (TP):<font><br1>
+ %theardInfoGenTask%
+<br>
+<font color="LEVEL">Theard Info - Event Tasks (TP):<font><br1>
+ %theardInfoEvnTask%
+<br>
+</center>
+</body></html>
\ No newline at end of file
Index: dist/game/data/html/admin/server_menu.htm
===================================================================
--- dist/game/data/html/admin/server_menu.htm (revision 10396)
+++ dist/game/data/html/admin/server_menu.htm (working copy)
@@ -35,6 +35,7 @@
 <tr>
 <td><button value="Skill Test" action="bypass -h admin_skill_test $qbox" width=82 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
 <td><button value="Zone Check" action="bypass -h admin_zone_check" width=82 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
+<td><button value="Server Info" action="bypass -h admin_serverinfo" width=82 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
 </tr>
 <tr>
 <td><button value="Mods" action="bypass -h admin_admin5" width=82 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
Index: dist/game/config/adminCommands.xml
===================================================================
--- dist/game/config/adminCommands.xml (revision 10396)
+++ dist/game/config/adminCommands.xml (working copy)
@@ -606,6 +606,9 @@
  <!-- ADMIN SCAN -->
  <admin command="admin_scan" accessLevel="7" />
  <admin command="admin_deleteNpcByObjectId" accessLevel="7" confirmDlg="true" />
+
+ <!-- ADMIN SERVERINFO -->
+ <admin command="admin_serverinfo" accessLevel="7" />
 
  <!-- VOICE COMMANDS -->
  <admin command="banchat" accessLevel="7" />
Index: dist/game/data/scripts/handlers/MasterHandler.java
===================================================================
--- dist/game/data/scripts/handlers/MasterHandler.java (revision 10396)
+++ dist/game/data/scripts/handlers/MasterHandler.java (working copy)
@@ -112,6 +112,7 @@
 import handlers.admincommandhandlers.AdminRes;
 import handlers.admincommandhandlers.AdminRide;
 import handlers.admincommandhandlers.AdminScan;
+import handlers.admincommandhandlers.AdminServerInfo;
 import handlers.admincommandhandlers.AdminShop;
 import handlers.admincommandhandlers.AdminShowQuests;
 import handlers.admincommandhandlers.AdminShutdown;
@@ -376,6 +377,7 @@
  AdminRes.class,
  AdminRide.class,
  AdminScan.class,
+ AdminServerInfo.class,
  AdminShop.class,
  AdminShowQuests.class,
  AdminShutdown.class,
Index: dist/game/data/scripts/handlers/admincommandhandlers/AdminServerInfo.java
===================================================================
--- dist/game/data/scripts/handlers/admincommandhandlers/AdminServerInfo.java (revision 0)
+++ dist/game/data/scripts/handlers/admincommandhandlers/AdminServerInfo.java (working copy)
@@ -0,0 +1,176 @@
+/*
+ * 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.admincommandhandlers;
+
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import javolution.text.TextBuilder;
+
+import com.l2jserver.Config;
+import com.l2jserver.gameserver.GameServer;
+import com.l2jserver.gameserver.GameTimeController;
+import com.l2jserver.gameserver.ThreadPoolManager;
+import com.l2jserver.gameserver.cache.HtmCache;
+import com.l2jserver.gameserver.handler.IAdminCommandHandler;
+import com.l2jserver.gameserver.model.L2World;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
+
+/**
+ * @author St3eT
+ */
+public class AdminServerInfo implements IAdminCommandHandler
+{
+ private static final SimpleDateFormat fmt = new SimpleDateFormat("hh:mm a");
+
+ private static final String[] ADMIN_COMMANDS =
+ {
+ "admin_serverinfo"
+ };
+
+ @Override
+ public boolean useAdminCommand(String command, L2PcInstance activeChar)
+ {
+ if (command.equals("admin_serverinfo"))
+ {
+ final NpcHtmlMessage html = new NpcHtmlMessage(0, 1);
+ final Runtime RunTime = Runtime.getRuntime();
+ final int mb = 1024 * 1024;
+ html.setHtml(HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/serverinfo.htm"));
+
+ html.replace("%os_name%", System.getProperty("os.name"));
+ html.replace("%os_ver%", System.getProperty("os.version"));
+ html.replace("%slots%", getPlayersCount("ALL") + "/" + Config.MAXIMUM_ONLINE_USERS);
+ html.replace("%gameTime%", GameTimeController.getInstance().getGameHour() + ":" + GameTimeController.getInstance().getGameMinute());
+ html.replace("%dayNight%", GameTimeController.getInstance().isNight() ? "Night" : "Day");
+ html.replace("%geodata%", Config.GEODATA > 0 ? "Enabled" : "Disabled");
+ html.replace("%serverTime%", fmt.format(new Date(System.currentTimeMillis())));
+ html.replace("%serverUpTime%", getServerUpTime());
+ html.replace("%onlineAll%", getPlayersCount("ALL"));
+ html.replace("%offlineTrade%", getPlayersCount("OFF_TRADE"));
+ html.replace("%onlineGM%", getPlayersCount("GM"));
+ html.replace("%onlineReal%", getPlayersCount("ALL_REAL"));
+ html.replace("%usedMem%", (RunTime.maxMemory() / mb) - (((RunTime.maxMemory() - RunTime.totalMemory()) + RunTime.freeMemory()) / mb));
+ html.replace("%freeMem%", ((RunTime.maxMemory() - RunTime.totalMemory()) + RunTime.freeMemory()) / mb);
+ html.replace("%totalMem%", Runtime.getRuntime().maxMemory() / 1048576);
+ html.replace("%theardInfoGen%", buildTheardInfo("GENERAL"));
+ html.replace("%theardInfoEff%", buildTheardInfo("EFFECTS"));
+ html.replace("%theardInfoAi%", buildTheardInfo("AI"));
+ html.replace("%theardInfoEvent%", buildTheardInfo("EVENT"));
+ html.replace("%theardInfoPack%", buildTheardInfo("PACKETS"));
+ html.replace("%theardInfoIOPack%", buildTheardInfo("IOPACKETS"));
+ html.replace("%theardInfoGenTask%", buildTheardInfo("GENERAL_TASKS"));
+ html.replace("%theardInfoEvnTask%", buildTheardInfo("EVENT_TASKS"));
+ activeChar.sendPacket(html);
+ }
+ return true;
+ }
+
+ private String getServerUpTime()
+ {
+ long time = System.currentTimeMillis() - GameServer.dateTimeServerStarted.getTimeInMillis();
+
+ final long days = TimeUnit.MILLISECONDS.toDays(time);
+ time -= TimeUnit.DAYS.toMillis(days);
+ final long hours = TimeUnit.MILLISECONDS.toHours(time);
+ time -= TimeUnit.HOURS.toMillis(hours);
+ final long minutes = TimeUnit.MILLISECONDS.toMinutes(time);
+
+ return days + " Days, " + hours + " Hours, " + minutes + " Minutes";
+ }
+
+ private String buildTheardInfo(String category)
+ {
+ final TextBuilder tb = new TextBuilder();
+
+ tb.append("<table width=\"270\" border=\"0\" bgcolor=\"444444\">");
+ for (Entry<String, Object> info : ThreadPoolManager.getInstance().getStats(category).getSet().entrySet())
+ {
+ tb.append("<tr>");
+ tb.append("<td>" + info.getKey() + ":</td>");
+ tb.append("<td><font color=\"00FF00\">" + info.getValue() + "</font></td>");
+ tb.append("</tr>");
+ }
+ tb.append("</table>");
+ return tb.toString();
+ }
+
+ private int getPlayersCount(String type)
+ {
+ switch (type)
+ {
+ case "ALL":
+ {
+ return L2World.getInstance().getAllPlayersCount();
+ }
+ case "OFF_TRADE":
+ {
+ int offlineCount = 0;
+
+ final Collection<L2PcInstance> objs = L2World.getInstance().getPlayers();
+ for (L2PcInstance player : objs)
+ {
+ if ((player.getClient() == null) || player.getClient().isDetached())
+ {
+ offlineCount++;
+ }
+ }
+ return offlineCount;
+ }
+ case "GM":
+ {
+ int onlineGMcount = 0;
+ for (L2PcInstance gm : L2World.getInstance().getAllGMs())
+ {
+ if ((gm != null) && gm.isOnline() && (gm.getClient() != null) && !gm.getClient().isDetached())
+ {
+ onlineGMcount++;
+ }
+ }
+ return onlineGMcount;
+ }
+ case "ALL_REAL":
+ {
+ Set<String> realPlayers = new HashSet<>();
+
+ for (L2PcInstance onlinePlayer : L2World.getInstance().getPlayers())
+ {
+ if (((onlinePlayer != null) && (onlinePlayer.getClient() != null)) && !onlinePlayer.getClient().isDetached())
+ {
+ realPlayers.add(onlinePlayer.getIPAddress());
+ }
+ }
+ return realPlayers.size();
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public String[] getAdminCommandList()
+ {
+ return ADMIN_COMMANDS;
+ }
+}