2024-04-28 04:53:00 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<title>Cards For Humanity Test Client</title>
|
2024-06-23 04:49:32 -04:00
|
|
|
<link type="text/css" rel="stylesheet" href="css">
|
2024-04-28 04:53:00 -04:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Cards For Humanity Test Client</h1>
|
2024-05-02 00:39:34 -04:00
|
|
|
<hr />
|
2024-04-29 02:18:20 -04:00
|
|
|
<div id="status">
|
|
|
|
<p><em>Disconnected...</em></p>
|
|
|
|
</div>
|
2024-05-03 21:12:23 -04:00
|
|
|
<div id="chat">
|
|
|
|
<form id="chat" onsubmit="chatSubmit();return false">
|
|
|
|
<textarea id="chat-history" readonly="true" wrap="soft" style="display:block; width:30rem; height:10rem; box-sizing: border-box" cols="30" rows="10"></textarea>
|
2024-05-03 23:17:39 -04:00
|
|
|
<input id="chat-input" type="text" style="width: 30rem;" placeholder="talk shit" />
|
2024-05-03 21:12:23 -04:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
<form id="new-game" onsubmit="createGame(); return false">
|
|
|
|
<p>Username:</p>
|
|
|
|
<input id="username" type="text" placeholder="username" />
|
|
|
|
<p>Game Name:</p>
|
|
|
|
<input id="gamename" type="text" placeholder="game name" />
|
|
|
|
<button id="create-game" type="submit">Create Game</button>
|
|
|
|
</form>
|
2024-05-02 00:39:34 -04:00
|
|
|
<hr />
|
|
|
|
<div id="socketTest">
|
|
|
|
<h3>Socket Test</h3>
|
|
|
|
<form id="socketForm" onsubmit="socketTest(); return false">
|
|
|
|
<p>int 3000-4999</p>
|
|
|
|
<input id="testCloseCode" placeholder="code" type="number" />
|
|
|
|
<p>string 123 bytes or less</p>
|
|
|
|
<input id="testCloseReason" placeholder="reason" />
|
|
|
|
<button id="close" type="submit">Close Connection</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
2024-04-28 04:53:00 -04:00
|
|
|
<script type="text/javascript">
|
2024-05-01 04:56:58 -04:00
|
|
|
socket = new WebSocket("ws://localhost:3030/websocket");
|
2024-04-28 04:53:00 -04:00
|
|
|
|
2024-05-02 00:39:34 -04:00
|
|
|
function socketTest() {
|
|
|
|
let code = testCloseCode.value;
|
|
|
|
let reason = testCloseReason.value;
|
|
|
|
socket.close(code, reason)
|
|
|
|
};
|
2024-04-30 02:28:43 -04:00
|
|
|
|
2024-05-02 00:39:34 -04:00
|
|
|
function createGame() {
|
2024-05-03 23:17:39 -04:00
|
|
|
let CAHPlayer = {
|
|
|
|
name: username.value,
|
|
|
|
role: 'Host',
|
|
|
|
white: [],
|
|
|
|
black: [],
|
|
|
|
};
|
2024-04-30 02:28:43 -04:00
|
|
|
|
2024-05-03 23:17:39 -04:00
|
|
|
let NewGameRequest = {
|
|
|
|
name: gamename.value,
|
|
|
|
host: CAHPlayer,
|
|
|
|
packs: [0],
|
|
|
|
};
|
2024-04-30 02:28:43 -04:00
|
|
|
|
2024-05-01 04:56:58 -04:00
|
|
|
socket.send(JSON.stringify(NewGameRequest));
|
2024-04-29 02:18:20 -04:00
|
|
|
};
|
2024-04-28 04:53:00 -04:00
|
|
|
|
2024-05-02 00:39:34 -04:00
|
|
|
function joinGame() {
|
2024-05-03 23:17:39 -04:00
|
|
|
console.log('not done yet');
|
2024-05-02 00:39:34 -04:00
|
|
|
}
|
|
|
|
|
2024-05-01 04:56:58 -04:00
|
|
|
socket.onopen = function() {
|
2024-05-03 23:17:39 -04:00
|
|
|
console.log("connection opened",socket.extensions, socket.protocol, socket.readyState);
|
|
|
|
document.getElementById("status").innerHTML = '<p><em>Connected!</em></p>';
|
2024-04-29 02:18:20 -04:00
|
|
|
}
|
2024-04-28 04:53:00 -04:00
|
|
|
|
2024-05-01 04:56:58 -04:00
|
|
|
socket.onclose = function() {
|
2024-05-03 23:17:39 -04:00
|
|
|
console.log("connection closed");
|
|
|
|
document.getElementById("status").innerHTML = '<p><em>Disconnected...</em></p>';
|
|
|
|
document.getElementById("chat-history").value = "";
|
2024-04-29 02:18:20 -04:00
|
|
|
}
|
2024-04-28 04:53:00 -04:00
|
|
|
|
2024-05-01 04:56:58 -04:00
|
|
|
socket.onmessage = function(e) {
|
2024-05-03 23:17:39 -04:00
|
|
|
const history = document.getElementById("chat-history")
|
|
|
|
console.log("received message: "+e.data);
|
|
|
|
history.value += e.data+"\r";
|
|
|
|
history.scrollTop = history.scrollHeight;
|
2024-04-29 02:18:20 -04:00
|
|
|
}
|
2024-04-28 04:53:00 -04:00
|
|
|
|
2024-04-29 02:18:20 -04:00
|
|
|
function chatSubmit() {
|
2024-05-03 23:17:39 -04:00
|
|
|
let input = document.getElementById("chat-input");
|
|
|
|
socket.send(input.value);
|
|
|
|
input.value = "";
|
2024-04-29 02:18:20 -04:00
|
|
|
};
|
2024-04-29 03:32:44 -04:00
|
|
|
|
2024-05-01 04:56:58 -04:00
|
|
|
socket.addEventListener("error", (event) => {
|
2024-05-03 23:17:39 -04:00
|
|
|
console.log("WebSocket error: ", event);
|
2024-04-29 03:32:44 -04:00
|
|
|
});
|
2024-04-28 04:53:00 -04:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|