Skip to content

Commit 60ae797

Browse files
committed
refactor(sdk): remove dead networking code
1 parent 1e19c2b commit 60ae797

File tree

7 files changed

+13
-148
lines changed

7 files changed

+13
-148
lines changed

sdk/src/server-api/sc/networking/XStreamProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package sc.networking
22

33
import com.thoughtworks.xstream.XStream
44
import com.thoughtworks.xstream.io.xml.KXml2Driver
5-
import sc.protocol.helpers.LobbyProtocol
5+
import sc.protocol.LobbyProtocol
66
import java.util.*
77

88
interface XStreamProvider {

sdk/src/server-api/sc/networking/clients/IHistoryListener.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package sc.networking.clients
2+
3+
import sc.api.plugins.IGameState
4+
import sc.protocol.responses.ProtocolErrorMessage
5+
import sc.shared.GameResult
6+
7+
interface IHistoryListener {
8+
fun onNewState(roomId: String, state: IGameState)
9+
fun onGameOver(roomId: String, result: GameResult) {}
10+
fun onGameError(roomId: String, error: ProtocolErrorMessage) {}
11+
}

sdk/src/server-api/sc/networking/clients/LobbyClient.java

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77
import sc.api.plugins.IGameState;
8-
import sc.api.plugins.host.IRequestResult;
98
import sc.framework.plugins.Player;
109
import sc.networking.INetworkInterface;
1110
import sc.networking.TcpNetwork;
12-
import sc.protocol.helpers.AsyncResultManager;
13-
import sc.protocol.helpers.RequestResult;
1411
import sc.protocol.requests.*;
1512
import sc.protocol.responses.*;
1613
import sc.shared.GameResult;
17-
import sc.shared.SharedConfiguration;
1814
import sc.shared.SlotDescriptor;
1915

2016
import java.io.IOException;
@@ -31,17 +27,10 @@
3127
*/
3228
public final class LobbyClient extends XStreamClient implements IPollsHistory {
3329
private static final Logger logger = LoggerFactory.getLogger(LobbyClient.class);
34-
private final AsyncResultManager asyncManager = new AsyncResultManager();
3530
private final List<ILobbyClientListener> listeners = new ArrayList<>();
3631
private final List<IHistoryListener> historyListeners = new ArrayList<>();
3732
private final List<IAdministrativeListener> administrativeListeners = new ArrayList<>();
3833

39-
public static final String DEFAULT_HOST = "127.0.0.1";
40-
41-
public LobbyClient() throws IOException {
42-
this(DEFAULT_HOST, SharedConfiguration.DEFAULT_PORT);
43-
}
44-
4534
public LobbyClient(String host, int port) throws IOException {
4635
super(createTcpNetwork(host, port));
4736
}
@@ -58,8 +47,6 @@ protected final void onObject(ProtocolMessage message) {
5847
return;
5948
}
6049

61-
invokeHandlers(message);
62-
6350
if (message instanceof RoomPacket) {
6451
RoomPacket packet = (RoomPacket) message;
6552
String roomId = packet.getRoomId();
@@ -137,9 +124,6 @@ private void onGameObserved(String roomId) {
137124
}
138125
}
139126

140-
private void invokeHandlers(@NotNull ProtocolMessage message) {
141-
this.asyncManager.invokeHandlers(message);
142-
}
143127

144128
protected void onGamePrepared(GamePreparedResponse response) {
145129
for (ILobbyClientListener listener : this.listeners) {
@@ -151,17 +135,6 @@ public void authenticate(String password) {
151135
send(new AuthenticateRequest(password));
152136
}
153137

154-
@SuppressWarnings("unchecked")
155-
public RequestResult<GamePreparedResponse> prepareGameAndWait(String gameType) throws InterruptedException {
156-
return blockingRequest(new PrepareGameRequest(gameType), GamePreparedResponse.class);
157-
}
158-
159-
@SuppressWarnings("unchecked")
160-
public RequestResult<GamePreparedResponse> prepareGameAndWait(
161-
PrepareGameRequest request) throws InterruptedException {
162-
return blockingRequest(request, GamePreparedResponse.class);
163-
}
164-
165138
public void prepareGame(String gameType) {
166139
send(new PrepareGameRequest(gameType));
167140
}
@@ -208,71 +181,14 @@ public void sendMessageToRoom(String roomId, ProtocolMessage o) {
208181
send(new RoomPacket(roomId, o));
209182
}
210183

211-
/**
212-
* used in server
213-
*
214-
* @param reservation reservation ID
215-
*/
216184
public void joinPreparedGame(String reservation) {
217185
send(new JoinPreparedRoomRequest(reservation));
218186
}
219187

220-
/**
221-
* currently not used in server
222-
*
223-
* @param gameType GameID
224-
*/
225188
public void joinRoomRequest(String gameType) {
226189
send(new JoinRoomRequest(gameType));
227190
}
228191

229-
/**
230-
* used in server
231-
*
232-
* @param request ProtocolMessage which contains the request
233-
* @param response Response class to be created
234-
* @param handler Handler for the requests
235-
*/
236-
protected void request(ProtocolMessage request, Class<? extends ProtocolMessage> response,
237-
IRequestResult handler) {
238-
this.asyncManager.addHandler(response, handler);
239-
send(request);
240-
}
241-
242-
protected RequestResult blockingRequest(ProtocolMessage request,
243-
Class<? extends ProtocolMessage> response) throws InterruptedException {
244-
// TODO return a proper future here
245-
// This is really old async code, so the variable needs to be final but still mutable
246-
// IDEA suggested to use an array and we'll stay with that until we reimplement it properly.
247-
final RequestResult[] requestResult = {null};
248-
final Object beacon = new Object();
249-
synchronized(beacon) {
250-
IRequestResult blockingHandler = new IRequestResult() {
251-
@Override
252-
public void handleError(ProtocolErrorMessage e) {
253-
requestResult[0] = new RequestResult.Error(e);
254-
notifySemaphore();
255-
}
256-
257-
@Override
258-
public void accept(ProtocolMessage result) {
259-
requestResult[0] = new RequestResult.Success<>(result);
260-
notifySemaphore();
261-
}
262-
263-
private void notifySemaphore() {
264-
synchronized(beacon) {
265-
beacon.notify();
266-
}
267-
}
268-
};
269-
request(request, response, blockingHandler);
270-
beacon.wait();
271-
}
272-
273-
return requestResult[0];
274-
}
275-
276192
public void addListener(ILobbyClientListener listener) {
277193
this.listeners.add(listener);
278194
}

sdk/src/server-api/sc/protocol/helpers/LobbyProtocol.kt renamed to sdk/src/server-api/sc/protocol/LobbyProtocol.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package sc.protocol.helpers
1+
package sc.protocol
22

33
import com.thoughtworks.xstream.XStream
44
import sc.api.plugins.ITeam

sdk/src/server-api/sc/protocol/helpers/AsyncResultManager.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

sdk/src/server-api/sc/protocol/helpers/RequestResult.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)