* updata validation on public games

This commit is contained in:
Mittani
2024-12-25 19:26:51 +01:00
committed by evanpelle
parent af6c519d77
commit 697b4c6111
2 changed files with 39 additions and 39 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ export class UsernameInput extends LitElement {
.value=${this.username}
@input=${this.handleInput}
placeholder="Enter your username"
maxlength="123"
maxlength="${MAX_USERNAME_LENGTH}"
>
${this.validationError
? html`<div class="error">${this.validationError}</div>`
+38 -38
View File
@@ -122,23 +122,20 @@ app.get('/private_lobby/:id', (req, res) => {
wss.on('connection', (ws, req) => {
ws.on('message', (message: string) => {
try {
const clientMsg: ClientMessage = ClientMessageSchema.parse(JSON.parse(message))
slog({
logKey: 'websocket_msg',
msg: 'server received websocket message',
data: clientMsg,
severity: LogSeverity.Debug
})
if (clientMsg.type == "join") {
const forwarded = req.headers['x-forwarded-for']
let ip = Array.isArray(forwarded)
? forwarded[0] // Get the first IP if it's an array
: forwarded || req.socket.remoteAddress;
if (Array.isArray(ip)) {
ip = ip[0]
}
const username = clientMsg.username;
const clientMsg: ClientMessage = ClientMessageSchema.parse(JSON.parse(message))
slog({
logKey: 'websocket_msg',
msg: 'server received websocket message',
data: clientMsg,
severity: LogSeverity.Debug
})
if (clientMsg.type == "join") {
const forwarded = req.headers['x-forwarded-for']
const ip = Array.isArray(forwarded)
? forwarded[0] // Get the first IP if it's an array
: forwarded || req.socket.remoteAddress;
const username = clientMsg.username;
const { isValid, error } = validateUsername(username);
if (!isValid) {
const errorMsg = error || "Invalid username.";
@@ -151,28 +148,31 @@ wss.on('connection', (ws, req) => {
return;
}
// If username is valid, add the client
gm.addClient(
new Client(
clientMsg.clientID,
clientMsg.persistentID,
ip,
username,
ws
),
clientMsg.gameID,
clientMsg.lastTurn
)
// If username is valid, add the client
gm.addClient(
new Client(
clientMsg.clientID,
clientMsg.persistentID,
ip,
username,
ws
),
clientMsg.gameID,
clientMsg.lastTurn
)
}
if (clientMsg.type == "log") {
slog({
logKey: "client_console_log",
msg: clientMsg.log,
severity: clientMsg.severity,
clientID: clientMsg.clientID,
gameID: clientMsg.gameID,
persistentID: clientMsg.persistentID,
})
}
if (clientMsg.type == "log") {
slog({
logKey: "client_console_log",
msg: clientMsg.log,
severity: clientMsg.severity,
clientID: clientMsg.clientID,
gameID: clientMsg.gameID,
persistentID: clientMsg.persistentID,
})
} catch (error) {
console.log(`errror handling websocket message: ${error}`)
}
} catch (error) {
console.log(`errror handling websocket message: ${error}`)