Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenttrinh3336 authored Mar 12, 2024
0 parents commit 7ee08d4
Show file tree
Hide file tree
Showing 20 changed files with 1,251 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Derived from an example provided by https://blog.benoitblanchon.fr/github-action-run-ssh-commands/
#
#
#
#
name: Deploy
on: [push]
jobs:
deploy:
name: "Deploy to server"
runs-on: ubuntu-latest
steps:
- name: configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/production.key
chmod 600 ~/.ssh/production.key
cat >>~/.ssh/config <<END
Host production
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}

- name: get source code and compile
run: |
ssh production "rm -rf ./TicTacToe"
ssh production "git clone https://github.com/BudDavis/TicTacToe"
ssh production "cd TicTacToe;mvn clean compile package"
- name: create systemd unit file
run: |
# without enable-linger, you must be logged in??
ssh production "loginctl enable-linger"
ssh production "mkdir --parents /home/sp24_group1/.config/systemd/user"
ssh production "rm -f /home/sp24_group1/.config/systemd/user/tictactoe.service"
ssh production 'echo "[Unit]" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "Description=tictactoe" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "[Service]" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "Type=simple" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "Restart=always" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "RestartSec=5" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "ExecStart=mvn exec:java -Dexec.mainClass=uta.cse3310.App" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "WorkingDirectory=/home/sp24_group1/TicTacToe" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "[Install]" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
ssh production 'echo "WantedBy=default.target" >>/home/sp24_group1/.config/systemd/user/tictactoe.service'
- name: systemd reload
run: |
ssh production "systemctl --user daemon-reload"
- name: restart daemon
run: |
ssh production "systemctl --user enable tictactoe.service"
ssh production "systemctl --user restart tictactoe.service"
ssh production "systemctl --user status tictactoe.service"
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# TicTacToe

```bash
% export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.18.0.9-0.3.ea.el8.x86_64
% mvn clean
% mvn compile
% mvn package
% mvn exec:java -Dexec.mainClass=uta.cse3310.App
```
Information on deployment:

https://www.programonaut.com/how-to-deploy-a-git-repository-to-a-server-using-github-actions/
Binary file added docs/Drawing.vsdx
Binary file not shown.
Binary file added docs/Requirements.docx
Binary file not shown.
120 changes: 120 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<head>
<meta charset="utf-8">
</head>

<label id="topMessage"></label>

<table>
<tr>

<td><input type="button" value="?" id="b1" onclick=buttonclick(0)></input></td>
<td><input type="button" value="?" id="b2" onclick=buttonclick(1)></input></td>
<td><input type="button" value="?" id="b3" onclick=buttonclick(2)></input></td>

</tr>
<tr>

<td><input type="button" value="?" id="b4" onclick=buttonclick(3)></input></td>
<td><input type="button" value="?" id="b5" onclick=buttonclick(4)></input></td>
<td><input type="button" value="?" id="b6" onclick=buttonclick(5)></input></td>

</tr>

<tr>

<td><input type="button" value="?" id="b7" onclick=buttonclick(6)></input></td>
<td><input type="button" value="?" id="b8" onclick=buttonclick(7)></input></td>
<td><input type="button" value="?" id="b9" onclick=buttonclick(8)></input></td>

</tr>
</table>

<label id="timeMsg"></label>
<label id="statMsg"></label>

<script>
var idx = -1;
var gameid = -1;
class UserEvent {
Button = -1;
PlayerIdx = 0;
GameId = 0;
}
var connection = null;

var serverUrl;
serverUrl = "ws://" + window.location.hostname + ":9880";
// Create the connection with the server
connection = new WebSocket(serverUrl);

connection.onopen = function (evt) {
console.log("open");
}
connection.onclose = function (evt) {
console.log("close");
document.getElementById("topMessage").innerHTML = "Server Offline"
}
const ButtonStateToDisplay = new Map();
ButtonStateToDisplay.set("XPLAYER", "X");
ButtonStateToDisplay.set("OPLAYER", "O");
ButtonStateToDisplay.set("NOPLAYER", " ");
connection.onmessage = function (evt) {
var msg;
msg = evt.data;

console.log("Message received: " + msg);
const obj = JSON.parse(msg);

if ('YouAre' in obj) {
if (obj.YouAre == "XPLAYER") {
idx = 0;
}
else {
idx = 1;
}

gameid = obj.GameId;
}
else if ('CurrentTurn' in obj) {
// show statistics to everyone
var t = obj.Stats;
if (t) {
document.getElementById("timeMsg").innerHTML = "elapsed time " + t.RunningTime;
document.getElementById("statMsg").innerHTML =
" in progress " + t.GamesInProgress + " XWin " + t.XWins + " OWin " + t.OWins +
" Draw " + t.Draws + " Total " + t.TotalGames;
}

// only pay attention to this game
if (gameid == obj.GameId) {
// button state to display values

document.getElementById("b1").value = ButtonStateToDisplay.get(obj.Button[0]);
document.getElementById("b2").value = ButtonStateToDisplay.get(obj.Button[1]);
document.getElementById("b3").value = ButtonStateToDisplay.get(obj.Button[2]);
document.getElementById("b4").value = ButtonStateToDisplay.get(obj.Button[3]);
document.getElementById("b5").value = ButtonStateToDisplay.get(obj.Button[4]);
document.getElementById("b6").value = ButtonStateToDisplay.get(obj.Button[5]);
document.getElementById("b7").value = ButtonStateToDisplay.get(obj.Button[6]);
document.getElementById("b8").value = ButtonStateToDisplay.get(obj.Button[7]);
document.getElementById("b9").value = ButtonStateToDisplay.get(obj.Button[8]);


// the message line
document.getElementById("topMessage").innerHTML = obj.Msg[idx];
}
}
}

function buttonclick(i) {
U = new UserEvent();
U.Button = i;
if (idx == 0)
U.PlayerIdx = "XPLAYER";
else
U.PlayerIdx = "OPLAYER";
U.GameId = gameid;
connection.send(JSON.stringify(U));
console.log(JSON.stringify(U))
}
</script>
99 changes: 99 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>uta.cse3310</groupId>
<artifactId>TicTacToe</artifactId>
<version>1.0-SNAPSHOT</version>

<name>TicTacToe</name>
<description>A simple game example.</description>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
</dependency>

<dependency>
<groupId>net.freeutils</groupId>
<artifactId>jlhttp</artifactId>
<version>2.6</version>
</dependency>

<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.4</version>
</dependency>

</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>
Loading

0 comments on commit 7ee08d4

Please sign in to comment.