22 package com.realtime.crossfire.jxclient.server.crossfire;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
59 private final Object
sync =
new Object();
104 synchronized (
sync) {
106 pendingNumLookObjects = 0;
107 if (debugProtocol != null) {
108 debugProtocol.
debugProtocolWrite(
"connected: defaulting to pending_num_look_objects="+pendingNumLookObjects);
111 if (debugProtocol != null) {
112 debugProtocol.
debugProtocolWrite(
"connected: defaulting to num_look_objects="+currentNumLookObjects);
122 final int numLookObjects;
123 synchronized (
sync) {
126 if (debugProtocol != null) {
131 if (debugProtocol != null) {
136 if (pendingNumLookObjects != 0) {
137 if (debugProtocol != null) {
138 debugProtocol.
debugProtocolWrite(
"negotiateNumLookObjects: already negotiating pending_num_look_objects="+pendingNumLookObjects+
", ignoring");
142 if (currentNumLookObjects == numLookObjects) {
143 if (debugProtocol != null) {
144 debugProtocol.
debugProtocolWrite(
"negotiateNumLookObjects: unchanged from num_look_objects="+currentNumLookObjects+
", ignoring");
148 pendingNumLookObjects = numLookObjects;
149 if (debugProtocol != null) {
150 debugProtocol.
debugProtocolWrite(
"negotiateNumLookObjects: pending_num_look_objects="+pendingNumLookObjects+
", sending setup command");
154 crossfireServerConnection.
sendSetup(
"num_look_objects "+numLookObjects);
164 if (value.equals(
"FALSE")) {
165 System.err.println(
"Warning: the server is too old for this client since it does not support the num_look_objects setup option.");
166 System.err.println(
"Expect issues with the ground view display.");
167 synchronized (
sync) {
168 pendingNumLookObjects = 0;
171 if (debugProtocol != null) {
172 debugProtocol.
debugProtocolWrite(
"processSetup: pending_num_look_objects=0 [server didn't understand setup command]");
175 final int thisNumLookObjects;
177 thisNumLookObjects = Integer.parseInt(value);
178 }
catch (
final NumberFormatException ignored) {
181 final boolean negotiate;
182 synchronized (
sync) {
183 if (pendingNumLookObjects == 0) {
184 System.err.println(
"the server sent an unexpected 'setup num_look_objects "+value+
"'.");
187 if (pendingNumLookObjects != thisNumLookObjects) {
188 System.err.println(
"Warning: the server didn't accept the num_look_objects setup option: requested "+pendingNumLookObjects+
", returned "+thisNumLookObjects+
".");
189 System.err.println(
"Expect issues with the ground view display.");
191 pendingNumLookObjects = 0;
192 if (debugProtocol != null) {
193 debugProtocol.
debugProtocolWrite(
"processSetup: pending_num_look_objects="+pendingNumLookObjects+
" [ok]");
195 currentNumLookObjects = thisNumLookObjects;
196 if (debugProtocol != null) {
197 debugProtocol.
debugProtocolWrite(
"processSetup: num_look_objects="+currentNumLookObjects);
217 synchronized (
sync) {
218 final int preferredNumLookObjects2 = Math.max(3, preferredNumLookObjects);
219 if (this.preferredNumLookObjects == preferredNumLookObjects2) {
223 this.preferredNumLookObjects = preferredNumLookObjects2;
234 synchronized (
sync) {
246 synchronized (
sync) {
247 while (!connected || pendingNumLookObjects != 0 || pending) {
258 synchronized (
sync) {
void negotiateNumLookObjects()
Requests a change of the number of ground objects from the server.
static final int DEFAULT_NUM_LOOK_OBJECTS
The default number of ground objects when no "setup num_look_objects" command has been sent...
void processSetupNumLookObjects(@NotNull final String value)
Called when a "setup num_look_objects" response has been received from the server.
void connected()
Called after the server connection has been established.
boolean pending
Whether negotiation may be pending.
final DebugWriter debugProtocol
The appender to write protocol commands to.
final Object sync
The synchronization objects for accessing mutable fields.
void debugProtocolWrite(@NotNull final CharSequence str)
Writes a message to the debug protocol.
int currentNumLookObjects
The currently active number of ground view objects.
Writer debug information to a log file.
int preferredNumLookObjects
The number of ground view objects to be negotiated with the server.
boolean connected
Whether the current client socket state is ClientSocketState#CONNECTED.
void setPreferredNumLookObjects(final int preferredNumLookObjects)
Sets the preferred number of ground items.
int getCurrentNumLookObjects()
Returns the current number of ground items.
An UnknownCommandException is generated whenever an unknown message packet is received from the serve...
void waitForCurrentNumLookObjectsValid()
Waits until getCurrentNumLookObjects() is stable.
final CrossfireServerConnection crossfireServerConnection
The CrossfireServerConnection for sending "setup" commands.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
void sendSetup(@NotNull String... options)
Sends a "setup" command to the server.
int pendingNumLookObjects
The number of ground view objects being negotiated with the server.
void setClientSocketState(@NotNull final ClientSocketState clientSocketState)
Called whenever the client socket state has changed.
Negotiates the size of the ground view in items with the Crossfire server.
Connection progress states of the Crossfire server connection.
CONNECTED
Connection is fully established.