mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-05 03:22:53 +00:00

This moves monitor networking into its own packet, rather than serialising using NBT. This allows us to be more flexible with how monitors are serialised. We now compress terminal data using gzip. This reduces the packet size of a max-sized-monitor from ~25kb to as little as 100b. On my test set of images (what I would consider to be the extreme end of the "reasonable" case), we have packets from 1.4kb bytes up to 12kb, with a mean of 6kb. Even in the worst case, this is a 2x reduction in packet size. While this is a fantastic win for the common case, it is not abuse-proof. One can create a terminal with high entropy (and so uncompressible). This will still be close to the original packet size. In order to prevent any other abuse, we also limit the amount of monitor data a client can possibly receive to 1MB (configurable).
85 lines
1.9 KiB
Java
85 lines
1.9 KiB
Java
/*
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
*/
|
|
package dan200.computercraft.shared.common;
|
|
|
|
import dan200.computercraft.core.terminal.Terminal;
|
|
import dan200.computercraft.shared.network.client.TerminalState;
|
|
|
|
public class ClientTerminal implements ITerminal
|
|
{
|
|
private boolean m_colour;
|
|
private Terminal m_terminal;
|
|
private boolean m_terminalChanged;
|
|
|
|
public ClientTerminal( boolean colour )
|
|
{
|
|
m_colour = colour;
|
|
m_terminal = null;
|
|
m_terminalChanged = false;
|
|
}
|
|
|
|
public boolean pollTerminalChanged()
|
|
{
|
|
boolean changed = m_terminalChanged;
|
|
m_terminalChanged = false;
|
|
|
|
Terminal terminal = m_terminal;
|
|
if( terminal != null ) terminal.clearChanged();
|
|
|
|
return changed;
|
|
}
|
|
|
|
// ITerminal implementation
|
|
|
|
@Override
|
|
public Terminal getTerminal()
|
|
{
|
|
return m_terminal;
|
|
}
|
|
|
|
@Override
|
|
public boolean isColour()
|
|
{
|
|
return m_colour;
|
|
}
|
|
|
|
public void read( TerminalState state )
|
|
{
|
|
m_colour = state.colour;
|
|
if( state.hasTerminal() )
|
|
{
|
|
resizeTerminal( state.width, state.height );
|
|
state.apply( m_terminal );
|
|
}
|
|
else
|
|
{
|
|
deleteTerminal();
|
|
}
|
|
}
|
|
|
|
private void resizeTerminal( int width, int height )
|
|
{
|
|
if( m_terminal == null )
|
|
{
|
|
m_terminal = new Terminal( width, height, () -> m_terminalChanged = true );
|
|
m_terminalChanged = true;
|
|
}
|
|
else
|
|
{
|
|
m_terminal.resize( width, height );
|
|
}
|
|
}
|
|
|
|
private void deleteTerminal()
|
|
{
|
|
if( m_terminal != null )
|
|
{
|
|
m_terminal = null;
|
|
m_terminalChanged = true;
|
|
}
|
|
}
|
|
}
|