Broke and cleaned up server commands
This commit is contained in:
@@ -21,7 +21,6 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.net.TraceInfo;
|
||||
import io.anuke.mindustry.net.ValidateException;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.modules.ItemModule;
|
||||
@@ -207,12 +206,6 @@ public class NetClient extends Module{
|
||||
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
|
||||
public static void onPlayerDisconnect(int playerid){
|
||||
playerGroup.removeByID(playerid);
|
||||
|
||||
@@ -106,11 +106,9 @@ public class NetServer extends Module{
|
||||
|
||||
connection.hasBegunConnecting = true;
|
||||
|
||||
TraceInfo trace = admins.getTraceByID(uuid);
|
||||
PlayerInfo info = admins.getInfo(uuid);
|
||||
trace.uuid = uuid;
|
||||
trace.ip = connection.address;
|
||||
trace.android = packet.mobile;
|
||||
|
||||
connection.mobile = packet.mobile;
|
||||
|
||||
if(admins.isIDBanned(uuid)){
|
||||
kick(id, KickReason.banned);
|
||||
@@ -150,7 +148,7 @@ public class NetServer extends Module{
|
||||
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;
|
||||
|
||||
@@ -162,7 +160,7 @@ public class NetServer extends Module{
|
||||
}
|
||||
|
||||
if(packet.version == -1){
|
||||
trace.modclient = true;
|
||||
connection.modclient = true;
|
||||
}
|
||||
|
||||
Player player = new Player();
|
||||
@@ -207,8 +205,6 @@ public class NetServer extends Module{
|
||||
|
||||
connections.put(id, player);
|
||||
|
||||
trace.playerid = player.id;
|
||||
|
||||
sendWorldData(player, id);
|
||||
|
||||
Platform.instance.updateRPC();
|
||||
@@ -395,11 +391,11 @@ public class NetServer extends Module{
|
||||
netServer.kick(other.con.id, KickReason.kick);
|
||||
Log.info("&lc{0} has kicked {1}.", player.name, other.name);
|
||||
}else if(action == AdminAction.trace){
|
||||
//TODO
|
||||
//TODO implement
|
||||
if(player.con != null){
|
||||
Call.onTraceInfo(player.con.id, netServer.admins.getTraceByID(other.uuid));
|
||||
//Call.onTraceInfo(player.con.id, other.con.trace);
|
||||
}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);
|
||||
}
|
||||
@@ -424,7 +420,6 @@ public class NetServer extends Module{
|
||||
|
||||
if(!headless && !closing && Net.server() && state.is(State.menu)){
|
||||
closing = true;
|
||||
reset();
|
||||
threads.runGraphics(() -> ui.loadfrag.show("$text.server.closing"));
|
||||
Timers.runTask(5f, () -> {
|
||||
Net.closeServer();
|
||||
@@ -438,10 +433,6 @@ public class NetServer extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
admins.clearTraces();
|
||||
}
|
||||
|
||||
public void kickAll(KickReason reason){
|
||||
for(NetConnection con : Net.getConnections()){
|
||||
kick(con.id, reason);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.io;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import io.anuke.annotations.Annotations.ReadClass;
|
||||
import io.anuke.annotations.Annotations.WriteClass;
|
||||
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.net.Packets.AdminAction;
|
||||
import io.anuke.mindustry.net.Packets.KickReason;
|
||||
import io.anuke.mindustry.net.TraceInfo;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -364,45 +362,4 @@ public class TypeIO{
|
||||
buffer.get(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import io.anuke.annotations.Annotations.Serialize;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
|
||||
@@ -11,8 +12,6 @@ public class Administration{
|
||||
|
||||
/**All player info. Maps UUIDs to info. This persists throughout restarts.*/
|
||||
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<>();
|
||||
|
||||
public Administration(){
|
||||
@@ -53,17 +52,20 @@ public class Administration{
|
||||
if(!info.ips.contains(ip, false)) info.ips.add(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns trace info by UUID.
|
||||
*/
|
||||
public TraceInfo getTraceByID(String uuid){
|
||||
if(!traceInfo.containsKey(uuid)) traceInfo.put(uuid, new TraceInfo(uuid));
|
||||
public boolean banPlayer(String uuid){
|
||||
if(bannedIPs.contains(ip, false))
|
||||
return false;
|
||||
|
||||
return traceInfo.get(uuid);
|
||||
}
|
||||
for(PlayerInfo info : playerInfo.values()){
|
||||
if(info.ips.contains(ip, false)){
|
||||
info.banned = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearTraces(){
|
||||
traceInfo.clear();
|
||||
bannedIPs.add(ip);
|
||||
save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,9 +88,7 @@ public class Administration{
|
||||
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){
|
||||
if(playerInfo.containsKey(id) && playerInfo.get(id).banned)
|
||||
return false;
|
||||
@@ -215,11 +215,13 @@ public class Administration{
|
||||
return info.admin && usip.equals(info.adminUsid);
|
||||
}
|
||||
|
||||
public Array<PlayerInfo> findByName(String name, boolean last){
|
||||
Array<PlayerInfo> result = new Array<>();
|
||||
/**Finds player info by IP, UUID and name.*/
|
||||
public ObjectSet<PlayerInfo> findByName(String name){
|
||||
ObjectSet<PlayerInfo> result = new ObjectSet<>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -287,8 +289,6 @@ public class Administration{
|
||||
public String adminUsid;
|
||||
public int timesKicked;
|
||||
public int timesJoined;
|
||||
public int totalBlockPlaced;
|
||||
public int totalBlocksBroken;
|
||||
public boolean banned, admin;
|
||||
public long lastKicked; //last kicked timestamp
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ public abstract class NetConnection{
|
||||
public final int id;
|
||||
public final String address;
|
||||
|
||||
public boolean modclient;
|
||||
public boolean mobile;
|
||||
|
||||
public int lastSentSnapshotID = -1;
|
||||
|
||||
/**ID of last recieved client snapshot.*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
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 TraceDialog(){
|
||||
@@ -12,14 +7,15 @@ public class TraceDialog extends FloatingDialog{
|
||||
|
||||
addCloseButton();
|
||||
}
|
||||
|
||||
public void show(Player player, TraceInfo info){
|
||||
/*
|
||||
public void show(Player player, SessionInfo info){
|
||||
content().clear();
|
||||
|
||||
Table table = new Table("clear");
|
||||
table.margin(14);
|
||||
table.defaults().pad(1);
|
||||
|
||||
/*
|
||||
table.defaults().left();
|
||||
table.add(Bundles.format("text.trace.playername", player.name));
|
||||
table.row();
|
||||
@@ -50,10 +46,10 @@ public class TraceDialog extends FloatingDialog{
|
||||
table.add(Bundles.format("text.trace.totalblocksplaced", info.totalBlocksPlaced));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.trace.lastblockplaced", info.lastBlockPlaced.formalName));
|
||||
table.row();*/
|
||||
table.row();
|
||||
|
||||
content().add(table);
|
||||
|
||||
show();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class PlayerListFragment extends Fragment{
|
||||
t.addImageButton("icon-admin", "toggle", 14 * 2, () -> {
|
||||
if(Net.client()) return;
|
||||
|
||||
String id = netServer.admins.getTraceByID(player.uuid).uuid;
|
||||
String id = player.uuid;
|
||||
|
||||
if(netServer.admins.isAdmin(id, connection.address)){
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> netServer.admins.unAdminPlayer(id));
|
||||
|
||||
Reference in New Issue
Block a user