Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GlowSession thread-safe #844

Merged
merged 3 commits into from Feb 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/main/java/net/glowstone/net/GlowSession.java
Expand Up @@ -11,12 +11,12 @@
import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.CodecException;
import java.net.InetSocketAddress;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.logging.Level;
import javax.crypto.SecretKey;
import lombok.Getter;
Expand Down Expand Up @@ -71,21 +71,21 @@ public class GlowSession extends BasicSession {
/**
* A queue of incoming and unprocessed messages.
*/
private final Queue<Message> messageQueue = new ArrayDeque<>();
private final Queue<Message> messageQueue = new ConcurrentLinkedDeque<>();

/**
* The remote address of the connection.
*/
@Getter
private InetSocketAddress address;
private volatile InetSocketAddress address;

/**
* The state of the connection.
*
* @return true if this session's state is online
*/
@Getter
private boolean online;
private volatile boolean online;
/**
* The randomly-generated verify token used in authentication for this session.
*
Expand All @@ -94,27 +94,27 @@ public class GlowSession extends BasicSession {
*/
@Getter
@Setter
private byte[] verifyToken;
private volatile byte[] verifyToken;

/**
* The verify username used in authentication.
*/
@Getter
@Setter
private String verifyUsername;
private volatile String verifyUsername;

/**
* The hostname/port the player used to connect to the server.
*/
@Getter
@Setter
private InetSocketAddress virtualHost;
private volatile InetSocketAddress virtualHost;

/**
* The version used to connect.
*/
@Getter
private int version = -1;
private volatile int version = -1;

/**
* Data regarding a user who has connected through a proxy, used to provide online-mode UUID and
Expand All @@ -125,35 +125,35 @@ public class GlowSession extends BasicSession {
* @return The proxy data to use, or null for an unproxied connection.
*/
@Getter
private ProxyData proxyData;
private volatile ProxyData proxyData;

/**
* The player associated with this session (if there is one).
*
* @return The player, or {@code null} if no player is associated with this session.
*/
@Getter
private GlowPlayer player;
private volatile GlowPlayer player;

/**
* The ID of the last ping message sent, used to ensure the client responded correctly.
*/
private long pingMessageId;
private volatile long pingMessageId;

/**
* The number of ticks until previousPlacement must be cleared.
*/
private int previousPlacementTicks;
private volatile int previousPlacementTicks;

/**
* If the connection has been disconnected.
*/
private boolean disconnected;
private volatile boolean disconnected;

/**
* If compression packet has been sent.
*/
private boolean compresssionSent;
private volatile boolean compresssionSent;

/**
* Creates a new session.
Expand Down