Admin server info improvements and minor font tag corrections.

Thanks to Trance.
This commit is contained in:
MobiusDevelopment
2021-11-12 02:33:59 +00:00
parent e8b65912f4
commit 2988292540
328 changed files with 4620 additions and 2294 deletions

View File

@@ -71,6 +71,7 @@ import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminRepairChar;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminRes;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminRideWyvern;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminScript;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminServerInfo;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminShop;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminShutdown;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminSiege;
@@ -145,6 +146,7 @@ public class AdminCommandHandler
registerAdminCommandHandler(new AdminRes());
registerAdminCommandHandler(new AdminRideWyvern());
registerAdminCommandHandler(new AdminScript());
registerAdminCommandHandler(new AdminServerInfo());
registerAdminCommandHandler(new AdminShop());
registerAdminCommandHandler(new AdminShutdown());
registerAdminCommandHandler(new AdminSiege());

View File

@@ -0,0 +1,168 @@
/*
* 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 org.l2jmobius.gameserver.handler.admincommandhandlers;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.lang.management.ThreadMXBean;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.gameserver.GameServer;
import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.xml.AdminData;
import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
/**
* @author St3eT
*/
public class AdminServerInfo implements IAdminCommandHandler
{
private static final SimpleDateFormat SDF = new SimpleDateFormat("hh:mm a");
private static final MemoryMXBean MEMORY_MX_BEAN = ManagementFactory.getMemoryMXBean();
private static final ThreadMXBean THREAD_MX_BEAN = ManagementFactory.getThreadMXBean();
private static final String[] ADMIN_COMMANDS =
{
"admin_serverinfo"
};
@Override
public boolean useAdminCommand(String command, PlayerInstance activeChar)
{
if (command.equals("admin_serverinfo"))
{
final MemoryUsage heapMemoryUsage = MEMORY_MX_BEAN.getHeapMemoryUsage();
final long freeMemory = heapMemoryUsage.getMax() - heapMemoryUsage.getUsed();
final int threadCount = THREAD_MX_BEAN.getThreadCount();
final int daemonCount = THREAD_MX_BEAN.getThreadCount();
final int nonDaemonCount = threadCount - daemonCount;
final int peakCount = THREAD_MX_BEAN.getPeakThreadCount();
final long totalCount = THREAD_MX_BEAN.getTotalStartedThreadCount();
final NpcHtmlMessage html = new NpcHtmlMessage(5);
html.setHtml(HtmCache.getInstance().getHtm("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%", GameTimeTaskManager.getInstance().getGameHour() + ":" + GameTimeTaskManager.getInstance().getGameMinute());
html.replace("%dayNight%", GameTimeTaskManager.getInstance().isNight() ? "Night" : "Day");
html.replace("%geodata%", Config.PATHFINDING ? "Enabled" : "Disabled");
html.replace("%serverTime%", SDF.format(new Date(Chronos.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%", (MEMORY_MX_BEAN.getHeapMemoryUsage().getUsed() / 0x100000) + " Mb");
html.replace("%freeMem%", (freeMemory / 0x100000) + " Mb");
html.replace("%totalMem%", (MEMORY_MX_BEAN.getHeapMemoryUsage().getMax() / 0x100000) + " Mb");
html.replace("%live%", threadCount);
html.replace("%nondaemon%", nonDaemonCount);
html.replace("%daemon%", daemonCount);
html.replace("%peak%", peakCount);
html.replace("%totalstarted%", totalCount);
for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans())
{
html.replace("%gcol%", gcBean.getName());
html.replace("%colcount%", gcBean.getCollectionCount());
html.replace("%coltime%", gcBean.getCollectionTime());
}
activeChar.sendPacket(html);
}
return true;
}
private String getServerUpTime()
{
long time = Chronos.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);
return days + " Days, " + hours + " Hours, " + TimeUnit.MILLISECONDS.toMinutes(time) + " Minutes";
}
private int getPlayersCount(String type)
{
switch (type)
{
case "ALL":
{
return World.getInstance().getAllPlayers().size();
}
case "OFF_TRADE":
{
int offlineCount = 0;
final Collection<PlayerInstance> objs = World.getInstance().getAllPlayers();
for (PlayerInstance player : objs)
{
if ((player.getClient() == null) || player.getClient().isDetached())
{
offlineCount++;
}
}
return offlineCount;
}
case "GM":
{
int onlineGMcount = 0;
for (PlayerInstance gm : AdminData.getInstance().getAllGms(true))
{
if ((gm != null) && gm.isOnline() && (gm.getClient() != null) && !gm.getClient().isDetached())
{
onlineGMcount++;
}
}
return onlineGMcount;
}
case "ALL_REAL":
{
final Set<String> realPlayers = new HashSet<>();
for (PlayerInstance onlinePlayer : World.getInstance().getAllPlayers())
{
if ((onlinePlayer != null) && (onlinePlayer.getClient() != null) && !onlinePlayer.getClient().isDetached())
{
realPlayers.add(onlinePlayer.getClient().getIpAddress());
}
}
return realPlayers.size();
}
}
return 0;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}

View File

@@ -77,6 +77,16 @@ public class GameTimeTaskManager
return _gameTicks;
}
public int getGameHour()
{
return getGameTime() / 60;
}
public int getGameMinute()
{
return getGameTime() % 60;
}
/**
* Add a Creature to movingObjects of GameTimeTaskManager.<br>
* <br>