summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock185
-rw-r--r--Cargo.toml1
-rw-r--r--page.html64
-rw-r--r--src/conn.rs3
4 files changed, 205 insertions, 48 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1f200e3..4e24412 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,19 @@
version = 3
[[package]]
+name = "ammonia"
+version = "3.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d5ed2509ee88cc023cccee37a6fab35826830fe8b748b3869790e7720c2c4a74"
+dependencies = [
+ "html5ever",
+ "maplit",
+ "once_cell",
+ "tendril",
+ "url",
+]
+
+[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -142,6 +155,16 @@ dependencies = [
]
[[package]]
+name = "futf"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843"
+dependencies = [
+ "mac",
+ "new_debug_unreachable",
+]
+
+[[package]]
name = "futures-channel"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -276,6 +299,20 @@ dependencies = [
]
[[package]]
+name = "html5ever"
+version = "0.26.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7"
+dependencies = [
+ "log",
+ "mac",
+ "markup5ever",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "http"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -410,6 +447,32 @@ dependencies = [
]
[[package]]
+name = "mac"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
+
+[[package]]
+name = "maplit"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
+
+[[package]]
+name = "markup5ever"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016"
+dependencies = [
+ "log",
+ "phf",
+ "phf_codegen",
+ "string_cache",
+ "string_cache_codegen",
+ "tendril",
+]
+
+[[package]]
name = "matches"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -439,25 +502,14 @@ dependencies = [
[[package]]
name = "mio"
-version = "0.8.2"
+version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9"
+checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799"
dependencies = [
"libc",
"log",
- "miow",
- "ntapi",
"wasi 0.11.0+wasi-snapshot-preview1",
- "winapi",
-]
-
-[[package]]
-name = "miow"
-version = "0.3.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
-dependencies = [
- "winapi",
+ "windows-sys",
]
[[package]]
@@ -479,13 +531,10 @@ dependencies = [
]
[[package]]
-name = "ntapi"
-version = "0.3.7"
+name = "new_debug_unreachable"
+version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
-dependencies = [
- "winapi",
-]
+checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "num_cpus"
@@ -539,6 +588,44 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
+name = "phf"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
+dependencies = [
+ "phf_shared",
+]
+
+[[package]]
+name = "phf_codegen"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd"
+dependencies = [
+ "phf_generator",
+ "phf_shared",
+]
+
+[[package]]
+name = "phf_generator"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
+dependencies = [
+ "phf_shared",
+ "rand",
+]
+
+[[package]]
+name = "phf_shared"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
+dependencies = [
+ "siphasher",
+]
+
+[[package]]
name = "pin-project"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -577,6 +664,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
+name = "precomputed-hash"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
+
+[[package]]
name = "proc-macro2"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -773,6 +866,12 @@ dependencies = [
]
[[package]]
+name = "siphasher"
+version = "0.3.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
+
+[[package]]
name = "slab"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -801,10 +900,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
+name = "string_cache"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08"
+dependencies = [
+ "new_debug_unreachable",
+ "once_cell",
+ "parking_lot",
+ "phf_shared",
+ "precomputed-hash",
+ "serde",
+]
+
+[[package]]
+name = "string_cache_codegen"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988"
+dependencies = [
+ "phf_generator",
+ "phf_shared",
+ "proc-macro2",
+ "quote",
+]
+
+[[package]]
name = "syn"
-version = "1.0.92"
+version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52"
+checksum = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a"
dependencies = [
"proc-macro2",
"quote",
@@ -826,6 +951,17 @@ dependencies = [
]
[[package]]
+name = "tendril"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0"
+dependencies = [
+ "futf",
+ "mac",
+ "utf-8",
+]
+
+[[package]]
name = "thiserror"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -862,9 +998,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
-version = "1.18.1"
+version = "1.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dce653fb475565de9f6fb0614b28bca8df2c430c0cf84bcd9c843f15de5414cc"
+checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395"
dependencies = [
"bytes",
"libc",
@@ -1224,6 +1360,7 @@ dependencies = [
name = "websweeper"
version = "1.0.0"
dependencies = [
+ "ammonia",
"futures-util",
"rand",
"tokio",
diff --git a/Cargo.toml b/Cargo.toml
index 1cfddc5..3a9c24e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,3 +11,4 @@ tokio = { version = "1", features = ["full"] }
warp = { version = "0.3", features = ["tls", "websocket"] }
rand = "0.8"
futures-util = "0.3"
+ammonia = "3"
diff --git a/page.html b/page.html
index 0508794..8656495 100644
--- a/page.html
+++ b/page.html
@@ -54,7 +54,7 @@
window.info_elem = document.getElementById("miscinfo");
window.info_elem.innerHTML =`
<input id="name-in" type="text" value="anon">
- <input id="clr-in" type="color" value="#ffffff"></input>
+ <input id="clr-in" type="color" value="#33c033"></input>
<button onclick=register()>Join</button>`;
window.board_elem = document.getElementById("board");
window.bwidth = NaN;
@@ -85,7 +85,7 @@
if (typeof d == "object") {
d.arrayBuffer().then(acceptBoard);
info_elem.onclick = undefined;
- info_elem.innerHTML = "Running";
+ info_elem.innerHTML = `Running, ${mine_ratio} tiles are mines`;
} else if (typeof e.data == "string") {
let fields = d.split(" ");
switch (fields[0]) {
@@ -98,10 +98,11 @@
if (!cursors.has(oid)) {
createCursor(oid, name, clr);
}
- let celem = window.cursors.get(oid).elem;
+ let celem = cursors.get(oid).elem;
celem.style.left = x + 'px';
celem.style.top = y + 'px';
- } break;
+ movSelWin(cursors.get(oid).selwin, x, y);
+ } break;
case "regack": {
name = fields[1];
id = Number(fields[2]);
@@ -114,18 +115,18 @@
case "win": {
info_elem.innerHTML = "<p>You win! Click here to play again.</p>";
info_elem.onclick = e => { s.send("reset") };
- } break;
+ } break;
case "lose": {
let badone = fields[1];
info_elem.innerHTML = `<p>You lost, ${badone} was blown up. Click here to retry.</p>`;
info_elem.onclick = e => { s.send("reset") };
- } break;
+ } break;
case "logoff": {
let oid = Number(fields[1]);
cursors.get(oid).elem.remove();
cursors.get(oid).selwin.remove();
cursors.delete(oid);
- } break;
+ } break;
}
}
}
@@ -145,14 +146,25 @@
let gamechars = /^[CFO# 1-8]+$/;
if ((cur != last && gamechars.test(cur)) || cur == undefined) {
let txt = board.substr(last_idx, i-last_idx);
- if (txt[0] == 'O') {
- txt = `<span style="color:red;">${txt}</span>`;
- } else if (txt[0] == 'C') {
- txt = `<span style="color:green;">${txt}</span>`;
- } else if (txt[0] == 'F') {
- txt = `<span style="color:yellow;">${txt}</span>`;
- } else {
- txt = `<span style="color:white;">${txt}</span>`;
+ switch(txt[0]) {
+ case 'O':
+ txt = `<span style="color:red;">${txt}</span>`;
+ break;
+ case 'C':
+ txt = `<span style="color:green;">${txt}</span>`;
+ break;
+ case 'F':
+ txt = `<span style="color:yellow;">${txt}</span>`;
+ break;
+
+ case '1': txt = `<span style="color:#0100FB;">${txt}</span>`; break;
+ case '2': txt = `<span style="color:#027F01;">${txt}</span>`; break;
+ case '3': txt = `<span style="color:#FD0100;">${txt}</span>`; break;
+ case '4': txt = `<span style="color:#01017B;">${txt}</span>`; break;
+ case '5': txt = `<span style="color:#7D0302;">${txt}</span>`; break;
+ case '6': txt = `<span style="color:#00807F;">${txt}</span>`; break;
+
+ default: txt = `<span style="color:white;">${txt}</span>`; break;
}
split_board.push(txt);
last_idx = i;
@@ -170,7 +182,7 @@
nametag.innerHTML = name;
nametag.classList.add('cursor-name');
let selection_window = document.createElement("div");
- selection_window.style.backgroundColor = "#00c000a0";
+ selection_window.style.backgroundColor = clr + "a0";
selection_window.style.position = "absolute";
selection_window.classList.add('cursor');
cursor.appendChild(nametag);
@@ -182,21 +194,27 @@
document.addEventListener('mousemove', e => {
cursor.style.left = (e.pageX + 15) + 'px';
cursor.style.top = (e.pageY + 15) + 'px';
+ movSelWin(selection_window, e.clientX, e.clientY);
let tpos = tilepos(e.clientX, e.clientY);
socket.send(`pos ${e.pageX} ${e.pageY}`);
},
false);
- board_elem.addEventListener('mousemove', e => {
- let tpos = tilepos(e.clientX, e.clientY);
- selection_window.style.left = ((tpos.x + 0.5) * tile_w) + 'px';
- selection_window.style.top = ((tpos.y + 0.5) * tile_h) + 'px';
- selection_window.style.width = tile_w + 'px';
- selection_window.style.height = tile_h + 'px';
- }, false);
}
cursors.set(id, {name: name, elem: cursor, selwin: selection_window});
return cursor;
}
+ function movSelWin(win, x, y) {
+ let tpos = tilepos(x, y);
+ if (tpos.x > (bwidth - 1) || tpos.x < 0 || tpos.y > (bheight - 1) || tpos.y < 0) {
+ win.style.display = "none";
+ } else {
+ win.style.display = "";
+ }
+ win.style.left = ((tpos.x + 0.5) * tile_w) + 'px';
+ win.style.top = ((tpos.y + 0.5) * tile_h) + 'px';
+ win.style.width = tile_w + 'px';
+ win.style.height = tile_h + 'px';
+ }
function getBoardBounds() {
let boardb = board_elem.getBoundingClientRect();
tile_w = boardb.width / bwidth;
diff --git a/src/conn.rs b/src/conn.rs
index 9c23592..14777bf 100644
--- a/src/conn.rs
+++ b/src/conn.rs
@@ -6,6 +6,7 @@ use std::{
use tokio::sync::RwLock;
use futures_util::{SinkExt, StreamExt, TryStreamExt, stream::SplitStream};
use warp::ws::{ WebSocket, Message };
+use ammonia;
pub async fn lobby(socket: WebSocket, addr: SocketAddr, room: Arc<RwLock<Room>>) {
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
@@ -32,7 +33,7 @@ pub async fn lobby(socket: WebSocket, addr: SocketAddr, room: Arc<RwLock<Room>>)
let def = "anon".to_string();
if all_fields.is_empty() { def }
else {
- let n = all_fields.join(" ");
+ let n = ammonia::clean(&all_fields.join(" "));
if n.is_empty() { def } else { n }
}
};