Skip to content

colbycade/chess

Repository files navigation

♕ BYU CS 240 Chess

This is a project created for the BYU CS 240 (Advanced Programming Concepts) course.

This project demonstrates mastery of proper software design, client/server architecture, networking using HTTP and WebSocket, database persistence, unit testing, serialization, concurrency, and security.

Using the Live Server

The chess server is deployed to an AWS EC2 instance.

A simple frontend can be accessed here and contains an interface for making all the http API calls as documented below. To play a game through the command-line client, download and run the included client.jar file.

Architecture Overview

The application implements a multiplayer chess server and a command line chess client.

Sequence Diagram

API

Endpoint HTTP Method Path Header Body Returns
Register POST /user {username, password, email} authToken
Login POST /session {username, password} authToken
Logout DELETE /session authToken {}
List Games GET /game authToken {gameID, whiteUsername, blackUsername, gameName}[]
Create Game POST /game authToken {gameName} gameID
Join Game PUT /game authToken {ClientColor, gameID} {}
Clear Application DELETE /db {}

Sequence Diagram

Click to view online

Sequence Diagram

Running Locally

  1. Install all dependencies as specified in the pom.xml files.
  2. Run the server using the client/src/main/java/Main class.
  3. Run multiple concurrent clients using the server/src/main/java/server/Main class.

IntelliJ Support

Open the project directory in IntelliJ in order to develop, run, and debug the code using an IDE.

Maven Support

You can use the following commands to build, test, package, and run the code.

Command Description
mvn compile Builds the code
mvn package Run the tests and build an Uber jar file
mvn package -DskipTests Build an Uber jar file
mvn install Installs the packages into the local repository
mvn test Run all the tests
mvn -pl shared test Run all the shared tests
mvn -pl client exec:java Build and run the client Main
mvn -pl server exec:java Build and run the server Main

These commands are configured by the pom.xml (Project Object Model) files. There is a POM file in the root of the project, and one in each of the modules. The root POM defines any global dependencies and references the module POM files.

Deployment

Prerequisites

  • First ensure you have a running AWS EC2 instance with Java installed and security group allowing inbound traffic on ports 22 and 8080.
  • Also install and run mysql and set up a database for the chess server.
    • Create a db.properties file in server/src/main/resources with the following content:
      db.host=localhost
      db.port=<your-database-port>
      db.name=<your-database-name>
      db.user=<your-database-username>
      db.password=<your-database-password>
      
    • Create the corresponding database and user

Running the Chess Server on external AWS EC2 instance

  1. Build the client jar with dependencies:
    mvn package -pl client -DskipTests
  2. Copy it to server's resources web directory so that it can be downloaded from the server
    cp client/target/client-jar-with-dependencies.jar server/src/main/resources/web/client.jar
  3. Build the server jar:
    mvn package -pl server -DskipTests
  4. Deploy the server jar to the EC2 instance:
    scp -i <path-to-pem> server/target/server-jar-with-dependencies.jar user@server:/path/to/deploy/server.jar
  5. SSH into the instance:
    ssh -i <path-to-pem> user@server
  6. Run the chess server:
    java -jar /path/to/deploy/server.jar
  7. Verify the server is running by navigating to http://<server-ip>:8080 in a web browser.

Make the Chess Server run on server boot

  1. Create a systemd service file /etc/systemd/system/chess.service with the following content:
    Description=Chess Server
    After=network.target mysql.service
    Requires=mysql.service
    
    [Service]
    Type=simple
    ExecStart=java -jar /path/to/deploy/server.jar 8080
    
    [Install]
    WantedBy=multi-user.target
    
  2. Enable and start the service:
    sudo systemctl enable chess
    sudo systemctl start chess
  3. Check the status of the service:
    sudo systemctl status chess
  4. Reboot instance and confirm the service starts on boot:
    sudo reboot

About

Multiplayer chess server and command-line client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages