diff --git a/src/client/UsernameInput.ts b/src/client/UsernameInput.ts
index 3adbcdbdb..79b194ad2 100644
--- a/src/client/UsernameInput.ts
+++ b/src/client/UsernameInput.ts
@@ -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`
${this.validationError}
`
diff --git a/src/server/Server.ts b/src/server/Server.ts
index 830af011e..298189599 100644
--- a/src/server/Server.ts
+++ b/src/server/Server.ts
@@ -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}`)