Announce player joins

Clients announce on join and maintain a list of known players
This commit is contained in:
jude 2022-12-29 14:36:55 +00:00
parent 98d0dbb216
commit 39c31e0f90
4 changed files with 39 additions and 8 deletions

2
.prettierrc.toml Normal file
View File

@ -0,0 +1,2 @@
printWidth = 90
tabWidth = 4

View File

@ -1,14 +1,33 @@
const ID = window.crypto.randomUUID();
document.addEventListener('DOMContentLoaded', () => {
let players = {};
document.addEventListener("DOMContentLoaded", () => {
let socket = io();
socket.on('connect', () => {
console.log('Connected!');
socket.emit('message', { 'type': 'CONNECTED', 'id': ID });
socket.on("connect", () => {
console.log("Connected!");
socket.emit("message", { type: "ANNOUNCE", author: ID, name: "" });
players[ID] = { name: "" };
});
socket.on('message', (data) => {
console.log(data);
})
socket.on("message", (data) => {
// Ignore any messages that originate from us.
if (data.author !== ID) {
switch (data.type) {
case "ANNOUNCE":
playerConnected(socket, data);
break;
}
}
});
});
function playerConnected(socket, data) {
// When a new player is seen, all announce to ensure they know all players.
if (players[data.author] === undefined) {
players[data.author] = { name: data.name };
socket.emit("message", { type: "ANNOUNCE", author: ID, name: "" });
} else {
}
}

Binary file not shown.

View File

@ -5,7 +5,7 @@
\usepackage{amssymb}
\title{\textbf{Cryptographic protocol for dishonest players to play Risk} \\ Literature and technology survey and review}
\title{Cryptographic protocol for playing Risk in an untrusted setting}
\author{Jude Southworth}
\date{Bachelor of Science in Computer Science and Mathematics \\
The University of Bath \\
@ -21,6 +21,12 @@
\maketitle
\section{Outline}
Risk is a strategy game developed by Albert Lamorisse in 1957. It is a highly competitive game, in which players battle for control over regions of a world map by stationing units within their territories in order to launch attacks on neighbouring territories that are not in their control.
\section{Existing solutions}
For playing games over an internet connection, multiple solutions already exist. These can roughly be broken down into those that are centralised and those that are decentralised, although many decentralised systems rely on federated or centralised communications for peer discovery.
@ -228,6 +234,10 @@ Blind signatures can also be performed with RSA \citep{bellare2003one}. In RSA-b
RSA blinding can incur a security risk, as by using the same keys to sign and encrypt, a player can be tricked into revealing their private key through a chosen-plaintext attack.
\section{Implementation}
The implementation provided uses WebSockets as the communication primitive. Whilst this is therefore a centralised implementation, no verification occurs in the server code, which instead simply "echoes" messages received to all connected clients.
\bibliography{Dissertation}
\end{document}