Skip to content

Commit b4bb6d5

Browse files
committed
Merge branch 'master'
2 parents 51eedef + 7d03dfc commit b4bb6d5

File tree

64 files changed

+422
-467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+422
-467
lines changed

GUIDELINES.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,27 @@ to make some year-specific implementations from the plugin accessible in the sdk
4949
Currently there are two interfaces, [IGamePlugin](sdk/src/server-api/sc/api/plugins/IGamePlugin.java) and [XStreamProvider]( sdk/src/server-api/sc/networking/XStreamProvider.kt), which are implemented in the plugin and then loaded through a ServiceLoader.
5050
The information which implementations to use resides in [resources/META-INF/services](plugin/src/resources/META-INF/services).
5151

52-
## Protocol Message Classes
52+
## Networking Protocol Classes
5353

54-
### [sdk/server-api/sc.protocol](sdk/src/server-api/sc/protocol)
54+
[ProtocolPacket](sdk/src/server-api/sc/protocol/ProtocolPacket.kt) is the common interface
55+
for objects sent via the XML Protocol.
5556

56-
(*Request) Ask for an action or information
57-
(? extends [AdminLobbyRequest](sdk/src/server-api/sc/protocol/requests/ILobbyRequest.kt)) Requires authentication
57+
### [Requests](sdk/src/server-api/sc/protocol/requests)
58+
- are all suffixed with `Request`
59+
- ask for an action or information
60+
- any request that extends [AdminLobbyRequest](sdk/src/server-api/sc/protocol/requests/ILobbyRequest.kt)
61+
requires authentication beforehand
5862

5963
#### [Responses](sdk/src/server-api/sc/protocol/responses)
6064

61-
If it extends `ProtocolMessage` directly, it is wrapped in a [RoomPacket](sdk/src/server-api/sc/protocol/responses/RoomPacket.kt)
62-
and sent to a specific room, otherwise it has to extend `ILobbyRequest` and is sent to LobbyListeners.
63-
6465
(*Response) Response to a request
6566
(*Event) Update to all observers
67+
68+
#### [Room Messages](sdk/src/server-api/sc/protocol/room)
69+
70+
Data sent to a specific room has to implement [RoomMessage](sdk/src/server-api/sc/protocol/room/RoomMessage.kt)
71+
and is then wrapped in a [RoomPacket](sdk/src/server-api/sc/protocol/room/RoomPacket.kt).
72+
73+
The package contains a few standard messages,
74+
but most will be implemented in the corresponding plugin.
75+

