Skip to content

Commit 8ae8328

Browse files
xerufanarchuser
authored andcommitted
refactor(plugin): update ILobbyClientListener signatures
1 parent 10a3a6f commit 8ae8328

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

plugin/src/client/sc/plugin2020/AbstractClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
5+
import sc.api.plugins.IGameState;
56
import sc.framework.plugins.Player;
67
import sc.framework.plugins.protocol.MoveRequest;
78
import sc.networking.clients.IControllableGame;
@@ -10,8 +11,8 @@
1011
import sc.plugin2020.util.Configuration;
1112
import sc.protocol.responses.PrepareGameProtocolMessage;
1213
import sc.protocol.responses.ProtocolErrorMessage;
14+
import sc.protocol.responses.ProtocolMessage;
1315
import sc.shared.GameResult;
14-
import sc.api.plugins.ITeam;
1516
import sc.shared.WelcomeMessage;
1617

1718
import java.io.IOException;
@@ -76,7 +77,7 @@ public IControllableGame observeGame(PrepareGameProtocolMessage handle) {
7677

7778
/** Called when a new message is sent to the room, e.g. move requests. */
7879
@Override
79-
public void onRoomMessage(String roomId, Object data) {
80+
public void onRoomMessage(String roomId, ProtocolMessage data) {
8081
if(data instanceof MoveRequest) {
8182
this.handler.onRequestAction();
8283
} else if(data instanceof WelcomeMessage) {
@@ -102,7 +103,7 @@ public void onError(String roomId, ProtocolErrorMessage response) {
102103
* Happens after a client made a move.
103104
*/
104105
@Override
105-
public void onNewState(String roomId, Object state) {
106+
public void onNewState(String roomId, IGameState state) {
106107
sc.plugin2020.GameState gameState = (GameState) state;
107108
logger.debug("{} got new state {}", this, gameState);
108109

plugin/src/client/sc/plugin2021/AbstractClient.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sc.plugin2021
22

33
import org.slf4j.LoggerFactory
4+
import sc.api.plugins.IGameState
45
import sc.framework.plugins.Player
56
import sc.framework.plugins.protocol.MoveRequest
67
import sc.networking.clients.IControllableGame
@@ -9,6 +10,7 @@ import sc.networking.clients.LobbyClient
910
import sc.plugin2021.util.Configuration
1011
import sc.protocol.responses.PrepareGameProtocolMessage
1112
import sc.protocol.responses.ProtocolErrorMessage
13+
import sc.protocol.responses.ProtocolMessage
1214
import sc.shared.GameResult
1315
import sc.shared.WelcomeMessage
1416
import java.io.IOException
@@ -54,7 +56,7 @@ abstract class AbstractClient @Throws(IOException::class) constructor(
5456
fun getError() = error
5557

5658
/** Current room of the player. */
57-
private lateinit var roomID: String
59+
private lateinit var roomId: String
5860

5961
/** The team the client belongs to in order to connect client and player. */
6062
private var team: Team? = when(type) {
@@ -68,19 +70,19 @@ abstract class AbstractClient @Throws(IOException::class) constructor(
6870
client.observe(handle)
6971

7072
/** Called for any new message sent to the game room, e.g., move requests. */
71-
override fun onRoomMessage(roomId: String, data: Any) {
73+
override fun onRoomMessage(roomId: String, data: ProtocolMessage) {
7274
if(data is MoveRequest) {
7375
handler.onRequestAction()
7476
}
7577
if(data is WelcomeMessage) {
7678
team = Team.valueOf(data.color.toUpperCase())
7779
}
78-
roomID = roomId
80+
this.roomId = roomId
7981
}
8082

8183
/** Sends the selected move to the server. */
8284
fun sendMove(move: Move) =
83-
client.sendMessageToRoom(roomID, move)
85+
client.sendMessageToRoom(roomId, move)
8486

8587
/** Called when an erroneous message is sent to the room. */
8688
override fun onError(roomId: String, error: ProtocolErrorMessage) {
@@ -92,7 +94,7 @@ abstract class AbstractClient @Throws(IOException::class) constructor(
9294
* Called when game state has been received.
9395
* Happens after a client made a move.
9496
*/
95-
override fun onNewState(roomId: String, state: Any) {
97+
override fun onNewState(roomId: String, state: IGameState) {
9698
val gameState = state as GameState
9799
logger.debug("$this got a new state $gameState")
98100

@@ -124,7 +126,7 @@ abstract class AbstractClient @Throws(IOException::class) constructor(
124126
override fun onGameObserved(roomId: String) {}
125127

126128
override fun onGameLeft(roomId: String) {
127-
logger.info("$this got game left $roomID")
129+
logger.info("$this got game left ${this.roomId}")
128130
client.stop()
129131
}
130132

server/test/sc/server/client/TestLobbyClientListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package sc.server.client;
22

3+
import sc.api.plugins.IGameState;
34
import sc.framework.plugins.Player;
45
import sc.networking.clients.ILobbyClientListener;
56
import sc.protocol.responses.PrepareGameProtocolMessage;
67
import sc.protocol.responses.ProtocolErrorMessage;
8+
import sc.protocol.responses.ProtocolMessage;
79
import sc.shared.GameResult;
810

911
public class TestLobbyClientListener implements ILobbyClientListener {
@@ -45,7 +47,7 @@ public boolean equals(Object obj) {
4547
}
4648

4749
@Override
48-
public void onNewState(String roomId, Object state) {
50+
public void onNewState(String roomId, IGameState state) {
4951
newStateReceived = true;
5052
this.roomId = roomId;
5153
this.newState = state;
@@ -59,7 +61,7 @@ public void onError(String roomId, ProtocolErrorMessage error) {
5961
}
6062

6163
@Override
62-
public void onRoomMessage(String roomId, Object data) {
64+
public void onRoomMessage(String roomId, ProtocolMessage data) {
6365
roomMessageReceived = true;
6466
this.roomId = roomId;
6567
this.roomMessage = data;

server/test/sc/server/client/TestObserverListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package sc.server.client;
22

3+
import sc.api.plugins.IGameState;
34
import sc.framework.plugins.Player;
45
import sc.networking.clients.ILobbyClientListener;
56
import sc.protocol.responses.PrepareGameProtocolMessage;
67
import sc.protocol.responses.ProtocolErrorMessage;
8+
import sc.protocol.responses.ProtocolMessage;
79
import sc.shared.GameResult;
810

911
public class TestObserverListener implements ILobbyClientListener {
@@ -16,15 +18,15 @@ public void onGameObserved(String roomId) {
1618
}
1719

1820
@Override
19-
public void onNewState(String roomId, Object state) {
21+
public void onNewState(String roomId, IGameState state) {
2022
}
2123

2224
@Override
2325
public void onError(String roomId, ProtocolErrorMessage error) {
2426
}
2527

2628
@Override
27-
public void onRoomMessage(String roomId, Object data) {
29+
public void onRoomMessage(String roomId, ProtocolMessage data) {
2830
}
2931

3032
@Override

server/test/sc/server/client/TestPreparedGameResponseListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package sc.server.client;
22

3+
import sc.api.plugins.IGameState;
34
import sc.framework.plugins.Player;
45
import sc.networking.clients.ILobbyClientListener;
56
import sc.protocol.responses.PrepareGameProtocolMessage;
67
import sc.protocol.responses.ProtocolErrorMessage;
8+
import sc.protocol.responses.ProtocolMessage;
79
import sc.shared.GameResult;
810

911
public class TestPreparedGameResponseListener implements ILobbyClientListener {
@@ -16,15 +18,15 @@ public void onGamePrepared(PrepareGameProtocolMessage gameResponse) {
1618
}
1719

1820
@Override
19-
public void onNewState(String roomId, Object state) {
21+
public void onNewState(String roomId, IGameState state) {
2022
}
2123

2224
@Override
2325
public void onError(String roomId, ProtocolErrorMessage error) {
2426
}
2527

2628
@Override
27-
public void onRoomMessage(String roomId, Object data) {
29+
public void onRoomMessage(String roomId, ProtocolMessage data) {
2830
}
2931

3032
@Override

socha-sdk/src/server-api/sc/networking/clients/ILobbyClientListener.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package sc.networking.clients;
22

3-
import sc.api.plugins.ITeam;
3+
import sc.api.plugins.IGameState;
44
import sc.framework.plugins.Player;
55
import sc.protocol.responses.ProtocolErrorMessage;
66
import sc.protocol.responses.PrepareGameProtocolMessage;
7+
import sc.protocol.responses.ProtocolMessage;
78
import sc.shared.GameResult;
89

910
public interface ILobbyClientListener {
1011

11-
void onNewState(String roomId, Object state);
12+
void onNewState(String roomId, IGameState state);
1213

13-
void onError(String roomId, ProtocolErrorMessage error);
14+
void onRoomMessage(String roomId, ProtocolMessage data);
1415

15-
void onRoomMessage(String roomId, Object data);
16+
void onError(String roomId, ProtocolErrorMessage error);
1617

1718
void onGamePrepared(PrepareGameProtocolMessage response);
1819

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ protected void onNewState(String roomId, IGameState state) {
220220
}
221221
}
222222

223+
protected void onRoomMessage(String roomId, ProtocolMessage data) {
224+
for (ILobbyClientListener listener : this.listeners) {
225+
listener.onRoomMessage(roomId, data);
226+
}
227+
}
228+
223229
protected void onError(String roomId, ProtocolErrorMessage error) {
224230
if (error.getOriginalRequest() != null) {
225231
logger.warn("The request {} caused the following error: {}",
@@ -239,12 +245,6 @@ public void sendMessageToRoom(String roomId, ProtocolMessage o) {
239245
send(new RoomPacket(roomId, o));
240246
}
241247

242-
protected void onRoomMessage(String roomId, ProtocolMessage data) {
243-
for (ILobbyClientListener listener : this.listeners) {
244-
listener.onRoomMessage(roomId, data);
245-
}
246-
}
247-
248248
/**
249249
* used in server
250250
*

0 commit comments

Comments
 (0)