Addition of admin online command.

This commit is contained in:
MobiusDevelopment 2020-02-01 11:09:52 +00:00
parent 29f2d60f28
commit 43c4afeb25
6 changed files with 148 additions and 80 deletions

View File

@ -412,6 +412,9 @@
<!-- Section: Noble -->
<admin command="admin_setnoble" accessLevel="90" />
<!-- Section: Online -->
<admin command="admin_online" accessLevel="80" />
<!-- Section: Petitions -->
<admin command="admin_view_petitions" accessLevel="80" />
<admin command="admin_view_petition" accessLevel="80" />

View File

@ -64,6 +64,7 @@ import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminMenu;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminMobGroup;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminMonsterRace;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminNoble;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminOnline;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminPForge;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminPetition;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminPledge;
@ -86,7 +87,6 @@ import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminTest;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminTownWar;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminTvTEngine;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminVIPEngine;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminWho;
import org.l2jmobius.gameserver.handler.admincommandhandlers.AdminZone;
/**
@ -146,6 +146,7 @@ public class AdminCommandHandler
registerAdminCommandHandler(new AdminMobGroup());
registerAdminCommandHandler(new AdminMonsterRace());
registerAdminCommandHandler(new AdminNoble());
registerAdminCommandHandler(new AdminOnline());
registerAdminCommandHandler(new AdminPetition());
registerAdminCommandHandler(new AdminPForge());
registerAdminCommandHandler(new AdminPledge());
@ -168,7 +169,6 @@ public class AdminCommandHandler
registerAdminCommandHandler(new AdminTownWar());
registerAdminCommandHandler(new AdminTvTEngine());
registerAdminCommandHandler(new AdminVIPEngine());
registerAdminCommandHandler(new AdminWho());
registerAdminCommandHandler(new AdminZone());
LOGGER.info("AdminCommandHandler: Loaded " + _datatable.size() + " handlers.");

View File

@ -1009,18 +1009,10 @@ public class AdminEditChar implements IAdminCommandHandler
String ip = "N/A";
String account = "N/A";
try
{
final StringTokenizer clientinfo = new StringTokenizer(player.getClient().toString(), " ]:-[");
clientinfo.nextToken();
clientinfo.nextToken();
clientinfo.nextToken();
account = clientinfo.nextToken();
clientinfo.nextToken();
ip = clientinfo.nextToken();
}
catch (Exception e)
if (player.getClient() != null)
{
account = player.getClient().getAccountName();
ip = player.getClient().getIpAddress();
}
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);

View File

@ -0,0 +1,115 @@
/*
* 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.util.ArrayList;
import java.util.List;
import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
import org.l2jmobius.gameserver.instancemanager.PlayerCountManager;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
import org.l2jmobius.gameserver.util.BuilderUtil;
/**
* @author Mobius
*/
public class AdminOnline implements IAdminCommandHandler
{
private static final String[] ADMIN_COMMANDS =
{
"admin_online"
};
@Override
public boolean useAdminCommand(String command, PlayerInstance activeChar)
{
if (command.equalsIgnoreCase("admin_online"))
{
final List<String> ips = new ArrayList<>();
int total = 0;
int online = 0;
int offline = 0;
int peace = 0;
int notPeace = 0;
// int instanced = 0;
int combat = 0;
for (PlayerInstance player : World.getInstance().getAllPlayers())
{
if (player.getClient() != null)
{
final String ip = player.getClient().getIpAddress();
if ((ip != null) && !ips.contains(ip))
{
ips.add(ip);
}
}
total++;
if (player.isInOfflineMode())
{
offline++;
}
else if (player.isOnline())
{
online++;
}
if (player.isInsideZone(ZoneId.PEACE))
{
peace++;
}
else
{
notPeace++;
}
// if (player.getInstanceId() > 0)
// {
// instanced++;
// }
if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player) || (player.getPvpFlag() > 0) || player.isInsideZone(ZoneId.PVP) || player.isInsideZone(ZoneId.SIEGE))
{
combat++;
}
}
BuilderUtil.sendSysMessage(activeChar, "Online Player Report");
BuilderUtil.sendSysMessage(activeChar, "Total count: " + total);
BuilderUtil.sendSysMessage(activeChar, "Total online: " + online);
BuilderUtil.sendSysMessage(activeChar, "Total offline: " + offline);
BuilderUtil.sendSysMessage(activeChar, "Max connected: " + PlayerCountManager.getInstance().getMaxConnectedCount());
BuilderUtil.sendSysMessage(activeChar, "Unique IPs: " + ips.size());
BuilderUtil.sendSysMessage(activeChar, "In peace zone: " + peace);
BuilderUtil.sendSysMessage(activeChar, "Not in peace zone: " + notPeace);
// BuilderUtil.sendSysMessage(activeChar, "In instances: " + instanced);
BuilderUtil.sendSysMessage(activeChar, "In combat: " + combat);
}
return true;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}

