Broke and cleaned up server commands

This commit is contained in:
Anuken
2018-10-28 14:26:58 -04:00
parent 2a21e7c2cb
commit 80aed31135
23 changed files with 92 additions and 348 deletions

View File

@ -1,4 +1,6 @@
apply plugin: "java" apply plugin: "java"
sourceCompatibility = 1.8 sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ] sourceSets.main.java.srcDirs = [ "src/main/java/" ]
sourceSets.main.resources.srcDirs = [ "src/main/resources/" ]

View File

@ -1,5 +1,7 @@
package io.anuke.annotations; package io.anuke.annotations;
import io.anuke.annotations.MethodEntry;
import java.util.ArrayList; import java.util.ArrayList;
/** Represents a class witha list method entries to include in it. */ /** Represents a class witha list method entries to include in it. */

View File

@ -2,6 +2,8 @@ package io.anuke.annotations;
import com.squareup.javapoet.*; import com.squareup.javapoet.*;
import io.anuke.annotations.IOFinder.ClassSerializer; import io.anuke.annotations.IOFinder.ClassSerializer;
import io.anuke.annotations.MethodEntry;
import io.anuke.annotations.Utils;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;

View File

@ -52,7 +52,7 @@ public class SerializeAnnotationProcessor extends AbstractProcessor{
TypeSpec.Builder serializer = TypeSpec.anonymousClassBuilder("") TypeSpec.Builder serializer = TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ParameterizedTypeName.get( .addSuperinterface(ParameterizedTypeName.get(
ClassName.get(Class.forName("io.anuke.ucore.io.TypeSerializer")), type)); ClassName.bestGuess("io.anuke.ucore.io.TypeSerializer"), type));
MethodSpec.Builder writeMethod = MethodSpec.methodBuilder("write") MethodSpec.Builder writeMethod = MethodSpec.methodBuilder("write")
.returns(void.class) .returns(void.class)

View File

@ -0,0 +1,2 @@
io.anuke.annotations.RemoteMethodAnnotationProcessor
io.anuke.annotations.SerializeAnnotationProcessor

View File

