Skip to content

Commit

Permalink
Merge pull request #112 from StenAL/features
Browse files Browse the repository at this point in the history
Upgrade to Java 21, fix Docker image, add server integration test
  • Loading branch information
PhilippvK authored Jul 27, 2024
2 parents a42cf4d + b9b705e commit 1749814
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 55 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'temurin'
# Step that caches and restores maven dependencies
- name: Cache maven dependencies
Expand All @@ -32,3 +32,7 @@ jobs:
run: sudo apt-get install -y genisoimage
- name: Build with Maven
run: mvn -B install --file pom.xml
- name: Build Docker image
uses: docker/build-push-action@v5
with:
tags: philippvk/minigolf:latest
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
uses: metcalfc/changelog-generator@v0.4.3
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'temurin'
# Step that caches and restores maven dependencies
- name: Cache maven dependencies
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#
# Build stage
#
FROM maven:3.6.0-jdk-8-slim AS build
FROM maven:3.9.7-eclipse-temurin-21 AS build
COPY . /home/app/
RUN mvn -f /home/app/pom.xml -pl server -am clean package

#
# Package stage
#
FROM openjdk:8-alpine
FROM eclipse-temurin:21-alpine
COPY --from=build /home/app/server/target/server-*.jar /home/minigolf/server.jar
COPY tracks/ /home/minigolf/tracks/
EXPOSE 4242
WORKDIR /home/minigolf
ENTRYPOINT ["java","-jar","server.jar"]
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The Java Applet-based Minigolf Client was one of the most popular multiplayer ga

