Skip to content

Commit 89ba054

Browse files
committed
feat: enable non-reserved slots in prepared games
- remove client roles - revamp game preparation - centralize responsibility for players in PlayerSlot
1 parent c323c3f commit 89ba054

25 files changed

+190
-517
lines changed

sdk/src/server-api/sc/api/plugins/host/IPlayerListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import sc.protocol.room.RoomMessage;
44

55
public interface IPlayerListener {
6-
void onPlayerEvent(RoomMessage request);
6+
void onPlayerEvent(RoomMessage message);
77
}

sdk/src/server-api/sc/framework/HelperMethods.java

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package sc.framework
2+
3+
import java.text.DateFormat
4+
import java.text.SimpleDateFormat
5+
import java.util.Date
6+
7+
object HelperMethods {
8+
private val dateTimeFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
9+
/**
10+
* Returns the current date and time as string formatted as yyyy.MM.dd
11+
* HH_mm_ss.
12+
*
13+
* @return current date and time
14+
*/
15+
private val currentDateTime: String
16+
get() = dateTimeFormat.format(Date())
17+
18+
/**
19+
* Returns a new generated filename for a replay file.
20+
*
21+
* @param gameId UUID of the plugin
22+
* @param names descriptor of player slot
23+
*
24+
* @return name of replay
25+
*/
26+
@JvmStatic
27+
fun getReplayFilename(gameId: String, names: List<String>): String =
28+
"./replays/replay_${gameId}_${currentDateTime}_" +
29+
"${names.joinToString("_") { it.replace(' ', '_') }}.xml"
30+
}

sdk/src/server-api/sc/framework/plugins/AbstractGame.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ abstract class AbstractGame<P : Player>(override val pluginUUID: String) : IGame
2626
var isPaused = false
2727

2828
fun afterPause() {
29-
logger.info("Sending MoveRequest to player $activePlayer")
3029
notifyOnNewState(currentState, false)
3130
notifyActivePlayer()
3231
}
@@ -161,7 +160,8 @@ abstract class AbstractGame<P : Player>(override val pluginUUID: String) : IGame
161160
player.hardTimeout = true
162161
onPlayerLeft(player, ScoreCause.HARD_TIMEOUT)
163162
}
164-
163+
164+
logger.info("Sending MoveRequest to player $activePlayer")
165165
player.requestMove()
166166
}
167167

Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
package sc.server.network;
1+
package sc.networking.clients;
22

33
import sc.protocol.ProtocolPacket;
44

55
/** Client interface to send packages to the server. */
66
public interface IClient {
7-
/** Add role to the client. */
8-
void addRole(IClientRole role);
9-
107
/** Send a package. */
118
void send(ProtocolPacket packet);
129
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.net.SocketException;
2121
import java.nio.charset.StandardCharsets;
2222

23-
public abstract class XStreamClient {
23+
public abstract class XStreamClient implements IClient {
2424
private static Logger logger = LoggerFactory.getLogger(XStreamClient.class);
2525

2626
public static INetworkInterface createTcpNetwork(String host, int port) throws IOException {
@@ -103,7 +103,7 @@ public void receiveThread() {
103103
if (object instanceof ProtocolPacket) {
104104
ProtocolPacket response = (ProtocolPacket) object;
105105

106-
logger.debug("{}: Received {} via {}", shortString(), response, networkInterface);
106+
logger.debug("Received {} via {}", response, networkInterface);
107107
if (logger.isTraceEnabled())
108108
logger.trace("Dumping {}:\n{}", response, xStream.toXML(response));
109109

@@ -154,12 +154,12 @@ public void receiveThread() {
154154
}
155155

156156
public void sendCustomData(String data) throws IOException {
157-
logger.debug("{}: Sending custom data: {}", shortString(), data);
157+
logger.debug("Sending custom data: {}", data);
158158
sendCustomData(data.getBytes(StandardCharsets.UTF_8));
159159
}
160160

161161
public void sendCustomData(byte[] data) throws IOException {
162-
logger.info("{}: Sending custom data (size={})", shortString(), data.length);
162+
logger.info("Sending custom data (size={})", data.length);
163163
networkInterface.getOutputStream().write(data);
164164
networkInterface.getOutputStream().flush();
165165
}
@@ -171,7 +171,7 @@ public void send(ProtocolPacket packet) {
171171
protected synchronized void sendObject(Object packet) {
172172
if (!isReady())
173173
throw new IllegalStateException(
174-
String.format("Trying to write packet on %s which wasn't started: %s", shortString(), packet));
174+
String.format("Trying to write packet %s on non-started client {}", packet, this));
175175

176176
if (isClosed()) {
177177
logger.warn("Writing on a closed Stream -> dropped the packet (tried to send package of type {}) Thread: {}",
@@ -180,7 +180,7 @@ protected synchronized void sendObject(Object packet) {
180180
return;
181181
}
182182

183-
logger.debug("{}: Sending {} via {} from {}", shortString(), packet, networkInterface, this);
183+
logger.debug("Sending {} via {} from {}", packet, networkInterface, this);
184184
if (logger.isTraceEnabled())
185185
logger.trace("Dumping {}:\n{}", packet, xStream.toXML(packet));
186186

@@ -200,11 +200,11 @@ protected final void handleDisconnect(DisconnectCause cause) {
200200

201201
protected final void handleDisconnect(DisconnectCause cause, Throwable exception) {
202202
if (exception != null) {
203-
logger.warn("{} disconnected (Cause: {}, Exception: {})", shortString(), cause, exception);
203+
logger.warn("{} disconnected (Cause: {}, Exception: {})", this, cause, exception);
204204
if (logger.isDebugEnabled())
205205
exception.printStackTrace();
206206
} else {
207-
logger.info("{} disconnected (Cause: {})", shortString(), cause);
207+
logger.info("{} disconnected (Cause: {})", this, cause);
208208
}
209209

210210
this.disconnectCause = cause;

0 commit comments

Comments
 (0)