Some websocket code

This commit is contained in:
catfoolyou 2025-02-04 12:41:18 -05:00
parent d90a17eb7a
commit ac8bb6cc9e
15 changed files with 61 additions and 1104 deletions

Binary file not shown.

View File

@ -487,7 +487,7 @@ public class DefaultSkinRenderer {
EaglerAdapter.glRotatef(180.0f, 1.0f, 0.0f, 0.0f); EaglerAdapter.glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
EaglerAdapter.glEnable(EaglerAdapter.GL_RESCALE_NORMAL); EaglerAdapter.glEnable(EaglerAdapter.GL_RESCALE_NORMAL);
EaglerAdapter.glScalef(1.0F, -1.0F, 1.0F); EaglerAdapter.glScalef(1.0F, -1.0F, 1.0F);
RenderHelper.enableGUIStandardItemLighting(); RenderHelper.enableGUIStandardItemLighting2();
EaglerAdapter.glTranslatef(0.0F, 1.0F, 0.0F); EaglerAdapter.glTranslatef(0.0F, 1.0F, 0.0F);
if(capeMode) { if(capeMode) {
EaglerAdapter.glRotatef(140.0f, 0.0f, 1.0f, 0.0f); EaglerAdapter.glRotatef(140.0f, 0.0f, 1.0f, 0.0f);

View File

@ -33,7 +33,6 @@ import net.minecraft.src.ISaveHandler;
import net.minecraft.src.IUpdatePlayerListBox; import net.minecraft.src.IUpdatePlayerListBox;
import net.minecraft.src.MathHelper; import net.minecraft.src.MathHelper;
import net.minecraft.src.MinecraftException; import net.minecraft.src.MinecraftException;
import net.minecraft.src.NetworkListenThread;
import net.minecraft.src.Packet; import net.minecraft.src.Packet;
import net.minecraft.src.Packet4UpdateTime; import net.minecraft.src.Packet4UpdateTime;
import net.minecraft.src.PlayerUsageSnooper; import net.minecraft.src.PlayerUsageSnooper;
@ -383,11 +382,6 @@ public abstract class MinecraftServer implements ICommandSender, Runnable, IPlay
{ {
this.getLogAgent().logInfo("Stopping server"); this.getLogAgent().logInfo("Stopping server");
if (this.getNetworkThread() != null)
{
this.getNetworkThread().stopListening();
}
if (this.serverConfigManager != null) if (this.serverConfigManager != null)
{ {
this.getLogAgent().logInfo("Saving players"); this.getLogAgent().logInfo("Saving players");
@ -663,7 +657,6 @@ public abstract class MinecraftServer implements ICommandSender, Runnable, IPlay
} }
this.theProfiler.endStartSection("connection"); this.theProfiler.endStartSection("connection");
this.getNetworkThread().networkTick();
this.theProfiler.endStartSection("players"); this.theProfiler.endStartSection("players");
this.serverConfigManager.sendPlayerInfoToAllPlayers(); this.serverConfigManager.sendPlayerInfoToAllPlayers();
this.theProfiler.endStartSection("tickables"); this.theProfiler.endStartSection("tickables");
@ -1253,7 +1246,6 @@ public abstract class MinecraftServer implements ICommandSender, Runnable, IPlay
} }
} }
public abstract NetworkListenThread getNetworkThread();
public boolean serverIsInRunLoop() public boolean serverIsInRunLoop()
{ {

View File

@ -1,26 +0,0 @@
package net.minecraft.src;
import java.util.concurrent.Callable;
class CallableConnectionName implements Callable
{
final NetServerHandler field_111201_a;
final NetworkListenThread field_111200_b;
CallableConnectionName(NetworkListenThread par1NetworkListenThread, NetServerHandler par2NetServerHandler)
{
this.field_111200_b = par1NetworkListenThread;
this.field_111201_a = par2NetServerHandler;
}
public String func_111199_a()
{
return this.field_111201_a.toString();
}
public Object call()
{
return this.func_111199_a();
}
}

View File

@ -1,44 +1,44 @@
package net.minecraft.src; package net.minecraft.src;
import java.net.SocketAddress; public interface INetworkManager {
public interface INetworkManager
{
/** /**
* Sets the NetHandler for this NetworkManager. Server-only. * Sets the NetHandler for this NetworkManager. Server-only.
*/ */
void setNetHandler(NetHandler var1); public void setNetHandler(NetHandler var1);
/** /**
* Adds the packet to the correct send queue (chunk data packets go to a separate queue). * Adds the packet to the correct send queue (chunk data packets go to a
* separate queue).
*/ */
void addToSendQueue(Packet var1); public void addToSendQueue(Packet var1);
/** /**
* Wakes reader and writer threads * Wakes reader and writer threads
*/ */
void wakeThreads(); public void wakeThreads();
/** /**
* Checks timeouts and processes all pending read packets. * Checks timeouts and processes all pending read packets.
*/ */
void processReadPackets(); public void processReadPackets();
/** /**
* Shuts down the server. (Only actually used on the server) * Shuts down the server. (Only actually used on the server)
*/ */
void serverShutdown(); public void serverShutdown();
/** /**
* returns 0 for memoryConnections * returns 0 for memoryConnections
*/ */
int packetSize(); public int packetSize();
/** /**
* Shuts down the network with the specified reason. Closes all streams and sockets, spawns NetworkMasterThread to * Shuts down the network with the specified reason. Closes all streams and
* stop reading and writing threads. * sockets, spawns NetworkMasterThread to stop reading and writing threads.
*/ */
void networkShutdown(String var1, Object ... var2); public void networkShutdown(String var1, Object... var2);
void closeConnections(); public void closeConnections();
public String getServerURI();
} }

View File

@ -1,158 +0,0 @@
package net.minecraft.src;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MemoryConnection implements INetworkManager
{
private static final SocketAddress mySocketAddress = new InetSocketAddress("127.0.0.1", 0);
private final List readPacketCache = Collections.synchronizedList(new ArrayList());
private final ILogAgent field_98214_c;
private MemoryConnection pairedConnection;
private NetHandler myNetHandler;
/** set to true by {server,network}Shutdown */
private boolean shuttingDown;
private String shutdownReason = "";
private Object[] field_74439_g;
private boolean gamePaused;
public MemoryConnection(ILogAgent par1ILogAgent, NetHandler par2NetHandler)
{
this.myNetHandler = par2NetHandler;
this.field_98214_c = par1ILogAgent;
}
/**
* Sets the NetHandler for this NetworkManager. Server-only.
*/
public void setNetHandler(NetHandler par1NetHandler)
{
this.myNetHandler = par1NetHandler;
}
/**
* Adds the packet to the correct send queue (chunk data packets go to a separate queue).
*/
public void addToSendQueue(Packet par1Packet)
{
if (!this.shuttingDown)
{
this.pairedConnection.processOrCachePacket(par1Packet);
}
}
public void closeConnections()
{
this.pairedConnection = null;
this.myNetHandler = null;
}
public boolean isConnectionActive()
{
return !this.shuttingDown && this.pairedConnection != null;
}
/**
* Wakes reader and writer threads
*/
public void wakeThreads() {}
/**
* Checks timeouts and processes all pending read packets.
*/
public void processReadPackets()
{
int var1 = 2500;
while (var1-- >= 0 && !this.readPacketCache.isEmpty())
{
Packet var2 = (Packet)this.readPacketCache.remove(0);
var2.processPacket(this.myNetHandler);
}
if (this.readPacketCache.size() > var1)
{
this.field_98214_c.logWarning("Memory connection overburdened; after processing 2500 packets, we still have " + this.readPacketCache.size() + " to go!");
}
if (this.shuttingDown && this.readPacketCache.isEmpty())
{
this.myNetHandler.handleErrorMessage(this.shutdownReason, this.field_74439_g);
}
}
/**
* Return the InetSocketAddress of the remote endpoint
*/
public SocketAddress getSocketAddress()
{
return mySocketAddress;
}
/**
* Shuts down the server. (Only actually used on the server)
*/
public void serverShutdown()
{
this.shuttingDown = true;
}
/**
* Shuts down the network with the specified reason. Closes all streams and sockets, spawns NetworkMasterThread to
* stop reading and writing threads.
*/
public void networkShutdown(String par1Str, Object ... par2ArrayOfObj)
{
this.shuttingDown = true;
this.shutdownReason = par1Str;
this.field_74439_g = par2ArrayOfObj;
}
/**
* returns 0 for memoryConnections
*/
public int packetSize()
{
return 0;
}
public void pairWith(MemoryConnection par1MemoryConnection)
{
this.pairedConnection = par1MemoryConnection;
par1MemoryConnection.pairedConnection = this;
}
public boolean isGamePaused()
{
return this.gamePaused;
}
public void setGamePaused(boolean par1)
{
this.gamePaused = par1;
}
public MemoryConnection getPairedConnection()
{
return this.pairedConnection;
}
/**
* acts immiditally if isWritePacket, otherwise adds it to the readCache to be processed next tick
*/
public void processOrCachePacket(Packet par1Packet)
{
if (par1Packet.canProcessAsync() && this.myNetHandler.canProcessPacketsAsync())
{
par1Packet.processPacket(this.myNetHandler);
}
else
{
this.readPacketCache.add(par1Packet);
}
}
}

View File

@ -2142,7 +2142,7 @@ public class Minecraft
public Session getSession() public Session getSession()
{ {
return null; return new Session(EaglerProfile.username, EaglerProfile.username);
} }
public RenderEngine getTextureManager() public RenderEngine getTextureManager()

View File

@ -1,77 +0,0 @@
package net.minecraft.src;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.server.MinecraftServer;
public abstract class NetworkListenThread
{
/** Reference to the MinecraftServer object. */
private final MinecraftServer mcServer;
private final List connections = Collections.synchronizedList(new ArrayList());
/** Whether the network listener object is listening. */
public volatile boolean isListening;
public NetworkListenThread(MinecraftServer par1MinecraftServer) throws IOException
{
this.mcServer = par1MinecraftServer;
this.isListening = true;
}
/**
* adds this connection to the list of currently connected players
*/
public void addPlayer(NetServerHandler par1NetServerHandler)
{
this.connections.add(par1NetServerHandler);
}
public void stopListening()
{
this.isListening = false;
}
/**
* processes packets and pending connections
*/
public void networkTick()
{
for (int var1 = 0; var1 < this.connections.size(); ++var1)
{
NetServerHandler var2 = (NetServerHandler)this.connections.get(var1);
try
{
var2.networkTick();
}
catch (Exception var6)
{
if (var2.netManager instanceof MemoryConnection)
{
CrashReport var4 = CrashReport.makeCrashReport(var6, "Ticking memory connection");
CrashReportCategory var5 = var4.makeCategory("Ticking connection");
var5.addCrashSectionCallable("Connection", new CallableConnectionName(this, var2));
throw new ReportedException(var4);
}
this.mcServer.getLogAgent().logWarningException("Failed to handle packet for " + var2.playerEntity.getEntityName() + "/" + var2.playerEntity.getPlayerIP() + ": " + var6, var6);
var2.kickPlayerFromServer("Internal server error");
}
if (var2.connectionClosed)
{
this.connections.remove(var1--);
}
var2.netManager.wakeThreads();
}
}
public MinecraftServer getServer()
{
return this.mcServer;
}
}

View File

@ -1,35 +1,30 @@
package net.minecraft.src; package net.minecraft.src;
import java.nio.FloatBuffer;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerAdapter;
public class RenderHelper public class RenderHelper {
{
/** Float buffer used to set OpenGL material colors */ /** Float buffer used to set OpenGL material colors */
private static FloatBuffer colorBuffer = GLAllocation.createDirectFloatBuffer(16); //private static FloatBuffer colorBuffer = GLAllocation.createDirectFloatBuffer(16);
private static final Vec3 field_82884_b = Vec3.createVectorHelper(0.20000000298023224D, 1.0D, -0.699999988079071D).normalize(); //private static final Vec3 field_82884_b = Vec3.createVectorHelper(0.20000000298023224D, 1.0D, -0.699999988079071D).normalize();
private static final Vec3 field_82885_c = Vec3.createVectorHelper(-0.20000000298023224D, 1.0D, 0.699999988079071D).normalize(); //private static final Vec3 field_82885_c = Vec3.createVectorHelper(-0.20000000298023224D, 1.0D, 0.699999988079071D).normalize();
/** /**
* Disables the OpenGL lighting properties enabled by enableStandardItemLighting * Disables the OpenGL lighting properties enabled by enableStandardItemLighting
*/ */
public static void disableStandardItemLighting() public static void disableStandardItemLighting() {
{
EaglerAdapter.glDisable(EaglerAdapter.GL_LIGHTING); EaglerAdapter.glDisable(EaglerAdapter.GL_LIGHTING);
EaglerAdapter.glDisable(EaglerAdapter.GL_LIGHT0);
EaglerAdapter.glDisable(EaglerAdapter.GL_LIGHT1);
EaglerAdapter.glDisable(EaglerAdapter.GL_COLOR_MATERIAL); EaglerAdapter.glDisable(EaglerAdapter.GL_COLOR_MATERIAL);
} }
/** /**
* Sets the OpenGL lighting properties to the values used when rendering blocks as items * Sets the OpenGL lighting properties to the values used when rendering blocks
* as items
*/ */
public static void enableStandardItemLighting() public static void enableStandardItemLighting() {
{
EaglerAdapter.glEnable(EaglerAdapter.GL_LIGHTING); EaglerAdapter.glEnable(EaglerAdapter.GL_LIGHTING);
EaglerAdapter.glEnable(EaglerAdapter.GL_LIGHT0);
EaglerAdapter.glEnable(EaglerAdapter.GL_LIGHT1);
EaglerAdapter.glEnable(EaglerAdapter.GL_COLOR_MATERIAL); EaglerAdapter.glEnable(EaglerAdapter.GL_COLOR_MATERIAL);
EaglerAdapter.copyModelToLightMatrix();
/*
EaglerAdapter.glColorMaterial(EaglerAdapter.GL_FRONT_AND_BACK, EaglerAdapter.GL_AMBIENT_AND_DIFFUSE); EaglerAdapter.glColorMaterial(EaglerAdapter.GL_FRONT_AND_BACK, EaglerAdapter.GL_AMBIENT_AND_DIFFUSE);
float var0 = 0.4F; float var0 = 0.4F;
float var1 = 0.6F; float var1 = 0.6F;
@ -44,35 +39,33 @@ public class RenderHelper
EaglerAdapter.glLight(EaglerAdapter.GL_LIGHT1, EaglerAdapter.GL_SPECULAR, setColorBuffer(var2, var2, var2, 1.0F)); EaglerAdapter.glLight(EaglerAdapter.GL_LIGHT1, EaglerAdapter.GL_SPECULAR, setColorBuffer(var2, var2, var2, 1.0F));
EaglerAdapter.glShadeModel(EaglerAdapter.GL_FLAT); EaglerAdapter.glShadeModel(EaglerAdapter.GL_FLAT);
EaglerAdapter.glLightModel(EaglerAdapter.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(var0, var0, var0, 1.0F)); EaglerAdapter.glLightModel(EaglerAdapter.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(var0, var0, var0, 1.0F));
*/
}
public static void enableStandardItemLighting2() {
EaglerAdapter.glPushMatrix();
EaglerAdapter.glScalef(1.0F, -1.0F, 1.0F);
enableStandardItemLighting();
EaglerAdapter.glPopMatrix();
} }
/** /**
* Update and return colorBuffer with the RGBA values passed as arguments * Sets OpenGL lighting for rendering blocks as items inside GUI screens (such
* as containers).
*/ */
private static FloatBuffer setColorBuffer(double par0, double par2, double par4, double par6) public static void enableGUIStandardItemLighting() {
{
return setColorBuffer((float)par0, (float)par2, (float)par4, (float)par6);
}
/**
* Update and return colorBuffer with the RGBA values passed as arguments
*/
private static FloatBuffer setColorBuffer(float par0, float par1, float par2, float par3)
{
colorBuffer.clear();
colorBuffer.put(par0).put(par1).put(par2).put(par3);
colorBuffer.flip();
return colorBuffer;
}
/**
* Sets OpenGL lighting for rendering blocks as items inside GUI screens (such as containers).
*/
public static void enableGUIStandardItemLighting()
{
EaglerAdapter.glPushMatrix(); EaglerAdapter.glPushMatrix();
EaglerAdapter.glRotatef(-30.0F, 0.0F, 1.0F, 0.0F); EaglerAdapter.glRotatef(-30.0F, 0.0F, 1.0F, 0.0F);
EaglerAdapter.glRotatef(165.0F, 1.0F, 0.0F, 0.0F); EaglerAdapter.glRotatef(165.0F, 1.0F, 0.0F, 0.0F);
//EaglerAdapter.glScalef(1.0F, -1.0F, 1.0F);
enableStandardItemLighting();
EaglerAdapter.glPopMatrix();
}
public static void enableGUIStandardItemLighting2() {
EaglerAdapter.glPushMatrix();
EaglerAdapter.glRotatef(-30.0F, 0.0F, 1.0F, 0.0F);
EaglerAdapter.glRotatef(165.0F, 1.0F, 0.0F, 0.0F);
EaglerAdapter.glScalef(1.0F, -1.0F, 1.0F);
enableStandardItemLighting(); enableStandardItemLighting();
EaglerAdapter.glPopMatrix(); EaglerAdapter.glPopMatrix();
} }

View File

@ -87,7 +87,6 @@ public abstract class ServerConfigurationManager
this.sendChatMsg(ChatMessageComponent.createFromTranslationWithSubstitutions("multiplayer.player.joined", new Object[] {par2EntityPlayerMP.getTranslatedEntityName()}).setColor(EnumChatFormatting.YELLOW)); this.sendChatMsg(ChatMessageComponent.createFromTranslationWithSubstitutions("multiplayer.player.joined", new Object[] {par2EntityPlayerMP.getTranslatedEntityName()}).setColor(EnumChatFormatting.YELLOW));
this.playerLoggedIn(par2EntityPlayerMP); this.playerLoggedIn(par2EntityPlayerMP);
var7.setPlayerLocation(par2EntityPlayerMP.posX, par2EntityPlayerMP.posY, par2EntityPlayerMP.posZ, par2EntityPlayerMP.rotationYaw, par2EntityPlayerMP.rotationPitch); var7.setPlayerLocation(par2EntityPlayerMP.posX, par2EntityPlayerMP.posY, par2EntityPlayerMP.posZ, par2EntityPlayerMP.rotationYaw, par2EntityPlayerMP.rotationPitch);
this.mcServer.getNetworkThread().addPlayer(var7);
var7.sendPacketToPlayer(new Packet4UpdateTime(var5.getTotalWorldTime(), var5.getWorldTime(), var5.getGameRules().getGameRuleBooleanValue("doDaylightCycle"))); var7.sendPacketToPlayer(new Packet4UpdateTime(var5.getTotalWorldTime(), var5.getWorldTime(), var5.getGameRules().getGameRuleBooleanValue("doDaylightCycle")));
if (this.mcServer.getTexturePack().length() > 0) if (this.mcServer.getTexturePack().length() > 0)

View File

@ -1,585 +0,0 @@
package net.minecraft.src;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import javax.crypto.SecretKey;
import net.minecraft.server.MinecraftServer;
public class TcpConnection implements INetworkManager
{
public static AtomicInteger field_74471_a = new AtomicInteger();
public static AtomicInteger field_74469_b = new AtomicInteger();
/** The object used for synchronization on the send queue. */
private final Object sendQueueLock;
/** Log agent for TCP connection */
private final ILogAgent tcpConLogAgent;
/** The socket used by this network manager. */
private Socket networkSocket;
/** The InetSocketAddress of the remote endpoint */
private final SocketAddress remoteSocketAddress;
/** The input stream connected to the socket. */
private volatile DataInputStream socketInputStream;
/** The output stream connected to the socket. */
private volatile DataOutputStream socketOutputStream;
/** Whether the network is currently operational. */
private volatile boolean isRunning;
/**
* Whether this network manager is currently terminating (and should ignore further errors).
*/
private volatile boolean isTerminating;
/**
* Linked list of packets that have been read and are awaiting processing.
*/
private Queue readPackets;
/** Linked list of packets awaiting sending. */
private List dataPackets;
/** Linked list of packets with chunk data that are awaiting sending. */
private List chunkDataPackets;
/** A reference to the NetHandler object. */
private NetHandler theNetHandler;
/**
* Whether this server is currently terminating. If this is a client, this is always false.
*/
private boolean isServerTerminating;
/** The thread used for writing. */
private Thread writeThread;
/** The thread used for reading. */
private Thread readThread;
/** A String indicating why the network has shutdown. */
private String terminationReason;
/** Contains shutdown description (internal error, etc.) as string array */
private Object[] shutdownDescription;
private int field_74490_x;
/**
* The length in bytes of the packets in both send queues (data and chunkData).
*/
private int sendQueueByteLength;
public static int[] field_74470_c = new int[256];
public static int[] field_74467_d = new int[256];
public int field_74468_e;
boolean isInputBeingDecrypted;
boolean isOutputEncrypted;
private SecretKey sharedKeyForEncryption;
private PrivateKey field_74463_A;
/**
* Delay for sending pending chunk data packets (as opposed to pending non-chunk data packets)
*/
private int chunkDataPacketsDelay;
public TcpConnection(ILogAgent par1ILogAgent, Socket par2Socket, String par3Str, NetHandler par4NetHandler) throws IOException
{
this(par1ILogAgent, par2Socket, par3Str, par4NetHandler, (PrivateKey)null);
}
public TcpConnection(ILogAgent par1ILogAgent, Socket par2Socket, String par3Str, NetHandler par4NetHandler, PrivateKey par5PrivateKey) throws IOException
{
this.sendQueueLock = new Object();
this.isRunning = true;
this.readPackets = new ConcurrentLinkedQueue();
this.dataPackets = Collections.synchronizedList(new ArrayList());
this.chunkDataPackets = Collections.synchronizedList(new ArrayList());
this.terminationReason = "";
this.chunkDataPacketsDelay = 50;
this.field_74463_A = par5PrivateKey;
this.networkSocket = par2Socket;
this.tcpConLogAgent = par1ILogAgent;
this.remoteSocketAddress = par2Socket.getRemoteSocketAddress();
this.theNetHandler = par4NetHandler;
try
{
par2Socket.setSoTimeout(30000);
par2Socket.setTrafficClass(24);
}
catch (SocketException var7)
{
System.err.println(var7.getMessage());
}
this.socketInputStream = new DataInputStream(par2Socket.getInputStream());
this.socketOutputStream = new DataOutputStream(new BufferedOutputStream(par2Socket.getOutputStream(), 5120));
this.readThread = new TcpReaderThread(this, par3Str + " read thread");
this.writeThread = new TcpWriterThread(this, par3Str + " write thread");
this.readThread.start();
this.writeThread.start();
}
public void closeConnections()
{
this.wakeThreads();
this.writeThread = null;
this.readThread = null;
}
/**
* Sets the NetHandler for this NetworkManager. Server-only.
*/
public void setNetHandler(NetHandler par1NetHandler)
{
this.theNetHandler = par1NetHandler;
}
/**
* Adds the packet to the correct send queue (chunk data packets go to a separate queue).
*/
public void addToSendQueue(Packet par1Packet)
{
if (!this.isServerTerminating)
{
Object var2 = this.sendQueueLock;
synchronized (this.sendQueueLock)
{
this.sendQueueByteLength += par1Packet.getPacketSize() + 1;
this.dataPackets.add(par1Packet);
}
}
}
/**
* Sends a data packet if there is one to send, or sends a chunk data packet if there is one and the counter is up,
* or does nothing.
*/
private boolean sendPacket()
{
boolean var1 = false;
try
{
int[] var10000;
int var10001;
Packet var2;
if (this.field_74468_e == 0 || !this.dataPackets.isEmpty() && MinecraftServer.getSystemTimeMillis() - ((Packet)this.dataPackets.get(0)).creationTimeMillis >= (long)this.field_74468_e)
{
var2 = this.func_74460_a(false);
if (var2 != null)
{
Packet.writePacket(var2, this.socketOutputStream);
if (var2 instanceof Packet252SharedKey && !this.isOutputEncrypted)
{
if (!this.theNetHandler.isServerHandler())
{
//this.sharedKeyForEncryption = ((Packet252SharedKey)var2).getSharedKey();
}
this.encryptOuputStream();
}
var10000 = field_74467_d;
var10001 = var2.getPacketId();
var10000[var10001] += var2.getPacketSize() + 1;
var1 = true;
}
}
if (this.chunkDataPacketsDelay-- <= 0 && (this.field_74468_e == 0 || !this.chunkDataPackets.isEmpty() && MinecraftServer.getSystemTimeMillis() - ((Packet)this.chunkDataPackets.get(0)).creationTimeMillis >= (long)this.field_74468_e))
{
var2 = this.func_74460_a(true);
if (var2 != null)
{
Packet.writePacket(var2, this.socketOutputStream);
var10000 = field_74467_d;
var10001 = var2.getPacketId();
var10000[var10001] += var2.getPacketSize() + 1;
this.chunkDataPacketsDelay = 0;
var1 = true;
}
}
return var1;
}
catch (Exception var3)
{
if (!this.isTerminating)
{
this.onNetworkError(var3);
}
return false;
}
}
private Packet func_74460_a(boolean par1)
{
Packet var2 = null;
List var3 = par1 ? this.chunkDataPackets : this.dataPackets;
Object var4 = this.sendQueueLock;
synchronized (this.sendQueueLock)
{
while (!var3.isEmpty() && var2 == null)
{
var2 = (Packet)var3.remove(0);
this.sendQueueByteLength -= var2.getPacketSize() + 1;
if (this.func_74454_a(var2, par1))
{
var2 = null;
}
}
return var2;
}
}
private boolean func_74454_a(Packet par1Packet, boolean par2)
{
if (!par1Packet.isRealPacket())
{
return false;
}
else
{
List var3 = par2 ? this.chunkDataPackets : this.dataPackets;
Iterator var4 = var3.iterator();
Packet var5;
do
{
if (!var4.hasNext())
{
return false;
}
var5 = (Packet)var4.next();
}
while (var5.getPacketId() != par1Packet.getPacketId());
return par1Packet.containsSameEntityIDAs(var5);
}
}
/**
* Wakes reader and writer threads
*/
public void wakeThreads()
{
if (this.readThread != null)
{
this.readThread.interrupt();
}
if (this.writeThread != null)
{
this.writeThread.interrupt();
}
}
/**
* Reads a single packet from the input stream and adds it to the read queue. If no packet is read, it shuts down
* the network.
*/
private boolean readPacket()
{
boolean var1 = false;
try
{
Packet var2 = Packet.readPacket(this.tcpConLogAgent, this.socketInputStream, this.theNetHandler.isServerHandler(), this.networkSocket);
if (var2 != null)
{
if (var2 instanceof Packet252SharedKey && !this.isInputBeingDecrypted)
{
if (this.theNetHandler.isServerHandler())
{
//this.sharedKeyForEncryption = ((Packet252SharedKey)var2).getSharedKey(this.field_74463_A);
}
this.decryptInputStream();
}
int[] var10000 = field_74470_c;
int var10001 = var2.getPacketId();
var10000[var10001] += var2.getPacketSize() + 1;
if (!this.isServerTerminating)
{
if (var2.canProcessAsync() && this.theNetHandler.canProcessPacketsAsync())
{
this.field_74490_x = 0;
var2.processPacket(this.theNetHandler);
}
else
{
this.readPackets.add(var2);
}
}
var1 = true;
}
else
{
this.networkShutdown("disconnect.endOfStream", new Object[0]);
}
return var1;
}
catch (Exception var3)
{
if (!this.isTerminating)
{
this.onNetworkError(var3);
}
return false;
}
}
/**
* Used to report network errors and causes a network shutdown.
*/
private void onNetworkError(Exception par1Exception)
{
par1Exception.printStackTrace();
this.networkShutdown("disconnect.genericReason", new Object[] {"Internal exception: " + par1Exception.toString()});
}
/**
* Shuts down the network with the specified reason. Closes all streams and sockets, spawns NetworkMasterThread to
* stop reading and writing threads.
*/
public void networkShutdown(String par1Str, Object ... par2ArrayOfObj)
{
if (this.isRunning)
{
this.isTerminating = true;
this.terminationReason = par1Str;
this.shutdownDescription = par2ArrayOfObj;
this.isRunning = false;
(new TcpMasterThread(this)).start();
try
{
this.socketInputStream.close();
}
catch (Throwable var6)
{
;
}
try
{
this.socketOutputStream.close();
}
catch (Throwable var5)
{
;
}
try
{
this.networkSocket.close();
}
catch (Throwable var4)
{
;
}
this.socketInputStream = null;
this.socketOutputStream = null;
this.networkSocket = null;
}
}
/**
* Checks timeouts and processes all pending read packets.
*/
public void processReadPackets()
{
if (this.sendQueueByteLength > 2097152)
{
this.networkShutdown("disconnect.overflow", new Object[0]);
}
if (this.readPackets.isEmpty())
{
if (this.field_74490_x++ == 1200)
{
this.networkShutdown("disconnect.timeout", new Object[0]);
}
}
else
{
this.field_74490_x = 0;
}
int var1 = 1000;
while (var1-- >= 0)
{
Packet var2 = (Packet)this.readPackets.poll();
if (var2 != null && !this.theNetHandler.isConnectionClosed())
{
var2.processPacket(this.theNetHandler);
}
}
this.wakeThreads();
if (this.isTerminating && this.readPackets.isEmpty())
{
this.theNetHandler.handleErrorMessage(this.terminationReason, this.shutdownDescription);
}
}
/**
* Return the InetSocketAddress of the remote endpoint
*/
public SocketAddress getSocketAddress()
{
return this.remoteSocketAddress;
}
/**
* Shuts down the server. (Only actually used on the server)
*/
public void serverShutdown()
{
if (!this.isServerTerminating)
{
this.wakeThreads();
this.isServerTerminating = true;
this.readThread.interrupt();
(new TcpMonitorThread(this)).start();
}
}
private void decryptInputStream() throws IOException
{
this.isInputBeingDecrypted = true;
InputStream var1 = this.networkSocket.getInputStream();
//this.socketInputStream = new DataInputStream(CryptManager.decryptInputStream(this.sharedKeyForEncryption, var1));
}
/**
* flushes the stream and replaces it with an encryptedOutputStream
*/
private void encryptOuputStream() throws IOException
{
this.socketOutputStream.flush();
this.isOutputEncrypted = true;
//BufferedOutputStream var1 = new BufferedOutputStream(CryptManager.encryptOuputStream(this.sharedKeyForEncryption, this.networkSocket.getOutputStream()), 5120);
//this.socketOutputStream = new DataOutputStream(var1);
}
/**
* returns 0 for memoryConnections
*/
public int packetSize()
{
return this.chunkDataPackets.size();
}
public Socket getSocket()
{
return this.networkSocket;
}
/**
* Whether the network is operational.
*/
static boolean isRunning(TcpConnection par0TcpConnection)
{
return par0TcpConnection.isRunning;
}
/**
* Is the server terminating? Client side aways returns false.
*/
static boolean isServerTerminating(TcpConnection par0TcpConnection)
{
return par0TcpConnection.isServerTerminating;
}
/**
* Static accessor to readPacket.
*/
static boolean readNetworkPacket(TcpConnection par0TcpConnection)
{
return par0TcpConnection.readPacket();
}
/**
* Static accessor to sendPacket.
*/
static boolean sendNetworkPacket(TcpConnection par0TcpConnection)
{
return par0TcpConnection.sendPacket();
}
static DataOutputStream getOutputStream(TcpConnection par0TcpConnection)
{
return par0TcpConnection.socketOutputStream;
}
/**
* Gets whether the Network manager is terminating.
*/
static boolean isTerminating(TcpConnection par0TcpConnection)
{
return par0TcpConnection.isTerminating;
}
/**
* Sends the network manager an error
*/
static void sendError(TcpConnection par0TcpConnection, Exception par1Exception)
{
par0TcpConnection.onNetworkError(par1Exception);
}
/**
* Returns the read thread.
*/
static Thread getReadThread(TcpConnection par0TcpConnection)
{
return par0TcpConnection.readThread;
}
/**
* Returns the write thread.
*/
static Thread getWriteThread(TcpConnection par0TcpConnection)
{
return par0TcpConnection.writeThread;
}
}

View File

@ -1,48 +0,0 @@
package net.minecraft.src;
class TcpMasterThread extends Thread
{
final TcpConnection theTcpConnection;
TcpMasterThread(TcpConnection par1TcpConnection)
{
this.theTcpConnection = par1TcpConnection;
}
@SuppressWarnings("deprecation")
public void run()
{
try
{
Thread.sleep(5000L);
if (TcpConnection.getReadThread(this.theTcpConnection).isAlive())
{
try
{
TcpConnection.getReadThread(this.theTcpConnection).stop();
}
catch (Throwable var3)
{
;
}
}
if (TcpConnection.getWriteThread(this.theTcpConnection).isAlive())
{
try
{
TcpConnection.getWriteThread(this.theTcpConnection).stop();
}
catch (Throwable var2)
{
;
}
}
}
catch (InterruptedException var4)
{
var4.printStackTrace();
}
}
}

View File

@ -1,29 +0,0 @@
package net.minecraft.src;
class TcpMonitorThread extends Thread
{
final TcpConnection theTcpConnection;
TcpMonitorThread(TcpConnection par1TcpConnection)
{
this.theTcpConnection = par1TcpConnection;
}
public void run()
{
try
{
Thread.sleep(2000L);
if (TcpConnection.isRunning(this.theTcpConnection))
{
TcpConnection.getWriteThread(this.theTcpConnection).interrupt();
this.theTcpConnection.networkShutdown("disconnect.closed", new Object[0]);
}
}
catch (Exception var2)
{
var2.printStackTrace();
}
}
}

View File

@ -1,42 +0,0 @@
package net.minecraft.src;
class TcpReaderThread extends Thread
{
final TcpConnection theTcpConnection;
TcpReaderThread(TcpConnection par1TcpConnection, String par2Str)
{
super(par2Str);
this.theTcpConnection = par1TcpConnection;
}
public void run()
{
TcpConnection.field_74471_a.getAndIncrement();
try
{
while (TcpConnection.isRunning(this.theTcpConnection) && !TcpConnection.isServerTerminating(this.theTcpConnection))
{
while (true)
{
if (!TcpConnection.readNetworkPacket(this.theTcpConnection))
{
try
{
sleep(2L);
}
catch (InterruptedException var5)
{
;
}
}
}
}
}
finally
{
TcpConnection.field_74471_a.getAndDecrement();
}
}
}

View File

@ -1,62 +0,0 @@
package net.minecraft.src;
import java.io.IOException;
class TcpWriterThread extends Thread
{
final TcpConnection theTcpConnection;
TcpWriterThread(TcpConnection par1TcpConnection, String par2Str)
{
super(par2Str);
this.theTcpConnection = par1TcpConnection;
}
public void run()
{
TcpConnection.field_74469_b.getAndIncrement();
try
{
while (TcpConnection.isRunning(this.theTcpConnection))
{
boolean var1;
for (var1 = false; TcpConnection.sendNetworkPacket(this.theTcpConnection); var1 = true)
{
;
}
try
{
if (var1 && TcpConnection.getOutputStream(this.theTcpConnection) != null)
{
TcpConnection.getOutputStream(this.theTcpConnection).flush();
}
}
catch (IOException var8)
{
if (!TcpConnection.isTerminating(this.theTcpConnection))
{
TcpConnection.sendError(this.theTcpConnection, var8);
}
var8.printStackTrace();
}
try
{
sleep(2L);
}
catch (InterruptedException var7)
{
;
}
}
}
finally
{
TcpConnection.field_74469_b.getAndDecrement();
}
}
}