### Prerequisites
- Clone this repo: `git clone git@github.com:PhilippvK/playforia-minigolf.git`
- Install Java Development Kit 17 (https://adoptium.net/en-GB/temurin/releases/)
- Install Java Development Kit 21 (https://adoptium.net/en-GB/temurin/releases/)
- Install Apache `maven` for building: https://maven.apache.org/install.html
- *Optional:* Install IntelliJ IDEA Java IDE (https://www.jetbrains.com/idea/download/) and import this repository as project

Expand All @@ -62,7 +62,13 @@ java -jar client.jar -server 192.168.1.7 -lang en_US # Replace IP with the one o

#### Running Minigolf Server in Docker Container

We provide an experimental Dockerfile for easy hosting of the server application. You can either build the image by yourself or download the pre-build images from [quay.io](https://quay.io/repository/philippvk/minigolf) via `docker pull quay.io/philippvk/minigolf:latest`.
We provide an experimental Dockerfile for easy hosting of the server application.
You can either build and run the image:
```sh
docker build -t pfmg .
docker run pfmg
```
or download the pre-built images from [quay.io](https://quay.io/repository/philippvk/minigolf) via `docker pull quay.io/philippvk/minigolf:latest`.

Running the Editor is quite straightforward as it can be started like expected: `java -jar editor.jar`

Expand All @@ -83,7 +89,7 @@ Client CLI options:
## Compatibility

Tested:
- Ubuntu 22.04 with Java version `17.0.6`
- Ubuntu 22.04 with Java version `21.0.3`
- Windows 10/11

## Problems
Expand Down
12 changes: 5 additions & 7 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<project.mainClass>org.moparforia.client.Launcher</project.mainClass>
<project.name>Playforia Minigolf Client</project.name>
<project.download.directory>${project.build.directory}/downloads</project.download.directory>
<project.jre.osx.link>https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/OpenJDK17U-jre_x64_mac_hotspot_17.0.7_7.tar.gz</project.jre.osx.link>
<project.jre.osx.name>jdk-17.0.7+7-jre</project.jre.osx.name>
<project.jre.osx.link>https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2%2B13/OpenJDK21U-jre_aarch64_mac_hotspot_21.0.2_13.tar.gz</project.jre.osx.link>
<project.jre.osx.name>jdk-21.0.2+13-jre</project.jre.osx.name>
</properties>

<dependencies>
Expand Down Expand Up @@ -84,7 +84,7 @@
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.9.0</version>
<executions>
<execution>
<id>download-osx-jre</id>
Expand All @@ -104,7 +104,6 @@
<plugin>
<groupId>sh.tak.appbundler</groupId>
<artifactId>appbundle-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<bundleName>${project.name}</bundleName>
<iconFile>src/main/resources/icons/playforia.icns</iconFile>
Expand Down Expand Up @@ -133,7 +132,6 @@
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<id>windows-build</id>
Expand All @@ -154,7 +152,7 @@
<icon>src/main/resources/icons/playforia.ico</icon>
<jre>
<path>jre</path>
<minVersion>17</minVersion>
<minVersion>21</minVersion>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
Expand All @@ -174,7 +172,7 @@
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<version>2.4.1</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.quality.Strictness;
import picocli.CommandLine;

import javax.swing.JFrame;
Expand Down Expand Up @@ -42,7 +43,7 @@ class LauncherCLITest {
void setUp() throws Exception {
// Mock game
launcher = mock(Launcher.class, withSettings()
.lenient()
.strictness(Strictness.LENIENT)
.withoutAnnotations());

// Use real methods
Expand Down
42 changes: 23 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<packaging>pom</packaging>
<version>2.1.2.0-BETA</version>
<name>Playforia Minigolf</name>
<organization>
<name>Playforia</name>
</organization>
<inceptionYear>2002</inceptionYear>
<description>An online multiplayer minigolf game</description>

<modules>
<module>server</module>
Expand All @@ -18,24 +23,24 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.mainClass>test.mainClass</project.mainClass>
<picocli.version>4.5.2</picocli.version>
<picocli.version>4.7.6</picocli.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -55,6 +60,7 @@
</manifestEntries>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
Expand All @@ -67,16 +73,20 @@
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.25</version>
<version>2.5.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.2.5</version>
<configuration>
<argLine>-XX:+EnableDynamicAgentLoading</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -105,37 +115,31 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.5.10</version>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.5.10</version>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.marschall</groupId>
<artifactId>memoryfilesystem</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.softsmithy.lib</groupId>
<artifactId>softsmithy-lib-core</artifactId>
<version>2.1.1</version>
<version>2.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.elnarion.util</groupId>
<artifactId>plantuml-generator-util</artifactId>
<version>1.1.2</version>
<version>2.4.1</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<version>2.4.1</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
Expand Down
13 changes: 11 additions & 2 deletions server/src/main/java/org/moparforia/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class Server implements Runnable {
private int port;
private Optional<String> tracksDirectory;

private Channel serverChannel;
private boolean running;

private HashMap<LobbyType, Lobby> lobbies = new HashMap<LobbyType, Lobby>();
//private ArrayList<LobbyRef> lobbies = new ArrayList<LobbyRef>();
//private HashMap<Integer, Game> games = new HashMap<Integer, Game>();
Expand Down Expand Up @@ -188,17 +191,23 @@ public void start() {
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
try {
bootstrap.bind(new InetSocketAddress(host, port));
this.serverChannel = bootstrap.bind(new InetSocketAddress(host, port));
this.running = true;
new Thread(this).start();
} catch (Exception ex) {
ex.printStackTrace();
}
}

public void stop() throws InterruptedException {
this.serverChannel.close().sync();
this.running = false;
}

@Override
public void run() {
System.out.println("Started server on host " + this.host + " with port " + this.port);
while (true) {
while (this.running) {
try {
Thread.sleep(10);
Iterator<Event> iterator = events.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void process(Server server) {
Player player;
if ((player = (Player)channel.getAttachment()) != null) {
if (player.getLobby() != null) {
player.getLobby().removePlayer(player, Lobby.PART_REASON_USERLEFT,null);
player.getLobby().removePlayer(player, Lobby.PART_REASON_USERLEFT);
}
}
System.out.println("Client disconnected: " + channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Pattern getPattern() {
public boolean handle(Server server, Packet packet, Matcher message) {
Player player = (Player) packet.getChannel().getAttachment();
if (message.group(1).contains("lobby")) {
player.getLobby().removePlayer(player, Lobby.PART_REASON_USERLEFT, null);
player.getLobby().removePlayer(player, Lobby.PART_REASON_USERLEFT);
}
packet.getChannel().disconnect();
packet.getChannel().close();
Expand Down
Loading

0 comments on commit 1749814

Please sign in to comment.