View File

@ -1,46 +0,0 @@
/*
* 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 org.l2jmobius.gameserver.handler.IAdminCommandHandler;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.util.BuilderUtil;
public class AdminWho implements IAdminCommandHandler
{
private static final String[] ADMIN_COMMANDS =
{
"admin_who"
};
@Override
public boolean useAdminCommand(String command, PlayerInstance activeChar)
{
if (command.equalsIgnoreCase("admin_who"))
{
BuilderUtil.sendSysMessage(activeChar, "SYS: current(" + World.getInstance().getAllPlayers().size() + "), playing(" + World.getInstance().getAllPlayers().size() + ")");
}
return true;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}

View File

@ -84,8 +84,8 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
public GameClientState _state;
// Info
public String accountName;
public SessionKey sessionId;
public String _accountName;
public SessionKey _sessionId;
public PlayerInstance _player;
private final ReentrantLock _playerLock = new ReentrantLock();
@ -214,22 +214,22 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
public void setAccountName(String pAccountName)
{
accountName = pAccountName;
_accountName = pAccountName;
}
public String getAccountName()
{
return accountName;
return _accountName;
}
public void setSessionId(SessionKey sk)
{
sessionId = sk;
_sessionId = sk;
}
public SessionKey getSessionId()
{
return sessionId;
return _sessionId;
}
public void sendPacket(GameServerPacket gsp)
@ -478,7 +478,7 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
if (character != null)
{
// exploit prevention, should not happens in normal way
LOGGER.warning("Attempt of double login: " + character.getName() + "(" + objId + ") " + accountName);
LOGGER.warning("Attempt of double login: " + character.getName() + "(" + objId + ") " + _accountName);
if (character.getClient() != null)
{
@ -599,6 +599,21 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
nProtect.getInstance().closeSession(this);
}
public String getIpAddress()
{
final InetAddress address = getConnection().getInetAddress();
String ip;
if (address == null)
{
ip = "N/A";
}
else
{
ip = address.getHostAddress();
}
return ip;
}
/**
* Produces the best possible string representation of this client.
*/
@ -607,31 +622,20 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
{
try
{
final InetAddress address = getConnection().getInetAddress();
String ip;
if (address == null)
{
ip = "disconnected";
}
else
{
ip = address.getHostAddress();
}
switch (_state)
{
case CONNECTED:
{
return "[IP: " + ip + "]";
return "[IP: " + getIpAddress() + "]";
}
case AUTHED:
{
return "[Account: " + accountName + " - IP: " + ip + "]";
return "[Account: " + _accountName + " - IP: " + getIpAddress() + "]";
}
case ENTERING:
case IN_GAME:
{
return "[Character: " + (_player == null ? "disconnected" : _player.getName()) + " - Account: " + accountName + " - IP: " + ip + "]";
return "[Character: " + (_player == null ? "disconnected" : _player.getName()) + " - Account: " + _accountName + " - IP: " + getIpAddress() + "]";
}
default:
{