changed from uuid + username to username + '#' + id
This commit is contained in:
parent
b5bb18fe7f
commit
cd75deef30
@ -129,9 +129,10 @@ function cmd_echo(input) {
|
|||||||
function cmd_nick(input) {
|
function cmd_nick(input) {
|
||||||
if (input === undefined)
|
if (input === undefined)
|
||||||
return "No nickname was given!";
|
return "No nickname was given!";
|
||||||
if (!user.connected)
|
if (user.connected)
|
||||||
return "You are not connected!";
|
|
||||||
sendNickname(input[0]);
|
sendNickname(input[0]);
|
||||||
|
else
|
||||||
|
connect(input[0]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,11 +180,5 @@ function cmd_ll() {
|
|||||||
if (!user.connected)
|
if (!user.connected)
|
||||||
return "You are not connected!";
|
return "You are not connected!";
|
||||||
requestUsernames();
|
requestUsernames();
|
||||||
}
|
return null;
|
||||||
|
|
||||||
// Connect to server
|
|
||||||
function cmd_connect() {
|
|
||||||
if (user.connected)
|
|
||||||
return "You are already connected!";
|
|
||||||
connect();
|
|
||||||
}
|
}
|
@ -188,7 +188,7 @@ function createText(str, safe=true) {
|
|||||||
// Rename last-posted pretext to own username
|
// Rename last-posted pretext to own username
|
||||||
function renameToSelf() {
|
function renameToSelf() {
|
||||||
const tbc = tbDiv.children;
|
const tbc = tbDiv.children;
|
||||||
tbc[tbc.length - 3].innerHTML = `${user.name}: `;
|
tbc[tbc.length - 3].innerHTML = `${user.name}#${user.id}: `;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update cursor position based on coordinates
|
// Update cursor position based on coordinates
|
||||||
|
@ -13,14 +13,23 @@ document.body.onunload = document.body.onbeforeunload = () => {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
name: user.name,
|
||||||
id: user.id
|
id: user.id
|
||||||
})
|
})
|
||||||
}).then(res => {});
|
}).then(res => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect to server
|
// Connect to server
|
||||||
function connect() {
|
function connect(name) {
|
||||||
fetch('/connect').then(res => {
|
user.name = name;
|
||||||
|
fetch('/connect', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ name })
|
||||||
|
}).then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
user.connected = true;
|
user.connected = true;
|
||||||
return res.json();
|
return res.json();
|
||||||
@ -31,11 +40,11 @@ function connect() {
|
|||||||
if (res === undefined)
|
if (res === undefined)
|
||||||
return;
|
return;
|
||||||
// Save provided id
|
// Save provided id
|
||||||
const {id} = res;
|
const { id } = res;
|
||||||
user.id = id;
|
user.id = id;
|
||||||
|
outputText({output: `Connected as '${name}#${id}'.`});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
connect();
|
|
||||||
|
|
||||||
|
|
||||||
// Send nickname to server, receive verification
|
// Send nickname to server, receive verification
|
||||||
@ -47,6 +56,7 @@ function sendNickname(name) {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
oldName: user.name,
|
||||||
id: user.id,
|
id: user.id,
|
||||||
name
|
name
|
||||||
})
|
})
|
||||||
@ -58,10 +68,11 @@ function sendNickname(name) {
|
|||||||
if (res === undefined)
|
if (res === undefined)
|
||||||
return;
|
return;
|
||||||
// Receive name and save it
|
// Receive name and save it
|
||||||
const { name } = res;
|
const { id } = res;
|
||||||
user.name = name;
|
user.name = name;
|
||||||
|
user.id = id;
|
||||||
// Reply whether name is taken or not
|
// Reply whether name is taken or not
|
||||||
outputText({output: `Applied name '${name}'.`});
|
outputText({output: `Applied name '${name}#${id}'.`});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +85,7 @@ function getChatMessages() {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
name: user.name,
|
||||||
id: user.id
|
id: user.id
|
||||||
})
|
})
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
@ -107,9 +119,10 @@ function directMessage(name, message) {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
recipient: name,
|
||||||
|
name: user.name,
|
||||||
id: user.id,
|
id: user.id,
|
||||||
message,
|
message
|
||||||
name
|
|
||||||
})
|
})
|
||||||
}).then(res => {});
|
}).then(res => {});
|
||||||
}
|
}
|
||||||
@ -129,10 +142,9 @@ function requestUsernames() {
|
|||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res === undefined)
|
if (res === undefined)
|
||||||
return;
|
return;
|
||||||
|
let output = "";
|
||||||
for (const u of res)
|
for (const u of res)
|
||||||
outputText({
|
output += `${u.name}#${u.id} `;
|
||||||
preNext: `${u.id}: `,
|
outputText({ output });
|
||||||
output: u.name
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user