helpers/test-client/src/sc/TestClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import sc.api.plugins.IGamePlugin;
1010
import sc.framework.plugins.Player;
1111
import sc.networking.clients.XStreamClient;
12+
import sc.protocol.ProtocolPacket;
13+
import sc.protocol.room.RoomPacket;
1214
import sc.protocol.requests.*;
1315
import sc.protocol.responses.*;
1416
import sc.server.Configuration;
@@ -185,7 +187,7 @@ public TestClient(String host, int port, int totalTests) throws IOException {
185187
private boolean gameProgressing = false;
186188

187189
@Override
188-
protected void onObject(@NotNull ProtocolMessage message) {
190+
protected void onObject(@NotNull ProtocolPacket message) {
189191
if (message == null) {
190192
logger.warn("Received null message");
191193
return;
@@ -335,8 +337,7 @@ private void prepareNewClients() {
335337

336338
private static void exit(int status) {
337339
if (testclient != null) {
338-
if (!testclient.isClosed())
339-
testclient.send(new CloseConnection());
340+
testclient.stop();
340341
testclient.waiter.shutdownNow();
341342
}
342343

plugin/src/server/sc/plugin2021/Game.kt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package sc.plugin2021
22

33
import org.slf4j.LoggerFactory
4+
import sc.api.plugins.exceptions.TooManyPlayersException
45
import sc.framework.plugins.AbstractGame
56
import sc.framework.plugins.ActionTimeout
67
import sc.framework.plugins.Player
78
import sc.plugin2021.util.Constants
89
import sc.plugin2021.util.GameRuleLogic
910
import sc.plugin2021.util.MoveMistake
1011
import sc.plugin2021.util.WinReason
11-
import sc.protocol.responses.ProtocolMessage
12+
import sc.protocol.room.RoomMessage
1213
import sc.shared.InvalidMoveException
1314
import sc.shared.PlayerScore
1415
import sc.shared.ScoreCause
@@ -22,7 +23,7 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
2223
private val availableTeams = mutableListOf(Team.ONE, Team.TWO)
2324
override fun onPlayerJoined(): Player {
2425
if (availableTeams.isEmpty())
25-
throw IllegalStateException("Too many players joined the game!")
26+
throw TooManyPlayersException()
2627
val player = currentState.getPlayer(availableTeams.removeAt(0))
2728

2829
players.add(player)
@@ -75,18 +76,6 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
7576
}
7677
}
7778

78-
override fun loadGameInfo(gameInfo: Any) {
79-
TODO("Not yet implemented")
80-
}
81-
82-
override fun loadFromFile(file: String) {
83-
TODO("Not yet implemented")
84-
}
85-
86-
override fun loadFromFile(file: String, turn: Int) {
87-
TODO("Not yet implemented")
88-
}
89-
9079
override fun getScoreFor(player: Player): PlayerScore {
9180
val team = player.color as Team
9281
logger.debug("Get score for player $team (violated: ${if (player.hasViolated()) "yes" else "no"})")
@@ -137,7 +126,7 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
137126
ActionTimeout(true, Constants.HARD_TIMEOUT, Constants.SOFT_TIMEOUT)
138127

139128
@Throws(InvalidMoveException::class)
140-
override fun onRoundBasedAction(fromPlayer: Player, data: ProtocolMessage) {
129+
override fun onRoundBasedAction(fromPlayer: Player, data: RoomMessage) {
141130
if (data !is Move)
142131
throw InvalidMoveException(MoveMistake.INVALID_FORMAT)
143132

sdk/src/framework/sc/shared/GameResult.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package sc.shared
33
import com.thoughtworks.xstream.annotations.XStreamAlias
44
import com.thoughtworks.xstream.annotations.XStreamImplicit
55
import sc.framework.plugins.Player
6-
import sc.protocol.responses.ProtocolMessage
6+
import sc.protocol.room.RoomMessage
77

88
/**
99
* Das Endergebnis eines Spiels.
@@ -17,7 +17,7 @@ data class GameResult(
1717
val scores: List<PlayerScore>,
1818
@XStreamImplicit(itemFieldName = "winner")
1919
val winners: List<Player>?
20-
): ProtocolMessage {
20+
): RoomMessage {
2121

2222
val isRegular: Boolean
2323
get() = scores.all { it.cause == ScoreCause.REGULAR }

sdk/src/framework/sc/shared/WelcomeMessage.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package sc.shared
33
import com.thoughtworks.xstream.annotations.XStreamAlias
44
import com.thoughtworks.xstream.annotations.XStreamAsAttribute
55
import sc.api.plugins.ITeam
6-
import sc.protocol.responses.ProtocolMessage
6+
import sc.protocol.room.RoomMessage
77

88
/** Nachricht, die zu Beginn eines Spiels an einen Client geschickt wird, um ihm seine Spielerfarbe mitzuteilen. */
99
@Suppress("DataClassPrivateConstructor")
1010
@XStreamAlias(value = "welcomeMessage")
1111
data class WelcomeMessage private constructor(
1212
@XStreamAsAttribute val color: String
13-
): ProtocolMessage {
13+
): RoomMessage {
1414
constructor(color: ITeam): this(color.name)
1515
}

sdk/src/player/sc/player/PlayerClient.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import sc.api.plugins.*
55
import sc.framework.plugins.protocol.MoveRequest
66
import sc.networking.clients.AbstractLobbyClientListener
77
import sc.networking.clients.LobbyClient
8-
import sc.protocol.responses.ProtocolErrorMessage
9-
import sc.protocol.responses.ProtocolMessage
8+
import sc.protocol.room.ErrorMessage
9+
import sc.protocol.room.RoomMessage
1010
import sc.shared.GameResult
1111
import java.net.ConnectException
1212
import kotlin.system.exitProcess
@@ -42,23 +42,21 @@ class PlayerClient(
4242
private lateinit var roomId: String
4343

4444
/** Called for any new message sent to the game room, e.g., move requests. */
45-
override fun onRoomMessage(roomId: String, data: ProtocolMessage) {
45+
override fun onRoomMessage(roomId: String, data: RoomMessage) {
4646
this.roomId = roomId
4747
when (data) {
4848
is MoveRequest -> sendMove(handler.calculateMove())
49+
is ErrorMessage -> {
50+
logger.debug("onError: Client $this received error ${data.message} in $roomId")
51+
this.error = data.message
52+
}
4953
}
5054
}
5155

5256
/** Sends the selected move to the server. */
5357
fun sendMove(move: IMove) =
5458
client.sendMessageToRoom(roomId, move)
5559

56-
/** Called when an erroneous message is sent to the room. */
57-
override fun onError(roomId: String?, error: ProtocolErrorMessage) {
58-
logger.debug("onError: Client $this received error ${error.message} in $roomId")
59-
this.error = error.message
60-
}
61-
6260
/**
6361
* Called when game state has been received.
6462
* Happens after a client made a move.

sdk/src/server-api/sc/api/plugins/IGameInstance.kt

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package sc.api.plugins
22

33
import sc.api.plugins.exceptions.GameLogicException
4-
import sc.api.plugins.exceptions.TooManyPlayersException
54
import sc.api.plugins.host.IGameListener
65
import sc.framework.plugins.Player
7-
import sc.protocol.responses.ProtocolMessage
6+
import sc.protocol.room.RoomMessage
87
import sc.shared.InvalidMoveException
98
import sc.shared.PlayerScore
109
import sc.shared.ScoreCause
1110
import kotlin.jvm.Throws
1211

1312
interface IGameInstance {
14-
/**
15-
* @return the player that joined
16-
*
17-
* @throws TooManyPlayersException when game is already full
18-
*/
19-
@Throws(TooManyPlayersException::class)
13+
/** @return the player that joined. */
2014
fun onPlayerJoined(): Player
2115
fun onPlayerLeft(player: Player, cause: ScoreCause? = null)
2216

@@ -30,7 +24,7 @@ interface IGameInstance {
3024
* @throws InvalidMoveException if the received move violates the rules
3125
*/
3226
@Throws(GameLogicException::class, InvalidMoveException::class)
33-
fun onAction(fromPlayer: Player, data: ProtocolMessage)
27+
fun onAction(fromPlayer: Player, data: RoomMessage)
3428
fun addGameListener(listener: IGameListener)
3529
fun removeGameListener(listener: IGameListener)
3630

@@ -44,30 +38,6 @@ interface IGameInstance {
4438
*/
4539
fun destroy()
4640

47-
/**
48-
* The game is requested to load itself from a file.
49-
* Similar to a replay but with actual clients.
50-
*
51-
* @param file File the game should be loaded from
52-
*/
53-
fun loadFromFile(file: String)
54-
55-
/**
56-
* The game is requested to load itself from a file.
57-
* Similar to a replay but with actual clients.
58-
*
59-
* @param file File where the game should be loaded from
60-
* @param turn The turn to load from the replay
61-
*/
62-
fun loadFromFile(file: String, turn: Int)
63-
64-
/**
65-
* The game is requested to load itself from a given game information object.
66-
*
67-
* @param gameInfo the stored gameInformation
68-
*/
69-
fun loadGameInfo(gameInfo: Any)
70-
7141
/**
7242
* Returns the players that have won the game, empty if the game has no winners,
7343
* or null if the game has not yet finished.

sdk/src/server-api/sc/api/plugins/IGameState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package sc.api.plugins
22

3-
import sc.protocol.responses.ProtocolMessage
3+
import sc.protocol.room.RoomMessage
44

55
/**
66
* Ein `GameState` beinhaltet alle Informationen, die den Spielstand zu
@@ -25,7 +25,7 @@ import sc.protocol.responses.ProtocolMessage
2525
*
2626
* @author Niklas, Sören, Janek
2727
*/
28-
interface IGameState : ProtocolMessage, Cloneable {
28+
interface IGameState : RoomMessage, Cloneable {
2929
/** Aktuelle Zugzahl */
3030
val turn: Int
3131

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package sc.api.plugins
22

3-
import sc.protocol.responses.ProtocolMessage
3+
import sc.protocol.room.RoomMessage
44

5-
interface IMove: ProtocolMessage
5+
interface IMove: RoomMessage
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package sc.api.plugins.exceptions
22

33
import sc.framework.plugins.Player
4-
import sc.protocol.responses.ProtocolMessage
4+
import sc.protocol.room.RoomMessage
55

66
data class NotYourTurnException(
77
val expected: Player?,
88
val actual: Player,
9-
val data: ProtocolMessage):
10-
GameLogicException("It's not your turn yet; expected: $expected, got $actual (msg was $data).")
9+
val data: RoomMessage
10+
): GameLogicException("It's not your turn yet; expected: $expected, got $actual (msg was $data).")

0 commit comments

Comments
 (0)