Source reformat
This commit is contained in:
@@ -2,21 +2,19 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.annotations.Annotations.Serialize;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.ObjectMap;
|
||||
import io.anuke.arc.collection.ObjectSet;
|
||||
import io.anuke.arc.collection.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.headless;
|
||||
|
||||
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 Array<String> bannedIPs = new Array<>();
|
||||
|
||||
public Administration(){
|
||||
Core.settings.defaults(
|
||||
"strict", true
|
||||
"strict", true
|
||||
);
|
||||
|
||||
load();
|
||||
@@ -40,7 +38,7 @@ public class Administration{
|
||||
Core.settings.save();
|
||||
}
|
||||
|
||||
/**Call when a player joins to update their information here.*/
|
||||
/** Call when a player joins to update their information here. */
|
||||
public void updatePlayerJoined(String id, String ip, String name){
|
||||
PlayerInfo info = getCreateInfo(id);
|
||||
info.lastName = name;
|
||||
@@ -74,7 +72,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;
|
||||
@@ -201,13 +199,13 @@ public class Administration{
|
||||
return info.admin && usid.equals(info.adminUsid);
|
||||
}
|
||||
|
||||
/**Finds player info by IP, UUID and name.*/
|
||||
/** 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()) || (info.names.contains(name, false))
|
||||
|| info.ips.contains(name, false) || info.id.equals(name)){
|
||||
|| info.ips.contains(name, false) || info.id.equals(name)){
|
||||
result.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.Net.HttpRequest;
|
||||
import io.anuke.arc.Net.HttpResponse;
|
||||
import io.anuke.arc.Net.HttpResponseListener;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.IntMap;
|
||||
import io.anuke.arc.collection.ObjectMap;
|
||||
import io.anuke.arc.Net.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.function.BiConsumer;
|
||||
import io.anuke.arc.function.Consumer;
|
||||
import io.anuke.arc.net.HttpRequestBuilder;
|
||||
@@ -15,9 +11,7 @@ import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.util.pooling.Pools;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.net.Packets.KickReason;
|
||||
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||
import io.anuke.mindustry.net.Packets.StreamChunk;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -47,7 +41,7 @@ public class Net{
|
||||
return serverProvider != null;
|
||||
}
|
||||
|
||||
/**Display a network error. Call on the graphics thread.*/
|
||||
/** Display a network error. Call on the graphics thread. */
|
||||
public static void showError(Throwable e){
|
||||
|
||||
if(!headless){
|
||||
@@ -170,7 +164,7 @@ public class Net{
|
||||
* Returns a list of all connections IDs.
|
||||
*/
|
||||
public static Array<NetConnection> getConnections(){
|
||||
return (Array<NetConnection>) serverProvider.getConnections();
|
||||
return (Array<NetConnection>)serverProvider.getConnections();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +231,7 @@ public class Net{
|
||||
* Registers a server listener for when an object is recieved.
|
||||
*/
|
||||
public static <T> void handleServer(Class<T> type, BiConsumer<Integer, T> listener){
|
||||
serverListeners.put(type, (BiConsumer<Integer, Object>) listener);
|
||||
serverListeners.put(type, (BiConsumer<Integer, Object>)listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,10 +240,10 @@ public class Net{
|
||||
public static void handleClientReceived(Object object){
|
||||
|
||||
if(object instanceof StreamBegin){
|
||||
StreamBegin b = (StreamBegin) object;
|
||||
StreamBegin b = (StreamBegin)object;
|
||||
streams.put(b.id, new StreamBuilder(b));
|
||||
}else if(object instanceof StreamChunk){
|
||||
StreamChunk c = (StreamChunk) object;
|
||||
StreamChunk c = (StreamChunk)object;
|
||||
StreamBuilder builder = streams.get(c.id);
|
||||
if(builder == null){
|
||||
throw new RuntimeException("Recieved stream chunk without a StreamBegin beforehand!");
|
||||
@@ -261,11 +255,11 @@ public class Net{
|
||||
}
|
||||
}else if(clientListeners.get(object.getClass()) != null){
|
||||
|
||||
if(clientLoaded || ((object instanceof Packet) && ((Packet) object).isImportant())){
|
||||
if(clientLoaded || ((object instanceof Packet) && ((Packet)object).isImportant())){
|
||||
if(clientListeners.get(object.getClass()) != null)
|
||||
clientListeners.get(object.getClass()).accept(object);
|
||||
Pools.free(object);
|
||||
}else if(!((object instanceof Packet) && ((Packet) object).isUnimportant())){
|
||||
}else if(!((object instanceof Packet) && ((Packet)object).isUnimportant())){
|
||||
packetQueue.add(object);
|
||||
}else{
|
||||
Pools.free(object);
|
||||
@@ -369,24 +363,24 @@ public class Net{
|
||||
tcp, udp
|
||||
}
|
||||
|
||||
/**Client implementation.*/
|
||||
/** Client implementation. */
|
||||
public interface ClientProvider{
|
||||
/**Connect to a server.*/
|
||||
/** Connect to a server. */
|
||||
void connect(String ip, int port, Runnable success) throws IOException;
|
||||
|
||||
/**Send an object to the server.*/
|
||||
/** Send an object to the server. */
|
||||
void send(Object object, SendMode mode);
|
||||
|
||||
/**Update the ping. Should be done every second or so.*/
|
||||
/** Update the ping. Should be done every second or so. */
|
||||
void updatePing();
|
||||
|
||||
/**Get ping in milliseconds. Will only be valid after a call to updatePing.*/
|
||||
/** Get ping in milliseconds. Will only be valid after a call to updatePing. */
|
||||
int getPing();
|
||||
|
||||
/**Disconnect from the server.*/
|
||||
/** Disconnect from the server. */
|
||||
void disconnect();
|
||||
|
||||
/**Decompress an input snapshot byte array.*/
|
||||
/** Decompress an input snapshot byte array. */
|
||||
byte[] decompressSnapshot(byte[] input, int size);
|
||||
|
||||
/**
|
||||
@@ -396,43 +390,43 @@ public class Net{
|
||||
*/
|
||||
void discover(Consumer<Host> callback, Runnable done);
|
||||
|
||||
/**Ping a host. If an error occured, failed() should be called with the exception.*/
|
||||
/** Ping a host. If an error occured, failed() should be called with the exception. */
|
||||
void pingHost(String address, int port, Consumer<Host> valid, Consumer<Exception> failed);
|
||||
|
||||
/**Close all connections.*/
|
||||
/** Close all connections. */
|
||||
void dispose();
|
||||
}
|
||||
|
||||
/**Server implementation.*/
|
||||
/** Server implementation. */
|
||||
public interface ServerProvider{
|
||||
/**Host a server at specified port.*/
|
||||
/** Host a server at specified port. */
|
||||
void host(int port) throws IOException;
|
||||
|
||||
/**Sends a large stream of data to a specific client.*/
|
||||
/** Sends a large stream of data to a specific client. */
|
||||
void sendStream(int id, Streamable stream);
|
||||
|
||||
/**Send an object to everyone connected.*/
|
||||
/** Send an object to everyone connected. */
|
||||
void send(Object object, SendMode mode);
|
||||
|
||||
/**Send an object to a specific client ID.*/
|
||||
/** Send an object to a specific client ID. */
|
||||
void sendTo(int id, Object object, SendMode mode);
|
||||
|
||||
/**Send an object to everyone <i>except</i> a client ID.*/
|
||||
/** Send an object to everyone <i>except</i> a client ID. */
|
||||
void sendExcept(int id, Object object, SendMode mode);
|
||||
|
||||
/**Close the server connection.*/
|
||||
/** Close the server connection. */
|
||||
void close();
|
||||
|
||||
/**Compress an input snapshot byte array.*/
|
||||
/** Compress an input snapshot byte array. */
|
||||
byte[] compressSnapshot(byte[] input);
|
||||
|
||||
/**Return all connected users.*/
|
||||
/** Return all connected users. */
|
||||
Array<? extends NetConnection> getConnections();
|
||||
|
||||
/**Returns a connection by ID.*/
|
||||
/** Returns a connection by ID. */
|
||||
NetConnection getByID(int id);
|
||||
|
||||
/**Close all connections.*/
|
||||
/** Close all connections. */
|
||||
void dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ public abstract class NetConnection{
|
||||
public boolean modclient;
|
||||
public boolean mobile;
|
||||
|
||||
/**ID of last recieved client snapshot.*/
|
||||
/** ID of last recieved client snapshot. */
|
||||
public int lastRecievedClientSnapshot = -1;
|
||||
/**Timestamp of last recieved snapshot.*/
|
||||
/** Timestamp of last recieved snapshot. */
|
||||
public long lastRecievedClientTime;
|
||||
|
||||
public boolean hasConnected = false;
|
||||
|
||||
@@ -6,10 +6,8 @@ import io.anuke.arc.collection.ObjectMap.Entry;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.entities.Entities;
|
||||
import io.anuke.mindustry.entities.type.Player;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.Teams;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.game.Teams.TeamData;
|
||||
import io.anuke.mindustry.game.Version;
|
||||
import io.anuke.mindustry.gen.Serialization;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.maps.Map;
|
||||
@@ -146,10 +144,10 @@ public class NetworkIO{
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(128);
|
||||
|
||||
buffer.put((byte) host.getBytes(charset).length);
|
||||
buffer.put((byte)host.getBytes(charset).length);
|
||||
buffer.put(host.getBytes(charset));
|
||||
|
||||
buffer.put((byte) map.getBytes(charset).length);
|
||||
buffer.put((byte)map.getBytes(charset).length);
|
||||
buffer.put(map.getBytes(charset));
|
||||
|
||||
buffer.putInt(playerGroup.size());
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Packets{
|
||||
TypeIO.writeString(buffer, versionType);
|
||||
TypeIO.writeString(buffer, name);
|
||||
TypeIO.writeString(buffer, usid);
|
||||
buffer.put(mobile ? (byte) 1 : 0);
|
||||
buffer.put(mobile ? (byte)1 : 0);
|
||||
buffer.putInt(color);
|
||||
buffer.put(Base64Coder.decode(uuid));
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class Packets{
|
||||
public void write(ByteBuffer buffer){
|
||||
buffer.put(type);
|
||||
buffer.put(priority);
|
||||
buffer.putShort((short) writeLength);
|
||||
buffer.putShort((short)writeLength);
|
||||
|
||||
writeBuffer.position(0);
|
||||
for(int i = 0; i < writeLength; i++){
|
||||
@@ -139,7 +139,7 @@ public class Packets{
|
||||
}
|
||||
}
|
||||
|
||||
/**Marks the beginning of a stream.*/
|
||||
/** Marks the beginning of a stream. */
|
||||
public static class StreamBegin implements Packet{
|
||||
private static int lastid;
|
||||
|
||||
@@ -169,7 +169,7 @@ public class Packets{
|
||||
@Override
|
||||
public void write(ByteBuffer buffer){
|
||||
buffer.putInt(id);
|
||||
buffer.putShort((short) data.length);
|
||||
buffer.putShort((short)data.length);
|
||||
buffer.put(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ import io.anuke.mindustry.net.Packets.*;
|
||||
|
||||
public class Registrator{
|
||||
private static ClassEntry[] classes = {
|
||||
new ClassEntry(StreamBegin.class, StreamBegin::new),
|
||||
new ClassEntry(StreamChunk.class, StreamChunk::new),
|
||||
new ClassEntry(WorldStream.class, WorldStream::new),
|
||||
new ClassEntry(ConnectPacket.class, ConnectPacket::new),
|
||||
new ClassEntry(InvokePacket.class, InvokePacket::new)
|
||||
new ClassEntry(StreamBegin.class, StreamBegin::new),
|
||||
new ClassEntry(StreamChunk.class, StreamChunk::new),
|
||||
new ClassEntry(WorldStream.class, WorldStream::new),
|
||||
new ClassEntry(ConnectPacket.class, ConnectPacket::new),
|
||||
new ClassEntry(InvokePacket.class, InvokePacket::new)
|
||||
};
|
||||
private static ObjectIntMap<Class> ids = new ObjectIntMap<>();
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Registrator{
|
||||
}
|
||||
|
||||
public static byte getID(Class<?> type){
|
||||
return (byte) ids.get(type, -1);
|
||||
return (byte)ids.get(type, -1);
|
||||
}
|
||||
|
||||
public static ClassEntry[] getClasses(){
|
||||
|
||||
@@ -2,9 +2,7 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
public class Streamable implements Packet{
|
||||
public transient ByteArrayInputStream stream;
|
||||
@@ -36,7 +34,7 @@ public class Streamable implements Packet{
|
||||
}
|
||||
|
||||
public Streamable build(){
|
||||
Streamable s = (Streamable) Registrator.getByID(type).constructor.get();
|
||||
Streamable s = (Streamable)Registrator.getByID(type).constructor.get();
|
||||
s.stream = new ByteArrayInputStream(stream.toByteArray());
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user