forked from BLOCKFANTASY/LOOHP-Limbo
format ClientConnection.java
This commit is contained in:
parent
4353859951
commit
ea7d33a0e3
|
|
@ -1,29 +1,5 @@
|
||||||
package com.loohp.limbo.network;
|
package com.loohp.limbo.network;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketIn;
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
import com.loohp.limbo.Limbo;
|
import com.loohp.limbo.Limbo;
|
||||||
import com.loohp.limbo.events.player.PlayerJoinEvent;
|
import com.loohp.limbo.events.player.PlayerJoinEvent;
|
||||||
import com.loohp.limbo.events.player.PlayerLoginEvent;
|
import com.loohp.limbo.events.player.PlayerLoginEvent;
|
||||||
|
|
@ -34,8 +10,8 @@ import com.loohp.limbo.events.player.PlayerSelectedSlotChangeEvent;
|
||||||
import com.loohp.limbo.events.status.StatusPingEvent;
|
import com.loohp.limbo.events.status.StatusPingEvent;
|
||||||
import com.loohp.limbo.file.ServerProperties;
|
import com.loohp.limbo.file.ServerProperties;
|
||||||
import com.loohp.limbo.location.Location;
|
import com.loohp.limbo.location.Location;
|
||||||
import com.loohp.limbo.network.protocol.packets.Packet;
|
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketHandshakingIn;
|
import com.loohp.limbo.network.protocol.packets.PacketHandshakingIn;
|
||||||
|
import com.loohp.limbo.network.protocol.packets.PacketIn;
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketLoginInLoginStart;
|
import com.loohp.limbo.network.protocol.packets.PacketLoginInLoginStart;
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketLoginInPluginMessaging;
|
import com.loohp.limbo.network.protocol.packets.PacketLoginInPluginMessaging;
|
||||||
import com.loohp.limbo.network.protocol.packets.PacketLoginOutDisconnect;
|
import com.loohp.limbo.network.protocol.packets.PacketLoginOutDisconnect;
|
||||||
|
|
@ -86,27 +62,39 @@ import com.loohp.limbo.utils.MojangAPIUtils;
|
||||||
import com.loohp.limbo.utils.MojangAPIUtils.SkinResponse;
|
import com.loohp.limbo.utils.MojangAPIUtils.SkinResponse;
|
||||||
import com.loohp.limbo.world.BlockPosition;
|
import com.loohp.limbo.world.BlockPosition;
|
||||||
import com.loohp.limbo.world.World;
|
import com.loohp.limbo.world.World;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ClientConnection extends Thread {
|
public class ClientConnection extends Thread {
|
||||||
|
|
||||||
public static enum ClientState {
|
|
||||||
LEGACY,
|
|
||||||
HANDSHAKE,
|
|
||||||
STATUS,
|
|
||||||
LOGIN,
|
|
||||||
PLAY,
|
|
||||||
DISCONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
private final Socket client_socket;
|
private final Socket client_socket;
|
||||||
|
protected Channel channel;
|
||||||
private boolean running;
|
private boolean running;
|
||||||
private ClientState state;
|
private ClientState state;
|
||||||
|
|
||||||
|
|
@ -114,11 +102,7 @@ public class ClientConnection extends Thread {
|
||||||
private TimerTask keepAliveTask;
|
private TimerTask keepAliveTask;
|
||||||
private AtomicLong lastPacketTimestamp;
|
private AtomicLong lastPacketTimestamp;
|
||||||
private AtomicLong lastKeepAlivePayLoad;
|
private AtomicLong lastKeepAlivePayLoad;
|
||||||
|
|
||||||
protected Channel channel;
|
|
||||||
|
|
||||||
private InetAddress inetAddress;
|
private InetAddress inetAddress;
|
||||||
|
|
||||||
private boolean ready;
|
private boolean ready;
|
||||||
|
|
||||||
public ClientConnection(Socket client_socket) {
|
public ClientConnection(Socket client_socket) {
|
||||||
|
|
@ -193,10 +177,12 @@ public class ClientConnection extends Thread {
|
||||||
try {
|
try {
|
||||||
PacketPlayOutDisconnect packet = new PacketPlayOutDisconnect(reason);
|
PacketPlayOutDisconnect packet = new PacketPlayOutDisconnect(reason);
|
||||||
sendPacket(packet);
|
sendPacket(packet);
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
client_socket.close();
|
client_socket.close();
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disconnectDuringLogin(BaseComponent[] reason) {
|
private void disconnectDuringLogin(BaseComponent[] reason) {
|
||||||
|
|
@ -207,10 +193,12 @@ public class ClientConnection extends Thread {
|
||||||
try {
|
try {
|
||||||
PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(reason);
|
PacketLoginOutDisconnect packet = new PacketLoginOutDisconnect(reason);
|
||||||
sendPacket(packet);
|
sendPacket(packet);
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
client_socket.close();
|
client_socket.close();
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
|
@ -467,7 +455,8 @@ public class ClientConnection extends Thread {
|
||||||
try {
|
try {
|
||||||
sendPacket(keepAlivePacket);
|
sendPacket(keepAlivePacket);
|
||||||
setLastKeepAlivePayLoad(now);
|
setLastKeepAlivePayLoad(now);
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
@ -581,12 +570,14 @@ public class ClientConnection extends Thread {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
channel.close();
|
channel.close();
|
||||||
client_socket.close();
|
client_socket.close();
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
state = ClientState.DISCONNECTED;
|
state = ClientState.DISCONNECTED;
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
|
|
@ -596,4 +587,13 @@ public class ClientConnection extends Thread {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static enum ClientState {
|
||||||
|
LEGACY,
|
||||||
|
HANDSHAKE,
|
||||||
|
STATUS,
|
||||||
|
LOGIN,
|
||||||
|
PLAY,
|
||||||
|
DISCONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue