diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b81645e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,74 @@ +# Derived from an example provided by https://blog.benoitblanchon.fr/github-action-run-ssh-commands/ +# https://github.blog/2015-06-16-read-only-deploy-keys/ +# +# +# +# +# +name: Deploy +on: [push] +jobs: + deploy: + name: "Deploy to server" + runs-on: ubuntu-latest + steps: + - name: configure SSH + run: | + # These are very useful for debugging + echo "Repository = ${{ github.repository }}" + echo "github url = ${{ github.server_url }}" + echo "Owner = ${{ github.repository_owner }}" + echo "Repository name = ${{ github.event.repository.name }}" + echo "Service name = ${{ vars.service_name }}" + echo "http port = ${{ vars.http_port }}" + echo "websocket port = ${{ vars.websocket_port }}" + echo "version = $${ github.sha }}" + # On to the work at hand. + mkdir -p ~/.ssh/ + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/production.key + chmod 600 ~/.ssh/production.key + cat >>~/.ssh/config <> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "Description=${{ vars.service_name }}" >> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "[Service]" >> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "Type=simple" >> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "Restart=always" >> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "RestartSec=5" >> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "Environment=VERSION=\"${{ github.sha }}\"" >>.config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "Environment=WEBSOCKET_PORT=${{ vars.websocket_port }}" >>.config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "Environment=HTTP_PORT=${{ vars.http_port }}" >>.config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "ExecStart=mvn exec:java -Dexec.mainClass=uta.cse3310.App" >> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "WorkingDirectory=$PWD/${{ github.event.repository.name }}" >> .config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "[Install]" >>.config/systemd/user/${{ vars.service_name }}.service' + ssh production 'echo "WantedBy=default.target" >>.config/systemd/user/${{ vars.service_name }}.service' + - name: systemd reload + run: | + ssh production "systemctl --user daemon-reload" + + - name: restart daemon + run: | + ssh production "systemctl --user enable ${{ vars.service_name }}" + ssh production "systemctl --user restart ${{ vars.service_name }}" + ssh production "systemctl --user status ${{ vars.service_name }}" + diff --git a/html/lobby.html b/html/lobby.html index 652a7c0..62f5c7f 100644 --- a/html/lobby.html +++ b/html/lobby.html @@ -10,6 +10,7 @@
+
@@ -51,6 +52,10 @@

The Word Search Game

socket.onclose = function(evt) { console.log("WebSocket connection closed."); + var nick = document.getElementById('nickInput').value.trim(); + if (nick) { + leaveGame(nick); + } document.getElementById("topMessage").innerText = "Server Offline"; }; @@ -117,16 +122,44 @@

The Word Search Game

socket.send(JSON.stringify(data)); } - // event listener for the leave button + // the leave button document.getElementById('leaveButton').addEventListener('click', function() { var nick = document.getElementById('nickInput').value; leaveGame(nick); }); - // add an event listener for the refresh button to request the game list + // refresh button to request the game list document.getElementById('refreshButton').addEventListener('click', function() { requestGameList(); }); + + //the help content + document.getElementById('helpButton').addEventListener('click', function() { + displayHelp(); + }); + + function displayHelp() { + alert("This is the rules of this game."); + } + + //the standby button + document.getElementById('standbyButton').addEventListener('click', function() { + var nick = document.getElementById('nickInput').value.trim(); + var mode = document.getElementById('modeSelect').value; + + putOnStandby(nick, mode); + }); + + function putOnStandby(nick, mode) { + var data = { + type: "JoinGame", + nick: nick, + gameIndex: "standby", + modeIndex: mode + }; + socket.send(JSON.stringify(data)); + alert("You are now on standby."); + } diff --git a/src/main/java/uta/cse3310/WordList.java b/src/main/java/uta/cse3310/WordList.java index c741886..ab9bb16 100644 --- a/src/main/java/uta/cse3310/WordList.java +++ b/src/main/java/uta/cse3310/WordList.java @@ -33,14 +33,26 @@ public void shuffleWords() Collections.shuffle(list); } - public List updatedWordList(List wordBank) { - if (wordBank.size() < 500) { - System.err.println("Word bank does not contain at least 500 words."); - return Collections.emptyList(); + public List updatedWordList(List wordBank) + { + int totalCharacters = 0; + int index = 0; + List updatedList = new ArrayList<>(); + + while (totalCharacters < 2000 && index < wordBank.size()) + { + String word = wordBank.get(index); + if (totalCharacters + word.length() <= 2000) + { + updatedList.add(word); + totalCharacters += word.length(); + } else + { + break; + } + index++; } - List updatedList = new ArrayList<>(wordBank.subList(0, 500)); - return updatedList; }