Skip to content

Commit c7ddd95

Browse files
committed
style(server): reformat sources
# Conflicts: # server/src/sc/server/Lobby.kt # server/src/sc/server/network/ClientManager.java # server/src/sc/server/network/NewClientListener.java
1 parent 256db82 commit c7ddd95

15 files changed

+427
-523
lines changed

server/src/sc/server/Application.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ public final class Application {
1414

1515
private static final Logger logger = LoggerFactory.getLogger(Application.class);
1616
private static final Object SYNCOBJ = new Object();
17+
1718
static {
1819
String config = System.getProperty("logback.configurationFile");
19-
logger.debug("Loading logback config from {}", config != null ? config : System.getProperty("user.dir")+File.separator+"logback.xml");
20-
if(config == null)
21-
System.setProperty("logback.configurationFile", System.getProperty("user.dir")+File.separator+"logback.xml");
20+
logger.debug("Loading logback config from {}", config != null ? config : System.getProperty("user.dir") + File.separator + "logback.xml");
21+
if (config == null)
22+
System.setProperty("logback.configurationFile", System.getProperty("user.dir") + File.separator + "logback.xml");
2223
System.setProperty("file.encoding", "UTF-8");
2324
}
2425

@@ -54,7 +55,7 @@ public static void main(String[] params) {
5455
long end = System.currentTimeMillis();
5556
logger.debug("Server has been initialized in {} ms.", end - start);
5657

57-
synchronized (SYNCOBJ) {
58+
synchronized(SYNCOBJ) {
5859
try {
5960
SYNCOBJ.wait();
6061
} catch (InterruptedException e) {
@@ -107,7 +108,7 @@ public static void addShutdownHook() {
107108
Thread shutdown = new Thread(() -> {
108109
ServiceManager.killAll();
109110
// continues the main-method of this class
110-
synchronized (SYNCOBJ) {
111+
synchronized(SYNCOBJ) {
111112
SYNCOBJ.notifyAll();
112113
logger.info("Exiting application...");
113114
}
Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,58 @@
11
package sc.server;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
36
import java.util.ArrayList;
47
import java.util.HashSet;
58
import java.util.List;
69
import java.util.Set;
710

8-
import org.slf4j.Logger;
9-
import org.slf4j.LoggerFactory;
10-
1111
/** Manages all threads */
1212

13-
public abstract class ServiceManager
14-
{
15-
private static Logger logger = LoggerFactory.getLogger(ServiceManager.class);
16-
17-
private static Set<Thread> threads = new HashSet<Thread>();
18-
private static Set<Thread> killedThreads = new HashSet<Thread>();
19-
20-
/**
21-
* Creates a new Thread
22-
* @param name Name of new Thread
23-
* @param target instance of Runnable
24-
*/
25-
public static Thread createService(String name, Runnable target)
26-
{
27-
return createService(name, target, true);
28-
}
29-
30-
private static synchronized Thread createService(String name,
31-
Runnable target, boolean daemon)
32-
{
33-
logger.debug("Spawning thread for new service (name={}, daemon={})",
34-
name, daemon);
35-
36-
Thread thread = new Thread(target);
37-
thread.setName(name);
38-
thread.setDaemon(daemon);
39-
threads.add(thread);
40-
return thread;
41-
}
42-
43-
private static synchronized void kill(Thread thread)
44-
{
45-
thread.interrupt();
46-
threads.remove(thread);
47-
killedThreads.add(thread);
48-
}
49-
50-
public static synchronized void killAll()
51-
{
52-
logger.info("Shutting down all services...");
53-
54-
List<Thread> clonedList = new ArrayList<Thread>(threads.size());
55-
clonedList.addAll(threads);
56-
57-
for (Thread thread : clonedList)
58-
{
59-
kill(thread);
60-
}
61-
}
13+
public abstract class ServiceManager {
14+
private static Logger logger = LoggerFactory.getLogger(ServiceManager.class);
15+
16+
private static Set<Thread> threads = new HashSet<Thread>();
17+
private static Set<Thread> killedThreads = new HashSet<Thread>();
18+
19+
/**
20+
* Creates a new Thread
21+
*
22+
* @param name Name of new Thread
23+
* @param target instance of Runnable
24+
*/
25+
public static Thread createService(String name, Runnable target) {
26+
return createService(name, target, true);
27+
}
28+
29+
private static synchronized Thread createService(String name,
30+
Runnable target, boolean daemon) {
31+
logger.debug("Spawning thread for new service (name={}, daemon={})",
32+
name, daemon);
33+
34+
Thread thread = new Thread(target);
35+
thread.setName(name);
36+
thread.setDaemon(daemon);
37+
threads.add(thread);
38+
return thread;
39+
}
40+
41+
private static synchronized void kill(Thread thread) {
42+
thread.interrupt();
43+
threads.remove(thread);
44+
killedThreads.add(thread);
45+
}
46+
47+
public static synchronized void killAll() {
48+
logger.info("Shutting down all services...");
49+
50+
List<Thread> clonedList = new ArrayList<Thread>(threads.size());
51+
clonedList.addAll(threads);
52+
53+
for (Thread thread : clonedList) {
54+
kill(thread);
55+
}
56+
}
6257

6358
}
Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,35 @@
11
package sc.server.gaming;
22

3-
import java.util.Collection;
4-
53
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
7-
85
import sc.api.plugins.host.IGamePluginHost;
96
import sc.server.Configuration;
107

11-
public class GamePluginApi implements IGamePluginHost
12-
{
13-
private static Logger logger = LoggerFactory.getLogger(GamePluginApi.class);
14-
15-
@Override
16-
public void registerProtocolClass(Class<?> clazz, String alias)
17-
{
18-
registerProtocolClass(clazz);
19-
Configuration.getXStream().alias(alias, clazz);
20-
}
21-
22-
@Override
23-
public void registerProtocolClass(Class<?> clazz)
24-
{
25-
logger.debug("Processing XStream annotations for {}", clazz);
26-
Configuration.getXStream().processAnnotations(clazz);
27-
}
8+
import java.util.Collection;
289

29-
@Override
30-
public void registerProtocolClasses(
31-
Collection<Class<? extends Object>> protocolClasses)
32-
{
33-
if (protocolClasses != null)
34-
{
35-
for (Class<? extends Object> clazz : protocolClasses)
36-
{
37-
registerProtocolClass(clazz);
38-
}
39-
}
40-
}
10+
public class GamePluginApi implements IGamePluginHost {
11+
private static Logger logger = LoggerFactory.getLogger(GamePluginApi.class);
12+
13+
@Override
14+
public void registerProtocolClass(Class<?> clazz, String alias) {
15+
registerProtocolClass(clazz);
16+
Configuration.getXStream().alias(alias, clazz);
17+
}
18+
19+
@Override
20+
public void registerProtocolClass(Class<?> clazz) {
21+
logger.debug("Processing XStream annotations for {}", clazz);
22+
Configuration.getXStream().processAnnotations(clazz);
23+
}
24+
25+
@Override
26+
public void registerProtocolClasses(
27+
Collection<Class<? extends Object>> protocolClasses) {
28+
if (protocolClasses != null) {
29+
for (Class<? extends Object> clazz : protocolClasses) {
30+
registerProtocolClass(clazz);
31+
}
32+
}
33+
}
4134

4235
}

server/src/sc/server/gaming/ReservationManager.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
11
package sc.server.gaming;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
5-
import java.util.UUID;
6-
73
import org.slf4j.Logger;
84
import org.slf4j.LoggerFactory;
9-
105
import sc.api.plugins.exceptions.RescuableClientException;
116
import sc.server.network.Client;
127

13-
public final class ReservationManager
14-
{
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.UUID;
11+
12+
public final class ReservationManager {
1513

1614
private static Logger logger = LoggerFactory.getLogger(ReservationManager.class);
17-
private static Map<String, PlayerSlot> reservations = new HashMap<String, PlayerSlot>();
15+
private static Map<String, PlayerSlot> reservations = new HashMap<String, PlayerSlot>();
1816

1917
/** create Object as singleton */
20-
private ReservationManager()
21-
{
18+
private ReservationManager() {
2219
// singleton
2320
}
2421

2522
/**
2623
* If reservation code is valid register client to playerslot and start game if all clients connected
27-
* @param client to fill a slot
24+
*
25+
* @param client to fill a slot
2826
* @param reservation code which will redeem the reservation
27+
*
2928
* @return newly filled PlayerSlot
29+
*
3030
* @throws RescuableClientException will be thrown if slot cannot be filled or reservation is unknown
3131
*/
3232
public static synchronized PlayerSlot redeemReservationCode(Client client,
33-
String reservation) throws RescuableClientException
34-
{
33+
String reservation) throws RescuableClientException {
3534
PlayerSlot result = reservations.remove(reservation);
3635

37-
if (result == null)
38-
{
36+
if (result == null) {
3937
throw new UnknownReservationException();
40-
}
41-
else
42-
{
38+
} else {
4339
logger.info("Reservation {} was redeemed.", reservation);
4440
result.getRoom().fillSlot(result, client);
4541
return result;
@@ -48,14 +44,15 @@ public static synchronized PlayerSlot redeemReservationCode(Client client,
4844

4945
/**
5046
* Reserve a specific slot
47+
*
5148
* @param playerSlot the slot, that is supposed to be reserved
49+
*
5250
* @return the reservation code
51+
*
5352
* @throws RuntimeException if the slot is already reserved
5453
*/
55-
public synchronized static String reserve(PlayerSlot playerSlot)
56-
{
57-
if (reservations.containsValue(playerSlot))
58-
{
54+
public synchronized static String reserve(PlayerSlot playerSlot) {
55+
if (reservations.containsValue(playerSlot)) {
5956
throw new RuntimeException("This slot is already reserved.");
6057
}
6158

@@ -66,14 +63,13 @@ public synchronized static String reserve(PlayerSlot playerSlot)
6663

6764
/**
6865
* Generate a uniqe String ID
66+
*
6967
* @return the unique ID
7068
*/
71-
private synchronized static String generateUniqueId()
72-
{
69+
private synchronized static String generateUniqueId() {
7370
String key = UUID.randomUUID().toString();
7471

75-
while (reservations.containsKey(key))
76-
{
72+
while (reservations.containsKey(key)) {
7773
key = UUID.randomUUID().toString();
7874
}
7975

@@ -82,10 +78,10 @@ private synchronized static String generateUniqueId()
8278

8379
/**
8480
* Remove reservation with given redeem code and free that slot
81+
*
8582
* @param reservation the redeem code
8683
*/
87-
public static synchronized void freeReservation(String reservation)
88-
{
84+
public static synchronized void freeReservation(String reservation) {
8985
PlayerSlot slot = reservations.remove(reservation);
9086
slot.free();
9187
}

server/src/sc/server/network/Client.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public synchronized void send(ProtocolMessage packet) {
6767
super.send(packet);
6868
} else {
6969
logger.warn("Writing on a closed Stream -> dropped the packet (tried to send package of type {}) Thread: {}",
70-
packet.getClass().getSimpleName(),
71-
Thread.currentThread().getName());
70+
packet.getClass().getSimpleName(),
71+
Thread.currentThread().getName());
7272
}
7373
}
7474

@@ -110,13 +110,13 @@ private void notifyOnPacket(Object packet) throws UnprocessedPacketException, In
110110
}
111111
if (!errors.isEmpty()) {
112112
logger.debug("Stopping client because of error. Thread: {}",
113-
Thread.currentThread().getName());
113+
Thread.currentThread().getName());
114114
stop();
115115
}
116116

117117
if (packet instanceof LeftGameEvent) {
118118
logger.debug("Stopping client because of LeftGameEvent received. Thread: {}",
119-
Thread.currentThread().getName());
119+
Thread.currentThread().getName());
120120
stop();
121121
}
122122
}
@@ -177,6 +177,7 @@ public boolean isAdministrator() {
177177

178178
/**
179179
* Authenticates a Client as Administrator
180+
*
180181
* @param password The secret that is required to gain administrative rights.
181182
*/
182183
public void authenticate(String password) throws AuthenticationFailedException {

0 commit comments

Comments
 (0)