@ -178,11 +178,14 @@ project(":core") {
compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion" compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
annotationProcessor project(":annotations")
} }
/*
compileJava.options.compilerArgs = [ compileJava.options.compilerArgs = [
"-processor", "io.anuke.annotations.RemoteMethodAnnotationProcessor,io.anuke.annotations.SerializeAnnotationProcessor" "-processor", "io.anuke.annotations.RemoteMethodAnnotationProcessor,io.anuke.annotations.SerializeAnnotationProcessor"
] ]*/
} }
project(":server") { project(":server") {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 B

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 103 KiB

View File

@ -21,7 +21,6 @@ import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.SendMode; import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.NetworkIO; import io.anuke.mindustry.net.NetworkIO;
import io.anuke.mindustry.net.Packets.*; import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.net.TraceInfo;
import io.anuke.mindustry.net.ValidateException; import io.anuke.mindustry.net.ValidateException;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.modules.ItemModule; import io.anuke.mindustry.world.modules.ItemModule;
@ -207,12 +206,6 @@ public class NetClient extends Module{
players[0].y = y; players[0].y = y;
} }
@Remote(variants = Variant.one)
public static void onTraceInfo(TraceInfo info){
Player player = playerGroup.getByID(info.playerid);
ui.traces.show(player, info);
}
@Remote @Remote
public static void onPlayerDisconnect(int playerid){ public static void onPlayerDisconnect(int playerid){
playerGroup.removeByID(playerid); playerGroup.removeByID(playerid);

View File

@ -106,11 +106,9 @@ public class NetServer extends Module{
connection.hasBegunConnecting = true; connection.hasBegunConnecting = true;
TraceInfo trace = admins.getTraceByID(uuid);
PlayerInfo info = admins.getInfo(uuid); PlayerInfo info = admins.getInfo(uuid);
trace.uuid = uuid;
trace.ip = connection.address; connection.mobile = packet.mobile;
trace.android = packet.mobile;
if(admins.isIDBanned(uuid)){ if(admins.isIDBanned(uuid)){
kick(id, KickReason.banned); kick(id, KickReason.banned);
@ -150,7 +148,7 @@ public class NetServer extends Module{
return; return;
} }
Log.info("Recieved connect packet for player '{0}' / UUID {1} / IP {2}", packet.name, uuid, trace.ip); Log.info("Recieved connect packet for player '{0}' / UUID {1} / IP {2}", packet.name, uuid, connection.address);
String ip = Net.getConnection(id).address; String ip = Net.getConnection(id).address;
@ -162,7 +160,7 @@ public class NetServer extends Module{
} }
if(packet.version == -1){ if(packet.version == -1){
trace.modclient = true; connection.modclient = true;
} }
Player player = new Player(); Player player = new Player();
@ -207,8 +205,6 @@ public class NetServer extends Module{
connections.put(id, player); connections.put(id, player);
trace.playerid = player.id;
sendWorldData(player, id); sendWorldData(player, id);
Platform.instance.updateRPC(); Platform.instance.updateRPC();
@ -395,11 +391,11 @@ public class NetServer extends Module{
netServer.kick(other.con.id, KickReason.kick); netServer.kick(other.con.id, KickReason.kick);
Log.info("&lc{0} has kicked {1}.", player.name, other.name); Log.info("&lc{0} has kicked {1}.", player.name, other.name);
}else if(action == AdminAction.trace){ }else if(action == AdminAction.trace){
//TODO //TODO implement
if(player.con != null){ if(player.con != null){
Call.onTraceInfo(player.con.id, netServer.admins.getTraceByID(other.uuid)); //Call.onTraceInfo(player.con.id, other.con.trace);
}else{ }else{
NetClient.onTraceInfo(netServer.admins.getTraceByID(other.uuid)); //NetClient.onTraceInfo(other.con.trace);
} }
Log.info("&lc{0} has requested trace info of {1}.", player.name, other.name); Log.info("&lc{0} has requested trace info of {1}.", player.name, other.name);
} }
@ -424,7 +420,6 @@ public class NetServer extends Module{
if(!headless && !closing && Net.server() && state.is(State.menu)){ if(!headless && !closing && Net.server() && state.is(State.menu)){
closing = true; closing = true;
reset();
threads.runGraphics(() -> ui.loadfrag.show("$text.server.closing")); threads.runGraphics(() -> ui.loadfrag.show("$text.server.closing"));
Timers.runTask(5f, () -> { Timers.runTask(5f, () -> {
Net.closeServer(); Net.closeServer();
@ -438,10 +433,6 @@ public class NetServer extends Module{
} }
} }
public void reset(){
admins.clearTraces();
}
public void kickAll(KickReason reason){ public void kickAll(KickReason reason){
for(NetConnection con : Net.getConnections()){ for(NetConnection con : Net.getConnections()){
kick(con.id, reason); kick(con.id, reason);

View File

@ -1,7 +1,6 @@
package io.anuke.mindustry.io; package io.anuke.mindustry.io;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Base64Coder;
import io.anuke.annotations.Annotations.ReadClass; import io.anuke.annotations.Annotations.ReadClass;
import io.anuke.annotations.Annotations.WriteClass; import io.anuke.annotations.Annotations.WriteClass;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
@ -17,7 +16,6 @@ import io.anuke.mindustry.entities.units.UnitCommand;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.net.Packets.AdminAction; import io.anuke.mindustry.net.Packets.AdminAction;
import io.anuke.mindustry.net.Packets.KickReason; import io.anuke.mindustry.net.Packets.KickReason;
import io.anuke.mindustry.net.TraceInfo;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@ -364,45 +362,4 @@ public class TypeIO{
buffer.get(bytes); buffer.get(bytes);
return bytes; return bytes;
} }
@WriteClass(TraceInfo.class)
public static void writeTrace(ByteBuffer buffer, TraceInfo info){
buffer.putInt(info.playerid);
buffer.putShort((short) info.ip.getBytes().length);
buffer.put(info.ip.getBytes());
buffer.put(info.modclient ? (byte) 1 : 0);
buffer.put(info.android ? (byte) 1 : 0);
buffer.putInt(info.totalBlocksBroken);
buffer.putInt(info.structureBlocksBroken);
buffer.putInt(info.lastBlockBroken.id);
buffer.putInt(info.totalBlocksPlaced);
buffer.putInt(info.lastBlockPlaced.id);
buffer.put(Base64Coder.decode(info.uuid));
}
@ReadClass(TraceInfo.class)
public static TraceInfo readTrace(ByteBuffer buffer){
int id = buffer.getInt();
short iplen = buffer.getShort();
byte[] ipb = new byte[iplen];
buffer.get(ipb);
TraceInfo info = new TraceInfo(new String(ipb));
info.playerid = id;
info.modclient = buffer.get() == 1;
info.android = buffer.get() == 1;
info.totalBlocksBroken = buffer.getInt();
info.structureBlocksBroken = buffer.getInt();
info.lastBlockBroken = content.block(buffer.getInt());
info.totalBlocksPlaced = buffer.getInt();
info.lastBlockPlaced = content.block(buffer.getInt());
byte[] uuid = new byte[8];
buffer.get(uuid);
info.uuid = new String(Base64Coder.encode(uuid));
return info;
}
} }

View File

@ -2,6 +2,7 @@ package io.anuke.mindustry.net;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.annotations.Annotations.Serialize; import io.anuke.annotations.Annotations.Serialize;
import io.anuke.ucore.core.Settings; import io.anuke.ucore.core.Settings;
@ -11,8 +12,6 @@ public class Administration{
/**All player info. Maps UUIDs to info. This persists throughout restarts.*/ /**All player info. Maps UUIDs to info. This persists throughout restarts.*/
private ObjectMap<String, PlayerInfo> playerInfo = new ObjectMap<>(); private ObjectMap<String, PlayerInfo> playerInfo = new ObjectMap<>();
/**Maps UUIDs to trace infos. This is wiped when a player logs off.*/
private ObjectMap<String, TraceInfo> traceInfo = new ObjectMap<>();
private Array<String> bannedIPs = new Array<>(); private Array<String> bannedIPs = new Array<>();
public Administration(){ public Administration(){
@ -53,17 +52,20 @@ public class Administration{
if(!info.ips.contains(ip, false)) info.ips.add(ip); if(!info.ips.contains(ip, false)) info.ips.add(ip);
} }
/** public boolean banPlayer(String uuid){
* Returns trace info by UUID. if(bannedIPs.contains(ip, false))
*/ return false;
public TraceInfo getTraceByID(String uuid){
if(!traceInfo.containsKey(uuid)) traceInfo.put(uuid, new TraceInfo(uuid));
return traceInfo.get(uuid); for(PlayerInfo info : playerInfo.values()){
} if(info.ips.contains(ip, false)){
info.banned = true;
}
}
public void clearTraces(){ bannedIPs.add(ip);
traceInfo.clear(); save();
return true;
} }
/** /**
@ -86,9 +88,7 @@ public class Administration{
return true; return true;
} }
/** /**Bans a player by UUID; returns whether this player was already banned.*/
* Bans a player by UUID; returns whether this player was already banned.
*/
public boolean banPlayerID(String id){ public boolean banPlayerID(String id){
if(playerInfo.containsKey(id) && playerInfo.get(id).banned) if(playerInfo.containsKey(id) && playerInfo.get(id).banned)
return false; return false;
@ -215,11 +215,13 @@ public class Administration{
return info.admin && usip.equals(info.adminUsid); return info.admin && usip.equals(info.adminUsid);
} }
public Array<PlayerInfo> findByName(String name, boolean last){ /**Finds player info by IP, UUID and name.*/
Array<PlayerInfo> result = new Array<>(); public ObjectSet<PlayerInfo> findByName(String name){
ObjectSet<PlayerInfo> result = new ObjectSet<>();
for(PlayerInfo info : playerInfo.values()){ for(PlayerInfo info : playerInfo.values()){
if(info.lastName.toLowerCase().equals(name.toLowerCase()) || (last && info.names.contains(name, false))){ if(info.lastName.toLowerCase().equals(name.toLowerCase()) || (info.names.contains(name, false))
|| info.ips.contains(name, false) || info.id.equals(name)){
result.add(info); result.add(info);
} }
} }
@ -287,8 +289,6 @@ public class Administration{
public String adminUsid; public String adminUsid;
public int timesKicked; public int timesKicked;
public int timesJoined; public int timesJoined;
public int totalBlockPlaced;
public int totalBlocksBroken;
public boolean banned, admin; public boolean banned, admin;
public long lastKicked; //last kicked timestamp public long lastKicked; //last kicked timestamp

View File

@ -6,6 +6,9 @@ public abstract class NetConnection{
public final int id; public final int id;
public final String address; public final String address;
public boolean modclient;
public boolean mobile;
public int lastSentSnapshotID = -1; public int lastSentSnapshotID = -1;
/**ID of last recieved client snapshot.*/ /**ID of last recieved client snapshot.*/

View File

@ -1,27 +0,0 @@
package io.anuke.mindustry.net;
import com.badlogic.gdx.utils.IntIntMap;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.world.Block;
public class TraceInfo{
public int playerid;
public String ip;
public boolean modclient;
public boolean android;
public IntIntMap fastShots = new IntIntMap();
public int totalBlocksBroken;
public int structureBlocksBroken;
public Block lastBlockBroken = Blocks.air;
public int totalBlocksPlaced;
public Block lastBlockPlaced = Blocks.air;
public String uuid;
public TraceInfo(String uuid){
this.uuid = uuid;
}
}

View File

@ -1,10 +1,5 @@
package io.anuke.mindustry.ui.dialogs; package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.net.TraceInfo;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
public class TraceDialog extends FloatingDialog{ public class TraceDialog extends FloatingDialog{
public TraceDialog(){ public TraceDialog(){
@ -12,14 +7,15 @@ public class TraceDialog extends FloatingDialog{
addCloseButton(); addCloseButton();
} }
/*
public void show(Player player, TraceInfo info){ public void show(Player player, SessionInfo info){
content().clear(); content().clear();
Table table = new Table("clear"); Table table = new Table("clear");
table.margin(14); table.margin(14);
table.defaults().pad(1); table.defaults().pad(1);
/*
table.defaults().left(); table.defaults().left();
table.add(Bundles.format("text.trace.playername", player.name)); table.add(Bundles.format("text.trace.playername", player.name));
table.row(); table.row();
@ -50,10 +46,10 @@ public class TraceDialog extends FloatingDialog{
table.add(Bundles.format("text.trace.totalblocksplaced", info.totalBlocksPlaced)); table.add(Bundles.format("text.trace.totalblocksplaced", info.totalBlocksPlaced));
table.row(); table.row();
table.add(Bundles.format("text.trace.lastblockplaced", info.lastBlockPlaced.formalName)); table.add(Bundles.format("text.trace.lastblockplaced", info.lastBlockPlaced.formalName));
table.row();*/ table.row();
content().add(table); content().add(table);
show(); show();
} }*/
} }

View File

@ -119,7 +119,7 @@ public class PlayerListFragment extends Fragment{
t.addImageButton("icon-admin", "toggle", 14 * 2, () -> { t.addImageButton("icon-admin", "toggle", 14 * 2, () -> {
if(Net.client()) return; if(Net.client()) return;
String id = netServer.admins.getTraceByID(player.uuid).uuid; String id = player.uuid;
if(netServer.admins.isAdmin(id, connection.address)){ if(netServer.admins.isAdmin(id, connection.address)){
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> netServer.admins.unAdminPlayer(id)); ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> netServer.admins.unAdminPlayer(id));

View File

@ -2,6 +2,7 @@ package io.anuke.mindustry.server;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectSet;
import com.badlogic.gdx.utils.Timer; import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task; import com.badlogic.gdx.utils.Timer.Task;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
@ -18,7 +19,6 @@ import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.net.Administration.PlayerInfo; import io.anuke.mindustry.net.Administration.PlayerInfo;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Packets.KickReason; import io.anuke.mindustry.net.Packets.KickReason;
import io.anuke.mindustry.net.TraceInfo;
import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemType; import io.anuke.mindustry.type.ItemType;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@ -157,7 +157,7 @@ public class ServerControl extends Module{
handler.register("help", "Displays this command list.", arg -> { handler.register("help", "Displays this command list.", arg -> {
info("Commands:"); info("Commands:");
for(Command command : handler.getCommandList()){ for(Command command : handler.getCommandList()){
print(" &y" + command.text + (command.paramText.isEmpty() ? "" : " ") + command.paramText + " - &lm" + command.description); info(" &y" + command.text + (command.paramText.isEmpty() ? "" : " ") + command.paramText + " - &lm" + command.description);
} }
}); });
@ -176,7 +176,6 @@ public class ServerControl extends Module{
Net.closeServer(); Net.closeServer();
if(lastTask != null) lastTask.cancel(); if(lastTask != null) lastTask.cancel();
state.set(State.menu); state.set(State.menu);
netServer.reset();
Log.info("Stopped server."); Log.info("Stopped server.");
}); });
@ -268,7 +267,7 @@ public class ServerControl extends Module{
if(playerGroup.size() > 0){ if(playerGroup.size() > 0){
info("&lyPlayers: {0}", playerGroup.size()); info("&lyPlayers: {0}", playerGroup.size());
for(Player p : playerGroup.all()){ for(Player p : playerGroup.all()){
print(" &y" + p.name); info(" &y{0} / {1}", p.name, p.uuid);
} }
}else{ }else{
info("&lyNo players connected."); info("&lyNo players connected.");
@ -277,21 +276,6 @@ public class ServerControl extends Module{
} }
}); });
handler.register("players", "Display player info.", arg -> {
if(state.is(State.menu)){
info("&lyServer is closed.");
}else{
if(playerGroup.size() > 0){
info("&lyPlayers: {0}", playerGroup.size());
for(Player p : playerGroup.all()){
print(" &y{0} / Connection {1} / IP: {2}", p.name, p.con.id, p.con.address);
}
}else{
info("&lyNo players connected.");
}
}
});
handler.register("say", "<message...>", "Send a message to all players.", arg -> { handler.register("say", "<message...>", "Send a message to all players.", arg -> {
if(!state.is(State.playing)){ if(!state.is(State.playing)){
err("Not hosting. Host a game first."); err("Not hosting. Host a game first.");
@ -384,14 +368,7 @@ public class ServerControl extends Module{
return; return;
} }
Player target = null; Player target = playerGroup.find(p -> p.name.equals(arg[0]));
for(Player player : playerGroup.all()){
if(player.name.equalsIgnoreCase(arg[0])){
target = player;
break;
}
}
if(target != null){ if(target != null){
netServer.kick(target.con.id, KickReason.kick); netServer.kick(target.con.id, KickReason.kick);
@ -401,17 +378,27 @@ public class ServerControl extends Module{
} }
}); });
handler.register("ban", "<username...>", "Ban a person by name.", arg -> { handler.register("ban", "<type (id/name/ip)> <username/IP/ID...>", "Ban a person.", arg -> {
if(!state.is(State.playing)){ if(arg[0].equals("id")){
err("Can't ban people by name with no players."); netServer.admins.banPlayerID(arg[0]);
return; }else if(arg[0].equals("name")){
Player target = playerGroup.find(p -> p.name.equalsIgnoreCase(arg[0]));
if(target != null){
netServer.admins.banPlayer(target.uuid);
}else{
err("No matches found.");
}
}else if(arg[0].equals("ip")){
netServer.admins.banPlayerIP(arg[0]);
}else{
err("Invalid type.");
} }
Player target = null; if(state.is(State.playing)){
for(Player player : playerGroup.all()){
for(Player player : playerGroup.all()){ if(player.name.equalsIgnoreCase(arg[0])){
if(player.name.equalsIgnoreCase(arg[0])){ targets.add(netServer.admins.getInfo(player.uuid));
target = player; }
} }
} }
@ -422,7 +409,7 @@ public class ServerControl extends Module{
netServer.kick(target.con.id, KickReason.banned); netServer.kick(target.con.id, KickReason.banned);
info("Banned player by IP and ID: {0} / {1}", ip, target.uuid); info("Banned player by IP and ID: {0} / {1}", ip, target.uuid);
}else{ }else{
info("Nobody with that name could be found."); info("No matches were found.");
} }
}); });
@ -455,35 +442,6 @@ public class ServerControl extends Module{
} }
}); });
handler.register("banip", "<ip>", "Ban a person by IP.", arg -> {
if(netServer.admins.banPlayerIP(arg[0])){
info("Banned player by IP: {0}.", arg[0]);
for(Player player : playerGroup.all()){
if(player.con.address != null &&
player.con.address.equals(arg[0])){
netServer.kick(player.con.id, KickReason.banned);
}
}
}else{
err("That IP is already banned!");
}
});
handler.register("banid", "<id>", "Ban a person by their unique ID.", arg -> {
if(netServer.admins.banPlayerID(arg[0])){
info("Banned player by ID: {0}.", arg[0]);
for(Player player : playerGroup.all()){
if(player.uuid.equals(arg[0])){
netServer.kick(player.con.id, KickReason.banned);
}
}
}else{
err("That ID is already banned!");
}
});
handler.register("unbanip", "<ip>", "Completely unban a person by IP.", arg -> { handler.register("unbanip", "<ip>", "Completely unban a person by IP.", arg -> {
if(netServer.admins.unbanPlayerIP(arg[0])){ if(netServer.admins.unbanPlayerIP(arg[0])){
info("Unbanned player by IP: {0}.", arg[0]); info("Unbanned player by IP: {0}.", arg[0]);
@ -500,49 +458,35 @@ public class ServerControl extends Module{
} }
}); });
handler.register("admin", "<username...>", "Make a user admin", arg -> { handler.register("admin", "<username...>", "Make an online user admin", arg -> {
if(!state.is(State.playing)){ if(!state.is(State.playing)){
err("Open the server first."); err("Open the server first.");
return; return;
} }
Player target = null; Player target = playerGroup.find(p -> p.name.equals(arg[0]));
for(Player player : playerGroup.all()){
if(player.name.equalsIgnoreCase(arg[0])){
target = player;
break;
}
}
if(target != null){ if(target != null){
netServer.admins.adminPlayer(target.uuid, target.usid); netServer.admins.adminPlayer(target.uuid, target.usid);
target.isAdmin = true; target.isAdmin = true;
info("Admin-ed player by ID: {0} / {1}", target.uuid, arg[0]); info("Admin-ed player: {0}", arg[0]);
}else{ }else{
info("Nobody with that name could be found."); info("Nobody with that name could be found.");
} }
}); });
handler.register("unadmin", "<username...>", "Removes admin status from a player", arg -> { handler.register("unadmin", "<username...>", "Removes admin status from an online player", arg -> {
if(!state.is(State.playing)){ if(!state.is(State.playing)){
err("Open the server first."); err("Open the server first.");
return; return;
} }
Player target = null; Player target = playerGroup.find(p -> p.name.equals(arg[0]));
for(Player player : playerGroup.all()){
if(player.name.equalsIgnoreCase(arg[0])){
target = player;
break;
}
}
if(target != null){ if(target != null){
netServer.admins.unAdminPlayer(target.uuid); netServer.admins.unAdminPlayer(target.uuid);
target.isAdmin = false; target.isAdmin = false;
info("Un-admin-ed player by ID: {0} / {1}", target.uuid, arg[0]); info("Un-admin-ed player: {0}", arg[0]);
}else{ }else{
info("Nobody with that name could be found."); info("Nobody with that name could be found.");
} }
@ -610,37 +554,6 @@ public class ServerControl extends Module{
}); });
}); });
handler.register("griefers", "[min-break:place-ratio] [min-breakage]", "Find possible griefers currently online.", arg -> {
if(!state.is(State.playing)){
err("Open the server first.");
return;
}
try{
float ratio = arg.length > 0 ? Float.parseFloat(arg[0]) : 0.5f;
int minbreak = arg.length > 1 ? Integer.parseInt(arg[1]) : 100;
boolean found = false;
for(Player player : playerGroup.all()){
TraceInfo info = netServer.admins.getTraceByID(player.uuid);
if(info.totalBlocksBroken >= minbreak && info.totalBlocksBroken / Math.max(info.totalBlocksPlaced, 1f) >= ratio){
info("&ly - Player '{0}' / UUID &lm{1}&ly found: &lc{2}&ly broken and &lc{3}&ly placed.",
player.name, info.uuid, info.totalBlocksBroken, info.totalBlocksPlaced);
found = true;
}
}
if(!found){
info("No griefers matching the criteria have been found.");
}
}catch(NumberFormatException e){
err("Invalid number format.");
}
});
handler.register("gameover", "Force a game over.", arg -> { handler.register("gameover", "Force a game over.", arg -> {
if(state.is(State.menu)){ if(state.is(State.menu)){
info("Not playing a map."); info("Not playing a map.");
@ -679,108 +592,22 @@ public class ServerControl extends Module{
} }
}); });
handler.register("find", "<name...>", "Find player info(s) by name. Can optionally check for all names a player has had.", arg -> { handler.register("info", "<IP/UUID/name...>", "Find player info(s). Can optionally check for all names or IPs a player has had.", arg -> {
boolean checkAll = true;
Array<PlayerInfo> infos = netServer.admins.findByName(arg[0], checkAll); ObjectSet<PlayerInfo> infos = netServer.admins.findByName(arg[0]);
if(infos.size == 1){ if(infos.size > 0){
PlayerInfo info = infos.peek(); Log.info("&lgPlayers found: {0}", infos.size);
Log.info("&lcTrace info for player '{0}' / UUID {1}:", info.lastName, info.id);
Log.info(" &lyall names used: {0}", info.names); int i = 0;
Log.info(" &lyIP: {0}", info.lastIP);
Log.info(" &lyall IPs used: {0}", info.ips);
Log.info(" &lytimes joined: {0}", info.timesJoined);
Log.info(" &lytimes kicked: {0}", info.timesKicked);
Log.info("");
Log.info(" &lytotal blocks broken: {0}", info.totalBlocksBroken);
Log.info(" &lytotal blocks placed: {0}", info.totalBlockPlaced);
}else if(infos.size > 1){
Log.info("&lcMultiple people have been found with that name:");
for(PlayerInfo info : infos){ for(PlayerInfo info : infos){
Log.info(" &ly{0}", info.id); Log.info("&lc[{0}] Trace info for player '{1}' / UUID {2}", i ++, info.lastName, info.id);
Log.info(" &lyall names used: {0}", info.names);
Log.info(" &lyIP: {0}", info.lastIP);
Log.info(" &lyall IPs used: {0}", info.ips);
Log.info(" &lytimes joined: {0}", info.timesJoined);
Log.info(" &lytimes kicked: {0}", info.timesKicked);
} }
Log.info("&lcUse the info command to examine each person individually.");
}else{
info("Nobody with that name could be found.");
}
});
handler.register("findip", "<ip>", "Find player info(s) by IP.", arg -> {
Array<PlayerInfo> infos = netServer.admins.findByIPs(arg[0]);
if(infos.size == 1){
PlayerInfo info = infos.peek();
Log.info("&lcTrace info for player '{0}' / UUID {1}:", info.lastName, info.id);
Log.info(" &lyall names used: {0}", info.names);
Log.info(" &lyIP: {0}", info.lastIP);
Log.info(" &lyall IPs used: {0}", info.ips);
Log.info(" &lytimes joined: {0}", info.timesJoined);
Log.info(" &lytimes kicked: {0}", info.timesKicked);
Log.info("");
Log.info(" &lytotal blocks broken: {0}", info.totalBlocksBroken);
Log.info(" &lytotal blocks placed: {0}", info.totalBlockPlaced);
}else if(infos.size > 1){
Log.info("&lcMultiple people have been found with that IP:");
for(PlayerInfo info : infos){
Log.info(" &ly{0}", info.id);
}
Log.info("&lcUse the info command to examine each person individually.");
}else{
info("Nobody with that IP could be found.");
}
});
handler.register("info", "<UUID>", "Get global info for a player's UUID.", arg -> {
PlayerInfo info = netServer.admins.getInfoOptional(arg[0]);
if(info != null){
Log.info("&lcTrace info for player '{0}':", info.lastName);
Log.info(" &lyall names used: {0}", info.names);
Log.info(" &lyIP: {0}", info.lastIP);
Log.info(" &lyall IPs used: {0}", info.ips);
Log.info(" &lytimes joined: {0}", info.timesJoined);
Log.info(" &lytimes kicked: {0}", info.timesKicked);
Log.info("");
Log.info(" &lytotal blocks broken: {0}", info.totalBlocksBroken);
Log.info(" &lytotal blocks placed: {0}", info.totalBlockPlaced);
}else{
info("Nobody with that UUID could be found.");
}
});
handler.register("trace", "<username...>", "Trace a player's actions", arg -> {
if(!state.is(State.playing)){
err("Open the server first.");
return;
}
Player target = null;
for(Player player : playerGroup.all()){
if(player.name.equalsIgnoreCase(arg[0])){
target = player;
break;
}
}
if(target != null){
TraceInfo info = netServer.admins.getTraceByID(target.uuid);
Log.info("&lcTrace info for player '{0}':", target.name);
Log.info(" &lyEntity ID: {0}", info.playerid);
Log.info(" &lyIP: {0}", info.ip);
Log.info(" &lyUUID: {0}", info.uuid);
Log.info(" &lycustom client: {0}", info.modclient);
Log.info(" &lyandroid: {0}", info.android);
Log.info("");
Log.info(" &lytotal blocks broken: {0}", info.totalBlocksBroken);
Log.info(" &lystructure blocks broken: {0}", info.structureBlocksBroken);
Log.info(" &lylast block broken: {0}", info.lastBlockBroken.formalName);
Log.info("");
Log.info(" &lytotal blocks placed: {0}", info.totalBlocksPlaced);
Log.info(" &lylast block placed: {0}", info.lastBlockPlaced.formalName);
}else{ }else{
info("Nobody with that name could be found."); info("Nobody with that name could be found.");
} }
@ -789,7 +616,7 @@ public class ServerControl extends Module{
private void readCommands(){ private void readCommands(){
Scanner scan = new Scanner(System.in); Scanner scan = new Scanner(System.in);
while(true){ while(scan.hasNext()){
String line = scan.nextLine(); String line = scan.nextLine();
Gdx.app.postRunnable(() -> { Gdx.app.postRunnable(() -> {
@ -880,11 +707,4 @@ public class ServerControl extends Module{
state.set(State.menu); state.set(State.menu);
} }
} }
@Override
public void update(){
if(!inExtraRound && state.mode.isPvp){
// checkPvPGameOver();
}
}
} }