Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep up to date #16

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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 <<END
Host production
HostName ${{ secrets.SSH_HOST }}
User ${{ secrets.SSH_USER }}
IdentityFile ~/.ssh/production.key
StrictHostKeyChecking no
END

- name: get source code and compile
run: |
echo "deleting the directory ${{ github.event.repository.name }} "
ssh production "rm -rf ${{ github.event.repository.name }}"
echo "cloning ${{ github.server_url }}/${{ github.repository }}"
ssh production "git clone ${{ github.server_url }}/${{ github.repository }}"
ssh production "cd ${{ github.event.repository.name }};mvn clean compile package"

- name: create systemd unit file
run: |
# without enable-linger, you must be logged in. So, we enable it.
ssh production "loginctl enable-linger"
ssh production "mkdir --parents .config/systemd/user"
ssh production "rm -f .config/systemd/user/${{ vars.service_name }}.service"
ssh production 'echo "[Unit]" >> .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 }}"

37 changes: 35 additions & 2 deletions html/lobby.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div id="lobbyContainer">
<div id="userInputSection">
<button id="helpButton">HELP</button>
<button id="standbyButton">PUT ON STANDBY</button>
<div>
<label for="nickInput">Insert Nick:</label>
<input type="text" id="nickInput" placeholder="Type here">
Expand Down Expand Up @@ -51,6 +52,10 @@ <h1>The Word Search Game</h1>

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";
};

Expand Down Expand Up @@ -117,16 +122,44 @@ <h1>The Word Search Game</h1>
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.");
}
</script>
</body>
</html>
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/uta/cse3310/WordList.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@ public void shuffleWords()
Collections.shuffle(list);
}

public List<String> updatedWordList(List<String> wordBank) {
if (wordBank.size() < 500) {
System.err.println("Word bank does not contain at least 500 words.");
return Collections.emptyList();
public List<String> updatedWordList(List<String> wordBank)
{
int totalCharacters = 0;
int index = 0;
List<String> 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<String> updatedList = new ArrayList<>(wordBank.subList(0, 500));

return updatedList;
}

Expand Down
Loading