This commit is contained in:
Adam 2024-07-28 02:50:26 -04:00
parent 89b7af27d6
commit 7707120e44
6 changed files with 2 additions and 207 deletions

View file

@ -1,23 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cards For Humanity</title>
<link type="text/css" rel="stylesheet" href="css">
</head>
<body>
<h1>Cards For Humanity</h1>
<hr />
<ul>
<li>
<a href="test_client">test_client</a>
</li>
<li>
<a href="spawn_clients">spawn_clients</a>
</li>
<li>
<a href="reference_client">reference_client</a>
</li>
</ul>
</body>
</html>

View file

@ -1,36 +0,0 @@
html,
body,
input,
textarea,
button {
font-family: monospace;
background-color: #111;
color: #ddd;
margin: 0;
padding: 0;
}
div {
margin-top: 1rem;
}
span {
padding-left: 1rem;
}
p {
margin: 0;
padding: 0;
}
input {
display: block;
width: 10rem;
box-sizing: border-box;
}
iframe {
width: 49%;
height: 49vh;
border-style: none;
}
.container {
width: 100vw;
height: 100vh;
display: flex;
}

View file

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cards For Humanity Reference Client</title>
<link type="text/css" rel="stylesheet" href="css">
</head>
<body>
<h1>Cards For Humanity Reference Client</h1>
<hr />
<p>I am the Reference Client.</p>
</body>
</html>

View file

@ -1,16 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cards For Humanity Test Clients</title>
<link type="text/css" rel="stylesheet" href="css">
</head>
<body>
<div id="container">
<iframe src="http://localhost:3030/test_client"></iframe>
<iframe src="http://localhost:3030/test_client"></iframe>
<iframe src="http://localhost:3030/test_client"></iframe>
<iframe src="http://localhost:3030/test_client"></iframe>
</div>
</body>
</html>

View file

@ -1,98 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cards For Humanity Test Client</title>
<link type="text/css" rel="stylesheet" href="css">
</head>
<body>
<h1>Cards For Humanity Test Client</h1>
<hr />
<div id="status">
<p><em>Disconnected...</em></p>
</div>
<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>
<input id="chat-input" type="text" style="width: 30rem;" placeholder="talk shit" />
</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>
<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>
<script type="text/javascript">
socket = new WebSocket("ws://localhost:3030/websocket");
function socketTest() {
let code = testCloseCode.value;
let reason = testCloseReason.value;
socket.close(code, reason)
};
function createGame() {
let CAHPlayer = {
name: username.value,
role: 'Host',
white: [],
black: [],
};
let NewGameRequest = {
name: gamename.value,
host: CAHPlayer,
packs: [0],
};
socket.send(JSON.stringify(NewGameRequest));
};
function joinGame() {
console.log('not done yet');
}
socket.onopen = function() {
console.log("connection opened",socket.extensions, socket.protocol, socket.readyState);
document.getElementById("status").innerHTML = '<p><em>Connected!</em></p>';
}
socket.onclose = function() {
console.log("connection closed");
document.getElementById("status").innerHTML = '<p><em>Disconnected...</em></p>';
document.getElementById("chat-history").value = "";
}
socket.onmessage = function(e) {
const history = document.getElementById("chat-history")
console.log("received message: "+e.data);
history.value += e.data+"\r";
history.scrollTop = history.scrollHeight;
}
function chatSubmit() {
let input = document.getElementById("chat-input");
socket.send(input.value);
input.value = "";
};
socket.addEventListener("error", (event) => {
console.log("WebSocket error: ", event);
});
</script>
</body>
</html>

View file

@ -1,6 +1,5 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use axum::{response::Html, routing::get, Router}; use axum::{routing::get, Router};
use axum_extra::response::Css;
use lib::models::*; use lib::models::*;
use std::{ use std::{
collections::HashMap, collections::HashMap,
@ -35,7 +34,7 @@ fn load_names(path: &str) -> Vec<String> {
buf.push(line.unwrap()) buf.push(line.unwrap())
} }
return buf; buf
} }
// this is still around just for reference // this is still around just for reference
@ -104,20 +103,6 @@ pub struct AppState {
last_names: Vec<String>, last_names: Vec<String>,
} }
// Include utf-8 files at **compile** time.
async fn test_client() -> Html<&'static str> {
Html(std::include_str!("../public/test_client.html"))
}
async fn spawn_clients() -> Html<&'static str> {
Html(std::include_str!("../public/spawn_clients.html"))
}
async fn reference_client() -> Html<&'static str> {
Html(std::include_str!("../public/reference_client.html"))
}
async fn css() -> Css<&'static str> {
Css(std::include_str!("../public/main.css"))
}
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
// stuff for logging // stuff for logging
@ -149,11 +134,7 @@ async fn main() -> Result<()> {
// set routes and apply state // set routes and apply state
let app = Router::new() let app = Router::new()
.route("/spawn_clients", get(spawn_clients))
.route("/test_client", get(test_client))
.route("/reference_client", get(reference_client))
.route("/websocket", get(websocket_connection_handler)) .route("/websocket", get(websocket_connection_handler))
.route("/css", get(css))
.nest_service("/", ServeDir::new("dist")) .nest_service("/", ServeDir::new("dist"))
.with_state(app_state); .with_state(app_state);